Skip to content

Instantly share code, notes, and snippets.

@ndenev
Created October 10, 2015 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndenev/1eec4d3838f5a0c1dfff to your computer and use it in GitHub Desktop.
Save ndenev/1eec4d3838f5a0c1dfff to your computer and use it in GitHub Desktop.
cerberus deep dependencies
#!/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