Skip to content

Commit

Permalink
add access-key argument to cli
Browse files Browse the repository at this point in the history
  • Loading branch information
redvox committed Apr 4, 2024
1 parent 396ea3e commit c0f6777
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def parse(args):
help='Overwrite region to login to')
parser.add_argument('--set-access-key', action='store_true',
help='set access key')
parser.add_argument('--rotate-access-key', action='store_true',
parser.add_argument('--rotate-access-key',
help='rotate access key')
parser.add_argument('-o', '--oneshot', action='store_true',
help='When used in combination with --login, the program will finish after login instead of running an infinite refresh loop')
Expand Down
16 changes: 11 additions & 5 deletions app/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,23 @@ def logout(self):
logout_result = self.core.logout()
self._check_and_signal_error(logout_result)

def rotate_access_key(self):
rotate_result = self.core.rotate_access_key()
def rotate_access_key(self, key_name):
rotate_result = self.core.rotate_access_key(key_name=key_name, mfa_callback=self.ask_for_mfa_token)
if not self._check_and_signal_error(rotate_result):
return
self._info('key was successfully rotated')

def set_access_key(self):
while True:
key_name = input('Key Name: ')
if not key_name.startswith('access-key'):
self._error('key name must start with \'access-key\'')
else:
break
key_id = getpass(prompt='Key ID: ')
access_key = getpass(prompt='Secret Access Key: ')
self.core.set_access_key(key_id=key_id, key_secret=access_key)
self._info('key was successfully rotated')
key_secret = getpass(prompt='Secret Access Key: ')
self.core.set_access_key(key_name=key_name, key_id=key_id, key_secret=key_secret)
self._info('key was successfully set')

@staticmethod
def ask_for_mfa_token():
Expand Down
2 changes: 1 addition & 1 deletion app/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ def start_cli(args):
if args.logout:
cli.logout()
if args.rotate_access_key:
cli.rotate_access_key()
cli.rotate_access_key(args.rotate_access_key)
if args.set_access_key:
cli.set_access_key()
4 changes: 2 additions & 2 deletions app/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ def _handle_support_files(profile_group: ProfileGroup):
files.write_active_group_file(profile_group.name)

@staticmethod
def set_access_key(key_name: str, key_id: str, access_key: str):
credentials.set_access_key(key_name=key_name, key_id=key_id, key_secret=access_key)
def set_access_key(key_name: str, key_id: str, key_secret: str):
credentials.set_access_key(key_name=key_name, key_id=key_id, key_secret=key_secret)

@staticmethod
def get_access_key_list():
Expand Down
4 changes: 2 additions & 2 deletions app/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def edit_config(self, config: Config):
self.tray_icon.populate_context_menu(self.core.get_profile_group_list())
self._to_reset_state()

def set_access_key(self, key_name, key_id, access_key):
self.core.set_access_key(key_name=key_name, key_id=key_id, access_key=access_key)
def set_access_key(self, key_name, key_id, key_secret):
self.core.set_access_key(key_name=key_name, key_id=key_id, key_secret=key_secret)
self._signal('Success', 'access key was set')

def rotate_access_key(self, key_name: str):
Expand Down

0 comments on commit c0f6777

Please sign in to comment.