Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

obfuscate devices ip in cloud_data object #64

Merged
merged 1 commit into from
Nov 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions custom_components/localtuya/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ async def async_get_config_entry_diagnostics(
tuya_api = hass_localtuya.cloud_data
# censoring private information on integration diagnostic data
for field in [CONF_CLIENT_ID, CONF_CLIENT_SECRET, CONF_USER_ID]:
data[field] = f"{data[field][0:3]}...{data[field][-3:]}"
data[field] = obfuscate(data[field])
data[CONF_DEVICES] = copy.deepcopy(entry.data[CONF_DEVICES])
for dev_id, dev in data[CONF_DEVICES].items():
local_key = dev[CONF_LOCAL_KEY]
local_key_obfuscated = f"{local_key[0:3]}...{local_key[-3:]}"
local_key_obfuscated = obfuscate(local_key)
dev[CONF_LOCAL_KEY] = local_key_obfuscated
data[CLOUD_DEVICES] = tuya_api.device_list
for dev_id, dev in data[CLOUD_DEVICES].items():
local_key = data[CLOUD_DEVICES][dev_id][CONF_LOCAL_KEY]
local_key_obfuscated = f"{local_key[0:3]}...{local_key[-3:]}"
local_key_obfuscated = obfuscate(local_key)
if ip := data[CLOUD_DEVICES][dev_id].get("ip"):
data[CLOUD_DEVICES][dev_id]["ip"] = obfuscate(ip, 1, 1)
data[CLOUD_DEVICES][dev_id][CONF_LOCAL_KEY] = local_key_obfuscated
return data

Expand All @@ -66,3 +68,8 @@ async def async_get_device_diagnostics(

# data["log"] = hass.data[DOMAIN][CONF_DEVICES][dev_id].logger.retrieve_log()
return data


def obfuscate(key, start_characters=3, end_characters=3) -> str:
"""Return obfuscated text by removing characters between [start_characters and end_characters]"""
return f"{key[0:start_characters]}...{key[-end_characters:]}"
Loading