]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
python: removed env vars from python code
authorAleš Mrázek <ales.mrazek@nic.cz>
Sun, 15 Sep 2024 19:45:36 +0000 (21:45 +0200)
committerAleš Mrázek <ales.mrazek@nic.cz>
Mon, 30 Sep 2024 09:16:07 +0000 (11:16 +0200)
python/constants.py.in
python/knot_resolver/client/command.py
python/knot_resolver/manager/main.py

index 4fa71cbbc455334ba879f050cbe9125618bca79f..39de89a0fe881d54855cd11bc41a296c145924fa 100644 (file)
@@ -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"
index f87589bdad60241478e452dd065b1bc228f47af5..960ac1f544fccafb4ff601559ac3031179c848aa 100644 (file)
@@ -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}"')
 
 
index 294e6cb9c1138f9b46270b1226cdc3a8c7d4d0c7..dac47bed4846b8155b1e36417885e0261ef9ba14 100644 (file)
@@ -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