chore: fix gateway authz cases

This commit is contained in:
JianBo He 2022-07-01 21:08:58 +08:00
parent 4c17b38102
commit 2d8231c638
1 changed files with 12 additions and 3 deletions

View File

@ -65,6 +65,15 @@
-record(state, {}).
-define(AUTHZ_HTTP_RESP(Result, Req),
cowboy_req:reply(
200,
#{<<"content-type">> => <<"application/json">>},
"{\"result\": \"" ++ atom_to_list(Result) ++ "\"}",
Req
)
).
%%------------------------------------------------------------------------------
%% API
%%------------------------------------------------------------------------------
@ -169,12 +178,12 @@ on_start_auth(authz_http) ->
Handler = fun(Req0, State) ->
case cowboy_req:match_qs([topic, action, username], Req0) of
#{topic := <<"/publish">>, action := <<"publish">>} ->
Req = cowboy_req:reply(200, Req0);
Req = ?AUTHZ_HTTP_RESP(allow, Req0);
#{topic := <<"/subscribe">>, action := <<"subscribe">>} ->
Req = cowboy_req:reply(200, Req0);
Req = ?AUTHZ_HTTP_RESP(allow, Req0);
%% for lwm2m
#{username := <<"lwm2m">>} ->
Req = cowboy_req:reply(200, Req0);
Req = ?AUTHZ_HTTP_RESP(allow, Req0);
_ ->
Req = cowboy_req:reply(400, Req0)
end,