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