-
Couldn't load subscription status.
- Fork 5
Change interface for HMAC #145
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
Change interface for HMAC #145
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
This pull request changes the interface for HMAC by removing the options dataclasses for signing and authentication and directly passing the secret and API key to the interceptors.
- Removed SigningOptions and AuthenticationOptions dataclasses.
- Updated SigningInterceptor and AuthenticationInterceptor constructors to accept direct string parameters.
- Modified parse_grpc_uri to support the new interface by adding key and sign_secret parameters.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/frequenz/client/base/signing.py | Removed SigningOptions and updated constructors to use a direct secret parameter. |
| src/frequenz/client/base/channel.py | Updated parse_grpc_uri to introduce key and sign_secret parameters instead of using options. |
| src/frequenz/client/base/authentication.py | Removed AuthenticationOptions and updated constructors to use a direct API key parameter. |
Comments suppressed due to low confidence (2)
src/frequenz/client/base/channel.py:91
- [nitpick] Consider renaming 'key' to 'api_key' in the parse_grpc_uri function for consistency with the naming used in authentication interceptors.
key: str | None = None,
src/frequenz/client/base/channel.py:92
- [nitpick] Consider renaming 'sign_secret' to 'secret' or 'signing_secret' to match the naming used in SigningInterceptor.
sign_secret: str | None = None,
| """An Interceptor that adds HMAC authentication of the metadata fields to a gRPC call.""" | ||
|
|
||
| def __init__(self, options: SigningOptions): | ||
| def __init__(self, secret: str): |
Copilot
AI
May 23, 2025
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.
Update the class documentation for SigningInterceptorUnaryUnary to reflect that the secret is now passed directly as a string parameter instead of via SigningOptions.
| """An Interceptor that adds HMAC authentication of the metadata fields to a gRPC call.""" | ||
|
|
||
| def __init__(self, options: AuthenticationOptions): | ||
| def __init__(self, api_key: str): |
Copilot
AI
May 23, 2025
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.
Update the class documentation for AuthenticationInterceptorUnaryUnary to reflect that the API key is now passed directly as a parameter instead of via AuthenticationOptions.
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.
We still need to make this available through the BaseClient.
e187a7c to
f233d0f
Compare
f233d0f to
8edf5b6
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.
Docs and tests are the most important comments for me, the rest is optional.
src/frequenz/client/base/client.py
Outdated
| auth_key: The API key to use when connecting to the service. | ||
| sign_secret: The secret to use when creating message 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.
I would clarify in here that the old ones are kept if they are not passed or ... is passed. While at it, maybe it is worth to homogenize this and change server_url: str | EllipsisType = ..., and then we can just mention once in the docs body that any omitted value (or value passed as ...) will keep the old value. But we can change the server_url in a separate PR too.
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.
I will clarify for now and not touch the server_url
src/frequenz/client/base/channel.py
Outdated
| uri: str, | ||
| /, | ||
| defaults: ChannelOptions = ChannelOptions(), | ||
| interceptors: list[ClientInterceptor] | None = None, |
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.
Nitpick: I would move interceptors before the /, to allow to use it as a positional argument. We require the keyword for defaults because ChannelOptions are sometimes used as concrete options and sometimes as defaults that will be overridden by those concrete options, so we wanted to make it extra clear these are just defaults and might not be the options that are used by the channel at the end. But with interceptors there is no ambiguity, instances passed in there will be instances of ClientInterceptors and there is only one way to use them and there will be no overrides.
Super nitpick because at the end probably almost nobody will use parse_grpc_uri directly, so it won't make much of a difference.
8edf5b6 to
d73c6a9
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.
Just one tiny formatting issue with the release notes.
As for the test, I can see if you are not familiar with mocking, patching and pytest it could be a bit complicated or very time consuming, so I'm OK with merging as is and then I can try to add a few basic tests to at least make sure some basic behavior doesn't accidentally break.
RELEASE_NOTES.md
Outdated
|
|
||
| <!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with --> | ||
| * Updated interface and behavior for HMAC | ||
| This brings with introduces a new positional argument to `parse_grpc_uri`. |
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.
This needs an extra space to render properly (or you can add some punctuation after the for HMAC if you want to keep it in one paragraph in the bullet point):
| This brings with introduces a new positional argument to `parse_grpc_uri`. | |
| This brings with introduces a new positional argument to `parse_grpc_uri`. |
You can see how the rendered markdown is shown with the button on the top of the 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.
Ah, thanks. I will add. I was hoping I could get the paragraph indented, alas, this ain't LaTeX.
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.
I feel you couldn't decide which beginning of the sentence to use and just went with both XD
This brings with introduces a new
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.
Damn, sometimes I focus too much on the format and forget about the contents 😆
d73c6a9 to
34afb00
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.
LGTM in general, there is only the grammar thing in the release notes now. Approving as we can also fix when preparing the notes for release, but feel free to fix before merging and just force-merging after it is fixed.
RELEASE_NOTES.md
Outdated
|
|
||
| <!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with --> | ||
| * Updated interface and behavior for HMAC | ||
| This brings with introduces a new positional argument to `parse_grpc_uri`. |
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.
Damn, sometimes I focus too much on the format and forget about the contents 😆
This changes the interface for communicating the API key and the signing secret. Specifically it removes them from "authentication options" and moves them to their own parameters instead. This allows using the default pattern for channel options in places that previously did not touch it. This is desired as soon most clients will require the API key and the signing secret to function properly, and we want to keep the changes needed to them minimal. Signed-off-by: Florian Wagner <[email protected]>
34afb00 to
b24c99f
Compare
This changes the interface for communicating the API key and the signing secret. Specifically it removes them from "authentication options" and moves them to their own parameters instead.
This allows using the default pattern for channel options in places that previously did not touch it. This is desired as soon most clients will require the API key and the signing secret to function properly, and we want to keep the changes needed to them minimal.