Merge pull request #6749 from zhongwencool/fix-authz-headers

fix(authz): Remove unnecessary headers
This commit is contained in:
zhongwencool 2022-01-14 15:15:12 +08:00 committed by GitHub
commit 5a31001906
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 11 deletions

View File

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