def delete_custom_validations(custom_validation_id): custom_validation = CustomValidationsModel.find_by_custom_validation_id(custom_validation_id) if not custom_validation: raise InvalidUsage("Custom Validation {} not exits".format( custom_validation_id), status_code=400) custom_validation.delete() return "", 204
def update_custom_validations(custom_validation_id): custom_validation_param = request.json["custom_validations"] CustomValidation.check_query(custom_validation_param) custom_validation = CustomValidationsModel.find_by_custom_validation_id(custom_validation_id) if not custom_validation: raise InvalidUsage("Custom Validation {} not exits".format( custom_validation_id), status_code=400) if CustomValidationsModel.find_by_implementation_key( custom_validation_param['implementation_key']): raise InvalidUsage('Rule {} already have a validation query' .format(custom_validation_param['implementation_key']), status_code=400) custom_validation.implementation_key = custom_validation_param["implementation_key"] custom_validation.query_validation = custom_validation_param["query_validation"] custom_validation.insert() return jsonify(custom_validation.to_dict()), 200
def rules_by_id(business_concept_id): rule_tags = request.json.get("rule_tags", None) data = Engine.get_data_from_dq( constants.GET_RULE_IMPLEMENTATIONS_BY_BUSINESS_CONCEPT, business_concept_id, constants.VALID_EXEC_STATUS, rule_tags) status_code = Engine.execute_rules_quality(data) if status_code != 200: raise InvalidUsage("unprocessable entity", status_code=422) return "", 204
def all_rules(): rule_tags = request.json.get("rule_tags", None) data = Engine.get_data_from_dq(constants.GET_RULE_IMPLEMENTATIONS, status=constants.VALID_EXEC_STATUS, rule_tags=rule_tags) status_code = Engine.execute_rules_quality(data) if status_code != 200: raise InvalidUsage("unprocessable entity", status_code=422) return "", 204
def get_data_from_vault(path): client = hvac.Client(url=app.config["VAULT_HOST"]) if client.is_sealed(): raise InvalidUsage('Error getting credentials. Check Vault', status_code=400) client.token = app.config["VAULT_TOKEN"] vault_data = client.read(path) if not vault_data: print("No data found in vault path {path}".format(path=path)) client.logout() return vault_data["data"]["data"] if vault_data else None
def create_custom_validations(): custom_validation_param = request.json["custom_validations"] CustomValidation.check_query(custom_validation_param) if CustomValidationsModel.find_by_implementation_key( custom_validation_param['implementation_key']): raise InvalidUsage('Rule {} already have a validation query' .format(custom_validation_param['implementation_key']), status_code=400) custom_validation = CustomValidationsModel( implementation_key=custom_validation_param["implementation_key"], query_validation=custom_validation_param["query_validation"]) custom_validation.insert() return jsonify(custom_validation.to_dict()), 201
def unauthorized(): raise InvalidUsage('Unauthorized access', status_code=403)
def check_query(custom_validation_param): sql_tokens = sqlparse.parse(custom_validation_param["query_validation"])[0] if Statement(sql_tokens).get_type() != "SELECT" or Identifier(sql_tokens).is_wildcard(): raise InvalidUsage('Not valid query', status_code=400)