feat(authz connector): match directly using the results returned by sql
Signed-off-by: zhanghongtong <rory-z@outlook.com>
This commit is contained in:
parent
088e615818
commit
3195561a79
|
@ -60,8 +60,7 @@ match(Client, PubSub, Topic,
|
|||
<<"permission">> := Permission,
|
||||
<<"action">> := Action
|
||||
}) ->
|
||||
Rule = #{<<"principal">> => all,
|
||||
<<"permission">> => Permission,
|
||||
Rule = #{<<"permission">> => Permission,
|
||||
<<"topics">> => Topics,
|
||||
<<"action">> => Action
|
||||
},
|
||||
|
|
|
@ -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, []).
|
||||
|
||||
|
|
|
@ -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, []).
|
||||
|
||||
|
|
Loading…
Reference in New Issue