Skip to content

Commit

Permalink
Merge pull request #9299 from sstrigler/authz-api-fixes
Browse files Browse the repository at this point in the history
Authz API fixes
  • Loading branch information
zmstone committed Nov 8, 2022
2 parents 30d9143 + aa21590 commit 6515032
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion apps/emqx_authz/src/emqx_authz.app.src
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%% -*- mode: erlang -*-
{application, emqx_authz, [
{description, "An OTP application"},
{vsn, "0.1.6"},
{vsn, "0.1.7"},
{registered, []},
{mod, {emqx_authz_app, []}},
{applications, [
Expand Down
13 changes: 7 additions & 6 deletions apps/emqx_authz/src/emqx_authz_api_sources.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
-export([
api_spec/0,
paths/0,
schema/1
schema/1,
fields/1
]).

-export([
Expand All @@ -63,6 +64,9 @@ paths() ->
"/authorization/sources/:type/move"
].

fields(sources) ->
[{sources, mk(array(hoconsc:union(authz_sources_type_refs())), #{desc => ?DESC(sources)})}].

%%--------------------------------------------------------------------
%% Schema for each URI
%%--------------------------------------------------------------------
Expand All @@ -75,10 +79,7 @@ schema("/authorization/sources") ->
tags => ?TAGS,
responses =>
#{
200 => mk(
array(hoconsc:union(authz_sources_type_refs())),
#{desc => ?DESC(sources)}
)
200 => ref(?MODULE, sources)
}
},
post =>
Expand Down Expand Up @@ -241,7 +242,7 @@ source(Method, #{bindings := #{type := Type} = Bindings} = Req) when
source(get, #{bindings := #{type := Type}}) ->
case get_raw_source(Type) of
[] ->
{404, #{message => <<"Not found ", Type/binary>>}};
{404, #{code => <<"NOT_FOUND">>, message => <<"Not found: ", Type/binary>>}};
[#{<<"type">> := <<"file">>, <<"enable">> := Enable, <<"path">> := Path}] ->
case file:read_file(Path) of
{ok, Rules} ->
Expand Down
6 changes: 6 additions & 0 deletions apps/emqx_authz/test/emqx_authz_api_sources_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,12 @@ t_api(_) ->
{ok, 200, Result1} = request(get, uri(["authorization", "sources"]), []),
?assertEqual([], get_sources(Result1)),

{ok, 404, ErrResult} = request(get, uri(["authorization", "sources", "http"]), []),
?assertMatch(
#{<<"code">> := <<"NOT_FOUND">>, <<"message">> := <<"Not found: http">>},
jsx:decode(ErrResult)
),

[
begin
{ok, 204, _} = request(post, uri(["authorization", "sources"]), Source)
Expand Down
6 changes: 5 additions & 1 deletion changes/v5.0.10-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@
- Fix incorrect topic authorize checking of delayed messages [#9290](https://github.com/emqx/emqx/pull/9290).
Now will determine the actual topic of the delayed messages, e.g. `$delayed/1/t/foo` will be treated as `t/foo` in authorize checks.

- Fix query string parameter 'node' to `/configs` resource being ignored, return 404 if node does not exist [#9310](https://github.com/emqx/emqx/pull/9310/).
- Add property `code` to error response for `/authentication/sources/:type` [9299](https://github.com/emqx/emqx/pull/9299).

- Align documentation for `/authentication/sources` with what we actually send [9299](https://github.com/emqx/emqx/pull/9299).

- Fix query string parameter 'node' to `/configs` resource being ignored, return 404 if node does not exist [#9310](https://github.com/emqx/emqx/pull/9310/).
7 changes: 6 additions & 1 deletion changes/v5.0.10-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@
- 修复延迟消息的主题授权判断不正确的问题 [#9290](https://github.com/emqx/emqx/pull/9290)
现在将会对延迟消息中的真实主题进行授权判断,比如,`$delayed/1/t/foo` 会被当作 `t/foo` 进行判断。

- 修复 `/configs` API 的 'node' 参数的问题,如果节点不存在,则返回 HTTP 状态码 404

- 为 API `/authentication/sources/:type` 的返回值增加 `code` 字段 [9299](https://github.com/emqx/emqx/pull/9299)

- 对齐文档,`/authentication/sources` 接口的文档仅列出已经支持的资源 [9299](https://github.com/emqx/emqx/pull/9299)

- 修复 `/configs` API 的 'node' 参数的问题,如果节点不存在,则返回 HTTP 状态码 404 [#9310](https://github.com/emqx/emqx/pull/9310/)

0 comments on commit 6515032

Please sign in to comment.