added validation, tawhiri request creation
This commit is contained in:
parent
456551cd4e
commit
2aef4d4756
12 changed files with 184 additions and 18 deletions
31
api/validators.py
Normal file
31
api/validators.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import base64
|
||||
import json
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
def rate_clip(rate):
|
||||
"""Ограничивает допустимые значения скорости (например, 0.1 ≤ x ≤ 100)"""
|
||||
return min(max(rate, 0.1), 100.0)
|
||||
|
||||
|
||||
def _rfc3339_to_timestamp(value):
|
||||
"""Парсинг RFC 3339 строки в datetime"""
|
||||
return datetime.fromisoformat(value.replace("Z", "+00:00"))
|
||||
|
||||
|
||||
def base64_to_curve(encoded):
|
||||
"""Декодирует base64-encoded curve"""
|
||||
try:
|
||||
decoded = base64.b64decode(encoded).decode('utf-8')
|
||||
return json.loads(decoded)
|
||||
except Exception as e:
|
||||
raise ValueError(f"Invalid curve format: {e}")
|
||||
|
||||
|
||||
def validate_custom_curve(curve):
|
||||
"""Проверяет, что curve имеет ожидаемую структуру (например, список точек)"""
|
||||
try:
|
||||
points = base64_to_curve(curve)
|
||||
return isinstance(points, list) and all(isinstance(p, list) and len(p) == 2 for p in points)
|
||||
except Exception:
|
||||
return False
|
||||
Loading…
Add table
Add a link
Reference in a new issue