def validate_policy(fileId: str) -> object: """ Validates a file :param fileId: File Object ID :return: JSON of submission state """ policy = getPolicies() db = Db() for key, val in policy.items(): results = db.Results.objects(file_id=fileId, rule_id=key) if (len(results) == 0): result = db.Results(file_id=fileId, message="", rule_id=key, state=2) result.save() v = Validator(policy[key], result) v.startValidate() return jsonify({"message": "Successful"}), http.HTTPStatus.CREATED
def validate_policy(policyName: str, fileId: str) -> object: """ Validates a file :param fileId: File Object ID :return: JSON of submission state """ policy = get_policy(policyName) db = Db() log.debug("Policies") log.debug(policy) for i in range(len(policy)): log.debug("rule") log.debug(policy[i]) results = db.Results.objects(file_id=fileId, rule_id=policy[i]['name']) log.debug("checking result length") log.debug(fileId) log.debug(policy[i]['name']) log.debug(results) conf = Config().data alwaysScan = conf.get('alwaysScanFiles', False) if ((len(results) == 0) or (alwaysScan)): log.debug("no results") result = db.Results(file_id=fileId, message="", rule_id=policy[i]['name'], state=2, mandatory=policy[i]['mandatory']) if alwaysScan and len(results) > 0: result = results[0] result.save() v = Validator() v.start_validate(policy[i], result) return jsonify({"message": "Successful"}), HTTPStatus.CREATED