diff --git a/app/controllers/api/v2/registration_commands_controller.rb b/app/controllers/api/v2/registration_commands_controller.rb index 3497d2d30f6..3fa023dca4d 100644 --- a/app/controllers/api/v2/registration_commands_controller.rb +++ b/app/controllers/api/v2/registration_commands_controller.rb @@ -18,8 +18,11 @@ class RegistrationCommandsController < V2::BaseController param :insecure, :bool, desc: N_("Enable insecure argument for the initial curl") param :packages, String, desc: N_("Packages to install on the host when registered. Can be set by `host_packages` parameter, example: `pkg1 pkg2`") param :update_packages, :bool, desc: N_("Update all packages on the host") + param :repo, String, desc: N_("DEPRECATED, use the `repo_data` param instead."), deprecated: true + param :repo_gpg_key_url, String, desc: N_("DEPRECATED, use the `repo_data` param instead."), deprecated: true + param :repo_data, Array, desc: N_("Array with repository URL and corresponding GPG key URL") do - 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, 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") end end @@ -30,6 +33,10 @@ def create return end + if params[:repo] || params[:repo_gpg_key_url] + Foreman::Deprecation.api_deprecation_warning("Use repo_data parameter instead of repo and repo_gpg_key_url. These will be removed soon.") + end + render json: { registration_command: command } end diff --git a/app/controllers/api/v2/registration_controller.rb b/app/controllers/api/v2/registration_controller.rb index 82dfb40568f..c79b58d8456 100644 --- a/app/controllers/api/v2/registration_controller.rb +++ b/app/controllers/api/v2/registration_controller.rb @@ -23,13 +23,20 @@ class RegistrationController < V2::BaseController param :setup_remote_execution, :bool, desc: N_("Set 'host_registration_remote_execution' parameter for the host. If it is set to true, SSH keys will be installed on the host") param :packages, String, desc: N_("Packages to install on the host when registered. Can be set by `host_packages` parameter, example: `pkg1 pkg2`") param :update_packages, :bool, desc: N_("Update all packages on the host") + param :repo, String, desc: N_("DEPRECATED, use the `repo_data` param instead."), deprecated: true + param :repo_gpg_key_url, String, desc: N_("DEPRECATED, use the `repo_data` param instead."), deprecated: true + param :repo_data, Array, desc: N_("Array with repository URL and corresponding GPG key URL") do - 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 OS family: 'http://yum.theforeman.org/client/latest/el8/x86_64/'") + 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 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") end def global find_global_registration + if params[:repo] || params[:repo_gpg_key_url] + Foreman::Deprecation.api_deprecation_warning("Use repo_data parameter instead of repo and repo_gpg_key_url. These will be removed soon.") + end + unless @provisioning_template not_found _('Global Registration Template with name %s defined via default_global_registration_item Setting not found, please configure the existing template name first') % Setting[:default_global_registration_item] return diff --git a/app/controllers/concerns/foreman/controller/registration.rb b/app/controllers/concerns/foreman/controller/registration.rb index 90f20197a83..0d71e7a15ad 100644 --- a/app/controllers/concerns/foreman/controller/registration.rb +++ b/app/controllers/concerns/foreman/controller/registration.rb @@ -18,9 +18,15 @@ def global_registration_vars location = Location.authorized(:view_locations).find(params['location_id']) if params['location_id'].present? host_group = Hostgroup.authorized(:view_hostgroups).find(params['hostgroup_id']) if params["hostgroup_id"].present? operatingsystem = Operatingsystem.authorized(:view_operatingsystems).find(params['operatingsystem_id']) if params["operatingsystem_id"].present? - if params["repo_data"].present? + + if params['repo'].present? repo_data = {} - params['repo_data'].each { |repo| repo_data[repo['repository']] = repo['repo_gpg_key_url'] } + repo_data[params['repo']] = params['repo_gpg_key_url'] || '' + end + + if params['repo_data'].present? + repo_data = {} unless repo_data.present? + params['repo_data'].each { |repo| repo_data[repo['repo']] = repo['repo_gpg_key_url'] } end context = { 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 3ff06615c0b..27b81b3f410 100644 --- a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/index.js +++ b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/index.js @@ -145,7 +145,7 @@ const RegistrationCommandsPage = () => { repoDataInternal .filter(r => r.repository !== '') .map(repo => ({ - repository: repo.repository, + repo: repo.repository, repo_gpg_key_url: repo.gpgKeyUrl, })) );