fix(auth mnesia api): fix write file error
This commit is contained in:
parent
0813a81517
commit
718dd80b48
|
@ -298,15 +298,15 @@ move_source_api() ->
|
||||||
{"/authorization/sources/:type/move", Metadata, move_source}.
|
{"/authorization/sources/:type/move", Metadata, move_source}.
|
||||||
|
|
||||||
sources(get, _) ->
|
sources(get, _) ->
|
||||||
Sources = lists:foldl(fun (#{enable := false} = Source, AccIn) ->
|
Sources = lists:foldl(fun (#{type := file, enable := Enable, path := Path}, AccIn) ->
|
||||||
lists:append(AccIn, [Source#{annotations => #{status => unhealthy}}]);
|
|
||||||
(#{type := file, path := Path}, AccIn) ->
|
|
||||||
{ok, Rules} = file:consult(Path),
|
{ok, Rules} = file:consult(Path),
|
||||||
lists:append(AccIn, [#{type => file,
|
lists:append(AccIn, [#{type => file,
|
||||||
enable => true,
|
enable => Enable,
|
||||||
rules => [ iolist_to_binary(io_lib:format("~p.", [R])) || R <- Rules],
|
rules => [ iolist_to_binary(io_lib:format("~p.", [R])) || R <- Rules],
|
||||||
annotations => #{status => healthy}
|
annotations => #{status => healthy}
|
||||||
}]);
|
}]);
|
||||||
|
(#{enable := false} = Source, AccIn) ->
|
||||||
|
lists:append(AccIn, [Source#{annotations => #{status => unhealthy}}]);
|
||||||
(#{type := _Type, annotations := #{id := Id}} = Source, AccIn) ->
|
(#{type := _Type, annotations := #{id := Id}} = Source, AccIn) ->
|
||||||
NSource0 = case maps:get(server, Source, undefined) of
|
NSource0 = case maps:get(server, Source, undefined) of
|
||||||
undefined -> Source;
|
undefined -> Source;
|
||||||
|
@ -367,15 +367,15 @@ sources(put, #{body := Body}) when is_list(Body) ->
|
||||||
source(get, #{bindings := #{type := Type}}) ->
|
source(get, #{bindings := #{type := Type}}) ->
|
||||||
case emqx_authz:lookup(Type) of
|
case emqx_authz:lookup(Type) of
|
||||||
{error, Reason} -> {404, #{messgae => atom_to_binary(Reason)}};
|
{error, Reason} -> {404, #{messgae => atom_to_binary(Reason)}};
|
||||||
#{enable := false} = Source -> {200, Source#{annotations => #{status => unhealthy}}};
|
#{type := file, enable := Enable, path := Path}->
|
||||||
#{type := file, path := Path}->
|
|
||||||
{ok, Rules} = file:consult(Path),
|
{ok, Rules} = file:consult(Path),
|
||||||
{200, #{type => file,
|
{200, #{type => file,
|
||||||
enable => true,
|
enable => Enable,
|
||||||
rules => [ iolist_to_binary(io_lib:format("~p.", [R])) || R <- Rules],
|
rules => [ iolist_to_binary(io_lib:format("~p.", [R])) || R <- Rules],
|
||||||
annotations => #{status => healthy}
|
annotations => #{status => healthy}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
#{enable := false} = Source -> {200, Source#{annotations => #{status => unhealthy}}};
|
||||||
#{annotations := #{id := Id}} = Source ->
|
#{annotations := #{id := Id}} = Source ->
|
||||||
NSource0 = case maps:get(server, Source, undefined) of
|
NSource0 = case maps:get(server, Source, undefined) of
|
||||||
undefined -> Source;
|
undefined -> Source;
|
||||||
|
@ -486,7 +486,7 @@ write_cert(Source) -> Source.
|
||||||
write_file(Filename, Bytes) ->
|
write_file(Filename, Bytes) ->
|
||||||
ok = filelib:ensure_dir(Filename),
|
ok = filelib:ensure_dir(Filename),
|
||||||
case file:write_file(Filename, Bytes) of
|
case file:write_file(Filename, Bytes) of
|
||||||
ok -> {ok, Filename};
|
ok -> {ok, iolist_to_binary(Filename)};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
?LOG(error, "Write File ~p Error: ~p", [Filename, Reason]),
|
?LOG(error, "Write File ~p Error: ~p", [Filename, Reason]),
|
||||||
error(Reason)
|
error(Reason)
|
||||||
|
|
Loading…
Reference in New Issue