fix: authz headers default value

This commit is contained in:
zhongwencool 2022-01-05 22:06:50 +08:00
parent 22e77eff7e
commit f4f5281b16
2 changed files with 20 additions and 3 deletions

View File

@ -412,9 +412,22 @@ get_raw_sources() ->
RawSources = emqx:get_raw_config([authorization, sources], []),
Schema = #{roots => emqx_authz_schema:fields("authorization"), fields => #{}},
Conf = #{<<"sources">> => RawSources},
#{<<"sources">> := Sources} = hocon_schema:check_plain(Schema, Conf,
#{only_fill_defaults => true}),
Sources.
#{<<"sources">> := Sources} = hocon_schema:check_plain(Schema, Conf, #{only_fill_defaults => true}),
merge_default_headers(Sources).
merge_default_headers(Sources) ->
lists:map(fun(Source) ->
Convert =
case Source of
#{<<"method">> := <<"get">>} ->
emqx_authz_schema:headers_no_content_type(converter);
#{<<"method">> := <<"post">>} ->
emqx_authz_schema:headers(converter);
_ -> fun(H) -> H end
end,
Headers = Convert(maps:get(<<"headers">>, Source, #{})),
Source#{<<"headers">> => Headers}
end, Sources).
get_raw_source(Type) ->
lists:filter(fun (#{<<"type">> := T}) ->

View File

@ -31,6 +31,10 @@
, fields/1
, validations/0
]).
-export([
headers_no_content_type/1,
headers/1
]).
-import(emqx_schema, [mk_duration/2]).
-include_lib("hocon/include/hoconsc.hrl").