chore(emqx_authz): use new config path

This commit is contained in:
zhanghongtong 2021-08-26 14:30:34 +08:00 committed by Rory Z
parent 6f8c87001f
commit f2e29184de
8 changed files with 14 additions and 14 deletions

View File

@ -36,7 +36,7 @@
-export([post_config_update/4, pre_config_update/2]). -export([post_config_update/4, pre_config_update/2]).
-define(CONF_KEY_PATH, [authorization_rules, rules]). -define(CONF_KEY_PATH, [authorization, rules]).
-spec(register_metrics() -> ok). -spec(register_metrics() -> ok).
register_metrics() -> register_metrics() ->
@ -185,9 +185,9 @@ post_config_update(_, NewRules, _OldConf, _AppEnvs) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
check_rules(RawRules) -> check_rules(RawRules) ->
{ok, Conf} = hocon:binary(jsx:encode(#{<<"authorization_rules">> => #{<<"rules">> => RawRules}}), #{format => richmap}), {ok, Conf} = hocon:binary(jsx:encode(#{<<"authorization">> => #{<<"rules">> => RawRules}}), #{format => richmap}),
CheckConf = hocon_schema:check(emqx_authz_schema, Conf, #{atom_key => true}), CheckConf = hocon_schema:check(emqx_authz_schema, Conf, #{atom_key => true}),
#{authorization_rules := #{rules := Rules}} = hocon_schema:richmap_to_map(CheckConf), #{authorization:= #{rules := Rules}} = hocon_schema:richmap_to_map(CheckConf),
Rules. Rules.
find_rule_by_id(Id) -> find_rule_by_id(Id, lookup()). find_rule_by_id(Id) -> find_rule_by_id(Id, lookup()).

View File

@ -22,7 +22,7 @@
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-define(CONF_DEFAULT, <<"authorization_rules: {rules: []}">>). -define(CONF_DEFAULT, <<"authorization: {rules: []}">>).
all() -> all() ->
emqx_ct:all(?MODULE). emqx_ct:all(?MODULE).
@ -37,7 +37,7 @@ init_per_suite(Config) ->
meck:expect(emqx_resource, remove, fun(_) -> ok end ), meck:expect(emqx_resource, remove, fun(_) -> ok end ),
ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT), ok = emqx_config:init_load(emqx_authz_schema, ?CONF_DEFAULT),
ok = emqx_ct_helpers:start_apps([emqx_authz]), ok = emqx_ct_helpers:start_apps([emqx_machine, emqx_authz]),
{ok, _} = emqx:update_config([authorization, cache, enable], false), {ok, _} = emqx:update_config([authorization, cache, enable], false),
{ok, _} = emqx:update_config([authorization, no_match], deny), {ok, _} = emqx:update_config([authorization, no_match], deny),
Config. Config.
@ -111,7 +111,7 @@ t_update_rule(_) ->
{ok, _} = emqx_authz:update(head, [?RULE1]), {ok, _} = emqx_authz:update(head, [?RULE1]),
{ok, _} = emqx_authz:update(tail, [?RULE3]), {ok, _} = emqx_authz:update(tail, [?RULE3]),
?assertMatch([#{type := http}, #{type := mongo}, #{type := mysql}], emqx:get_config([authorization_rules, rules], [])), ?assertMatch([#{type := http}, #{type := mongo}, #{type := mysql}], emqx:get_config([authorization, rules], [])),
[#{annotations := #{id := Id1}, type := http}, [#{annotations := #{id := Id1}, type := http},
#{annotations := #{id := Id2}, type := mongo}, #{annotations := #{id := Id2}, type := mongo},
@ -120,7 +120,7 @@ t_update_rule(_) ->
{ok, _} = emqx_authz:update({replace_once, Id1}, ?RULE5), {ok, _} = emqx_authz:update({replace_once, Id1}, ?RULE5),
{ok, _} = emqx_authz:update({replace_once, Id3}, ?RULE4), {ok, _} = emqx_authz:update({replace_once, Id3}, ?RULE4),
?assertMatch([#{type := redis}, #{type := mongo}, #{type := pgsql}], emqx:get_config([authorization_rules, rules], [])), ?assertMatch([#{type := redis}, #{type := mongo}, #{type := pgsql}], emqx:get_config([authorization, rules], [])),
[#{annotations := #{id := Id1}, type := redis}, [#{annotations := #{id := Id1}, type := redis},
#{annotations := #{id := Id2}, type := mongo}, #{annotations := #{id := Id2}, type := mongo},

View File

@ -22,7 +22,7 @@
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-define(CONF_DEFAULT, <<"authorization_rules: {rules: []}">>). -define(CONF_DEFAULT, <<"authorization: {rules: []}">>).
-import(emqx_ct_http, [ request_api/3 -import(emqx_ct_http, [ request_api/3
, request_api/5 , request_api/5
@ -126,7 +126,7 @@ set_special_configs(emqx_dashboard) ->
emqx_config:put([emqx_dashboard], Config), emqx_config:put([emqx_dashboard], Config),
ok; ok;
set_special_configs(emqx_authz) -> set_special_configs(emqx_authz) ->
emqx_config:put([authorization_rules], #{rules => []}), emqx_config:put([authorization], #{rules => []}),
ok; ok;
set_special_configs(_App) -> set_special_configs(_App) ->
ok. ok.

View File

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

View File

@ -22,7 +22,7 @@
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-define(CONF_DEFAULT, <<"authorization_rules: {rules: []}">>). -define(CONF_DEFAULT, <<"authorization: {rules: []}">>).
all() -> all() ->
emqx_ct:all(?MODULE). emqx_ct:all(?MODULE).

View File

@ -22,7 +22,7 @@
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-define(CONF_DEFAULT, <<"authorization_rules: {rules: []}">>). -define(CONF_DEFAULT, <<"authorization: {rules: []}">>).
all() -> all() ->
emqx_ct:all(?MODULE). emqx_ct:all(?MODULE).

View File

@ -22,7 +22,7 @@
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-define(CONF_DEFAULT, <<"authorization_rules: {rules: []}">>). -define(CONF_DEFAULT, <<"authorization: {rules: []}">>).
all() -> all() ->
emqx_ct:all(?MODULE). emqx_ct:all(?MODULE).

View File

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