Fix updating __AssumeCache while iterating over it

This commit is contained in:
MKLeb 2023-05-31 13:07:41 -04:00 committed by Megan Wilhite
parent 560ab52ccf
commit 219e6fdb1a

View file

@ -8,6 +8,7 @@ This is a base library used by a number of AWS services.
:depends: requests
"""
import copy
import hashlib
import hmac
import logging
@ -230,9 +231,9 @@ def assumed_creds(prov_dict, role_arn, location=None):
# current time in epoch seconds
now = time.mktime(datetime.utcnow().timetuple())
for key, creds in __AssumeCache__.items():
for key, creds in copy.deepcopy(__AssumeCache__).items():
if (creds["Expiration"] - now) <= 120:
__AssumeCache__[key].delete()
del __AssumeCache__[key]
if role_arn in __AssumeCache__:
c = __AssumeCache__[role_arn]