Files
service-types-authority/validate.py
Monty Taylor b62518d952 Build a transformed JSON document for publication
The YAML format is intended for human interaction. Scripts also want
to consume this data, so we'd like to publish a machine-friendly format
for them. That format adds a version and a sha, so that people have
a way to trace the published data back to its source, as well as forward
and reverse mappings built from the data to simplify the questions
consumers will wind up querying from the data.

Change-Id: Ia62e01ca4380df0a36daaf76fe90e5f808ac7773
2017-06-01 12:28:27 -05:00

51 lines
1.5 KiB
Python

# Copyright (c) 2017 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json
import sys
import jsonschema
import yaml
def main():
ret = 0
schema = json.load(open('schema.json', 'r'))
validator = jsonschema.Draft4Validator(schema)
data = yaml.load(open('service-types.yaml', 'r'))
for error in validator.iter_errors(data):
print(error.message)
ret = 1
service_types = []
aliases = []
for service in data['services']:
service_types.append(service['service_type'])
if "aliases" in service:
for alias in service['aliases']:
if alias in aliases:
print("Alias {alias} appears twice".format(alias=alias))
ret = 1
aliases.append(alias)
for alias in aliases:
if alias in service_types:
print("Alias {alias} conflicts with a service_type".format(
alias=alias))
ret = 1
return ret
if __name__ == '__main__':
sys.exit(main())