Complete admin
This commit is contained in:
55
packages/sshecret-admin/src/sshecret_admin/view_models.py
Normal file
55
packages/sshecret-admin/src/sshecret_admin/view_models.py
Normal file
@ -0,0 +1,55 @@
|
||||
"""Models for the API."""
|
||||
|
||||
from typing import Annotated
|
||||
from pydantic import AfterValidator, BaseModel, Field, IPvAnyAddress, IPvAnyNetwork
|
||||
from .crypto import validate_public_key
|
||||
from .backend import Client
|
||||
|
||||
|
||||
def public_key_validator(value: str) -> str:
|
||||
"""Public key validator."""
|
||||
if validate_public_key(value):
|
||||
return value
|
||||
raise ValueError("Error: Public key must be a valid RSA public key.")
|
||||
|
||||
class SecretListView(BaseModel):
|
||||
"""Model containing a list of all available secrets."""
|
||||
|
||||
name: str
|
||||
clients: list[str] = Field(default_factory=list) # Clients that have access to it.
|
||||
|
||||
|
||||
class SecretView(BaseModel):
|
||||
"""Model containing a secret, including its clear-text value."""
|
||||
|
||||
name: str
|
||||
secret: str
|
||||
clients: list[str] = Field(default_factory=list) # Clients that have access to it.
|
||||
|
||||
|
||||
class UpdateKeyModel(BaseModel):
|
||||
"""Model for updating client public key."""
|
||||
|
||||
public_key: Annotated[str, AfterValidator(public_key_validator)]
|
||||
|
||||
|
||||
class UpdateKeyResponse(BaseModel):
|
||||
"""Response model after updating the public key."""
|
||||
|
||||
public_key: str
|
||||
updated_secrets: list[str] = Field(default_factory=list)
|
||||
detail: str | None = None
|
||||
|
||||
|
||||
class UpdatePoliciesRequest(BaseModel):
|
||||
"""Update policy request."""
|
||||
|
||||
sources: list[IPvAnyAddress | IPvAnyNetwork]
|
||||
|
||||
|
||||
class ClientCreate(BaseModel):
|
||||
"""Model to create a client."""
|
||||
|
||||
name: str
|
||||
public_key: Annotated[str, AfterValidator(public_key_validator)]
|
||||
sources: list[IPvAnyAddress | IPvAnyNetwork] = Field(default_factory=list)
|
||||
Reference in New Issue
Block a user