@@ -312,6 +312,7 @@ class Credentials:
312
312
:param str token: The security token, valid only for session credentials.
313
313
:param str method: A string which identifies where the credentials
314
314
were found.
315
+ :param str account_id: (optional) An account ID associated with the credentials.
315
316
"""
316
317
317
318
def __init__ (
@@ -1118,6 +1119,7 @@ class EnvProvider(CredentialProvider):
1118
1119
# AWS_SESSION_TOKEN is what other AWS SDKs have standardized on.
1119
1120
TOKENS = ['AWS_SECURITY_TOKEN' , 'AWS_SESSION_TOKEN' ]
1120
1121
EXPIRY_TIME = 'AWS_CREDENTIAL_EXPIRATION'
1122
+ ACCOUNT_ID = 'AWS_ACCOUNT_ID'
1121
1123
1122
1124
def __init__ (self , environ = None , mapping = None ):
1123
1125
"""
@@ -1127,8 +1129,12 @@ def __init__(self, environ=None, mapping=None):
1127
1129
:param mapping: An optional mapping of variable names to
1128
1130
environment variable names. Use this if you want to
1129
1131
change the mapping of access_key->AWS_ACCESS_KEY_ID, etc.
1130
- The dict can have up to 3 keys: ``access_key``, ``secret_key``,
1131
- ``session_token``.
1132
+ The dict can have up to 5 keys:
1133
+ * ``access_key``
1134
+ * ``secret_key``
1135
+ * ``token``
1136
+ * ``expiry_time``
1137
+ * ``account_id``
1132
1138
"""
1133
1139
if environ is None :
1134
1140
environ = os .environ
@@ -1144,6 +1150,7 @@ def _build_mapping(self, mapping):
1144
1150
var_mapping ['secret_key' ] = self .SECRET_KEY
1145
1151
var_mapping ['token' ] = self .TOKENS
1146
1152
var_mapping ['expiry_time' ] = self .EXPIRY_TIME
1153
+ var_mapping ['account_id' ] = self .ACCOUNT_ID
1147
1154
else :
1148
1155
var_mapping ['access_key' ] = mapping .get (
1149
1156
'access_key' , self .ACCESS_KEY
@@ -1157,6 +1164,9 @@ def _build_mapping(self, mapping):
1157
1164
var_mapping ['expiry_time' ] = mapping .get (
1158
1165
'expiry_time' , self .EXPIRY_TIME
1159
1166
)
1167
+ var_mapping ['account_id' ] = mapping .get (
1168
+ 'account_id' , self .ACCOUNT_ID
1169
+ )
1160
1170
return var_mapping
1161
1171
1162
1172
def load (self ):
@@ -1181,13 +1191,15 @@ def load(self):
1181
1191
expiry_time ,
1182
1192
refresh_using = fetcher ,
1183
1193
method = self .METHOD ,
1194
+ account_id = credentials ['account_id' ],
1184
1195
)
1185
1196
1186
1197
return Credentials (
1187
1198
credentials ['access_key' ],
1188
1199
credentials ['secret_key' ],
1189
1200
credentials ['token' ],
1190
1201
method = self .METHOD ,
1202
+ account_id = credentials ['account_id' ],
1191
1203
)
1192
1204
else :
1193
1205
return None
@@ -1230,6 +1242,11 @@ def fetch_credentials(require_expiry=True):
1230
1242
provider = method , cred_var = mapping ['expiry_time' ]
1231
1243
)
1232
1244
1245
+ credentials ['account_id' ] = None
1246
+ account_id = environ .get (mapping ['account_id' ], '' )
1247
+ if account_id :
1248
+ credentials ['account_id' ] = account_id
1249
+
1233
1250
return credentials
1234
1251
1235
1252
return fetch_credentials
0 commit comments