Skip to content

Commit 868422a

Browse files
author
Brujo Benavides
authored
Merge pull request #1 from AdRoll/RTI-5174-otp21
[RTI-5174] Move to rebar3 and OTP21
2 parents de322bf + f0f6695 commit 868422a

File tree

9 files changed

+214
-89
lines changed

9 files changed

+214
-89
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ clean:
99
@rebar3 clean -a
1010

1111
test:
12-
@rebar3 eunit
12+
@rebar3 test

elvis.config

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[
2+
{
3+
elvis,
4+
[
5+
{config,
6+
[#{dirs => ["src"],
7+
filter => "*.erl",
8+
ruleset => erl_files,
9+
rules => [
10+
{elvis_style, line_length, #{limit => 100}},
11+
{elvis_style, nesting_level, #{level => 4}},
12+
%% the default rule included {right, ","} and not {right, "=>"} or {left, "=>"}
13+
{
14+
elvis_style,
15+
operator_spaces,
16+
#{rules => [{right, "++"}, {left, "++"}, {right, "=>"}, {left, "=>"}]}
17+
}
18+
]
19+
},
20+
#{dirs => ["."],
21+
filter => "rebar.config",
22+
ruleset => rebar_config
23+
},
24+
#{dirs => ["."],
25+
filter => "elvis.config",
26+
ruleset => elvis_config
27+
}
28+
]
29+
}
30+
]
31+
}
32+
].

include/erliam.hrl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
-type iso_datetime() :: string(). % "YYYY-MM-DDTHH:MM:SSZ"
33

44
-record(credentials, {
5-
expiration :: iso_datetime(),
6-
security_token :: string(), % required when using temporary credentials
5+
expiration :: undefined | iso_datetime(),
6+
security_token :: undefined | string(), % required when using temporary credentials
77
secret_access_key :: string(),
8-
access_key_id :: string()
8+
access_key_id :: string()
99
}).

old.rebar.config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{erl_opts, [debug_info]}.
2+
3+
{deps, [
4+
{jiffy, ".*", {git, "https://github.com/davisp/jiffy.git", {tag, "0.15.2"}}}
5+
]}.

rebar.config

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
11
% -*- mode: erlang -*-
2-
{erl_opts, [debug_info]}.
2+
{erl_opts, [
3+
warn_unused_vars,
4+
warn_export_all,
5+
warn_shadow_vars,
6+
warn_unused_import,
7+
warn_unused_function,
8+
warn_bif_clash,
9+
warn_unused_record,
10+
warn_deprecated_function,
11+
warn_obsolete_guard,
12+
strict_validation,
13+
warn_export_vars,
14+
warn_exported_vars,
15+
debug_info
16+
]}.
317

4-
{deps, [
5-
{jiffy, ".*",
6-
{git, "https://github.com/davisp/jiffy.git", {tag, "0.14.11"}}}
7-
]}.
18+
{minimum_otp_vsn, "20"}.
19+
20+
{cover_enabled, true}.
21+
22+
{cover_opts, [verbose]}.
23+
24+
{deps, [{jiffy, "0.15.2"}]}.
25+
26+
{dialyzer, [
27+
{warnings, [no_return, error_handling]},
28+
{plt_apps, top_level_deps},
29+
{plt_extra_apps, []},
30+
{plt_location, local},
31+
{base_plt_apps, [erts, stdlib, kernel, inets, crypto, ssl]},
32+
{base_plt_location, global}
33+
]}.
34+
35+
{xref_checks,[
36+
undefined_function_calls,
37+
locals_not_used,
38+
deprecated_function_calls,
39+
deprecated_functions
40+
]}.
41+
42+
{alias, [{test, [xref, dialyzer, lint, eunit, cover]}]}.
43+
44+
{plugins, [{rebar3_lint, "0.1.10"}]}.

rebar.config.script

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
IsRebar3 = erlang:function_exported(rebar3, main, 1),
2+
case IsRebar3 of
3+
false ->
4+
{ok, OldConfig} = file:consult("old.rebar.config"),
5+
OldConfig;
6+
true ->
7+
CONFIG
8+
end.

src/awsv4.erl

