Skip to content

Conversation

@zhaoyuyoung
Copy link
Contributor

Checklist

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

@codecov
Copy link

codecov bot commented Aug 5, 2025

Codecov Report

❌ Patch coverage is 85.43689% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 36.26%. Comparing base (7f167d0) to head (8e767e3).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
python/lsst/ctrl/bps/panda/panda_auth_utils.py 71.11% 6 Missing and 7 partials ⚠️
tests/test_panda_auth_utils.py 95.65% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #92      +/-   ##
==========================================
+ Coverage   31.90%   36.26%   +4.35%     
==========================================
  Files          12       13       +1     
  Lines        1147     1249     +102     
  Branches      193      204      +11     
==========================================
+ Hits          366      453      +87     
- Misses        769      776       +7     
- Partials       12       20       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zhaoyuyoung zhaoyuyoung force-pushed the tickets/DM-48912 branch 5 times, most recently from 57b70b4 to ed11c91 Compare August 5, 2025 20:12
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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a couple exceptions and changed those printing to raise. I also added simple unit tests for the refresh 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.

@zhaoyuyoung zhaoyuyoung force-pushed the tickets/DM-48912 branch 3 times, most recently from 4dd24d2 to 73d0882 Compare October 14, 2025 01:33
@zhaoyuyoung zhaoyuyoung merged commit 110c3fb into main Oct 15, 2025
18 checks passed
@zhaoyuyoung zhaoyuyoung deleted the tickets/DM-48912 branch October 15, 2025 00:09
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.

4 participants