Skip to content

Commit

Permalink
Merge pull request #464 from noamcohen97/fix-default-force-classic
Browse files Browse the repository at this point in the history
Keep original `force_classic` value during profile inheritance
  • Loading branch information
epierce authored May 9, 2024
2 parents 763ae83 + 88445b5 commit 76c2257
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
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

0 comments on commit 76c2257

Please sign in to comment.