43 lines
903 B
Python
43 lines
903 B
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from datetime import datetime
|
||
|
|
|
||
|
|
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
||
|
|
|
||
|
|
|
||
|
|
class BindingItem(BaseModel):
|
||
|
|
model_config = ConfigDict(from_attributes=True)
|
||
|
|
|
||
|
|
id: int
|
||
|
|
token_display: str
|
||
|
|
bound_ip: str
|
||
|
|
status: int
|
||
|
|
status_label: str
|
||
|
|
first_used_at: datetime
|
||
|
|
last_used_at: datetime
|
||
|
|
created_at: datetime
|
||
|
|
|
||
|
|
|
||
|
|
class BindingListResponse(BaseModel):
|
||
|
|
items: list[BindingItem]
|
||
|
|
total: int
|
||
|
|
page: int
|
||
|
|
page_size: int
|
||
|
|
|
||
|
|
|
||
|
|
class BindingActionRequest(BaseModel):
|
||
|
|
id: int = Field(gt=0)
|
||
|
|
|
||
|
|
|
||
|
|
class BindingIPUpdateRequest(BaseModel):
|
||
|
|
id: int = Field(gt=0)
|
||
|
|
bound_ip: str = Field(min_length=3, max_length=64)
|
||
|
|
|
||
|
|
@field_validator("bound_ip")
|
||
|
|
@classmethod
|
||
|
|
def validate_bound_ip(cls, value: str) -> str:
|
||
|
|
from ipaddress import ip_network
|
||
|
|
|
||
|
|
ip_network(value, strict=False)
|
||
|
|
return value
|