From a4e70e9750c2419b2944a625da3ec930c846cae3 Mon Sep 17 00:00:00 2001 From: Jason Kohles Date: Sun, 4 Aug 2024 14:48:39 -0400 Subject: [PATCH] Cleanup the output of 'esphome config' command. When running `esphome config` as a CLI tool, the output adds some escaping to any config property that ends with 'password', 'key', 'psk', or 'ssid' so that the dashboard can redact secrets. I was using `esphome config` for linting purposes and having the output transformed like this was causing problems for me. I attempted to figure out how to tell when the tool was being run in a context where the output would be going to the dashboard so that it would only do that under those circumstances, but I wasn't able to determine if there was any way to detect that. Since I couldn't figure that out I did what felt like the next best thing and just modified the regex so that only wraps those values when they don't start with `!secret`, which fixes the problem for my use case, and having the dashboard only redact values that actually contain secrets seems like a win to me too. --- esphome/__main__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/esphome/__main__.py b/esphome/__main__.py index cf2741dbdb..ea8f18c365 100644 --- a/esphome/__main__.py +++ b/esphome/__main__.py @@ -414,7 +414,9 @@ def command_config(args, config): # add the console decoration so the front-end can hide the secrets if not args.show_secrets: output = re.sub( - r"(password|key|psk|ssid)\: (.+)", r"\1: \\033[5m\2\\033[6m", output + r"(password|key|psk|ssid)\: ((?!\!secret).+)", + r"\1: \\033[5m\2\\033[6m", + output, ) if not CORE.quiet: safe_print(output)