diff --git a/app/controllers/api/v2/registration_commands_controller.rb b/app/controllers/api/v2/registration_commands_controller.rb index 5e5886caf15a..f3019bd3f766 100644 --- a/app/controllers/api/v2/registration_commands_controller.rb +++ b/app/controllers/api/v2/registration_commands_controller.rb @@ -21,7 +21,7 @@ class RegistrationCommandsController < V2::BaseController param :update_packages, :bool, desc: N_("Update all packages on the host") param :repo, String, desc: N_("Repository URL / details, for example for Debian OS family: 'deb http://deb.example.com/ buster 1.0', for Red Hat and SUSE OS family: 'http://yum.theforeman.org/client/latest/el8/x86_64/'") param :repo_gpg_key_url, String, desc: N_("URL of the GPG key for the repository") - param :use_wget, :bool, desc: N_("Use wget instead of curl") + param :download_utility, String, desc: N_("The download utility to use for host registration") end def create unless os_with_template? diff --git a/app/controllers/concerns/foreman/controller/registration.rb b/app/controllers/concerns/foreman/controller/registration.rb index f3494c9e65eb..82201bbd23ac 100644 --- a/app/controllers/concerns/foreman/controller/registration.rb +++ b/app/controllers/concerns/foreman/controller/registration.rb @@ -32,7 +32,7 @@ def global_registration_vars update_packages: params['update_packages'], repo: params['repo'], repo_gpg_key_url: params['repo_gpg_key_url'], - use_wget: params['use_wget'], + download_utility: params['download_utility'], } params.permit(permitted) diff --git a/app/controllers/concerns/foreman/controller/registration_commands.rb b/app/controllers/concerns/foreman/controller/registration_commands.rb index f37ff77679cc..236310a83e32 100644 --- a/app/controllers/concerns/foreman/controller/registration_commands.rb +++ b/app/controllers/concerns/foreman/controller/registration_commands.rb @@ -16,19 +16,27 @@ def registration_args end def insecure - if use_wget - registration_params['insecure'] ? ' --no-check-certificate' : '' + if registration_params['insecure'] + if download_utility == 'curl' + ' --insecure' + else + ' --no-check-certificate' + end else - registration_params['insecure'] ? ' --insecure' : '' + '' end end def application - use_wget ? 'wget --no-verbose -O-' : 'curl -sS' + if download_utility == 'curl' + 'curl -sS' + else + 'wget --no-verbose -O-' + end end - def use_wget - return registration_params['use_wget'] + def download_utility + return registration_params['download_utility'] end def registration_url(proxy = nil) diff --git a/app/views/unattended/provisioning_templates/registration/global_registration.erb b/app/views/unattended/provisioning_templates/registration/global_registration.erb index eaa4607948a6..ac3c1f42b953 100644 --- a/app/views/unattended/provisioning_templates/registration/global_registration.erb +++ b/app/views/unattended/provisioning_templates/registration/global_registration.erb @@ -36,7 +36,7 @@ export LC_ALL=C LANG=C <%= "\n# Ignore subman errors: [#{@ignore_subman_errors}]" unless @ignore_subman_errors.nil? -%> <%= "\n# Lifecycle environment id: [#{@lifecycle_environment_id}]" if @lifecycle_environment_id.present? -%> <%= "\n# Activation keys: [#{activation_keys}]" if activation_keys.present? -%> -<%= "\n# Use wget: [#{@use_wget}]" unless @use_wget.nil? -%> +<%= "\n# Download utility: [#{@download_utility}]" unless @download_utility.nil? -%> if ! [ $(id -u) = 0 ]; then @@ -87,10 +87,10 @@ elif [ -f /etc/debian_version ]; then <%= save_to_file('/etc/apt/sources.list.d/foreman_registration.list', @repo) %> <% -if @use_wget - gpg_key_download_command="wget --no-verbose -O-" -else +if @download_utility == 'curl' gpg_key_download_command="curl --silent --show-error" +else + gpg_key_download_command="wget --no-verbose -O-" end %> @@ -107,16 +107,16 @@ fi <% end -%> <% -if @use_wget - data_keyword = "--post-data" -else +if @download_utility == 'curl' data_keyword = "--data" +else + data_keyword = "--post-data" end -if @use_wget - registration_command="wget --no-verbose -O- --ca-certificate" -else +if @download_utility == 'curl' registration_command="curl --silent --show-error --request POST --cacert" +else + registration_command="wget --no-verbose -O- --ca-certificate" end %> diff --git a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/fixtures.js b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/fixtures.js index 273b745f2797..cbdf50a6f56e 100644 --- a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/fixtures.js +++ b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/__tests__/fixtures.js @@ -1,4 +1,5 @@ import { STATUS } from '../../../../constants'; +import { DownloadUtilities } from '../components/fields/DownloadUtility' export const generalComponentProps = { organizationId: 0, @@ -21,8 +22,8 @@ export const generalComponentProps = { handleInsecure: () => {}, handleInvalidField: () => {}, isLoading: false, - useWget: false, - handleUseWget: () => {}, + downloadUtility: DownloadUtilities.curl, + handleDownloadUtility: () => {}, }; export const advancedComponentProps = { configParams: {}, @@ -102,9 +103,9 @@ export const updatePackagesProps = { isLoading: false, }; -export const useWgetProps = { - useWget: false, - handleUseWget: () => {}, +export const downloadUtilityProps = { + downloadUtility: DownloadUtilities.curl, + handleDownloadUtility: () => {}, isLoading: false, }; diff --git a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/components/General.js b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/components/General.js index c6a2e9e59d1d..2f685c47cc4c 100644 --- a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/components/General.js +++ b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/components/General.js @@ -6,7 +6,7 @@ import HostGroup from './fields/HostGroup'; import OperatingSystem from './fields/OperatingSystem'; import SmartProxy from './fields/SmartProxy'; import Insecure from './fields/Insecure'; -import UseWget from './fields/UseWget'; +import DownloadUtility, { DownloadUtilities } from './fields/DownloadUtility'; const General = ({ organizationId, @@ -29,8 +29,8 @@ const General = ({ handleInsecure, handleInvalidField, isLoading, - useWget, - handleUseWget, + downloadUtility, + handleDownloadUtility, }) => ( <> - @@ -106,8 +106,8 @@ General.propTypes = { handleInsecure: PropTypes.func.isRequired, handleInvalidField: PropTypes.func.isRequired, isLoading: PropTypes.bool.isRequired, - useWget: PropTypes.bool.isRequired, - handleUseWget: PropTypes.func.isRequired, + downloadUtility: PropTypes.oneOf([DownloadUtilities.curl, DownloadUtilities.wget]).isRequired, + handleDownloadUtility: PropTypes.func.isRequired, }; General.defaultProps = { diff --git a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/components/fields/DownloadUtility.js b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/components/fields/DownloadUtility.js new file mode 100644 index 000000000000..e66d95920ef1 --- /dev/null +++ b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/components/fields/DownloadUtility.js @@ -0,0 +1,43 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + +import { + FormGroup, + FormSelect, + FormSelectOption, +} from '@patternfly/react-core'; + +import { translate as __ } from '../../../../../common/I18n'; + +export const DownloadUtilities = { + curl: 'curl', + wget: 'wget', +} +const DownloadUtility = ({ downloadUtility, handleDownloadUtility, isLoading }) => ( + + handleDownloadUtility(v)} + className="without_select2" + id="reg_download_utility" + isDisabled={isLoading} + > + {_.map(DownloadUtilities, (key, value) => ( + + ))} + + +); + +DownloadUtility.propTypes = { + downloadUtility: PropTypes.oneOf([DownloadUtilities.curl, DownloadUtilities.wget]), + handleHostGroup: PropTypes.func.isRequired, + isLoading: PropTypes.bool.isRequired, +}; + +DownloadUtility.defaultProps = { + downloadUtility: DownloadUtilities.curl, +}; + +export default DownloadUtility; diff --git a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/components/fields/UseWget.js b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/components/fields/UseWget.js deleted file mode 100644 index 579689195a33..000000000000 --- a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/components/fields/UseWget.js +++ /dev/null @@ -1,36 +0,0 @@ -import React from 'react'; -import PropTypes from 'prop-types'; - -import { FormGroup, Checkbox } from '@patternfly/react-core'; -import LabelIcon from '../../../../../components/common/LabelIcon'; - -import { translate as __ } from '../../../../../common/I18n'; - -const UseWget = ({ useWget, handleUseWget, isLoading }) => ( - - - {__('Use wget')}{' '} - - - } - id="reg_use_wget" - onChange={() => handleUseWget(!useWget)} - isDisabled={isLoading} - isChecked={useWget} - /> - -); - -UseWget.propTypes = { - useWget: PropTypes.bool.isRequired, - handleUseWget: PropTypes.func.isRequired, - isLoading: PropTypes.bool.isRequired, -}; - -export default UseWget; diff --git a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/index.js b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/index.js index 7197533fa05f..98b8890d8822 100644 --- a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/index.js +++ b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/index.js @@ -46,6 +46,7 @@ import Advanced from './components/Advanced'; import Actions from './components/Actions'; import Command from './components/Command'; import './RegistrationCommandsPage.scss'; +import { DownloadUtilities } from './components/fields/DownloadUtility'; const RegistrationCommandsPage = () => { const dispatch = useDispatch(); @@ -91,7 +92,7 @@ const RegistrationCommandsPage = () => { const [repo, setRepo] = useState(''); const [repoGpgKeyUrl, setRepoGpgKeyUrl] = useState(''); const [invalidFields, setInvalidFields] = useState([]); - const [useWget, setUseWget] = useState(false); + const [downloadUtility, setDownloadUtility] = useState(DownloadUtilities.curl); // Command const command = useSelector(selectCommand); @@ -133,7 +134,7 @@ const RegistrationCommandsPage = () => { repo, repoGpgKeyUrl, updatePackages, - useWget, + downloadUtility, ...pluginValues, }; @@ -267,8 +268,8 @@ const RegistrationCommandsPage = () => { handleInvalidField={handleInvalidField} invalidFields={invalidFields} isLoading={isLoading} - useWget={useWget} - handleUseWget={setUseWget} + downloadUtility={downloadUtility} + handleDownloadUtility={setDownloadUtility} />