mirror of
https://github.com/docker/compose.git
synced 2025-07-24 22:24:41 +02:00
Allow integer value for ports
While it was intended as a positive to be stricter in validation it would in fact break backwards compatibility, which we do not want to be doing. Consider re-visiting this later and include a deprecation warning if we want to be stricter. Signed-off-by: Mazz Mosley <mazz@houseofmnowster.com>
This commit is contained in:
parent
df74b131ff
commit
b4872de213
@ -75,10 +75,22 @@
|
|||||||
"pid": {"type": "string"},
|
"pid": {"type": "string"},
|
||||||
|
|
||||||
"ports": {
|
"ports": {
|
||||||
"type": "array",
|
"oneOf": [
|
||||||
"items": {"type": "string"},
|
{
|
||||||
"uniqueItems": true,
|
"type": "array",
|
||||||
"format": "ports"
|
"items": {"type": "string"},
|
||||||
|
"uniqueItems": true,
|
||||||
|
"format": "ports"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"format": "ports"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "number",
|
||||||
|
"format": "ports"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
"privileged": {"type": "string"},
|
"privileged": {"type": "string"},
|
||||||
|
@ -84,6 +84,13 @@ def process_errors(errors):
|
|||||||
required.append("Service '{}' has neither an image nor a build path specified. Exactly one must be provided.".format(service_name))
|
required.append("Service '{}' has neither an image nor a build path specified. Exactly one must be provided.".format(service_name))
|
||||||
else:
|
else:
|
||||||
required.append(error.message)
|
required.append(error.message)
|
||||||
|
elif error.validator == 'oneOf':
|
||||||
|
config_key = error.path[1]
|
||||||
|
valid_types = [context.validator_value for context in error.context]
|
||||||
|
valid_type_msg = " or ".join(valid_types)
|
||||||
|
type_errors.append("Service '{}' configuration key '{}' contains an invalid type, it should be either {}".format(
|
||||||
|
service_name, config_key, valid_type_msg)
|
||||||
|
)
|
||||||
elif error.validator == 'type':
|
elif error.validator == 'type':
|
||||||
msg = "a"
|
msg = "a"
|
||||||
if error.validator_value == "array":
|
if error.validator_value == "array":
|
||||||
|
@ -75,8 +75,9 @@ class ConfigTest(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_config_invalid_ports_format_validation(self):
|
def test_config_invalid_ports_format_validation(self):
|
||||||
with self.assertRaises(ConfigurationError):
|
expected_error_msg = "Service 'web' configuration key 'ports' contains an invalid type"
|
||||||
for invalid_ports in [{"1": "8000"}, "whatport", "625", "8000:8050"]:
|
with self.assertRaisesRegexp(ConfigurationError, expected_error_msg):
|
||||||
|
for invalid_ports in [{"1": "8000"}, False, 0]:
|
||||||
config.load(
|
config.load(
|
||||||
config.ConfigDetails(
|
config.ConfigDetails(
|
||||||
{'web': {'image': 'busybox', 'ports': invalid_ports}},
|
{'web': {'image': 'busybox', 'ports': invalid_ports}},
|
||||||
@ -86,7 +87,7 @@ class ConfigTest(unittest.TestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_config_valid_ports_format_validation(self):
|
def test_config_valid_ports_format_validation(self):
|
||||||
valid_ports = [["8000", "9000"], ["8000/8050"], ["8000"]]
|
valid_ports = [["8000", "9000"], ["8000/8050"], ["8000"], "8000", 8000]
|
||||||
for ports in valid_ports:
|
for ports in valid_ports:
|
||||||
config.load(
|
config.load(
|
||||||
config.ConfigDetails(
|
config.ConfigDetails(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user