-
Notifications
You must be signed in to change notification settings - Fork 995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #36972 - Make hammer accept unlimited as JWT life time #9951
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,6 +3,10 @@ module Foreman::Controller::RegistrationCommands | |||||
|
||||||
private | ||||||
|
||||||
MIN_VALUE = 0 | ||||||
MAX_VALUE = 999999 | ||||||
DEFAULT_VALUE = 4 | ||||||
|
||||||
def command | ||||||
args_query = "?#{registration_args.to_query}" | ||||||
"curl -sS #{insecure} '#{registration_url(@smart_proxy)}#{args_query if args_query != '?'}' #{command_headers} | bash" | ||||||
|
@@ -27,17 +31,40 @@ def registration_url(proxy = nil) | |||||
"#{url}/register" | ||||||
end | ||||||
|
||||||
def invalid_expiration_error | ||||||
raise ::Foreman::Exception.new(N_("Invalid value '%s' for jwt_expiration. The value must be between %s and %s. 0 means 'unlimited'."), registration_params['jwt_expiration'], MIN_VALUE, MAX_VALUE) | ||||||
end | ||||||
|
||||||
def jwt_expiration_param | ||||||
param = registration_params['jwt_expiration'] || DEFAULT_VALUE | ||||||
@jwt_expiration_param ||= begin | ||||||
if param == 'unlimited' | ||||||
0 | ||||||
elsif Float(param, exception: false) | ||||||
param.to_i | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This implementation will not fail validation of strings other than Since you have to accept decimal values, you can still have it validated:
Suggested change
This will accept |
||||||
else | ||||||
invalid_expiration_error | ||||||
end | ||||||
end | ||||||
end | ||||||
|
||||||
def expiration_unlimited? | ||||||
jwt_expiration_param == 0 | ||||||
end | ||||||
|
||||||
def expiration_valid? | ||||||
jwt_expiration_param.between?(MIN_VALUE, MAX_VALUE) | ||||||
end | ||||||
|
||||||
def command_headers | ||||||
jwt_args = { | ||||||
scope: [{ controller: :registration, actions: [:global, :host] }], | ||||||
} | ||||||
|
||||||
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 expiration_valid? | ||||||
jwt_args[:expiration] = jwt_expiration_param.hours.to_i unless expiration_unlimited? | ||||||
else | ||||||
jwt_args[:expiration] = 4.hours.to_i | ||||||
invalid_expiration_error | ||||||
end | ||||||
|
||||||
"-H 'Authorization: Bearer #{User.current.jwt_token!(**jwt_args)}'" | ||||||
end | ||||||
|
||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This broke translations:
I think this is because you can only use
%s
once. More than that and it becomes ambiguous.#10176