Skip to content
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

fix: Added support for sso-session in aws configure get command #8690

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions awscli/customizations/configure/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,33 @@ def _get_dotted_config_value(self, varname):

# Logic to deal with predefined sections like [preview], [plugin] and
# etc.
# default section type for full_config is profiles, override with sso-sessions if qualified name is an sso-session
section_type = "profiles"
profile_name = None
session_name = None
if num_dots == 1 and parts[0] in PREDEFINED_SECTION_NAMES:
full_config = self._session.full_config
section, config_name = varname.split('.')
value = full_config.get(section, {}).get(config_name)
if value is None:
# Try to retrieve it from the profile config.
value = full_config['profiles'].get(
value = full_config[section_type].get(
section, {}).get(config_name)
return value

if parts[0] == 'profile':
profile_name = parts[1]
config_name = parts[2]
remaining = parts[3:]
elif parts[0] == 'sso-session':
section_type = "sso-sessions"
session_name = parts[1]
config_name = parts[2]
remaining = parts[3:]
# Check if varname starts with 'default' profile (e.g.
# default.emr-dev.emr.instance_profile) If not, go further to check
# if varname starts with a known profile name
elif parts[0] == 'default' or (
parts[0] in self._session.full_config['profiles']):
parts[0] in self._session.full_config[section_type]):
profile_name = parts[0]
config_name = parts[1]
remaining = parts[2:]
Expand All @@ -104,9 +112,9 @@ def _get_dotted_config_value(self, varname):
profile_name = 'default'
config_name = parts[0]
remaining = parts[1:]

value = self._session.full_config['profiles'].get(
profile_name, {}).get(config_name)
section_label = profile_name or session_name
value = self._session.full_config[section_type].get(
section_label, {}).get(config_name)
if len(remaining) == 1:
try:
value = value.get(remaining[-1])
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/customizations/configure/test_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ def test_get_from_profile(self):
rendered = stream.getvalue()
self.assertEqual(rendered.strip(), 'access_key')

def test_get_from_session(self):
"""Validate config items from an sso-session can be read."""
session = FakeSession({})
session.full_config = {
'sso-sessions': {'testing-sso': {'sso_start_url': 'https://dummy-sso-url'}}}
stream, error_stream, config_get = self.create_command(session)
config_get = ConfigureGetCommand(session, stream)
config_get(args=['sso-session.testing-sso.sso_start_url'],
parsed_globals=None)
rendered = stream.getvalue()
self.assertEqual(rendered.strip(), 'https://dummy-sso-url')


def test_get_nested_attribute(self):
session = FakeSession({})
session.full_config = {
Expand Down