Skip to content
Merged
Prev Previous commit
Next Next commit
Issue #19, attempt to fix windows tests
  • Loading branch information
giuseppe-carboni committed Jan 7, 2026
commit 0701192ade7442406f3792827ca005816f559aab
32 changes: 19 additions & 13 deletions discos_client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@

base_config = Path(user_config_dir("discos"))
target_dir = base_config / "rpc" / "client"
key_filename = "identity"
full_path_public = target_dir / f"{key_filename}.key"
full_path_secret = target_dir / f"{key_filename}.key_secret"
KEY_FILENAME = "identity"
full_path_public = target_dir / f"{KEY_FILENAME}.key"
full_path_secret = target_dir / f"{KEY_FILENAME}.key_secret"


def create_discos_keys(overwrite):

if full_path_secret.exists() and not overwrite:
print("Kept previously created key pair. Use --overwrite to replace it.\n")
print("Kept previously created key pair. "
"Use --overwrite to replace it.\n")
return

try:
Expand All @@ -23,29 +25,32 @@ def create_discos_keys(overwrite):
print(f"Error creating the configuration directory: {e}")
sys.exit(1)

create_certificates(str(target_dir), key_filename)
create_certificates(str(target_dir), KEY_FILENAME)

if os.name == 'posix':
full_path_secret.chmod(0o600)
(target_dir / f"{key_filename}.key").chmod(0o644)
(target_dir / f"{KEY_FILENAME}.key").chmod(0o644)
print(f"Key pair created in: '{target_dir}'.")


def print_discos_keys():
if not full_path_public.exists():
print("No key was generated yet.")
return

with open(full_path_public, "r") as f:
with open(full_path_public, "r", encoding="utf-8") as f:
print(f.read())
print(f"\nPath of the public key file: {full_path_public}")
print(f"Remember to never share the '{key_filename}.key_secret' file with anyone.")
print(f"Remember to never share the '{KEY_FILENAME}.key_secret' file with "
"anyone.")
print(
"In order to be authorized to send command to any of the telescopes, " \
f"remember to send a copy of the '{key_filename}.key' file to the " \
"DISCOS team, asking for authorization. Your request will be taken " \
"In order to be authorized to send command to any of the telescopes, "
f"remember to send a copy of the '{KEY_FILENAME}.key' file to the "
"DISCOS team, asking for authorization. Your request will be taken "
"into consideration and you will hear back from the team."
)


def main():
parser = ArgumentParser(
"DISCOS CURVE key pairs generator."
Expand All @@ -58,10 +63,11 @@ def main():
parser.add_argument(
"--show-only",
action="store_true",
help="Only prints the public key and its path without generating a new pair."
help="Only prints the public key and its path without \
generating a new pair."
)
args = parser.parse_args()

if not args.show_only:
create_discos_keys(args.overwrite)
print_discos_keys()
print_discos_keys()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ discos-keygen = "discos_client.cli:main"
discos_client = ["schemas/**", "servers/**"]

[project.optional-dependencies]
test = ["coverage", "prospector", "jsonschema", "referencing", "tornado"]
test = ["coverage", "prospector", "jsonschema", "referencing"]
docs = ["sphinx<9,>=6", "sphinx-rtd-theme", "sphinx-autodoc-typehints", "sphinx-jsonschema"]
6 changes: 6 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import unittest
import time
import re
import asyncio
import sys
from unittest.mock import patch
from pathlib import Path
from threading import Thread, Event
Expand All @@ -11,6 +13,10 @@
from discos_client.client import DISCOSClient, \
DEFAULT_SUB_PORT, DEFAULT_REQ_PORT


if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

keys_path = Path(__file__).resolve().parent / "test_keys"
dummy_public, dummy_secret = load_certificate(
keys_path / "dummy.key_secret"
Expand Down