mirror of
https://github.com/home-assistant/core.git
synced 2025-04-28 03:07:50 +00:00
Prevent possible secret values to show up in deprecation logs (#36368)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
37f7d262d7
commit
e86bedb223
@ -657,30 +657,30 @@ def deprecated(
|
||||
|
||||
if replacement_key and invalidation_version:
|
||||
warning = (
|
||||
"The '{key}' option (with value '{value}') is"
|
||||
" deprecated, please replace it with '{replacement_key}'."
|
||||
"The '{key}' option is deprecated,"
|
||||
" please replace it with '{replacement_key}'."
|
||||
" This option will become invalid in version"
|
||||
" {invalidation_version}"
|
||||
)
|
||||
elif replacement_key:
|
||||
warning = (
|
||||
"The '{key}' option (with value '{value}') is"
|
||||
" deprecated, please replace it with '{replacement_key}'"
|
||||
"The '{key}' option is deprecated,"
|
||||
" please replace it with '{replacement_key}'"
|
||||
)
|
||||
elif invalidation_version:
|
||||
warning = (
|
||||
"The '{key}' option (with value '{value}') is"
|
||||
" deprecated, please remove it from your configuration."
|
||||
"The '{key}' option is deprecated,"
|
||||
" please remove it from your configuration."
|
||||
" This option will become invalid in version"
|
||||
" {invalidation_version}"
|
||||
)
|
||||
else:
|
||||
warning = (
|
||||
"The '{key}' option (with value '{value}') is"
|
||||
" deprecated, please remove it from your configuration"
|
||||
"The '{key}' option is deprecated,"
|
||||
" please remove it from your configuration"
|
||||
)
|
||||
|
||||
def check_for_invalid_version(value: Optional[Any]) -> None:
|
||||
def check_for_invalid_version() -> None:
|
||||
"""Raise error if current version has reached invalidation."""
|
||||
if not invalidation_version:
|
||||
return
|
||||
@ -689,7 +689,6 @@ def deprecated(
|
||||
raise vol.Invalid(
|
||||
warning.format(
|
||||
key=key,
|
||||
value=value,
|
||||
replacement_key=replacement_key,
|
||||
invalidation_version=invalidation_version,
|
||||
)
|
||||
@ -698,19 +697,20 @@ def deprecated(
|
||||
def validator(config: Dict) -> Dict:
|
||||
"""Check if key is in config and log warning."""
|
||||
if key in config:
|
||||
value = config[key]
|
||||
check_for_invalid_version(value)
|
||||
check_for_invalid_version()
|
||||
KeywordStyleAdapter(logging.getLogger(module_name)).warning(
|
||||
warning,
|
||||
key=key,
|
||||
value=value,
|
||||
replacement_key=replacement_key,
|
||||
invalidation_version=invalidation_version,
|
||||
)
|
||||
|
||||
value = config[key]
|
||||
if replacement_key:
|
||||
config.pop(key)
|
||||
else:
|
||||
value = default
|
||||
|
||||
keys = [key]
|
||||
if replacement_key:
|
||||
keys.append(replacement_key)
|
||||
|
@ -548,8 +548,7 @@ def test_deprecated_with_no_optionals(caplog, schema):
|
||||
"homeassistant.helpers.config_validation",
|
||||
]
|
||||
assert (
|
||||
"The 'mars' option (with value 'True') is deprecated, "
|
||||
"please remove it from your configuration"
|
||||
"The 'mars' option is deprecated, please remove it from your configuration"
|
||||
) in caplog.text
|
||||
assert test_data == output
|
||||
|
||||
@ -582,8 +581,7 @@ def test_deprecated_with_replacement_key(caplog, schema):
|
||||
output = deprecated_schema(test_data.copy())
|
||||
assert len(caplog.records) == 1
|
||||
assert (
|
||||
"The 'mars' option (with value 'True') is deprecated, "
|
||||
"please replace it with 'jupiter'"
|
||||
"The 'mars' option is deprecated, please replace it with 'jupiter'"
|
||||
) in caplog.text
|
||||
assert {"jupiter": True} == output
|
||||
|
||||
@ -617,7 +615,7 @@ def test_deprecated_with_invalidation_version(caplog, schema, version):
|
||||
)
|
||||
|
||||
message = (
|
||||
"The 'mars' option (with value 'True') is deprecated, "
|
||||
"The 'mars' option is deprecated, "
|
||||
"please remove it from your configuration. "
|
||||
"This option will become invalid in version 1.0.0"
|
||||
)
|
||||
@ -643,7 +641,7 @@ def test_deprecated_with_invalidation_version(caplog, schema, version):
|
||||
with pytest.raises(vol.MultipleInvalid) as exc_info:
|
||||
invalidated_schema(test_data)
|
||||
assert str(exc_info.value) == (
|
||||
"The 'mars' option (with value 'True') is deprecated, "
|
||||
"The 'mars' option is deprecated, "
|
||||
"please remove it from your configuration. This option will "
|
||||
"become invalid in version 0.1.0"
|
||||
)
|
||||
@ -671,7 +669,7 @@ def test_deprecated_with_replacement_key_and_invalidation_version(
|
||||
)
|
||||
|
||||
warning = (
|
||||
"The 'mars' option (with value 'True') is deprecated, "
|
||||
"The 'mars' option is deprecated, "
|
||||
"please replace it with 'jupiter'. This option will become "
|
||||
"invalid in version 1.0.0"
|
||||
)
|
||||
@ -703,7 +701,7 @@ def test_deprecated_with_replacement_key_and_invalidation_version(
|
||||
with pytest.raises(vol.MultipleInvalid) as exc_info:
|
||||
invalidated_schema(test_data)
|
||||
assert str(exc_info.value) == (
|
||||
"The 'mars' option (with value 'True') is deprecated, "
|
||||
"The 'mars' option is deprecated, "
|
||||
"please replace it with 'jupiter'. This option will become "
|
||||
"invalid in version 0.1.0"
|
||||
)
|
||||
@ -725,8 +723,7 @@ def test_deprecated_with_default(caplog, schema):
|
||||
assert len(caplog.records) == 1
|
||||
assert caplog.records[0].name == __name__
|
||||
assert (
|
||||
"The 'mars' option (with value 'True') is deprecated, "
|
||||
"please remove it from your configuration"
|
||||
"The 'mars' option is deprecated, please remove it from your configuration"
|
||||
) in caplog.text
|
||||
assert test_data == output
|
||||
|
||||
@ -759,8 +756,7 @@ def test_deprecated_with_replacement_key_and_default(caplog, schema):
|
||||
output = deprecated_schema(test_data.copy())
|
||||
assert len(caplog.records) == 1
|
||||
assert (
|
||||
"The 'mars' option (with value 'True') is deprecated, "
|
||||
"please replace it with 'jupiter'"
|
||||
"The 'mars' option is deprecated, please replace it with 'jupiter'"
|
||||
) in caplog.text
|
||||
assert {"jupiter": True} == output
|
||||
|
||||
@ -792,8 +788,7 @@ def test_deprecated_with_replacement_key_and_default(caplog, schema):
|
||||
output = deprecated_schema_with_default(test_data.copy())
|
||||
assert len(caplog.records) == 1
|
||||
assert (
|
||||
"The 'mars' option (with value 'True') is deprecated, "
|
||||
"please replace it with 'jupiter'"
|
||||
"The 'mars' option is deprecated, please replace it with 'jupiter'"
|
||||
) in caplog.text
|
||||
assert {"jupiter": True} == output
|
||||
|
||||
@ -828,7 +823,7 @@ def test_deprecated_with_replacement_key_invalidation_version_default(
|
||||
output = deprecated_schema(test_data.copy())
|
||||
assert len(caplog.records) == 1
|
||||
assert (
|
||||
"The 'mars' option (with value 'True') is deprecated, "
|
||||
"The 'mars' option is deprecated, "
|
||||
"please replace it with 'jupiter'. This option will become "
|
||||
"invalid in version 1.0.0"
|
||||
) in caplog.text
|
||||
@ -855,7 +850,7 @@ def test_deprecated_with_replacement_key_invalidation_version_default(
|
||||
with pytest.raises(vol.MultipleInvalid) as exc_info:
|
||||
invalidated_schema(test_data)
|
||||
assert str(exc_info.value) == (
|
||||
"The 'mars' option (with value 'True') is deprecated, "
|
||||
"The 'mars' option is deprecated, "
|
||||
"please replace it with 'jupiter'. This option will become "
|
||||
"invalid in version 0.1.0"
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user