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 .. import shell_command
|
||||||
from ..job_queue import JobQueue
|
from ..job_queue import JobQueue
|
||||||
from ..job_state import JobState
|
from ..job_state import JobState
|
||||||
|
from ..secrets import Secrets
|
||||||
StrOrPath = Union[str, pathlib.Path]
|
StrOrPath = Union[str, pathlib.Path]
|
||||||
DBComp = database.MoonrakerDatabase
|
DBComp = database.MoonrakerDatabase
|
||||||
APIComp = klippy_apis.KlippyAPI
|
APIComp = klippy_apis.KlippyAPI
|
||||||
|
@ -147,6 +148,9 @@ class FileManager:
|
||||||
"server:klippy_identified", self._update_fixed_paths)
|
"server:klippy_identified", self._update_fixed_paths)
|
||||||
|
|
||||||
# Register Data Folders
|
# 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)
|
config.get('config_path', None, deprecate=True)
|
||||||
self.register_data_folder("config", full_access=True)
|
self.register_data_folder("config", full_access=True)
|
||||||
|
|
||||||
|
|
|
@ -16,12 +16,10 @@ from typing import (
|
||||||
)
|
)
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ..confighelper import ConfigHelper
|
from ..confighelper import ConfigHelper
|
||||||
from .file_manager.file_manager import FileManager
|
|
||||||
|
|
||||||
class Secrets:
|
class Secrets:
|
||||||
def __init__(self, config: ConfigHelper) -> None:
|
def __init__(self, config: ConfigHelper) -> None:
|
||||||
server = config.get_server()
|
server = config.get_server()
|
||||||
self.secrets_file: Optional[pathlib.Path] = None
|
|
||||||
path: Optional[str] = config.get("secrets_path", None, deprecate=True)
|
path: Optional[str] = config.get("secrets_path", None, deprecate=True)
|
||||||
app_args = server.get_app_args()
|
app_args = server.get_app_args()
|
||||||
data_path = app_args["data_path"]
|
data_path = app_args["data_path"]
|
||||||
|
@ -30,10 +28,8 @@ class Secrets:
|
||||||
fpath = pathlib.Path(path).expanduser().resolve()
|
fpath = pathlib.Path(path).expanduser().resolve()
|
||||||
self.type = "invalid"
|
self.type = "invalid"
|
||||||
self.values: Dict[str, Any] = {}
|
self.values: Dict[str, Any] = {}
|
||||||
fm: FileManager = server.lookup_component("file_manager")
|
self.secrets_file = fpath
|
||||||
fm.add_reserved_path("secrets", fpath, False)
|
|
||||||
if fpath.is_file():
|
if fpath.is_file():
|
||||||
self.secrets_file = fpath
|
|
||||||
data = self.secrets_file.read_text()
|
data = self.secrets_file.read_text()
|
||||||
vals = self._parse_json(data)
|
vals = self._parse_json(data)
|
||||||
if vals is not None:
|
if vals is not None:
|
||||||
|
@ -63,6 +59,9 @@ class Secrets:
|
||||||
logging.debug(
|
logging.debug(
|
||||||
"[secrets]: Option `secrets_path` not supplied")
|
"[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]]:
|
def _parse_ini(self, data: str) -> Optional[Dict[str, Any]]:
|
||||||
try:
|
try:
|
||||||
cfg = configparser.ConfigParser(interpolation=None)
|
cfg = configparser.ConfigParser(interpolation=None)
|
||||||
|
|
Loading…
Reference in New Issue