This commit is contained in:
parent
89d38f493b
commit
969921dd79
@ -1,5 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
from typing import Annotated, Self
|
from typing import Annotated, Self, cast
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from pydantic import BaseModel, Field, model_validator
|
from pydantic import BaseModel, Field, model_validator
|
||||||
@ -20,7 +20,7 @@ class _ComponentConfig(BaseModel):
|
|||||||
server: str
|
server: str
|
||||||
|
|
||||||
# The component's secret.
|
# The component's secret.
|
||||||
secret: str | None = Field(default=None)
|
secret_plain: str | None = Field(default=None, alias="secret")
|
||||||
|
|
||||||
# Optional file to read the secret from
|
# Optional file to read the secret from
|
||||||
secret_file: str | None = Field(default=None)
|
secret_file: str | None = Field(default=None)
|
||||||
@ -35,6 +35,16 @@ class _ComponentConfig(BaseModel):
|
|||||||
)
|
)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@property
|
||||||
|
def secret(self) -> str:
|
||||||
|
"""
|
||||||
|
The component secret.
|
||||||
|
|
||||||
|
The backing may be None if secret_file is used instead. secret_plain is, however, replaced
|
||||||
|
with that file's contents during configuration loading.
|
||||||
|
"""
|
||||||
|
return cast(str, self.secret_plain)
|
||||||
|
|
||||||
|
|
||||||
class _Config(BaseModel):
|
class _Config(BaseModel):
|
||||||
# DB URI for sqlmodel
|
# DB URI for sqlmodel
|
||||||
@ -61,7 +71,7 @@ def load_config() -> _Config:
|
|||||||
if config.component.secret_file is not None:
|
if config.component.secret_file is not None:
|
||||||
log.info("Reading component secret from %s", config.component.secret_file)
|
log.info("Reading component secret from %s", config.component.secret_file)
|
||||||
with open(config.component.secret_file, "r", encoding="utf8") as f:
|
with open(config.component.secret_file, "r", encoding="utf8") as f:
|
||||||
config.component.secret = f.read().strip().replace("\n", "")
|
config.component.secret_plain = f.read().strip().replace("\n", "")
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user