Skip to content

Commit 97226f3

Browse files
authored
Merge pull request #495 from its-mirus-lu/feat/select-all-option
Feature: Implement the ability to select all roles in the role selection screen with "a" or "all"
2 parents 4515c88 + f0041bf commit 97226f3

2 files changed

Lines changed: 39 additions & 20 deletions

File tree

gimme_aws_creds/main.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -420,25 +420,30 @@ def _get_user_int_selections_many(self, min_int, max_int, max_retries=5):
420420
for _ in range(max_retries):
421421
selections = set()
422422
error = False
423+
input_values = self.ui.input('Selections (comma separated; specify "A" for all profiles): ').lower().split(',')
423424

424-
for value in self.ui.input('Selections (comma separated): ').split(','):
425-
value = value.strip()
426-
427-
if not value:
428-
continue
429-
430-
try:
431-
selection = int(value)
432-
except ValueError:
433-
self.ui.warning('Invalid selection {}, must be an integer value.'.format(repr(value)))
434-
error = True
435-
continue
436-
437-
if min_int <= selection <= max_int:
438-
selections.add(value)
439-
else:
440-
self.ui.warning(
441-
'Selection {} out of range <{}, {}>'.format(repr(selection), min_int, max_int))
425+
if 'a' in input_values or 'all' in input_values:
426+
selections = set(range(min_int, max_int+1))
427+
self.ui.message("Generating credentials for profile indices {} to {} ".format(min_int, max_int))
428+
else:
429+
for value in input_values:
430+
value = value.strip()
431+
432+
if not value:
433+
continue
434+
435+
try:
436+
selection = int(value)
437+
except ValueError:
438+
self.ui.warning('Invalid selection {}, must be an integer value, or "A" for all profiles'.format(repr(value)))
439+
error = True
440+
continue
441+
442+
if min_int <= selection <= max_int:
443+
selections.add(value)
444+
else:
445+
self.ui.warning(
446+
'Selection {} out of range <{}, {}>'.format(repr(selection), min_int, max_int))
442447

443448
if error:
444449
continue

tests/test_main.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,26 @@ def test_choose_roles_app_2(self, mock):
4747
self.assertRaises(errors.GimmeAWSCredsExitBase, creds._choose_roles, self.APP_INFO)
4848
self.assertRaises(errors.GimmeAWSCredsExitBase, creds._choose_app, self.AWS_INFO)
4949

50-
@patch('builtins.input', return_value='a')
51-
def test_choose_roles_app_a(self, mock):
50+
@patch('builtins.input', return_value='b')
51+
def test_choose_roles_app_b(self, mock):
5252
creds = GimmeAWSCreds()
5353
self.assertRaises(errors.GimmeAWSCredsExitBase, creds._choose_roles, self.APP_INFO)
5454
self.assertRaises(errors.GimmeAWSCredsExitBase, creds._choose_app, self.AWS_INFO)
5555

56+
@patch('builtins.input', return_value='all')
57+
def test_choose_roles_app_select_all(self, mock):
58+
creds = GimmeAWSCreds()
59+
selections = creds._choose_roles(self.APP_INFO)
60+
expected_selections = {self.APP_INFO[0].role, self.APP_INFO[1].role}
61+
self.assertEqual(selections, expected_selections)
62+
63+
@patch('builtins.input', return_value='a')
64+
def test_choose_roles_app_select_all_a(self, mock):
65+
creds = GimmeAWSCreds()
66+
selections = creds._choose_roles(self.APP_INFO)
67+
expected_selections = {self.APP_INFO[0].role, self.APP_INFO[1].role}
68+
self.assertEqual(selections, expected_selections)
69+
5670
def test_get_selected_app_from_config_0(self):
5771
creds = GimmeAWSCreds()
5872

0 commit comments

Comments
 (0)