Lines changed: 92 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,12 @@ long_term_credentials(AccessKeyId, SecretAccessKey) ->
145145
-spec credentials_from_plist(list({expiration | token | access_key_id | secret_access_key,
146146
iodata() | undefined})) -> credentials().
147147
credentials_from_plist(Plist) ->
148-
lists:foldl(fun ({Name, N}, Acc) ->
149-
setelement(N, Acc, erliam_util:getkey(Name, Plist))
150-
end,
151-
#credentials{},
152-
[{expiration, #credentials.expiration},
153-
{token, #credentials.security_token},
154-
{access_key_id, #credentials.access_key_id},
155-
{secret_access_key, #credentials.secret_access_key}]).
148+
#credentials{
149+
expiration = erliam_util:getkey(expiration, Plist),
150+
security_token = erliam_util:getkey(token, Plist),
151+
access_key_id = erliam_util:getkey(access_key_id, Plist),
152+
secret_access_key = erliam_util:getkey(secret_access_key, Plist)
153+
}.
156154

157155

158156
%%%% INTERNAL FUNCTIONS
@@ -259,75 +257,104 @@ basic_headers_test() ->
259257
"20140629T022822Z", "Kinesis_20131202.ListStreams",
260258
"POST", "/", [], #{},
261259
"something"]),
262-
Expected = flattened([{"authorization",
263-
["AWS4-HMAC-SHA256 Credential=accesskey/20140629/us-east-1/kinesis/aws4_request",
264-
",SignedHeaders=host;x-amz-date;x-amz-security-token;x-amz-target",
265-
",Signature=847fee48568298911772356fe332443bf2679c48fd42695a84aaa0d0e7f28c66"]},
266-
{"x-amz-content-sha256",
267-
"3fc9b689459d738f8c88a3a48aa9e33542016b7a4052e001aaa536fca74813cb"},
268-
{"host","kinesis.us-east-1.amazonaws.com"},
269-
{"x-amz-date","20140629T022822Z"},
270-
{"x-amz-security-token","securitytoken"},
271-
{"x-amz-target","Kinesis_20131202.ListStreams"}]),
260+
Expected = flattened([
261+
{"authorization", [
262+
"AWS4-HMAC-SHA256 Credential=accesskey/20140629/us-east-1/kinesis/aws4_request",
263+
",SignedHeaders=host;x-amz-date;x-amz-security-token;x-amz-target",
264+
",Signature=847fee48568298911772356fe332443bf2679c48fd42695a84aaa0d0e7f28c66"
265+
]},
266+
{"x-amz-content-sha256",
267+
"3fc9b689459d738f8c88a3a48aa9e33542016b7a4052e001aaa536fca74813cb"},
268+
{"host","kinesis.us-east-1.amazonaws.com"},
269+
{"x-amz-date","20140629T022822Z"},
270+
{"x-amz-security-token","securitytoken"},
271+
{"x-amz-target","Kinesis_20131202.ListStreams"}
272+
]),
272273
?assertEqual(Expected, Actual).
273274

274275
aws4_example1_test() ->
275276
%% get-vanilla-query-order-key-case from aws4 test suite
276-
Actual = flattened_headers([#credentials{secret_access_key = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY",
277-
access_key_id = "AKIDEXAMPLE"},
278-
#{aws_date => "20150830T123600Z",
279-
service => "service",
280-
region => "us-east-1",
281-
host => "example.amazonaws.com",
282-
query_params => #{"Param2" => "value2",
283-
"Param1" => "value1"}}]),
284-
Expected = flattened([{"authorization",
285-
["AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request",
286-
",SignedHeaders=host;x-amz-date",
287-
",Signature=b97d918cfa904a5beff61c982a1b6f458b799221646efd99d3219ec94cdf2500"]},
288-
{"x-amz-content-sha256",
289-
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
290-
{"host", "example.amazonaws.com"},
291-
{"x-amz-date", "20150830T123600Z"}]),
277+
Actual = flattened_headers([
278+
#credentials{
279+
secret_access_key = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY",
280+
access_key_id = "AKIDEXAMPLE"
281+
},
282+
#{
283+
aws_date => "20150830T123600Z",
284+
service => "service",
285+
region => "us-east-1",
286+
host => "example.amazonaws.com",
287+
query_params => #{"Param2" => "value2", "Param1" => "value1"}
288+
}
289+
]),
290+
Expected = flattened([
291+
{"authorization", [
292+
"AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request",
293+
",SignedHeaders=host;x-amz-date",
294+
",Signature=b97d918cfa904a5beff61c982a1b6f458b799221646efd99d3219ec94cdf2500"
295+
]},
296+
{"x-amz-content-sha256",
297+
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
298+
{"host", "example.amazonaws.com"},
299+
{"x-amz-date", "20150830T123600Z"}
300+
]),
292301
?assertEqual(Expected, Actual).
293302

294303
aws4_example2_test() ->
295304
%% post-vanilla-query from aws4 test suite
296-
Actual = flattened_headers([#credentials{secret_access_key = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY",
297-
access_key_id = "AKIDEXAMPLE"},
298-
#{aws_date => "20150830T123600Z",
299-
service => "service",
300-
region => "us-east-1",
301-
host => "example.amazonaws.com",
302-
method => "POST",
303-
query_params => #{"Param1" => "value1"}}]),
304-
Expected = flattened([{"authorization",
305-
["AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request",
306-
",SignedHeaders=host;x-amz-date",
307-
",Signature=28038455d6de14eafc1f9222cf5aa6f1a96197d7deb8263271d420d138af7f11"]},
308-
{"x-amz-content-sha256",
309-
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
310-
{"host", "example.amazonaws.com"},
311-
{"x-amz-date", "20150830T123600Z"}]),
305+
Actual = flattened_headers([
306+
#credentials{
307+
secret_access_key = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY",
308+
access_key_id = "AKIDEXAMPLE"
309+
},
310+
#{
311+
aws_date => "20150830T123600Z",
312+
service => "service",
313+
region => "us-east-1",
314+
host => "example.amazonaws.com",
315+
method => "POST",
316+
query_params => #{"Param1" => "value1"}
317+
}
318+
]),
319+
Expected = flattened([
320+
{"authorization", [
321+
"AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request",
322+
",SignedHeaders=host;x-amz-date",
323+
",Signature=28038455d6de14eafc1f9222cf5aa6f1a96197d7deb8263271d420d138af7f11"
324+
]},
325+
{"x-amz-content-sha256",
326+
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
327+
{"host", "example.amazonaws.com"},
328+
{"x-amz-date", "20150830T123600Z"}
329+
]),
312330
?assertEqual(Expected, Actual).
313331

314332
aws4_example3_test() ->
315333
%% get-unreserved from aws4 test suite
316-
Actual = flattened_headers([#credentials{secret_access_key = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY",
317-
access_key_id = "AKIDEXAMPLE"},
318-
#{aws_date => "20150830T123600Z",
319-
service => "service",
320-
region => "us-east-1",
321-
host => "example.amazonaws.com",
322-
path => "/-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"}]),
323-
Expected = flattened([{"authorization",
324-
["AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request",
325-
",SignedHeaders=host;x-amz-date",
326-
",Signature=07ef7494c76fa4850883e2b006601f940f8a34d404d0cfa977f52a65bbf5f24f"]},
327-
{"x-amz-content-sha256",
328-
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
329-
{"host", "example.amazonaws.com"},
330-
{"x-amz-date", "20150830T123600Z"}]),
334+
Actual = flattened_headers([
335+
#credentials{
336+
secret_access_key = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY",
337+
access_key_id = "AKIDEXAMPLE"
338+
},
339+
#{
340+
aws_date => "20150830T123600Z",
341+
service => "service",
342+
region => "us-east-1",
343+
host => "example.amazonaws.com",
344+
path => "/-._~0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
345+
}
346+
]),
347+
Expected = flattened([
348+
{"authorization", [
349+
"AWS4-HMAC-SHA256 Credential=AKIDEXAMPLE/20150830/us-east-1/service/aws4_request",
350+
",SignedHeaders=host;x-amz-date",
351+
",Signature=07ef7494c76fa4850883e2b006601f940f8a34d404d0cfa977f52a65bbf5f24f"
352+
]},
353+
{"x-amz-content-sha256",
354+
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
355+
{"host", "example.amazonaws.com"},
356+
{"x-amz-date", "20150830T123600Z"}
357+
]),
331358
?assertEqual(Expected, Actual).
332359

333360

src/erliam_srv.erl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,13 @@ invalidate() ->
4848

4949
init([]) ->
5050
ets:new(?TAB, [named_table, public, {read_concurrency, true}]),
51-
R = update_credentials(),
52-
timer:send_interval(1000, refresh),
53-
{R, #state{}}.
51+
case update_credentials() of
52+
{error, Error} ->
53+
{stop, Error};
54+
ok ->
55+
timer:send_interval(1000, refresh),
56+
{ok, #state{}}
57+
end.
5458

5559
handle_call(invalidate, _From, State) ->
5660
update_credentials(),
@@ -117,7 +121,8 @@ parse_exptime([Y1,Y2,Y3,Y4, $-, Mon1,Mon2, $-, D1,D2, $T, H1,H2, $:, Min1,Min2,
117121
{list_to_integer([H1,H2]),
118122
list_to_integer([Min1,Min2]),
119123
list_to_integer([S1,S2])}};
120-
parse_exptime([Y1,Y2,Y3,Y4, $-, Mon1,Mon2, $-, D1,D2, $T, H1,H2, $:, Min1,Min2, $:, S1,S2, $.,_,_,_, $Z]) ->
124+
parse_exptime(
125+
[Y1,Y2,Y3,Y4, $-, Mon1,Mon2, $-, D1,D2, $T, H1,H2, $:, Min1,Min2, $:, S1,S2, $.,_,_,_, $Z]) ->
121126
parse_exptime([Y1,Y2,Y3,Y4, $-, Mon1,Mon2, $-, D1,D2, $T, H1,H2, $:, Min1,Min2, $:, S1,S2, $Z]).
122127

123128

src/imds.erl

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,27 @@ metadata_response_to_token_proplist(Body) ->
139139
{<<"AccessKeyId">>, access_key_id},
140140
{<<"SecretAccessKey">>, secret_access_key},
141141
{<<"Token">>, token}],
142+
case get_code(Body) of
143+
{success, Plist} ->
144+
lists:foldl(
145+
fun({Element, Value}, Acc) ->
146+
case erliam_util:getkey(Element, Targets) of
147+
undefined ->
148+
Acc;
149+
AtomName ->
150+
[{AtomName, binary_to_list(Value)} | Acc]
151+
end
152+
end, [], Plist);
153+
Error ->
154+
Error
155+
end.
156+
157+
get_code(Body) ->
142158
case jiffy:decode(Body) of
143159
{Plist} ->
144160
case erliam_util:getkey(<<"Code">>, Plist) of
145161
<<"Success">> ->
146-
lists:foldl(fun ({Element, Value}, Acc) ->
147-
case erliam_util:getkey(Element, Targets) of
148-
undefined ->
149-
Acc;
150-
AtomName ->
151-
[{AtomName, binary_to_list(Value)} | Acc]
152-
end
153-
end,
154-
[],
155-
Plist);
162+
{success, Plist};
156163
_ ->
157164
{error, failed_token_response}
158165
end;
@@ -194,7 +201,11 @@ imds_tokens(Suffix) ->
194201
-include_lib("eunit/include/eunit.hrl").
195202

196203
metadata_response_to_proplist_test() ->
197-
Body = <<"{\"Code\":\"Success\",\"LastUpdated\":\"2014-10-17T15:17:07-07:00\",\"Type\":\"AWS-HMAC\",\"AccessKeyId\":\"XYZZY\",\"SecretAccessKey\":\"FLOOBLE\",\"Token\":\"BAZZLE\",\"Expiration\":\"2014-10-18T09:00:30Z\"}">>,
204+
Body = <<
205+
"{\"Code\":\"Success\",\"LastUpdated\":\"2014-10-17T15:17:07-07:00\","
206+
"\"Type\":\"AWS-HMAC\",\"AccessKeyId\":\"XYZZY\",\"SecretAccessKey\":"
207+
"\"FLOOBLE\",\"Token\":\"BAZZLE\",\"Expiration\":\"2014-10-18T09:00:30Z\"}"
208+
>>,
198209
Result = metadata_response_to_token_proplist(Body),
199210
Expected = [{expiration, "2014-10-18T09:00:30Z"},
200211
{access_key_id, "XYZZY"},

0 commit comments

Comments
 (0)