style: apply ruff formatting
This commit is contained in:
@@ -49,12 +49,14 @@ _GLOBAL_FIELD_TYPES: dict[str, type[Any]] = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Fields that cannot be loaded from config files (callables, complex objects)
|
# Fields that cannot be loaded from config files (callables, complex objects)
|
||||||
_NON_LOADABLE_FIELDS: frozenset[str] = frozenset({
|
_NON_LOADABLE_FIELDS: frozenset[str] = frozenset(
|
||||||
"key_extractor",
|
{
|
||||||
"exempt_when",
|
"key_extractor",
|
||||||
"on_blocked",
|
"exempt_when",
|
||||||
"backend",
|
"on_blocked",
|
||||||
})
|
"backend",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ConfigLoader:
|
class ConfigLoader:
|
||||||
@@ -200,7 +202,11 @@ class ConfigLoader:
|
|||||||
value = value.strip()
|
value = value.strip()
|
||||||
|
|
||||||
# Remove surrounding quotes if present
|
# Remove surrounding quotes if present
|
||||||
if len(value) >= 2 and value[0] == value[-1] and value[0] in ('"', "'"):
|
if (
|
||||||
|
len(value) >= 2
|
||||||
|
and value[0] == value[-1]
|
||||||
|
and value[0] in ('"', "'")
|
||||||
|
):
|
||||||
value = value[1:-1]
|
value = value[1:-1]
|
||||||
|
|
||||||
env_vars[key] = value
|
env_vars[key] = value
|
||||||
@@ -261,7 +267,7 @@ class ConfigLoader:
|
|||||||
|
|
||||||
for key, value in source.items():
|
for key, value in source.items():
|
||||||
if key.startswith(full_prefix):
|
if key.startswith(full_prefix):
|
||||||
field_name = key[len(full_prefix):].lower()
|
field_name = key[len(full_prefix) :].lower()
|
||||||
if field_name in field_types:
|
if field_name in field_types:
|
||||||
result[field_name] = value
|
result[field_name] = value
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ F = TypeVar("F", bound=Callable[..., Any])
|
|||||||
|
|
||||||
# Note: Config loader from secrets .env
|
# Note: Config loader from secrets .env
|
||||||
|
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
def rate_limit(
|
def rate_limit(
|
||||||
limit: int,
|
limit: int,
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ from fastapi_traffic.middleware import RateLimitMiddleware
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from collections.abc import AsyncGenerator, Generator
|
from collections.abc import AsyncGenerator, Generator
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -143,9 +143,7 @@ class TestConfigLoaderEnv:
|
|||||||
assert config.exempt_ips == {"127.0.0.1", "192.168.1.1", "10.0.0.1"}
|
assert config.exempt_ips == {"127.0.0.1", "192.168.1.1", "10.0.0.1"}
|
||||||
assert config.exempt_paths == {"/health", "/metrics"}
|
assert config.exempt_paths == {"/health", "/metrics"}
|
||||||
|
|
||||||
def test_load_global_config_from_env_empty_sets(
|
def test_load_global_config_from_env_empty_sets(self, loader: ConfigLoader) -> None:
|
||||||
self, loader: ConfigLoader
|
|
||||||
) -> None:
|
|
||||||
"""Test loading GlobalConfig with empty set fields."""
|
"""Test loading GlobalConfig with empty set fields."""
|
||||||
env_vars = {
|
env_vars = {
|
||||||
"FASTAPI_TRAFFIC_GLOBAL_EXEMPT_IPS": "",
|
"FASTAPI_TRAFFIC_GLOBAL_EXEMPT_IPS": "",
|
||||||
|
|||||||
Reference in New Issue
Block a user