Skip to content

Commit

Permalink
Fixes #36972 - Make hammer accept unlimited as JWT life time
Browse files Browse the repository at this point in the history
  • Loading branch information
girijaasoni committed Dec 19, 2023
1 parent 70b2144 commit 7a45ce4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v2/registration_commands_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 7a45ce4

Please sign in to comment.