Skip to content

Commit 16cb584

Browse files
authored
Bugfix expired calculation (#37)
* Version 5.2.5 * [bugfix] Calculation within *clientlib.TokenInfo.expired()* now returns *None* as expected when no *expires_at* is available for a token. Previous versions would raise an exception. * *False* instead of *None*
1 parent c20a6e0 commit 16cb584

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# v5.2.5
2+
3+
* [bugfix] Calculation within *clientlib.TokenInfo.expired()* now returns *False* as expected when no *expires_at*
4+
is available for a token. Previous versions would raise an exception.
5+
16
# v5.2.4
27

38
* Merge headers in AbstractAPI instead of replacing them.

src/hiro_graph_client/VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.2.4
1+
5.2.5

src/hiro_graph_client/clientlib.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,6 @@ def _log_communication(self, res: requests.Response, request_body: bool = True,
555555
:param res: The response of a request. Also contains the request.
556556
:param request_body: Option to disable the logging of the request_body.
557557
:param response_body: Option to disable the logging of the response_body.
558-
:return:
559558
"""
560559

561560
def _log_headers(headers) -> str:
@@ -944,6 +943,7 @@ def decode_token(self) -> dict:
944943
"""
945944
Return a dict with the decoded token payload. This payload contains detailed information about what this token
946945
has access to.
946+
947947
:return: The dict with the decoded token payload.
948948
"""
949949
base64_payload: list = self.token.split('.')
@@ -1088,6 +1088,7 @@ def __init__(self, token: str = None, refresh_token: str = None, expires_at: int
10881088
def get_epoch_millis() -> int:
10891089
"""
10901090
Get timestamp
1091+
10911092
:return: Current epoch in milliseconds
10921093
"""
10931094
return int(time.time_ns() / 1000000)
@@ -1129,10 +1130,14 @@ def parse_token_result(self, res: dict, what: str) -> None:
11291130

11301131
def expired(self) -> bool:
11311132
"""
1132-
Check token expiration
1133+
Check token expiration.
11331134
1134-
:return: True when the token has been expired *(expires_at - refresh_offset) <= get_epoch_mills()*
1135+
:return: True when the token has been expired *(expires_at - refresh_offset) <= get_epoch_mills()*. If
1136+
no *expires_at* is available, always return False since this token would never expire.
11351137
"""
1138+
if self.refresh_time() is None:
1139+
return False
1140+
11361141
return self.refresh_time() <= self.get_epoch_millis()
11371142

11381143
def fresh(self, span: int = 30000) -> bool:
@@ -1312,7 +1317,7 @@ def refresh_time(self) -> Optional[int]:
13121317
"""
13131318
Calculate refresh time.
13141319
1315-
:return: Timestamp after which the token becomes invalid.
1320+
:return: Timestamp after which the token becomes invalid. Returns None if token cannot be refreshed.
13161321
"""
13171322
return self._token_info.refresh_time()
13181323

0 commit comments

Comments
 (0)