chore: fix dialyzer error

Signed-off-by: zhanghongtong <rory-z@outlook.com>
This commit is contained in:
Rory Z 2021-08-24 15:56:17 +08:00 committed by Rory Z
parent a2bafd1a18
commit 7e8dde7e26
7 changed files with 11 additions and 53 deletions

View File

@ -233,7 +233,6 @@ create_resource(#{type := DB,
{error, Reason} -> {error, Reason}
end.
-spec(init_provider(rule()) -> rule()).
init_provider(#{enable := true,
type := file,
path := Path
@ -301,7 +300,7 @@ init_provider(#{enable := false} = Rule) ->Rule.
-> {stop, allow} | {ok, deny}).
authorize(#{username := Username,
peerhost := IpAddress
} = Client, PubSub, Topic, _DefaultResult, Rules) ->
} = Client, PubSub, Topic, DefaultResult, Rules) ->
case do_authorize(Client, PubSub, Topic, Rules) of
{matched, allow} ->
?LOG(info, "Client succeeded authorization: Username: ~p, IP: ~p, Topic: ~p, Permission: allow", [Username, IpAddress, Topic]),
@ -313,7 +312,7 @@ authorize(#{username := Username,
{stop, deny};
nomatch ->
?LOG(info, "Client failed authorization: Username: ~p, IP: ~p, Topic: ~p, Reasion: ~p", [Username, IpAddress, Topic, "no-match rule"]),
{stop, deny}
{stop, DefaultResult}
end.
do_authorize(Client, PubSub, Topic,

View File

@ -70,11 +70,6 @@ atom(B) when is_binary(B) ->
catch
_ -> binary_to_atom(B)
end;
atom(L) when is_list(L) ->
try list_to_existing_atom(L)
catch
_ -> list_to_atom(L)
end;
atom(A) when is_atom(A) -> A.
bin(L) when is_list(L) ->
@ -84,7 +79,7 @@ bin(B) when is_binary(B) ->
-spec(matches(emqx_types:clientinfo(), emqx_types:pubsub(), emqx_types:topic(), [rule()])
-> {matched, allow} | {matched, deny} | nomatch).
matches(Client, PubSub, Topic, []) -> nomatch;
matches(_Client, _PubSub, _Topic, []) -> nomatch;
matches(Client, PubSub, Topic, [{Permission, Who, Action, TopicFilters} | Tail]) ->
case match(Client, PubSub, Topic, {Permission, Who, Action, TopicFilters}) of
nomatch -> matches(Client, PubSub, Topic, Tail);

View File

@ -33,6 +33,7 @@ groups() ->
init_per_suite(Config) ->
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end),
meck:expect(emqx_resource, update, fun(_, _, _, _) -> {ok, meck_data} end),
meck:expect(emqx_resource, remove, fun(_) -> ok end ),
ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT),
@ -110,10 +111,7 @@ t_update_rule(_) ->
{ok, _} = emqx_authz:update(head, [?RULE1]),
{ok, _} = emqx_authz:update(tail, [?RULE3]),
dbg:tracer(),dbg:p(all,c),
dbg:tpl(hocon_schema, check, cx),
Lists1 = emqx_authz:check_rules([?RULE1, ?RULE2, ?RULE3]),
?assertMatch(Lists1, emqx:get_config([authorization_rules, rules], [])),
?assertMatch([#{type := http}, #{type := mongo}, #{type := mysql}], emqx:get_config([authorization_rules, rules], [])),
[#{annotations := #{id := Id1}, type := http},
#{annotations := #{id := Id2}, type := mongo},
@ -122,8 +120,7 @@ t_update_rule(_) ->
{ok, _} = emqx_authz:update({replace_once, Id1}, ?RULE5),
{ok, _} = emqx_authz:update({replace_once, Id3}, ?RULE4),
Lists2 = emqx_authz:check_rules([?RULE1, ?RULE2, ?RULE4]),
?assertMatch(Lists2, emqx:get_config([authorization_rules, rules], [])),
?assertMatch([#{type := redis}, #{type := mongo}, #{type := pgsql}], emqx:get_config([authorization_rules, rules], [])),
[#{annotations := #{id := Id1}, type := redis},
#{annotations := #{id := Id2}, type := mongo},

View File

@ -37,37 +37,6 @@
-define(API_VERSION, "v5").
-define(BASE_PATH, "api").
% -define(RULE1, #{<<"principal">> => <<"all">>,
% <<"topics">> => [<<"#">>],
% <<"action">> => <<"all">>,
% <<"permission">> => <<"deny">>}
% ).
% -define(RULE2, #{<<"principal">> =>
% #{<<"ipaddress">> => <<"127.0.0.1">>},
% <<"topics">> =>
% [#{<<"eq">> => <<"#">>},
% #{<<"eq">> => <<"+">>}
% ] ,
% <<"action">> => <<"all">>,
% <<"permission">> => <<"allow">>}
% ).
% -define(RULE3,#{<<"principal">> =>
% #{<<"and">> => [#{<<"username">> => <<"^test?">>},
% #{<<"clientid">> => <<"^test?">>}
% ]},
% <<"topics">> => [<<"test">>],
% <<"action">> => <<"publish">>,
% <<"permission">> => <<"allow">>}
% ).
% -define(RULE4,#{<<"principal">> =>
% #{<<"or">> => [#{<<"username">> => <<"^test">>},
% #{<<"clientid">> => <<"test?">>}
% ]},
% <<"topics">> => [<<"%u">>,<<"%c">>],
% <<"action">> => <<"publish">>,
% <<"permission">> => <<"deny">>}
% ).
-define(RULE1, #{<<"type">> => <<"http">>,
<<"config">> => #{
<<"url">> => <<"https://fake.com:443/">>,
@ -119,8 +88,7 @@
}).
all() ->
% emqx_ct:all(?MODULE).
[].
emqx_ct:all(?MODULE).
groups() ->
[].
@ -129,6 +97,7 @@ init_per_suite(Config) ->
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end),
meck:expect(emqx_resource, update, fun(_, _, _, _) -> {ok, meck_data} end),
meck:expect(emqx_resource, health_check, fun(_) -> ok end),
meck:expect(emqx_resource, remove, fun(_) -> ok end ),
ekka_mnesia:start(),

View File

@ -21,8 +21,6 @@
-include("emqx_authz.hrl").
-include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl").
-define(CONF_DEFAULT, <<"authorization: {rules: []}">>).
-define(CONF_DEFAULT, <<"authorization_rules: {rules: []}">>).
all() ->

View File

@ -21,8 +21,6 @@
-include("emqx_authz.hrl").
-include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl").
-define(CONF_DEFAULT, <<"authorization: {rules: []}">>).
-define(CONF_DEFAULT, <<"authorization_rules: {rules: []}">>).
all() ->

View File

@ -84,7 +84,9 @@ mongo_fields() ->
nullable => true}}
, {database, fun emqx_connector_schema_lib:database/1}
, {topology, #{type => hoconsc:ref(?MODULE, topology),
nullable => true}}
default => #{}}}
%% TODO: Does the ref type support nullable=ture ?
% nullable => true}}
] ++
emqx_connector_schema_lib:ssl_fields().