Diff
1diff --git a/plugins/aws/aws.plugin.zsh b/plugins/aws/aws.plugin.zsh
2index ef435fe3b30cead5bc403386770cf49f6f5f4182..e1566b1133c1063d06d2447372ff9ca4f7a5e7f4 100644
3--- a/plugins/aws/aws.plugin.zsh
4+++ b/plugins/aws/aws.plugin.zsh
5@@ -50,32 +50,39 @@ function acp() {
6
7 # First, if the profile has MFA configured, lets get the token and session duration
8 local mfa_serial="$(aws configure get mfa_serial --profile $profile)"
9+ local sess_duration="$(aws configure get duration_seconds --profile $profile)"
10
11 if [[ -n "$mfa_serial" ]]; then
12 local -a mfa_opt
13- local mfa_token sess_duration
14+ local mfa_token
15 echo -n "Please enter your MFA token for $mfa_serial: "
16 read -r mfa_token
17- echo -n "Please enter the session duration in seconds (900-43200; default: 3600, which is the default maximum for a role): "
18- read -r sess_duration
19+ if [[ -z "$sess_duration" ]]; then
20+ echo -n "Please enter the session duration in seconds (900-43200; default: 3600, which is the default maximum for a role): "
21+ read -r sess_duration
22+ fi
23 mfa_opt=(--serial-number "$mfa_serial" --token-code "$mfa_token" --duration-seconds "${sess_duration:-3600}")
24
25 # Now see whether we need to just MFA for the current role, or assume a different one
26 local role_arn="$(aws configure get role_arn --profile $profile)"
27+ local sess_name="$(aws configure get role_session_name --profile $profile)"
28
29 if [[ -n "$role_arn" ]]; then
30 # Means we need to assume a specified role
31 aws_command=(aws sts assume-role --role-arn "$role_arn" "${mfa_opt[@]}")
32
33 # Check whether external_id is configured to use while assuming the role
34- local external_id="$(aws configure get external_id --profile "$profile")"
35+ local external_id="$(aws configure get external_id --profile $profile)"
36 if [[ -n "$external_id" ]]; then
37 aws_command+=(--external-id "$external_id")
38 fi
39
40 # Get source profile to use to assume role
41- local source_profile="$(aws configure get source_profile --profile "$profile")"
42- aws_command+=(--profile="${source_profile:-profile}" --role-session-name "${source_profile:-profile}")
43+ local source_profile="$(aws configure get source_profile --profile $profile)"
44+ if [[ -z "$sess_name" ]]; then
45+ sess_name="${source_profile:-profile}"
46+ fi
47+ aws_command+=(--profile="${source_profile:-profile}" --role-session-name "${sess_name}")
48
49 echo "Assuming role $role_arn using profile ${source_profile:-profile}"
50 else
51@@ -122,13 +129,13 @@ function aws_change_access_key() {
52 return 1
53 fi
54
55- echo Insert the credentials when asked.
56+ echo "Insert the credentials when asked."
57 asp "$1" || return 1
58 AWS_PAGER="" aws iam create-access-key
59 AWS_PAGER="" aws configure --profile "$1"
60
61- echo You can now safely delete the old access key running \`aws iam delete-access-key --access-key-id ID\`
62- echo Your current keys are:
63+ echo "You can now safely delete the old access key running \`aws iam delete-access-key --access-key-id ID\`"
64+ echo "Your current keys are:"
65 AWS_PAGER="" aws iam list-access-keys
66 }
67