Skip to content

Conversation

zhaoyuyoung
Copy link
Contributor

Checklist

  • ran Jenkins
  • added a release note for user-visible changes to doc/changes

Copy link

codecov bot commented Aug 5, 2025

Codecov Report

❌ Patch coverage is 8.00000% with 46 lines in your changes missing coverage. Please review.
✅ Project coverage is 31.33%. Comparing base (b4ee9c7) to head (ed11c91).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
python/lsst/ctrl/bps/panda/panda_auth_utils.py 8.00% 46 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@zhaoyuyoung zhaoyuyoung force-pushed the tickets/DM-48912 branch 4 times, most recently from 3c98f47 to 57b70b4 Compare August 5, 2025 20:08
Copy link
Contributor

@MichelleGower MichelleGower left a 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"""
Copy link
Contributor

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.")
Copy link
Contributor

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")
Copy link
Contributor

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.

Copy link
Contributor

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.")
Copy link
Contributor

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.

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants