From 88445b5a2c881a18559e23c4b3351a0eaecea810 Mon Sep 17 00:00:00 2001 From: Noam Cohen Date: Wed, 8 May 2024 22:54:54 +0300 Subject: [PATCH] Keep original `force_classic` value during profile inheritance --- gimme_aws_creds/config.py | 17 ++++++++--------- tests/test_config.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/gimme_aws_creds/config.py b/gimme_aws_creds/config.py index fe541d3..b5a881b 100644 --- a/gimme_aws_creds/config.py +++ b/gimme_aws_creds/config.py @@ -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""" diff --git a/tests/test_config.py b/tests/test_config.py index fc1390f..d327c85 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -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=[])