Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Introduce oscapd-evaluate config, this generates default oscapd config
Browse files Browse the repository at this point in the history
Will help when injecting it into SPC containers.
  • Loading branch information
Martin Preisler committed Mar 8, 2016
1 parent fc8a69d commit 6600dc4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
18 changes: 18 additions & 0 deletions bin/oscapd-evaluate
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ def main():
subparsers = parser.add_subparsers(dest="action")
subparsers.required = True

config_parser = subparsers.add_parser(
"config",
help="Start with default configuration, auto-detect tool and content "
"locations and output the resulting INI results into stdout or "
"given file path"
)
config_parser.add_argument(
"--path", metavar="PATH", type=argparse.FileType("w"),
default=sys.stdout
)

xml_parser = subparsers.add_parser(
"xml",
help="Evaluate an EvaluationSpec passed as an XML, either to stdin or "
Expand Down Expand Up @@ -112,6 +123,13 @@ def main():
level=logging.DEBUG if args.verbose else logging.INFO)
logging.info("OpenSCAP Daemon one-off evaluator %s", version.VERSION_STRING)

if args.action == "config":
config = config_.Configuration()
config.autodetect_tool_paths()
config.autodetect_content_paths()
config.save_as(args.path)
sys.exit(0)

config_file = os.path.join("/", "etc", "oscapd", "config.ini")
if "OSCAPD_CONFIG_FILE" in os.environ:
config_file = os.environ["OSCAPD_CONFIG_FILE"]
Expand Down
12 changes: 9 additions & 3 deletions openscap_daemon/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,16 @@ def save_as(self, config_file):
config.set("CVEScanner", "fetch-cve", "yes" if self.fetch_cve else "no")
config.set("CVEScanner", "fetch-cve-url", str(self.fetch_cve_url))

with open(config_file, "w") as f:
config.write(f)
if hasattr(config_file, "write"):
# config_file is an already opened file, let's use it like one
config.write(config_file)

self.config_file = config_file
else:
# treat config_file as a path
with open(config_file, "w") as f:
config.write(f)

self.config_file = config_file

def save(self):
self.save_as(self.config_file)
Expand Down

0 comments on commit 6600dc4

Please sign in to comment.