-
Notifications
You must be signed in to change notification settings - Fork 0
React to 401 http errors, execute a callback and retry the request #260
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
…nto maint/401_http
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #260 +/- ##
==========================================
- Coverage 84.22% 84.10% -0.13%
==========================================
Files 17 17
Lines 1509 1560 +51
==========================================
+ Hits 1271 1312 +41
- Misses 238 248 +10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| >>> from ansys.hps.data_transfer.client import Client | ||
| >>> token = authenticate(username=username, password=password, verify=False, url=auth_url) | ||
| >>> token = token.get("access_token", None) | ||
| >>> def 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.
maybe call it refresh_token_cb or similar to disambiguate from the refresh_token itself
| >>> token = token.get("access_token", None) | ||
| >>> def refresh_token(): | ||
| # Function to refresh the token | ||
| token = authenticate(username=username, self.password, verify=False, url=auth_url) |
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.
self.password --> just password?
| def __init__(self, *args, refresh_token_callback: Callable[[], Awaitable[str]] = None, **kwargs): | ||
| """Initializes the AsyncClient class object.""" | ||
| super().__init__(*args, **kwargs) | ||
| self.refresh_token_callback = refresh_token_callback # Override the callback |
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.
why do you need to override it?
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.
overriding refresh_token_callback in the AsyncClient class for it to be asynchronous (Callable[[], Awaitable[str]]) because the parent class defines it (Callable[[], str])
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.
The changes here as well as the content of the async version (with the loop on get storage) seem to me more of a script to test tokens than an examples. It's fine to keep this code around as a script, but I think it should not a user-facing example.
Description
Addressing: #106
How to test:
In data-transfer config add:
"auth": {
"auto_config_worker": true
}
Restart docker service, set Access Token Lifespan to something like 30 second.
Can we do more with testing?
Do we want a callback for AsyncClient as well?
Checklist