fix(authz_api): rm authz sources full update
This commit is contained in:
parent
0b7f1ab69c
commit
1ed8e783f4
|
@ -80,16 +80,6 @@ schema("/authorization/sources") ->
|
||||||
<<"Bad Request">>)
|
<<"Bad Request">>)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
, put =>
|
|
||||||
#{ description => <<"Update all sources">>
|
|
||||||
, 'requestBody' => mk( array(hoconsc:union(authz_sources_type_refs()))
|
|
||||||
, #{desc => <<"Sources">>})
|
|
||||||
, responses =>
|
|
||||||
#{ 204 => <<"Authorization source updated successfully">>
|
|
||||||
, 400 => emqx_dashboard_swagger:error_codes([?BAD_REQUEST],
|
|
||||||
<<"Bad Request">>)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
schema("/authorization/sources/:type") ->
|
schema("/authorization/sources/:type") ->
|
||||||
#{ 'operationId' => source
|
#{ 'operationId' => source
|
||||||
|
@ -183,17 +173,7 @@ sources(post, #{body := #{<<"type">> := <<"file">>, <<"rules">> := Rules}}) ->
|
||||||
update_config(?CMD_PREPEND, [#{<<"type">> => <<"file">>,
|
update_config(?CMD_PREPEND, [#{<<"type">> => <<"file">>,
|
||||||
<<"enable">> => true, <<"path">> => Filename}]);
|
<<"enable">> => true, <<"path">> => Filename}]);
|
||||||
sources(post, #{body := Body}) when is_map(Body) ->
|
sources(post, #{body := Body}) when is_map(Body) ->
|
||||||
update_config(?CMD_PREPEND, [maybe_write_certs(Body)]);
|
update_config(?CMD_PREPEND, [maybe_write_certs(Body)]).
|
||||||
sources(put, #{body := Body}) when is_list(Body) ->
|
|
||||||
NBody = [ begin
|
|
||||||
case Source of
|
|
||||||
#{<<"type">> := <<"file">>, <<"rules">> := Rules, <<"enable">> := Enable} ->
|
|
||||||
{ok, Filename} = write_file(acl_conf_file(), Rules),
|
|
||||||
#{<<"type">> => <<"file">>, <<"enable">> => Enable, <<"path">> => Filename};
|
|
||||||
_ -> maybe_write_certs(Source)
|
|
||||||
end
|
|
||||||
end || Source <- Body],
|
|
||||||
update_config(?CMD_REPLACE, NBody).
|
|
||||||
|
|
||||||
source(Method, #{bindings := #{type := Type} = Bindings } = Req)
|
source(Method, #{bindings := #{type := Type} = Bindings } = Req)
|
||||||
when is_atom(Type) ->
|
when is_atom(Type) ->
|
||||||
|
|
|
@ -98,6 +98,7 @@ groups() ->
|
||||||
[].
|
[].
|
||||||
|
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
|
ok = stop_apps([emqx_resource, emqx_connector]),
|
||||||
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
|
||||||
meck:expect(emqx_resource, create_local, fun(_, _, _, _) -> {ok, meck_data} end),
|
meck:expect(emqx_resource, create_local, fun(_, _, _, _) -> {ok, meck_data} end),
|
||||||
meck:expect(emqx_resource, create_dry_run_local,
|
meck:expect(emqx_resource, create_dry_run_local,
|
||||||
|
@ -111,6 +112,7 @@ init_per_suite(Config) ->
|
||||||
ok = emqx_common_test_helpers:start_apps(
|
ok = emqx_common_test_helpers:start_apps(
|
||||||
[emqx_conf, emqx_authz, emqx_dashboard],
|
[emqx_conf, emqx_authz, emqx_dashboard],
|
||||||
fun set_special_configs/1),
|
fun set_special_configs/1),
|
||||||
|
ok = start_apps([emqx_resource, emqx_connector]),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_suite(_Config) ->
|
end_per_suite(_Config) ->
|
||||||
|
@ -172,8 +174,8 @@ t_api(_) ->
|
||||||
{ok, 200, Result1} = request(get, uri(["authorization", "sources"]), []),
|
{ok, 200, Result1} = request(get, uri(["authorization", "sources"]), []),
|
||||||
?assertEqual([], get_sources(Result1)),
|
?assertEqual([], get_sources(Result1)),
|
||||||
|
|
||||||
{ok, 204, _} = request(put, uri(["authorization", "sources"]),
|
[ begin {ok, 204, _} = request(post, uri(["authorization", "sources"]), Source) end
|
||||||
[?SOURCE2, ?SOURCE3, ?SOURCE4, ?SOURCE5, ?SOURCE6]),
|
|| Source <- lists:reverse([?SOURCE2, ?SOURCE3, ?SOURCE4, ?SOURCE5, ?SOURCE6])],
|
||||||
{ok, 204, _} = request(post, uri(["authorization", "sources"]), ?SOURCE1),
|
{ok, 204, _} = request(post, uri(["authorization", "sources"]), ?SOURCE1),
|
||||||
|
|
||||||
Snd = fun ({_, Val}) -> Val end,
|
Snd = fun ({_, Val}) -> Val end,
|
||||||
|
@ -392,5 +394,8 @@ auth_header_() ->
|
||||||
|
|
||||||
data_dir() -> emqx:data_dir().
|
data_dir() -> emqx:data_dir().
|
||||||
|
|
||||||
|
start_apps(Apps) ->
|
||||||
|
lists:foreach(fun application:ensure_all_started/1, Apps).
|
||||||
|
|
||||||
stop_apps(Apps) ->
|
stop_apps(Apps) ->
|
||||||
lists:foreach(fun application:stop/1, Apps).
|
lists:foreach(fun application:stop/1, Apps).
|
||||||
|
|
Loading…
Reference in New Issue