Skip to content

Commit 1eb6c1d

Browse files
committed
feat(ApiAuth): reduce probability of token expiry moments after retrieval
1 parent fa64970 commit 1eb6c1d

3 files changed

Lines changed: 8678 additions & 11213 deletions

File tree

staxapp/auth.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/local/bin/python3
2-
from datetime import datetime, timezone
2+
from datetime import datetime, timedelta, timezone
33

44
import boto3
55
from aws_requests_auth.aws_auth import AWSRequestsAuth
@@ -139,7 +139,10 @@ def requests_auth(username, password, **kwargs):
139139
class ApiTokenAuth:
140140
@staticmethod
141141
def requests_auth(username, password, **kwargs):
142-
if StaxConfig.expiration and StaxConfig.expiration > datetime.now(timezone.utc):
142+
# Minimize the potentical for token to expire while still being used for auth (say within a lambda function)
143+
if StaxConfig.expiration and StaxConfig.expiration - timedelta(
144+
minutes=10
145+
) > datetime.now(timezone.utc):
143146
return StaxConfig.auth
144147

145148
return StaxAuth("ApiAuth").requests_auth(username, password, **kwargs)

0 commit comments

Comments
 (0)