chore(authn): fix dialyzer
This commit is contained in:
parent
69755ad3fb
commit
bb4e5fdb4f
|
@ -659,8 +659,12 @@ reply(Reply, State) ->
|
|||
certs_dir(Dirs) when is_list(Dirs) ->
|
||||
to_bin(filename:join([emqx:get_config([node, data_dir]), "certs/authn"] ++ Dirs)).
|
||||
|
||||
convert_certs(CertsDir, #{<<"ssl">> := SSLOpts} = Config) ->
|
||||
NSSLOPts = lists:foldl(fun(K, Acc) ->
|
||||
convert_certs(CertsDir, Config) ->
|
||||
case maps:get(<<"ssl">>, Config, undefined) of
|
||||
undefined ->
|
||||
Config;
|
||||
SSLOpts ->
|
||||
NSSLOPts = lists:foldl(fun(K, Acc) ->
|
||||
case maps:get(K, Acc, undefined) of
|
||||
undefined -> Acc;
|
||||
PemBin ->
|
||||
|
@ -669,32 +673,37 @@ convert_certs(CertsDir, #{<<"ssl">> := SSLOpts} = Config) ->
|
|||
Acc#{K => CertFile}
|
||||
end
|
||||
end, SSLOpts, [<<"certfile">>, <<"keyfile">>, <<"cacertfile">>]),
|
||||
Config#{<<"ssl">> => NSSLOPts};
|
||||
convert_certs(_CertsDir, Config) ->
|
||||
Config.
|
||||
Config#{<<"ssl">> => NSSLOPts}
|
||||
end.
|
||||
|
||||
convert_certs(CertsDir, #{<<"ssl">> := NewSSLOpts} = NewConfig, OldConfig) ->
|
||||
OldSSLOpts = maps:get(<<"ssl">>, OldConfig, #{}),
|
||||
Diff = diff_certs(NewSSLOpts, OldSSLOpts),
|
||||
NSSLOpts = lists:foldl(fun({identical, K}, Acc) ->
|
||||
Acc#{K => maps:get(K, OldSSLOpts)};
|
||||
({_, K}, Acc) ->
|
||||
CertFile = generate_filename(CertsDir, K),
|
||||
ok = save_cert_to_file(CertFile, maps:get(K, NewSSLOpts)),
|
||||
Acc#{K => CertFile}
|
||||
end, NewSSLOpts, Diff),
|
||||
NewConfig#{<<"ssl">> => NSSLOpts};
|
||||
convert_certs(_CertsDir, NewConfig, _OldConfig) ->
|
||||
NewConfig.
|
||||
convert_certs(CertsDir, NewConfig, OldConfig) ->
|
||||
case maps:get(<<"ssl">>, NewConfig, undefined) of
|
||||
undefined ->
|
||||
NewConfig;
|
||||
NewSSLOpts ->
|
||||
OldSSLOpts = maps:get(<<"ssl">>, OldConfig, #{}),
|
||||
Diff = diff_certs(NewSSLOpts, OldSSLOpts),
|
||||
NSSLOpts = lists:foldl(fun({identical, K}, Acc) ->
|
||||
Acc#{K => maps:get(K, OldSSLOpts)};
|
||||
({_, K}, Acc) ->
|
||||
CertFile = generate_filename(CertsDir, K),
|
||||
ok = save_cert_to_file(CertFile, maps:get(K, NewSSLOpts)),
|
||||
Acc#{K => CertFile}
|
||||
end, NewSSLOpts, Diff),
|
||||
NewConfig#{<<"ssl">> => NSSLOpts}
|
||||
end.
|
||||
|
||||
clear_certs(CertsDir, #{<<"ssl">> := SSLOpts}) ->
|
||||
lists:foreach(
|
||||
fun({_, Filename}) ->
|
||||
_ = file:delete(filename:join([CertsDir, Filename]))
|
||||
end,
|
||||
maps:to_list(maps:with([<<"certfile">>, <<"keyfile">>, <<"cacertfile">>], SSLOpts)));
|
||||
clear_certs(_CertsDir, _Config) ->
|
||||
ok.
|
||||
clear_certs(CertsDir, Config) ->
|
||||
case maps:get(<<"ssl">>, Config, undefined) of
|
||||
undefined ->
|
||||
ok;
|
||||
SSLOpts ->
|
||||
lists:foreach(
|
||||
fun({_, Filename}) ->
|
||||
_ = file:delete(filename:join([CertsDir, Filename]))
|
||||
end,
|
||||
maps:to_list(maps:with([<<"certfile">>, <<"keyfile">>, <<"cacertfile">>], SSLOpts)))
|
||||
end.
|
||||
|
||||
save_cert_to_file(Filename, PemBin) ->
|
||||
case public_key:pem_decode(PemBin) =/= [] of
|
||||
|
|
|
@ -1840,11 +1840,10 @@ find_listener(ListenerID) ->
|
|||
{ok, {Type, Name}}
|
||||
end.
|
||||
|
||||
create_authenticator(ConfKeyPath, ChainName0, Config) ->
|
||||
ChainName = to_atom(ChainName0),
|
||||
case update_config(ConfKeyPath, {create_authenticator, ChainName, Config}) of
|
||||
create_authenticator(ConfKeyPath, ChainName, Config) ->
|
||||
case update_config(ConfKeyPath, {create_authenticator, to_atom(ChainName), Config}) of
|
||||
{ok, #{post_config_update := #{?AUTHN := #{id := ID}},
|
||||
raw_config := AuthenticatorsConfig}} ->
|
||||
raw_config := AuthenticatorsConfig}} ->
|
||||
{ok, AuthenticatorConfig} = find_config(ID, AuthenticatorsConfig),
|
||||
{200, maps:put(id, ID, convert_certs(fill_defaults(AuthenticatorConfig)))};
|
||||
{error, {_, _, Reason}} ->
|
||||
|
@ -1866,9 +1865,8 @@ list_authenticator(ConfKeyPath, AuthenticatorID) ->
|
|||
serialize_error(Reason)
|
||||
end.
|
||||
|
||||
update_authenticator(ConfKeyPath, ChainName0, AuthenticatorID, Config) ->
|
||||
ChainName = to_atom(ChainName0),
|
||||
case update_config(ConfKeyPath, {update_authenticator, ChainName, AuthenticatorID, Config}) of
|
||||
update_authenticator(ConfKeyPath, ChainName, AuthenticatorID, Config) ->
|
||||
case update_config(ConfKeyPath, {update_authenticator, to_atom(ChainName), AuthenticatorID, Config}) of
|
||||
{ok, #{post_config_update := #{?AUTHN := #{id := ID}},
|
||||
raw_config := AuthenticatorsConfig}} ->
|
||||
{ok, AuthenticatorConfig} = find_config(ID, AuthenticatorsConfig),
|
||||
|
|
Loading…
Reference in New Issue