TD-929: fix secrets setting

This commit is contained in:
ttt161 2024-07-02 17:16:49 +03:00
parent 6a90cbb220
commit cd96743129

View File

@ -14,8 +14,8 @@
-export([start/2, stop/1]). -export([start/2, stop/1]).
start(_StartType, _StartArgs) -> start(_StartType, _StartArgs) ->
Databases = application:get_env(epg_connector, databases, #{}), Databases0 = application:get_env(epg_connector, databases, #{}),
ok = maybe_set_secrets(Databases), Databases = maybe_set_secrets(Databases0),
Pools = application:get_env(epg_connector, pools, #{}), Pools = application:get_env(epg_connector, pools, #{}),
ok = start_pools(Pools, Databases), ok = start_pools(Pools, Databases),
epg_connector_sup:start_link(). epg_connector_sup:start_link().
@ -50,13 +50,12 @@ maybe_set_secrets(Databases) ->
set_secrets(canal:read(Key), Databases); set_secrets(canal:read(Key), Databases);
Error -> Error ->
logger:error("can`t auth vault client with error: ~p", [Error]), logger:error("can`t auth vault client with error: ~p", [Error]),
skip Databases
catch catch
_:_ -> _:_ ->
logger:error("catch exception when auth vault client"), logger:error("catch exception when auth vault client"),
skip Databases
end, end.
ok.
vault_client_auth(TokenPath) -> vault_client_auth(TokenPath) ->
case read_maybe_linked_file(TokenPath) of case read_maybe_linked_file(TokenPath) of
@ -91,11 +90,11 @@ set_secrets({ok, #{<<"pg_creds">> := #{<<"pg_user">> := PgUser, <<"pg_password">
} }
end, #{}, Databases), end, #{}, Databases),
application:set_env(epg_connector, databases, NewDbConfig), application:set_env(epg_connector, databases, NewDbConfig),
ok; NewDbConfig;
set_secrets({ok, #{<<"pg_creds">> := PgCreds}}, Databases) -> set_secrets({ok, #{<<"pg_creds">> := PgCreds}}, Databases) ->
logger:info("postgres credentials successfuly read from vault (as string)"), logger:info("postgres credentials successfuly read from vault (as string)"),
set_secrets({ok, #{<<"pg_creds">> => jsx:decode(PgCreds, [return_maps])}}, Databases); set_secrets({ok, #{<<"pg_creds">> => jsx:decode(PgCreds, [return_maps])}}, Databases);
set_secrets(Error, _Databases) -> set_secrets(Error, Databases) ->
logger:error("can`t read postgres credentials from vault with error: ~p", [Error]), logger:error("can`t read postgres credentials from vault with error: ~p", [Error]),
skip. Databases.