Merge pull request #12240 from zhongwencool/ft-api-e-541
fix: return raw config when update ft's config
This commit is contained in:
commit
a6acebb4aa
|
@ -2,7 +2,7 @@
|
||||||
{application, emqx, [
|
{application, emqx, [
|
||||||
{id, "emqx"},
|
{id, "emqx"},
|
||||||
{description, "EMQX Core"},
|
{description, "EMQX Core"},
|
||||||
{vsn, "5.1.17"},
|
{vsn, "5.1.18"},
|
||||||
{modules, []},
|
{modules, []},
|
||||||
{registered, []},
|
{registered, []},
|
||||||
{applications, [
|
{applications, [
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{application, emqx_ft, [
|
{application, emqx_ft, [
|
||||||
{description, "EMQX file transfer over MQTT"},
|
{description, "EMQX file transfer over MQTT"},
|
||||||
{vsn, "0.1.11"},
|
{vsn, "0.1.12"},
|
||||||
{registered, []},
|
{registered, []},
|
||||||
{mod, {emqx_ft_app, []}},
|
{mod, {emqx_ft_app, []}},
|
||||||
{applications, [
|
{applications, [
|
||||||
|
|
|
@ -176,13 +176,13 @@ check_ft_enabled(Params, _Meta) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
'/file_transfer'(get, _Meta) ->
|
'/file_transfer'(get, _Meta) ->
|
||||||
{200, format_config(emqx_ft_conf:get())};
|
{200, format_config(emqx_ft_conf:get_raw())};
|
||||||
'/file_transfer'(put, #{body := ConfigIn}) ->
|
'/file_transfer'(put, #{body := ConfigIn}) ->
|
||||||
OldConf = emqx_ft_conf:get_raw(),
|
OldConf = emqx_ft_conf:get_raw(),
|
||||||
UpdateConf = emqx_utils:deobfuscate(ConfigIn, OldConf),
|
UpdateConf = emqx_utils:deobfuscate(ConfigIn, OldConf),
|
||||||
case emqx_ft_conf:update(UpdateConf) of
|
case emqx_ft_conf:update(UpdateConf) of
|
||||||
{ok, #{config := Config}} ->
|
{ok, #{raw_config := RawConfig}} ->
|
||||||
{200, format_config(Config)};
|
{200, format_config(RawConfig)};
|
||||||
{error, Error = #{kind := validation_error}} ->
|
{error, Error = #{kind := validation_error}} ->
|
||||||
{400, error_msg('INVALID_CONFIG', format_validation_error(Error))};
|
{400, error_msg('INVALID_CONFIG', format_validation_error(Error))};
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
|
@ -199,13 +199,11 @@ format_page(#{items := Files}) ->
|
||||||
<<"files">> => lists:map(fun format_file_info/1, Files)
|
<<"files">> => lists:map(fun format_file_info/1, Files)
|
||||||
}.
|
}.
|
||||||
|
|
||||||
format_config(Config) ->
|
format_config(RawConf) ->
|
||||||
Schema = emqx_hocon:make_schema(emqx_ft_schema:fields(file_transfer)),
|
RootKey = <<"file_transfer">>,
|
||||||
hocon_tconf:make_serializable(
|
Opts = #{obfuscate_sensitive_values => true, make_serializable => true},
|
||||||
Schema,
|
Conf = emqx_config:fill_defaults(emqx_ft_schema, #{RootKey => RawConf}, Opts),
|
||||||
emqx_utils_maps:binary_key_map(Config),
|
maps:get(RootKey, Conf).
|
||||||
#{obfuscate_sensitive_values => true}
|
|
||||||
).
|
|
||||||
|
|
||||||
format_validation_error(Error) ->
|
format_validation_error(Error) ->
|
||||||
emqx_logger_jsonfmt:best_effort_json(Error).
|
emqx_logger_jsonfmt:best_effort_json(Error).
|
||||||
|
|
|
@ -345,6 +345,7 @@ test_configure(Uri, Config) ->
|
||||||
<<"host">> => <<"localhost">>,
|
<<"host">> => <<"localhost">>,
|
||||||
<<"port">> => 9000,
|
<<"port">> => 9000,
|
||||||
<<"bucket">> => <<"emqx">>,
|
<<"bucket">> => <<"emqx">>,
|
||||||
|
<<"url_expire_time">> => <<"2h">>,
|
||||||
<<"secret_access_key">> => ?SECRET_ACCESS_KEY,
|
<<"secret_access_key">> => ?SECRET_ACCESS_KEY,
|
||||||
<<"transport_options">> => #{
|
<<"transport_options">> => #{
|
||||||
<<"ssl">> => #{
|
<<"ssl">> => #{
|
||||||
|
@ -384,6 +385,8 @@ test_configure(Uri, Config) ->
|
||||||
<<"keyfile">> := <<"/", _KeyFilepath/bytes>>
|
<<"keyfile">> := <<"/", _KeyFilepath/bytes>>
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
%% ensure 2h is unchanged
|
||||||
|
<<"url_expire_time">> := <<"2h">>,
|
||||||
<<"secret_access_key">> := <<"******">>
|
<<"secret_access_key">> := <<"******">>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue