From 3278a3716ba9f545bf69ab534256e9c9a21d2f38 Mon Sep 17 00:00:00 2001 From: Jamie Strandboge Date: Tue, 14 Jul 2026 13:59:49 -0500 Subject: [PATCH] feat: support SEDG_CONF env var --- README.md | 4 +++- cvelib/common.py | 2 ++ tests/test_common.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a271ff4..54a149b 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,8 @@ cve-data = /path/to/cve-data ``` + Set `SEDG_CONF=/path/to/sedg.conf` to use a different configuration file. + Optionally add any template URLs for GitHub alert template text to the `Behavior` section (comma-separated): @@ -502,7 +504,7 @@ The file format was initially defined in Ubuntu and the syntax above is largely compatible with the Ubuntu CVE tracker (UCT) and a longer term goal of this project is to push this tooling to UCT. The above format is more generalized, strict and applicable to other projects. If using this tooling with UCT data, -then adjust `~/.config/sedg_ubuntu.conf` to contain: +set `SEDG_CONF=~/.config/sedg_ubuntu.conf` and adjust that file to contain: ``` [Behavior] compat-ubuntu = yes diff --git a/cvelib/common.py b/cvelib/common.py index ee561f1..9478979 100644 --- a/cvelib/common.py +++ b/cvelib/common.py @@ -476,6 +476,8 @@ def getCacheDirPath() -> str: def getConfigFilePath() -> str: """Return the path to sedg.conf""" + if "SEDG_CONF" in os.environ: + return os.path.expandvars(os.environ["SEDG_CONF"]) if "XDG_CONFIG_HOME" in os.environ: return os.path.expandvars("$XDG_CONFIG_HOME/sedg/sedg.conf") return os.path.expandvars("$HOME/.config/sedg/sedg.conf") diff --git a/tests/test_common.py b/tests/test_common.py index af0ef1c..98d9d79 100644 --- a/tests/test_common.py +++ b/tests/test_common.py @@ -18,6 +18,7 @@ class TestCommon(TestCase): def setUp(self): """Setup functions common for all tests""" self.orig_xdg_config_home = None + self.orig_sedg_conf = os.environ.pop("SEDG_CONF", None) self.tmpdir = None def tearDown(self): @@ -29,6 +30,11 @@ def tearDown(self): os.environ["XDG_CONFIG_HOME"] = self.orig_xdg_config_home self.orig_xdg_config_home = None + os.environ.pop("SEDG_CONF", None) + if self.orig_sedg_conf is not None: # pragma: nocover + os.environ["SEDG_CONF"] = self.orig_sedg_conf + self.orig_sedg_conf = None + if self.tmpdir is not None: cvelib.common.recursive_rm(self.tmpdir) @@ -124,6 +130,12 @@ def test_getConfigFilePath(self): if "XDG_CONFIG_HOME" in os.environ: self.orig_xdg_config_home = os.environ["XDG_CONFIG_HOME"] + os.environ["SEDG_CONF"] = "$HOME/custom-sedg.conf" + os.environ["XDG_CONFIG_HOME"] = "/fake/.config" + res = cvelib.common.getConfigFilePath() + self.assertEqual(os.path.expandvars("$HOME/custom-sedg.conf"), res) + + del os.environ["SEDG_CONF"] os.environ["XDG_CONFIG_HOME"] = "/fake/.config" res = cvelib.common.getConfigFilePath() self.assertEqual("/fake/.config/sedg/sedg.conf", res) @@ -135,6 +147,25 @@ def test_getConfigFilePath(self): res, ) + def test_readConfigSedgConf(self): + """Test readConfig() with SEDG_CONF""" + self.tmpdir = tests.testutil._createTmpDir() + + fn = os.path.join(self.tmpdir, "custom", "sedg.conf") + os.environ["SEDG_CONF"] = fn + os.environ["XDG_CONFIG_HOME"] = "/fake/.config" + + with tests.testutil.capturedOutput() as (output, error): + exp_conf, exp_fn = cvelib.common.readConfig() + self.assertEqual(exp_fn, fn) + self.assertTrue(os.path.exists(fn)) + self.assertTrue("Locations" in exp_conf) + self.assertEqual( + "Created default config in %s" % fn, + output.getvalue().strip(), + ) + self.assertEqual("", error.getvalue().strip()) + def test_readConfig(self): """Test readConfig()""" self.tmpdir = tests.testutil._createTmpDir()