diff --git a/bin/oscapd-evaluate b/bin/oscapd-evaluate index 4d4723f..b0b5ec3 100755 --- a/bin/oscapd-evaluate +++ b/bin/oscapd-evaluate @@ -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 " @@ -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"] diff --git a/openscap_daemon/config.py b/openscap_daemon/config.py index 24701bf..eb99342 100644 --- a/openscap_daemon/config.py +++ b/openscap_daemon/config.py @@ -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)