fix: disable authn_api, authz_api_sources swagger spec

This commit is contained in:
EMQ-YangM 2022-03-14 19:12:06 +08:00
parent 4fce9d4cc3
commit eb5570dd07
2 changed files with 54 additions and 32 deletions

View File

@ -84,7 +84,7 @@
-elvis([{elvis_style, god_modules, disable}]). -elvis([{elvis_style, god_modules, disable}]).
api_spec() -> api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}). emqx_dashboard_swagger:spec(?MODULE, #{check_schema => false}).
paths() -> [ "/authentication" paths() -> [ "/authentication"
, "/authentication/:id" , "/authentication/:id"
@ -758,9 +758,8 @@ list_authenticator(ChainName, ConfKeyPath, AuthenticatorID) ->
{ok, AuthenticatorConfig} -> {ok, AuthenticatorConfig} ->
case lookup_from_all_nodes(ChainName, AuthenticatorID) of case lookup_from_all_nodes(ChainName, AuthenticatorID) of
{ok, StatusAndMetrics} -> {ok, StatusAndMetrics} ->
Fun = fun ({Key, Val}, Map) -> maps:put(Key, Val, Map) end, {200, maps:merge(convert_certs(AuthenticatorConfig),
AppendList = [{id, AuthenticatorID} | maps:to_list(StatusAndMetrics)], maps:put(id, AuthenticatorID, StatusAndMetrics))};
{200, lists:foldl(Fun, convert_certs(AuthenticatorConfig), AppendList)};
{error, ErrorMsg} -> {500, ErrorMsg} {error, ErrorMsg} -> {500, ErrorMsg}
end; end;
{error, Reason} -> {error, Reason} ->
@ -796,22 +795,26 @@ lookup_from_all_nodes(ChainName, AuthenticatorID) ->
Nodes = mria_mnesia:running_nodes(), Nodes = mria_mnesia:running_nodes(),
case is_ok(emqx_authn_proto_v1:lookup_from_all_nodes(Nodes, ChainName, AuthenticatorID)) of case is_ok(emqx_authn_proto_v1:lookup_from_all_nodes(Nodes, ChainName, AuthenticatorID)) of
{ok, ResList} -> {ok, ResList} ->
{StatusMap, MetricsMap, ErrorMap} = make_result_map(ResList), {StatusMap, MetricsMap, _} = make_result_map(ResList),
AggregateStatus = aggregate_status(maps:values(StatusMap)), AggregateStatus = aggregate_status(maps:values(StatusMap)),
AggregateMetrics = aggregate_metrics(maps:values(MetricsMap)), AggregateMetrics = aggregate_metrics(maps:values(MetricsMap)),
Fun = fun(_, V1) -> restructure_map(V1) end, Fun = fun (_, V1) -> restructure_map(V1) end,
{ok, #{node_status => StatusMap, MKMap = fun (Name) -> fun ({Key, Val}) -> #{ node => Key, Name => Val } end end,
node_metrics => maps:map(Fun, MetricsMap), HelpFun = fun (M, Name) -> lists:map(MKMap(Name), maps:to_list(M)) end,
node_error => ErrorMap, case AggregateStatus of
status => AggregateStatus, empty_metrics_and_status -> {ok, #{}};
metrics => restructure_map(AggregateMetrics) _ -> {ok, #{node_status => HelpFun(StatusMap, status),
} node_metrics => HelpFun(maps:map(Fun, MetricsMap), metrics),
}; status => AggregateStatus,
metrics => restructure_map(AggregateMetrics)
}
}
end;
{error, ErrL} -> {error, ErrL} ->
{error, error_msg('INTERNAL_ERROR', ErrL)} {error, error_msg('INTERNAL_ERROR', ErrL)}
end. end.
aggregate_status([]) -> error_some_strange_happen; aggregate_status([]) -> empty_metrics_and_status;
aggregate_status(AllStatus) -> aggregate_status(AllStatus) ->
Head = fun ([A | _]) -> A end, Head = fun ([A | _]) -> A end,
HeadVal = Head(AllStatus), HeadVal = Head(AllStatus),
@ -821,7 +824,7 @@ aggregate_status(AllStatus) ->
false -> inconsistent false -> inconsistent
end. end.
aggregate_metrics([]) -> error_some_strange_happen; aggregate_metrics([]) -> empty_metrics_and_status;
aggregate_metrics([HeadMetrics | AllMetrics]) -> aggregate_metrics([HeadMetrics | AllMetrics]) ->
CombinerFun = CombinerFun =
fun ComFun(Val1, Val2) -> fun ComFun(Val1, Val2) ->
@ -879,8 +882,17 @@ is_ok(ResL) ->
ErrL -> {error, ErrL} ErrL -> {error, ErrL}
end. end.
filter_out_request_body(Conf) ->
ExtraConfs = [<<"status">>, <<"node_status">>,
<<"node_metrics">>, <<"metrics">>, <<"node">>],
maps:without(ExtraConfs, Conf).
update_authenticator(ConfKeyPath, ChainName, AuthenticatorID, Config) -> update_authenticator(ConfKeyPath, ChainName, AuthenticatorID, Config) ->
case update_config(ConfKeyPath, {update_authenticator, ChainName, AuthenticatorID, Config}) of case update_config(ConfKeyPath,
{update_authenticator,
ChainName,
AuthenticatorID,
filter_out_request_body(Config)}) of
{ok, #{post_config_update := #{emqx_authentication := #{id := ID}}, {ok, #{post_config_update := #{emqx_authentication := #{id := ID}},
raw_config := AuthenticatorsConfig}} -> raw_config := AuthenticatorsConfig}} ->
{ok, AuthenticatorConfig} = find_config(ID, AuthenticatorsConfig), {ok, AuthenticatorConfig} = find_config(ID, AuthenticatorsConfig),

