mirror of
https://github.com/valitydev/epg_connector.git
synced 2024-11-06 00:05:21 +00:00
TD-927: fix canal init
This commit is contained in:
parent
44aa256172
commit
d435cb934c
@ -4,9 +4,9 @@
|
||||
default_db => #{
|
||||
host =>"127.0.0.1",
|
||||
port => 5432,
|
||||
database => "db_name",
|
||||
username => "postgres",
|
||||
password => "postgres"
|
||||
database => "progressor_db",
|
||||
username => "progressor",
|
||||
password => "progressor"
|
||||
}
|
||||
}},
|
||||
{pools, #{
|
||||
@ -22,7 +22,7 @@
|
||||
]},
|
||||
|
||||
{canal, [
|
||||
{url, "http://vault:8200"},
|
||||
{url, "http://vault"},
|
||||
{engine, kvv2}
|
||||
]}
|
||||
].
|
||||
].
|
||||
|
28
docker-compose.yml
Normal file
28
docker-compose.yml
Normal file
@ -0,0 +1,28 @@
|
||||
services:
|
||||
|
||||
postgres:
|
||||
image: postgres:15-bookworm
|
||||
environment:
|
||||
POSTGRES_DB: "progressor_db"
|
||||
POSTGRES_USER: "progressor"
|
||||
POSTGRES_PASSWORD: "progressor"
|
||||
PGDATA: "/tmp/postgresql/data/pgdata"
|
||||
volumes:
|
||||
- progressor-data:/tmp/postgresql/data
|
||||
ports:
|
||||
- "5432:5432"
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U progressor -d progressor_db"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
start_period: 10s
|
||||
restart: unless-stopped
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: "1"
|
||||
memory: 4G
|
||||
|
||||
volumes:
|
||||
progressor-data:
|
@ -8,6 +8,6 @@
|
||||
]}.
|
||||
|
||||
{shell, [
|
||||
% {config, "config/sys.config"},
|
||||
{config, "config/sys.config"},
|
||||
{apps, [epg_connector]}
|
||||
]}.
|
||||
|
@ -6,7 +6,6 @@
|
||||
{applications,
|
||||
[kernel,
|
||||
stdlib,
|
||||
canal,
|
||||
epgsql,
|
||||
epgsql_pool
|
||||
]},
|
||||
|
@ -14,6 +14,7 @@
|
||||
-export([start/2, stop/1]).
|
||||
|
||||
start(_StartType, _StartArgs) ->
|
||||
_ = maybe_start_canal(application:get_all_env(canal)),
|
||||
Databases0 = application:get_env(epg_connector, databases, #{}),
|
||||
Databases = maybe_set_secrets(Databases0),
|
||||
Pools = application:get_env(epg_connector, pools, #{}),
|
||||
@ -25,6 +26,11 @@ stop(_State) ->
|
||||
|
||||
%% internal functions
|
||||
|
||||
maybe_start_canal([]) ->
|
||||
ok;
|
||||
maybe_start_canal(_Env) ->
|
||||
_ = application:ensure_all_started(canal).
|
||||
|
||||
start_pools(Pools, Databases) ->
|
||||
maps:fold(
|
||||
fun(PoolName, Opts, _Acc) ->
|
||||
@ -61,7 +67,7 @@ vault_client_auth(TokenPath) ->
|
||||
case read_maybe_linked_file(TokenPath) of
|
||||
{ok, Token} ->
|
||||
Role = unicode:characters_to_binary(application:get_env(epg_connector, vault_role, ?VAULT_ROLE)),
|
||||
canal:auth({kubernetes, Role, Token});
|
||||
try_auth(Role, Token);
|
||||
Error ->
|
||||
Error
|
||||
end.
|
||||
@ -79,6 +85,14 @@ read_maybe_linked_file(MaybeLinkName) ->
|
||||
maybe_expand_relative(BaseFilename, Filename) ->
|
||||
filename:absname_join(filename:dirname(BaseFilename), Filename).
|
||||
|
||||
try_auth(Role, Token) ->
|
||||
try
|
||||
canal:auth({kubernetes, Role, Token})
|
||||
catch
|
||||
_:_ ->
|
||||
{error, {canal, auth_error}}
|
||||
end.
|
||||
|
||||
set_secrets({ok, #{<<"pg_creds">> := #{<<"pg_user">> := PgUser, <<"pg_password">> := PgPassword}}}, Databases) ->
|
||||
logger:info("postgres credentials successfuly read from vault (as json)"),
|
||||
NewDbConfig = maps:fold(fun(DbName, ConnOpts, Acc) ->
|
||||
@ -97,4 +111,3 @@ set_secrets({ok, #{<<"pg_creds">> := PgCreds}}, Databases) ->
|
||||
set_secrets(Error, Databases) ->
|
||||
logger:error("can`t read postgres credentials from vault with error: ~p", [Error]),
|
||||
Databases.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user