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

Keep original force_classic value during profile inheritance #464

Merged
merged 1 commit into from
May 9, 2024
Merged
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
17 changes: 8 additions & 9 deletions gimme_aws_creds/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,23 +201,22 @@ def _handle_config(self, config, profile_config, include_inherits = True):
profile_config[key] = True
elif profile_config[key] == 'False':
profile_config[key] = False

# Empty string in force_classic should be handled as True - this makes sure that migrating from Classic to OIE is seamless
if profile_config.get('force_classic') == '' or profile_config.get('force_classic') is None:
profile_config['force_classic'] = True

if "inherits" in profile_config.keys() and include_inherits:
self.ui.message("Using inherited config: " + profile_config["inherits"])
if profile_config["inherits"] not in config:
raise errors.GimmeAWSCredsError(self.conf_profile + " inherits from " + profile_config["inherits"] + ", but could not find " + profile_config["inherits"])
combined_config = {
profile_config = {
**self._handle_config(config, dict(config[profile_config["inherits"]])),
**profile_config,
}
del combined_config["inherits"]
return combined_config
else:
return profile_config
del profile_config["inherits"]

# Empty string in force_classic should be handled as True - this makes sure that migrating from Classic to OIE is seamless
if profile_config.get('force_classic') == '' or profile_config.get('force_classic') is None:
profile_config['force_classic'] = True

return profile_config

def get_config_dict(self, include_inherits = True):
"""returns the conf dict from the okta config file"""
Expand Down
29 changes: 29 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,35 @@ def test_read_nested_config_inherited(self):
"force_classic": True
})

def test_read_nested_config_inherited_no_force_classic(self):
"""Test to make sure getting config works when inherited"""
test_ui = MockUserInterface(argv = [
"--profile",
"myprofile",
])
with open(test_ui.HOME + "/.okta_aws_login_config", "w") as config_file:
config_file.write("""
[mybase-level1]
client_id = bar
[mybase-level2]
inherits = mybase-level1
aws_appname = baz
force_classic = False
[myprofile]
inherits = mybase-level2
client_id = foo
aws_rolename = myrole
""")
config = Config(gac_ui=test_ui, create_config=False)
config.conf_profile = "myprofile"
profile_config = config.get_config_dict()
self.assertEqual(profile_config, {
"client_id": "foo",
"aws_appname": "baz",
"aws_rolename": "myrole",
"force_classic": False
})

def test_fail_if_profile_not_found(self):
"""Test to make sure missing Default fails properly"""
test_ui = MockUserInterface(argv=[])
Expand Down