Skip to content

Commit

Permalink
lg,lgp: Set config file via env.var.
Browse files Browse the repository at this point in the history
  • Loading branch information
dueringa committed Jul 7, 2024
1 parent 996ff6e commit c7c444e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------

Expand Down
6 changes: 4 additions & 2 deletions lg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]

Expand Down Expand Up @@ -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], \
Expand Down
5 changes: 3 additions & 2 deletions lgproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

"""HTTP proxy for BIRD socket."""


import os
import logging
from logging.handlers import TimedRotatingFileHandler
from urllib.parse import unquote
Expand All @@ -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"],
Expand Down

0 comments on commit c7c444e

Please sign in to comment.