-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Handle sso session names with quotes/spaces #2895
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -359,12 +359,8 @@ def sso_credentials_from_profile(cfg, profile) | |
!(prof_config.keys & SSO_CREDENTIAL_PROFILE_KEYS).empty? | ||
|
||
if sso_session_name = prof_config['sso_session'] | ||
sso_session = cfg["sso-session #{sso_session_name}"] | ||
unless sso_session | ||
raise ArgumentError, | ||
"sso-session #{sso_session_name} must be defined in the config file. " \ | ||
"Referenced by profile #{profile}" | ||
end | ||
sso_session = sso_session(cfg, profile, sso_session_name) | ||
|
||
sso_region = sso_session['sso_region'] | ||
sso_start_url = sso_session['sso_start_url'] | ||
|
||
|
@@ -402,16 +398,7 @@ def sso_token_from_profile(cfg, profile) | |
!(prof_config.keys & SSO_TOKEN_PROFILE_KEYS).empty? | ||
|
||
sso_session_name = prof_config['sso_session'] | ||
sso_session = cfg["sso-session #{sso_session_name}"] | ||
unless sso_session | ||
raise ArgumentError, | ||
"sso-session #{sso_session_name} must be defined in the config file." \ | ||
"Referenced by profile #{profile}" | ||
end | ||
|
||
unless sso_session['sso_region'] | ||
raise ArgumentError, "sso-session #{sso_session_name} missing required parameter: sso_region" | ||
end | ||
sso_session = sso_session(cfg, profile, sso_session_name) | ||
|
||
SSOTokenProvider.new( | ||
sso_session: sso_session_name, | ||
|
@@ -469,5 +456,26 @@ def determine_profile(options) | |
ret ||= 'default' | ||
ret | ||
end | ||
|
||
def sso_session(cfg, profile, sso_session_name) | ||
sso_session = cfg["sso-session #{sso_session_name}"] | ||
|
||
if sso_session.nil? && sso_session_name.match(/\s/) | ||
# aws sso-configure may add quotes around sso session names with whitespace | ||
sso_session = cfg["sso-session '#{sso_session_name}'"] | ||
end | ||
|
||
unless sso_session | ||
raise ArgumentError, | ||
"sso-session #{sso_session_name} must be defined in the config file. " \ | ||
"Referenced by profile #{profile}" | ||
end | ||
|
||
unless sso_session['sso_region'] | ||
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.
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. The SSOCredentials will fail if sso_region is unset, so this moves the failure case up to here (with hopefully slightly. more info). |
||
raise ArgumentError, "sso-session #{sso_session_name} missing required parameter: sso_region" | ||
end | ||
|
||
sso_session | ||
end | ||
end | ||
end |
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.
You can possible just add an
|| cfg["sso-session '#{sso_session_name}'"]
aftercfg["sso-session #{sso_session_name}"]
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.
Yeah, we can skip the check for it containing whitespace and always use this check - I think thats reasonable and forwards compatible.