forked from p15670423/monkey
island: Move _expand_path() to file_utils.py so it can be reused
This commit is contained in:
parent
e4866b1286
commit
0519153aaf
|
@ -0,0 +1,5 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def expand_path(path: str) -> str:
|
||||||
|
return os.path.expandvars(os.path.expanduser(path))
|
|
@ -1,7 +1,5 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
from monkey_island.cc.server_utils.consts import (
|
from monkey_island.cc.server_utils.consts import (
|
||||||
DEFAULT_CERTIFICATE_PATHS,
|
DEFAULT_CERTIFICATE_PATHS,
|
||||||
DEFAULT_CRT_PATH,
|
DEFAULT_CRT_PATH,
|
||||||
|
@ -10,11 +8,12 @@ from monkey_island.cc.server_utils.consts import (
|
||||||
DEFAULT_LOG_LEVEL,
|
DEFAULT_LOG_LEVEL,
|
||||||
DEFAULT_START_MONGO_DB,
|
DEFAULT_START_MONGO_DB,
|
||||||
)
|
)
|
||||||
|
from monkey_island.cc.server_utils.file_utils import expand_path
|
||||||
|
|
||||||
|
|
||||||
class IslandConfigOptions:
|
class IslandConfigOptions:
|
||||||
def __init__(self, config_contents: dict):
|
def __init__(self, config_contents: dict):
|
||||||
self.data_dir = _expand_path(config_contents.get("data_dir", DEFAULT_DATA_DIR))
|
self.data_dir = expand_path(config_contents.get("data_dir", DEFAULT_DATA_DIR))
|
||||||
|
|
||||||
self.log_level = config_contents.get("log_level", DEFAULT_LOG_LEVEL)
|
self.log_level = config_contents.get("log_level", DEFAULT_LOG_LEVEL)
|
||||||
|
|
||||||
|
@ -22,17 +21,13 @@ class IslandConfigOptions:
|
||||||
"mongodb", {"start_mongodb": DEFAULT_START_MONGO_DB}
|
"mongodb", {"start_mongodb": DEFAULT_START_MONGO_DB}
|
||||||
).get("start_mongodb", DEFAULT_START_MONGO_DB)
|
).get("start_mongodb", DEFAULT_START_MONGO_DB)
|
||||||
|
|
||||||
self.crt_path = _expand_path(
|
self.crt_path = expand_path(
|
||||||
config_contents.get("ssl_certificate", DEFAULT_CERTIFICATE_PATHS).get(
|
config_contents.get("ssl_certificate", DEFAULT_CERTIFICATE_PATHS).get(
|
||||||
"ssl_certificate_file", DEFAULT_CRT_PATH
|
"ssl_certificate_file", DEFAULT_CRT_PATH
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
self.key_path = _expand_path(
|
self.key_path = expand_path(
|
||||||
config_contents.get("ssl_certificate", DEFAULT_CERTIFICATE_PATHS).get(
|
config_contents.get("ssl_certificate", DEFAULT_CERTIFICATE_PATHS).get(
|
||||||
"ssl_certificate_key_file", DEFAULT_KEY_PATH
|
"ssl_certificate_key_file", DEFAULT_KEY_PATH
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _expand_path(path: str) -> str:
|
|
||||||
return os.path.expandvars(os.path.expanduser(path))
|
|
||||||
|
|
Loading…
Reference in New Issue