Check existence of expires_in for auth

If a registries doesn't provide an expires_in with their token, the
current code fails doing the comparison. If no such header is included,
let's assume there is no expire time so we can just use the cached
token.  If the token expires, we'll reauth as usual.

Change-Id: I96ab407ba50e2183141daec3341dbb29545d5beb
Closes-Bug: #1912645
(cherry picked from commit e04774948e)
This commit is contained in:
Alex Schultz 2021-01-21 08:55:45 -07:00
parent 71bc42cf7f
commit 2effe2ff00
1 changed files with 2 additions and 1 deletions

View File

@ -313,7 +313,8 @@ class RegistrySessionHelper(object):
if data and data.get('issued_at'):
token_time = dt_parse(data.get('issued_at'))
now = datetime.now(tzlocal())
if (now - token_time).seconds < data.get('expires_in'):
expires_in = data.get('expires_in')
if not expires_in or (now - token_time).seconds < expires_in:
return data['token']
return None