Coverage for functions \ flipdare \ request \ request_types.py: 95%
44 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
« prev ^ index » next coverage.py v7.13.0, created at 2026-05-08 12:22 +1000
1#!/usr/bin/env python
2# Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved.
3#
4# This file is part of Flipdare's proprietary software and contains
5# confidential and copyrighted material. Unauthorised copying,
6# modification, distribution, or use of this file is strictly
7# prohibited without prior written permission from Flipdare Pty Ltd.
8#
9# This software includes third-party components licensed under MIT,
10# BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details.
11#
14from dataclasses import dataclass
15from enum import Enum
16import flask
18__all__ = ["AppHttpRequest", "AppHttpRequestType"]
21@dataclass(frozen=True, slots=True)
22class AppHttpRequest:
23 raw_request: flask.Request
24 http_type: "AppHttpRequestType"
27class _AuthType(Enum):
28 API_KEY = "API_KEY"
29 BACKEND_API_KEY = "BACKEND_API_KEY"
30 STRIPE_STATE_KEY = "STRIPE_STATE_KEY"
31 FIREBASE = "FIREBASE"
34class AppHttpRequestType(Enum):
35 UNSUBSCRIBE = ("h__unsubscribe", "POST", _AuthType.API_KEY)
36 DELETE = ("h__delete", "POST", _AuthType.API_KEY)
37 DELETE_CONFIRM = ("h__delete_confirm", "POST", _AuthType.API_KEY)
38 CONTACT = ("h__contact", "POST", _AuthType.API_KEY)
39 PING_BACKEND = ("h__ping", "POST", _AuthType.BACKEND_API_KEY)
40 PING_SEARCH = ("h__ping_search", "POST", _AuthType.BACKEND_API_KEY)
41 STRIPE_REFRESH = ("h__stripe_refresh", "GET", _AuthType.STRIPE_STATE_KEY)
42 STRIPE_RETURN = ("h__stripe_return", "GET", _AuthType.STRIPE_STATE_KEY)
44 def __init__(self, called_by: str, method: str, auth_type: _AuthType) -> None:
45 self._called_by = called_by
46 self._method = method
47 self._auth_type = auth_type
49 @property
50 def called_by(self) -> str:
51 return self._called_by
53 @property
54 def method(self) -> str:
55 return self._method
57 @property
58 def is_api_auth(self) -> bool:
59 return self._auth_type in {_AuthType.API_KEY, _AuthType.BACKEND_API_KEY}
61 @property
62 def is_firebase_auth(self) -> bool:
63 return self._auth_type == _AuthType.FIREBASE
65 @property
66 def is_stripe_auth(self) -> bool:
67 return self._auth_type == _AuthType.STRIPE_STATE_KEY
69 @property
70 def is_backend_auth(self) -> bool:
71 return self._auth_type == _AuthType.BACKEND_API_KEY