mirror of
https://github.com/home-assistant/core.git
synced 2025-04-30 12:17:52 +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:
|
if replacement_key and invalidation_version:
|
||||||
warning = (
|
warning = (
|
||||||
"The '{key}' option (with value '{value}') is"
|
"The '{key}' option is deprecated,"
|
||||||
" deprecated, please replace it with '{replacement_key}'."
|
" please replace it with '{replacement_key}'."
|
||||||
" This option will become invalid in version"
|
" This option will become invalid in version"
|
||||||
" {invalidation_version}"
|
" {invalidation_version}"
|
||||||
)
|
)
|
||||||
elif replacement_key:
|
elif replacement_key:
|
||||||
warning = (
|
warning = (
|
||||||
"The '{key}' option (with value '{value}') is"
|
"The '{key}' option is deprecated,"
|
||||||
" deprecated, please replace it with '{replacement_key}'"
|
" please replace it with '{replacement_key}'"
|
||||||
)
|
)
|
||||||
elif invalidation_version:
|
elif invalidation_version:
|
||||||
warning = (
|
warning = (
|
||||||
"The '{key}' option (with value '{value}') is"
|
"The '{key}' option is deprecated,"
|
||||||
" deprecated, please remove it from your configuration."
|
" please remove it from your configuration."
|
||||||
" This option will become invalid in version"
|
" This option will become invalid in version"
|
||||||
" {invalidation_version}"
|
" {invalidation_version}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
warning = (
|
warning = (
|
||||||
"The '{key}' option (with value '{value}') is"
|
"The '{key}' option is deprecated,"
|
||||||
" deprecated, please remove it from your configuration"
|
" 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."""
|
"""Raise error if current version has reached invalidation."""
|
||||||
if not invalidation_version:
|
if not invalidation_version:
|
||||||
return
|
return
|
||||||
@ -689,7 +689,6 @@ def deprecated(
|
|||||||
raise vol.Invalid(
|
raise vol.Invalid(
|
||||||
warning.format(
|
warning.format(
|
||||||
key=key,
|
key=key,
|
||||||
value=value,
|
|
||||||
replacement_key=replacement_key,
|
replacement_key=replacement_key,
|
||||||
invalidation_version=invalidation_version,
|
invalidation_version=invalidation_version,
|
||||||
)
|
)
|
||||||
@ -698,19 +697,20 @@ def deprecated(
|
|||||||
def validator(config: Dict) -> Dict:
|
def validator(config: Dict) -> Dict:
|
||||||
"""Check if key is in config and log warning."""
|
"""Check if key is in config and log warning."""
|
||||||
if key in config:
|
if key in config:
|
||||||
value = config[key]
|
check_for_invalid_version()
|
||||||
check_for_invalid_version(value)
|
|
||||||
KeywordStyleAdapter(logging.getLogger(module_name)).warning(
|
KeywordStyleAdapter(logging.getLogger(module_name)).warning(
|
||||||
warning,
|
warning,
|
||||||
key=key,
|
key=key,
|
||||||
value=value,
|
|
||||||
replacement_key=replacement_key,
|
replacement_key=replacement_key,
|
||||||
invalidation_version=invalidation_version,
|
invalidation_version=invalidation_version,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
value = config[key]
|
||||||
if replacement_key:
|
if replacement_key:
|
||||||
config.pop(key)
|
config.pop(key)
|
||||||
else:
|
else:
|
||||||
value = default
|
value = default
|
||||||
|
|
||||||
keys = [key]
|
keys = [key]
|
||||||
if replacement_key:
|
if replacement_key:
|
||||||
keys.append(replacement_key)
|
keys.append(replacement_key)
|
||||||
|
@ -548,8 +548,7 @@ def test_deprecated_with_no_optionals(caplog, schema):
|
|||||||
"homeassistant.helpers.config_validation",
|
"homeassistant.helpers.config_validation",
|
||||||
]
|
]
|
||||||
assert (
|
assert (
|
||||||
"The 'mars' option (with value 'True') is deprecated, "
|
"The 'mars' option is deprecated, please remove it from your configuration"
|
||||||
"please remove it from your configuration"
|
|
||||||
) in caplog.text
|
) in caplog.text
|
||||||
assert test_data == output
|
assert test_data == output
|
||||||
|
|
||||||
@ -582,8 +581,7 @@ def test_deprecated_with_replacement_key(caplog, schema):
|
|||||||
output = deprecated_schema(test_data.copy())
|
output = deprecated_schema(test_data.copy())
|
||||||
assert len(caplog.records) == 1
|
assert len(caplog.records) == 1
|
||||||
assert (
|
assert (
|
||||||
"The 'mars' option (with value 'True') is deprecated, "
|
"The 'mars' option is deprecated, please replace it with 'jupiter'"
|
||||||
"please replace it with 'jupiter'"
|
|
||||||
) in caplog.text
|
) in caplog.text
|
||||||
assert {"jupiter": True} == output
|
assert {"jupiter": True} == output
|
||||||
|
|
||||||
@ -617,7 +615,7 @@ def test_deprecated_with_invalidation_version(caplog, schema, version):
|
|||||||
)
|
)
|
||||||
|
|
||||||
message = (
|
message = (
|
||||||
"The 'mars' option (with value 'True') is deprecated, "
|
"The 'mars' option is deprecated, "
|
||||||
"please remove it from your configuration. "
|
"please remove it from your configuration. "
|
||||||
"This option will become invalid in version 1.0.0"
|
"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:
|
with pytest.raises(vol.MultipleInvalid) as exc_info:
|
||||||
invalidated_schema(test_data)
|
invalidated_schema(test_data)
|
||||||
assert str(exc_info.value) == (
|
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 "
|
"please remove it from your configuration. This option will "
|
||||||
"become invalid in version 0.1.0"
|
"become invalid in version 0.1.0"
|
||||||
)
|
)
|
||||||
@ -671,7 +669,7 @@ def test_deprecated_with_replacement_key_and_invalidation_version(
|
|||||||
)
|
)
|
||||||
|
|
||||||
warning = (
|
warning = (
|
||||||
"The 'mars' option (with value 'True') is deprecated, "
|
"The 'mars' option is deprecated, "
|
||||||
"please replace it with 'jupiter'. This option will become "
|
"please replace it with 'jupiter'. This option will become "
|
||||||
"invalid in version 1.0.0"
|
"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:
|
with pytest.raises(vol.MultipleInvalid) as exc_info:
|
||||||
invalidated_schema(test_data)
|
invalidated_schema(test_data)
|
||||||
assert str(exc_info.value) == (
|
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 "
|
"please replace it with 'jupiter'. This option will become "
|
||||||
"invalid in version 0.1.0"
|
"invalid in version 0.1.0"
|
||||||
)
|
)
|
||||||
@ -725,8 +723,7 @@ def test_deprecated_with_default(caplog, schema):
|
|||||||
assert len(caplog.records) == 1
|
assert len(caplog.records) == 1
|
||||||
assert caplog.records[0].name == __name__
|
assert caplog.records[0].name == __name__
|
||||||
assert (
|
assert (
|
||||||
"The 'mars' option (with value 'True') is deprecated, "
|
"The 'mars' option is deprecated, please remove it from your configuration"
|
||||||
"please remove it from your configuration"
|
|
||||||
) in caplog.text
|
) in caplog.text
|
||||||
assert test_data == output
|
assert test_data == output
|
||||||
|
|
||||||
@ -759,8 +756,7 @@ def test_deprecated_with_replacement_key_and_default(caplog, schema):
|
|||||||
output = deprecated_schema(test_data.copy())
|
output = deprecated_schema(test_data.copy())
|
||||||
assert len(caplog.records) == 1
|
assert len(caplog.records) == 1
|
||||||
assert (
|
assert (
|
||||||
"The 'mars' option (with value 'True') is deprecated, "
|
"The 'mars' option is deprecated, please replace it with 'jupiter'"
|
||||||
"please replace it with 'jupiter'"
|
|
||||||
) in caplog.text
|
) in caplog.text
|
||||||
assert {"jupiter": True} == output
|
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())
|
output = deprecated_schema_with_default(test_data.copy())
|
||||||
assert len(caplog.records) == 1
|
assert len(caplog.records) == 1
|
||||||
assert (
|
assert (
|
||||||
"The 'mars' option (with value 'True') is deprecated, "
|
"The 'mars' option is deprecated, please replace it with 'jupiter'"
|
||||||
"please replace it with 'jupiter'"
|
|
||||||
) in caplog.text
|
) in caplog.text
|
||||||
assert {"jupiter": True} == output
|
assert {"jupiter": True} == output
|
||||||
|
|
||||||
@ -828,7 +823,7 @@ def test_deprecated_with_replacement_key_invalidation_version_default(
|
|||||||
output = deprecated_schema(test_data.copy())
|
output = deprecated_schema(test_data.copy())
|
||||||
assert len(caplog.records) == 1
|
assert len(caplog.records) == 1
|
||||||
assert (
|
assert (
|
||||||
"The 'mars' option (with value 'True') is deprecated, "
|
"The 'mars' option is deprecated, "
|
||||||
"please replace it with 'jupiter'. This option will become "
|
"please replace it with 'jupiter'. This option will become "
|
||||||
"invalid in version 1.0.0"
|
"invalid in version 1.0.0"
|
||||||
) in caplog.text
|
) in caplog.text
|
||||||
@ -855,7 +850,7 @@ def test_deprecated_with_replacement_key_invalidation_version_default(
|
|||||||
with pytest.raises(vol.MultipleInvalid) as exc_info:
|
with pytest.raises(vol.MultipleInvalid) as exc_info:
|
||||||
invalidated_schema(test_data)
|
invalidated_schema(test_data)
|
||||||
assert str(exc_info.value) == (
|
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 "
|
"please replace it with 'jupiter'. This option will become "
|
||||||
"invalid in version 0.1.0"
|
"invalid in version 0.1.0"
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user