From b630edf8c7ce6b88ad90ba8f7b46a2a861fa7594 Mon Sep 17 00:00:00 2001 From: Paul Swartz Date: Thu, 5 Oct 2023 10:32:30 -0400 Subject: [PATCH] fix(mqtt): store password as a 0-arity function to prevent logging --- apps/state_mediator/lib/state_mediator.ex | 2 +- apps/state_mediator/lib/state_mediator/mqtt_mediator.ex | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/state_mediator/lib/state_mediator.ex b/apps/state_mediator/lib/state_mediator.ex index 6d2e5514..fc423252 100644 --- a/apps/state_mediator/lib/state_mediator.ex +++ b/apps/state_mediator/lib/state_mediator.ex @@ -88,7 +88,7 @@ defmodule StateMediator do url: broker, topic: app_value(State.Vehicle, :topic), username: app_value(State.Vehicle, :username), - password: app_value(State.Vehicle, :password), + password: fn -> app_value(State.Vehicle, :password) end, sync_timeout: 30_000 ] } diff --git a/apps/state_mediator/lib/state_mediator/mqtt_mediator.ex b/apps/state_mediator/lib/state_mediator/mqtt_mediator.ex index 17278fd5..702aa807 100644 --- a/apps/state_mediator/lib/state_mediator/mqtt_mediator.ex +++ b/apps/state_mediator/lib/state_mediator/mqtt_mediator.ex @@ -79,8 +79,14 @@ defmodule StateMediator.MqttMediator do end defp configs_from_url(url, opts) do - password_opts = + password_value = case opts[:password] do + fun when is_function(fun, 0) -> fun.() + other -> other + end + + password_opts = + case password_value do nil -> [[]] [""] -> [[]] passwords -> for password <- String.split(passwords, " "), do: [password: password]