Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cvelib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
31 changes: 31 additions & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
Loading