Skip to content

Commit f4bd740

Browse files
Fix/ensure secure connection (#76)
Continued work on #75
2 parents 10685d4 + 697afe1 commit f4bd740

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
## New Features
1010

11+
* TLS is now enabled for all connections.
12+
1113
## Bug Fixes
1214

1315
<!-- Here goes notable bug fixes that are worth a special mention or explanation -->

src/frequenz/client/reporting/_client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from datetime import datetime
1010
from typing import Any, cast
1111

12+
import grpc
1213
import grpc.aio as grpcaio
1314

1415
# pylint: disable=no-name-in-module
@@ -107,7 +108,9 @@ def __init__(self, service_address: str, key: str | None = None) -> None:
107108
service_address: The address of the Reporting service.
108109
key: The API key for the authorization.
109110
"""
110-
self._grpc_channel = grpcaio.insecure_channel(service_address)
111+
self._grpc_channel = grpcaio.secure_channel(
112+
service_address, grpc.ssl_channel_credentials()
113+
)
111114
self._stub = ReportingStub(self._grpc_channel)
112115
self._metadata = (("key", key),) if key else ()
113116

tests/test_client_reporting.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
"""Tests for the frequenz.client.reporting package."""
55
from typing import Generator
6-
from unittest.mock import MagicMock, patch
6+
from unittest.mock import ANY, MagicMock, patch
77

88
import pytest
99

@@ -13,16 +13,16 @@
1313

1414
@pytest.fixture
1515
def mock_channel() -> Generator[MagicMock, None, None]:
16-
"""Fixture for grpc.aio.insecure_channel."""
17-
with patch("grpc.aio.insecure_channel") as mock:
16+
"""Fixture for grpc.aio.secure_channel."""
17+
with patch("grpc.aio.secure_channel") as mock:
1818
yield mock
1919

2020

2121
@pytest.mark.asyncio
2222
async def test_client_initialization(mock_channel: MagicMock) -> None:
2323
"""Test that the client initializes the channel."""
2424
client = ReportingApiClient("localhost:50051") # noqa: F841
25-
mock_channel.assert_called_once_with("localhost:50051")
25+
mock_channel.assert_called_once_with("localhost:50051", ANY)
2626

2727

2828
def test_components_data_batch_is_empty_true() -> None:

0 commit comments

Comments
 (0)