chore(emqx authz): rename root name for authz conf

Signed-off-by: zhanghongtong <rory-z@outlook.com>
This commit is contained in:
zhanghongtong 2021-07-29 15:41:46 +08:00 committed by Rory Z
parent 4ef00072b9
commit 4c6739161d
13 changed files with 45 additions and 37 deletions

View File

@ -244,7 +244,7 @@ fields("auth") ->
[ {"enable", t(boolean(), undefined, false)} [ {"enable", t(boolean(), undefined, false)}
]; ];
fields("authorization") -> fields("authorization_settings") ->
[ {"enable", t(boolean(), undefined, true)} [ {"enable", t(boolean(), undefined, true)}
, {"cache", ref("authorization_cache")} , {"cache", ref("authorization_cache")}
, {"deny_action", t(union(ignore, disconnect), undefined, ignore)} , {"deny_action", t(union(ignore, disconnect), undefined, ignore)}
@ -293,7 +293,7 @@ fields("zones") ->
fields("zone_settings") -> fields("zone_settings") ->
[ {"mqtt", ref("mqtt")} [ {"mqtt", ref("mqtt")}
, {"authorization", ref("authorization")} , {"authorization", ref("authorization_settings")}
, {"auth", ref("auth")} , {"auth", ref("auth")}
, {"stats", ref("stats")} , {"stats", ref("stats")}
, {"flapping_detect", ref("flapping_detect")} , {"flapping_detect", ref("flapping_detect")}

View File

@ -1,4 +1,4 @@
emqx_authz:{ authorization:{
rules: [ rules: [
# { # {
# type: http # type: http

View File

@ -33,7 +33,7 @@
-export([post_config_update/2, pre_config_update/2]). -export([post_config_update/2, pre_config_update/2]).
-define(CONF_KEY_PATH, [emqx_authz, rules]). -define(CONF_KEY_PATH, [authorization, rules]).
-spec(register_metrics() -> ok). -spec(register_metrics() -> ok).
register_metrics() -> register_metrics() ->

View File

@ -47,8 +47,8 @@ parse_query(Sql) ->
authorize(Client, PubSub, Topic, authorize(Client, PubSub, Topic,
#{annotations := #{id := ResourceID, #{annotations := #{id := ResourceID,
sql := {SQL, Params} sql := {SQL, Params}
} }
}) -> }) ->
case emqx_resource:query(ResourceID, {sql, SQL, replvar(Params, Client)}) of case emqx_resource:query(ResourceID, {sql, SQL, replvar(Params, Client)}) of
{ok, _Columns, []} -> nomatch; {ok, _Columns, []} -> nomatch;

View File

@ -51,8 +51,8 @@ parse_query(Sql) ->
authorize(Client, PubSub, Topic, authorize(Client, PubSub, Topic,
#{annotations := #{id := ResourceID, #{annotations := #{id := ResourceID,
sql := {SQL, Params} sql := {SQL, Params}
} }
}) -> }) ->
case emqx_resource:query(ResourceID, {sql, SQL, replvar(Params, Client)}) of case emqx_resource:query(ResourceID, {sql, SQL, replvar(Params, Client)}) of
{ok, _Columns, []} -> nomatch; {ok, _Columns, []} -> nomatch;

View File

@ -17,9 +17,9 @@
, fields/1 , fields/1
]). ]).
structs() -> ["emqx_authz"]. structs() -> ["authorization"].
fields("emqx_authz") -> fields("authorization") ->
[ {rules, rules()} [ {rules, rules()}
]; ];
fields(http) -> fields(http) ->

View File

