diff --git a/apps/emqx_authz/src/emqx_authz.erl b/apps/emqx_authz/src/emqx_authz.erl index 889fd6a21..286d8f472 100644 --- a/apps/emqx_authz/src/emqx_authz.erl +++ b/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}) -> diff --git a/apps/emqx_authz/src/emqx_authz_schema.erl b/apps/emqx_authz/src/emqx_authz_schema.erl index 1f9831232..94b7ce158 100644 --- a/apps/emqx_authz/src/emqx_authz_schema.erl +++ b/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("").