refactor: move api `top` -> `front`, `bottom` -> `rear`
This commit is contained in:
parent
2a866e7c91
commit
02ed2148d7
|
@ -29,8 +29,8 @@
|
||||||
-define(EMQX_AUTHENTICATION_SCHEMA_MODULE_PT_KEY, emqx_authentication_schema_module).
|
-define(EMQX_AUTHENTICATION_SCHEMA_MODULE_PT_KEY, emqx_authentication_schema_module).
|
||||||
|
|
||||||
%% authentication move cmd
|
%% authentication move cmd
|
||||||
-define(CMD_MOVE_TOP, top).
|
-define(CMD_MOVE_FRONT, front).
|
||||||
-define(CMD_MOVE_BOTTOM, bottom).
|
-define(CMD_MOVE_REAR, rear).
|
||||||
-define(CMD_MOVE_BEFORE(Before), {before, Before}).
|
-define(CMD_MOVE_BEFORE(Before), {before, Before}).
|
||||||
-define(CMD_MOVE_AFTER(After), {'after', After}).
|
-define(CMD_MOVE_AFTER(After), {'after', After}).
|
||||||
|
|
||||||
|
|
|
@ -100,7 +100,7 @@
|
||||||
|
|
||||||
-type chain_name() :: atom().
|
-type chain_name() :: atom().
|
||||||
-type authenticator_id() :: binary().
|
-type authenticator_id() :: binary().
|
||||||
-type position() :: top | bottom | {before, authenticator_id()} | {'after', authenticator_id()}.
|
-type position() :: front | rear | {before, authenticator_id()} | {'after', authenticator_id()}.
|
||||||
-type authn_type() :: atom() | {atom(), atom()}.
|
-type authn_type() :: atom() | {atom(), atom()}.
|
||||||
-type provider() :: module().
|
-type provider() :: module().
|
||||||
|
|
||||||
|
@ -695,9 +695,9 @@ do_move_authenticator(ID, Authenticators, Position) ->
|
||||||
{error, {not_found, {authenticator, ID}}};
|
{error, {not_found, {authenticator, ID}}};
|
||||||
{value, Authenticator, NAuthenticators} ->
|
{value, Authenticator, NAuthenticators} ->
|
||||||
case Position of
|
case Position of
|
||||||
?CMD_MOVE_TOP ->
|
?CMD_MOVE_FRONT ->
|
||||||
{ok, [Authenticator | NAuthenticators]};
|
{ok, [Authenticator | NAuthenticators]};
|
||||||
?CMD_MOVE_BOTTOM ->
|
?CMD_MOVE_REAR ->
|
||||||
{ok, NAuthenticators ++ [Authenticator]};
|
{ok, NAuthenticators ++ [Authenticator]};
|
||||||
?CMD_MOVE_BEFORE(RelatedID) ->
|
?CMD_MOVE_BEFORE(RelatedID) ->
|
||||||
insert(Authenticator, NAuthenticators, ?CMD_MOVE_BEFORE(RelatedID), []);
|
insert(Authenticator, NAuthenticators, ?CMD_MOVE_BEFORE(RelatedID), []);
|
||||||
|
|
|
@ -89,9 +89,9 @@ do_pre_config_update({move_authenticator, _ChainName, AuthenticatorID, Position}
|
||||||
{error, Reason} -> {error, Reason};
|
{error, Reason} -> {error, Reason};
|
||||||
{ok, BeforeFound, [Found | AfterFound]} ->
|
{ok, BeforeFound, [Found | AfterFound]} ->
|
||||||
case Position of
|
case Position of
|
||||||
?CMD_MOVE_TOP ->
|
?CMD_MOVE_FRONT ->
|
||||||
{ok, [Found | BeforeFound] ++ AfterFound};
|
{ok, [Found | BeforeFound] ++ AfterFound};
|
||||||
?CMD_MOVE_BOTTOM ->
|
?CMD_MOVE_REAR ->
|
||||||
{ok, BeforeFound ++ AfterFound ++ [Found]};
|
{ok, BeforeFound ++ AfterFound ++ [Found]};
|
||||||
?CMD_MOVE_BEFORE(BeforeRelatedID) ->
|
?CMD_MOVE_BEFORE(BeforeRelatedID) ->
|
||||||
case split_by_id(BeforeRelatedID, BeforeFound ++ AfterFound) of
|
case split_by_id(BeforeRelatedID, BeforeFound ++ AfterFound) of
|
||||||
|
|
|
@ -185,14 +185,17 @@ t_authenticator(Config) when is_list(Config) ->
|
||||||
% Move authenticator
|
% Move authenticator
|
||||||
?assertMatch({ok, [#{id := ID1}, #{id := ID2}]}, ?AUTHN:list_authenticators(ChainName)),
|
?assertMatch({ok, [#{id := ID1}, #{id := ID2}]}, ?AUTHN:list_authenticators(ChainName)),
|
||||||
|
|
||||||
?assertEqual(ok, ?AUTHN:move_authenticator(ChainName, ID2, top)),
|
?assertEqual(ok, ?AUTHN:move_authenticator(ChainName, ID2, ?CMD_MOVE_FRONT)),
|
||||||
?assertMatch({ok, [#{id := ID2}, #{id := ID1}]}, ?AUTHN:list_authenticators(ChainName)),
|
?assertMatch({ok, [#{id := ID2}, #{id := ID1}]}, ?AUTHN:list_authenticators(ChainName)),
|
||||||
|
|
||||||
?assertEqual(ok, ?AUTHN:move_authenticator(ChainName, ID2, bottom)),
|
?assertEqual(ok, ?AUTHN:move_authenticator(ChainName, ID2, ?CMD_MOVE_REAR)),
|
||||||
?assertMatch({ok, [#{id := ID1}, #{id := ID2}]}, ?AUTHN:list_authenticators(ChainName)),
|
?assertMatch({ok, [#{id := ID1}, #{id := ID2}]}, ?AUTHN:list_authenticators(ChainName)),
|
||||||
|
|
||||||
?assertEqual(ok, ?AUTHN:move_authenticator(ChainName, ID2, {before, ID1})),
|
?assertEqual(ok, ?AUTHN:move_authenticator(ChainName, ID2, ?CMD_MOVE_BEFORE(ID1))),
|
||||||
?assertMatch({ok, [#{id := ID2}, #{id := ID1}]}, ?AUTHN:list_authenticators(ChainName));
|
?assertMatch({ok, [#{id := ID2}, #{id := ID1}]}, ?AUTHN:list_authenticators(ChainName)),
|
||||||
|
|
||||||
|
?assertEqual(ok, ?AUTHN:move_authenticator(ChainName, ID2, ?CMD_MOVE_AFTER(ID1))),
|
||||||
|
?assertMatch({ok, [#{id := ID1}, #{id := ID2}]}, ?AUTHN:list_authenticators(ChainName));
|
||||||
|
|
||||||
t_authenticator({'end', Config}) ->
|
t_authenticator({'end', Config}) ->
|
||||||
?AUTHN:delete_chain(test),
|
?AUTHN:delete_chain(test),
|
||||||
|
@ -291,7 +294,7 @@ t_update_config(Config) when is_list(Config) ->
|
||||||
|
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
{ok, _},
|
{ok, _},
|
||||||
update_config([?CONF_ROOT], {move_authenticator, Global, ID2, top})),
|
update_config([?CONF_ROOT], {move_authenticator, Global, ID2, ?CMD_MOVE_FRONT})),
|
||||||
|
|
||||||
?assertMatch({ok, [#{id := ID2}, #{id := ID1}]}, ?AUTHN:list_authenticators(Global)),
|
?assertMatch({ok, [#{id := ID2}, #{id := ID1}]}, ?AUTHN:list_authenticators(Global)),
|
||||||
|
|
||||||
|
@ -344,7 +347,7 @@ t_update_config(Config) when is_list(Config) ->
|
||||||
|
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
{ok, _},
|
{ok, _},
|
||||||
update_config(ConfKeyPath, {move_authenticator, ListenerID, ID2, top})),
|
update_config(ConfKeyPath, {move_authenticator, ListenerID, ID2, ?CMD_MOVE_FRONT})),
|
||||||
|
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
{ok, [#{id := ID2}, #{id := ID1}]},
|
{ok, [#{id := ID2}, #{id := ID1}]},
|
||||||
|
|
|
@ -1059,10 +1059,10 @@ serialize_error(Reason) ->
|
||||||
{400, #{code => <<"BAD_REQUEST">>,
|
{400, #{code => <<"BAD_REQUEST">>,
|
||||||
message => binfmt("~p", [Reason])}}.
|
message => binfmt("~p", [Reason])}}.
|
||||||
|
|
||||||
parse_position(<<"top">>) ->
|
parse_position(<<"front">>) ->
|
||||||
{ok, ?CMD_MOVE_TOP};
|
{ok, ?CMD_MOVE_FRONT};
|
||||||
parse_position(<<"bottom">>) ->
|
parse_position(<<"rear">>) ->
|
||||||
{ok, ?CMD_MOVE_BOTTOM};
|
{ok, ?CMD_MOVE_REAR};
|
||||||
parse_position(<<"before:">>) ->
|
parse_position(<<"before:">>) ->
|
||||||
{error, {invalid_parameter, position}};
|
{error, {invalid_parameter, position}};
|
||||||
parse_position(<<"after:">>) ->
|
parse_position(<<"after:">>) ->
|
||||||
|
@ -1205,16 +1205,16 @@ request_user_update_examples() ->
|
||||||
|
|
||||||
request_move_examples() ->
|
request_move_examples() ->
|
||||||
#{
|
#{
|
||||||
move_to_top => #{
|
move_to_front => #{
|
||||||
summary => <<"Move authenticator to the beginning of the chain">>,
|
summary => <<"Move authenticator to the beginning of the chain">>,
|
||||||
value => #{
|
value => #{
|
||||||
position => <<"top">>
|
position => <<"front">>
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
move_to_bottom => #{
|
move_to_rear => #{
|
||||||
summary => <<"Move authenticator to the end of the chain">>,
|
summary => <<"Move authenticator to the end of the chain">>,
|
||||||
value => #{
|
value => #{
|
||||||
position => <<"bottom">>
|
position => <<"rear">>
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'move_before_password_based:built_in_database' => #{
|
'move_before_password_based:built_in_database' => #{
|
||||||
|
|
|
@ -376,11 +376,11 @@ test_authenticator_move(PathPrefix) ->
|
||||||
|
|
||||||
%% Valid moves
|
%% Valid moves
|
||||||
|
|
||||||
%% test top
|
%% test front
|
||||||
{ok, 204, _} = request(
|
{ok, 204, _} = request(
|
||||||
post,
|
post,
|
||||||
uri(PathPrefix ++ [?CONF_NS, "jwt", "move"]),
|
uri(PathPrefix ++ [?CONF_NS, "jwt", "move"]),
|
||||||
#{position => <<"top">>}),
|
#{position => <<"front">>}),
|
||||||
|
|
||||||
?assertAuthenticatorsMatch(
|
?assertAuthenticatorsMatch(
|
||||||
[
|
[
|
||||||
|
@ -390,11 +390,11 @@ test_authenticator_move(PathPrefix) ->
|
||||||
],
|
],
|
||||||
PathPrefix ++ [?CONF_NS]),
|
PathPrefix ++ [?CONF_NS]),
|
||||||
|
|
||||||
%% test bottom
|
%% test rear
|
||||||
{ok, 204, _} = request(
|
{ok, 204, _} = request(
|
||||||
post,
|
post,
|
||||||
uri(PathPrefix ++ [?CONF_NS, "jwt", "move"]),
|
uri(PathPrefix ++ [?CONF_NS, "jwt", "move"]),
|
||||||
#{position => <<"bottom">>}),
|
#{position => <<"rear">>}),
|
||||||
|
|
||||||
?assertAuthenticatorsMatch(
|
?assertAuthenticatorsMatch(
|
||||||
[
|
[
|
||||||
|
|
|
@ -34,8 +34,8 @@
|
||||||
-define(CMD_APPEND, append).
|
-define(CMD_APPEND, append).
|
||||||
-define(CMD_MOVE, move).
|
-define(CMD_MOVE, move).
|
||||||
|
|
||||||
-define(CMD_MOVE_TOP, top).
|
-define(CMD_MOVE_FRONT, front).
|
||||||
-define(CMD_MOVE_BOTTOM, bottom).
|
-define(CMD_MOVE_REAR, rear).
|
||||||
-define(CMD_MOVE_BEFORE(Before), {before, Before}).
|
-define(CMD_MOVE_BEFORE(Before), {before, Before}).
|
||||||
-define(CMD_MOVE_AFTER(After), {'after', After}).
|
-define(CMD_MOVE_AFTER(After), {'after', After}).
|
||||||
|
|
||||||
|
|
|
@ -127,10 +127,10 @@ update({?CMD_DELETE, Type}, Sources) ->
|
||||||
update(Cmd, Sources) ->
|
update(Cmd, Sources) ->
|
||||||
emqx_authz_utils:update_config(?CONF_KEY_PATH, {Cmd, Sources}).
|
emqx_authz_utils:update_config(?CONF_KEY_PATH, {Cmd, Sources}).
|
||||||
|
|
||||||
do_update({?CMD_MOVE, Type, ?CMD_MOVE_TOP}, Conf) when is_list(Conf) ->
|
do_update({?CMD_MOVE, Type, ?CMD_MOVE_FRONT}, Conf) when is_list(Conf) ->
|
||||||
{Source, Front, Rear} = take(Type, Conf),
|
{Source, Front, Rear} = take(Type, Conf),
|
||||||
[Source | Front] ++ Rear;
|
[Source | Front] ++ Rear;
|
||||||
do_update({?CMD_MOVE, Type, ?CMD_MOVE_BOTTOM}, Conf) when is_list(Conf) ->
|
do_update({?CMD_MOVE, Type, ?CMD_MOVE_REAR}, Conf) when is_list(Conf) ->
|
||||||
{Source, Front, Rear} = take(Type, Conf),
|
{Source, Front, Rear} = take(Type, Conf),
|
||||||
Front ++ Rear ++ [Source];
|
Front ++ Rear ++ [Source];
|
||||||
do_update({?CMD_MOVE, Type, ?CMD_MOVE_BEFORE(Before)}, Conf) when is_list(Conf) ->
|
do_update({?CMD_MOVE, Type, ?CMD_MOVE_BEFORE(Before)}, Conf) when is_list(Conf) ->
|
||||||
|
|
|
@ -477,10 +477,10 @@ parameters_field() ->
|
||||||
}
|
}
|
||||||
].
|
].
|
||||||
|
|
||||||
parse_position(<<"top">>) ->
|
parse_position(<<"front">>) ->
|
||||||
{ok, ?CMD_MOVE_TOP};
|
{ok, ?CMD_MOVE_FRONT};
|
||||||
parse_position(<<"bottom">>) ->
|
parse_position(<<"rear">>) ->
|
||||||
{ok, ?CMD_MOVE_BOTTOM};
|
{ok, ?CMD_MOVE_REAR};
|
||||||
parse_position(<<"before:", Before/binary>>) ->
|
parse_position(<<"before:", Before/binary>>) ->
|
||||||
{ok, ?CMD_MOVE_BEFORE(Before)};
|
{ok, ?CMD_MOVE_BEFORE(Before)};
|
||||||
parse_position(<<"after:", After/binary>>) ->
|
parse_position(<<"after:", After/binary>>) ->
|
||||||
|
@ -493,15 +493,18 @@ parse_position(_) ->
|
||||||
{error, {invalid_parameter, position}}.
|
{error, {invalid_parameter, position}}.
|
||||||
|
|
||||||
position_example() ->
|
position_example() ->
|
||||||
#{ top =>
|
#{ front =>
|
||||||
#{ summary => <<"top example">>
|
#{ summary => <<"front example">>
|
||||||
, value => #{<<"position">> => <<"top">>}}
|
, value => #{<<"position">> => <<"front">>}}
|
||||||
, bottom =>
|
, rear =>
|
||||||
#{ summary => <<"bottom example">>
|
#{ summary => <<"rear example">>
|
||||||
, value => #{<<"position">> => <<"bottom">>}}
|
, value => #{<<"position">> => <<"rear">>}}
|
||||||
, relative =>
|
, relative_before =>
|
||||||
#{ summary => <<"relative example">>
|
#{ summary => <<"relative example">>
|
||||||
, value => #{<<"position">> => <<"before:file">>}}
|
, value => #{<<"position">> => <<"before:file">>}}
|
||||||
|
, relative_after =>
|
||||||
|
#{ summary => <<"relative example">>
|
||||||
|
, value => #{<<"position">> => <<"after:file">>}}
|
||||||
}.
|
}.
|
||||||
|
|
||||||
authz_sources_types(Type) ->
|
authz_sources_types(Type) ->
|
||||||
|
|
|
@ -186,7 +186,7 @@ t_move_source(_) ->
|
||||||
, #{type := file}
|
, #{type := file}
|
||||||
], emqx_authz:lookup()),
|
], emqx_authz:lookup()),
|
||||||
|
|
||||||
{ok, _} = emqx_authz:move(postgresql, top),
|
{ok, _} = emqx_authz:move(postgresql, ?CMD_MOVE_FRONT),
|
||||||
?assertMatch([ #{type := postgresql}
|
?assertMatch([ #{type := postgresql}
|
||||||
, #{type := http}
|
, #{type := http}
|
||||||
, #{type := mongodb}
|
, #{type := mongodb}
|
||||||
|
@ -195,7 +195,7 @@ t_move_source(_) ->
|
||||||
, #{type := file}
|
, #{type := file}
|
||||||
], emqx_authz:lookup()),
|
], emqx_authz:lookup()),
|
||||||
|
|
||||||
{ok, _} = emqx_authz:move(http, bottom),
|
{ok, _} = emqx_authz:move(http, ?CMD_MOVE_REAR),
|
||||||
?assertMatch([ #{type := postgresql}
|
?assertMatch([ #{type := postgresql}
|
||||||
, #{type := mongodb}
|
, #{type := mongodb}
|
||||||
, #{type := mysql}
|
, #{type := mysql}
|
||||||
|
@ -204,7 +204,7 @@ t_move_source(_) ->
|
||||||
, #{type := http}
|
, #{type := http}
|
||||||
], emqx_authz:lookup()),
|
], emqx_authz:lookup()),
|
||||||
|
|
||||||
{ok, _} = emqx_authz:move(mysql, {before, postgresql}),
|
{ok, _} = emqx_authz:move(mysql, ?CMD_MOVE_BEFORE(postgresql)),
|
||||||
?assertMatch([ #{type := mysql}
|
?assertMatch([ #{type := mysql}
|
||||||
, #{type := postgresql}
|
, #{type := postgresql}
|
||||||
, #{type := mongodb}
|
, #{type := mongodb}
|
||||||
|
@ -213,7 +213,7 @@ t_move_source(_) ->
|
||||||
, #{type := http}
|
, #{type := http}
|
||||||
], emqx_authz:lookup()),
|
], emqx_authz:lookup()),
|
||||||
|
|
||||||
{ok, _} = emqx_authz:move(mongodb, {'after', http}),
|
{ok, _} = emqx_authz:move(mongodb, ?CMD_MOVE_AFTER(http)),
|
||||||
?assertMatch([ #{type := mysql}
|
?assertMatch([ #{type := mysql}
|
||||||
, #{type := postgresql}
|
, #{type := postgresql}
|
||||||
, #{type := redis}
|
, #{type := redis}
|
||||||
|
|
|
@ -318,7 +318,7 @@ t_move_source(_) ->
|
||||||
], emqx_authz:lookup()),
|
], emqx_authz:lookup()),
|
||||||
|
|
||||||
{ok, 204, _} = request(post, uri(["authorization", "sources", "postgresql", "move"]),
|
{ok, 204, _} = request(post, uri(["authorization", "sources", "postgresql", "move"]),
|
||||||
#{<<"position">> => <<"top">>}),
|
#{<<"position">> => <<"front">>}),
|
||||||
?assertMatch([ #{type := postgresql}
|
?assertMatch([ #{type := postgresql}
|
||||||
, #{type := http}
|
, #{type := http}
|
||||||
, #{type := mongodb}
|
, #{type := mongodb}
|
||||||
|
@ -327,7 +327,7 @@ t_move_source(_) ->
|
||||||
], emqx_authz:lookup()),
|
], emqx_authz:lookup()),
|
||||||
|
|
||||||
{ok, 204, _} = request(post, uri(["authorization", "sources", "http", "move"]),
|
{ok, 204, _} = request(post, uri(["authorization", "sources", "http", "move"]),
|
||||||
#{<<"position">> => <<"bottom">>}),
|
#{<<"position">> => <<"rear">>}),
|
||||||
?assertMatch([ #{type := postgresql}
|
?assertMatch([ #{type := postgresql}
|
||||||
, #{type := mongodb}
|
, #{type := mongodb}
|
||||||
, #{type := mysql}
|
, #{type := mysql}
|
||||||
|
|
|
@ -45,3 +45,8 @@
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-endif.
|
-endif.
|
||||||
|
|
||||||
|
-define(CMD_MOVE_FRONT, {front, <<>>}).
|
||||||
|
-define(CMD_MOVE_REAR, {rear, <<>>}).
|
||||||
|
-define(CMD_MOVE_BEFORE(Before), {before, Before}).
|
||||||
|
-define(CMD_MOVE_AFTER(After), {'after', After}).
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
-behaviour(minirest_api).
|
-behaviour(minirest_api).
|
||||||
|
|
||||||
|
-include("emqx_exhook.hrl").
|
||||||
-include_lib("typerefl/include/types.hrl").
|
-include_lib("typerefl/include/types.hrl").
|
||||||
-include_lib("emqx/include/logger.hrl").
|
-include_lib("emqx/include/logger.hrl").
|
||||||
|
|
||||||
|
@ -104,8 +105,9 @@ schema("/exhooks/:name/hooks") ->
|
||||||
schema("/exhooks/:name/move") ->
|
schema("/exhooks/:name/move") ->
|
||||||
#{'operationId' => move,
|
#{'operationId' => move,
|
||||||
post => #{tags => ?TAGS,
|
post => #{tags => ?TAGS,
|
||||||
description => <<"Move the server.\n"
|
description =>
|
||||||
"NOTE: The position should be \"top|bottom|before:{name}\"\n">>,
|
<<"Move the server.\n",
|
||||||
|
"NOTE: The position should be \"front|rear|before:{name}|after:{name}\"\n">>,
|
||||||
parameters => params_server_name_in_path(),
|
parameters => params_server_name_in_path(),
|
||||||
'requestBody' => emqx_dashboard_swagger:schema_with_examples(
|
'requestBody' => emqx_dashboard_swagger:schema_with_examples(
|
||||||
ref(move_req),
|
ref(move_req),
|
||||||
|
@ -119,7 +121,7 @@ schema("/exhooks/:name/move") ->
|
||||||
|
|
||||||
fields(move_req) ->
|
fields(move_req) ->
|
||||||
[{position, mk(string(), #{ desc => <<"The target position to be moved.">>
|
[{position, mk(string(), #{ desc => <<"The target position to be moved.">>
|
||||||
, example => <<"top">>})}];
|
, example => <<"front">>})}];
|
||||||
|
|
||||||
fields(detail_server_info) ->
|
fields(detail_server_info) ->
|
||||||
[ {metrics, mk(ref(metrics), #{})}
|
[ {metrics, mk(ref(metrics), #{})}
|
||||||
|
@ -401,12 +403,12 @@ call_cluster(Fun) ->
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
position_example() ->
|
position_example() ->
|
||||||
#{ top =>
|
#{ front =>
|
||||||
#{ summary => <<"absolute position 'top'">>
|
#{ summary => <<"absolute position 'front'">>
|
||||||
, value => #{<<"position">> => <<"top">>}}
|
, value => #{<<"position">> => <<"front">>}}
|
||||||
, bottom =>
|
, rear =>
|
||||||
#{ summary => <<"absolute position 'bottom'">>
|
#{ summary => <<"absolute position 'rear'">>
|
||||||
, value => #{<<"position">> => <<"bottom">>}}
|
, value => #{<<"position">> => <<"rear">>}}
|
||||||
, related_before =>
|
, related_before =>
|
||||||
#{ summary => <<"relative position 'before'">>
|
#{ summary => <<"relative position 'before'">>
|
||||||
, value => #{<<"position">> => <<"before:default">>}}
|
, value => #{<<"position">> => <<"before:default">>}}
|
||||||
|
@ -415,14 +417,14 @@ position_example() ->
|
||||||
, value => #{<<"position">> => <<"after:default">>}}
|
, value => #{<<"position">> => <<"after:default">>}}
|
||||||
}.
|
}.
|
||||||
|
|
||||||
parse_position(<<"top">>) ->
|
parse_position(<<"front">>) ->
|
||||||
{ok, {top, <<>>}};
|
{ok, ?CMD_MOVE_FRONT};
|
||||||
parse_position(<<"bottom">>) ->
|
parse_position(<<"rear">>) ->
|
||||||
{ok, {bottom, <<>>}};
|
{ok, ?CMD_MOVE_REAR};
|
||||||
parse_position(<<"before:", Related/binary>>) ->
|
parse_position(<<"before:", Related/binary>>) ->
|
||||||
{ok, {before, Related}};
|
{ok, ?CMD_MOVE_BEFORE(Related)};
|
||||||
parse_position(<<"after:", Related/binary>>) ->
|
parse_position(<<"after:", Related/binary>>) ->
|
||||||
{ok, {'after', Related}};
|
{ok, ?CMD_MOVE_AFTER(Related)};
|
||||||
parse_position(<<"before:">>) ->
|
parse_position(<<"before:">>) ->
|
||||||
{error, invalid_position};
|
{error, invalid_position};
|
||||||
parse_position(<<"after:">>) ->
|
parse_position(<<"after:">>) ->
|
||||||
|
|
|
@ -74,8 +74,8 @@
|
||||||
-type server() :: server_options().
|
-type server() :: server_options().
|
||||||
-type server_options() :: map().
|
-type server_options() :: map().
|
||||||
|
|
||||||
-type move_direct() :: top
|
-type move_direct() :: front
|
||||||
| bottom
|
| rear
|
||||||
| before
|
| before
|
||||||
| 'after'.
|
| 'after'.
|
||||||
|
|
||||||
|
@ -475,10 +475,10 @@ move([Server | T], Name, Direct, ToName, HeadL) ->
|
||||||
move([], _Name, _Direct, _ToName, _HeadL) ->
|
move([], _Name, _Direct, _ToName, _HeadL) ->
|
||||||
not_found.
|
not_found.
|
||||||
|
|
||||||
move_to(top, _, Server, ServerL) ->
|
move_to(front, _, Server, ServerL) ->
|
||||||
[Server | ServerL];
|
[Server | ServerL];
|
||||||
|
|
||||||
move_to(bottom, _, Server, ServerL) ->
|
move_to(rear, _, Server, ServerL) ->
|
||||||
ServerL ++ [Server];
|
ServerL ++ [Server];
|
||||||
|
|
||||||
move_to(Direct, ToName, Server, ServerL) ->
|
move_to(Direct, ToName, Server, ServerL) ->
|
||||||
|
|
|
@ -37,7 +37,7 @@ exhook {
|
||||||
">>).
|
">>).
|
||||||
|
|
||||||
all() ->
|
all() ->
|
||||||
[ t_list, t_get, t_add, t_move_top, t_move_bottom
|
[ t_list, t_get, t_add, t_move_front, t_move_rear
|
||||||
, t_move_before, t_move_after, t_delete, t_hooks, t_update
|
, t_move_before, t_move_after, t_delete, t_hooks, t_update
|
||||||
].
|
].
|
||||||
|
|
||||||
|
@ -133,18 +133,18 @@ t_add(Cfg) ->
|
||||||
|
|
||||||
?assertMatch([<<"default">>, <<"test1">>], emqx_exhook_mgr:running()).
|
?assertMatch([<<"default">>, <<"test1">>], emqx_exhook_mgr:running()).
|
||||||
|
|
||||||
t_move_top(_) ->
|
t_move_front(_) ->
|
||||||
Result = request_api(post, api_path(["exhooks", "default", "move"]), "",
|
Result = request_api(post, api_path(["exhooks", "default", "move"]), "",
|
||||||
auth_header_(),
|
auth_header_(),
|
||||||
#{position => <<"top">>}),
|
#{position => <<"front">>}),
|
||||||
|
|
||||||
?assertMatch({ok, <<>>}, Result),
|
?assertMatch({ok, <<>>}, Result),
|
||||||
?assertMatch([<<"default">>, <<"test1">>], emqx_exhook_mgr:running()).
|
?assertMatch([<<"default">>, <<"test1">>], emqx_exhook_mgr:running()).
|
||||||
|
|
||||||
t_move_bottom(_) ->
|
t_move_rear(_) ->
|
||||||
Result = request_api(post, api_path(["exhooks", "default", "move"]), "",
|
Result = request_api(post, api_path(["exhooks", "default", "move"]), "",
|
||||||
auth_header_(),
|
auth_header_(),
|
||||||
#{position => <<"bottom">>}),
|
#{position => <<"rear">>}),
|
||||||
|
|
||||||
?assertMatch({ok, <<>>}, Result),
|
?assertMatch({ok, <<>>}, Result),
|
||||||
?assertMatch([<<"test1">>, <<"default">>], emqx_exhook_mgr:running()).
|
?assertMatch([<<"test1">>, <<"default">>], emqx_exhook_mgr:running()).
|
||||||
|
|
|
@ -199,11 +199,11 @@ fields(builder) ->
|
||||||
{website, hoconsc:mk(string(), #{example => "www.emqx.com"})}
|
{website, hoconsc:mk(string(), #{example => "www.emqx.com"})}
|
||||||
];
|
];
|
||||||
fields(position) ->
|
fields(position) ->
|
||||||
[{position, hoconsc:mk(hoconsc:union([top, bottom, binary()]),
|
[{position, hoconsc:mk(hoconsc:union([front, rear, binary()]),
|
||||||
#{
|
#{
|
||||||
desc => """
|
desc => """
|
||||||
Enable auto-boot at position in the boot list, where Position could be
|
Enable auto-boot at position in the boot list, where Position could be
|
||||||
'top', 'bottom', or 'before:other-vsn', 'after:other-vsn'
|
'front', 'rear', or 'before:other-vsn', 'after:other-vsn'
|
||||||
to specify a relative position.
|
to specify a relative position.
|
||||||
""",
|
""",
|
||||||
required => false
|
required => false
|
||||||
|
@ -221,13 +221,13 @@ fields(running_status) ->
|
||||||
move_request_body() ->
|
move_request_body() ->
|
||||||
emqx_dashboard_swagger:schema_with_examples(hoconsc:ref(?MODULE, position),
|
emqx_dashboard_swagger:schema_with_examples(hoconsc:ref(?MODULE, position),
|
||||||
#{
|
#{
|
||||||
move_to_top => #{
|
move_to_front => #{
|
||||||
summary => <<"move plugin on the top">>,
|
summary => <<"move plugin on the front">>,
|
||||||
value => #{position => <<"top">>}
|
value => #{position => <<"front">>}
|
||||||
},
|
},
|
||||||
move_to_bottom => #{
|
move_to_rear => #{
|
||||||
summary => <<"move plugin on the bottom">>,
|
summary => <<"move plugin on the rear">>,
|
||||||
value => #{position => <<"bottom">>}
|
value => #{position => <<"rear">>}
|
||||||
},
|
},
|
||||||
move_to_before => #{
|
move_to_before => #{
|
||||||
summary => <<"move plugin before other plugins">>,
|
summary => <<"move plugin before other plugins">>,
|
||||||
|
@ -350,8 +350,8 @@ return(_, {error, #{error := "bad_info_file", return := {enoent, _}, path := Pat
|
||||||
return(_, {error, Reason}) ->
|
return(_, {error, Reason}) ->
|
||||||
{400, #{code => 'PARAM_ERROR', message => iolist_to_binary(io_lib:format("~p", [Reason]))}}.
|
{400, #{code => 'PARAM_ERROR', message => iolist_to_binary(io_lib:format("~p", [Reason]))}}.
|
||||||
|
|
||||||
parse_position(#{<<"position">> := <<"top">>}, _) -> front;
|
parse_position(#{<<"position">> := <<"front">>}, _) -> front;
|
||||||
parse_position(#{<<"position">> := <<"bottom">>}, _) -> rear;
|
parse_position(#{<<"position">> := <<"rear">>}, _) -> rear;
|
||||||
parse_position(#{<<"position">> := <<"before:", Name/binary>>}, Name) ->
|
parse_position(#{<<"position">> := <<"before:", Name/binary>>}, Name) ->
|
||||||
{error, <<"Can't before:self">>};
|
{error, <<"Can't before:self">>};
|
||||||
parse_position(#{<<"position">> := <<"after:", Name/binary>>}, Name) ->
|
parse_position(#{<<"position">> := <<"after:", Name/binary>>}, Name) ->
|
||||||
|
|
Loading…
Reference in New Issue