@@ -125,8 +125,10 @@ def display_pacu_help():
125
125
supply --all to import all the credentials in the file.
126
126
delete_keys Delete a set of AWS keys in the current session from the Pacu database
127
127
assume_role <role arn> Call AssumeRole on the specified role from the current
128
- credentials, add the resulting temporary keys to the Pacu
128
+ [<serial arn>] [<token code>] credentials, add the resulting temporary keys to the Pacu
129
129
key database and start using these new credentials.
130
+ Optionally you can provide serial number arn and token code
131
+ in case MFA is required to assume the role
130
132
export_keys Export the active credentials to a profile in the AWS CLI
131
133
credentials file (~/.aws/credentials)
132
134
sessions/list_sessions List all sessions in the Pacu database
@@ -612,7 +614,7 @@ def parse_command(self, command):
612
614
elif command [0 ] == 'import_keys' :
613
615
self .parse_awscli_keys_import (command )
614
616
elif command [0 ] == 'assume_role' :
615
- self .assume_role (command [ 1 ] )
617
+ self .assume_role (command )
616
618
elif command [0 ] == 'list' or command [0 ] == 'ls' :
617
619
self .parse_list_command (command )
618
620
elif command [0 ] == 'load_commands_file' :
@@ -1078,8 +1080,9 @@ def display_command_help(self, command_name: str) -> None:
1078
1080
'current sessions database. Enter the name of a profile you would like to import or supply --all to import all the credentials in the '
1079
1081
'file. No argument will import the default system AWS credentials.\n ' )
1080
1082
elif command_name == 'assume_role' :
1081
- print ('\n assume_role <role arn>\n Call AssumeRole on the specified role from the current credentials, add the resulting temporary '
1082
- 'keys to the Pacu key database and start using these new credentials.' )
1083
+ print ('\n assume_role <role arn> [<serial arn>] [<token code>]\n Call AssumeRole on the specified role from the current credentials, '
1084
+ 'add the resulting temporary keys to the Pacu key database and start using these new credentials.'
1085
+ 'Optionally you can provide serial number arn and token code in case MFA is required to assume the role' )
1083
1086
elif command_name == 'aws' :
1084
1087
print ('\n aws <command>\n Use the AWS CLI directly. This command runs in your local shell to use the AWS CLI. Warning: The AWS CLI\' s '
1085
1088
'authentication is not related to Pacu. Be careful to ensure that you are using the keys you want when using the AWS CLI. It is suggested '
@@ -1974,11 +1977,30 @@ def run(self) -> None:
1974
1977
else :
1975
1978
self .run_gui (args .quiet )
1976
1979
1977
- def assume_role (self , role_arn : str ):
1980
+ def assume_role (self , command : list [str ]):
1981
+ if len (command ) == 1 :
1982
+ print ("No role ARN provided" )
1983
+ return
1984
+
1985
+ role_arn = command [1 ]
1986
+ mfa = {}
1987
+
1988
+ if len (command ) == 3 :
1989
+ print ('Invalid number of arguments.' )
1990
+ self .display_command_help (command [0 ])
1991
+ return
1992
+
1993
+ if len (command ) == 4 :
1994
+ mfa = {
1995
+ "SerialNumber" : command [2 ],
1996
+ "TokenCode" : command [3 ]
1997
+ }
1998
+
1978
1999
sts = self .get_boto3_client ('sts' )
1979
2000
resp = sts .assume_role (
1980
2001
RoleArn = role_arn ,
1981
2002
RoleSessionName = 'assume-role' ,
2003
+ ** mfa
1982
2004
)
1983
2005
cur_key_name = self .get_active_session ().name
1984
2006
new_key_name = f"{ cur_key_name } /{ resp ['AssumedRoleUser' ]['Arn' ]} "
0 commit comments