@@ -123,6 +123,7 @@ def display_pacu_help():
123
123
at ~/.aws/credentials) to the current sessions database.
124
124
Enter the name of a profile you would like to import or
125
125
supply --all to import all the credentials in the file.
126
+ delete_keys Delete a set of AWS keys in the current session from the Pacu database
126
127
assume_role <role arn> Call AssumeRole on the specified role from the current
127
128
credentials, add the resulting temporary keys to the Pacu
128
129
key database and start using these new credentials.
@@ -184,7 +185,7 @@ def get_data_from_traceback(tb) -> Tuple[Optional[PacuSession], List[str], List[
184
185
185
186
class Main :
186
187
COMMANDS = [
187
- 'assume_role' , 'aws' , 'console' , 'data' , 'delete_session' , 'exec' , 'exit' , 'export_keys' , 'help' ,
188
+ 'assume_role' , 'aws' , 'console' , 'data' , 'delete_keys' , ' delete_session' , 'exec' , 'exit' , 'export_keys' , 'help' ,
188
189
'history' , 'import_keys' , 'list' , 'list_sessions' , 'load_commands_file' , 'ls' , 'open_console' , 'quit' ,
189
190
'regions' , 'run' , 'search' , 'services' , 'sessions' , 'set_keys' , 'set_regions' , 'set_ua_suffix' ,
190
191
'swap_keys' , 'swap_session' , 'unset_ua_suffix' , 'update_regions' , 'use' , 'whoami' , 'debug'
@@ -600,6 +601,8 @@ def parse_command(self, command):
600
601
self .check_sessions (command )
601
602
elif command [0 ] == 'delete_session' :
602
603
self .delete_session ()
604
+ elif command [0 ] == 'delete_keys' :
605
+ self .delete_keys ()
603
606
elif command [0 ] == 'export_keys' :
604
607
self .export_keys (command )
605
608
elif command [0 ] == 'help' :
@@ -1122,6 +1125,8 @@ def display_command_help(self, command_name: str) -> None:
1122
1125
print ('\n set_keys\n Add a set of AWS keys to the session and set them as the default\n ' )
1123
1126
elif command_name == 'swap_keys' :
1124
1127
print ('\n swap_keys\n Change the currently active AWS key to another key that has previously been set for this session\n ' )
1128
+ elif command_name == 'delete_keys' :
1129
+ print ('\n delete_keys\n Delete a set of AWS keys in the current session from the Pacu database\n ' )
1125
1130
elif command_name == 'exit' or command_name == 'quit' :
1126
1131
print ('\n exit/quit\n Exit Pacu\n ' )
1127
1132
elif command_name == 'load_commands_file' :
@@ -1358,6 +1363,35 @@ def swap_keys(self, key_name: str = None) -> None:
1358
1363
self .database .commit ()
1359
1364
self .print ('AWS key is now {}.' .format (session .key_alias ))
1360
1365
1366
+ def delete_keys (self ) -> None :
1367
+ active_session = self .get_active_session ()
1368
+ all_keys = self .database .query (AWSKey ).filter (AWSKey .session_id == active_session .id ).all ()
1369
+ print ('Delete which key set?' )
1370
+
1371
+ for index , key in enumerate (all_keys , 0 ):
1372
+ if key .key_alias == active_session .key_alias :
1373
+ print (' [{}] {} (ACTIVE)' .format (index , key .key_alias ))
1374
+ else :
1375
+ print (' [{}] {}' .format (index , key .key_alias ))
1376
+
1377
+ choice = input ('Choose an option: ' )
1378
+
1379
+ try :
1380
+ key = all_keys [int (choice )]
1381
+ if key .key_alias == active_session .key_alias :
1382
+ print ('Cannot delete the active keys! Switch keys and try again.' )
1383
+ return
1384
+ except (ValueError , IndexError ):
1385
+ print ('Please choose a number from 0 to {}.' .format (len (all_keys ) - 1 ))
1386
+ return self .delete_keys ()
1387
+
1388
+ self .database .delete (key )
1389
+ self .database .commit ()
1390
+
1391
+ print ('Deleted {} from the database!' .format (key .key_alias ))
1392
+
1393
+ return
1394
+
1361
1395
def activate_session (self , session_name ) -> None :
1362
1396
sessions = self .database .query (PacuSession ).all ()
1363
1397
found_session = False
0 commit comments