Check in backend in working state
This commit is contained in:
@ -1,24 +1,27 @@
|
||||
"""Models for API views."""
|
||||
|
||||
import ipaddress
|
||||
import uuid
|
||||
from datetime import datetime
|
||||
from typing import Annotated, Any, Self, override
|
||||
from typing import Annotated, Self, override
|
||||
|
||||
from sqlmodel import Field, SQLModel
|
||||
from pydantic import IPvAnyAddress, IPvAnyNetwork
|
||||
from . import models
|
||||
from pydantic import AfterValidator, IPvAnyAddress, IPvAnyNetwork
|
||||
|
||||
from sshecret.crypto import public_key_validator
|
||||
|
||||
from . import models
|
||||
|
||||
|
||||
class ClientView(SQLModel):
|
||||
"""View for a single client."""
|
||||
|
||||
id: uuid.UUID
|
||||
name: str
|
||||
description: str | None = None
|
||||
public_key: str
|
||||
policies: list[str] = ["0.0.0.0/0", "::/0"]
|
||||
secrets: list[str] = Field(default_factory=list)
|
||||
created_at: datetime
|
||||
created_at: datetime | None
|
||||
updated_at: datetime | None = None
|
||||
|
||||
@classmethod
|
||||
@ -33,6 +36,7 @@ class ClientView(SQLModel):
|
||||
view = cls(
|
||||
id=client.id,
|
||||
name=client.name,
|
||||
description=client.description,
|
||||
public_key=client.public_key,
|
||||
created_at=client.created_at,
|
||||
updated_at=client.updated_at or None,
|
||||
@ -46,24 +50,34 @@ class ClientView(SQLModel):
|
||||
return view
|
||||
|
||||
|
||||
class ClientQueryResult(SQLModel):
|
||||
"""Result class for queries towards the client list."""
|
||||
|
||||
clients: list[ClientView] = Field(default_factory=list)
|
||||
total_results: int
|
||||
remaining_results: int
|
||||
|
||||
|
||||
class ClientCreate(SQLModel):
|
||||
"""Model to create a client."""
|
||||
|
||||
name: str
|
||||
public_key: str
|
||||
description: str | None = None
|
||||
public_key: Annotated[str, AfterValidator(public_key_validator)]
|
||||
|
||||
def to_client(self) -> models.Client:
|
||||
"""Instantiate a client."""
|
||||
public_key = self.public_key
|
||||
return models.Client(
|
||||
name=self.name, public_key=public_key
|
||||
name=self.name,
|
||||
public_key=self.public_key,
|
||||
description=self.description,
|
||||
)
|
||||
|
||||
|
||||
class ClientUpdate(SQLModel):
|
||||
"""Model to update the client public key."""
|
||||
|
||||
public_key: str
|
||||
public_key: Annotated[str, AfterValidator(public_key_validator)]
|
||||
|
||||
|
||||
class BodyValue(SQLModel):
|
||||
@ -77,6 +91,7 @@ class ClientSecretPublic(SQLModel):
|
||||
|
||||
name: str
|
||||
secret: str
|
||||
description: str | None = None
|
||||
|
||||
@classmethod
|
||||
def from_client_secret(cls, client_secret: models.ClientSecret) -> Self:
|
||||
@ -84,13 +99,14 @@ class ClientSecretPublic(SQLModel):
|
||||
return cls(
|
||||
name=client_secret.name,
|
||||
secret=client_secret.secret,
|
||||
description=client_secret.description,
|
||||
)
|
||||
|
||||
|
||||
class ClientSecretResponse(ClientSecretPublic):
|
||||
"""A secret view."""
|
||||
|
||||
created_at: datetime
|
||||
created_at: datetime | None
|
||||
updated_at: datetime | None = None
|
||||
|
||||
@override
|
||||
@ -123,3 +139,31 @@ class ClientPolicyUpdate(SQLModel):
|
||||
"""Model for updating policies."""
|
||||
|
||||
sources: list[IPvAnyAddress | IPvAnyNetwork]
|
||||
|
||||
|
||||
class ClientSecretList(SQLModel):
|
||||
"""Model for aggregating identically named secrets."""
|
||||
|
||||
name: str
|
||||
clients: list[str]
|
||||
|
||||
|
||||
class ClientReference(SQLModel):
|
||||
"""Reference to a client."""
|
||||
|
||||
id: str
|
||||
name: str
|
||||
|
||||
|
||||
class ClientSecretDetailList(SQLModel):
|
||||
"""A more detailed version of the ClientSecretList."""
|
||||
|
||||
name: str
|
||||
ids: list[str] = Field(default_factory=list)
|
||||
clients: list[ClientReference] = Field(default_factory=list)
|
||||
|
||||
|
||||
class AuditInfo(SQLModel):
|
||||
"""Information about audit information."""
|
||||
|
||||
entries: int
|
||||
|
||||
Reference in New Issue
Block a user