View File

@ -69,7 +69,7 @@
]). ]).
api_spec() -> api_spec() ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}). emqx_dashboard_swagger:spec(?MODULE, #{check_schema => false}).
paths() -> paths() ->
[ "/authorization/sources" [ "/authorization/sources"
@ -254,10 +254,16 @@ source(put, #{bindings := #{type := <<"file">>}, body := #{<<"type">> := <<"file
message => bin(Reason)}} message => bin(Reason)}}
end; end;
source(put, #{bindings := #{type := Type}, body := Body}) when is_map(Body) -> source(put, #{bindings := #{type := Type}, body := Body}) when is_map(Body) ->
update_config({?CMD_REPLACE, Type}, maybe_write_certs(Body#{<<"type">> => Type})); update_config({?CMD_REPLACE, Type},
maybe_write_certs(filter_out_request_body(Body#{<<"type">> => Type})));
source(delete, #{bindings := #{type := Type}}) -> source(delete, #{bindings := #{type := Type}}) ->
update_config({?CMD_DELETE, Type}, #{}). update_config({?CMD_DELETE, Type}, #{}).
filter_out_request_body(Conf) ->
ExtraConfs = [<<"status">>, <<"node_status">>,
<<"node_metrics">>, <<"metrics">>, <<"node">>],
maps:without(ExtraConfs, Conf).
move_source(Method, #{bindings := #{type := Type} = Bindings } = Req) move_source(Method, #{bindings := #{type := Type} = Bindings } = Req)
when is_atom(Type) -> when is_atom(Type) ->
move_source(Method, Req#{bindings => Bindings#{type => atom_to_binary(Type, utf8)}}); move_source(Method, Req#{bindings => Bindings#{type => atom_to_binary(Type, utf8)}});
@ -302,22 +308,26 @@ lookup_from_all_nodes(ResourceId) ->
Nodes = mria_mnesia:running_nodes(), Nodes = mria_mnesia:running_nodes(),
case is_ok(emqx_authz_proto_v1:lookup_from_all_nodes(Nodes, ResourceId)) of case is_ok(emqx_authz_proto_v1:lookup_from_all_nodes(Nodes, ResourceId)) of
{ok, ResList} -> {ok, ResList} ->
{StatusMap, MetricsMap, ErrorMap} = make_result_map(ResList), {StatusMap, MetricsMap, _} = make_result_map(ResList),
AggregateStatus = aggregate_status(maps:values(StatusMap)), AggregateStatus = aggregate_status(maps:values(StatusMap)),
AggregateMetrics = aggregate_metrics(maps:values(MetricsMap)), AggregateMetrics = aggregate_metrics(maps:values(MetricsMap)),
Fun = fun(_, V1) -> restructure_map(V1) end, Fun = fun (_, V1) -> restructure_map(V1) end,
{ok, #{node_status => StatusMap, MKMap = fun (Name) -> fun ({Key, Val}) -> #{ node => Key, Name => Val } end end,
node_metrics => maps:map(Fun, MetricsMap), HelpFun = fun (M, Name) -> lists:map(MKMap(Name), maps:to_list(M)) end,
node_error => ErrorMap, case AggregateStatus of
status => AggregateStatus, empty_metrics_and_status -> {ok, #{}};
metrics => restructure_map(AggregateMetrics) _ -> {ok, #{node_status => HelpFun(StatusMap, status),
node_metrics => HelpFun(maps:map(Fun, MetricsMap), metrics),
status => AggregateStatus,
metrics => restructure_map(AggregateMetrics)
}
} }
}; end;
{error, ErrL} -> {error, ErrL} ->
{error, error_msg('INTERNAL_ERROR', ErrL)} {error, error_msg('INTERNAL_ERROR', ErrL)}
end. end.
aggregate_status([]) -> error_some_strange_happen; aggregate_status([]) -> empty_metrics_and_status;
aggregate_status(AllStatus) -> aggregate_status(AllStatus) ->
Head = fun ([A | _]) -> A end, Head = fun ([A | _]) -> A end,
HeadVal = Head(AllStatus), HeadVal = Head(AllStatus),
@ -327,7 +337,7 @@ aggregate_status(AllStatus) ->
false -> inconsistent false -> inconsistent
end. end.
aggregate_metrics([]) -> error_some_strange_happen; aggregate_metrics([]) -> empty_metrics_and_status;
aggregate_metrics([HeadMetrics | AllMetrics]) -> aggregate_metrics([HeadMetrics | AllMetrics]) ->
CombinerFun = CombinerFun =
fun ComFun(Val1, Val2) -> fun ComFun(Val1, Val2) ->