From d79e25344de955c94b0d856c07cf71465d7ebb76 Mon Sep 17 00:00:00 2001 From: Jakob Schlyter Date: Fri, 29 Nov 2024 15:17:40 +0100 Subject: [PATCH] remove ca_url, add better examples --- nodeman/models.py | 13 ++++++++----- nodeman/nodes.py | 4 +--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/nodeman/models.py b/nodeman/models.py index 39312e4..a29aa38 100644 --- a/nodeman/models.py +++ b/nodeman/models.py @@ -1,7 +1,7 @@ from datetime import datetime from cryptography.x509 import load_pem_x509_certificates -from pydantic import AnyHttpUrl, BaseModel, Field, field_validator +from pydantic import BaseModel, Field, field_validator from .db_models import TapirNode from .settings import MqttUrl @@ -41,13 +41,16 @@ class NodeCollection(BaseModel): class NodeConfiguration(BaseModel): - name: str = Field(title="Node name") - mqtt_broker: MqttUrl = Field(title="MQTT Broker") - mqtt_topics: dict[str, str] = Field(title="MQTT Topics", default={}) + name: str = Field(title="Node name", examples=["node.example.com"]) + mqtt_broker: MqttUrl = Field(title="MQTT Broker", examples=["mqtts://broker.example.com"]) + mqtt_topics: dict[str, str] = Field( + title="MQTT Topics", + default={}, + examples=[{"edm": "configuration/node.example.com/edm", "pop": "configuration/node.example.com/pop"}], + ) trusted_keys: list[PublicJwk] = Field(title="Trusted keys") x509_certificate: str = Field(title="X.509 Client Certificate Bundle") x509_ca_certificate: str = Field(title="X.509 CA Certificate Bundle") - x509_ca_url: AnyHttpUrl = Field(title="X.509 CA URL") @field_validator("x509_certificate", "x509_ca_certificate") @classmethod diff --git a/nodeman/nodes.py b/nodeman/nodes.py index 30a943b..0d249e6 100644 --- a/nodeman/nodes.py +++ b/nodeman/nodes.py @@ -140,7 +140,7 @@ def delete_node( @router.post( "/api/v1/node/{name}/enroll", responses={ - 201: {"model": NodeConfiguration}, + 200: {"model": NodeConfiguration}, }, tags=["client"], ) @@ -203,7 +203,6 @@ async def enroll_node( [certificate.public_bytes(serialization.Encoding.PEM).decode() for certificate in ca_response.cert_chain] ) x509_ca_certificate = ca_response.ca_cert.public_bytes(serialization.Encoding.PEM).decode() - x509_ca_url = request.app.ca_client.ca_url node.activated = datetime.now(tz=timezone.utc) node.save() @@ -216,5 +215,4 @@ async def enroll_node( trusted_keys=request.app.trusted_keys, x509_certificate=x509_certificate, x509_ca_certificate=x509_ca_certificate, - x509_ca_url=x509_ca_url, )