fix(authz api): fix file type error
This commit is contained in:
parent
d2278b02d9
commit
11c90cfce4
|
@ -326,7 +326,7 @@ sources(put, #{body := Body}) when is_list(Body) ->
|
||||||
source(get, #{bindings := #{type := Type}}) ->
|
source(get, #{bindings := #{type := Type}}) ->
|
||||||
case get_raw_source(Type) of
|
case get_raw_source(Type) of
|
||||||
[] -> {404, #{message => <<"Not found ", Type/binary>>}};
|
[] -> {404, #{message => <<"Not found ", Type/binary>>}};
|
||||||
[#{type := <<"file">>, enable := Enable, path := Path}] ->
|
[#{type := file, enable := Enable, path := Path}] ->
|
||||||
case file:read_file(Path) of
|
case file:read_file(Path) of
|
||||||
{ok, Rules} ->
|
{ok, Rules} ->
|
||||||
{200, #{type => file,
|
{200, #{type => file,
|
||||||
|
@ -336,7 +336,7 @@ source(get, #{bindings := #{type := Type}}) ->
|
||||||
};
|
};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
{400, #{code => <<"BAD_REQUEST">>,
|
{400, #{code => <<"BAD_REQUEST">>,
|
||||||
message => atom_to_binary(Reason)}}
|
message => bin(Reason)}}
|
||||||
end;
|
end;
|
||||||
[Source] ->
|
[Source] ->
|
||||||
{200, read_cert(Source)}
|
{200, read_cert(Source)}
|
||||||
|
@ -347,7 +347,7 @@ source(put, #{bindings := #{type := <<"file">>}, body := #{<<"type">> := <<"file
|
||||||
{ok, _} -> {204};
|
{ok, _} -> {204};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
{400, #{code => <<"BAD_REQUEST">>,
|
{400, #{code => <<"BAD_REQUEST">>,
|
||||||
message => atom_to_binary(Reason)}}
|
message => bin(Reason)}}
|
||||||
end;
|
end;
|
||||||
source(put, #{bindings := #{type := Type}, body := Body}) when is_map(Body) ->
|
source(put, #{bindings := #{type := Type}, body := Body}) when is_map(Body) ->
|
||||||
update_config({replace_once, Type}, write_cert(Body));
|
update_config({replace_once, Type}, write_cert(Body));
|
||||||
|
@ -362,7 +362,7 @@ move_source(post, #{bindings := #{type := Type}, body := #{<<"position">> := Pos
|
||||||
message => <<"source ", Type/binary, " not found">>}};
|
message => <<"source ", Type/binary, " not found">>}};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
{400, #{code => <<"BAD_REQUEST">>,
|
{400, #{code => <<"BAD_REQUEST">>,
|
||||||
message => atom_to_binary(Reason)}}
|
message => bin(Reason)}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_raw_sources() ->
|
get_raw_sources() ->
|
||||||
|
@ -374,7 +374,7 @@ get_raw_sources() ->
|
||||||
|
|
||||||
get_raw_source(Type) ->
|
get_raw_source(Type) ->
|
||||||
lists:filter(fun (#{type := T}) ->
|
lists:filter(fun (#{type := T}) ->
|
||||||
T =:= Type
|
bin(T) =:= Type
|
||||||
end, get_raw_sources()).
|
end, get_raw_sources()).
|
||||||
|
|
||||||
update_config(Cmd, Sources) ->
|
update_config(Cmd, Sources) ->
|
||||||
|
@ -382,13 +382,13 @@ update_config(Cmd, Sources) ->
|
||||||
{ok, _} -> {204};
|
{ok, _} -> {204};
|
||||||
{error, {pre_config_update, emqx_authz, Reason}} ->
|
{error, {pre_config_update, emqx_authz, Reason}} ->
|
||||||
{400, #{code => <<"BAD_REQUEST">>,
|
{400, #{code => <<"BAD_REQUEST">>,
|
||||||
message => atom_to_binary(Reason)}};
|
message => bin(Reason)}};
|
||||||
{error, {post_config_update, emqx_authz, Reason}} ->
|
{error, {post_config_update, emqx_authz, Reason}} ->
|
||||||
{400, #{code => <<"BAD_REQUEST">>,
|
{400, #{code => <<"BAD_REQUEST">>,
|
||||||
message => atom_to_binary(Reason)}};
|
message => bin(Reason)}};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
{400, #{code => <<"BAD_REQUEST">>,
|
{400, #{code => <<"BAD_REQUEST">>,
|
||||||
message => atom_to_binary(Reason)}}
|
message => bin(Reason)}}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
read_cert(#{ssl := #{enable := true} = SSL} = Source) ->
|
read_cert(#{ssl := #{enable := true} = SSL} = Source) ->
|
||||||
|
@ -459,3 +459,6 @@ do_write_file(Filename, Bytes) ->
|
||||||
?LOG(error, "Write File ~p Error: ~p", [Filename, Reason]),
|
?LOG(error, "Write File ~p Error: ~p", [Filename, Reason]),
|
||||||
error(Reason)
|
error(Reason)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
bin(Term) ->
|
||||||
|
erlang:iolist_to_binary(io_lib:format("~p", [Term])).
|
||||||
|
|
Loading…
Reference in New Issue