增加对http协议的token支持
This commit is contained in:
parent
dc0211ecc2
commit
2de2bd6431
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
-record(http_endpoint, {
|
-record(http_endpoint, {
|
||||||
url = <<>> :: binary(),
|
url = <<>> :: binary(),
|
||||||
|
token = <<>> :: binary(),
|
||||||
pool_size = 10 :: integer()
|
pool_size = 10 :: integer()
|
||||||
}).
|
}).
|
||||||
|
|
||||||
|
|||||||
@ -116,9 +116,11 @@ parse_config(<<"mqtt">>, #{<<"host">> := Host, <<"port">> := Port0, <<"client_id
|
|||||||
false ->
|
false ->
|
||||||
{error, Errors}
|
{error, Errors}
|
||||||
end;
|
end;
|
||||||
parse_config(<<"http">>, #{<<"url">> := Url, <<"pool_size">> := PoolSize}) ->
|
parse_config(<<"http">>, C = #{<<"url">> := Url, <<"pool_size">> := PoolSize}) ->
|
||||||
|
Token = maps:get(<<"token">>, C, <<>>),
|
||||||
{ok, #http_endpoint{
|
{ok, #http_endpoint{
|
||||||
url = Url,
|
url = Url,
|
||||||
|
token = Token,
|
||||||
pool_size = PoolSize
|
pool_size = PoolSize
|
||||||
}};
|
}};
|
||||||
parse_config(<<"kafka">>, #{<<"sasl_config">> := #{<<"username">> := Username, <<"password">> := Password, <<"mechanism">> := Mechanism0}, <<"bootstrap_servers">> := BootstrapServers, <<"topic">> := Topic}) ->
|
parse_config(<<"kafka">>, #{<<"sasl_config">> := #{<<"username">> := Username, <<"password">> := Password, <<"mechanism">> := Mechanism0}, <<"bootstrap_servers">> := BootstrapServers, <<"topic">> := Topic}) ->
|
||||||
|
|||||||
@ -14,6 +14,7 @@
|
|||||||
-export([step/3, chunks/2, rand_bytes/1, uuid/0, md5/1, parse_mapper/1]).
|
-export([step/3, chunks/2, rand_bytes/1, uuid/0, md5/1, parse_mapper/1]).
|
||||||
-export([json_data/1, json_error/2, is_json/1]).
|
-export([json_data/1, json_error/2, is_json/1]).
|
||||||
-export([queue_limited_in/3, assert_call/2, assert/2]).
|
-export([queue_limited_in/3, assert_call/2, assert/2]).
|
||||||
|
-export([sha256/1]).
|
||||||
|
|
||||||
-spec is_json(Json :: term()) -> boolean().
|
-spec is_json(Json :: term()) -> boolean().
|
||||||
is_json(Json) when is_binary(Json) ->
|
is_json(Json) when is_binary(Json) ->
|
||||||
@ -112,6 +113,14 @@ assert_call(true, Fun) ->
|
|||||||
assert_call(false, _) ->
|
assert_call(false, _) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
-spec sha256(Str :: string() | binary()) -> string().
|
||||||
|
sha256(Str) when is_list(Str) ->
|
||||||
|
sha256(unicode:characters_to_binary(Str));
|
||||||
|
sha256(Bin) when is_binary(Bin) ->
|
||||||
|
HashBin = crypto:hash(sha256, Bin),
|
||||||
|
HexStr = lists:flatten([io_lib:format("~2.16.0B", [B]) || B <- binary:bin_to_list(HashBin)]),
|
||||||
|
string:lowercase(HexStr).
|
||||||
|
|
||||||
-spec md5(Str :: binary()) -> binary().
|
-spec md5(Str :: binary()) -> binary().
|
||||||
md5(Str) when is_binary(Str) ->
|
md5(Str) when is_binary(Str) ->
|
||||||
list_to_binary(lists:flatten([hex(X) || <<X:4>> <= erlang:md5(Str)])).
|
list_to_binary(lists:flatten([hex(X) || <<X:4>> <= erlang:md5(Str)])).
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user