Compare commits
3 commits
c0670b2f18
...
7867b8cf60
| Author | SHA1 | Date | |
|---|---|---|---|
| 7867b8cf60 | |||
| e64c1a22a6 | |||
| 2400dfecc3 |
2 changed files with 6 additions and 47 deletions
|
|
@ -29,6 +29,7 @@ class AsteriskManagerClient:
|
|||
headers = kwargs.get('headers', {})
|
||||
if self.token:
|
||||
headers['Authorization'] = f'Bearer {self.token}'
|
||||
kwargs['headers'] = headers
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.request(method, f"{self.base_url}{endpoint}", **kwargs) as response:
|
||||
if response.status >= 400:
|
||||
|
|
|
|||
|
|
@ -6,41 +6,17 @@ class User(BaseModel):
|
|||
id: Optional[int] = Field(description="Идентификатор (автоматический)", default=None)
|
||||
username: str = Field(max_length=150, description="Пользовательское имя", example="john_doe")
|
||||
#password: str = Field(max_length=255, description="Пароль", example="secret123")
|
||||
email: str = Field(max_length=254, default="", description="Электронная почта", example="john@example.com")
|
||||
first_name: str = Field(max_length=150, default="", description="Имя", example="John")
|
||||
last_name: str = Field(max_length=150, default="", description="Фамилия", example="Doe")
|
||||
email: Optional[str] = Field(max_length=254, default="", description="Электронная почта", example="john@example.com")
|
||||
first_name: Optional[str] = Field(max_length=150, default="", description="Имя", example="John")
|
||||
last_name: Optional[str] = Field(max_length=150, default="", description="Фамилия", example="Doe")
|
||||
#is_staff: bool = Field(default=False, description="Статус администратора")
|
||||
#is_active: bool = Field(default=False, description="Активен")
|
||||
#is_superuser: bool = Field(default=False, description="Суперпользователь")
|
||||
#date_joined: str = Field(description="Дата создания", example="2024-01-01T12:00:00")
|
||||
#last_login: Optional[str] = Field(null=True, default=None, description="Последний вход")
|
||||
|
||||
@validator("email")
|
||||
def validate_email(cls, v):
|
||||
if v and "@" not in v or "." not in v:
|
||||
raise ValueError("Некорректный email")
|
||||
return v
|
||||
|
||||
@validator("username")
|
||||
def validate_username(cls, v):
|
||||
if len(v) > 150:
|
||||
raise ValueError("Имя пользователя слишком длинное (максимум 150 символов)")
|
||||
return v
|
||||
|
||||
@validator("first_name")
|
||||
def validate_first_name(cls, v):
|
||||
if v and len(v) > 150:
|
||||
raise ValueError("Имя слишком длинное (максимум 150 символов)")
|
||||
return v
|
||||
|
||||
@validator("last_name")
|
||||
def validate_last_name(cls, v):
|
||||
if v and len(v) > 150:
|
||||
raise ValueError("Фамилия слишком длинная (максимум 150 символов)")
|
||||
return v
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
extra = "ignore"
|
||||
from_attributes = True
|
||||
|
||||
|
||||
|
|
@ -69,24 +45,6 @@ class SIPAccount(BaseModel):
|
|||
internal_number: Optional[str] = Field(max_length=255, null=True, blank=True, description="Внутренний номер")
|
||||
endpoint_name: Optional[str] = Field(max_length=255, null=True, blank=True, description="Имя конечной точки")
|
||||
|
||||
@validator("server_url")
|
||||
def validate_server_url(cls, v):
|
||||
if not v:
|
||||
return v
|
||||
# Проверяем, содержит ли строка URL (в формате http:// или https://)
|
||||
if v.startswith("http://") or v.startswith("https://"):
|
||||
return v
|
||||
# Проверяем, является ли это IPv4 (простая проверкаDetails)
|
||||
parts = v.strip().split(':')
|
||||
if len(parts) == 1:
|
||||
ip_part = parts[0]
|
||||
if re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$", ip_part):
|
||||
# Проверяем, что каждая часть от 0 до 255
|
||||
ip_parts = [int(x) for x in ip_part.split('.')]
|
||||
if all(0 <= part <= 255 for part in ip_parts):
|
||||
return v
|
||||
raise ValueError("Invalid server URL format (must be http(s):// or IPv4 address)")
|
||||
|
||||
@validator("username")
|
||||
def validate_username(cls, v):
|
||||
if len(v) > 40:
|
||||
|
|
@ -118,7 +76,7 @@ class SIPAccount(BaseModel):
|
|||
return v
|
||||
|
||||
class Config:
|
||||
extra = "forbid"
|
||||
extra = "ignore"
|
||||
from_attributes = True
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue