Skip to content

Commit

Permalink
redo tokens again
Browse files Browse the repository at this point in the history
  • Loading branch information
tylern4 committed Apr 21, 2022
1 parent fbba9a5 commit 095a121
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions python/SuperfacilityAPI/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ def __init__(self, client_id: str = None, private_key: str = None, key_path: str

@property
def token(self):
# If key is older than 5 minutes renew
if self.access_token is not None and (datetime.now() - self.__token_time).seconds > (5*60):
self.__renew_token()
if self.session is not None:
print(f"Getting new token", file=sys.stderr)
self.access_token = self.session.fetch_token()['access_token']

return self.access_token

Expand Down Expand Up @@ -104,7 +104,7 @@ def __renew_token(self):
pkey = self.private_key
else:
# If no private key don't look for getting a token
return
return None

self.session = OAuth2Session(
cid, # client_id
Expand All @@ -119,7 +119,7 @@ def __renew_token(self):
except OAuthError as e:
print(
f"Oauth error {e}\nMake sure your api key is still active in iris.nersc.gov", file=sys.stderr)
exit(2)
return None


class SuperfacilityAPI:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
author_email="[email protected]",
packages=['SuperfacilityAPI'],
package_dir={'': 'python'},
version='0.1.2',
version='0.1.3',
scripts=['python/SuperfacilityAPI/bin/sfapi'],
install_requires=install_requires,
classifiers=[
Expand Down

0 comments on commit 095a121

Please sign in to comment.