From 0bb59c73084a3616328122f7caeb4bcb63a0784e Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Tue, 12 May 2020 13:17:12 +0200 Subject: [PATCH] add expires timestamp to the BasicAuth object --- CHANGELOG.md | 4 ++-- corenetworks/authenticators.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0c6dd3..4304910 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,2 @@ -* BUGFIX - * extend the workaround to ensure CNAME records could not mixed with other types using the same name +* ENHANCEMENT + * add `expires` timestamp to the BasicAuth object diff --git a/corenetworks/authenticators.py b/corenetworks/authenticators.py index a09dd16..ec7455b 100644 --- a/corenetworks/authenticators.py +++ b/corenetworks/authenticators.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- """Custom authenticators.""" +import datetime import json from requests import ConnectionError @@ -19,7 +20,7 @@ class CoreNetworksBasicAuth(AuthBase): self.user = user self.password = password self.endpoint = endpoint - self.token = self._login() + self.token, self.expires = self._login() def __eq__(self, other): # noqa return all([ @@ -60,8 +61,10 @@ class CoreNetworksBasicAuth(AuthBase): raise response = handle.json() + token = response["token"] + expires = datetime.datetime.now() + datetime.timedelta(seconds=response["expires"]) - return response["token"] + return token, expires class CoreNetworksTokenAuth(AuthBase):