|
@@ -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,
|
|
|
|
|
- AppendList = [{id, AuthenticatorID} | maps:to_list(StatusAndMetrics)],
|
|
|
|
|
- {200, lists:foldl(Fun, convert_certs(AuthenticatorConfig), AppendList)};
|
|
|
|
|
|
|
+ {200, maps:merge(convert_certs(AuthenticatorConfig),
|
|
|
|
|
+ maps:put(id, AuthenticatorID, StatusAndMetrics))};
|
|
|
{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),
|
|
|
|
|
- AggregateStatus = aggregate_status(maps:values(StatusMap)),
|
|
|
|
|
- AggregateMetrics = aggregate_metrics(maps:values(MetricsMap)),
|
|
|
|
|
- Fun = fun(_, V1) -> restructure_map(V1) end,
|
|
|
|
|
- {ok, #{node_status => StatusMap,
|
|
|
|
|
- node_metrics => maps:map(Fun, MetricsMap),
|
|
|
|
|
- node_error => ErrorMap,
|
|
|
|
|
- status => AggregateStatus,
|
|
|
|
|
- metrics => restructure_map(AggregateMetrics)
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ {StatusMap, MetricsMap, _} = make_result_map(ResList),
|
|
|
|
|
+ AggregateStatus = aggregate_status(maps:values(StatusMap)),
|
|
|
|
|
+ AggregateMetrics = aggregate_metrics(maps:values(MetricsMap)),
|
|
|
|
|
+ Fun = fun (_, V1) -> restructure_map(V1) end,
|
|
|
|
|
+ MKMap = fun (Name) -> fun ({Key, Val}) -> #{ node => Key, Name => Val } end end,
|
|
|
|
|
+ HelpFun = fun (M, Name) -> lists:map(MKMap(Name), maps:to_list(M)) end,
|
|
|
|
|
+ case AggregateStatus of
|
|
|
|
|
+ empty_metrics_and_status -> {ok, #{}};
|
|
|
|
|
+ _ -> {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),
|