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