-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from nathan-v/Feature_region_arg
Add region parameter, screen only output option, command wrapper, bug fixes, v0.7.5
- Loading branch information
Showing
11 changed files
with
241 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,9 @@ def __init__(self, argv): | |
self.oktapreview = None | ||
self.password_cache = None | ||
self.password_reset = None | ||
self.command = None | ||
self.screen = None | ||
self.region = None | ||
|
||
if len(argv) > 1: | ||
if argv[1] == 'config': | ||
|
@@ -65,6 +68,9 @@ def validate(self): | |
"or as an argument") | ||
raise ValueError(err) | ||
|
||
if self.region is None: | ||
self.region = 'us-east-1' | ||
|
||
if self.username is None: | ||
user = getpass.getuser() | ||
LOG.info( | ||
|
@@ -166,13 +172,14 @@ def main_args(arg_group, required=False): | |
@staticmethod | ||
def optional_args(optional_args): | ||
"""Define the always-optional arguments.""" | ||
optional_args.add_argument('-u', '--username', type=str, help=( | ||
'Okta Login Name - either ' | ||
'[email protected], or just bob works too,' | ||
' depending on your organization ' | ||
'settings. Will use the current user if not' | ||
'specified.' | ||
)), | ||
optional_args.add_argument('-u', '--username', type=str, | ||
help=( | ||
'Okta Login Name - either ' | ||
'[email protected], or just bob works too,' | ||
' depending on your organization ' | ||
'settings. Will use the current user if ' | ||
'not specified.' | ||
)) | ||
optional_args.add_argument('-a', '--appid', type=str, help=( | ||
'The "redirect link" Application ID - ' | ||
'this can be found by mousing over the ' | ||
|
@@ -228,6 +235,24 @@ def optional_args(optional_args): | |
' if it has changed or is incorrect.' | ||
), | ||
default=False) | ||
optional_args.add_argument('-C', '--command', type=str, | ||
help=( | ||
'Command to run with the requested ' | ||
'AWS keys provided as environment ' | ||
'variables.' | ||
)) | ||
optional_args.add_argument('-s', '--screen', action='store_true', | ||
help=( | ||
'Print the retrieved key ' | ||
'only and do not write to the AWS ' | ||
'credentials file.' | ||
), | ||
default=False) | ||
optional_args.add_argument('-re', '--region', type=str, | ||
help=( | ||
'AWS region to use for calls. ' | ||
'Required for GovCloud.' | ||
)) | ||
|
||
@staticmethod | ||
def read_yaml(filename, raise_on_error=False): | ||
|
@@ -274,14 +299,20 @@ def write_config(self): | |
|
||
LOG.debug("YAML being saved: {}".format(config_out)) | ||
|
||
file_folder = os.path.dirname(os.path.abspath(file_path)) | ||
if not os.path.exists(file_folder): | ||
LOG.debug("Creating missin config file folder : {}".format( | ||
file_folder)) | ||
os.makedirs(file_folder) | ||
|
||
with open(file_path, 'w') as outfile: | ||
yaml.safe_dump(config_out, outfile, default_flow_style=False) | ||
|
||
@staticmethod | ||
def clean_config_for_write(config): | ||
"""Remove args we don't want to save to a config file.""" | ||
ignore = ['name', 'appid', 'argv', 'writepath', 'config', 'debug', | ||
'oktapreview', 'password_reset'] | ||
'oktapreview', 'password_reset', 'command'] | ||
for var in ignore: | ||
del config[var] | ||
|
||
|
@@ -293,7 +324,7 @@ def clean_config_for_write(config): | |
@staticmethod | ||
def user_input(text): | ||
"""Wrap input() making testing support of py2 and py3 easier.""" | ||
return input(text) | ||
return input(text).strip() | ||
|
||
def interactive_config(self): | ||
""" Runs an interactive configuration to make it simpler to create | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.