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 1414- Description: Session Token for the current AWS session. Only required if you assume a role first.
1515
1616#### 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
1919
2020#### PERSONAL_ACCESS_TOKEN
2121- Required: *** True***
Original file line number Diff line number Diff line change 2222)
2323
2424def 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 ()
2626 github_token = os .environ ['PERSONAL_ACCESS_TOKEN' ]
2727 owner_repository = os .environ ['OWNER_REPOSITORY' ]
2828
@@ -59,6 +59,19 @@ def main_function():
5959
6060 sys .exit (0 )
6161
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+
6275def create_new_keys (iam_username ):
6376 # create the keys
6477 create_ret = iam .create_access_key (
You can’t perform that action at this time.
0 commit comments