Skip to content

Commit

Permalink
remove ca_url, add better examples (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
jschlyter authored Nov 29, 2024
1 parent 42997d4 commit e33cbaf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 8 additions & 5 deletions nodeman/models.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions nodeman/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def delete_node(
@router.post(
"/api/v1/node/{name}/enroll",
responses={
201: {"model": NodeConfiguration},
200: {"model": NodeConfiguration},
},
tags=["client"],
)
Expand Down Expand Up @@ -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()
Expand All @@ -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,
)

0 comments on commit e33cbaf

Please sign in to comment.