mirror of
https://github.com/valitydev/api-key-mgmt-v2.git
synced 2024-11-06 02:15:19 +00:00
TD-791: fix compile template (#18)
This commit is contained in:
parent
7196f37e86
commit
70147d9655
@ -5,6 +5,7 @@
|
||||
-include_lib("bouncer_proto/include/bouncer_ctx_thrift.hrl").
|
||||
-include_lib("epgsql/include/epgsql.hrl").
|
||||
|
||||
-define(TEMPLATE_DIR, "/opt/api-key-mgmt-v2/templates").
|
||||
-define(TEMPLATE_FILE, "request_revoke.dtl").
|
||||
|
||||
-export([send_revoke_mail/4]).
|
||||
@ -12,7 +13,7 @@
|
||||
-spec send_revoke_mail(string(), binary(), binary(), binary()) ->
|
||||
ok | {error, {failed_to_send, term()}}.
|
||||
send_revoke_mail(Email, PartyID, ApiKeyID, Token) ->
|
||||
Mod = ?RENDER_MODULE,
|
||||
{ok, Mod} = compile_template(),
|
||||
{ok, Body} = Mod:render([
|
||||
{url, url()},
|
||||
{party_id, PartyID},
|
||||
@ -20,7 +21,6 @@ send_revoke_mail(Email, PartyID, ApiKeyID, Token) ->
|
||||
{revoke_token, Token}
|
||||
]),
|
||||
BinaryBody = unicode:characters_to_binary(Body),
|
||||
logger:info("Try send email with body: ~p", [BinaryBody]),
|
||||
Pid = self(),
|
||||
case
|
||||
gen_smtp_client:send(
|
||||
@ -94,6 +94,22 @@ to_int(Value) when is_integer(Value) -> Value;
|
||||
to_int(Value) when is_binary(Value) -> erlang:binary_to_integer(Value);
|
||||
to_int(Value) when is_list(Value) -> erlang:list_to_integer(Value).
|
||||
|
||||
compile_template() ->
|
||||
TemplateFile = template_file(),
|
||||
File =
|
||||
case filelib:is_file(TemplateFile) of
|
||||
true -> TemplateFile;
|
||||
false -> default_template_file()
|
||||
end,
|
||||
erlydtl:compile({file, File}, ?RENDER_MODULE).
|
||||
|
||||
default_template_file() ->
|
||||
AkmPrivDir = code:priv_dir(akm),
|
||||
filename:join([AkmPrivDir, "mails", ?TEMPLATE_FILE]).
|
||||
|
||||
template_file() ->
|
||||
filename:join([?TEMPLATE_DIR, ?TEMPLATE_FILE]).
|
||||
|
||||
-ifdef(TEST).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
|
@ -7,8 +7,6 @@
|
||||
|
||||
-include("akm.hrl").
|
||||
|
||||
-define(TEMPLATE_FILE, "request_revoke.dtl").
|
||||
-define(TEMPLATE_DIR, "/opt/api-key-mgmt-v2/templates").
|
||||
-define(VAULT_TOKEN_PATH, "/var/run/secrets/kubernetes.io/serviceaccount/token").
|
||||
-define(VAULT_ROLE, <<"api-key-mgmt-v2">>).
|
||||
-define(VAULT_KEY_PG_CREDS, <<"api-key-mgmt-v2/pg_creds">>).
|
||||
@ -31,7 +29,6 @@ start_link() ->
|
||||
init([]) ->
|
||||
ok = maybe_set_secrets(),
|
||||
ok = dbinit(),
|
||||
{ok, _} = compile_template(),
|
||||
{LogicHandlers, LogicHandlerSpecs} = get_logic_handler_info(),
|
||||
HealthCheck = enable_health_logging(genlib_app:env(akm, health_check, #{})),
|
||||
AdditionalRoutes = [{'_', [erl_health_handle:get_route(HealthCheck), get_prometheus_route()]}],
|
||||
@ -83,23 +80,6 @@ dbinit() ->
|
||||
{error, Reason} -> throw({migrations_error, Reason})
|
||||
end.
|
||||
|
||||
compile_template() ->
|
||||
TemplateFile = template_file(),
|
||||
File =
|
||||
case filelib:is_file(TemplateFile) of
|
||||
true -> TemplateFile;
|
||||
false -> default_template_file()
|
||||
end,
|
||||
AkmEbinDir = code:lib_dir(akm, ebin),
|
||||
erlydtl:compile({file, File}, ?RENDER_MODULE, [{out_dir, AkmEbinDir}]).
|
||||
|
||||
default_template_file() ->
|
||||
AkmPrivDir = code:priv_dir(akm),
|
||||
filename:join([AkmPrivDir, "mails", ?TEMPLATE_FILE]).
|
||||
|
||||
template_file() ->
|
||||
filename:join([?TEMPLATE_DIR, ?TEMPLATE_FILE]).
|
||||
|
||||
set_database_url() ->
|
||||
{ok, #{
|
||||
host := PgHost,
|
||||
|
Loading…
Reference in New Issue
Block a user