Compare commits
1 Commits
master
...
chore/rena
Author | SHA1 | Date |
---|---|---|
![]() |
28853c3a02 |
|
@ -1,7 +1,7 @@
|
||||||
authorization {
|
authorization {
|
||||||
sources = [
|
sources = [
|
||||||
# {
|
# {
|
||||||
# type: http
|
# type: http-server
|
||||||
# url: "https://emqx.com"
|
# url: "https://emqx.com"
|
||||||
# headers: {
|
# headers: {
|
||||||
# Accept: "application/json"
|
# Accept: "application/json"
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
-export([post_config_update/4, pre_config_update/2]).
|
-export([post_config_update/4, pre_config_update/2]).
|
||||||
|
|
||||||
-define(CONF_KEY_PATH, [authorization, sources]).
|
-define(CONF_KEY_PATH, [authorization, sources]).
|
||||||
-define(SOURCE_TYPES, [file, http, mongo, mysql, postgresql, redis]).
|
-define(SOURCE_TYPES, [file, 'http-server', mongo, mysql, postgresql, redis]).
|
||||||
|
|
||||||
-spec(register_metrics() -> ok).
|
-spec(register_metrics() -> ok).
|
||||||
register_metrics() ->
|
register_metrics() ->
|
||||||
|
@ -289,7 +289,7 @@ init_source(#{enable := true,
|
||||||
end,
|
end,
|
||||||
Source#{annotations => #{rules => Rules}};
|
Source#{annotations => #{rules => Rules}};
|
||||||
init_source(#{enable := true,
|
init_source(#{enable := true,
|
||||||
type := http,
|
type := 'http-server',
|
||||||
url := Url
|
url := Url
|
||||||
} = Source) ->
|
} = Source) ->
|
||||||
NSource= maps:put(base_url, maps:remove(query, Url), Source),
|
NSource= maps:put(base_url, maps:remove(query, Url), Source),
|
||||||
|
@ -387,6 +387,8 @@ find_action_in_hooks() ->
|
||||||
[Action] = [Action || {callback,{?MODULE, authorize, _} = Action, _, _} <- Callbacks ],
|
[Action] = [Action || {callback,{?MODULE, authorize, _} = Action, _, _} <- Callbacks ],
|
||||||
Action.
|
Action.
|
||||||
|
|
||||||
|
gen_id('http-server') ->
|
||||||
|
gen_id(http);
|
||||||
gen_id(Type) ->
|
gen_id(Type) ->
|
||||||
iolist_to_binary([io_lib:format("~s_~s",[?APP, Type])]).
|
iolist_to_binary([io_lib:format("~s_~s",[?APP, Type])]).
|
||||||
|
|
||||||
|
@ -404,9 +406,13 @@ create_resource(#{type := DB} = Source) ->
|
||||||
{error, Reason} -> {error, Reason}
|
{error, Reason} -> {error, Reason}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
authz_module('http-server') ->
|
||||||
|
authz_module(http);
|
||||||
authz_module(Type) ->
|
authz_module(Type) ->
|
||||||
list_to_existing_atom("emqx_authz_" ++ atom_to_list(Type)).
|
list_to_existing_atom("emqx_authz_" ++ atom_to_list(Type)).
|
||||||
|
|
||||||
|
connector_module('http-server') ->
|
||||||
|
emqx_connector_http;
|
||||||
connector_module(postgresql) ->
|
connector_module(postgresql) ->
|
||||||
emqx_connector_pgsql;
|
emqx_connector_pgsql;
|
||||||
connector_module(Type) ->
|
connector_module(Type) ->
|
||||||
|
|
|
@ -82,8 +82,8 @@ definitions() ->
|
||||||
properties => #{
|
properties => #{
|
||||||
type => #{
|
type => #{
|
||||||
type => string,
|
type => string,
|
||||||
enum => [<<"http">>],
|
enum => [<<"http-server">>],
|
||||||
example => <<"http">>
|
example => <<"http-server">>
|
||||||
},
|
},
|
||||||
enable => #{
|
enable => #{
|
||||||
type => boolean,
|
type => boolean,
|
||||||
|
|
|
@ -34,7 +34,7 @@ description() ->
|
||||||
"AuthZ with http".
|
"AuthZ with http".
|
||||||
|
|
||||||
authorize(Client, PubSub, Topic,
|
authorize(Client, PubSub, Topic,
|
||||||
#{type := http,
|
#{type := 'http-server',
|
||||||
url := #{path := Path} = Url,
|
url := #{path := Path} = Url,
|
||||||
headers := Headers,
|
headers := Headers,
|
||||||
method := Method,
|
method := Method,
|
||||||
|
|
|
@ -53,7 +53,7 @@ fields(file) ->
|
||||||
}}
|
}}
|
||||||
];
|
];
|
||||||
fields(http_get) ->
|
fields(http_get) ->
|
||||||
[ {type, #{type => http}}
|
[ {type, #{type => 'http-server'}}
|
||||||
, {enable, #{type => boolean(),
|
, {enable, #{type => boolean(),
|
||||||
default => true}}
|
default => true}}
|
||||||
, {url, #{type => url()}}
|
, {url, #{type => url()}}
|
||||||
|
@ -80,7 +80,7 @@ fields(http_get) ->
|
||||||
, {request_timeout, #{type => timeout(), default => 30000 }}
|
, {request_timeout, #{type => timeout(), default => 30000 }}
|
||||||
] ++ proplists:delete(base_url, emqx_connector_http:fields(config));
|
] ++ proplists:delete(base_url, emqx_connector_http:fields(config));
|
||||||
fields(http_post) ->
|
fields(http_post) ->
|
||||||
[ {type, #{type => http}}
|
[ {type, #{type => 'http-server'}}
|
||||||
, {enable, #{type => boolean(),
|
, {enable, #{type => boolean(),
|
||||||
default => true}}
|
default => true}}
|
||||||
, {url, #{type => url()}}
|
, {url, #{type => url()}}
|
||||||
|
|
|
@ -60,7 +60,7 @@ init_per_testcase(_, Config) ->
|
||||||
{ok, _} = emqx_authz:update(replace, []),
|
{ok, _} = emqx_authz:update(replace, []),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
-define(SOURCE1, #{<<"type">> => <<"http">>,
|
-define(SOURCE1, #{<<"type">> => <<"http-server">>,
|
||||||
<<"enable">> => true,
|
<<"enable">> => true,
|
||||||
<<"url">> => <<"https://fake.com:443/">>,
|
<<"url">> => <<"https://fake.com:443/">>,
|
||||||
<<"headers">> => #{},
|
<<"headers">> => #{},
|
||||||
|
@ -127,7 +127,7 @@ t_update_source(_) ->
|
||||||
{ok, _} = emqx_authz:update(tail, [?SOURCE5]),
|
{ok, _} = emqx_authz:update(tail, [?SOURCE5]),
|
||||||
{ok, _} = emqx_authz:update(tail, [?SOURCE6]),
|
{ok, _} = emqx_authz:update(tail, [?SOURCE6]),
|
||||||
|
|
||||||
?assertMatch([ #{type := http, enable := true}
|
?assertMatch([ #{type := 'http-server', enable := true}
|
||||||
, #{type := mongo, enable := true}
|
, #{type := mongo, enable := true}
|
||||||
, #{type := mysql, enable := true}
|
, #{type := mysql, enable := true}
|
||||||
, #{type := postgresql, enable := true}
|
, #{type := postgresql, enable := true}
|
||||||
|
@ -135,14 +135,14 @@ t_update_source(_) ->
|
||||||
, #{type := file, enable := true}
|
, #{type := file, enable := true}
|
||||||
], emqx:get_config([authorization, sources], [])),
|
], emqx:get_config([authorization, sources], [])),
|
||||||
|
|
||||||
{ok, _} = emqx_authz:update({replace_once, http}, ?SOURCE1#{<<"enable">> := false}),
|
{ok, _} = emqx_authz:update({replace_once, 'http-server'}, ?SOURCE1#{<<"enable">> := false}),
|
||||||
{ok, _} = emqx_authz:update({replace_once, mongo}, ?SOURCE2#{<<"enable">> := false}),
|
{ok, _} = emqx_authz:update({replace_once, mongo}, ?SOURCE2#{<<"enable">> := false}),
|
||||||
{ok, _} = emqx_authz:update({replace_once, mysql}, ?SOURCE3#{<<"enable">> := false}),
|
{ok, _} = emqx_authz:update({replace_once, mysql}, ?SOURCE3#{<<"enable">> := false}),
|
||||||
{ok, _} = emqx_authz:update({replace_once, postgresql}, ?SOURCE4#{<<"enable">> := false}),
|
{ok, _} = emqx_authz:update({replace_once, postgresql}, ?SOURCE4#{<<"enable">> := false}),
|
||||||
{ok, _} = emqx_authz:update({replace_once, redis}, ?SOURCE5#{<<"enable">> := false}),
|
{ok, _} = emqx_authz:update({replace_once, redis}, ?SOURCE5#{<<"enable">> := false}),
|
||||||
{ok, _} = emqx_authz:update({replace_once, file}, ?SOURCE6#{<<"enable">> := false}),
|
{ok, _} = emqx_authz:update({replace_once, file}, ?SOURCE6#{<<"enable">> := false}),
|
||||||
|
|
||||||
?assertMatch([ #{type := http, enable := false}
|
?assertMatch([ #{type := 'http-server', enable := false}
|
||||||
, #{type := mongo, enable := false}
|
, #{type := mongo, enable := false}
|
||||||
, #{type := mysql, enable := false}
|
, #{type := mysql, enable := false}
|
||||||
, #{type := postgresql, enable := false}
|
, #{type := postgresql, enable := false}
|
||||||
|
@ -154,7 +154,7 @@ t_update_source(_) ->
|
||||||
|
|
||||||
t_move_source(_) ->
|
t_move_source(_) ->
|
||||||
{ok, _} = emqx_authz:update(replace, [?SOURCE1, ?SOURCE2, ?SOURCE3, ?SOURCE4, ?SOURCE5, ?SOURCE6]),
|
{ok, _} = emqx_authz:update(replace, [?SOURCE1, ?SOURCE2, ?SOURCE3, ?SOURCE4, ?SOURCE5, ?SOURCE6]),
|
||||||
?assertMatch([ #{type := http}
|
?assertMatch([ #{type := 'http-server'}
|
||||||
, #{type := mongo}
|
, #{type := mongo}
|
||||||
, #{type := mysql}
|
, #{type := mysql}
|
||||||
, #{type := postgresql}
|
, #{type := postgresql}
|
||||||
|
@ -164,20 +164,20 @@ t_move_source(_) ->
|
||||||
|
|
||||||
{ok, _} = emqx_authz:move(postgresql, <<"top">>),
|
{ok, _} = emqx_authz:move(postgresql, <<"top">>),
|
||||||
?assertMatch([ #{type := postgresql}
|
?assertMatch([ #{type := postgresql}
|
||||||
, #{type := http}
|
, #{type := 'http-server'}
|
||||||
, #{type := mongo}
|
, #{type := mongo}
|
||||||
, #{type := mysql}
|
, #{type := mysql}
|
||||||
, #{type := redis}
|
, #{type := redis}
|
||||||
, #{type := file}
|
, #{type := file}
|
||||||
], emqx_authz:lookup()),
|
], emqx_authz:lookup()),
|
||||||
|
|
||||||
{ok, _} = emqx_authz:move(http, <<"bottom">>),
|
{ok, _} = emqx_authz:move('http-server', <<"bottom">>),
|
||||||
?assertMatch([ #{type := postgresql}
|
?assertMatch([ #{type := postgresql}
|
||||||
, #{type := mongo}
|
, #{type := mongo}
|
||||||
, #{type := mysql}
|
, #{type := mysql}
|
||||||
, #{type := redis}
|
, #{type := redis}
|
||||||
, #{type := file}
|
, #{type := file}
|
||||||
, #{type := http}
|
, #{type := 'http-server'}
|
||||||
], emqx_authz:lookup()),
|
], emqx_authz:lookup()),
|
||||||
|
|
||||||
{ok, _} = emqx_authz:move(mysql, #{<<"before">> => postgresql}),
|
{ok, _} = emqx_authz:move(mysql, #{<<"before">> => postgresql}),
|
||||||
|
@ -186,15 +186,15 @@ t_move_source(_) ->
|
||||||
, #{type := mongo}
|
, #{type := mongo}
|
||||||
, #{type := redis}
|
, #{type := redis}
|
||||||
, #{type := file}
|
, #{type := file}
|
||||||
, #{type := http}
|
, #{type := 'http-server'}
|
||||||
], emqx_authz:lookup()),
|
], emqx_authz:lookup()),
|
||||||
|
|
||||||
{ok, _} = emqx_authz:move(mongo, #{<<"after">> => http}),
|
{ok, _} = emqx_authz:move(mongo, #{<<"after">> => 'http-server'}),
|
||||||
?assertMatch([ #{type := mysql}
|
?assertMatch([ #{type := mysql}
|
||||||
, #{type := postgresql}
|
, #{type := postgresql}
|
||||||
, #{type := redis}
|
, #{type := redis}
|
||||||
, #{type := file}
|
, #{type := file}
|
||||||
, #{type := http}
|
, #{type := 'http-server'}
|
||||||
, #{type := mongo}
|
, #{type := mongo}
|
||||||
], emqx_authz:lookup()),
|
], emqx_authz:lookup()),
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
-define(API_VERSION, "v5").
|
-define(API_VERSION, "v5").
|
||||||
-define(BASE_PATH, "api").
|
-define(BASE_PATH, "api").
|
||||||
|
|
||||||
-define(SOURCE1, #{<<"type">> => <<"http">>,
|
-define(SOURCE1, #{<<"type">> => <<"http-server">>,
|
||||||
<<"enable">> => true,
|
<<"enable">> => true,
|
||||||
<<"url">> => <<"https://fake.com:443/">>,
|
<<"url">> => <<"https://fake.com:443/">>,
|
||||||
<<"headers">> => #{},
|
<<"headers">> => #{},
|
||||||
|
@ -180,7 +180,7 @@ t_api(_) ->
|
||||||
|
|
||||||
{ok, 200, Result2} = request(get, uri(["authorization", "sources"]), []),
|
{ok, 200, Result2} = request(get, uri(["authorization", "sources"]), []),
|
||||||
Sources = get_sources(Result2),
|
Sources = get_sources(Result2),
|
||||||
?assertMatch([ #{<<"type">> := <<"http">>}
|
?assertMatch([ #{<<"type">> := <<"http-server">>}
|
||||||
, #{<<"type">> := <<"mongo">>}
|
, #{<<"type">> := <<"mongo">>}
|
||||||
, #{<<"type">> := <<"mysql">>}
|
, #{<<"type">> := <<"mysql">>}
|
||||||
, #{<<"type">> := <<"postgresql">>}
|
, #{<<"type">> := <<"postgresql">>}
|
||||||
|
@ -189,9 +189,9 @@ t_api(_) ->
|
||||||
], Sources),
|
], Sources),
|
||||||
?assert(filelib:is_file(filename:join([emqx:get_config([node, data_dir]), "acl.conf"]))),
|
?assert(filelib:is_file(filename:join([emqx:get_config([node, data_dir]), "acl.conf"]))),
|
||||||
|
|
||||||
{ok, 204, _} = request(put, uri(["authorization", "sources", "http"]), ?SOURCE1#{<<"enable">> := false}),
|
{ok, 204, _} = request(put, uri(["authorization", "sources", "http-server"]), ?SOURCE1#{<<"enable">> := false}),
|
||||||
{ok, 200, Result3} = request(get, uri(["authorization", "sources", "http"]), []),
|
{ok, 200, Result3} = request(get, uri(["authorization", "sources", "http-server"]), []),
|
||||||
?assertMatch(#{<<"type">> := <<"http">>, <<"enable">> := false}, jsx:decode(Result3)),
|
?assertMatch(#{<<"type">> := <<"http-server">>, <<"enable">> := false}, jsx:decode(Result3)),
|
||||||
|
|
||||||
{ok, 204, _} = request(put, uri(["authorization", "sources", "mongo"]),
|
{ok, 204, _} = request(put, uri(["authorization", "sources", "mongo"]),
|
||||||
?SOURCE2#{<<"ssl">> := #{
|
?SOURCE2#{<<"ssl">> := #{
|
||||||
|
@ -224,7 +224,7 @@ t_api(_) ->
|
||||||
|
|
||||||
t_move_source(_) ->
|
t_move_source(_) ->
|
||||||
{ok, _} = emqx_authz:update(replace, [?SOURCE1, ?SOURCE2, ?SOURCE3, ?SOURCE4, ?SOURCE5]),
|
{ok, _} = emqx_authz:update(replace, [?SOURCE1, ?SOURCE2, ?SOURCE3, ?SOURCE4, ?SOURCE5]),
|
||||||
?assertMatch([ #{type := http}
|
?assertMatch([ #{type := 'http-server'}
|
||||||
, #{type := mongo}
|
, #{type := mongo}
|
||||||
, #{type := mysql}
|
, #{type := mysql}
|
||||||
, #{type := postgresql}
|
, #{type := postgresql}
|
||||||
|
@ -234,19 +234,19 @@ t_move_source(_) ->
|
||||||
{ok, 204, _} = request(post, uri(["authorization", "sources", "postgresql", "move"]),
|
{ok, 204, _} = request(post, uri(["authorization", "sources", "postgresql", "move"]),
|
||||||
#{<<"position">> => <<"top">>}),
|
#{<<"position">> => <<"top">>}),
|
||||||
?assertMatch([ #{type := postgresql}
|
?assertMatch([ #{type := postgresql}
|
||||||
, #{type := http}
|
, #{type := 'http-server'}
|
||||||
, #{type := mongo}
|
, #{type := mongo}
|
||||||
, #{type := mysql}
|
, #{type := mysql}
|
||||||
, #{type := redis}
|
, #{type := redis}
|
||||||
], emqx_authz:lookup()),
|
], emqx_authz:lookup()),
|
||||||
|
|
||||||
{ok, 204, _} = request(post, uri(["authorization", "sources", "http", "move"]),
|
{ok, 204, _} = request(post, uri(["authorization", "sources", "http-server", "move"]),
|
||||||
#{<<"position">> => <<"bottom">>}),
|
#{<<"position">> => <<"bottom">>}),
|
||||||
?assertMatch([ #{type := postgresql}
|
?assertMatch([ #{type := postgresql}
|
||||||
, #{type := mongo}
|
, #{type := mongo}
|
||||||
, #{type := mysql}
|
, #{type := mysql}
|
||||||
, #{type := redis}
|
, #{type := redis}
|
||||||
, #{type := http}
|
, #{type := 'http-server'}
|
||||||
], emqx_authz:lookup()),
|
], emqx_authz:lookup()),
|
||||||
|
|
||||||
{ok, 204, _} = request(post, uri(["authorization", "sources", "mysql", "move"]),
|
{ok, 204, _} = request(post, uri(["authorization", "sources", "mysql", "move"]),
|
||||||
|
@ -255,15 +255,15 @@ t_move_source(_) ->
|
||||||
, #{type := postgresql}
|
, #{type := postgresql}
|
||||||
, #{type := mongo}
|
, #{type := mongo}
|
||||||
, #{type := redis}
|
, #{type := redis}
|
||||||
, #{type := http}
|
, #{type := 'http-server'}
|
||||||
], emqx_authz:lookup()),
|
], emqx_authz:lookup()),
|
||||||
|
|
||||||
{ok, 204, _} = request(post, uri(["authorization", "sources", "mongo", "move"]),
|
{ok, 204, _} = request(post, uri(["authorization", "sources", "mongo", "move"]),
|
||||||
#{<<"position">> => #{<<"after">> => <<"http">>}}),
|
#{<<"position">> => #{<<"after">> => <<"http-server">>}}),
|
||||||
?assertMatch([ #{type := mysql}
|
?assertMatch([ #{type := mysql}
|
||||||
, #{type := postgresql}
|
, #{type := postgresql}
|
||||||
, #{type := redis}
|
, #{type := redis}
|
||||||
, #{type := http}
|
, #{type := 'http-server'}
|
||||||
, #{type := mongo}
|
, #{type := mongo}
|
||||||
], emqx_authz:lookup()),
|
], emqx_authz:lookup()),
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ init_per_suite(Config) ->
|
||||||
|
|
||||||
{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),
|
||||||
Rules = [#{<<"type">> => <<"http">>,
|
Rules = [#{<<"type">> => <<"http-server">>,
|
||||||
<<"url">> => <<"https://fake.com:443/">>,
|
<<"url">> => <<"https://fake.com:443/">>,
|
||||||
<<"headers">> => #{},
|
<<"headers">> => #{},
|
||||||
<<"method">> => <<"get">>,
|
<<"method">> => <<"get">>,
|
||||||
|
|
Loading…
Reference in New Issue