secrets: remove dependency on file_manager
It is desirable to use templates (and therefore secrets) in the server's configuration options. We need to defer loading the "file_manager", remove its dependency from secrets. When the file_manager is loaded it will look up "secrets" and register the file path as reserved. Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
60f4a82873
commit
69f527b7c7
|
@ -50,6 +50,7 @@ if TYPE_CHECKING:
|
|||
from .. import shell_command
|
||||
from ..job_queue import JobQueue
|
||||
from ..job_state import JobState
|
||||
from ..secrets import Secrets
|
||||
StrOrPath = Union[str, pathlib.Path]
|
||||
DBComp = database.MoonrakerDatabase
|
||||
APIComp = klippy_apis.KlippyAPI
|
||||
|
@ -147,6 +148,9 @@ class FileManager:
|
|||
"server:klippy_identified", self._update_fixed_paths)
|
||||
|
||||
# Register Data Folders
|
||||
secrets: Secrets = self.server.load_component(config, "secrets")
|
||||
self.add_reserved_path("secrets", secrets.get_secrets_file(), False)
|
||||
|
||||
config.get('config_path', None, deprecate=True)
|
||||
self.register_data_folder("config", full_access=True)
|
||||
|
||||
|
|
|
@ -16,12 +16,10 @@ from typing import (
|
|||
)
|
||||
if TYPE_CHECKING:
|
||||
from ..confighelper import ConfigHelper
|
||||
from .file_manager.file_manager import FileManager
|
||||
|
||||
class Secrets:
|
||||
def __init__(self, config: ConfigHelper) -> None:
|
||||
server = config.get_server()
|
||||
self.secrets_file: Optional[pathlib.Path] = None
|
||||
path: Optional[str] = config.get("secrets_path", None, deprecate=True)
|
||||
app_args = server.get_app_args()
|
||||
data_path = app_args["data_path"]
|
||||
|
@ -30,10 +28,8 @@ class Secrets:
|
|||
fpath = pathlib.Path(path).expanduser().resolve()
|
||||
self.type = "invalid"
|
||||
self.values: Dict[str, Any] = {}
|
||||
fm: FileManager = server.lookup_component("file_manager")
|
||||
fm.add_reserved_path("secrets", fpath, False)
|
||||
self.secrets_file = fpath
|
||||
if fpath.is_file():
|
||||
self.secrets_file = fpath
|
||||
data = self.secrets_file.read_text()
|
||||
vals = self._parse_json(data)
|
||||
if vals is not None:
|
||||
|
@ -63,6 +59,9 @@ class Secrets:
|
|||
logging.debug(
|
||||
"[secrets]: Option `secrets_path` not supplied")
|
||||
|
||||
def get_secrets_file(self) -> pathlib.Path:
|
||||
return self.secrets_file
|
||||
|
||||
def _parse_ini(self, data: str) -> Optional[Dict[str, Any]]:
|
||||
try:
|
||||
cfg = configparser.ConfigParser(interpolation=None)
|
||||
|
|
Loading…
Reference in New Issue