-
Notifications
You must be signed in to change notification settings - Fork 8
Add HMAC capabilities #181
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: v0.x.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -9,6 +9,9 @@ | |||||||||
from pprint import pprint | ||||||||||
from typing import AsyncIterator | ||||||||||
|
||||||||||
from frequenz.client.base.authentication import AuthenticationOptions | ||||||||||
from frequenz.client.base.channel import ChannelOptions | ||||||||||
from frequenz.client.base.signing import SigningOptions | ||||||||||
from frequenz.client.common.metric import Metric | ||||||||||
|
||||||||||
from frequenz.client.reporting import ReportingApiClient | ||||||||||
|
@@ -85,6 +88,12 @@ def main() -> None: | |||||||||
help="API key", | ||||||||||
default=None, | ||||||||||
) | ||||||||||
parser.add_argument( | ||||||||||
"--secret", | ||||||||||
type=str, | ||||||||||
help="The secret for the reporting service", | ||||||||||
default=None, | ||||||||||
) | ||||||||||
args = parser.parse_args() | ||||||||||
asyncio.run( | ||||||||||
run( | ||||||||||
|
@@ -99,6 +108,7 @@ def main() -> None: | |||||||||
service_address=args.url, | ||||||||||
key=args.key, | ||||||||||
fmt=args.format, | ||||||||||
secret=args.secret, | ||||||||||
) | ||||||||||
) | ||||||||||
|
||||||||||
|
@@ -116,6 +126,7 @@ async def run( # noqa: DOC502 | |||||||||
bounds: bool, | ||||||||||
service_address: str, | ||||||||||
key: str, | ||||||||||
secret: str, | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe call this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gladly |
||||||||||
fmt: str, | ||||||||||
) -> None: | ||||||||||
"""Test the ReportingApiClient. | ||||||||||
|
@@ -130,13 +141,19 @@ async def run( # noqa: DOC502 | |||||||||
states: include states in the output | ||||||||||
bounds: include bounds in the output | ||||||||||
service_address: service address | ||||||||||
key: API key | ||||||||||
key: API key (per customer) | ||||||||||
secret: cryptographic secret of the service (per API) | ||||||||||
fmt: output format | ||||||||||
|
||||||||||
Raises: | ||||||||||
ValueError: if output format is invalid | ||||||||||
""" | ||||||||||
client = ReportingApiClient(service_address, key) | ||||||||||
auth = AuthenticationOptions(key) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Always constructing
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||
sign = SigningOptions(secret) | ||||||||||
|
||||||||||
channel_options = ChannelOptions(auth=auth, sign=sign) | ||||||||||
|
||||||||||
client = ReportingApiClient(service_address, key, channel_defaults=channel_options) | ||||||||||
Comment on lines
+151
to
+156
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks pretty inconsistent, IMHO this should be done inside the client class, and the signing secret should be taken as a separate argument, like with Looking at the All channel options were designed to be mainly set from the I think we should probably change the base client to pass secrets outside the A for a temporary solution I suggest changing the current class ReportingApiClient(BaseApiClient[ReportingStub]):
"""A client for the Reporting service."""
def __init__(
self,
server_url: str,
auth_key: str | None = None,
sign_secret: str | None = None,
connect: bool = True,
channel_defaults: ChannelOptions = ChannelOptions(), # default options
) -> None:
channel_defaults = channel_defaults.replace(sign=SigningOptions(secret=sign_secret))
channel_defaults = channel_defaults.replace(auth=AuthenticationOptions(api_key=auth_key))
super().__init__(
server_url,
ReportingStub,
connect=connect,
channel_defaults=channel_defaults,
) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I will do the temporary fix first and see how far I get with doing it properly in the base client. I agree with your arguments.
So the targeted interface for the clients/apps stays to pass via command line argument (possibly from environment variable). |
||||||||||
|
||||||||||
metrics = [Metric[mn] for mn in metric_names] | ||||||||||
|
||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# License: MIT | ||
# Copyright © 2025 Frequenz Energy-as-a-Service GmbH | ||
|
||
"""Show Protobuf version warning during tests, but don't treat as error.""" | ||
|
||
import warnings | ||
|
||
warnings.filterwarnings( | ||
"once", | ||
message=r"Protobuf gencode version 5\..*exactly one major version older.*", | ||
category=UserWarning, | ||
) | ||
|
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.
-Werror
should be keptThere 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.
okay, but I think then I might need to put the specific warning back in. This is the fix Flora applied.
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.
oh, really, I didn't realized that, I guess I missed that change as there were other changes too in that line. Then something went wrong. @flora-hofmann-frequenz :-/
Removing
-Werror
means we don't generally treat warnings as errors anymore. I will have a look.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.
OK, I found a fix, and while at it, tried a few improvements, with these options we don't need to add the
conftest.py
file at all!I think it is better to complete ignore the protobuf warnings, and also not care about the reported version (so we don't need to update the ignore rule when we bump the protobuf version), we know we are doing this, so it only adds noise to the tests to show it. We'll get a proper error if we go beyond the supported range anyways.
Also show deprecations only once, we don't need to get spammed if a deprecated symbol is used more than once.
I will add these improvements to
repo-config
.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.