File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 14
14
- Description: Session Token for the current AWS session. Only required if you assume a role first.
15
15
16
16
#### IAM_USERNAME
17
- - Required: *** True ***
18
- - Description: Name of IAM user being rotated
17
+ - Required: *** False ***
18
+ - Description: Name of IAM user being rotated, if not set the username which is used in the AWS credentials is used
19
19
20
20
#### PERSONAL_ACCESS_TOKEN
21
21
- Required: *** True***
Original file line number Diff line number Diff line change 22
22
)
23
23
24
24
def main_function ():
25
- iam_username = os .environ ['IAM_USERNAME' ]
25
+ iam_username = os .environ ['IAM_USERNAME' ] if 'IAM_USERNAME' in os . environ else who_am_i ()
26
26
github_token = os .environ ['PERSONAL_ACCESS_TOKEN' ]
27
27
owner_repository = os .environ ['OWNER_REPOSITORY' ]
28
28
@@ -59,6 +59,19 @@ def main_function():
59
59
60
60
sys .exit (0 )
61
61
62
+ def who_am_i ():
63
+ # ask the aws backend for myself with a boto3 sts client
64
+ sts = boto3 .client (
65
+ 'sts' ,
66
+ aws_access_key_id = os .environ ['AWS_ACCESS_KEY_ID' ],
67
+ aws_secret_access_key = os .environ ['AWS_SECRET_ACCESS_KEY' ],
68
+ aws_session_token = os .environ ['AWS_SESSION_TOKEN' ] if 'AWS_SESSION_TOKEN' in os .environ else None
69
+ )
70
+
71
+ user = sts .get_caller_identity ()
72
+ # return last element of splitted list to get username
73
+ return user ['Arn' ].split ("/" )[- 1 ]
74
+
62
75
def create_new_keys (iam_username ):
63
76
# create the keys
64
77
create_ret = iam .create_access_key (
You can’t perform that action at this time.
0 commit comments