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 11, 2023
1 parent d48325f commit f2d2d08
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 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, String, desc: N_("Expiration of the authorization token (in hours)")
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,14 @@ 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'
if /^-?\d+\.?\d*$/.match?(registration_params['jwt_expiration'].to_s)
jwt_args[:expiration] = registration_params['jwt_expiration'].to_i.hours.to_i
elsif registration_params['jwt_expiration'] != 'unlimited'
raise ArgumentError, _("Error: Option --jwt-expiration: Numeric value is required.")
end
else
jwt_args[:expiration] = 4.hours.to_i
end

"-H 'Authorization: Bearer #{User.current.jwt_token!(**jwt_args)}'"
end

Expand Down

0 comments on commit f2d2d08

Please sign in to comment.