[UP] api_manager.py + data_models.py
This commit is contained in:
parent
7867b8cf60
commit
448ba89d59
2 changed files with 52 additions and 0 deletions
|
|
@ -57,6 +57,10 @@ class AsteriskManagerClient:
|
||||||
response = await self._request('GET', f'/sip/{account_id}')
|
response = await self._request('GET', f'/sip/{account_id}')
|
||||||
return SIPAccount(**response)
|
return SIPAccount(**response)
|
||||||
|
|
||||||
|
async def update_sip_account(self, account_id: int, data: SIPAccountIn):
|
||||||
|
response = await self._request('PATCH', f'/sip/{account_id}', json=data.model_dump(exclude_unset=True, exclude_none=True))
|
||||||
|
return SIPAccount(**response)
|
||||||
|
|
||||||
async def set_sip_register_status(self, account_id: int, is_registered: bool):
|
async def set_sip_register_status(self, account_id: int, is_registered: bool):
|
||||||
data = {"is_registered": is_registered}
|
data = {"is_registered": is_registered}
|
||||||
response = await self._request('PATCH', f'/sip/{account_id}', json=data)
|
response = await self._request('PATCH', f'/sip/{account_id}', json=data)
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,54 @@ class SIPAccount(BaseModel):
|
||||||
extra = "ignore"
|
extra = "ignore"
|
||||||
from_attributes = True
|
from_attributes = True
|
||||||
|
|
||||||
|
class SIPAccountIn(BaseModel):
|
||||||
|
"""
|
||||||
|
SIP-аккаунт.
|
||||||
|
"""
|
||||||
|
owner_id: Optional[int]
|
||||||
|
name: Optional[str]
|
||||||
|
is_registered: Optional[bool]
|
||||||
|
username: Optional[str]
|
||||||
|
password: Optional[str]
|
||||||
|
|
||||||
|
server_url: Optional[str]
|
||||||
|
port: Optional[int]
|
||||||
|
internal_number: Optional[str]
|
||||||
|
endpoint_name: Optional[str]
|
||||||
|
|
||||||
|
@validator("username")
|
||||||
|
def validate_username(cls, v):
|
||||||
|
if v and len(v) > 40:
|
||||||
|
raise ValueError("Username too long (max 40 characters)")
|
||||||
|
return v
|
||||||
|
|
||||||
|
@validator("name")
|
||||||
|
def validate_name(cls, v):
|
||||||
|
if v and len(v) > 255:
|
||||||
|
raise ValueError("Name too long (max 255 characters)")
|
||||||
|
return v
|
||||||
|
|
||||||
|
@validator("internal_number")
|
||||||
|
def validate_internal_number(cls, v):
|
||||||
|
if v and len(v) > 255:
|
||||||
|
raise ValueError("Internal number too long (max 255 characters)")
|
||||||
|
return v
|
||||||
|
|
||||||
|
@validator("endpoint_name")
|
||||||
|
def validate_endpoint_name(cls, v):
|
||||||
|
if v and len(v) > 255:
|
||||||
|
raise ValueError("Endpoint name too long (max 255 characters)")
|
||||||
|
return v
|
||||||
|
|
||||||
|
@validator("port")
|
||||||
|
def validate_port(cls, v):
|
||||||
|
if v is not None and not (0 <= v <= 65535):
|
||||||
|
raise ValueError("Port must be between 0 and 65535")
|
||||||
|
return v
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
extra = "ignore"
|
||||||
|
from_attributes = True
|
||||||
|
|
||||||
|
|
||||||
class AccessResponse(BaseModel):
|
class AccessResponse(BaseModel):
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue