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.
This commit is contained in:
Jason Kohles 2024-08-04 14:48:39 -04:00
parent ca8e45cf4c
commit a4e70e9750

View file

@ -414,7 +414,9 @@ def command_config(args, config):
# add the console decoration so the front-end can hide the secrets # add the console decoration so the front-end can hide the secrets
if not args.show_secrets: if not args.show_secrets:
output = re.sub( 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: if not CORE.quiet:
safe_print(output) safe_print(output)