Skip to content

Commit 7615ab3

Browse files
Slight variation for server_public_key_file
1 parent 0a5a063 commit 7615ab3

2 files changed

Lines changed: 17 additions & 44 deletions

File tree

‎discos_client/utils.py‎

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -182,25 +182,19 @@ def get_server_public_key(
182182
) -> bytes:
183183
"""Retrieve the CURVE public key of a DISCOS RPC server.
184184
185-
The server public key can be obtained either from a predefined
186-
telescope configuration or from an explicit key file.
187-
188-
Exactly one of the following must be provided:
189-
- ``telescope``: loads the key from the package resources
190-
(``discos_client/servers/<telescope>/server.key``)
191-
- ``server_public_key_file``: loads the key from a user-specified path
185+
If ``server_public_key_file`` is provided, it overrides the default
186+
server key associated with ``telescope``. Otherwise, the bundled key
187+
for the given telescope is used.
192188
193189
:param telescope: The telescope name used to locate a bundled server key.
194190
:param server_public_key_file: Path to a server public key file.
191+
If provided, it overrides the default key associated with
192+
``telescope``.
195193
:return: The server public key.
196-
:raises ValueError: If both or neither arguments are provided.
197-
:raises OSError: If the key file cannot be found or loaded.
194+
:raises ValueError: If neither ``telescope`` nor
195+
``server_public_key_file`` is provided.
196+
:raises OSError: If the selected key file cannot be found or loaded.
198197
"""
199-
if telescope is not None and server_public_key_file is not None:
200-
raise ValueError(
201-
"Use either 'telescope' or 'server_public_key_file', not both."
202-
)
203-
204198
if server_public_key_file is not None:
205199
server_public, _ = load_certificate(Path(server_public_key_file))
206200
return server_public
@@ -224,21 +218,20 @@ def get_auth_keys(
224218
) -> tuple[bytes, bytes, bytes]:
225219
"""Retrieve CURVE authentication keys for both client and server.
226220
227-
This function loads:
228-
- the client key pair associated with the given ``identity``
229-
- the server public key, either from a telescope profile or an
230-
explicit file
231-
232-
The server key selection follows these rules:
233-
- if ``server_public_key_file`` is provided, it is used
234-
- otherwise, ``telescope`` must be provided to load a bundled key
221+
The client key pair is loaded from the user configuration associated
222+
with ``identity``. The server public key is loaded from
223+
``server_public_key_file`` if provided; otherwise, the bundled key
224+
for ``telescope`` is used.
235225
236226
:param identity: The name of the client identity (key file prefix).
237227
:param telescope: The telescope name used to locate a bundled server key.
238228
:param server_public_key_file: Path to a server public key file.
229+
If provided, it overrides the default key associated with
230+
``telescope``.
239231
:return: A tuple containing (client_public, client_secret, server_public).
240-
:raises ValueError: If neither or both server key sources are provided.
241-
:raises OSError: If any key file cannot be found or loaded.
232+
:raises ValueError: If neither ``telescope`` nor
233+
``server_public_key_file`` is provided.
234+
:raises OSError: If any selected key file cannot be found or loaded.
242235
"""
243236
client_public, client_secret = get_client_auth_keys(identity)
244237
server_public = get_server_public_key(telescope, server_public_key_file)

‎tests/test_client.py‎

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -431,26 +431,6 @@ def test_command_with_server_public_key_file(self, mock_load_cert):
431431
answer = client.command("dummy")
432432
self.assertTrue(answer.executed)
433433

434-
@patch("discos_client.utils.load_certificate")
435-
def test_command_with_telescope_and_server_public_key_file(
436-
self,
437-
mock_load_cert
438-
):
439-
mock_load_cert.return_value = (dummy_public, dummy_secret)
440-
with self.assertRaises(ValueError) as ex:
441-
DISCOSClient(
442-
address="127.0.0.1",
443-
sub_port=DEFAULT_SUB_PORT,
444-
req_port=DEFAULT_REQ_PORT,
445-
telescope="SRT",
446-
identity="identity",
447-
server_public_key_file="/tmp/server.key",
448-
)
449-
self.assertIn(
450-
"Use either 'telescope' or 'server_public_key_file', not both.",
451-
str(ex.exception)
452-
)
453-
454434
@patch("discos_client.utils.load_certificate")
455435
def test_command_without_telescope_or_server_public_key_file(
456436
self,

0 commit comments

Comments
 (0)