Skip to content

Commit 11e11f2

Browse files
committed
Support key signing
Signed-off-by: Mathias L. Baumann <[email protected]>
1 parent 49ebc13 commit 11e11f2

File tree

4 files changed

+37
-17
lines changed

4 files changed

+37
-17
lines changed

RELEASE_NOTES.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
## Upgrading
88

9-
<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
9+
* The `key` parameter in the `Dispatcher` constructor is now deprecated. Use `sign_secret` instead.
1010

1111
## New Features
1212

13-
<!-- Here goes the main new features and examples or instructions on how to use them -->
13+
* Two new parmeters where added to the `Dispatcher` constructor:
14+
* `sign_secret`: A secret key used for signing messages.
15+
* `auth_key`: An authentication key for the Dispatch API.
1416

1517
## Bug Fixes
1618

17-
* The merge by type class now uses the correct logger path.
18-
* The merge by type was made more robust under heavy load, making sure to use the same `now` for all dispatches that are checked.
19-
* Fix that the merge filter was using an outdated dispatches dict once fetch() ran.
19+
<!-- Here goes notable bug fixes that are worth a special mention or explanation -->

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ dependencies = [
4040
# plugins.mkdocstrings.handlers.python.import)
4141
"frequenz-sdk >= 1.0.0-rc2100, < 1.0.0-rc2200",
4242
"frequenz-channels >= 1.6.1, < 2.0.0",
43-
"frequenz-client-dispatch >= 0.11.1, < 0.12.0",
44-
"frequenz-client-common >= 0.3.2, < 0.4.0",
43+
"frequenz-client-dispatch >= 0.11.2, < 0.12.0",
4544
"frequenz-client-base >= 0.11.0, < 0.12.0",
4645
]
4746
dynamic = ["version"]
@@ -54,7 +53,7 @@ email = "[email protected]"
5453
dev-flake8 = [
5554
"flake8 == 7.3.0",
5655
"flake8-docstrings == 1.7.0",
57-
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
56+
"flake8-pyproject == 1.2.3", # For reading the flake8 config from pyproject.toml
5857
"pydoclint == 0.6.6",
5958
"pydocstyle == 6.3.0",
6059
]

src/frequenz/dispatch/_dispatcher.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ async def run():
6464
async with Dispatcher(
6565
microgrid_id=microgrid_id,
6666
server_url=url,
67-
key=key
67+
auth_key=key
6868
) as dispatcher:
6969
dispatcher.start_managing(
7070
dispatch_type="DISPATCH_TYPE",
@@ -90,7 +90,7 @@ async def run():
9090
async with Dispatcher(
9191
microgrid_id=microgrid_id,
9292
server_url=url,
93-
key=key
93+
auth_key=key
9494
) as dispatcher:
9595
actor = MagicMock() # replace with your actor
9696
@@ -135,7 +135,7 @@ async def run():
135135
async with Dispatcher(
136136
microgrid_id=microgrid_id,
137137
server_url=url,
138-
key=key,
138+
auth_key=key,
139139
) as dispatcher:
140140
events_receiver = dispatcher.new_lifecycle_events_receiver("DISPATCH_TYPE")
141141
@@ -172,7 +172,7 @@ async def run():
172172
async with Dispatcher(
173173
microgrid_id=microgrid_id,
174174
server_url=url,
175-
key=key,
175+
auth_key=key,
176176
) as dispatcher:
177177
# Create a new dispatch
178178
new_dispatch = await dispatcher.client.create(
@@ -205,7 +205,9 @@ def __init__(
205205
*,
206206
microgrid_id: MicrogridId,
207207
server_url: str,
208-
key: str,
208+
key: str | None = None,
209+
auth_key: str | None = None,
210+
sign_secret: str | None = None,
209211
call_timeout: timedelta = timedelta(seconds=60),
210212
stream_timeout: timedelta = timedelta(minutes=5),
211213
):
@@ -214,15 +216,29 @@ def __init__(
214216
Args:
215217
microgrid_id: The microgrid id.
216218
server_url: The URL of the dispatch service.
217-
key: The key to access the service.
219+
key: The key to access the service, deprecated, use `auth_key` instead.
220+
auth_key: The authentication key to access the service.
221+
sign_secret: The secret to sign the requests, optional
218222
call_timeout: The timeout for API calls.
219223
stream_timeout: The timeout for streaming API calls.
224+
225+
Raises:
226+
ValueError: If both `key` and `auth_key` are provided.
220227
"""
221228
super().__init__()
222229

230+
if key is not None and auth_key is not None:
231+
raise ValueError(
232+
"Both 'key' and 'auth_key' are provided, please use only 'auth_key'."
233+
)
234+
235+
if key is not None:
236+
auth_key = key
237+
223238
self._client = DispatchApiClient(
224239
server_url=server_url,
225-
key=key,
240+
auth_key=key,
241+
sign_secret=sign_secret,
226242
call_timeout=call_timeout,
227243
stream_timeout=stream_timeout,
228244
)

tests/test_managing_actor.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,20 +335,25 @@ async def test_manage_abstraction(
335335
class MyFakeClient(FakeClient):
336336
"""Fake client for testing."""
337337

338+
# pylint: disable=too-many-arguments,unused-argument
338339
def __init__(
339340
self,
340341
*,
341342
server_url: str,
342-
key: str,
343+
auth_key: str | None = None,
344+
key: str | None = None,
345+
sign_secret: str | None = None,
343346
call_timeout: timedelta,
344347
stream_timeout: timedelta,
345348
) -> None:
346349
assert server_url
347-
assert key
350+
assert key is None or auth_key is None
348351
assert call_timeout
349352
assert stream_timeout
350353
super().__init__()
351354

355+
# pylint: enable=too-many-arguments,unused-argument
356+
352357
mid = MicrogridId(1)
353358

354359
# Patch `Client` class in Dispatcher with MyFakeClient

0 commit comments

Comments
 (0)