-
Notifications
You must be signed in to change notification settings - Fork 1
Add refresh function in panda_auth #92
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
base: main
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #92 +/- ##
==========================================
- Coverage 32.36% 31.33% -1.03%
==========================================
Files 12 12
Lines 1134 1184 +50
Branches 191 198 +7
==========================================
+ Hits 367 371 +4
- Misses 755 801 +46
Partials 12 12 ☔ View full report in Codecov by Sentry. |
3c98f47
to
57b70b4
Compare
57b70b4
to
ed11c91
Compare
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.
Some suggestions. Also it would be good to have unit tests, but not sure how difficult mocking the various calls would be.
|
||
|
||
def panda_auth_refresh(days=4, verbose=False): | ||
"""Refresh auth token""" |
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.
Need the parameters description in the docstring.
print("=" * 60 + "\n") | ||
return | ||
else: | ||
print("Cannot find token 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.
Perhaps point the user to the command should use instead?
status = panda_auth_status() | ||
if status: | ||
print(f"{'New expiration time:':23} {datetime.utcfromtimestamp(status['exp'])} UTC") | ||
print("Success to refresh token") |
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.
No failure status nor exception is being thrown in all the failure cases. This means the function nor command can be used in a script/program where want to halt on error. If some of these one might not want to hard fail (e.g., maybe the too early to refresh), could throw different exceptions and let the calling program decide.
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.
If do this, then many of the user messages can be moved to the driver upon catching the exception instead of in this function.
print(f"Token will expire in {minutes} minutes.") | ||
print(f"Token expiration time : {exp_time.strftime('%Y-%m-%d %H:%M:%S')} UTC") | ||
if delta < timedelta(minutes=0): | ||
print("Token already expired. Cannot refresh.") |
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.
Here you need to check the exp time of the refresh token, not the id_token. For cases, the id_token lifetime can be 24 hours, but the refresh_token can be 30 days or even longer.
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.
oh. It's correct. If the token is expired (even the refresh token is valid), you should not be able to connect the server to refresh the token. So this part is correct.
Checklist
doc/changes