feat(authz connector): match directly using the results returned by sql

Signed-off-by: zhanghongtong <rory-z@outlook.com>
This commit is contained in:
zhanghongtong 2021-07-09 14:28:48 +08:00 committed by Rory Z
parent 088e615818
commit 3195561a79
3 changed files with 3 additions and 38 deletions

View File

@ -60,8 +60,7 @@ match(Client, PubSub, Topic,
<<"permission">> := Permission,
<<"action">> := Action
}) ->
Rule = #{<<"principal">> => all,
<<"permission">> => Permission,
Rule = #{<<"permission">> => Permission,
<<"topics">> => Topics,
<<"action">> => Action
},

View File

@ -77,13 +77,9 @@ format_result(Columns, Row) ->
match(Client, PubSub, Topic,
#{<<"permission">> := Permission,
<<"action">> := Action,
<<"clientid">> := ClientId,
<<"username">> := Username,
<<"ipaddress">> := IpAddress,
<<"topic">> := TopicFilter
}) ->
Rule = #{<<"principal">> => principal(IpAddress, Username, ClientId),
<<"topics">> => [TopicFilter],
Rule = #{<<"topics">> => [TopicFilter],
<<"action">> => Action,
<<"permission">> => Permission
},
@ -99,19 +95,6 @@ match(Client, PubSub, Topic,
false -> nomatch
end.
principal(CIDR, Username, ClientId) ->
Cols = [{<<"ipaddress">>, CIDR}, {<<"username">>, Username}, {<<"clientid">>, ClientId}],
case [#{C => V} || {C, V} <- Cols, not empty(V)] of
[] -> throw(undefined_who);
[Who] -> Who;
Conds -> #{<<"and">> => Conds}
end.
empty(null) -> true;
empty("") -> true;
empty(<<>>) -> true;
empty(_) -> false.
replvar(Params, ClientInfo) ->
replvar(Params, ClientInfo, []).

View File

@ -81,13 +81,9 @@ format_result(Columns, Row) ->
match(Client, PubSub, Topic,
#{<<"permission">> := Permission,
<<"action">> := Action,
<<"clientid">> := ClientId,
<<"username">> := Username,
<<"ipaddress">> := IpAddress,
<<"topic">> := TopicFilter
}) ->
Rule = #{<<"principal">> => principal(IpAddress, Username, ClientId),
<<"topics">> => [TopicFilter],
Rule = #{<<"topics">> => [TopicFilter],
<<"action">> => Action,
<<"permission">> => Permission
},
@ -103,19 +99,6 @@ match(Client, PubSub, Topic,
false -> nomatch
end.
principal(CIDR, Username, ClientId) ->
Cols = [{<<"ipaddress">>, CIDR}, {<<"username">>, Username}, {<<"clientid">>, ClientId}],
case [#{C => V} || {C, V} <- Cols, not empty(V)] of
[] -> throw(undefined_who);
[Who] -> Who;
Conds -> #{<<"and">> => Conds}
end.
empty(null) -> true;
empty("") -> true;
empty(<<>>) -> true;
empty(_) -> false.
replvar(Params, ClientInfo) ->
replvar(Params, ClientInfo, []).