From: Aleš Mrázek Date: Sun, 15 Sep 2024 19:45:36 +0000 (+0200) Subject: python: removed env vars from python code X-Git-Tag: v6.0.9~9^2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff7179ea53c8eeb8160b03f52a1cb4c5b59a8c7d;p=thirdparty%2Fknot-resolver.git python: removed env vars from python code --- diff --git a/python/constants.py.in b/python/constants.py.in index 4fa71cbbc..39de89a0f 100644 --- a/python/constants.py.in +++ b/python/constants.py.in @@ -13,10 +13,6 @@ SBIN_DIR = Path("@sbin_dir@") CONFIG_FILE = ETC_DIR / "config.yaml" API_SOCK_FILE = RUN_DIR / "kres-api.sock" -# environmental variables -CONFIG_FILE_ENV_VAR = "KRES_CONFIG_FILE" -API_SOCK_FILE_ENV_VAR = "KRES_API_SOCK_FILE" - # executables paths KRESD_EXECUTABLE = SBIN_DIR / "kresd" KRES_CACHE_GC_EXECUTABLE = SBIN_DIR / "kres-cache-gc" diff --git a/python/knot_resolver/client/command.py b/python/knot_resolver/client/command.py index f87589bda..960ac1f54 100644 --- a/python/knot_resolver/client/command.py +++ b/python/knot_resolver/client/command.py @@ -1,11 +1,10 @@ import argparse -import os from abc import ABC, abstractmethod # pylint: disable=[no-name-in-module] from pathlib import Path from typing import Dict, List, Optional, Tuple, Type, TypeVar from urllib.parse import quote -from knot_resolver.constants import API_SOCK_FILE, API_SOCK_FILE_ENV_VAR, CONFIG_FILE, CONFIG_FILE_ENV_VAR +from knot_resolver.constants import API_SOCK_FILE, CONFIG_FILE from knot_resolver.datamodel.types import IPAddressPort from knot_resolver.utils.modeling import parsing from knot_resolver.utils.modeling.exceptions import DataValidationError @@ -69,26 +68,17 @@ def determine_socket(namespace: argparse.Namespace) -> SocketDesc: if len(namespace.socket) > 0: return SocketDesc(namespace.socket[0], "--socket argument") - config_path = os.getenv(CONFIG_FILE_ENV_VAR) - socket_env = os.getenv(API_SOCK_FILE_ENV_VAR) - socket: Optional[SocketDesc] = None # 2) socket from config file ('--config' argument) if len(namespace.config) > 0: socket = get_socket_from_config(namespace.config[0], False) - # 3) socket from config file (environment variable) - elif config_path: - socket = get_socket_from_config(Path(config_path), False) - # 4) socket from environment variable - elif socket_env: - socket = SocketDesc(socket_env, f'Environment variable "{API_SOCK_FILE_ENV_VAR}"') - # 5) socket from config file (default config file constant) + # 3) socket from config file (default config file constant) else: socket = get_socket_from_config(CONFIG_FILE, True) if socket: return socket - # 6) socket default + # 4) socket default return SocketDesc(str(API_SOCK_FILE), f'Default value "{API_SOCK_FILE}"') diff --git a/python/knot_resolver/manager/main.py b/python/knot_resolver/manager/main.py index 294e6cb9c..dac47bed4 100644 --- a/python/knot_resolver/manager/main.py +++ b/python/knot_resolver/manager/main.py @@ -4,12 +4,11 @@ file to allow us to exclude the __main__.py file from black's autoformatting """ import argparse -import os import sys from pathlib import Path from typing import NoReturn -from knot_resolver.constants import CONFIG_FILE, CONFIG_FILE_ENV_VAR, VERSION +from knot_resolver.constants import CONFIG_FILE, VERSION from knot_resolver.manager.logging import logger_startup from knot_resolver.manager.server import start_server from knot_resolver.utils import compat @@ -44,11 +43,8 @@ def main() -> NoReturn: args = parse_args() # where to look for config - config_env = os.getenv(CONFIG_FILE_ENV_VAR) if args.config is not None: config_path = Path(args.config[0]) - elif config_env is not None: - config_path = Path(config_env) else: config_path = CONFIG_FILE