Validate the 'expose' option

Signed-off-by: Aanand Prasad <aanand.prasad@gmail.com>
This commit is contained in:
Aanand Prasad 2015-11-26 19:17:58 +00:00
commit ccf548b98c
3 changed files with 44 additions and 2 deletions

View file

@ -41,7 +41,10 @@
"expose": {
"type": "array",
"items": {"type": ["string", "number"]},
"items": {
"type": ["string", "number"],
"format": "expose"
},
"uniqueItems": true
},

View file

@ -1,6 +1,7 @@
import json
import logging
import os
import re
import sys
import six
@ -34,6 +35,7 @@ DOCKER_CONFIG_HINTS = {
VALID_NAME_CHARS = '[a-zA-Z0-9\._\-]'
VALID_EXPOSE_FORMAT = r'^\d+(\/[a-zA-Z]+)?$'
@FormatChecker.cls_checks(format="ports", raises=ValidationError)
@ -45,6 +47,16 @@ def format_ports(instance):
return True
@FormatChecker.cls_checks(format="expose", raises=ValidationError)
def format_expose(instance):
if isinstance(instance, six.string_types):
if not re.match(VALID_EXPOSE_FORMAT, instance):
raise ValidationError(
"should be of the format 'PORT[/PROTOCOL]'")
return True
@FormatChecker.cls_checks(format="bool-value-in-mapping")
def format_boolean_in_environment(instance):
"""
@ -273,7 +285,7 @@ def validate_against_fields_schema(config, filename):
_validate_against_schema(
config,
"fields_schema.json",
format_checker=["ports", "bool-value-in-mapping"],
format_checker=["ports", "expose", "bool-value-in-mapping"],
filename=filename)