Skip to content

Commit

Permalink
added cert check/warning to run cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
Cielquan committed Feb 15, 2020
1 parent 7b6d232 commit fc78f8e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
23 changes: 22 additions & 1 deletion src/dothdns/commands/run/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
import docker.errors # type: ignore

from ...commands import config, images
from ...config import ABS_PATH_HOME_REPO_DIR_DOTENV_FILE, CONTAINER_NAMES
from ...config import (
ABS_PATH_HOME_REPO_DIR_CERT_DIR,
ABS_PATH_HOME_REPO_DIR_DOTENV_FILE,
CONTAINER_NAMES,
)
from ...helpers import echo_wr, get_env_file_data
from ...utils import load_container_configs_file
from ..cmd_class import CommandWithConfigFile
Expand All @@ -60,6 +64,23 @@ def run(ctx, proxy) -> None:
if proxy is None:
proxy = True

#: Check for cert.crt and key.key
missing = []
if not ABS_PATH_HOME_REPO_DIR_CERT_DIR.joinpath("cert.crt").is_file():
missing.append("cert.crt")
if not ABS_PATH_HOME_REPO_DIR_CERT_DIR.joinpath("key.key").is_file():
missing.append("key.key")
if missing:
echo_wr(
{
"txt": f"No {missing} file{'s' if len(missing) == 2 else ''} found. "
"Dashboards, DoH and DoT need both a 'certificate' and a corresponding "
"'key'. If you have not set those files up on another way encryption "
"will not work properly.",
"cat": "warning",
}
)

ctx.obj["invoked_internally_by"] = "run"
ctx.invoke(config)

Expand Down
6 changes: 2 additions & 4 deletions src/dothdns/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@
ABS_PATH_HOME = Path.home()
#: DoTH-DNS dir
ABS_PATH_HOME_REPO_DIR = Path(ABS_PATH_HOME, "DoTH-DNS")
#: unbound-docker `root.hints` file
ABS_PATH_HOME_REPO_DIR_UNBOUND_ROOT_HINTS_FILE = Path(
ABS_PATH_HOME_REPO_DIR, "unbound-docker/var_dir/root.hints"
)
#: certificates dir
ABS_PATH_HOME_REPO_DIR_CERT_DIR = Path(ABS_PATH_HOME_REPO_DIR, "certificates")
#: traefik-docker `.htpasswd` file
ABS_PATH_HOME_REPO_DIR_TRAEFIK_HTPASSWD_FILE = Path(
ABS_PATH_HOME_REPO_DIR, "traefik-docker", "shared", ".htpasswd"
Expand Down

0 comments on commit fc78f8e

Please sign in to comment.