fix(authz): `DELETE` method return codes
This commit is contained in:
parent
09404c555f
commit
ba05cdc412
|
@ -171,6 +171,8 @@ schema("/authorization/sources/built-in-database/username/:username") ->
|
|||
#{ 204 => <<"Deleted">>
|
||||
, 400 => emqx_dashboard_swagger:error_codes(
|
||||
[?BAD_REQUEST], <<"Bad username">>)
|
||||
, 404 => emqx_dashboard_swagger:error_codes(
|
||||
[?NOT_FOUND], <<"Username Not Found">>)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -207,6 +209,8 @@ schema("/authorization/sources/built-in-database/clientid/:clientid") ->
|
|||
#{ 204 => <<"Deleted">>
|
||||
, 400 => emqx_dashboard_swagger:error_codes(
|
||||
[?BAD_REQUEST], <<"Bad clientid">>)
|
||||
, 404 => emqx_dashboard_swagger:error_codes(
|
||||
[?NOT_FOUND], <<"ClientID Not Found">>)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -315,8 +319,8 @@ clients(get, #{query_string := QueryString}) ->
|
|||
?ACL_TABLE, ?ACL_CLIENTID_QSCHEMA, ?QUERY_CLIENTID_FUN),
|
||||
emqx_mgmt_util:generate_response(Response);
|
||||
clients(post, #{body := Body}) when is_list(Body) ->
|
||||
lists:foreach(fun(#{<<"clientid">> := Clientid, <<"rules">> := Rules}) ->
|
||||
emqx_authz_mnesia:store_rules({clientid, Clientid}, format_rules(Rules))
|
||||
lists:foreach(fun(#{<<"clientid">> := ClientID, <<"rules">> := Rules}) ->
|
||||
emqx_authz_mnesia:store_rules({clientid, ClientID}, format_rules(Rules))
|
||||
end, Body),
|
||||
{204}.
|
||||
|
||||
|
@ -332,31 +336,41 @@ user(get, #{bindings := #{username := Username}}) ->
|
|||
}
|
||||
end;
|
||||
user(put, #{bindings := #{username := Username},
|
||||
body := #{<<"username">> := Username, <<"rules">> := Rules}}) ->
|
||||
body := #{<<"username">> := Username, <<"rules">> := Rules}}) ->
|
||||
emqx_authz_mnesia:store_rules({username, Username}, format_rules(Rules)),
|
||||
{204};
|
||||
user(delete, #{bindings := #{username := Username}}) ->
|
||||
emqx_authz_mnesia:delete_rules({username, Username}),
|
||||
{204}.
|
||||
case emqx_authz_mnesia:get_rules({username, Username}) of
|
||||
not_found ->
|
||||
{404, #{code => <<"NOT_FOUND">>, message => <<"Username Not Found">>}};
|
||||
{ok, _Rules} ->
|
||||
emqx_authz_mnesia:delete_rules({username, Username}),
|
||||
{204}
|
||||
end.
|
||||
|
||||
client(get, #{bindings := #{clientid := Clientid}}) ->
|
||||
case emqx_authz_mnesia:get_rules({clientid, Clientid}) of
|
||||
client(get, #{bindings := #{clientid := ClientID}}) ->
|
||||
case emqx_authz_mnesia:get_rules({clientid, ClientID}) of
|
||||
not_found -> {404, #{code => <<"NOT_FOUND">>, message => <<"Not Found">>}};
|
||||
{ok, Rules} ->
|
||||
{200, #{clientid => Clientid,
|
||||
{200, #{clientid => ClientID,
|
||||
rules => [ #{topic => Topic,
|
||||
action => Action,
|
||||
permission => Permission
|
||||
} || {Permission, Action, Topic} <- Rules]}
|
||||
}
|
||||
end;
|
||||
client(put, #{bindings := #{clientid := Clientid},
|
||||
body := #{<<"clientid">> := Clientid, <<"rules">> := Rules}}) ->
|
||||
emqx_authz_mnesia:store_rules({clientid, Clientid}, format_rules(Rules)),
|
||||
client(put, #{bindings := #{clientid := ClientID},
|
||||
body := #{<<"clientid">> := ClientID, <<"rules">> := Rules}}) ->
|
||||
emqx_authz_mnesia:store_rules({clientid, ClientID}, format_rules(Rules)),
|
||||
{204};
|
||||
client(delete, #{bindings := #{clientid := Clientid}}) ->
|
||||
emqx_authz_mnesia:delete_rules({clientid, Clientid}),
|
||||
{204}.
|
||||
client(delete, #{bindings := #{clientid := ClientID}}) ->
|
||||
case emqx_authz_mnesia:get_rules({clientid, ClientID}) of
|
||||
not_found ->
|
||||
{404, #{code => <<"NOT_FOUND">>, message => <<"ClientID Not Found">>}};
|
||||
{ok, _Rules} ->
|
||||
emqx_authz_mnesia:delete_rules({clientid, ClientID}),
|
||||
{204}
|
||||
end.
|
||||
|
||||
all(get, _) ->
|
||||
case emqx_authz_mnesia:get_rules(all) of
|
||||
|
@ -453,8 +467,8 @@ format_result([{username, Username}, {rules, Rules}]) ->
|
|||
permission => Permission
|
||||
} || {Permission, Action, Topic} <- Rules]
|
||||
};
|
||||
format_result([{clientid, Clientid}, {rules, Rules}]) ->
|
||||
#{clientid => Clientid,
|
||||
format_result([{clientid, ClientID}, {rules, Rules}]) ->
|
||||
#{clientid => ClientID,
|
||||
rules => [ #{topic => Topic,
|
||||
action => Action,
|
||||
permission => Permission
|
||||
|
|
Loading…
Reference in New Issue