fastapi-factory-utilities 0.4.0__py3-none-any.whl → 0.8.3__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.
Potentially problematic release.
This version of fastapi-factory-utilities might be problematic. Click here for more details.
- fastapi_factory_utilities/core/api/__init__.py +1 -1
- fastapi_factory_utilities/core/api/v1/sys/health.py +1 -1
- fastapi_factory_utilities/core/app/__init__.py +4 -4
- fastapi_factory_utilities/core/app/application.py +22 -26
- fastapi_factory_utilities/core/app/builder.py +8 -32
- fastapi_factory_utilities/core/app/fastapi_builder.py +3 -2
- fastapi_factory_utilities/core/exceptions.py +64 -29
- fastapi_factory_utilities/core/plugins/__init__.py +2 -31
- fastapi_factory_utilities/core/plugins/abstracts.py +40 -0
- fastapi_factory_utilities/core/plugins/aiopika/__init__.py +25 -0
- fastapi_factory_utilities/core/plugins/aiopika/abstract.py +48 -0
- fastapi_factory_utilities/core/plugins/aiopika/configs.py +85 -0
- fastapi_factory_utilities/core/plugins/aiopika/depends.py +20 -0
- fastapi_factory_utilities/core/plugins/aiopika/exceptions.py +29 -0
- fastapi_factory_utilities/core/plugins/aiopika/exchange.py +69 -0
- fastapi_factory_utilities/core/plugins/aiopika/listener/__init__.py +7 -0
- fastapi_factory_utilities/core/plugins/aiopika/listener/abstract.py +72 -0
- fastapi_factory_utilities/core/plugins/aiopika/message.py +86 -0
- fastapi_factory_utilities/core/plugins/aiopika/plugins.py +84 -0
- fastapi_factory_utilities/core/plugins/aiopika/publisher/__init__.py +7 -0
- fastapi_factory_utilities/core/plugins/aiopika/publisher/abstract.py +66 -0
- fastapi_factory_utilities/core/plugins/aiopika/queue.py +88 -0
- fastapi_factory_utilities/core/plugins/odm_plugin/__init__.py +14 -157
- fastapi_factory_utilities/core/plugins/odm_plugin/builder.py +3 -3
- fastapi_factory_utilities/core/plugins/odm_plugin/configs.py +1 -1
- fastapi_factory_utilities/core/plugins/odm_plugin/documents.py +1 -1
- fastapi_factory_utilities/core/plugins/odm_plugin/helpers.py +16 -0
- fastapi_factory_utilities/core/plugins/odm_plugin/plugins.py +155 -0
- fastapi_factory_utilities/core/plugins/odm_plugin/repositories.py +1 -0
- fastapi_factory_utilities/core/plugins/opentelemetry_plugin/__init__.py +8 -121
- fastapi_factory_utilities/core/plugins/opentelemetry_plugin/instruments/__init__.py +85 -0
- fastapi_factory_utilities/core/plugins/opentelemetry_plugin/plugins.py +137 -0
- fastapi_factory_utilities/core/plugins/taskiq_plugins/__init__.py +31 -0
- fastapi_factory_utilities/core/plugins/taskiq_plugins/configs.py +12 -0
- fastapi_factory_utilities/core/plugins/taskiq_plugins/depends.py +51 -0
- fastapi_factory_utilities/core/plugins/taskiq_plugins/exceptions.py +13 -0
- fastapi_factory_utilities/core/plugins/taskiq_plugins/plugin.py +41 -0
- fastapi_factory_utilities/core/plugins/taskiq_plugins/schedulers.py +187 -0
- fastapi_factory_utilities/core/protocols.py +1 -54
- fastapi_factory_utilities/core/security/__init__.py +5 -0
- fastapi_factory_utilities/core/security/abstracts.py +42 -0
- fastapi_factory_utilities/core/security/jwt/__init__.py +45 -0
- fastapi_factory_utilities/core/security/jwt/configs.py +32 -0
- fastapi_factory_utilities/core/security/jwt/decoders.py +130 -0
- fastapi_factory_utilities/core/security/jwt/exceptions.py +23 -0
- fastapi_factory_utilities/core/security/jwt/objects.py +107 -0
- fastapi_factory_utilities/core/security/jwt/services.py +176 -0
- fastapi_factory_utilities/core/security/jwt/stores.py +43 -0
- fastapi_factory_utilities/core/security/jwt/types.py +9 -0
- fastapi_factory_utilities/core/security/jwt/verifiers.py +46 -0
- fastapi_factory_utilities/core/security/kratos.py +43 -43
- fastapi_factory_utilities/core/services/hydra/__init__.py +10 -3
- fastapi_factory_utilities/core/services/hydra/services.py +112 -34
- fastapi_factory_utilities/core/services/status/__init__.py +2 -2
- fastapi_factory_utilities/core/services/status/exceptions.py +1 -1
- fastapi_factory_utilities/core/utils/status.py +2 -1
- fastapi_factory_utilities/core/utils/yaml_reader.py +1 -1
- fastapi_factory_utilities/example/app.py +15 -5
- fastapi_factory_utilities/example/entities/books/__init__.py +1 -1
- fastapi_factory_utilities/example/models/books/__init__.py +1 -1
- {fastapi_factory_utilities-0.4.0.dist-info → fastapi_factory_utilities-0.8.3.dist-info}/METADATA +14 -8
- fastapi_factory_utilities-0.8.3.dist-info/RECORD +111 -0
- {fastapi_factory_utilities-0.4.0.dist-info → fastapi_factory_utilities-0.8.3.dist-info}/WHEEL +1 -1
- fastapi_factory_utilities/core/app/plugin_manager/__init__.py +0 -15
- fastapi_factory_utilities/core/app/plugin_manager/exceptions.py +0 -33
- fastapi_factory_utilities/core/app/plugin_manager/plugin_manager.py +0 -190
- fastapi_factory_utilities/core/plugins/example/__init__.py +0 -31
- fastapi_factory_utilities/core/plugins/httpx_plugin/__init__.py +0 -31
- fastapi_factory_utilities/core/security/jwt.py +0 -158
- fastapi_factory_utilities-0.4.0.dist-info/RECORD +0 -82
- {fastapi_factory_utilities-0.4.0.dist-info → fastapi_factory_utilities-0.8.3.dist-info}/entry_points.txt +0 -0
- {fastapi_factory_utilities-0.4.0.dist-info → fastapi_factory_utilities-0.8.3.dist-info/licenses}/LICENSE +0 -0
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
"""Plugin manager.
|
|
2
|
-
|
|
3
|
-
This module provides the plugin manager for the application.
|
|
4
|
-
|
|
5
|
-
Objective:
|
|
6
|
-
- Provide a way to manage plugins for the application.
|
|
7
|
-
- The plugins are activated based on the configuration.
|
|
8
|
-
- The plugins are checked for pre-conditions.
|
|
9
|
-
- The plugins are loaded on application load.
|
|
10
|
-
- The plugins are started on application startup.
|
|
11
|
-
- The plugins are stopped on application shutdown.
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
from importlib import import_module
|
|
15
|
-
from types import ModuleType
|
|
16
|
-
from typing import Self
|
|
17
|
-
|
|
18
|
-
from fastapi_factory_utilities.core.plugins import PluginsEnum, PluginState
|
|
19
|
-
from fastapi_factory_utilities.core.protocols import (
|
|
20
|
-
ApplicationAbstractProtocol,
|
|
21
|
-
PluginProtocol,
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
from .exceptions import InvalidPluginError, PluginPreConditionNotMetError
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
class PluginManager:
|
|
28
|
-
"""Plugin manager for the application."""
|
|
29
|
-
|
|
30
|
-
DEFAULT_PLUGIN_PACKAGE: str = "fastapi_factory_utilities.core.plugins"
|
|
31
|
-
|
|
32
|
-
@classmethod
|
|
33
|
-
def _import_module(cls, name: str, package: str) -> ModuleType:
|
|
34
|
-
"""Import the module. This is a wrapper around the import_module function to be able to mock it in the tests.
|
|
35
|
-
|
|
36
|
-
Args:
|
|
37
|
-
name (str): The name of the module.
|
|
38
|
-
package (str): The package of the module.
|
|
39
|
-
|
|
40
|
-
Returns:
|
|
41
|
-
ModuleType: The module.
|
|
42
|
-
|
|
43
|
-
Raises:
|
|
44
|
-
ImportError: If the module cannot be imported.
|
|
45
|
-
ModuleNotFoundError: If the module is not found.
|
|
46
|
-
"""
|
|
47
|
-
return import_module(name=f"{package}.{name}")
|
|
48
|
-
|
|
49
|
-
@classmethod
|
|
50
|
-
def _check_pre_conditions(
|
|
51
|
-
cls, plugin_package: str, want_to_activate_plugins: list[PluginsEnum], application: ApplicationAbstractProtocol
|
|
52
|
-
) -> list[PluginProtocol]:
|
|
53
|
-
"""Check the pre-conditions for the plugins.
|
|
54
|
-
|
|
55
|
-
Args:
|
|
56
|
-
plugin_package (str): The package for the plugins.
|
|
57
|
-
want_to_activate_plugins (list[PluginsEnum]): The plugins to activate.
|
|
58
|
-
application (BaseApplicationProtocol): The application.
|
|
59
|
-
|
|
60
|
-
Returns:
|
|
61
|
-
list[PluginProtocol]: The activated plugins.
|
|
62
|
-
|
|
63
|
-
Raises:
|
|
64
|
-
InvalidPluginError: If the plugin is invalid.
|
|
65
|
-
PluginPreConditionNotMetError: If the pre-conditions are not met.
|
|
66
|
-
"""
|
|
67
|
-
plugins: list[PluginProtocol] = []
|
|
68
|
-
|
|
69
|
-
for plugin_enum in want_to_activate_plugins:
|
|
70
|
-
|
|
71
|
-
try:
|
|
72
|
-
# Using a custom import function to be able to mock it in the tests.
|
|
73
|
-
plugin_module: ModuleType = cls._import_module(name=plugin_enum.value, package=plugin_package)
|
|
74
|
-
except (ImportError, ModuleNotFoundError) as import_error:
|
|
75
|
-
# TODO: Later, if we introduce extra mecanism to manage dependencies,
|
|
76
|
-
# we must handle a part of the error here. To be able to provide a better error message.
|
|
77
|
-
# For now, we just raise the error.
|
|
78
|
-
raise InvalidPluginError(
|
|
79
|
-
plugin_name=plugin_enum.value, message="Error importing the plugin "
|
|
80
|
-
) from import_error
|
|
81
|
-
|
|
82
|
-
if not isinstance(plugin_module, PluginProtocol):
|
|
83
|
-
raise InvalidPluginError(
|
|
84
|
-
plugin_name=plugin_enum.value, message="The plugin does not implement the PluginProtocol"
|
|
85
|
-
)
|
|
86
|
-
|
|
87
|
-
if not plugin_module.pre_conditions_check(application=application):
|
|
88
|
-
raise PluginPreConditionNotMetError(
|
|
89
|
-
plugin_name=plugin_enum.value, message="The pre-conditions are not met"
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
plugins.append(plugin_module)
|
|
93
|
-
|
|
94
|
-
return plugins
|
|
95
|
-
|
|
96
|
-
def __init__(self, activated: list[PluginsEnum] | None = None, plugin_package: str | None = None) -> None:
|
|
97
|
-
"""Instanciate the plugin manager."""
|
|
98
|
-
self._plugin_package: str = plugin_package or self.DEFAULT_PLUGIN_PACKAGE
|
|
99
|
-
self._plugins_wanted_to_be_activated: list[PluginsEnum] = activated or []
|
|
100
|
-
self._activated_plugins: list[PluginProtocol] = []
|
|
101
|
-
self._states: list[PluginState] = []
|
|
102
|
-
|
|
103
|
-
def activate(self, plugin: PluginsEnum) -> Self:
|
|
104
|
-
"""Activate a plugin.
|
|
105
|
-
|
|
106
|
-
Args:
|
|
107
|
-
plugin (PluginsEnum): The plugin to activate.
|
|
108
|
-
|
|
109
|
-
Returns:
|
|
110
|
-
Self: The plugin manager.
|
|
111
|
-
"""
|
|
112
|
-
self._plugins_wanted_to_be_activated.append(plugin)
|
|
113
|
-
|
|
114
|
-
return self
|
|
115
|
-
|
|
116
|
-
@property
|
|
117
|
-
def states(self) -> list[PluginState]:
|
|
118
|
-
"""Get the states."""
|
|
119
|
-
return self._states
|
|
120
|
-
|
|
121
|
-
def add_application_context(self, application: ApplicationAbstractProtocol) -> Self:
|
|
122
|
-
"""Add the application context to the plugins.
|
|
123
|
-
|
|
124
|
-
Args:
|
|
125
|
-
application (BaseApplicationProtocol): The application.
|
|
126
|
-
|
|
127
|
-
Returns:
|
|
128
|
-
Self: The plugin manager.
|
|
129
|
-
"""
|
|
130
|
-
self._application: ApplicationAbstractProtocol = application
|
|
131
|
-
|
|
132
|
-
return self
|
|
133
|
-
|
|
134
|
-
def add_states(self, states: list[PluginState]) -> Self:
|
|
135
|
-
"""Add the states to the plugin manager.
|
|
136
|
-
|
|
137
|
-
Args:
|
|
138
|
-
states (list[PluginState]): The states.
|
|
139
|
-
|
|
140
|
-
Returns:
|
|
141
|
-
Self: The plugin manager.
|
|
142
|
-
"""
|
|
143
|
-
for state in states:
|
|
144
|
-
self._states.append(state)
|
|
145
|
-
return self
|
|
146
|
-
|
|
147
|
-
def clear_states(self) -> Self:
|
|
148
|
-
"""Clear the states."""
|
|
149
|
-
self._states = []
|
|
150
|
-
return self
|
|
151
|
-
|
|
152
|
-
def load(self) -> Self:
|
|
153
|
-
"""Load the plugins.
|
|
154
|
-
|
|
155
|
-
Returns:
|
|
156
|
-
Self: The plugin manager.
|
|
157
|
-
|
|
158
|
-
Raises:
|
|
159
|
-
InvalidPluginError: If the plugin is invalid.
|
|
160
|
-
PluginPreConditionNotMetError: If the pre-conditions are not met.
|
|
161
|
-
|
|
162
|
-
"""
|
|
163
|
-
# Remove duplicates.
|
|
164
|
-
self._plugins_wanted_to_be_activated = list(set(self._plugins_wanted_to_be_activated))
|
|
165
|
-
# Check the pre-conditions for the plugins.
|
|
166
|
-
self._activated_plugins = self._check_pre_conditions(
|
|
167
|
-
plugin_package=self._plugin_package,
|
|
168
|
-
want_to_activate_plugins=self._plugins_wanted_to_be_activated,
|
|
169
|
-
application=self._application,
|
|
170
|
-
)
|
|
171
|
-
# Load from the previous check.
|
|
172
|
-
for plugin in self._activated_plugins:
|
|
173
|
-
self.add_states(states=plugin.on_load(application=self._application) or [])
|
|
174
|
-
|
|
175
|
-
return self
|
|
176
|
-
|
|
177
|
-
async def trigger_startup(self) -> Self:
|
|
178
|
-
"""Trigger the startup of the plugins."""
|
|
179
|
-
for plugin in self._activated_plugins:
|
|
180
|
-
states: list[PluginState] | None = await plugin.on_startup(application=self._application)
|
|
181
|
-
self.add_states(states=states or [])
|
|
182
|
-
|
|
183
|
-
return self
|
|
184
|
-
|
|
185
|
-
async def trigger_shutdown(self) -> Self:
|
|
186
|
-
"""Trigger the shutdown of the plugins."""
|
|
187
|
-
for plugin in self._activated_plugins:
|
|
188
|
-
await plugin.on_shutdown(application=self._application)
|
|
189
|
-
|
|
190
|
-
return self
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"""Example Plugin Module."""
|
|
2
|
-
|
|
3
|
-
from typing import TYPE_CHECKING
|
|
4
|
-
|
|
5
|
-
if TYPE_CHECKING:
|
|
6
|
-
from fastapi_factory_utilities.core.plugins import PluginState
|
|
7
|
-
from fastapi_factory_utilities.core.protocols import ApplicationAbstractProtocol
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def pre_conditions_check(application: "ApplicationAbstractProtocol") -> bool: # pylint: disable=unused-argument
|
|
11
|
-
"""Check the pre-conditions for the example plugin."""
|
|
12
|
-
return True
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def on_load(
|
|
16
|
-
application: "ApplicationAbstractProtocol", # pylint: disable=unused-argument
|
|
17
|
-
) -> list["PluginState"] | None:
|
|
18
|
-
"""Actions to perform on load for the example plugin."""
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
async def on_startup(
|
|
23
|
-
application: "ApplicationAbstractProtocol", # pylint: disable=unused-argument
|
|
24
|
-
) -> list["PluginState"] | None:
|
|
25
|
-
"""Actions to perform on startup for the example plugin."""
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
async def on_shutdown(application: "ApplicationAbstractProtocol") -> None: # pylint: disable=unused-argument
|
|
30
|
-
"""Actions to perform on shutdown for the example plugin."""
|
|
31
|
-
return
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"""Httpx Plugin Module."""
|
|
2
|
-
|
|
3
|
-
from typing import TYPE_CHECKING
|
|
4
|
-
|
|
5
|
-
if TYPE_CHECKING:
|
|
6
|
-
from fastapi_factory_utilities.core.plugins import PluginState
|
|
7
|
-
from fastapi_factory_utilities.core.protocols import ApplicationAbstractProtocol
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def pre_conditions_check(application: "ApplicationAbstractProtocol") -> bool: # pylint: disable=unused-argument
|
|
11
|
-
"""Check the pre-conditions for the example plugin."""
|
|
12
|
-
return True
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def on_load(
|
|
16
|
-
application: "ApplicationAbstractProtocol", # pylint: disable=unused-argument
|
|
17
|
-
) -> list["PluginState"] | None:
|
|
18
|
-
"""Actions to perform on load for the example plugin."""
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
async def on_startup(
|
|
23
|
-
application: "ApplicationAbstractProtocol", # pylint: disable=unused-argument
|
|
24
|
-
) -> list["PluginState"] | None:
|
|
25
|
-
"""Actions to perform on startup for the example plugin."""
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
async def on_shutdown(application: "ApplicationAbstractProtocol") -> None: # pylint: disable=unused-argument
|
|
30
|
-
"""Actions to perform on shutdown for the example plugin."""
|
|
31
|
-
return
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
"""Provides security-related functions for the API."""
|
|
2
|
-
|
|
3
|
-
from asyncio import Task, TaskGroup
|
|
4
|
-
from http import HTTPStatus
|
|
5
|
-
from typing import Any, ClassVar, NewType, cast
|
|
6
|
-
|
|
7
|
-
import jwt
|
|
8
|
-
import pydantic
|
|
9
|
-
from fastapi import Request
|
|
10
|
-
from fastapi.exceptions import HTTPException
|
|
11
|
-
from pydantic import BaseModel
|
|
12
|
-
|
|
13
|
-
Scope = NewType("Scope", str)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
class JWTBearerDecoded(BaseModel):
|
|
17
|
-
"""JWT bearer token decoded."""
|
|
18
|
-
|
|
19
|
-
model_config: ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
|
|
20
|
-
arbitrary_types_allowed=True,
|
|
21
|
-
extra="forbid",
|
|
22
|
-
frozen=True,
|
|
23
|
-
)
|
|
24
|
-
|
|
25
|
-
scopes: list[str] | None = None
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class JWTBearerAuthentication:
|
|
29
|
-
"""JWT Bearer Authentication.
|
|
30
|
-
|
|
31
|
-
This class is used to authenticate users using JWT tokens.
|
|
32
|
-
It extracts the token from the request, decodes it, and verifies its validity.
|
|
33
|
-
"""
|
|
34
|
-
|
|
35
|
-
def __init__(self, scopes: list[Scope] | None = None, jwt_raw: str | None = None) -> None:
|
|
36
|
-
"""Initialize the OAuth2 class.
|
|
37
|
-
|
|
38
|
-
Args:
|
|
39
|
-
scopes (SecurityScopes): Security scopes for the OAuth2.
|
|
40
|
-
jwt_raw (str): JWT token to be used for authentication.
|
|
41
|
-
"""
|
|
42
|
-
self.jwt_raw: str | None = jwt_raw
|
|
43
|
-
self.scopes: list[Scope] | None = scopes
|
|
44
|
-
|
|
45
|
-
def _extract_raw_token(self, request: Request) -> str:
|
|
46
|
-
"""Extract the raw token from the request.
|
|
47
|
-
|
|
48
|
-
Args:
|
|
49
|
-
request (Request): FastAPI request object.
|
|
50
|
-
|
|
51
|
-
Returns:
|
|
52
|
-
str: Raw token.
|
|
53
|
-
|
|
54
|
-
Raises:
|
|
55
|
-
HTTPException: If the token is missing or invalid.
|
|
56
|
-
"""
|
|
57
|
-
try:
|
|
58
|
-
authorization_header: str | None = request.headers.get("Authorization")
|
|
59
|
-
except (AttributeError, KeyError) as e:
|
|
60
|
-
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED, detail="Missing Credentials") from e
|
|
61
|
-
|
|
62
|
-
if not authorization_header:
|
|
63
|
-
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED, detail="Missing Credentials")
|
|
64
|
-
|
|
65
|
-
if not authorization_header.startswith("Bearer "):
|
|
66
|
-
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED, detail="Invalid Credentials")
|
|
67
|
-
|
|
68
|
-
return authorization_header.split(sep=" ")[1]
|
|
69
|
-
|
|
70
|
-
async def _decode_jwt(self, jwt_raw: str) -> JWTBearerDecoded:
|
|
71
|
-
"""Decode the JWT token.
|
|
72
|
-
|
|
73
|
-
Args:
|
|
74
|
-
jwt_raw (str): Raw JWT token.
|
|
75
|
-
|
|
76
|
-
Returns:
|
|
77
|
-
JWTBearerDecoded: Decoded JWT token.
|
|
78
|
-
|
|
79
|
-
Raises:
|
|
80
|
-
HTTPException: If the token is invalid or expired.
|
|
81
|
-
"""
|
|
82
|
-
try:
|
|
83
|
-
jwt_decoded: dict[str, Any] = cast(
|
|
84
|
-
dict[str, Any],
|
|
85
|
-
jwt.decode(
|
|
86
|
-
jwt=jwt_raw,
|
|
87
|
-
algorithms=["HS256", "RS256"],
|
|
88
|
-
options={"verify_signature": True},
|
|
89
|
-
),
|
|
90
|
-
)
|
|
91
|
-
return JWTBearerDecoded(**jwt_decoded)
|
|
92
|
-
except jwt.ExpiredSignatureError as e:
|
|
93
|
-
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED, detail="Token expired") from e
|
|
94
|
-
except jwt.InvalidTokenError as e:
|
|
95
|
-
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED, detail="Invalid token") from e
|
|
96
|
-
except pydantic.ValidationError as e:
|
|
97
|
-
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED, detail=f"Invalid token: {e.json()}") from e
|
|
98
|
-
|
|
99
|
-
async def _verify(self, jwt_raw: str) -> None:
|
|
100
|
-
"""Verify the JWT token.
|
|
101
|
-
|
|
102
|
-
Args:
|
|
103
|
-
jwt_raw (str): Raw JWT token.
|
|
104
|
-
"""
|
|
105
|
-
pass
|
|
106
|
-
|
|
107
|
-
def _has_scope(self, jwt_decoded: JWTBearerDecoded) -> None:
|
|
108
|
-
"""Check if the JWT token has the required scope.
|
|
109
|
-
|
|
110
|
-
Args:
|
|
111
|
-
jwt_decoded (JWTBearerDecoded): Decoded JWT token.
|
|
112
|
-
|
|
113
|
-
"""
|
|
114
|
-
# Just Authentication (no scopes, no authorization)
|
|
115
|
-
if not self.scopes:
|
|
116
|
-
return
|
|
117
|
-
# JWT without scopes (no authorization)
|
|
118
|
-
if not jwt_decoded.scopes:
|
|
119
|
-
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Unauthorized")
|
|
120
|
-
# Check if all required scopes are present
|
|
121
|
-
if not all(scope in jwt_decoded.scopes for scope in (self.scopes or [])):
|
|
122
|
-
raise HTTPException(status_code=HTTPStatus.FORBIDDEN, detail="Unauthorized")
|
|
123
|
-
|
|
124
|
-
# All scopes are valid (authorization)
|
|
125
|
-
return
|
|
126
|
-
|
|
127
|
-
async def __call__(self, request: Request | None = None) -> JWTBearerDecoded:
|
|
128
|
-
"""Call the JWT bearer authentication.
|
|
129
|
-
|
|
130
|
-
Args:
|
|
131
|
-
request (Request): FastAPI request object.
|
|
132
|
-
|
|
133
|
-
Returns:
|
|
134
|
-
JWTBearerDecoded: Decoded JWT token.
|
|
135
|
-
|
|
136
|
-
Raises:
|
|
137
|
-
HTTPException: If the token is missing or invalid.
|
|
138
|
-
"""
|
|
139
|
-
# Ensure that the jwt will be provided
|
|
140
|
-
# by the request or by the jwt parameter
|
|
141
|
-
if self.jwt_raw is None and request is None:
|
|
142
|
-
raise HTTPException(status_code=HTTPStatus.UNAUTHORIZED, detail="Missing Credentials")
|
|
143
|
-
jwt_raw: str = (
|
|
144
|
-
self.jwt_raw
|
|
145
|
-
if self.jwt_raw is not None
|
|
146
|
-
else self._extract_raw_token(request=request) # type: ignore[arg-type]
|
|
147
|
-
)
|
|
148
|
-
# Execute the io bound and cpu bound tasks in parallel
|
|
149
|
-
async with TaskGroup() as tg:
|
|
150
|
-
# TODO: Can be disabled by configuration (for operation purposes)
|
|
151
|
-
# Ensure that the jwt is not revoked or expired
|
|
152
|
-
tg.create_task(self._verify(jwt_raw=jwt_raw), name="verify_jwt")
|
|
153
|
-
# Ensure that the jwt is not altered or expired
|
|
154
|
-
task_decode: Task[Any] = tg.create_task(self._decode_jwt(jwt_raw=jwt_raw), name="decode_jwt")
|
|
155
|
-
# Scope Validation
|
|
156
|
-
jwt_decoded: JWTBearerDecoded = task_decode.result()
|
|
157
|
-
self._has_scope(jwt_decoded=jwt_decoded)
|
|
158
|
-
return jwt_decoded
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
fastapi_factory_utilities/__main__.py,sha256=w8o9KpyHcxGyLHmTK8ixbIqJIsB3NbIGuAMY7OfnxrA,147
|
|
2
|
-
fastapi_factory_utilities/core/__init__.py,sha256=tt5a-MgeFt_oACkc9K5xl2rynIbca9DGqsKBDEqGzto,34
|
|
3
|
-
fastapi_factory_utilities/core/api/__init__.py,sha256=eehUFVDPk07MUPIorGdC8WqDRB8NjdSy7Za55CdLrps,542
|
|
4
|
-
fastapi_factory_utilities/core/api/tags.py,sha256=3hQcTeW0FS78sPTJ2PB44dMDTSkoW-xKj7rrfKX2Lk0,154
|
|
5
|
-
fastapi_factory_utilities/core/api/v1/sys/__init__.py,sha256=mTXhpn3_KgQ1snt0-0PFmGvFr4n5srQRRADEdRSGFJM,345
|
|
6
|
-
fastapi_factory_utilities/core/api/v1/sys/health.py,sha256=IF51Z1seOFn91m3FC57U8uWfAA7c_EhhBpjbu_ly9WQ,2807
|
|
7
|
-
fastapi_factory_utilities/core/api/v1/sys/readiness.py,sha256=xIY8pQLShU7KWRtlOUK5gTDyZ8aB1KBvLczC6boT-tg,1711
|
|
8
|
-
fastapi_factory_utilities/core/app/__init__.py,sha256=IHHkcu3t-fX8vxQk12A36cE-yTjGn_PInDpL_OlRSE8,596
|
|
9
|
-
fastapi_factory_utilities/core/app/application.py,sha256=WrDXh00r_jzQTtZGeFO43lIzvDraplitejTaSJj_uFE,5091
|
|
10
|
-
fastapi_factory_utilities/core/app/builder.py,sha256=XKtJuRxvaqzNdhfNXGkyyxEH4MkZCgAUjkqYnOws8n0,4728
|
|
11
|
-
fastapi_factory_utilities/core/app/config.py,sha256=MuV4G_M4QgZWYHoulusJLv_m4Qr2php-Cg9Jum4qkNA,7303
|
|
12
|
-
fastapi_factory_utilities/core/app/enums.py,sha256=X1upnaehYU0eHExXTde5xsH-pI9q7HZDNsOEF5PApdg,226
|
|
13
|
-
fastapi_factory_utilities/core/app/exceptions.py,sha256=tQDf0_4j5xgCbku7TL7JaZGs3_bjsWG2YLBCydQJpPw,664
|
|
14
|
-
fastapi_factory_utilities/core/app/fastapi_builder.py,sha256=DgIqiCnJK6cqsG-sg4H7Pi0lkhaxOhSLQt_ksHjpjW0,2835
|
|
15
|
-
fastapi_factory_utilities/core/app/plugin_manager/__init__.py,sha256=eMfxCsk41Caw_juAawmDZHhytNI_ubXmqfRDug2AzvQ,319
|
|
16
|
-
fastapi_factory_utilities/core/app/plugin_manager/exceptions.py,sha256=CFrZvROT7mLzNpXWwDra1j08lA_7ZrSrOHN94sEEfnQ,1026
|
|
17
|
-
fastapi_factory_utilities/core/app/plugin_manager/plugin_manager.py,sha256=5E_Qp535xNJHNujZ_QRiMfIkDUy9F_3Rbjlclny5P08,6682
|
|
18
|
-
fastapi_factory_utilities/core/exceptions.py,sha256=HAd0RDJNBVc1NOcwfHQo_Xya8SCYuD9edynx3VKMYVs,1784
|
|
19
|
-
fastapi_factory_utilities/core/plugins/__init__.py,sha256=W-BCkqP0xG980980z3mc8T6Vrp1Akv4szA0PRzkUbiU,756
|
|
20
|
-
fastapi_factory_utilities/core/plugins/example/__init__.py,sha256=GF69IygLXxzrCh7VryekEWun663kKBhWtRS3w-1tzBc,1030
|
|
21
|
-
fastapi_factory_utilities/core/plugins/httpx_plugin/__init__.py,sha256=P5FUyv7mQr8RZWQ8ifkoK8GXvqSI71q2b2dm-ag2JhQ,1028
|
|
22
|
-
fastapi_factory_utilities/core/plugins/odm_plugin/__init__.py,sha256=L6iZW7beZLpvXbcXoTjP6iALEwWWymworb6Mok72s2w,5741
|
|
23
|
-
fastapi_factory_utilities/core/plugins/odm_plugin/builder.py,sha256=Wf9Geo2ayCX9no8ENJcsfLRo-zrAuZFfUJkvnb01PRk,8759
|
|
24
|
-
fastapi_factory_utilities/core/plugins/odm_plugin/configs.py,sha256=zQoJC1wLNyq2pZyFhl0bKeNsTl4y_4_82BHCCaOEjCQ,331
|
|
25
|
-
fastapi_factory_utilities/core/plugins/odm_plugin/depends.py,sha256=OcLsfTLzMBk_xFV6qsMy_-qFkiphEbbEuaHUooagxg8,730
|
|
26
|
-
fastapi_factory_utilities/core/plugins/odm_plugin/documents.py,sha256=BFQYHxHBmTacJRfhZi2OffvT_RAFvAAiDVQAa_d6Y7w,1141
|
|
27
|
-
fastapi_factory_utilities/core/plugins/odm_plugin/exceptions.py,sha256=acnKJB0lGAzDs-7-LjBap8shjP3iV1a7dw7ouPVF27o,551
|
|
28
|
-
fastapi_factory_utilities/core/plugins/odm_plugin/repositories.py,sha256=pOOADEe8mz6FuZkNzV46H8RNvi77FojJqb3bz9RQapo,11279
|
|
29
|
-
fastapi_factory_utilities/core/plugins/opentelemetry_plugin/__init__.py,sha256=4mq4a6U_nRxe3VxpHnC0FhRh0hpKO8l6QSUE7AazeBw,4689
|
|
30
|
-
fastapi_factory_utilities/core/plugins/opentelemetry_plugin/builder.py,sha256=9npQImifYAbEg0lFG7KwZ8V78SNrPoaINgd8vKitdMw,12509
|
|
31
|
-
fastapi_factory_utilities/core/plugins/opentelemetry_plugin/configs.py,sha256=pMG9leMB7rtdkdGFLIxXflV7bf9epGrrYPt2N97KZcM,3750
|
|
32
|
-
fastapi_factory_utilities/core/plugins/opentelemetry_plugin/exceptions.py,sha256=CpsHayfQpP0zghN8y5PP6TBy-cXhHoNxBR--I86gAdE,327
|
|
33
|
-
fastapi_factory_utilities/core/plugins/opentelemetry_plugin/helpers.py,sha256=qpTIzX67orJz7vy6SBIwRs24omMBoToJkhpurZRjPuk,1533
|
|
34
|
-
fastapi_factory_utilities/core/protocols.py,sha256=TzZKr_KfmTphk2LL-TD2XzxNlLbihbGM2DxWMhc5lEQ,2428
|
|
35
|
-
fastapi_factory_utilities/core/security/jwt.py,sha256=LuNVmTlONrmoKl7ghNv5JHV4qzMNOwuxJQlWgGSvBoo,5631
|
|
36
|
-
fastapi_factory_utilities/core/security/kratos.py,sha256=yP9-TkELeXRPRYE9aQRlOPlwvaUJ7VQpyAea8ucWUfg,3364
|
|
37
|
-
fastapi_factory_utilities/core/services/hydra/__init__.py,sha256=AKBYNc3zW5OsCLLeFSXqmDbWbQefHUJxstLpsXLQEUQ,369
|
|
38
|
-
fastapi_factory_utilities/core/services/hydra/exceptions.py,sha256=ePMrfZturU2IVcxOebR0CbVKKqprce_fK-4UXbPPgNI,450
|
|
39
|
-
fastapi_factory_utilities/core/services/hydra/objects.py,sha256=2CeV_4zmwwpfbXQ0TM9B_UnNkZuIRXweFP_VALBo57c,601
|
|
40
|
-
fastapi_factory_utilities/core/services/hydra/services.py,sha256=Urc98pM23OatHr_WdgrpK1U4E2qsjF1fpXo0xnNjZ60,4411
|
|
41
|
-
fastapi_factory_utilities/core/services/kratos/__init__.py,sha256=DaC29-Ol0WR5vX56IHLGDXP9UrhISq0Juhg_sJTasw4,368
|
|
42
|
-
fastapi_factory_utilities/core/services/kratos/enums.py,sha256=ULJppowlZbOjdnUIXQyI4_nHmHZoNnv7-M1CYQBYXFY,220
|
|
43
|
-
fastapi_factory_utilities/core/services/kratos/exceptions.py,sha256=xAX01-lQvPpADgcwhB5YWSy1UqAxG38s2rlU9AJBJd8,472
|
|
44
|
-
fastapi_factory_utilities/core/services/kratos/objects.py,sha256=a0npt4Q6d9UbF0w3e6EvyKLwMWO2l639_dFjruA8_2c,980
|
|
45
|
-
fastapi_factory_utilities/core/services/kratos/services.py,sha256=RFKrME6M6omWiHORMBCSyvIG0BsimQaCfnmtsOdFfsg,3158
|
|
46
|
-
fastapi_factory_utilities/core/services/status/__init__.py,sha256=N5H0cCN9ZFu_0YZar4RLdCDEjKMICrIhNtfKgB0LI78,370
|
|
47
|
-
fastapi_factory_utilities/core/services/status/enums.py,sha256=IUxWAd0Ecknri4BqzaqoDRRhT_8LdcgtQcNqgNVDXGE,599
|
|
48
|
-
fastapi_factory_utilities/core/services/status/exceptions.py,sha256=_fQFGqHKnG54Hs-ZtC4gs0xwzSH246_WwQOonraoGKw,856
|
|
49
|
-
fastapi_factory_utilities/core/services/status/health_calculator_strategies.py,sha256=p2KKJo-dq1j9iWHT0mvlBKtldH9m8l31aytLkUsb9nQ,1634
|
|
50
|
-
fastapi_factory_utilities/core/services/status/readiness_calculator_strategies.py,sha256=hA1LX2pSxva-7bVaQ0dw8NpTbl1ZWDtXd9xzqQUGUsI,1354
|
|
51
|
-
fastapi_factory_utilities/core/services/status/services.py,sha256=qtgYdnxNQMbb6q6G9uGasRO3lZcpiWNmw1padPkh6jA,8490
|
|
52
|
-
fastapi_factory_utilities/core/services/status/types.py,sha256=GJOGRra6NtpUS4q1cr4cdWR0BbIUtEwP7vQX-sXX5jQ,3297
|
|
53
|
-
fastapi_factory_utilities/core/utils/configs.py,sha256=qM0pCrsK8ZyfCoyova_VrhR4eUX3LSPCbWunGMWcSVg,2581
|
|
54
|
-
fastapi_factory_utilities/core/utils/importlib.py,sha256=DYcPo7K0s95WV5xxtucpufWsTj8Pxv25sWunDmmNUYI,797
|
|
55
|
-
fastapi_factory_utilities/core/utils/log.py,sha256=6V9CL3bQio4e47YxcSXM2JQRGhVxuBfmcEbcF4RtCfQ,6393
|
|
56
|
-
fastapi_factory_utilities/core/utils/status.py,sha256=1zxur98Wfum3JzpuzoAPoRIwQmXhFsTS2oxgbn5uFfg,1933
|
|
57
|
-
fastapi_factory_utilities/core/utils/uvicorn.py,sha256=XThylG-nOPVL00w6MIWGODnweoM7VxmpSFcyoPcmqns,2609
|
|
58
|
-
fastapi_factory_utilities/core/utils/yaml_reader.py,sha256=KNlwHvpraAp04JjeXSSk72BLuILH3lhEKrmRaUUgo2k,6103
|
|
59
|
-
fastapi_factory_utilities/example/__init__.py,sha256=LEKnPTBcgDyfHeOjlVxjK5lFdFqS-7-mHDuVuM2Jh_Y,206
|
|
60
|
-
fastapi_factory_utilities/example/__main__.py,sha256=Iwp_6rK7Lcv2F-XAKn6xjxQHOWjx2OjgwKAr91tfUfk,135
|
|
61
|
-
fastapi_factory_utilities/example/api/__init__.py,sha256=qI82eeSwVjR6jSkX1pxm8ALv9WPQ_iHurFY4G2K7VzE,554
|
|
62
|
-
fastapi_factory_utilities/example/api/books/__init__.py,sha256=zXARBnjywJwg1XsLbcixYWcHH4uC9mF-kbbX4P8cVgA,160
|
|
63
|
-
fastapi_factory_utilities/example/api/books/responses.py,sha256=21WeD6bdg0MCD_0vRHwmsL4W79iDcG9NnDLemXysc84,540
|
|
64
|
-
fastapi_factory_utilities/example/api/books/routes.py,sha256=bwg8Bhvoj9vx2SdwunzFS-Z3cHECtjl_yGdo8MfiGEM,1529
|
|
65
|
-
fastapi_factory_utilities/example/app.py,sha256=mcXQOg0A74mc8xFT0XuRHne3YjXXI7dTMV48G_Ypng8,1555
|
|
66
|
-
fastapi_factory_utilities/example/application.yaml,sha256=5xRyFSuMxmgZ5Mikai94UqKYJ7PxJp8omlXobTjv14M,485
|
|
67
|
-
fastapi_factory_utilities/example/entities/books/__init__.py,sha256=q2UTwLyCs3te38n7RgwT0go3Hp0bE9-NvoX7P-DR-3o,185
|
|
68
|
-
fastapi_factory_utilities/example/entities/books/entities.py,sha256=rLE01lE7U6WizrD5ZHMRwkynd8_dWF6DltBFH61f-Do,405
|
|
69
|
-
fastapi_factory_utilities/example/entities/books/enums.py,sha256=lXYUvhIkT1pi0teflMpnqeafeiBZMokyWxoFLgzV6a8,330
|
|
70
|
-
fastapi_factory_utilities/example/entities/books/types.py,sha256=7LYGPu-CcI3noIORJyIZlVF-CBugWPXEqgDzWrO3XmQ,1558
|
|
71
|
-
fastapi_factory_utilities/example/models/__init__.py,sha256=RJmp3R9bhbQv7n0WOlsHP65LqbEs_DjF9hzYKwYTRGo,22
|
|
72
|
-
fastapi_factory_utilities/example/models/books/__init__.py,sha256=1GJFCYMGZugQRxlFl-q7fPBFvNsl2ykeW8lV7rpURHU,181
|
|
73
|
-
fastapi_factory_utilities/example/models/books/document.py,sha256=lYJfMGr5GqEEsn7L--PFs75hC2q-jQx77wl7EhTrp5U,568
|
|
74
|
-
fastapi_factory_utilities/example/models/books/repository.py,sha256=7K63uAsSEGZ2EXqufU4Tc8KpymgXK8JX8WjAE2Sw8ok,387
|
|
75
|
-
fastapi_factory_utilities/example/services/books/__init__.py,sha256=Z06yNRoA7Zg3TGN-Q9rrvJg6Bbx-qJw661MVwukV6vQ,148
|
|
76
|
-
fastapi_factory_utilities/example/services/books/services.py,sha256=-x7d4hotUWLzWo5uImMjFmtNcSTHwWv2bfttIbYYKbA,5380
|
|
77
|
-
fastapi_factory_utilities/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
78
|
-
fastapi_factory_utilities-0.4.0.dist-info/LICENSE,sha256=iO1nLzMMst6vEiqgSUrfrbetM7b0bvdzXhbed5tqG8o,1074
|
|
79
|
-
fastapi_factory_utilities-0.4.0.dist-info/METADATA,sha256=BKswnNy_dt9__jBRcefkF5Ol2AxoI1TMDUs_UQ8_L-M,3478
|
|
80
|
-
fastapi_factory_utilities-0.4.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
81
|
-
fastapi_factory_utilities-0.4.0.dist-info/entry_points.txt,sha256=IK0VcBexXo4uXQmTrbfhhnnfq4GmXPRn0GBB8hzlsq4,101
|
|
82
|
-
fastapi_factory_utilities-0.4.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|