Merge pull request #6645 from zhongwencool/fix-authz-reboot-headers-atom
fix: make sure authz headers is binary.
This commit is contained in:
commit
adca9e6f22
|
@ -17,7 +17,7 @@
|
||||||
, {esockd, {git, "https://github.com/emqx/esockd", {tag, "5.9.0"}}}
|
, {esockd, {git, "https://github.com/emqx/esockd", {tag, "5.9.0"}}}
|
||||||
, {ekka, {git, "https://github.com/emqx/ekka", {tag, "0.11.1"}}}
|
, {ekka, {git, "https://github.com/emqx/ekka", {tag, "0.11.1"}}}
|
||||||
, {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "2.5.1"}}}
|
, {gen_rpc, {git, "https://github.com/emqx/gen_rpc", {tag, "2.5.1"}}}
|
||||||
, {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.22.1"}}}
|
, {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.22.3"}}}
|
||||||
, {pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {tag, "2.0.4"}}}
|
, {pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {tag, "2.0.4"}}}
|
||||||
, {recon, {git, "https://github.com/ferd/recon", {tag, "2.5.1"}}}
|
, {recon, {git, "https://github.com/ferd/recon", {tag, "2.5.1"}}}
|
||||||
, {snabbkaffe, {git, "https://github.com/kafka4beam/snabbkaffe.git", {tag, "0.16.0"}}}
|
, {snabbkaffe, {git, "https://github.com/kafka4beam/snabbkaffe.git", {tag, "0.16.0"}}}
|
||||||
|
|
|
@ -124,14 +124,14 @@ generate_request( PubSub
|
||||||
case Method of
|
case Method of
|
||||||
get ->
|
get ->
|
||||||
NPath = append_query(Path, NBaseQuery ++ Body),
|
NPath = append_query(Path, NBaseQuery ++ Body),
|
||||||
{NPath, maps:to_list(Headers)};
|
{NPath, Headers};
|
||||||
_ ->
|
_ ->
|
||||||
NPath = append_query(Path, NBaseQuery),
|
NPath = append_query(Path, NBaseQuery),
|
||||||
NBody = serialize_body(
|
NBody = serialize_body(
|
||||||
maps:get(<<"Accept">>, Headers, <<"application/json">>),
|
maps:get(<<"Accept">>, Headers, <<"application/json">>),
|
||||||
Body
|
Body
|
||||||
),
|
),
|
||||||
{NPath, maps:to_list(Headers), NBody}
|
{NPath, Headers, NBody}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
append_query(Path, []) ->
|
append_query(Path, []) ->
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-import(emqx_schema, [mk_duration/2]).
|
-import(emqx_schema, [mk_duration/2]).
|
||||||
|
-include_lib("hocon/include/hoconsc.hrl").
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Hocon Schema
|
%% Hocon Schema
|
||||||
|
@ -158,20 +159,20 @@ validations() ->
|
||||||
, {check_headers, fun check_headers/1}
|
, {check_headers, fun check_headers/1}
|
||||||
].
|
].
|
||||||
|
|
||||||
headers(type) -> map();
|
headers(type) -> list({binary(), binary()});
|
||||||
headers(converter) ->
|
headers(converter) ->
|
||||||
fun(Headers) ->
|
fun(Headers) ->
|
||||||
maps:merge(default_headers(), transform_header_name(Headers))
|
maps:to_list(maps:merge(default_headers(), transform_header_name(Headers)))
|
||||||
end;
|
end;
|
||||||
headers(default) -> default_headers();
|
headers(default) -> maps:to_list(default_headers());
|
||||||
headers(_) -> undefined.
|
headers(_) -> undefined.
|
||||||
|
|
||||||
headers_no_content_type(type) -> map();
|
headers_no_content_type(type) -> list({binary(), binary()});
|
||||||
headers_no_content_type(converter) ->
|
headers_no_content_type(converter) ->
|
||||||
fun(Headers) ->
|
fun(Headers) ->
|
||||||
maps:merge(default_headers_no_content_type(), transform_header_name(Headers))
|
maps:to_list(maps:merge(default_headers_no_content_type(), transform_header_name(Headers)))
|
||||||
end;
|
end;
|
||||||
headers_no_content_type(default) -> default_headers_no_content_type();
|
headers_no_content_type(default) -> maps:to_list(default_headers_no_content_type());
|
||||||
headers_no_content_type(_) -> undefined.
|
headers_no_content_type(_) -> undefined.
|
||||||
|
|
||||||
url(type) -> binary();
|
url(type) -> binary();
|
||||||
|
@ -221,7 +222,7 @@ check_headers(Conf)
|
||||||
check_headers(Conf) ->
|
check_headers(Conf) ->
|
||||||
Method = to_bin(hocon_schema:get_value("config.method", Conf)),
|
Method = to_bin(hocon_schema:get_value("config.method", Conf)),
|
||||||
Headers = hocon_schema:get_value("config.headers", Conf),
|
Headers = hocon_schema:get_value("config.headers", Conf),
|
||||||
Method =:= <<"post">> orelse (not maps:is_key(<<"content-type">>, Headers)).
|
Method =:= <<"post">> orelse (not lists:member(<<"content-type">>, Headers)).
|
||||||
|
|
||||||
union_array(Item) when is_list(Item) ->
|
union_array(Item) when is_list(Item) ->
|
||||||
hoconsc:array(hoconsc:union(Item)).
|
hoconsc:array(hoconsc:union(Item)).
|
||||||
|
|
|
@ -262,11 +262,20 @@ preprocess_request(#{
|
||||||
, request_timeout => maps:get(request_timeout, Req, 30000)
|
, request_timeout => maps:get(request_timeout, Req, 30000)
|
||||||
}.
|
}.
|
||||||
|
|
||||||
preproc_headers(Headers) ->
|
preproc_headers(Headers) when is_map(Headers) ->
|
||||||
maps:fold(fun(K, V, Acc) ->
|
maps:fold(fun(K, V, Acc) ->
|
||||||
Acc#{emqx_plugin_libs_rule:preproc_tmpl(bin(K)) =>
|
[{
|
||||||
emqx_plugin_libs_rule:preproc_tmpl(bin(V))}
|
emqx_plugin_libs_rule:preproc_tmpl(bin(K)),
|
||||||
end, #{}, Headers).
|
emqx_plugin_libs_rule:preproc_tmpl(bin(V))
|
||||||
|
} | Acc]
|
||||||
|
end, [], Headers);
|
||||||
|
preproc_headers(Headers) when is_list(Headers) ->
|
||||||
|
lists:map(fun({K, V}) ->
|
||||||
|
{
|
||||||
|
emqx_plugin_libs_rule:preproc_tmpl(bin(K)),
|
||||||
|
emqx_plugin_libs_rule:preproc_tmpl(bin(V))
|
||||||
|
}
|
||||||
|
end, Headers).
|
||||||
|
|
||||||
process_request(#{
|
process_request(#{
|
||||||
method := MethodTks,
|
method := MethodTks,
|
||||||
|
@ -278,7 +287,7 @@ process_request(#{
|
||||||
Conf#{ method => make_method(emqx_plugin_libs_rule:proc_tmpl(MethodTks, Msg))
|
Conf#{ method => make_method(emqx_plugin_libs_rule:proc_tmpl(MethodTks, Msg))
|
||||||
, path => emqx_plugin_libs_rule:proc_tmpl(PathTks, Msg)
|
, path => emqx_plugin_libs_rule:proc_tmpl(PathTks, Msg)
|
||||||
, body => process_request_body(BodyTks, Msg)
|
, body => process_request_body(BodyTks, Msg)
|
||||||
, headers => maps:to_list(proc_headers(HeadersTks, Msg))
|
, headers => proc_headers(HeadersTks, Msg)
|
||||||
, request_timeout => ReqTimeout
|
, request_timeout => ReqTimeout
|
||||||
}.
|
}.
|
||||||
|
|
||||||
|
@ -288,10 +297,12 @@ process_request_body(BodyTks, Msg) ->
|
||||||
emqx_plugin_libs_rule:proc_tmpl(BodyTks, Msg).
|
emqx_plugin_libs_rule:proc_tmpl(BodyTks, Msg).
|
||||||
|
|
||||||
proc_headers(HeaderTks, Msg) ->
|
proc_headers(HeaderTks, Msg) ->
|
||||||
maps:fold(fun(K, V, Acc) ->
|
lists:map(fun({K, V}) ->
|
||||||
Acc#{emqx_plugin_libs_rule:proc_tmpl(K, Msg) =>
|
{
|
||||||
emqx_plugin_libs_rule:proc_tmpl(V, Msg)}
|
emqx_plugin_libs_rule:proc_tmpl(K, Msg),
|
||||||
end, #{}, HeaderTks).
|
emqx_plugin_libs_rule:proc_tmpl(V, Msg)
|
||||||
|
}
|
||||||
|
end, HeaderTks).
|
||||||
|
|
||||||
make_method(M) when M == <<"POST">>; M == <<"post">> -> post;
|
make_method(M) when M == <<"POST">>; M == <<"post">> -> post;
|
||||||
make_method(M) when M == <<"PUT">>; M == <<"put">> -> put;
|
make_method(M) when M == <<"PUT">>; M == <<"put">> -> put;
|
||||||
|
|
|
@ -436,6 +436,7 @@ typename_to_spec("timeout()", _Mod) -> #{<<"oneOf">> => [#{type => string, examp
|
||||||
typename_to_spec("bytesize()", _Mod) -> #{type => string, example => <<"32MB">>};
|
typename_to_spec("bytesize()", _Mod) -> #{type => string, example => <<"32MB">>};
|
||||||
typename_to_spec("wordsize()", _Mod) -> #{type => string, example => <<"1024KB">>};
|
typename_to_spec("wordsize()", _Mod) -> #{type => string, example => <<"1024KB">>};
|
||||||
typename_to_spec("map()", _Mod) -> #{type => object, example => #{}};
|
typename_to_spec("map()", _Mod) -> #{type => object, example => #{}};
|
||||||
|
typename_to_spec("{binary(), binary()}", _Mod) -> #{type => object, example => #{}};
|
||||||
typename_to_spec("comma_separated_list()", _Mod) ->
|
typename_to_spec("comma_separated_list()", _Mod) ->
|
||||||
#{type => string, example => <<"item1,item2">>};
|
#{type => string, example => <<"item1,item2">>};
|
||||||
typename_to_spec("comma_separated_atoms()", _Mod) ->
|
typename_to_spec("comma_separated_atoms()", _Mod) ->
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
, {system_monitor, {git, "https://github.com/klarna-incubator/system_monitor", {tag, "2.2.0"}}}
|
, {system_monitor, {git, "https://github.com/klarna-incubator/system_monitor", {tag, "2.2.0"}}}
|
||||||
, {getopt, "1.0.2"}
|
, {getopt, "1.0.2"}
|
||||||
, {snabbkaffe, {git, "https://github.com/kafka4beam/snabbkaffe.git", {tag, "0.16.0"}}}
|
, {snabbkaffe, {git, "https://github.com/kafka4beam/snabbkaffe.git", {tag, "0.16.0"}}}
|
||||||
, {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.22.1"}}}
|
, {hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.22.3"}}}
|
||||||
, {emqx_http_lib, {git, "https://github.com/emqx/emqx_http_lib.git", {tag, "0.4.1"}}}
|
, {emqx_http_lib, {git, "https://github.com/emqx/emqx_http_lib.git", {tag, "0.4.1"}}}
|
||||||
, {esasl, {git, "https://github.com/emqx/esasl", {tag, "0.2.0"}}}
|
, {esasl, {git, "https://github.com/emqx/esasl", {tag, "0.2.0"}}}
|
||||||
, {jose, {git, "https://github.com/potatosalad/erlang-jose", {tag, "1.11.2"}}}
|
, {jose, {git, "https://github.com/potatosalad/erlang-jose", {tag, "1.11.2"}}}
|
||||||
|
|
Loading…
Reference in New Issue