Ver código fonte

feat(authz): add enable config for connectot in config file

Signed-off-by: zhanghongtong <rory-z@outlook.com>
zhanghongtong 4 anos atrás
pai
commit
c1cbd8ece4

+ 8 - 1
apps/emqx_authz/src/emqx_authz.erl

@@ -116,6 +116,7 @@ init_rule(#{topics := Topics,
          };
 
 init_rule(#{principal := Principal,
+            enable := true,
             type := http,
             config := #{url := Url} = Config
            } = Rule) ->
@@ -124,6 +125,7 @@ init_rule(#{principal := Principal,
     NRule#{principal => compile_principal(Principal)};
 
 init_rule(#{principal := Principal,
+            enable := true,
             type := DB
          } = Rule) when DB =:= redis;
                         DB =:= mongo ->
@@ -131,6 +133,7 @@ init_rule(#{principal := Principal,
     NRule#{principal => compile_principal(Principal)};
 
 init_rule(#{principal := Principal,
+            enable := true,
             type := DB,
             sql := SQL
          } = Rule) when DB =:= mysql;
@@ -139,7 +142,11 @@ init_rule(#{principal := Principal,
     NRule = create_resource(Rule),
     NRule#{principal => compile_principal(Principal),
            sql => Mod:parse_query(SQL)
-          }.
+          };
+init_rule(#{enable := false,
+            type := _DB
+         } = Rule) ->
+    Rule.
 
 compile_principal(all) -> all;
 compile_principal(#{username := Username}) ->

+ 4 - 0
apps/emqx_authz/src/emqx_authz_schema.erl

@@ -25,6 +25,8 @@ fields("emqx_authz") ->
 fields(http) ->
     [ {principal, principal()}
     , {type, #{type => http}}
+    , {enable, #{type => boolean(),
+                 default => true}}
     , {config, #{type => hoconsc:union([ hoconsc:ref(?MODULE, http_get)
                                        , hoconsc:ref(?MODULE, http_post)
                                        ])}
@@ -188,4 +190,6 @@ connector_fields(DB) ->
           end,
     [ {principal, principal()}
     , {type, #{type => DB}}
+    , {enable, #{type => boolean(),
+                 default => true}}
     ] ++ Mod:fields("").