From 4f0684e887d47d91e9251c84f581c3ddad7518e0 Mon Sep 17 00:00:00 2001 From: zhanghongtong Date: Thu, 23 Sep 2021 17:59:32 +0800 Subject: [PATCH] chore(authz api): delete healthy status for get method --- apps/emqx_authz/src/emqx_authz.erl | 2 - apps/emqx_authz/src/emqx_authz_api_schema.erl | 24 +-------- .../emqx_authz/src/emqx_authz_api_sources.erl | 54 +++++-------------- 3 files changed, 15 insertions(+), 65 deletions(-) diff --git a/apps/emqx_authz/src/emqx_authz.erl b/apps/emqx_authz/src/emqx_authz.erl index 224039391..e7ccbe5b0 100644 --- a/apps/emqx_authz/src/emqx_authz.erl +++ b/apps/emqx_authz/src/emqx_authz.erl @@ -36,8 +36,6 @@ , authorize/5 ]). --export([gen_id/1]). - -export([post_config_update/4, pre_config_update/2]). -define(CONF_KEY_PATH, [authorization, sources]). diff --git a/apps/emqx_authz/src/emqx_authz_api_schema.erl b/apps/emqx_authz/src/emqx_authz_api_schema.erl index d99c5acb5..b41aaf3b3 100644 --- a/apps/emqx_authz/src/emqx_authz_api_schema.erl +++ b/apps/emqx_authz/src/emqx_authz_api_schema.erl @@ -19,27 +19,6 @@ -export([definitions/0]). definitions() -> - RetruenedSources = #{ - allOf => [ #{type => object, - properties => #{ - annotations => #{ - type => object, - required => [status], - properties => #{ - id => #{ - type => string - }, - status => #{ - type => string, - example => <<"healthy">> - } - } - } - } - } - , minirest:ref(<<"sources">>) - ] - }, Sources = #{ oneOf => [ minirest:ref(<<"http">>) , minirest:ref(<<"mongo_single">>) @@ -493,8 +472,7 @@ definitions() -> } } }, - [ #{<<"returned_sources">> => RetruenedSources} - , #{<<"sources">> => Sources} + [ #{<<"sources">> => Sources} , #{<<"ssl">> => SSL} , #{<<"http">> => HTTP} , #{<<"mongo_single">> => MongoSingle} diff --git a/apps/emqx_authz/src/emqx_authz_api_sources.erl b/apps/emqx_authz/src/emqx_authz_api_sources.erl index 241766ed1..15820b4ed 100644 --- a/apps/emqx_authz/src/emqx_authz_api_sources.erl +++ b/apps/emqx_authz/src/emqx_authz_api_sources.erl @@ -35,16 +35,9 @@ rules => <<"{allow,{username,\"^dashboard?\"},subscribe,[\"$SYS/#\"]}.\n{allow,{ipaddr,\"127.0.0.1\"},all,[\"$SYS/#\",\"#\"]}.">> }). --define(EXAMPLE_RETURNED_REDIS, - maps:put(annotations, #{status => healthy}, ?EXAMPLE_REDIS) - ). --define(EXAMPLE_RETURNED_FILE, - maps:put(annotations, #{status => healthy}, ?EXAMPLE_FILE) - ). - -define(EXAMPLE_RETURNED, - #{sources => [ ?EXAMPLE_RETURNED_REDIS - , ?EXAMPLE_RETURNED_FILE + #{sources => [ ?EXAMPLE_REDIS + , ?EXAMPLE_FILE ] }). @@ -76,7 +69,7 @@ sources_api() -> required => [sources], properties => #{sources => #{ type => array, - items => minirest:ref(<<"returned_sources">>) + items => minirest:ref(<<"sources">>) } } }, @@ -122,7 +115,7 @@ sources_api() -> 'application/json' => #{ schema => #{ type => array, - items => minirest:ref(<<"returned_sources">>) + items => minirest:ref(<<"sources">>) }, examples => #{ redis => #{ @@ -164,15 +157,15 @@ source_api() -> description => <<"OK">>, content => #{ 'application/json' => #{ - schema => minirest:ref(<<"returned_sources">>), + schema => minirest:ref(<<"sources">>), examples => #{ redis => #{ summary => <<"Redis">>, - value => jsx:encode(?EXAMPLE_RETURNED_REDIS) + value => jsx:encode(?EXAMPLE_REDIS) }, file => #{ summary => <<"File">>, - value => jsx:encode(?EXAMPLE_RETURNED_FILE) + value => jsx:encode(?EXAMPLE_FILE) } } } @@ -302,26 +295,16 @@ sources(get, _) -> {ok, Rules} -> lists:append(AccIn, [#{type => file, enable => Enable, - rules => Rules, - annotations => #{status => healthy} + rules => Rules }]); {error, _} -> lists:append(AccIn, [#{type => file, enable => Enable, - rules => <<"">>, - annotations => #{status => unhealthy} + rules => <<"">> }]) end; - (#{type := DB, enable := true} = Source, AccIn) -> - NSource = case emqx_resource:health_check(emqx_authz:gen_id(DB)) of - ok -> - Source#{annotations => #{status => healthy}}; - _ -> - Source#{annotations => #{status => unhealthy}} - end, - lists:append(AccIn, [read_cert(NSource)]); - (#{enable := false} = Source, AccIn) -> - lists:append(AccIn, [Source#{annotations => #{status => unhealthy}}]) + (Source, AccIn) -> + lists:append(AccIn, [read_cert(Source)]) end, [], get_raw_sources()), {200, #{sources => Sources}}; sources(post, #{body := #{<<"type">> := <<"file">>, <<"rules">> := Rules}}) -> @@ -348,24 +331,15 @@ source(get, #{bindings := #{type := Type}}) -> {ok, Rules} -> {200, #{type => file, enable => Enable, - rules => Rules, - annotations => #{status => healthy} + rules => Rules } }; {error, Reason} -> {400, #{code => <<"BAD_REQUEST">>, message => atom_to_binary(Reason)}} end; - [#{type := DB, enable := true} = Source] -> - NSource = case emqx_resource:health_check(emqx_authz:gen_id(DB)) of - ok -> - Source#{annotations => #{status => healthy}}; - _ -> - Source#{annotations => #{status => unhealthy}} - end, - {200, read_cert(NSource)}; - [#{enable := false} = Source] -> - {200, Source#{annotations => #{status => unhealthy}}} + [Source] -> + {200, read_cert(Source)} end; source(put, #{bindings := #{type := <<"file">>}, body := #{<<"type">> := <<"file">>, <<"rules">> := Rules, <<"enable">> := Enable}}) -> {ok, Filename} = write_file(maps:get(path, emqx_authz:lookup(file), ""), Rules),