mirror of https://github.com/docker/compose.git
Merge pull request #3053 from dnephin/handle_booleans_in_mappings
Don't allow booleans for mapping types
This commit is contained in:
commit
f75408923e
|
@ -156,8 +156,7 @@
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"patternProperties": {
|
"patternProperties": {
|
||||||
".+": {
|
".+": {
|
||||||
"type": ["string", "number", "boolean", "null"],
|
"type": ["string", "number", "null"]
|
||||||
"format": "bool-value-in-mapping"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
|
|
@ -301,8 +301,7 @@
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"patternProperties": {
|
"patternProperties": {
|
||||||
".+": {
|
".+": {
|
||||||
"type": ["string", "number", "boolean", "null"],
|
"type": ["string", "number", "null"]
|
||||||
"format": "bool-value-in-mapping"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
|
|
@ -63,23 +63,6 @@ def format_expose(instance):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@FormatChecker.cls_checks(format="bool-value-in-mapping")
|
|
||||||
def format_boolean_in_environment(instance):
|
|
||||||
"""Check if there is a boolean in the mapping sections and display a warning.
|
|
||||||
Always return True here so the validation won't raise an error.
|
|
||||||
"""
|
|
||||||
if isinstance(instance, bool):
|
|
||||||
log.warn(
|
|
||||||
"There is a boolean value in the 'environment', 'labels', or "
|
|
||||||
"'extra_hosts' field of a service.\n"
|
|
||||||
"These sections only support string values.\n"
|
|
||||||
"Please add quotes to any boolean values to make them strings "
|
|
||||||
"(eg, 'True', 'false', 'yes', 'N', 'on', 'Off').\n"
|
|
||||||
"This warning will become an error in a future release. \r\n"
|
|
||||||
)
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def match_named_volumes(service_dict, project_volumes):
|
def match_named_volumes(service_dict, project_volumes):
|
||||||
service_volumes = service_dict.get('volumes', [])
|
service_volumes = service_dict.get('volumes', [])
|
||||||
for volume_spec in service_volumes:
|
for volume_spec in service_volumes:
|
||||||
|
@ -370,7 +353,7 @@ def process_config_schema_errors(error):
|
||||||
|
|
||||||
def validate_against_config_schema(config_file):
|
def validate_against_config_schema(config_file):
|
||||||
schema = load_jsonschema(config_file.version)
|
schema = load_jsonschema(config_file.version)
|
||||||
format_checker = FormatChecker(["ports", "expose", "bool-value-in-mapping"])
|
format_checker = FormatChecker(["ports", "expose"])
|
||||||
validator = Draft4Validator(
|
validator = Draft4Validator(
|
||||||
schema,
|
schema,
|
||||||
resolver=RefResolver(get_resolver_path(), schema),
|
resolver=RefResolver(get_resolver_path(), schema),
|
||||||
|
|
|
@ -1095,22 +1095,18 @@ class ConfigTest(unittest.TestCase):
|
||||||
).services
|
).services
|
||||||
self.assertEqual(service[0]['entrypoint'], entrypoint)
|
self.assertEqual(service[0]['entrypoint'], entrypoint)
|
||||||
|
|
||||||
@mock.patch('compose.config.validation.log')
|
def test_logs_warning_for_boolean_in_environment(self):
|
||||||
def test_logs_warning_for_boolean_in_environment(self, mock_logging):
|
config_details = build_config_details({
|
||||||
expected_warning_msg = "There is a boolean value in the 'environment'"
|
'web': {
|
||||||
config.load(
|
'image': 'busybox',
|
||||||
build_config_details(
|
'environment': {'SHOW_STUFF': True}
|
||||||
{'web': {
|
}
|
||||||
'image': 'busybox',
|
})
|
||||||
'environment': {'SHOW_STUFF': True}
|
|
||||||
}},
|
|
||||||
'working_dir',
|
|
||||||
'filename.yml'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
assert mock_logging.warn.called
|
with pytest.raises(ConfigurationError) as exc:
|
||||||
assert expected_warning_msg in mock_logging.warn.call_args[0][0]
|
config.load(config_details)
|
||||||
|
|
||||||
|
assert "contains true, which is an invalid type" in exc.exconly()
|
||||||
|
|
||||||
def test_config_valid_environment_dict_key_contains_dashes(self):
|
def test_config_valid_environment_dict_key_contains_dashes(self):
|
||||||
services = config.load(
|
services = config.load(
|
||||||
|
|
Loading…
Reference in New Issue