-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
webapi fixes #277
webapi fixes #277
Conversation
Credential folder only created when needed Maximum attempts in authentication while loops Authentication only called when needed, and checks if already done
tidy3d/web/auth.py
Outdated
user for login info and saves to file.""" | ||
user for login info and saves to file. | ||
|
||
If Config["auth" is already set, returns immediately. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo
So what is the new behavior of this in terms of users? Will it try to log in each web api call? Also, does this print anything to STDOUT each auth call because that could be annoying eg. if Also, can we use log.info instead of print? |
when credential is verified, we can also set values back to env. also the current solution requested unnecessary calls for auth. It is fine for right now. def handle_response(func):
def wrapper(*args, **kwargs):
resp = func(*args, **kwargs)
if resp.status_code == 401 and Config.auth_retry < 1:
getEmailPasswdAuthKey()
Config.auth_retry = Config.auth_retry + 1
resp = func(*args, **kwargs)
elif resp.status_code != 200:
print(resp.content)
resp.raise_for_status()
try:
Config.auth_retry = 0
jsn = resp.json()['data']
except Exception as e:
print('Could not json decode response : {0}!'.format(resp.text))
raise
return jsn
return wrapper |
tidy3d/web/auth.py
Outdated
@@ -3,24 +3,30 @@ | |||
import getpass | |||
import hashlib | |||
import json | |||
import logging |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from ..log import log
tidy3d/web/auth.py
Outdated
if "TIDY3D_USER" in os.environ and ( | ||
"TIDY3D_PASS" in os.environ or "TIDY3D_PASS_HASH" in os.environ | ||
): | ||
logging.debug("Using Tidy3D credentials from enviornment") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.debug
tidy3d/web/auth.py
Outdated
|
||
# if we find something in the credential path | ||
if os.path.exists(credential_path): | ||
print("Using Tidy3D credentials from stored file") | ||
logging.info("Using Tidy3D credentials from stored file") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.info
tidy3d/web/auth.py
Outdated
return | ||
|
||
except Exception: # pylint:disable=broad-except | ||
print("Error: Failed to log in with environment credentials.") | ||
logging.info("Error: Failed to log in with environment credentials.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.info
tidy3d/web/auth.py
Outdated
@@ -73,10 +86,13 @@ def get_credentials() -> None: | |||
return | |||
|
|||
except Exception: # pylint:disable=broad-except | |||
print("Error: Failed to log in with saved credentials.") | |||
logging.info("Error: Failed to log in with saved credentials.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.info
tidy3d/web/auth.py
Outdated
|
||
# keep trying to log in | ||
while True: | ||
attempts = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could also just do for attempts in range(MAX_ATTEMPTS):
I think (or for _ in range(MAX_ATTEMPTS)
if attempts
is not used.
tidy3d/web/auth.py
Outdated
return | ||
|
||
except Exception: # pylint:disable=broad-except | ||
logging.info("Error: Failed to store credentials.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.info
tidy3d/web/auth.py
Outdated
@@ -88,27 +104,46 @@ def get_credentials() -> None: | |||
break | |||
|
|||
except Exception: # pylint:disable=broad-except | |||
print("Error: Failed to log in with new username and password.") | |||
logging.info("Error: Failed to log in with new username and password.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.info
tidy3d/web/auth.py
Outdated
return | ||
|
||
except Exception: # pylint:disable=broad-except | ||
logging.info("Error: Failed to store credentials.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log.info
Credential folder only created when needed
Maximum attempts in authentication while loops
Authentication only called when needed, and checks if already done