chore(gw): return 204 if no authn config

This commit is contained in:
JianBo He 2021-10-18 19:23:19 +08:00
parent 46e0609544
commit 2416fa4e13
4 changed files with 22 additions and 6 deletions

View File

@ -112,7 +112,7 @@ gateway_insta(get, #{bindings := #{name := Name0}}) ->
{200, maps:merge(GwConf, GwInfo1)} {200, maps:merge(GwConf, GwInfo1)}
end end
catch catch
error : badname -> error : badarg ->
return_http_error(400, "Bad gateway name") return_http_error(400, "Bad gateway name")
end; end;
gateway_insta(put, #{body := GwConf, gateway_insta(put, #{body := GwConf,

View File

@ -53,7 +53,14 @@ apis() ->
authn(get, #{bindings := #{name := Name0}}) -> authn(get, #{bindings := #{name := Name0}}) ->
with_gateway(Name0, fun(GwName, _) -> with_gateway(Name0, fun(GwName, _) ->
{200, emqx_gateway_http:authn(GwName)} try
emqx_gateway_http:authn(GwName)
of
Authn -> {200, Authn}
catch
error : {config_not_found, _} ->
{204}
end
end); end);
authn(put, #{bindings := #{name := Name0}, authn(put, #{bindings := #{name := Name0},
@ -104,6 +111,7 @@ swagger("/gateway/:name/authentication", get) ->
, <<"404">> => schema_not_found() , <<"404">> => schema_not_found()
, <<"500">> => schema_internal_error() , <<"500">> => schema_internal_error()
, <<"200">> => schema_authn() , <<"200">> => schema_authn()
, <<"204">> => schema_no_content()
} }
}; };
swagger("/gateway/:name/authentication", put) -> swagger("/gateway/:name/authentication", put) ->

View File

@ -112,7 +112,14 @@ listeners_insta_authn(get, #{bindings := #{name := Name0,
id := ListenerId0}}) -> id := ListenerId0}}) ->
ListenerId = emqx_mgmt_util:urldecode(ListenerId0), ListenerId = emqx_mgmt_util:urldecode(ListenerId0),
with_gateway(Name0, fun(GwName, _) -> with_gateway(Name0, fun(GwName, _) ->
{200, emqx_gateway_http:authn(GwName, ListenerId)} try
emqx_gateway_http:authn(GwName, ListenerId)
of
Authn -> {200, Authn}
catch
error : {config_not_found, _} ->
{204}
end
end); end);
listeners_insta_authn(post, #{body := Conf, listeners_insta_authn(post, #{body := Conf,
bindings := #{name := Name0, bindings := #{name := Name0,
@ -222,6 +229,7 @@ swagger("/gateway/:name/listeners/:id/authentication", get) ->
, <<"404">> => schema_not_found() , <<"404">> => schema_not_found()
, <<"500">> => schema_internal_error() , <<"500">> => schema_internal_error()
, <<"200">> => schema_authn() , <<"200">> => schema_authn()
, <<"204">> => schema_no_content()
} }
}; };
swagger("/gateway/:name/listeners/:id/authentication", post) -> swagger("/gateway/:name/listeners/:id/authentication", post) ->

View File

@ -32,7 +32,7 @@
%% Setup %% Setup
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
all() -> emqx_ct:all(?MODULE). all() -> emqx_common_test_helpers:all(?MODULE).
init_per_suite(Conf) -> init_per_suite(Conf) ->
%% FIXME: Magic line. for saving gateway schema name for emqx_config %% FIXME: Magic line. for saving gateway schema name for emqx_config
@ -189,7 +189,7 @@ t_gateway_exproto(_) ->
t_authn(_) -> t_authn(_) ->
GwConf = #{name => <<"stomp">>}, GwConf = #{name => <<"stomp">>},
{204, _} = request(post, "/gateway", GwConf), {204, _} = request(post, "/gateway", GwConf),
{404, _} = request(get, "/gateway/stomp/authentication"), {204, _} = request(get, "/gateway/stomp/authentication"),
AuthConf = #{mechanism => <<"password-based">>, AuthConf = #{mechanism => <<"password-based">>,
backend => <<"built-in-database">>, backend => <<"built-in-database">>,
@ -206,7 +206,7 @@ t_authn(_) ->
assert_confs(AuthConf2, ConfResp2), assert_confs(AuthConf2, ConfResp2),
{204, _} = request(delete, "/gateway/stomp/authentication"), {204, _} = request(delete, "/gateway/stomp/authentication"),
{404, _} = request(get, "/gateway/stomp/authentication"), {204, _} = request(get, "/gateway/stomp/authentication"),
{204, _} = request(delete, "/gateway/stomp"). {204, _} = request(delete, "/gateway/stomp").
t_listeners(_) -> t_listeners(_) ->