@ -43,12 +43,12 @@ groups() ->
[]. [].
init_per_suite(Config) -> init_per_suite(Config) ->
ok = emqx_ct_helpers:start_apps([emqx_authz]),
%% important! let emqx_schema include the current app! %% important! let emqx_schema include the current app!
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]), meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_schema, includes, fun() -> ["emqx_authz"] end ), meck:expect(emqx_schema, includes, fun() -> ["authorization"] end ),
meck:expect(emqx_schema, extra_schema_fields, fun(FieldName) -> emqx_authz_schema:fields(FieldName) end), meck:expect(emqx_schema, extra_schema_fields, fun(FieldName) -> emqx_authz_schema:fields(FieldName) end),
ok = emqx_ct_helpers:start_apps([emqx_authz]),
%create_default_app(), %create_default_app(),
Config. Config.
@ -92,7 +92,7 @@ t_api_unit_test(_Config) ->
principal := principal :=
#{'and' := [#{username := <<"^test?">>}, #{'and' := [#{username := <<"^test?">>},
#{clientid := <<"^test?">>}]}, #{clientid := <<"^test?">>}]},
topics := [<<"%u">>]}] = emqx_config:get([emqx_authz, rules]). topics := [<<"%u">>]}] = emqx_config:get([authorization, rules]).
% t_api(_Config) -> % t_api(_Config) ->
% Rule1 = #{<<"principal">> => % Rule1 = #{<<"principal">> =>

View File

