chore(emqx_authz): change api path

This commit is contained in:
Rory Z 2021-08-31 10:29:28 +08:00 committed by Rory Z
parent 6b313a60d4
commit c0eaa30064
2 changed files with 17 additions and 18 deletions

View File

@ -137,7 +137,6 @@ sources_api() ->
} }
}, },
put => #{ put => #{
description => "Update all sources", description => "Update all sources",
requestBody => #{ requestBody => #{
content => #{ content => #{
@ -177,7 +176,7 @@ sources_api() ->
} }
} }
}, },
{"/authorization", Metadata, sources}. {"/authorization/sources", Metadata, sources}.
source_api() -> source_api() ->
Metadata = #{ Metadata = #{
@ -324,7 +323,7 @@ source_api() ->
} }
} }
}, },
{"/authorization/:type", Metadata, source}. {"/authorization/sources/:type", Metadata, source}.
move_source_api() -> move_source_api() ->
Metadata = #{ Metadata = #{
@ -414,7 +413,7 @@ move_source_api() ->
} }
} }
}, },
{"/authorization/:type/move", Metadata, move_source}. {"/authorization/sources/:type/move", Metadata, move_source}.
sources(get, #{query_string := Query}) -> sources(get, #{query_string := Query}) ->
Sources = lists:foldl(fun (#{type := _Type, enable := true, config := #{server := Server} = Config, annotations := #{id := Id}} = Source, AccIn) -> Sources = lists:foldl(fun (#{type := _Type, enable := true, config := #{server := Server} = Config, annotations := #{id := Id}} = Source, AccIn) ->

View File

@ -149,25 +149,25 @@ set_special_configs(_App) ->
%%------------------------------------------------------------------------------ %%------------------------------------------------------------------------------
t_api(_) -> t_api(_) ->
{ok, 200, Result1} = request(get, uri(["authorization"]), []), {ok, 200, Result1} = request(get, uri(["authorization", "sources"]), []),
?assertEqual([], get_sources(Result1)), ?assertEqual([], get_sources(Result1)),
lists:foreach(fun(_) -> lists:foreach(fun(_) ->
{ok, 204, _} = request(post, uri(["authorization"]), ?SOURCE1) {ok, 204, _} = request(post, uri(["authorization", "sources"]), ?SOURCE1)
end, lists:seq(1, 20)), end, lists:seq(1, 20)),
{ok, 200, Result2} = request(get, uri(["authorization"]), []), {ok, 200, Result2} = request(get, uri(["authorization", "sources"]), []),
?assertEqual(20, length(get_sources(Result2))), ?assertEqual(20, length(get_sources(Result2))),
lists:foreach(fun(Page) -> lists:foreach(fun(Page) ->
Query = "?page=" ++ integer_to_list(Page) ++ "&&limit=10", Query = "?page=" ++ integer_to_list(Page) ++ "&&limit=10",
Url = uri(["authorization" ++ Query]), Url = uri(["authorization/sources" ++ Query]),
{ok, 200, Result} = request(get, Url, []), {ok, 200, Result} = request(get, Url, []),
?assertEqual(10, length(get_sources(Result))) ?assertEqual(10, length(get_sources(Result)))
end, lists:seq(1, 2)), end, lists:seq(1, 2)),
{ok, 204, _} = request(put, uri(["authorization"]), [?SOURCE1, ?SOURCE2, ?SOURCE3, ?SOURCE4]), {ok, 204, _} = request(put, uri(["authorization", "sources"]), [?SOURCE1, ?SOURCE2, ?SOURCE3, ?SOURCE4]),
{ok, 200, Result3} = request(get, uri(["authorization"]), []), {ok, 200, Result3} = request(get, uri(["authorization", "sources"]), []),
Sources = get_sources(Result3), Sources = get_sources(Result3),
?assertMatch([ #{<<"type">> := <<"http">>} ?assertMatch([ #{<<"type">> := <<"http">>}
, #{<<"type">> := <<"mongo">>} , #{<<"type">> := <<"mongo">>}
@ -175,15 +175,15 @@ t_api(_) ->
, #{<<"type">> := <<"pgsql">>} , #{<<"type">> := <<"pgsql">>}
], Sources), ], Sources),
{ok, 204, _} = request(put, uri(["authorization", "http"]), ?SOURCE1#{<<"enable">> := false}), {ok, 204, _} = request(put, uri(["authorization", "sources", "http"]), ?SOURCE1#{<<"enable">> := false}),
{ok, 200, Result4} = request(get, uri(["authorization", "http"]), []), {ok, 200, Result4} = request(get, uri(["authorization", "sources", "http"]), []),
?assertMatch(#{<<"type">> := <<"http">>, <<"enable">> := false}, jsx:decode(Result4)), ?assertMatch(#{<<"type">> := <<"http">>, <<"enable">> := false}, jsx:decode(Result4)),
lists:foreach(fun(#{<<"type">> := Type}) -> lists:foreach(fun(#{<<"type">> := Type}) ->
{ok, 204, _} = request(delete, uri(["authorization", binary_to_list(Type)]), []) {ok, 204, _} = request(delete, uri(["authorization", "sources", binary_to_list(Type)]), [])
end, Sources), end, Sources),
{ok, 200, Result5} = request(get, uri(["authorization"]), []), {ok, 200, Result5} = request(get, uri(["authorization", "sources"]), []),
?assertEqual([], get_sources(Result5)), ?assertEqual([], get_sources(Result5)),
ok. ok.
@ -196,7 +196,7 @@ t_move_source(_) ->
, #{type := redis} , #{type := redis}
], emqx_authz:lookup()), ], emqx_authz:lookup()),
{ok, 204, _} = request(post, uri(["authorization", "pgsql", "move"]), {ok, 204, _} = request(post, uri(["authorization", "sources", "pgsql", "move"]),
#{<<"position">> => <<"top">>}), #{<<"position">> => <<"top">>}),
?assertMatch([ #{type := pgsql} ?assertMatch([ #{type := pgsql}
, #{type := http} , #{type := http}
@ -205,7 +205,7 @@ t_move_source(_) ->
, #{type := redis} , #{type := redis}
], emqx_authz:lookup()), ], emqx_authz:lookup()),
{ok, 204, _} = request(post, uri(["authorization", "http", "move"]), {ok, 204, _} = request(post, uri(["authorization", "sources", "http", "move"]),
#{<<"position">> => <<"bottom">>}), #{<<"position">> => <<"bottom">>}),
?assertMatch([ #{type := pgsql} ?assertMatch([ #{type := pgsql}
, #{type := mongo} , #{type := mongo}
@ -214,7 +214,7 @@ t_move_source(_) ->
, #{type := http} , #{type := http}
], emqx_authz:lookup()), ], emqx_authz:lookup()),
{ok, 204, _} = request(post, uri(["authorization", "mysql", "move"]), {ok, 204, _} = request(post, uri(["authorization", "sources", "mysql", "move"]),
#{<<"position">> => #{<<"before">> => <<"pgsql">>}}), #{<<"position">> => #{<<"before">> => <<"pgsql">>}}),
?assertMatch([ #{type := mysql} ?assertMatch([ #{type := mysql}
, #{type := pgsql} , #{type := pgsql}
@ -223,7 +223,7 @@ t_move_source(_) ->
, #{type := http} , #{type := http}
], emqx_authz:lookup()), ], emqx_authz:lookup()),
{ok, 204, _} = request(post, uri(["authorization", "mongo", "move"]), {ok, 204, _} = request(post, uri(["authorization", "sources", "mongo", "move"]),
#{<<"position">> => #{<<"after">> => <<"http">>}}), #{<<"position">> => #{<<"after">> => <<"http">>}}),
?assertMatch([ #{type := mysql} ?assertMatch([ #{type := mysql}
, #{type := pgsql} , #{type := pgsql}