hmpf
This commit is contained in:
parent
c5438199e4
commit
2a3c2cfd93
|
@ -9,7 +9,8 @@
|
||||||
-behavior(gen_server).
|
-behavior(gen_server).
|
||||||
|
|
||||||
%% API exports
|
%% API exports
|
||||||
-export([get/2, get/3, put/4,
|
-export([get/2, get/3, get/4,
|
||||||
|
put/4, put/5,
|
||||||
post/4,
|
post/4,
|
||||||
refresh_credentials/0,
|
refresh_credentials/0,
|
||||||
request/5, request/6, request/7,
|
request/5, request/6, request/7,
|
||||||
|
@ -60,7 +61,10 @@ get(Service, Path) ->
|
||||||
%% format.
|
%% format.
|
||||||
%% @end
|
%% @end
|
||||||
get(Service, Path, Headers) ->
|
get(Service, Path, Headers) ->
|
||||||
request(Service, get, Path, "", Headers).
|
request(Service, get, Path, "", Headers, []).
|
||||||
|
|
||||||
|
get(Service, Path, Headers, Options) ->
|
||||||
|
request(Service, get, Path, "", Headers, Options).
|
||||||
|
|
||||||
|
|
||||||
-spec post(Service :: string(),
|
-spec post(Service :: string(),
|
||||||
|
@ -84,7 +88,10 @@ post(Service, Path, Body, Headers) ->
|
||||||
%% format.
|
%% format.
|
||||||
%% @end
|
%% @end
|
||||||
put(Service, Path, Body, Headers) ->
|
put(Service, Path, Body, Headers) ->
|
||||||
request(Service, put, Path, Body, Headers).
|
put(Service, Path, Body, Headers, []).
|
||||||
|
|
||||||
|
put(Service, Path, Body, Headers, Options) ->
|
||||||
|
request(Service, put, Path, Body, Headers, Options).
|
||||||
|
|
||||||
|
|
||||||
-spec refresh_credentials() -> ok | error.
|
-spec refresh_credentials() -> ok | error.
|
||||||
|
@ -657,7 +664,8 @@ get_or_create_gun_connection(State, Host, Port, Path, Options) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_connection_key(Host, Port, Path, Options) ->
|
get_connection_key(Host, Port, Path, Options) ->
|
||||||
case proplists:get_value(connection_per_path, Options, true) of
|
io:format(">>~p~n",[Options]),
|
||||||
|
case proplists:get_value(connection_per_path, Options, false) of
|
||||||
true -> Host ++ ":" ++ integer_to_list(Port) ++ Path; % Per-path
|
true -> Host ++ ":" ++ integer_to_list(Port) ++ Path; % Per-path
|
||||||
false -> Host ++ ":" ++ integer_to_list(Port) % Per-host (default)
|
false -> Host ++ ":" ++ integer_to_list(Port) % Per-host (default)
|
||||||
end.
|
end.
|
||||||
|
|
|
@ -746,26 +746,8 @@ region_from_availability_zone(Value) ->
|
||||||
%% @doc Attempt to obtain EC2 IMDSv2 token.
|
%% @doc Attempt to obtain EC2 IMDSv2 token.
|
||||||
%% @end
|
%% @end
|
||||||
load_imdsv2_token() ->
|
load_imdsv2_token() ->
|
||||||
<<<<<<< HEAD
|
|
||||||
TokenUrl = imdsv2_token_url(),
|
TokenUrl = imdsv2_token_url(),
|
||||||
?LOG_INFO("Attempting to obtain EC2 IMDSv2 token from ~tp ...", [TokenUrl]),
|
?LOG_INFO("Attempting to obtain EC2 IMDSv2 token from ~tp ...", [TokenUrl]),
|
||||||
case httpc:request(put, {TokenUrl, [{?METADATA_TOKEN_TTL_HEADER, integer_to_list(?METADATA_TOKEN_TTL_SECONDS)}]},
|
|
||||||
[{timeout, ?DEFAULT_HTTP_TIMEOUT}], []) of
|
|
||||||
{ok, {{_, 200, _}, _, Value}} ->
|
|
||||||
?LOG_DEBUG("Successfully obtained EC2 IMDSv2 token."),
|
|
||||||
Value;
|
|
||||||
{error, {{_, 400, _}, _, _}} ->
|
|
||||||
?LOG_WARNING("Failed to obtain EC2 IMDSv2 token: Missing or Invalid Parameters – The PUT request is not valid."),
|
|
||||||
undefined;
|
|
||||||
Other ->
|
|
||||||
?LOG_WARNING(
|
|
||||||
get_instruction_on_instance_metadata_error("Failed to obtain EC2 IMDSv2 token: ~tp. "
|
|
||||||
"Falling back to EC2 IMDSv1 for now. It is recommended to use EC2 IMDSv2."), [Other]),
|
|
||||||
undefined
|
|
||||||
end.
|
|
||||||
=======
|
|
||||||
TokenUrl = imdsv2_token_url(),
|
|
||||||
rabbit_log:info("Attempting to obtain EC2 IMDSv2 token from ~tp ...", [TokenUrl]),
|
|
||||||
% Parse metadata service URL
|
% Parse metadata service URL
|
||||||
{Host, Port, Path} = rabbitmq_aws:parse_uri(TokenUrl),
|
{Host, Port, Path} = rabbitmq_aws:parse_uri(TokenUrl),
|
||||||
% Simple Gun connection for metadata service
|
% Simple Gun connection for metadata service
|
||||||
|
@ -779,22 +761,22 @@ load_imdsv2_token() ->
|
||||||
StreamRef = gun:put(ConnPid, Path, Headers, <<>>),
|
StreamRef = gun:put(ConnPid, Path, Headers, <<>>),
|
||||||
Result = case gun:await(ConnPid, StreamRef, ?DEFAULT_HTTP_TIMEOUT) of
|
Result = case gun:await(ConnPid, StreamRef, ?DEFAULT_HTTP_TIMEOUT) of
|
||||||
{response, fin, 200, _RespHeaders} ->
|
{response, fin, 200, _RespHeaders} ->
|
||||||
rabbit_log:debug("Successfully obtained EC2 IMDSv2 token."),
|
?LOG_DEBUG("Successfully obtained EC2 IMDSv2 token."),
|
||||||
<<>>; % Empty body for fin response
|
<<>>; % Empty body for fin response
|
||||||
{response, nofin, 200, _RespHeaders} ->
|
{response, nofin, 200, _RespHeaders} ->
|
||||||
{ok, Body} = gun:await_body(ConnPid, StreamRef, ?DEFAULT_HTTP_TIMEOUT),
|
{ok, Body} = gun:await_body(ConnPid, StreamRef, ?DEFAULT_HTTP_TIMEOUT),
|
||||||
rabbit_log:debug("Successfully obtained EC2 IMDSv2 token."),
|
?LOG_DEBUG("Successfully obtained EC2 IMDSv2 token."),
|
||||||
binary_to_list(Body);
|
binary_to_list(Body);
|
||||||
{response, _, 400, _RespHeaders} ->
|
{response, _, 400, _RespHeaders} ->
|
||||||
rabbit_log:warning("Failed to obtain EC2 IMDSv2 token: Missing or Invalid Parameters – The PUT request is not valid."),
|
?LOG_WARNING("Failed to obtain EC2 IMDSv2 token: Missing or Invalid Parameters – The PUT request is not valid."),
|
||||||
undefined;
|
undefined;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
rabbit_log:warning(
|
?LOG_WARNING(
|
||||||
get_instruction_on_instance_metadata_error("Failed to obtain EC2 IMDSv2 token: ~tp. "
|
get_instruction_on_instance_metadata_error("Failed to obtain EC2 IMDSv2 token: ~tp. "
|
||||||
"Falling back to EC2 IMDSv1 for now. It is recommended to use EC2 IMDSv2."), [Reason]),
|
"Falling back to EC2 IMDSv1 for now. It is recommended to use EC2 IMDSv2."), [Reason]),
|
||||||
undefined;
|
undefined;
|
||||||
Other ->
|
Other ->
|
||||||
rabbit_log:warning(
|
?LOG_WARNING(
|
||||||
get_instruction_on_instance_metadata_error("Failed to obtain EC2 IMDSv2 token: ~tp. "
|
get_instruction_on_instance_metadata_error("Failed to obtain EC2 IMDSv2 token: ~tp. "
|
||||||
"Falling back to EC2 IMDSv1 for now. It is recommended to use EC2 IMDSv2."), [Other]),
|
"Falling back to EC2 IMDSv1 for now. It is recommended to use EC2 IMDSv2."), [Other]),
|
||||||
undefined
|
undefined
|
||||||
|
@ -803,19 +785,17 @@ load_imdsv2_token() ->
|
||||||
Result;
|
Result;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
gun:close(ConnPid),
|
gun:close(ConnPid),
|
||||||
rabbit_log:warning(
|
?LOG_WARNING(
|
||||||
get_instruction_on_instance_metadata_error("Failed to connect for EC2 IMDSv2 token: ~tp. "
|
get_instruction_on_instance_metadata_error("Failed to connect for EC2 IMDSv2 token: ~tp. "
|
||||||
"Falling back to EC2 IMDSv1 for now. It is recommended to use EC2 IMDSv2."), [Reason]),
|
"Falling back to EC2 IMDSv1 for now. It is recommended to use EC2 IMDSv2."), [Reason]),
|
||||||
undefined
|
undefined
|
||||||
end;
|
end;
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
rabbit_log:warning(
|
?LOG_WARNING(
|
||||||
get_instruction_on_instance_metadata_error("Failed to open connection for EC2 IMDSv2 token: ~tp. "
|
get_instruction_on_instance_metadata_error("Failed to open connection for EC2 IMDSv2 token: ~tp. "
|
||||||
"Falling back to EC2 IMDSv1 for now. It is recommended to use EC2 IMDSv2."), [Reason]),
|
"Falling back to EC2 IMDSv1 for now. It is recommended to use EC2 IMDSv2."), [Reason]),
|
||||||
undefined
|
undefined
|
||||||
end.
|
end.
|
||||||
>>>>>>> f04e9ce16a (Fully remove httpc)
|
|
||||||
|
|
||||||
|
|
||||||
-spec instance_metadata_request_headers() -> headers().
|
-spec instance_metadata_request_headers() -> headers().
|
||||||
%% @doc Return headers used for instance metadata service requests.
|
%% @doc Return headers used for instance metadata service requests.
|
||||||
|
|
Loading…
Reference in New Issue