@ -29,14 +29,16 @@ groups() ->
[]. [].
init_per_suite(Config) -> init_per_suite(Config) ->
%% important! let emqx_schema include the current app! ok = emqx_ct_helpers:start_apps([emqx_authz]),
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_schema, includes, fun() -> ["emqx_authz"] end ),
meck:expect(emqx_schema, extra_schema_fields, fun(FieldName) -> emqx_authz_schema:fields(FieldName) end),
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]), meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ),
ok = emqx_ct_helpers:start_apps([emqx_authz]),
%% important! let emqx_schema include the current app!
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_schema, includes, fun() -> ["authorization"] end ),
meck:expect(emqx_schema, extra_schema_fields, fun(FieldName) -> emqx_authz_schema:fields(FieldName) end),
ok = emqx_config:update([zones, default, authorization, cache, enable], false), ok = emqx_config:update([zones, default, authorization, cache, enable], false),
ok = emqx_config:update([zones, default, authorization, enable], true), ok = emqx_config:update([zones, default, authorization, enable], true),
Rules = [#{ <<"config">> => #{ Rules = [#{ <<"config">> => #{

View File

@ -29,16 +29,16 @@ groups() ->
[]. [].
init_per_suite(Config) -> init_per_suite(Config) ->
ok = emqx_ct_helpers:start_apps([emqx_authz]),
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]), meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ),
%% important! let emqx_schema include the current app! %% important! let emqx_schema include the current app!
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]), meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_schema, includes, fun() -> ["emqx_authz"] end ), meck:expect(emqx_schema, includes, fun() -> ["authorization"] end ),
meck:expect(emqx_schema, extra_schema_fields, fun(FieldName) -> emqx_authz_schema:fields(FieldName) end), meck:expect(emqx_schema, extra_schema_fields, fun(FieldName) -> emqx_authz_schema:fields(FieldName) end),
ok = emqx_ct_helpers:start_apps([emqx_authz]),
ct:pal("---- emqx_hooks: ~p", [ets:tab2list(emqx_hooks)]),
ok = emqx_config:update([zones, default, authorization, cache, enable], false), ok = emqx_config:update([zones, default, authorization, cache, enable], false),
ok = emqx_config:update([zones, default, authorization, enable], true), ok = emqx_config:update([zones, default, authorization, enable], true),
Rules = [#{ <<"config">> => #{ Rules = [#{ <<"config">> => #{

View File

@ -29,14 +29,16 @@ groups() ->
[]. [].
init_per_suite(Config) -> init_per_suite(Config) ->
%% important! let emqx_schema include the current app! ok = emqx_ct_helpers:start_apps([emqx_authz]),
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_schema, includes, fun() -> ["emqx_authz"] end ),
meck:expect(emqx_schema, extra_schema_fields, fun(FieldName) -> emqx_authz_schema:fields(FieldName) end),
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]), meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ),
ok = emqx_ct_helpers:start_apps([emqx_authz]),
%% important! let emqx_schema include the current app!
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_schema, includes, fun() -> ["authorization"] end ),
meck:expect(emqx_schema, extra_schema_fields, fun(FieldName) -> emqx_authz_schema:fields(FieldName) end),
ok = emqx_config:update([zones, default, authorization, cache, enable], false), ok = emqx_config:update([zones, default, authorization, cache, enable], false),
ok = emqx_config:update([zones, default, authorization, enable], true), ok = emqx_config:update([zones, default, authorization, enable], true),
Rules = [#{ <<"config">> => #{ Rules = [#{ <<"config">> => #{

View File

@ -29,14 +29,16 @@ groups() ->
[]. [].
init_per_suite(Config) -> init_per_suite(Config) ->
%% important! let emqx_schema include the current app! ok = emqx_ct_helpers:start_apps([emqx_authz]),
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_schema, includes, fun() -> ["emqx_authz"] end ),
meck:expect(emqx_schema, extra_schema_fields, fun(FieldName) -> emqx_authz_schema:fields(FieldName) end),
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]), meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ),
ok = emqx_ct_helpers:start_apps([emqx_authz]),
%% important! let emqx_schema include the current app!
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_schema, includes, fun() -> ["authorization"] end ),
meck:expect(emqx_schema, extra_schema_fields, fun(FieldName) -> emqx_authz_schema:fields(FieldName) end),
ok = emqx_config:update([zones, default, authorization, cache, enable], false), ok = emqx_config:update([zones, default, authorization, cache, enable], false),
ok = emqx_config:update([zones, default, authorization, enable], true), ok = emqx_config:update([zones, default, authorization, enable], true),
Rules = [#{ <<"config">> => #{ Rules = [#{ <<"config">> => #{

View File

@ -29,14 +29,16 @@ groups() ->
[]. [].
init_per_suite(Config) -> init_per_suite(Config) ->
%% important! let emqx_schema include the current app! ok = emqx_ct_helpers:start_apps([emqx_authz]),
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_schema, includes, fun() -> ["emqx_authz"] end ),
meck:expect(emqx_schema, extra_schema_fields, fun(FieldName) -> emqx_authz_schema:fields(FieldName) end),
meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]), meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ),
ok = emqx_ct_helpers:start_apps([emqx_authz]),
%% important! let emqx_schema include the current app!
meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]),
meck:expect(emqx_schema, includes, fun() -> ["authorization"] end ),
meck:expect(emqx_schema, extra_schema_fields, fun(FieldName) -> emqx_authz_schema:fields(FieldName) end),
ok = emqx_config:update([zones, default, authorization, cache, enable], false), ok = emqx_config:update([zones, default, authorization, cache, enable], false),
ok = emqx_config:update([zones, default, authorization, enable], true), ok = emqx_config:update([zones, default, authorization, enable], true),
Rules = [#{ <<"config">> => #{ Rules = [#{ <<"config">> => #{

View File

@ -6,7 +6,7 @@
[ {"emqx_data_bridge", emqx_data_bridge_schema} [ {"emqx_data_bridge", emqx_data_bridge_schema}
, {"emqx_retainer", emqx_retainer_schema} , {"emqx_retainer", emqx_retainer_schema}
, {"emqx_authn", emqx_authn_schema} , {"emqx_authn", emqx_authn_schema}
, {"emqx_authz", emqx_authz_schema} , {"authorization", emqx_authz_schema}
, {"emqx_bridge_mqtt", emqx_bridge_mqtt_schema} , {"emqx_bridge_mqtt", emqx_bridge_mqtt_schema}
, {"emqx_modules", emqx_modules_schema} , {"emqx_modules", emqx_modules_schema}
, {"emqx_management", emqx_management_schema} , {"emqx_management", emqx_management_schema}