fix warning
This commit is contained in:
parent
83afafcb12
commit
cec0a25e7c
@ -165,23 +165,7 @@ gather_output(Port, Acc) ->
|
|||||||
{Status, iolist_to_binary(Acc)}
|
{Status, iolist_to_binary(Acc)}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
extract_sha256(Output) when is_binary(Output) ->
|
|
||||||
Parts = binary:split(Output, <<$\n>>, [global]),
|
|
||||||
lager:debug("parts: ~p", [Parts]),
|
|
||||||
case lists:search(fun(Line) -> starts_with(Line, <<"Digest:">>) end, Parts) of
|
|
||||||
{value, Digest} ->
|
|
||||||
Sha256 = lists:last(binary:split(Digest, <<":">>, [global])),
|
|
||||||
{ok, Sha256};
|
|
||||||
false ->
|
|
||||||
error
|
|
||||||
end.
|
|
||||||
|
|
||||||
starts_with(Binary, Prefix) when is_binary(Binary), is_binary(Prefix) ->
|
|
||||||
PrefixSize = byte_size(Prefix),
|
|
||||||
case Binary of
|
|
||||||
<<Prefix:PrefixSize/binary, _Rest/binary>> -> true;
|
|
||||||
_ -> false
|
|
||||||
end.
|
|
||||||
|
|
||||||
%% 构建所有参数
|
%% 构建所有参数
|
||||||
build_options(Config) ->
|
build_options(Config) ->
|
||||||
|
|||||||
@ -33,7 +33,7 @@
|
|||||||
%%% API
|
%%% API
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
|
||||||
-spec deploy(TaskId :: integer(), Config :: map()) -> {ok, ContainerId :: binary()} | {error, Reason :: binary()}.
|
-spec deploy(TaskId :: integer(), Config :: map()) -> ok | {error, Reason :: binary()}.
|
||||||
deploy(TaskId, Config) when is_integer(TaskId), is_map(Config) ->
|
deploy(TaskId, Config) when is_integer(TaskId), is_map(Config) ->
|
||||||
gen_server:call(?SERVER, {deploy, TaskId, Config}).
|
gen_server:call(?SERVER, {deploy, TaskId, Config}).
|
||||||
|
|
||||||
|
|||||||
@ -102,8 +102,6 @@ decode0(_, _) ->
|
|||||||
-spec marshal(Type :: integer(), Field :: any()) -> binary().
|
-spec marshal(Type :: integer(), Field :: any()) -> binary().
|
||||||
marshal(?I32, Field) when is_integer(Field) ->
|
marshal(?I32, Field) when is_integer(Field) ->
|
||||||
<<?I32, Field:32>>;
|
<<?I32, Field:32>>;
|
||||||
marshal(?Bytes, undefined) ->
|
|
||||||
<<?Bytes, 0:16>>;
|
|
||||||
marshal(?Bytes, Field) when is_binary(Field) ->
|
marshal(?Bytes, Field) when is_binary(Field) ->
|
||||||
Len = byte_size(Field),
|
Len = byte_size(Field),
|
||||||
<<?Bytes, Len:16, Field/binary>>;
|
<<?Bytes, Len:16, Field/binary>>;
|
||||||
|
|||||||
@ -92,11 +92,12 @@ handle_event(cast, {metric_data, ServiceId, DeviceUUID, RouteKey, Metric}, ?STAT
|
|||||||
efka_transport:send(TransportPid, Packet),
|
efka_transport:send(TransportPid, Packet),
|
||||||
{keep_state, State};
|
{keep_state, State};
|
||||||
|
|
||||||
handle_event(cast, {metric_data, ServiceId, DeviceUUID, LineProtocolData}, _, State) ->
|
handle_event(cast, {metric_data, ServiceId, DeviceUUID, RouteKey, Metric}, _, State) ->
|
||||||
Packet = efka_codec:encode(?MESSAGE_DATA, #data{
|
Packet = efka_codec:encode(?MESSAGE_DATA, #data{
|
||||||
service_id = ServiceId,
|
service_id = ServiceId,
|
||||||
device_uuid = DeviceUUID,
|
device_uuid = DeviceUUID,
|
||||||
metric = LineProtocolData
|
route_key = RouteKey,
|
||||||
|
metric = Metric
|
||||||
}),
|
}),
|
||||||
ok = cache_model:insert(Packet),
|
ok = cache_model:insert(Packet),
|
||||||
{keep_state, State};
|
{keep_state, State};
|
||||||
@ -272,7 +273,8 @@ handle_event(info, {server_rpc, PacketId, #rpc_container{method = <<"config">>,
|
|||||||
% {keep_state, State};
|
% {keep_state, State};
|
||||||
|
|
||||||
%% 处理命令
|
%% 处理命令
|
||||||
handle_event(info, {server_command, #command{command_type = ?COMMAND_AUTH, command = Auth}}, StateName, State = #state{transport_pid = TransportPid}) ->
|
handle_event(info, {server_command, #command{command_type = ?COMMAND_AUTH, command = Auth0}}, StateName, State = #state{transport_pid = TransportPid}) ->
|
||||||
|
Auth = binary_to_integer(Auth0),
|
||||||
case {Auth, StateName} of
|
case {Auth, StateName} of
|
||||||
{1, ?STATE_ACTIVATED} ->
|
{1, ?STATE_ACTIVATED} ->
|
||||||
{keep_state, State};
|
{keep_state, State};
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
-export([timestamp/0, number_format/2, timestamp_ms/0, float_to_binary/2, int_format/2]).
|
-export([timestamp/0, number_format/2, timestamp_ms/0, float_to_binary/2, int_format/2]).
|
||||||
-export([chunks/2, rand_bytes/1, uuid/0, md5/1, sha_uuid/0]).
|
-export([chunks/2, rand_bytes/1, uuid/0, md5/1, sha_uuid/0]).
|
||||||
-export([json_data/1, json_error/2]).
|
-export([json_data/1, json_error/2]).
|
||||||
|
-export([starts_with/2]).
|
||||||
|
|
||||||
get_file_md5(FilePath) when is_list(FilePath) ->
|
get_file_md5(FilePath) when is_list(FilePath) ->
|
||||||
{ok, FileData} = file:read_file(FilePath),
|
{ok, FileData} = file:read_file(FilePath),
|
||||||
@ -102,4 +103,12 @@ float_to_binary(V, Decimals) when is_float(V), is_integer(Decimals) ->
|
|||||||
sha_uuid() ->
|
sha_uuid() ->
|
||||||
Salt = crypto:strong_rand_bytes(32),
|
Salt = crypto:strong_rand_bytes(32),
|
||||||
Str = string:lowercase(binary:encode_hex(crypto:hash(sha256, Salt))),
|
Str = string:lowercase(binary:encode_hex(crypto:hash(sha256, Salt))),
|
||||||
binary:part(Str, 1, 32).
|
binary:part(Str, 1, 32).
|
||||||
|
|
||||||
|
-spec starts_with(Binary :: binary(), Prefix :: binary()) -> boolean().
|
||||||
|
starts_with(Binary, Prefix) when is_binary(Binary), is_binary(Prefix) ->
|
||||||
|
PrefixSize = byte_size(Prefix),
|
||||||
|
case Binary of
|
||||||
|
<<Prefix:PrefixSize/binary, _Rest/binary>> -> true;
|
||||||
|
_ -> false
|
||||||
|
end.
|
||||||
Loading…
x
Reference in New Issue
Block a user