diff --git a/app/controllers/api/v2/registration_commands_controller.rb b/app/controllers/api/v2/registration_commands_controller.rb index 8c8bb6984a9e..992d1a5297cb 100644 --- a/app/controllers/api/v2/registration_commands_controller.rb +++ b/app/controllers/api/v2/registration_commands_controller.rb @@ -15,7 +15,7 @@ class RegistrationCommandsController < V2::BaseController param :smart_proxy_id, :number, desc: N_("ID of the Smart Proxy. This Proxy must have enabled both the 'Templates' and 'Registration' features") param :setup_insights, :bool, desc: N_("Set 'host_registration_insights' parameter for the host. If it is set to true, insights client will be installed and registered on Red Hat family operating systems") 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 :jwt_expiration, :number, desc: N_("Expiration of the authorization token (in hours)") + param :jwt_expiration, :number, desc: N_("Expiration of the authorization token (in hours), -1 means 'unlimited'.") 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") diff --git a/app/controllers/concerns/foreman/controller/registration_commands.rb b/app/controllers/concerns/foreman/controller/registration_commands.rb index 6db3b94a31ab..773b206e9ca2 100644 --- a/app/controllers/concerns/foreman/controller/registration_commands.rb +++ b/app/controllers/concerns/foreman/controller/registration_commands.rb @@ -33,11 +33,13 @@ def command_headers } if registration_params['jwt_expiration'].present? - jwt_args[:expiration] = registration_params['jwt_expiration'].to_i.hours.to_i if registration_params['jwt_expiration'] != 'unlimited' + jwt_args[:expiration] = registration_params['jwt_expiration'].to_i.hours.to_i if registration_params['jwt_expiration'] != 'unlimited' && registration_params['jwt_expiration'].to_i != -1 + if registration_params['jwt_expiration'].to_i < -1 + raise ArgumentError, _("Error: Option --jwt-expiration: The value must be between -1 to 999999 hours. -1 means 'unlimited'.") + end else jwt_args[:expiration] = 4.hours.to_i end - "-H 'Authorization: Bearer #{User.current.jwt_token!(**jwt_args)}'" end diff --git a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/components/fields/TokenLifeTime.js b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/components/fields/TokenLifeTime.js index bc57af5a3ce6..a3f9e2052745 100644 --- a/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/components/fields/TokenLifeTime.js +++ b/webpack/assets/javascripts/react_app/routes/RegistrationCommands/RegistrationCommandsPage/components/fields/TokenLifeTime.js @@ -14,7 +14,7 @@ import LabelIcon from '../../../../../components/common/LabelIcon'; import { sprintf, translate as __ } from '../../../../../common/I18n'; const TokenLifeTime = ({ value, onChange, handleInvalidField, isLoading }) => { - const minValue = 1; + const minValue = 0; const maxValue = 999999; const isValid = v => {