Created
October 10, 2015 09:42
-
-
Save ndenev/1eec4d3838f5a0c1dfff to your computer and use it in GitHub Desktop.
cerberus deep dependencies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/local/bin/python2.7 | |
from __future__ import print_function | |
import yaml | |
import cerberus | |
SCHEMA = ''' | |
document: | |
type: list | |
schema: | |
type: dict | |
schema: | |
batch: | |
type: list | |
schema: | |
type: dict | |
schema: | |
requests: | |
type: integer | |
min: 1 | |
required: true | |
port: | |
type: integer | |
min: 1 | |
max: 65535 | |
required: true | |
method: | |
type: string | |
empty: false | |
required: true | |
allowed: | |
- get | |
- post | |
proto: | |
type: string | |
empty: false | |
required: true | |
allowed: | |
- http | |
- https | |
https_protocol: | |
type: string | |
empty: false | |
allowed: | |
- SSL2 | |
- TLS1 | |
- TLS1.1 | |
- TLS1.2 | |
dependencies: | |
proto: https | |
''' | |
DOCUMENT = ''' | |
- batch: | |
- method: get | |
proto: http | |
port: 80 | |
requests: 10 | |
- method: get | |
proto: https | |
port: 443 | |
requests: 20 | |
https_protocol: TLS1 | |
- method: get | |
proto: https | |
port: 8080 | |
requests: 1 | |
https_protocol: TLS1 | |
- batch: | |
- method: get | |
proto: http | |
port: 8080 | |
requests: 15 | |
https_protocol: SSL2 | |
- method: get | |
proto: https | |
port: 8443 | |
requests: 35 | |
https_protocol: TLS1.2 | |
- method: get | |
proto: https | |
port: 8088 | |
requests: 1 | |
https_protocol: TLS1 | |
''' | |
schema = yaml.safe_load(SCHEMA) | |
document = {'document': yaml.safe_load(DOCUMENT)} | |
validator = cerberus.Validator(schema=schema) | |
if not validator.validate(document): | |
print("Error: {}".format(validator.errors)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment