Skip to content

Commit 51866ef

Browse files
committed
hmpf
1 parent c543819 commit 51866ef

File tree

2 files changed

+24
-34
lines changed

2 files changed

+24
-34
lines changed

deps/rabbitmq_aws/src/rabbitmq_aws.erl

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
-behavior(gen_server).
1010

1111
%% API exports
12-
-export([get/2, get/3, put/4,
12+
-export([get/2, get/3, get/4,
13+
put/4, put/5,
1314
post/4,
1415
refresh_credentials/0,
1516
request/5, request/6, request/7,
@@ -60,7 +61,10 @@ get(Service, Path) ->
6061
%% format.
6162
%% @end
6263
get(Service, Path, Headers) ->
63-
request(Service, get, Path, "", Headers).
64+
request(Service, get, Path, "", Headers, []).
65+
66+
get(Service, Path, Headers, Options) ->
67+
request(Service, get, Path, "", Headers, Options).
6468

6569

6670
-spec post(Service :: string(),
@@ -84,7 +88,10 @@ post(Service, Path, Body, Headers) ->
8488
%% format.
8589
%% @end
8690
put(Service, Path, Body, Headers) ->
87-
request(Service, put, Path, Body, Headers).
91+
put(Service, Path, Body, Headers, []).
92+
93+
put(Service, Path, Body, Headers, Options) ->
94+
request(Service, put, Path, Body, Headers, Options).
8895

8996

9097
-spec refresh_credentials() -> ok | error.
@@ -657,7 +664,8 @@ get_or_create_gun_connection(State, Host, Port, Path, Options) ->
657664
end.
658665

659666
get_connection_key(Host, Port, Path, Options) ->
660-
case proplists:get_value(connection_per_path, Options, true) of
667+
io:format(">>~p~n",[Options]),
668+
case proplists:get_value(connection_per_path, Options, false) of
661669
true -> Host ++ ":" ++ integer_to_list(Port) ++ Path; % Per-path
662670
false -> Host ++ ":" ++ integer_to_list(Port) % Per-host (default)
663671
end.

deps/rabbitmq_aws/src/rabbitmq_aws_config.erl

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -746,26 +746,8 @@ region_from_availability_zone(Value) ->
746746
%% @doc Attempt to obtain EC2 IMDSv2 token.
747747
%% @end
748748
load_imdsv2_token() ->
749-
<<<<<<< HEAD
750-
TokenUrl = imdsv2_token_url(),
751-
?LOG_INFO("Attempting to obtain EC2 IMDSv2 token from ~tp ...", [TokenUrl]),
752-
case httpc:request(put, {TokenUrl, [{?METADATA_TOKEN_TTL_HEADER, integer_to_list(?METADATA_TOKEN_TTL_SECONDS)}]},
753-
[{timeout, ?DEFAULT_HTTP_TIMEOUT}], []) of
754-
{ok, {{_, 200, _}, _, Value}} ->
755-
?LOG_DEBUG("Successfully obtained EC2 IMDSv2 token."),
756-
Value;
757-
{error, {{_, 400, _}, _, _}} ->
758-
?LOG_WARNING("Failed to obtain EC2 IMDSv2 token: Missing or Invalid Parameters – The PUT request is not valid."),
759-
undefined;
760-
Other ->
761-
?LOG_WARNING(
762-
get_instruction_on_instance_metadata_error("Failed to obtain EC2 IMDSv2 token: ~tp. "
763-
"Falling back to EC2 IMDSv1 for now. It is recommended to use EC2 IMDSv2."), [Other]),
764-
undefined
765-
end.
766-
=======
767749
TokenUrl = imdsv2_token_url(),
768-
rabbit_log:info("Attempting to obtain EC2 IMDSv2 token from ~tp ...", [TokenUrl]),
750+
?LOG_INFO("Attempting to obtain EC2 IMDSv2 token from ~tp ...", [TokenUrl]),
769751
% Parse metadata service URL
770752
{Host, Port, Path} = rabbitmq_aws:parse_uri(TokenUrl),
771753
% Simple Gun connection for metadata service
@@ -779,38 +761,38 @@ load_imdsv2_token() ->
779761
StreamRef = gun:put(ConnPid, Path, Headers, <<>>),
780762
Result = case gun:await(ConnPid, StreamRef, ?DEFAULT_HTTP_TIMEOUT) of
781763
{response, fin, 200, _RespHeaders} ->
782-
rabbit_log:debug("Successfully obtained EC2 IMDSv2 token."),
764+
?LOG_DEBUG("Successfully obtained EC2 IMDSv2 token."),
783765
<<>>; % Empty body for fin response
784766
{response, nofin, 200, _RespHeaders} ->
785767
{ok, Body} = gun:await_body(ConnPid, StreamRef, ?DEFAULT_HTTP_TIMEOUT),
786-
rabbit_log:debug("Successfully obtained EC2 IMDSv2 token."),
768+
?LOG_DEBUG("Successfully obtained EC2 IMDSv2 token."),
787769
binary_to_list(Body);
788770
{response, _, 400, _RespHeaders} ->
789-
rabbit_log:warning("Failed to obtain EC2 IMDSv2 token: Missing or Invalid Parameters – The PUT request is not valid."),
771+
?LOG_WARNING("Failed to obtain EC2 IMDSv2 token: Missing or Invalid Parameters – The PUT request is not valid."),
790772
undefined;
791773
{error, Reason} ->
792-
rabbit_log:warning(
793-
get_instruction_on_instance_metadata_error("Failed to obtain EC2 IMDSv2 token: ~tp. "
774+
?LOG_WARNING(
775+
get_instruction_on_instance_metadata_error("Failed to obtain EC2 IMDSv2 token: ~tp. "
794776
"Falling back to EC2 IMDSv1 for now. It is recommended to use EC2 IMDSv2."), [Reason]),
795777
undefined;
796778
Other ->
797-
rabbit_log:warning(
798-
get_instruction_on_instance_metadata_error("Failed to obtain EC2 IMDSv2 token: ~tp. "
779+
?LOG_WARNING(
780+
get_instruction_on_instance_metadata_error("Failed to obtain EC2 IMDSv2 token: ~tp. "
799781
"Falling back to EC2 IMDSv1 for now. It is recommended to use EC2 IMDSv2."), [Other]),
800782
undefined
801783
end,
802784
gun:close(ConnPid),
803785
Result;
804786
{error, Reason} ->
805787
gun:close(ConnPid),
806-
rabbit_log:warning(
807-
get_instruction_on_instance_metadata_error("Failed to connect for EC2 IMDSv2 token: ~tp. "
788+
?LOG_WARNING(
789+
get_instruction_on_instance_metadata_error("Failed to connect for EC2 IMDSv2 token: ~tp. "
808790
"Falling back to EC2 IMDSv1 for now. It is recommended to use EC2 IMDSv2."), [Reason]),
809791
undefined
810792
end;
811793
{error, Reason} ->
812-
rabbit_log:warning(
813-
get_instruction_on_instance_metadata_error("Failed to open connection for EC2 IMDSv2 token: ~tp. "
794+
?LOG_WARNING(
795+
get_instruction_on_instance_metadata_error("Failed to open connection for EC2 IMDSv2 token: ~tp. "
814796
"Falling back to EC2 IMDSv1 for now. It is recommended to use EC2 IMDSv2."), [Reason]),
815797
undefined
816798
end.

0 commit comments

Comments
 (0)