diff --git a/README.mkd b/README.mkd index bde5153..0f2c354 100644 --- a/README.mkd +++ b/README.mkd @@ -11,6 +11,11 @@ Fork notes - Use "... tables all" for all route queries - Python3 compatibility! +Environment variables +--------------------- + +LG_CONFIG_FILE / LGPROXY_CONFIG_FILE: set the corresponding config file to use. + Overview -------- diff --git a/lg.py b/lg.py index 274918f..d93cb77 100644 --- a/lg.py +++ b/lg.py @@ -28,6 +28,7 @@ import subprocess import logging from logging.handlers import TimedRotatingFileHandler +import os import re from urllib.error import HTTPError from urllib.request import urlopen @@ -49,7 +50,8 @@ re_pat_time = re.compile("([0-9]{2}:[0-9]{2}(:[0-9]{2})?)") app = Flask(__name__) -app.config.from_pyfile("lg.cfg") +config_file = os.environ.get("LG_CONFIG_FILE", "lg.cfg") +app.config.from_pyfile(config_file) app.secret_key = app.config["SESSION_KEY"] app.debug = app.config["DEBUG"] @@ -537,7 +539,7 @@ def build_as_tree_from_raw_bird_ouput(text: list[str]): # remove unparsed BGP attributes. # string comparisons are cheaper than regex. text = [line.strip() for line in text] - text = [line for line in text if not (line.startswith("BGP.") and line[4] != "a") ] + text = [line for line in text if not (line.startswith("BGP.") and line[4] != "a")] # No idea how I could clean this up, pylint complains... for line in text: # bird1: cli_printf(c, -1008, "\tType: %s %s %s", src_names[a->source], \ diff --git a/lgproxy.py b/lgproxy.py index d0408eb..7c28216 100644 --- a/lgproxy.py +++ b/lgproxy.py @@ -25,7 +25,7 @@ """HTTP proxy for BIRD socket.""" - +import os import logging from logging.handlers import TimedRotatingFileHandler from urllib.parse import unquote @@ -37,8 +37,9 @@ from bird import BirdSocket app = Flask(__name__) +config_file = os.environ.get("LGPROXY_CONFIG_FILE", "lgproxy.cfg") +app.config.from_pyfile(config_file) app.debug = app.config["DEBUG"] -app.config.from_pyfile("lgproxy.cfg") file_handler = TimedRotatingFileHandler( filename=app.config["LOG_FILE"],