3232
3333
3434class AWSRoleSTS :
35- def __init__ (self , role_arn : str , username : str = "" , region : str = None ) -> None :
35+ def __init__ (
36+ self ,
37+ role_arn : str ,
38+ username : str = "" ,
39+ region : str = None ,
40+ duration_seconds : int = 3600 ,
41+ ) -> None :
42+
3643 self .role_arn = role_arn
3744 self .username = username
3845 self .region = region
46+ self .duration_seconds = duration_seconds
3947
40- def oidc_sts (self , jwt_token : str , duration_seconds : int = 3600 ) -> dict :
48+ def oidc_sts (self , jwt_token : str ) -> dict :
4149 """
4250 Returns a boto3 client for OpenID Connect STS (Security Token Service)
4351 """
@@ -49,11 +57,9 @@ def oidc_sts(self, jwt_token: str, duration_seconds: int = 3600) -> dict:
4957 RoleArn = self .role_arn ,
5058 RoleSessionName = self .username or "sts-role-session" ,
5159 WebIdentityToken = jwt_token ,
52- DurationSeconds = duration_seconds ,
60+ DurationSeconds = self . duration_seconds ,
5361 )
5462
55- self .duration_seconds = duration_seconds
56-
5763 if isinstance (self .region , str ) or self .region in aws_regions :
5864 # login based on region if provided
5965 self .response ["Region" ] = self .region
@@ -124,13 +130,23 @@ def quote_plus_function(s):
124130
125131
126132def get_role (
127- token , role : str , username : str = "" , issuer : str = None , region : str = None
133+ token ,
134+ role : str ,
135+ username : str = "" ,
136+ issuer : str = None ,
137+ region : str = None ,
138+ duration_seconds : int = 3600 ,
128139):
129140 """Provide aws sts role access to aws cli or console based on web identity token"""
130141
131142 sts : dict = {}
132143 if isinstance (username , str ) and username != "" :
133- aws_role = AWSRoleSTS (role_arn = role , username = username , region = region )
144+ aws_role = AWSRoleSTS (
145+ role_arn = role ,
146+ username = username ,
147+ region = region ,
148+ duration_seconds = duration_seconds ,
149+ )
134150 else :
135151 aws_role = AWSRoleSTS (role_arn = role )
136152 try :
0 commit comments