chore(authz api): delete healthy status for get method
This commit is contained in:
parent
22e8c83a52
commit
4f0684e887
|
@ -36,8 +36,6 @@
|
||||||
, authorize/5
|
, authorize/5
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-export([gen_id/1]).
|
|
||||||
|
|
||||||
-export([post_config_update/4, pre_config_update/2]).
|
-export([post_config_update/4, pre_config_update/2]).
|
||||||
|
|
||||||
-define(CONF_KEY_PATH, [authorization, sources]).
|
-define(CONF_KEY_PATH, [authorization, sources]).
|
||||||
|
|
|
@ -19,27 +19,6 @@
|
||||||
-export([definitions/0]).
|
-export([definitions/0]).
|
||||||
|
|
||||||
definitions() ->
|
definitions() ->
|
||||||
RetruenedSources = #{
|
|
||||||
allOf => [ #{type => object,
|
|
||||||
properties => #{
|
|
||||||
annotations => #{
|
|
||||||
type => object,
|
|
||||||
required => [status],
|
|
||||||
properties => #{
|
|
||||||
id => #{
|
|
||||||
type => string
|
|
||||||
},
|
|
||||||
status => #{
|
|
||||||
type => string,
|
|
||||||
example => <<"healthy">>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
, minirest:ref(<<"sources">>)
|
|
||||||
]
|
|
||||||
},
|
|
||||||
Sources = #{
|
Sources = #{
|
||||||
oneOf => [ minirest:ref(<<"http">>)
|
oneOf => [ minirest:ref(<<"http">>)
|
||||||
, minirest:ref(<<"mongo_single">>)
|
, minirest:ref(<<"mongo_single">>)
|
||||||
|
@ -493,8 +472,7 @@ definitions() ->
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[ #{<<"returned_sources">> => RetruenedSources}
|
[ #{<<"sources">> => Sources}
|
||||||
, #{<<"sources">> => Sources}
|
|
||||||
, #{<<"ssl">> => SSL}
|
, #{<<"ssl">> => SSL}
|
||||||
, #{<<"http">> => HTTP}
|
, #{<<"http">> => HTTP}
|
||||||
, #{<<"mongo_single">> => MongoSingle}
|
, #{<<"mongo_single">> => MongoSingle}
|
||||||
|
|
|
@ -35,16 +35,9 @@
|
||||||
rules => <<"{allow,{username,\"^dashboard?\"},subscribe,[\"$SYS/#\"]}.\n{allow,{ipaddr,\"127.0.0.1\"},all,[\"$SYS/#\",\"#\"]}.">>
|
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,
|
-define(EXAMPLE_RETURNED,
|
||||||
#{sources => [ ?EXAMPLE_RETURNED_REDIS
|
#{sources => [ ?EXAMPLE_REDIS
|
||||||
, ?EXAMPLE_RETURNED_FILE
|
, ?EXAMPLE_FILE
|
||||||
]
|
]
|
||||||
}).
|
}).
|
||||||
|
|
||||||
|
@ -76,7 +69,7 @@ sources_api() ->
|
||||||
required => [sources],
|
required => [sources],
|
||||||
properties => #{sources => #{
|
properties => #{sources => #{
|
||||||
type => array,
|
type => array,
|
||||||
items => minirest:ref(<<"returned_sources">>)
|
items => minirest:ref(<<"sources">>)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -122,7 +115,7 @@ sources_api() ->
|
||||||
'application/json' => #{
|
'application/json' => #{
|
||||||
schema => #{
|
schema => #{
|
||||||
type => array,
|
type => array,
|
||||||
items => minirest:ref(<<"returned_sources">>)
|
items => minirest:ref(<<"sources">>)
|
||||||
},
|
},
|
||||||
examples => #{
|
examples => #{
|
||||||
redis => #{
|
redis => #{
|
||||||
|
@ -164,15 +157,15 @@ source_api() ->
|
||||||
description => <<"OK">>,
|
description => <<"OK">>,
|
||||||
content => #{
|
content => #{
|
||||||
'application/json' => #{
|
'application/json' => #{
|
||||||
schema => minirest:ref(<<"returned_sources">>),
|
schema => minirest:ref(<<"sources">>),
|
||||||
examples => #{
|
examples => #{
|
||||||
redis => #{
|
redis => #{
|
||||||
summary => <<"Redis">>,
|
summary => <<"Redis">>,
|
||||||
value => jsx:encode(?EXAMPLE_RETURNED_REDIS)
|
value => jsx:encode(?EXAMPLE_REDIS)
|
||||||
},
|
},
|
||||||
file => #{
|
file => #{
|
||||||
summary => <<"File">>,
|
summary => <<"File">>,
|
||||||
value => jsx:encode(?EXAMPLE_RETURNED_FILE)
|
value => jsx:encode(?EXAMPLE_FILE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -302,26 +295,16 @@ sources(get, _) ->
|
||||||
{ok, Rules} ->
|
{ok, Rules} ->
|
||||||
lists:append(AccIn, [#{type => file,
|
lists:append(AccIn, [#{type => file,
|
||||||
enable => Enable,
|
enable => Enable,
|
||||||
rules => Rules,
|
rules => Rules
|
||||||
annotations => #{status => healthy}
|
|
||||||
}]);
|
}]);
|
||||||
{error, _} ->
|
{error, _} ->
|
||||||
lists:append(AccIn, [#{type => file,
|
lists:append(AccIn, [#{type => file,
|
||||||
enable => Enable,
|
enable => Enable,
|
||||||
rules => <<"">>,
|
rules => <<"">>
|
||||||
annotations => #{status => unhealthy}
|
|
||||||
}])
|
}])
|
||||||
end;
|
end;
|
||||||
(#{type := DB, enable := true} = Source, AccIn) ->
|
(Source, AccIn) ->
|
||||||
NSource = case emqx_resource:health_check(emqx_authz:gen_id(DB)) of
|
lists:append(AccIn, [read_cert(Source)])
|
||||||
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}}])
|
|
||||||
end, [], get_raw_sources()),
|
end, [], get_raw_sources()),
|
||||||
{200, #{sources => Sources}};
|
{200, #{sources => Sources}};
|
||||||
sources(post, #{body := #{<<"type">> := <<"file">>, <<"rules">> := Rules}}) ->
|
sources(post, #{body := #{<<"type">> := <<"file">>, <<"rules">> := Rules}}) ->
|
||||||
|
@ -348,24 +331,15 @@ source(get, #{bindings := #{type := Type}}) ->
|
||||||
{ok, Rules} ->
|
{ok, Rules} ->
|
||||||
{200, #{type => file,
|
{200, #{type => file,
|
||||||
enable => Enable,
|
enable => Enable,
|
||||||
rules => Rules,
|
rules => Rules
|
||||||
annotations => #{status => healthy}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
{400, #{code => <<"BAD_REQUEST">>,
|
{400, #{code => <<"BAD_REQUEST">>,
|
||||||
message => atom_to_binary(Reason)}}
|
message => atom_to_binary(Reason)}}
|
||||||
end;
|
end;
|
||||||
[#{type := DB, enable := true} = Source] ->
|
[Source] ->
|
||||||
NSource = case emqx_resource:health_check(emqx_authz:gen_id(DB)) of
|
{200, read_cert(Source)}
|
||||||
ok ->
|
|
||||||
Source#{annotations => #{status => healthy}};
|
|
||||||
_ ->
|
|
||||||
Source#{annotations => #{status => unhealthy}}
|
|
||||||
end,
|
|
||||||
{200, read_cert(NSource)};
|
|
||||||
[#{enable := false} = Source] ->
|
|
||||||
{200, Source#{annotations => #{status => unhealthy}}}
|
|
||||||
end;
|
end;
|
||||||
source(put, #{bindings := #{type := <<"file">>}, body := #{<<"type">> := <<"file">>, <<"rules">> := Rules, <<"enable">> := Enable}}) ->
|
source(put, #{bindings := #{type := <<"file">>}, body := #{<<"type">> := <<"file">>, <<"rules">> := Rules, <<"enable">> := Enable}}) ->
|
||||||
{ok, Filename} = write_file(maps:get(path, emqx_authz:lookup(file), ""), Rules),
|
{ok, Filename} = write_file(maps:get(path, emqx_authz:lookup(file), ""), Rules),
|
||||||
|
|
Loading…
Reference in New Issue