ursaproxy 0.1.2__py3-none-any.whl → 0.2.0__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.
- ursaproxy/config.py +62 -3
- {ursaproxy-0.1.2.dist-info → ursaproxy-0.2.0.dist-info}/METADATA +1 -1
- {ursaproxy-0.1.2.dist-info → ursaproxy-0.2.0.dist-info}/RECORD +5 -5
- {ursaproxy-0.1.2.dist-info → ursaproxy-0.2.0.dist-info}/WHEEL +0 -0
- {ursaproxy-0.1.2.dist-info → ursaproxy-0.2.0.dist-info}/entry_points.txt +0 -0
ursaproxy/config.py
CHANGED
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
from pydantic import field_validator
|
|
2
|
-
from pydantic_settings import
|
|
2
|
+
from pydantic_settings import (
|
|
3
|
+
BaseSettings,
|
|
4
|
+
PydanticBaseSettingsSource,
|
|
5
|
+
SettingsConfigDict,
|
|
6
|
+
TomlConfigSettingsSource,
|
|
7
|
+
)
|
|
3
8
|
|
|
4
9
|
|
|
5
10
|
class Settings(BaseSettings):
|
|
6
|
-
"""Configuration from environment variables.
|
|
11
|
+
"""Configuration from ursaproxy.toml file and/or environment variables.
|
|
12
|
+
|
|
13
|
+
Settings are loaded in this priority order (highest to lowest):
|
|
14
|
+
1. Environment variables (e.g., BEARBLOG_URL)
|
|
15
|
+
2. ursaproxy.toml file in current directory
|
|
16
|
+
3. Default values
|
|
17
|
+
|
|
18
|
+
Example ursaproxy.toml:
|
|
19
|
+
bearblog_url = "https://example.bearblog.dev"
|
|
20
|
+
blog_name = "My Blog"
|
|
21
|
+
pages = { about = "About Me", now = "Now" }
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
model_config = SettingsConfigDict(
|
|
25
|
+
toml_file="ursaproxy.toml",
|
|
26
|
+
)
|
|
7
27
|
|
|
8
28
|
# Required: the Bearblog URL to proxy
|
|
9
29
|
bearblog_url: str
|
|
@@ -26,6 +46,24 @@ class Settings(BaseSettings):
|
|
|
26
46
|
cert_file: str | None = None
|
|
27
47
|
key_file: str | None = None
|
|
28
48
|
|
|
49
|
+
@classmethod
|
|
50
|
+
def settings_customise_sources(
|
|
51
|
+
cls,
|
|
52
|
+
settings_cls: type[BaseSettings],
|
|
53
|
+
init_settings: PydanticBaseSettingsSource,
|
|
54
|
+
env_settings: PydanticBaseSettingsSource,
|
|
55
|
+
dotenv_settings: PydanticBaseSettingsSource,
|
|
56
|
+
file_secret_settings: PydanticBaseSettingsSource,
|
|
57
|
+
) -> tuple[PydanticBaseSettingsSource, ...]:
|
|
58
|
+
"""Configure settings sources with TOML file support.
|
|
59
|
+
|
|
60
|
+
Priority (highest to lowest): env vars -> TOML file -> defaults.
|
|
61
|
+
"""
|
|
62
|
+
return (
|
|
63
|
+
env_settings,
|
|
64
|
+
TomlConfigSettingsSource(settings_cls),
|
|
65
|
+
)
|
|
66
|
+
|
|
29
67
|
@field_validator("bearblog_url")
|
|
30
68
|
@classmethod
|
|
31
69
|
def normalize_url(cls, v: str) -> str:
|
|
@@ -36,4 +74,25 @@ class Settings(BaseSettings):
|
|
|
36
74
|
return v
|
|
37
75
|
|
|
38
76
|
|
|
39
|
-
|
|
77
|
+
def _load_settings() -> Settings:
|
|
78
|
+
"""Load settings, handling missing TOML file gracefully."""
|
|
79
|
+
try:
|
|
80
|
+
return Settings() # type: ignore[call-arg]
|
|
81
|
+
except FileNotFoundError:
|
|
82
|
+
# No TOML file - disable TOML source and rely on env vars only
|
|
83
|
+
class _EnvOnlySettings(Settings):
|
|
84
|
+
@classmethod
|
|
85
|
+
def settings_customise_sources(
|
|
86
|
+
cls,
|
|
87
|
+
settings_cls: type[BaseSettings],
|
|
88
|
+
init_settings: PydanticBaseSettingsSource,
|
|
89
|
+
env_settings: PydanticBaseSettingsSource,
|
|
90
|
+
dotenv_settings: PydanticBaseSettingsSource,
|
|
91
|
+
file_secret_settings: PydanticBaseSettingsSource,
|
|
92
|
+
) -> tuple[PydanticBaseSettingsSource, ...]:
|
|
93
|
+
return (env_settings,)
|
|
94
|
+
|
|
95
|
+
return _EnvOnlySettings() # type: ignore[call-arg]
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
settings = _load_settings()
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
ursaproxy/__init__.py,sha256=bO2ym_YzTMOUVBbqTjXWWI0ZQqRc81HnZ2o0JBkkZso,5777
|
|
2
2
|
ursaproxy/cache.py,sha256=Q5cypE91xGte1ph-_NqcEwZ0NoT7_LszYT1DVpfd2bM,1205
|
|
3
|
-
ursaproxy/config.py,sha256=
|
|
3
|
+
ursaproxy/config.py,sha256=j9QOFB1a-VaEYkr_stuxFPyG5D7dKY10h5YBQTNYMjs,3191
|
|
4
4
|
ursaproxy/converter.py,sha256=FAW0fA7a3WtlPYMtZbDlsM0Gl7twXK73DAV911R7SPI,1955
|
|
5
5
|
ursaproxy/fetcher.py,sha256=1Bsm96QYjnKQMorS2xwp9e3WRq8GbA6tKZrs1Z4ObOM,1591
|
|
6
6
|
ursaproxy/templates/about.gmi,sha256=hJxK25i9uXr2geBo1HrdkLztqkebICDy-_bdnQ4jlGI,105
|
|
7
7
|
ursaproxy/templates/feed.xml,sha256=0aiFNOfgHeMH0427LPc58pEf0NdvcDHIRa-x9tc_Ty8,597
|
|
8
8
|
ursaproxy/templates/index.gmi,sha256=2J-1lQRcwoxr46bqasW969RPpo_X5n2sh9sVuXIMdFg,265
|
|
9
9
|
ursaproxy/templates/post.gmi,sha256=DMPbqZl52v-G-6wmwbXh15kg8dYpTDUx3mfqkce-HhQ,133
|
|
10
|
-
ursaproxy-0.
|
|
11
|
-
ursaproxy-0.
|
|
12
|
-
ursaproxy-0.
|
|
13
|
-
ursaproxy-0.
|
|
10
|
+
ursaproxy-0.2.0.dist-info/WHEEL,sha256=iHtWm8nRfs0VRdCYVXocAWFW8ppjHL-uTJkAdZJKOBM,80
|
|
11
|
+
ursaproxy-0.2.0.dist-info/entry_points.txt,sha256=uM3A9bQS-p_6VhWbkFRtob2oN-SuBboJWS3ZwCjlAFk,46
|
|
12
|
+
ursaproxy-0.2.0.dist-info/METADATA,sha256=zwq7-OQSXqWywFSbsiMR0oDuveuPIGzfiqRglvVJZUc,4781
|
|
13
|
+
ursaproxy-0.2.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|