Merge pull request #7815 from terry-xiaoyu/fix_bridge_ssl_dry_run_fail
fix: convert ssl certfiles for dry-run creating bridges
This commit is contained in:
commit
8528d76371
|
@ -166,6 +166,7 @@ t_trans(_) ->
|
||||||
).
|
).
|
||||||
|
|
||||||
with_metrics_server(Fun) ->
|
with_metrics_server(Fun) ->
|
||||||
|
_ = supervisor:terminate_child(emqx_kernel_sup, emqx_metrics),
|
||||||
{ok, _} = emqx_metrics:start_link(),
|
{ok, _} = emqx_metrics:start_link(),
|
||||||
_ = Fun(),
|
_ = Fun(),
|
||||||
ok = emqx_metrics:stop().
|
ok = emqx_metrics:stop().
|
||||||
|
|
|
@ -343,20 +343,18 @@ recreate(Type, Name, Conf) ->
|
||||||
).
|
).
|
||||||
|
|
||||||
create_dry_run(Type, Conf) ->
|
create_dry_run(Type, Conf) ->
|
||||||
Conf0 = Conf#{
|
Conf0 = fill_dry_run_conf(Conf),
|
||||||
<<"egress">> =>
|
|
||||||
#{
|
|
||||||
<<"remote_topic">> => <<"t">>,
|
|
||||||
<<"remote_qos">> => 0,
|
|
||||||
<<"retain">> => true,
|
|
||||||
<<"payload">> => <<"val">>
|
|
||||||
},
|
|
||||||
<<"ingress">> =>
|
|
||||||
#{<<"remote_topic">> => <<"t">>}
|
|
||||||
},
|
|
||||||
case emqx_resource:check_config(emqx_bridge:resource_type(Type), Conf0) of
|
case emqx_resource:check_config(emqx_bridge:resource_type(Type), Conf0) of
|
||||||
{ok, Conf1} ->
|
{ok, Conf1} ->
|
||||||
emqx_resource:create_dry_run_local(emqx_bridge:resource_type(Type), Conf1);
|
TmpPath = iolist_to_binary(["bridges-create-dry-run:", emqx_misc:gen_id(8)]),
|
||||||
|
try emqx_connector_ssl:convert_certs(TmpPath, Conf1) of
|
||||||
|
{error, Reason} ->
|
||||||
|
{error, Reason};
|
||||||
|
{ok, ConfNew} ->
|
||||||
|
emqx_resource:create_dry_run_local(emqx_bridge:resource_type(Type), ConfNew)
|
||||||
|
after
|
||||||
|
emqx_connector_ssl:clear_certs(TmpPath, Conf1)
|
||||||
|
end;
|
||||||
{error, _} = Error ->
|
{error, _} = Error ->
|
||||||
Error
|
Error
|
||||||
end.
|
end.
|
||||||
|
@ -557,6 +555,19 @@ get_basic_usage_info() ->
|
||||||
InitialAcc
|
InitialAcc
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
fill_dry_run_conf(Conf) ->
|
||||||
|
Conf#{
|
||||||
|
<<"egress">> =>
|
||||||
|
#{
|
||||||
|
<<"remote_topic">> => <<"t">>,
|
||||||
|
<<"remote_qos">> => 0,
|
||||||
|
<<"retain">> => true,
|
||||||
|
<<"payload">> => <<"val">>
|
||||||
|
},
|
||||||
|
<<"ingress">> =>
|
||||||
|
#{<<"remote_topic">> => <<"t">>}
|
||||||
|
}.
|
||||||
|
|
||||||
bin(Bin) when is_binary(Bin) -> Bin;
|
bin(Bin) when is_binary(Bin) -> Bin;
|
||||||
bin(Str) when is_list(Str) -> list_to_binary(Str);
|
bin(Str) when is_list(Str) -> list_to_binary(Str);
|
||||||
bin(Atom) when is_atom(Atom) -> atom_to_binary(Atom, utf8).
|
bin(Atom) when is_atom(Atom) -> atom_to_binary(Atom, utf8).
|
||||||
|
|
|
@ -648,11 +648,11 @@ fill_defaults(Type, RawConf) ->
|
||||||
unpack_bridge_conf(Type, FullConf).
|
unpack_bridge_conf(Type, FullConf).
|
||||||
|
|
||||||
pack_bridge_conf(Type, RawConf) ->
|
pack_bridge_conf(Type, RawConf) ->
|
||||||
#{<<"bridges">> => #{Type => #{<<"foo">> => RawConf}}}.
|
#{<<"bridges">> => #{bin(Type) => #{<<"foo">> => RawConf}}}.
|
||||||
|
|
||||||
unpack_bridge_conf(Type, PackedConf) ->
|
unpack_bridge_conf(Type, PackedConf) ->
|
||||||
#{<<"bridges">> := Bridges} = PackedConf,
|
#{<<"bridges">> := Bridges} = PackedConf,
|
||||||
#{<<"foo">> := RawConf} = maps:get(Type, Bridges),
|
#{<<"foo">> := RawConf} = maps:get(bin(Type), Bridges),
|
||||||
RawConf.
|
RawConf.
|
||||||
|
|
||||||
is_ok(ResL) ->
|
is_ok(ResL) ->
|
||||||
|
@ -689,4 +689,8 @@ error_msg(Code, Msg) ->
|
||||||
#{code => Code, message => bin(io_lib:format("~p", [Msg]))}.
|
#{code => Code, message => bin(io_lib:format("~p", [Msg]))}.
|
||||||
|
|
||||||
bin(S) when is_list(S) ->
|
bin(S) when is_list(S) ->
|
||||||
list_to_binary(S).
|
list_to_binary(S);
|
||||||
|
bin(S) when is_atom(S) ->
|
||||||
|
atom_to_binary(S, utf8);
|
||||||
|
bin(S) when is_binary(S) ->
|
||||||
|
S.
|
||||||
|
|
|
@ -171,6 +171,7 @@ t_http_crud_apis(_) ->
|
||||||
#{
|
#{
|
||||||
<<"type">> := ?BRIDGE_TYPE,
|
<<"type">> := ?BRIDGE_TYPE,
|
||||||
<<"name">> := ?BRIDGE_NAME,
|
<<"name">> := ?BRIDGE_NAME,
|
||||||
|
<<"enable">> := true,
|
||||||
<<"status">> := _,
|
<<"status">> := _,
|
||||||
<<"node_status">> := [_ | _],
|
<<"node_status">> := [_ | _],
|
||||||
<<"metrics">> := _,
|
<<"metrics">> := _,
|
||||||
|
@ -208,6 +209,7 @@ t_http_crud_apis(_) ->
|
||||||
#{
|
#{
|
||||||
<<"type">> := ?BRIDGE_TYPE,
|
<<"type">> := ?BRIDGE_TYPE,
|
||||||
<<"name">> := ?BRIDGE_NAME,
|
<<"name">> := ?BRIDGE_NAME,
|
||||||
|
<<"enable">> := true,
|
||||||
<<"status">> := _,
|
<<"status">> := _,
|
||||||
<<"node_status">> := [_ | _],
|
<<"node_status">> := [_ | _],
|
||||||
<<"metrics">> := _,
|
<<"metrics">> := _,
|
||||||
|
@ -224,6 +226,7 @@ t_http_crud_apis(_) ->
|
||||||
#{
|
#{
|
||||||
<<"type">> := ?BRIDGE_TYPE,
|
<<"type">> := ?BRIDGE_TYPE,
|
||||||
<<"name">> := ?BRIDGE_NAME,
|
<<"name">> := ?BRIDGE_NAME,
|
||||||
|
<<"enable">> := true,
|
||||||
<<"status">> := _,
|
<<"status">> := _,
|
||||||
<<"node_status">> := [_ | _],
|
<<"node_status">> := [_ | _],
|
||||||
<<"metrics">> := _,
|
<<"metrics">> := _,
|
||||||
|
@ -240,6 +243,7 @@ t_http_crud_apis(_) ->
|
||||||
#{
|
#{
|
||||||
<<"type">> := ?BRIDGE_TYPE,
|
<<"type">> := ?BRIDGE_TYPE,
|
||||||
<<"name">> := ?BRIDGE_NAME,
|
<<"name">> := ?BRIDGE_NAME,
|
||||||
|
<<"enable">> := true,
|
||||||
<<"status">> := _,
|
<<"status">> := _,
|
||||||
<<"node_status">> := [_ | _],
|
<<"node_status">> := [_ | _],
|
||||||
<<"metrics">> := _,
|
<<"metrics">> := _,
|
||||||
|
@ -305,6 +309,7 @@ do_start_stop_bridges(Type) ->
|
||||||
#{
|
#{
|
||||||
<<"type">> := ?BRIDGE_TYPE,
|
<<"type">> := ?BRIDGE_TYPE,
|
||||||
<<"name">> := ?BRIDGE_NAME,
|
<<"name">> := ?BRIDGE_NAME,
|
||||||
|
<<"enable">> := true,
|
||||||
<<"status">> := <<"connected">>,
|
<<"status">> := <<"connected">>,
|
||||||
<<"node_status">> := [_ | _],
|
<<"node_status">> := [_ | _],
|
||||||
<<"metrics">> := _,
|
<<"metrics">> := _,
|
||||||
|
@ -349,6 +354,7 @@ t_enable_disable_bridges(_) ->
|
||||||
#{
|
#{
|
||||||
<<"type">> := ?BRIDGE_TYPE,
|
<<"type">> := ?BRIDGE_TYPE,
|
||||||
<<"name">> := ?BRIDGE_NAME,
|
<<"name">> := ?BRIDGE_NAME,
|
||||||
|
<<"enable">> := true,
|
||||||
<<"status">> := <<"connected">>,
|
<<"status">> := <<"connected">>,
|
||||||
<<"node_status">> := [_ | _],
|
<<"node_status">> := [_ | _],
|
||||||
<<"metrics">> := _,
|
<<"metrics">> := _,
|
||||||
|
@ -397,6 +403,7 @@ t_reset_bridges(_) ->
|
||||||
#{
|
#{
|
||||||
<<"type">> := ?BRIDGE_TYPE,
|
<<"type">> := ?BRIDGE_TYPE,
|
||||||
<<"name">> := ?BRIDGE_NAME,
|
<<"name">> := ?BRIDGE_NAME,
|
||||||
|
<<"enable">> := true,
|
||||||
<<"status">> := <<"connected">>,
|
<<"status">> := <<"connected">>,
|
||||||
<<"node_status">> := [_ | _],
|
<<"node_status">> := [_ | _],
|
||||||
<<"metrics">> := _,
|
<<"metrics">> := _,
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
]).
|
]).
|
||||||
|
|
||||||
convert_certs(RltvDir, NewConfig) ->
|
convert_certs(RltvDir, NewConfig) ->
|
||||||
NewSSL = drop_invalid_certs(maps:get(<<"ssl">>, NewConfig, undefined)),
|
NewSSL = drop_invalid_certs(map_get_oneof([<<"ssl">>, ssl], NewConfig, undefined)),
|
||||||
case emqx_tls_lib:ensure_ssl_files(RltvDir, NewSSL) of
|
case emqx_tls_lib:ensure_ssl_files(RltvDir, NewSSL) of
|
||||||
{ok, NewSSL1} ->
|
{ok, NewSSL1} ->
|
||||||
{ok, new_ssl_config(NewConfig, NewSSL1)};
|
{ok, new_ssl_config(NewConfig, NewSSL1)};
|
||||||
|
@ -35,7 +35,8 @@ clear_certs(RltvDir, Config) ->
|
||||||
ok = emqx_tls_lib:delete_ssl_files(RltvDir, undefined, OldSSL).
|
ok = emqx_tls_lib:delete_ssl_files(RltvDir, undefined, OldSSL).
|
||||||
|
|
||||||
new_ssl_config(Config, undefined) -> Config;
|
new_ssl_config(Config, undefined) -> Config;
|
||||||
new_ssl_config(Config, SSL) -> Config#{<<"ssl">> => SSL}.
|
new_ssl_config(Config, #{<<"enable">> := _} = SSL) -> Config#{<<"ssl">> => SSL};
|
||||||
|
new_ssl_config(Config, #{enable := _} = SSL) -> Config#{ssl => SSL}.
|
||||||
|
|
||||||
drop_invalid_certs(undefined) -> undefined;
|
drop_invalid_certs(undefined) -> undefined;
|
||||||
drop_invalid_certs(SSL) -> emqx_tls_lib:drop_invalid_certs(SSL).
|
drop_invalid_certs(SSL) -> emqx_tls_lib:drop_invalid_certs(SSL).
|
||||||
|
|
Loading…
Reference in New Issue