Skip to content

Commit 1ef5d9b

Browse files
Bring the metadata keys in line with the server
The keys currently used to store the authentication and signature metadata use the `x-***` pattern. However, the server just used plain names (e.g. `x-key` vs. `key`). This changes the used metadata keys to be the same as the ones used by the server. Signed-off-by: Florian Wagner <[email protected]>
1 parent 0221304 commit 1ef5d9b

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

RELEASE_NOTES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@
99
* Updated `protobuf` dependency range: changed from `>=4.21.6, <6` to `>=5.29.2, <7`
1010
* The minimum dependency for `typing-extensions` is now `4.6.0` to be compatible with Python 3.12
1111
* The minimum dependency for `grpcio` is now `1.59` to be compatible with Python 3.12
12+
13+
## Bug Fixes
14+
15+
* Fixed keys of signature to match what fuse-rs expects

src/frequenz/client/base/authentication.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,4 @@ def add_auth_header(
7474
if client_call_details.metadata is None:
7575
client_call_details.metadata = Metadata()
7676

77-
client_call_details.metadata["x-key"] = self._key
77+
client_call_details.metadata["key"] = self._key

src/frequenz/client/base/signing.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def add_hmac(
8585
)
8686
return
8787

88-
key: Any = client_call_details.metadata.get("x-key")
88+
key: Any = client_call_details.metadata.get("key")
8989
if key is None:
9090
_logger.error("No key found in metadata, cannot sign the request.")
9191
return
@@ -96,6 +96,6 @@ def add_hmac(
9696

9797
hmac_obj.update(client_call_details.method.encode())
9898

99-
client_call_details.metadata["x-ts"] = ts
100-
client_call_details.metadata["x-nonce"] = nonce
101-
client_call_details.metadata["x-hmac"] = urlsafe_b64encode(hmac_obj.digest())
99+
client_call_details.metadata["ts"] = ts
100+
client_call_details.metadata["nonce"] = nonce
101+
client_call_details.metadata["sig"] = urlsafe_b64encode(hmac_obj.digest())

tests/test_authentication.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ async def test_auth_interceptor() -> None:
2525

2626
auth_interceptor.add_auth_header(client_call_details)
2727

28-
assert metadata["x-key"] == "my_key"
28+
assert metadata["key"] == "my_key"

tests/test_signing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ async def test_sign_interceptor() -> None:
1616
sign: SigningOptions = SigningOptions(secret="my_secret")
1717
sign_interceptor: SigningInterceptor = SigningInterceptor(options=sign)
1818

19-
metadata: dict[str, str | bytes] = {"x-key": "my_key"}
19+
metadata: dict[str, str | bytes] = {"key": "my_key"}
2020

2121
client_call_details = mock.MagicMock(method="my_rpc")
2222
client_call_details.metadata = metadata
2323

2424
sign_interceptor.add_hmac(client_call_details, b"1634567890", b"123456789")
2525

26-
assert metadata["x-hmac"] == "NJDvrkRZhOPekn5AvPiaJsYTJYCgnLzA-LQFC2D7GNE=".encode(
26+
assert metadata["sig"] == "NJDvrkRZhOPekn5AvPiaJsYTJYCgnLzA-LQFC2D7GNE=".encode(
2727
"utf-8"
2828
)

0 commit comments

Comments
 (0)