From 235747a66d5c487c8d154a0f2cbd6b58bfc561bd Mon Sep 17 00:00:00 2001 From: Brujo Benavides Date: Thu, 27 May 2021 16:56:45 +0200 Subject: [PATCH] Adjust for OTP23 (#18) * Adjust for OTP23 * Get rid of encode_hex for good, thanks to @zerth's advice * Update libs * Format --- rebar.config | 4 ++-- src/awsv4.erl | 6 ++++-- src/imds.erl | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/rebar.config b/rebar.config index d6ecbf2..0a2bc86 100644 --- a/rebar.config +++ b/rebar.config @@ -39,7 +39,7 @@ {alias, [{test, [format, lint, hank, xref, dialyzer, eunit, cover]}]}. {project_plugins, - [{rebar3_hex, "~> 6.11.0"}, + [{rebar3_hex, "~> 6.11.4"}, {rebar3_format, "~> 1.0.0"}, {rebar3_lint, "~> 0.4.0"}, - {rebar3_hank, "~> 0.4.0"}]}. + {rebar3_hank, "~> 1.1.2"}]}. diff --git a/src/awsv4.erl b/src/awsv4.erl index fe4ab54..3a18c8b 100644 --- a/src/awsv4.erl +++ b/src/awsv4.erl @@ -76,7 +76,9 @@ headers(#credentials{secret_access_key = SecretAccessKey, Hash = sha256, Algorithm = "AWS4-HMAC-SHA256", SigningKey = - lists:foldl(fun(E, A) -> crypto:hmac(Hash, A, E) end, "AWS4" ++ SecretAccessKey, Scope), + lists:foldl(fun(E, A) -> crypto:mac(hmac, Hash, A, E) end, + "AWS4" ++ SecretAccessKey, + Scope), Headers = lists:keysort(1, @@ -116,7 +118,7 @@ headers(#credentials{secret_access_key = SecretAccessKey, CredentialScope, hexlify(crypto:hash(Hash, CanonicalRequest))]), - Signature = hexlify(crypto:hmac(Hash, SigningKey, StringToSign)), + Signature = hexlify(crypto:mac(hmac, Hash, SigningKey, StringToSign)), [{"authorization", [Algorithm, diff --git a/src/imds.erl b/src/imds.erl index 5c4ac9e..a3ed8e8 100644 --- a/src/imds.erl +++ b/src/imds.erl @@ -40,7 +40,7 @@ public_hostname() -> get_session_token() -> case role_name() of {ok, RoleName} -> - Result = imds_tokens(["iam/security-credentials/", http_uri:encode(RoleName)]), + Result = imds_tokens(["iam/security-credentials/", RoleName]), awsv4:credentials_from_plist(Result); Error -> Error @@ -178,7 +178,7 @@ call_with_retry(_, _, _, _, _) -> {error, retries_exceeded}. imds_url(Suffix) -> - lists:flatten(["http://", ?IMDS_HOST, "/", ?IMDS_VERSION, "/meta-data/", Suffix]). + uri_string:normalize(["http://", ?IMDS_HOST, "/", ?IMDS_VERSION, "/meta-data/", Suffix]). imds_text(Suffix) -> imds_text_response(imds_url(Suffix)).