-
Couldn't load subscription status.
- Fork 5
Add interceptors for stream requests #142
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
Add interceptors for stream requests #142
Conversation
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.
Pull Request Overview
Adds HMAC signing and API key authentication interceptors for both unary-unary and unary-stream gRPC calls by extracting header logic into helper functions and registering both variants in the channel builder.
- Factor out
_add_hmacand_add_auth_headerto centralize metadata injection - Introduce
SigningInterceptorUnaryUnary/SigningInterceptorUnaryStreamandAuthenticationInterceptorUnaryUnary/AuthenticationInterceptorUnaryStream - Update channel setup to append both interceptor types and adjust tests to call new helpers directly
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/frequenz/client/base/signing.py | Add _add_hmac helper, split signing interceptors for two call types |
| src/frequenz/client/base/authentication.py | Add _add_auth_header helper, split auth interceptors for two call types |
| src/frequenz/client/base/channel.py | Register both UnaryUnary and UnaryStream interceptors in channel builder |
| tests/test_signing.py | Update test to call _add_hmac directly and adjust expected sig |
| tests/test_authentication.py | Update test to call _add_auth_header directly |
| RELEASE_NOTES.md | Note HMAC signing support for both UnaryUnary and UnaryStream |
Comments suppressed due to low confidence (3)
tests/test_signing.py:21
- [nitpick] The test only asserts the
sigfield but does not verify thattsandnoncemetadata entries are set correctly; consider adding assertions for those headers.
_add_hmac(b"hunter2", client_call_details, 1634567890, b"123456789")
tests/test_authentication.py:20
- [nitpick] There are no tests covering the new UnaryStream authentication interceptor; consider adding a test to ensure
_add_auth_headeris applied in the stream context or via the interceptor.
_add_auth_header(key, client_call_details)
src/frequenz/client/base/signing.py:25
- This module uses
hmac.newand_loggerbut neitherimport hmacnorimport loggingis present; add those imports at the top to avoid NameError.
def _add_hmac(
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.
LGTM. 2 very minor and optional comments:
- Split the
erros->errorstypo fix into a separate commit - Put the common code into a mixin class (like
SigningInterceptorMixin) and then inherit from both the interceptor and the mixin. This can save a couple of extra lines (basically the__init__()method). Mostly FYI in case you are not familiar with this option in Python, the code is so simple that for me it is still perfectly fine too keep it as it is.
Signed-off-by: Florian Wagner <[email protected]>
This adds authentication and signing interceptors for stream requests. Specifically for those where the client sends a single message and receives a stream. Signed-off-by: Florian Wagner <[email protected]>
4573a9b to
591354f
Compare
|
I decided not to do the mixin, but split out the error. |
This adds authentication and signing interceptors for stream requests. Specifically for those where the client sends a single message and receives a stream.