Skeleton contracts / contracts (pull_request) Canceled after 0s
Закрывает обязательный минимум и трек 1: ротация leaf и секрета, sealed OpenBao и сохранность queued-задачи.
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
class AppError(Exception):
|
|
def __init__(self, status, code, message, headers=None):
|
|
super().__init__(message)
|
|
self.status = status
|
|
self.code = code
|
|
self.message = message
|
|
self.headers = headers or {}
|
|
|
|
|
|
def bad_request(message="Неверный запрос"):
|
|
return AppError(400, "invalid_request", message)
|
|
|
|
|
|
def unauthorized(challenge):
|
|
return AppError(
|
|
401,
|
|
"unauthorized",
|
|
"Требуется аутентификация",
|
|
{"WWW-Authenticate": challenge},
|
|
)
|
|
|
|
|
|
def not_found():
|
|
return AppError(404, "not_found", "Объект не найден")
|
|
|
|
|
|
def conflict(message="Конфликт"):
|
|
return AppError(409, "conflict", message)
|
|
|
|
|
|
def too_large(message="Слишком большой объект"):
|
|
return AppError(413, "payload_too_large", message)
|
|
|
|
|
|
def unsupported(message="Неподдерживаемый тип изображения"):
|
|
return AppError(415, "unsupported_media_type", message)
|
|
|
|
|
|
def unavailable(message="Сервис временно недоступен"):
|
|
return AppError(503, "unavailable", message)
|
|
|
|
|
|
def rate_limited(retry_after):
|
|
return AppError(
|
|
429,
|
|
"rate_limited",
|
|
"Слишком много попыток входа",
|
|
{"Retry-After": str(int(retry_after))},
|
|
)
|