Skip to content

Commit

Permalink
Merge pull request #222 from frspfpt/preserve-inherits
Browse files Browse the repository at this point in the history
Do not write inheritance to config file. Should fix #221
  • Loading branch information
Sector95 authored Oct 13, 2020
2 parents 35655b9 + 746d103 commit 18d0a75
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions gimme_aws_creds/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ def get_args(self):
self.roles = [role.strip() for role in args.roles.split(',') if role.strip()]
self.conf_profile = args.profile or 'DEFAULT'

def _handle_config(self, config, profile_config):
if "inherits" in profile_config.keys():
def _handle_config(self, config, profile_config, include_inherits = True):
if "inherits" in profile_config.keys() and include_inherits:
print("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"])
Expand All @@ -181,7 +181,7 @@ def _handle_config(self, config, profile_config):
else:
return profile_config

def get_config_dict(self):
def get_config_dict(self, include_inherits = True):
"""returns the conf dict from the okta config file"""
# Check to see if config file exists, if not complain and exit
# If config file does exist return config dict from file
Expand All @@ -191,7 +191,7 @@ def get_config_dict(self):

try:
profile_config = dict(config[self.conf_profile])
return self._handle_config(config, profile_config)
return self._handle_config(config, profile_config, include_inherits)
except KeyError:
raise errors.GimmeAWSCredsError(
'Configuration profile not found! Use the --action-configure flag to generate the profile.')
Expand Down
7 changes: 4 additions & 3 deletions gimme_aws_creds/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,9 +850,10 @@ def handle_action_register_device(self):
self.ui.notify('*** You may be prompted for MFA more than once for this run.\n')

auth_result = self.auth_session
self.conf_dict['device_token'] = auth_result['device_token']
self.config.write_config_file(self.conf_dict)
self.okta.device_token = self.conf_dict['device_token']
base_config = self.config.get_config_dict(include_inherits = False)
base_config['device_token'] = auth_result['device_token']
self.config.write_config_file(base_config)
self.okta.device_token = base_config['device_token']

self.ui.notify('\nDevice token saved!\n')

Expand Down

0 comments on commit 18d0a75

Please sign in to comment.