From 9a1ab1c0d6f861f1ffd34af36d539c675e43e8c1 Mon Sep 17 00:00:00 2001 From: Hemna Date: Mon, 5 Jul 2021 10:57:22 -0400 Subject: [PATCH] Dump out the config during startup This patch adds the dumping out of a flattened config to the log at startup. This is helpful for seeing what aprsd server is actually using for config entries at startup and since it's in the log, you can reference it. --- aprsd/main.py | 9 +++++++++ aprsd/utils.py | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/aprsd/main.py b/aprsd/main.py index 08ffda6..a28c7bd 100644 --- a/aprsd/main.py +++ b/aprsd/main.py @@ -445,6 +445,7 @@ def server( if not quiet: click.echo("Load config") + config = utils.parse_config(config_file) # Force setting the config to the modules that need it @@ -460,6 +461,14 @@ def server( else: LOG.info(msg) + flat_config = utils.flatten_dict(config) + LOG.info("Using CONFIG values:") + for x in flat_config: + if "password" in x or "aprsd.web.users.admin" in x: + LOG.info("{} = XXXXXXXXXXXXXXXXXXX".format(x)) + else: + LOG.info("{} = {}".format(x, flat_config[x])) + if config["aprsd"].get("trace", False): trace.setup_tracing(["method", "api"]) LOG.info("APRSD Started version: {}".format(aprsd.__version__)) diff --git a/aprsd/utils.py b/aprsd/utils.py index afeeecb..50117c2 100644 --- a/aprsd/utils.py +++ b/aprsd/utils.py @@ -1,5 +1,6 @@ """Utilities and helper functions.""" +import collections import errno import functools import logging @@ -394,3 +395,15 @@ def _check_version(): # Lets put up an error and move on. We might not # have internet in this aprsd deployment. return 1, "Couldn't check for new version of APRSD" + + +def flatten_dict(d, parent_key="", sep="."): + """Flatten a dict to key.key.key = value.""" + items = [] + for k, v in d.items(): + new_key = parent_key + sep + k if parent_key else k + if isinstance(v, collections.MutableMapping): + items.extend(flatten_dict(v, new_key, sep=sep).items()) + else: + items.append((new_key, v)) + return dict(items)