nexo-schemas 0.0.16__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nexo/schemas/__init__.py +0 -0
- nexo/schemas/application.py +292 -0
- nexo/schemas/connection.py +134 -0
- nexo/schemas/data.py +27 -0
- nexo/schemas/document.py +237 -0
- nexo/schemas/error/__init__.py +476 -0
- nexo/schemas/error/constants.py +50 -0
- nexo/schemas/error/descriptor.py +354 -0
- nexo/schemas/error/enums.py +40 -0
- nexo/schemas/error/metadata.py +15 -0
- nexo/schemas/error/spec.py +312 -0
- nexo/schemas/exception/__init__.py +0 -0
- nexo/schemas/exception/exc.py +911 -0
- nexo/schemas/exception/factory.py +1928 -0
- nexo/schemas/exception/handlers.py +110 -0
- nexo/schemas/google.py +14 -0
- nexo/schemas/key/__init__.py +0 -0
- nexo/schemas/key/rsa.py +131 -0
- nexo/schemas/metadata.py +21 -0
- nexo/schemas/mixins/__init__.py +0 -0
- nexo/schemas/mixins/filter.py +140 -0
- nexo/schemas/mixins/general.py +65 -0
- nexo/schemas/mixins/hierarchy.py +19 -0
- nexo/schemas/mixins/identity.py +387 -0
- nexo/schemas/mixins/parameter.py +50 -0
- nexo/schemas/mixins/service.py +40 -0
- nexo/schemas/mixins/sort.py +111 -0
- nexo/schemas/mixins/timestamp.py +192 -0
- nexo/schemas/model.py +240 -0
- nexo/schemas/operation/__init__.py +0 -0
- nexo/schemas/operation/action/__init__.py +9 -0
- nexo/schemas/operation/action/base.py +14 -0
- nexo/schemas/operation/action/resource.py +371 -0
- nexo/schemas/operation/action/status.py +8 -0
- nexo/schemas/operation/action/system.py +6 -0
- nexo/schemas/operation/action/websocket.py +6 -0
- nexo/schemas/operation/base.py +289 -0
- nexo/schemas/operation/constants.py +18 -0
- nexo/schemas/operation/context.py +68 -0
- nexo/schemas/operation/dependency.py +26 -0
- nexo/schemas/operation/enums.py +168 -0
- nexo/schemas/operation/extractor.py +36 -0
- nexo/schemas/operation/mixins.py +53 -0
- nexo/schemas/operation/request.py +1066 -0
- nexo/schemas/operation/resource.py +839 -0
- nexo/schemas/operation/system.py +55 -0
- nexo/schemas/operation/websocket.py +55 -0
- nexo/schemas/pagination.py +67 -0
- nexo/schemas/parameter.py +60 -0
- nexo/schemas/payload.py +116 -0
- nexo/schemas/resource.py +64 -0
- nexo/schemas/response.py +1041 -0
- nexo/schemas/security/__init__.py +0 -0
- nexo/schemas/security/api_key.py +63 -0
- nexo/schemas/security/authentication.py +848 -0
- nexo/schemas/security/authorization.py +922 -0
- nexo/schemas/security/enums.py +32 -0
- nexo/schemas/security/impersonation.py +179 -0
- nexo/schemas/security/token.py +402 -0
- nexo/schemas/security/types.py +17 -0
- nexo/schemas/success/__init__.py +0 -0
- nexo/schemas/success/descriptor.py +100 -0
- nexo/schemas/success/enums.py +23 -0
- nexo/schemas/user_agent.py +46 -0
- nexo_schemas-0.0.16.dist-info/METADATA +87 -0
- nexo_schemas-0.0.16.dist-info/RECORD +69 -0
- nexo_schemas-0.0.16.dist-info/WHEEL +5 -0
- nexo_schemas-0.0.16.dist-info/licenses/LICENSE +21 -0
- nexo_schemas-0.0.16.dist-info/top_level.txt +1 -0
|
File without changes
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import re
|
|
2
|
+
from enum import StrEnum
|
|
3
|
+
from nexo.enums.environment import Environment
|
|
4
|
+
from nexo.types.string import ListOfStrs
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class APIKeyType(StrEnum):
|
|
8
|
+
SYSTEM = "sak"
|
|
9
|
+
TENANT = "tak"
|
|
10
|
+
|
|
11
|
+
@classmethod
|
|
12
|
+
def choices(cls) -> ListOfStrs:
|
|
13
|
+
return [e.value for e in cls]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
KEY_BODY_PATTERN = re.compile(r"^[A-Za-z0-9_-]{32,256}$")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def validate(api_key: str, application: str, environment: Environment):
|
|
20
|
+
components = api_key.split("-", maxsplit=3)
|
|
21
|
+
|
|
22
|
+
# Validate components count
|
|
23
|
+
if len(components) != 4:
|
|
24
|
+
raise ValueError("API Key must have excatly four components")
|
|
25
|
+
|
|
26
|
+
# Ensure 'maleo' exist
|
|
27
|
+
if components[0] != application:
|
|
28
|
+
raise ValueError(
|
|
29
|
+
f"API Key must start with '{application}' as the first component"
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
# Ensure valid environment
|
|
33
|
+
api_key_environment = components[1]
|
|
34
|
+
if api_key_environment not in [e.value for e in Environment]:
|
|
35
|
+
raise ValueError(
|
|
36
|
+
f"Unknown enviromnent in API Key second component: {api_key_environment}"
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
api_key_environment = Environment(api_key_environment)
|
|
40
|
+
|
|
41
|
+
if environment is Environment.LOCAL:
|
|
42
|
+
if api_key_environment not in (Environment.LOCAL, Environment.STAGING):
|
|
43
|
+
raise ValueError(
|
|
44
|
+
"Only local and staging API Key can be used in local environment"
|
|
45
|
+
)
|
|
46
|
+
elif environment is Environment.STAGING:
|
|
47
|
+
if api_key_environment is not Environment.STAGING:
|
|
48
|
+
raise ValueError("Only staging API Key can be used in staging environment")
|
|
49
|
+
elif environment is Environment.PRODUCTION:
|
|
50
|
+
if api_key_environment is not Environment.PRODUCTION:
|
|
51
|
+
raise ValueError(
|
|
52
|
+
"Only production API Key can be used in production environment"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
# Ensure valid type
|
|
56
|
+
api_key_type = components[2]
|
|
57
|
+
if api_key_type not in [t.value for t in APIKeyType]:
|
|
58
|
+
raise ValueError(f"Unknown type in API Key third component: {api_key_type}")
|
|
59
|
+
|
|
60
|
+
# Validate key body
|
|
61
|
+
key_body = components[3]
|
|
62
|
+
if not KEY_BODY_PATTERN.match(key_body):
|
|
63
|
+
raise ValueError(f"Invalid API Key body format: {key_body!r}")
|