1 # ============LICENSE_START=======================================================
3 # ================================================================================
4 # Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
5 # ================================================================================
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
10 # http://www.apache.org/licenses/LICENSE-2.0
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 # ============LICENSE_END=========================================================
19 # ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 Function for Policy schema validation
25 from jsonschema import validate, ValidationError
26 from dcae_cli.util.logger import get_logger
27 from dcae_cli.util import reraise_with_msg
29 logger = get_logger('policy')
32 "$schema": "http://json-schema.org/draft-04/schema#",
33 "title": "Schema for policy changes",
36 "updated_policies": {"type": "array"},
37 "removed_policies": {"type": "array"},
38 "policies": {"type": "array"}
40 "additionalProperties": False
44 Is your Policy file a valid json?
45 Does your Policy file follow this format?
48 "updated_policies": [{},{},...],
49 "removed_policies": [{},{},...],
50 "policies": [{},{},...]
55 def validate_against_policy_schema(policy_file):
56 """Validate the policy file against the schema"""
59 validate(policy_file, _SCHEMA)
60 except ValidationError as e:
61 logger.error("Policy file validation issue")
62 logger.error(_validation_msg)
63 reraise_with_msg(e, as_dcae=True)