0
0
mirror of https://github.com/thegeeklab/corenetworks.git synced 2024-06-02 16:59:41 +02:00

add expires timestamp to the BasicAuth object

This commit is contained in:
Robert Kaussow 2020-05-12 13:17:12 +02:00
parent f2d705a994
commit 0bb59c7308
2 changed files with 7 additions and 4 deletions

View File

@ -1,2 +1,2 @@
* BUGFIX * ENHANCEMENT
* extend the workaround to ensure CNAME records could not mixed with other types using the same name * add `expires` timestamp to the BasicAuth object

View File

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
"""Custom authenticators.""" """Custom authenticators."""
import datetime
import json import json
from requests import ConnectionError from requests import ConnectionError
@ -19,7 +20,7 @@ class CoreNetworksBasicAuth(AuthBase):
self.user = user self.user = user
self.password = password self.password = password
self.endpoint = endpoint self.endpoint = endpoint
self.token = self._login() self.token, self.expires = self._login()
def __eq__(self, other): # noqa def __eq__(self, other): # noqa
return all([ return all([
@ -60,8 +61,10 @@ class CoreNetworksBasicAuth(AuthBase):
raise raise
response = handle.json() response = handle.json()
token = response["token"]
expires = datetime.datetime.now() + datetime.timedelta(seconds=response["expires"])
return response["token"] return token, expires
class CoreNetworksTokenAuth(AuthBase): class CoreNetworksTokenAuth(AuthBase):