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">>
|
#{ 204 => <<"Deleted">>
|
||||||
, 400 => emqx_dashboard_swagger:error_codes(
|
, 400 => emqx_dashboard_swagger:error_codes(
|
||||||
[?BAD_REQUEST], <<"Bad username">>)
|
[?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">>
|
#{ 204 => <<"Deleted">>
|
||||||
, 400 => emqx_dashboard_swagger:error_codes(
|
, 400 => emqx_dashboard_swagger:error_codes(
|
||||||
[?BAD_REQUEST], <<"Bad clientid">>)
|
[?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),
|
?ACL_TABLE, ?ACL_CLIENTID_QSCHEMA, ?QUERY_CLIENTID_FUN),
|
||||||
emqx_mgmt_util:generate_response(Response);
|
emqx_mgmt_util:generate_response(Response);
|
||||||
clients(post, #{body := Body}) when is_list(Body) ->
|
clients(post, #{body := Body}) when is_list(Body) ->
|
||||||
lists:foreach(fun(#{<<"clientid">> := Clientid, <<"rules">> := Rules}) ->
|
lists:foreach(fun(#{<<"clientid">> := ClientID, <<"rules">> := Rules}) ->
|
||||||
emqx_authz_mnesia:store_rules({clientid, Clientid}, format_rules(Rules))
|
emqx_authz_mnesia:store_rules({clientid, ClientID}, format_rules(Rules))
|
||||||
end, Body),
|
end, Body),
|
||||||
{204}.
|
{204}.
|
||||||
|
|
||||||
|
@ -336,27 +340,37 @@ user(put, #{bindings := #{username := Username},
|
||||||
emqx_authz_mnesia:store_rules({username, Username}, format_rules(Rules)),
|
emqx_authz_mnesia:store_rules({username, Username}, format_rules(Rules)),
|
||||||
{204};
|
{204};
|
||||||
user(delete, #{bindings := #{username := Username}}) ->
|
user(delete, #{bindings := #{username := Username}}) ->
|
||||||
|
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}),
|
emqx_authz_mnesia:delete_rules({username, Username}),
|
||||||
{204}.
|
{204}
|
||||||
|
end.
|
||||||
|
|
||||||
client(get, #{bindings := #{clientid := Clientid}}) ->
|
client(get, #{bindings := #{clientid := ClientID}}) ->
|
||||||
case emqx_authz_mnesia:get_rules({clientid, Clientid}) of
|
case emqx_authz_mnesia:get_rules({clientid, ClientID}) of
|
||||||
not_found -> {404, #{code => <<"NOT_FOUND">>, message => <<"Not Found">>}};
|
not_found -> {404, #{code => <<"NOT_FOUND">>, message => <<"Not Found">>}};
|
||||||
{ok, Rules} ->
|
{ok, Rules} ->
|
||||||
{200, #{clientid => Clientid,
|
{200, #{clientid => ClientID,
|
||||||
rules => [ #{topic => Topic,
|
rules => [ #{topic => Topic,
|
||||||
action => Action,
|
action => Action,
|
||||||
permission => Permission
|
permission => Permission
|
||||||
} || {Permission, Action, Topic} <- Rules]}
|
} || {Permission, Action, Topic} <- Rules]}
|
||||||
}
|
}
|
||||||
end;
|
end;
|
||||||
client(put, #{bindings := #{clientid := Clientid},
|
client(put, #{bindings := #{clientid := ClientID},
|
||||||
body := #{<<"clientid">> := Clientid, <<"rules">> := Rules}}) ->
|
body := #{<<"clientid">> := ClientID, <<"rules">> := Rules}}) ->
|
||||||
emqx_authz_mnesia:store_rules({clientid, Clientid}, format_rules(Rules)),
|
emqx_authz_mnesia:store_rules({clientid, ClientID}, format_rules(Rules)),
|
||||||
{204};
|
{204};
|
||||||
client(delete, #{bindings := #{clientid := Clientid}}) ->
|
client(delete, #{bindings := #{clientid := ClientID}}) ->
|
||||||
emqx_authz_mnesia:delete_rules({clientid, Clientid}),
|
case emqx_authz_mnesia:get_rules({clientid, ClientID}) of
|
||||||
{204}.
|
not_found ->
|
||||||
|
{404, #{code => <<"NOT_FOUND">>, message => <<"ClientID Not Found">>}};
|
||||||
|
{ok, _Rules} ->
|
||||||
|
emqx_authz_mnesia:delete_rules({clientid, ClientID}),
|
||||||
|
{204}
|
||||||
|
end.
|
||||||
|
|
||||||
all(get, _) ->
|
all(get, _) ->
|
||||||
case emqx_authz_mnesia:get_rules(all) of
|
case emqx_authz_mnesia:get_rules(all) of
|
||||||
|
@ -453,8 +467,8 @@ format_result([{username, Username}, {rules, Rules}]) ->
|
||||||
permission => Permission
|
permission => Permission
|
||||||
} || {Permission, Action, Topic} <- Rules]
|
} || {Permission, Action, Topic} <- Rules]
|
||||||
};
|
};
|
||||||
format_result([{clientid, Clientid}, {rules, Rules}]) ->
|
format_result([{clientid, ClientID}, {rules, Rules}]) ->
|
||||||
#{clientid => Clientid,
|
#{clientid => ClientID,
|
||||||
rules => [ #{topic => Topic,
|
rules => [ #{topic => Topic,
|
||||||
action => Action,
|
action => Action,
|
||||||
permission => Permission
|
permission => Permission
|
||||||
|
|
Loading…
Reference in New Issue