refactor(authz_api): avoid copy paste
This commit is contained in:
parent
0ee3e49db7
commit
0b7f1ab69c
|
@ -108,10 +108,10 @@ lookup(Type) ->
|
||||||
{Source, _Front, _Rear} = take(Type),
|
{Source, _Front, _Rear} = take(Type),
|
||||||
Source.
|
Source.
|
||||||
|
|
||||||
move(Type, {before, Before}) ->
|
move(Type, ?CMD_MOVE_BEFORE(Before)) ->
|
||||||
emqx_authz_utils:update_config(
|
emqx_authz_utils:update_config(
|
||||||
?CONF_KEY_PATH, {?CMD_MOVE, type(Type), ?CMD_MOVE_BEFORE(type(Before))});
|
?CONF_KEY_PATH, {?CMD_MOVE, type(Type), ?CMD_MOVE_BEFORE(type(Before))});
|
||||||
move(Type, {'after', After}) ->
|
move(Type, ?CMD_MOVE_AFTER(After)) ->
|
||||||
emqx_authz_utils:update_config(
|
emqx_authz_utils:update_config(
|
||||||
?CONF_KEY_PATH, {?CMD_MOVE, type(Type), ?CMD_MOVE_AFTER(type(After))});
|
?CONF_KEY_PATH, {?CMD_MOVE, type(Type), ?CMD_MOVE_AFTER(type(After))});
|
||||||
move(Type, Position) ->
|
move(Type, Position) ->
|
||||||
|
|
|
@ -66,16 +66,13 @@ schema("/authorization/sources") ->
|
||||||
, get =>
|
, get =>
|
||||||
#{ description => <<"List all authorization sources">>
|
#{ description => <<"List all authorization sources">>
|
||||||
, responses =>
|
, responses =>
|
||||||
#{ 200 => mk( array(hoconsc:union(
|
#{ 200 => mk( array(hoconsc:union(authz_sources_type_refs()))
|
||||||
[ref(?API_SCHEMA_MODULE, Type) || Type <- authz_sources_types(detailed)]))
|
|
||||||
, #{desc => <<"Authorization source">>})
|
, #{desc => <<"Authorization source">>})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
, post =>
|
, post =>
|
||||||
#{ description => <<"Add a new source">>
|
#{ description => <<"Add a new source">>
|
||||||
, 'requestBody' => mk( hoconsc:union(
|
, 'requestBody' => mk( hoconsc:union(authz_sources_type_refs())
|
||||||
[ref(?API_SCHEMA_MODULE, Type)
|
|
||||||
|| Type <- authz_sources_types(detailed)])
|
|
||||||
, #{desc => <<"Source config">>})
|
, #{desc => <<"Source config">>})
|
||||||
, responses =>
|
, responses =>
|
||||||
#{ 204 => <<"Authorization source created successfully">>
|
#{ 204 => <<"Authorization source created successfully">>
|
||||||
|
@ -85,9 +82,7 @@ schema("/authorization/sources") ->
|
||||||
}
|
}
|
||||||
, put =>
|
, put =>
|
||||||
#{ description => <<"Update all sources">>
|
#{ description => <<"Update all sources">>
|
||||||
, 'requestBody' => mk( array(hoconsc:union(
|
, 'requestBody' => mk( array(hoconsc:union(authz_sources_type_refs()))
|
||||||
[ref(?API_SCHEMA_MODULE, Type)
|
|
||||||
|| Type <- authz_sources_types(detailed)]))
|
|
||||||
, #{desc => <<"Sources">>})
|
, #{desc => <<"Sources">>})
|
||||||
, responses =>
|
, responses =>
|
||||||
#{ 204 => <<"Authorization source updated successfully">>
|
#{ 204 => <<"Authorization source updated successfully">>
|
||||||
|
@ -102,9 +97,7 @@ schema("/authorization/sources/:type") ->
|
||||||
#{ description => <<"Get a authorization source">>
|
#{ description => <<"Get a authorization source">>
|
||||||
, parameters => parameters_field()
|
, parameters => parameters_field()
|
||||||
, responses =>
|
, responses =>
|
||||||
#{ 200 => mk( hoconsc:union(
|
#{ 200 => mk( hoconsc:union(authz_sources_type_refs())
|
||||||
[ref(?API_SCHEMA_MODULE, Type)
|
|
||||||
|| Type <- authz_sources_types(detailed)])
|
|
||||||
, #{desc => <<"Authorization source">>})
|
, #{desc => <<"Authorization source">>})
|
||||||
, 404 => emqx_dashboard_swagger:error_codes([?NOT_FOUND], <<"Not Found">>)
|
, 404 => emqx_dashboard_swagger:error_codes([?NOT_FOUND], <<"Not Found">>)
|
||||||
}
|
}
|
||||||
|
@ -112,8 +105,7 @@ schema("/authorization/sources/:type") ->
|
||||||
, put =>
|
, put =>
|
||||||
#{ description => <<"Update source">>
|
#{ description => <<"Update source">>
|
||||||
, parameters => parameters_field()
|
, parameters => parameters_field()
|
||||||
, 'requestBody' => mk( hoconsc:union([ref(?API_SCHEMA_MODULE, Type)
|
, 'requestBody' => mk( hoconsc:union(authz_sources_type_refs()))
|
||||||
|| Type <- authz_sources_types(detailed)]))
|
|
||||||
, responses =>
|
, responses =>
|
||||||
#{ 204 => <<"Authorization source updated successfully">>
|
#{ 204 => <<"Authorization source updated successfully">>
|
||||||
, 400 => emqx_dashboard_swagger:error_codes([?BAD_REQUEST], <<"Bad Request">>)
|
, 400 => emqx_dashboard_swagger:error_codes([?BAD_REQUEST], <<"Bad Request">>)
|
||||||
|
@ -511,8 +503,9 @@ position_example() ->
|
||||||
, value => #{<<"position">> => <<"after:file">>}}
|
, value => #{<<"position">> => <<"after:file">>}}
|
||||||
}.
|
}.
|
||||||
|
|
||||||
authz_sources_types(Type) ->
|
authz_sources_type_refs() ->
|
||||||
emqx_authz_api_schema:authz_sources_types(Type).
|
[ref(?API_SCHEMA_MODULE, Type)
|
||||||
|
|| Type <- emqx_authz_api_schema:authz_sources_types(detailed)].
|
||||||
|
|
||||||
bin(Term) -> erlang:iolist_to_binary(io_lib:format("~p", [Term])).
|
bin(Term) -> erlang:iolist_to_binary(io_lib:format("~p", [Term])).
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue