def LoadCheckFromFile(file_path, check_id, overwrite_if_exists=True): """Load a single check from a file.""" configs = LoadConfigsFromFile(file_path) conf = configs.get(check_id) check = rdfvalue.Check(**conf) check.Validate() CheckRegistry.RegisterCheck(check, source="file:%s" % file_path, overwrite_if_exists=overwrite_if_exists) logging.debug("Loaded check %s from %s", check.check_id, file_path)
def LoadChecksFromFiles(file_paths, overwrite_if_exists=True): for file_path in file_paths: configs = LoadConfigsFromFile(file_path) for conf in configs.values(): check = rdfvalue.Check(**conf) check.Validate() CheckRegistry.RegisterCheck( check, source="file:%s" % file_path, overwrite_if_exists=overwrite_if_exists) logging.debug("Loaded check %s from %s", check.check_id, file_path)
def GetCheckErrors(self, check_spec): errors = [] try: check = rdfvalue.Check(**check_spec) check.Validate() except (checks.Error, filters.Error, hints.Error, type_info.Error) as e: errors.append(str(e)) except Exception as e: # TODO(user): More granular exception handling. errors.append("Unknown error %s: %s" % (type(e), e)) return errors
def LoadChecksFromFiles(file_paths, overwrite_if_exists=True): """Load the checks defined in the specified files.""" loaded = [] for file_path in file_paths: configs = LoadConfigsFromFile(file_path) for conf in configs.values(): check = rdfvalue.Check(**conf) # Validate will raise if the check doesn't load. check.Validate() loaded.append(check) CheckRegistry.RegisterCheck( check, source="file:%s" % file_path, overwrite_if_exists=overwrite_if_exists) logging.debug("Loaded check %s from %s", check.check_id, file_path) return loaded