|
@@ -122,6 +122,7 @@ schema("/configs") ->
|
|
|
}}
|
|
}}
|
|
|
]
|
|
]
|
|
|
},
|
|
},
|
|
|
|
|
+ 400 => emqx_dashboard_swagger:error_codes(['INVALID_ACCEPT']),
|
|
|
404 => emqx_dashboard_swagger:error_codes(['NOT_FOUND']),
|
|
404 => emqx_dashboard_swagger:error_codes(['NOT_FOUND']),
|
|
|
500 => emqx_dashboard_swagger:error_codes(['BAD_NODE'])
|
|
500 => emqx_dashboard_swagger:error_codes(['BAD_NODE'])
|
|
|
}
|
|
}
|
|
@@ -337,9 +338,10 @@ config_reset(post, _Params, Req) ->
|
|
|
|
|
|
|
|
configs(get, #{query_string := QueryStr, headers := Headers}, _Req) ->
|
|
configs(get, #{query_string := QueryStr, headers := Headers}, _Req) ->
|
|
|
%% Should deprecated json v1 since 5.2.0
|
|
%% Should deprecated json v1 since 5.2.0
|
|
|
- case maps:get(<<"accept">>, Headers, <<"text/plain">>) of
|
|
|
|
|
- <<"application/json">> -> get_configs_v1(QueryStr);
|
|
|
|
|
- <<"text/plain">> -> get_configs_v2(QueryStr)
|
|
|
|
|
|
|
+ case find_suitable_accept(Headers, [<<"text/plain">>, <<"application/json">>]) of
|
|
|
|
|
+ {ok, <<"application/json">>} -> get_configs_v1(QueryStr);
|
|
|
|
|
+ {ok, <<"text/plain">>} -> get_configs_v2(QueryStr);
|
|
|
|
|
+ {error, _} = Error -> {400, #{code => 'INVALID_ACCEPT', message => ?ERR_MSG(Error)}}
|
|
|
end;
|
|
end;
|
|
|
configs(put, #{body := Conf, query_string := #{<<"mode">> := Mode}}, _Req) ->
|
|
configs(put, #{body := Conf, query_string := #{<<"mode">> := Mode}}, _Req) ->
|
|
|
case emqx_conf_cli:load_config(Conf, Mode) of
|
|
case emqx_conf_cli:load_config(Conf, Mode) of
|
|
@@ -348,6 +350,28 @@ configs(put, #{body := Conf, query_string := #{<<"mode">> := Mode}}, _Req) ->
|
|
|
{error, Errors} -> {400, #{code => 'UPDATE_FAILED', message => ?ERR_MSG(Errors)}}
|
|
{error, Errors} -> {400, #{code => 'UPDATE_FAILED', message => ?ERR_MSG(Errors)}}
|
|
|
end.
|
|
end.
|
|
|
|
|
|
|
|
|
|
+find_suitable_accept(Headers, Perferences) when is_list(Perferences), length(Perferences) > 0 ->
|
|
|
|
|
+ AcceptVal = maps:get(<<"accept">>, Headers, <<"*/*">>),
|
|
|
|
|
+ %% Multiple types, weighted with the quality value syntax:
|
|
|
|
|
+ %% Accept: text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8
|
|
|
|
|
+ Accepts = lists:map(
|
|
|
|
|
+ fun(S) ->
|
|
|
|
|
+ [T | _] = binary:split(string:trim(S), <<";">>),
|
|
|
|
|
+ T
|
|
|
|
|
+ end,
|
|
|
|
|
+ re:split(AcceptVal, ",")
|
|
|
|
|
+ ),
|
|
|
|
|
+ case lists:member(<<"*/*">>, Accepts) of
|
|
|
|
|
+ true ->
|
|
|
|
|
+ {ok, lists:nth(1, Perferences)};
|
|
|
|
|
+ false ->
|
|
|
|
|
+ Found = lists:filter(fun(Accept) -> lists:member(Accept, Accepts) end, Perferences),
|
|
|
|
|
+ case Found of
|
|
|
|
|
+ [] -> {error, no_suitalbe_accept};
|
|
|
|
|
+ _ -> {ok, lists:nth(1, Found)}
|
|
|
|
|
+ end
|
|
|
|
|
+ end.
|
|
|
|
|
+
|
|
|
get_configs_v1(QueryStr) ->
|
|
get_configs_v1(QueryStr) ->
|
|
|
Node = maps:get(<<"node">>, QueryStr, node()),
|
|
Node = maps:get(<<"node">>, QueryStr, node()),
|
|
|
case
|
|
case
|