Permalink
Browse files

If we cannot get a token, return an error.

  • Loading branch information...
1 parent fe4441b commit e895a3d8d435414cf91014d43de9fd5d98e0dec7 @knutin knutin committed Jan 15, 2013
Showing with 26 additions and 19 deletions.
  1. +22 −15 src/dinerl.erl
  2. +4 −4 src/iam.erl
View
@@ -248,22 +248,29 @@ update_data(AccessKeyId, SecretAccessKey, Zone, Options) ->
NowSeconds = calendar:datetime_to_gregorian_seconds(erlang:universaltime()),
SecondsToExpire = CurrentExpirationSeconds - NowSeconds,
- case SecondsToExpire < 120 of
- true ->
- NewToken = iam:get_session_token(AccessKeyId, SecretAccessKey),
-
- ExpirationString = proplists:get_value(expiration, NewToken),
- ApiAccessKeyId = proplists:get_value(access_key_id, NewToken),
- ApiSecretAccessKey = proplists:get_value(secret_access_key, NewToken),
- ApiToken = proplists:get_value(token, NewToken),
- ExpirationSeconds = calendar:datetime_to_gregorian_seconds(iso8601:parse(ExpirationString)),
-
- NewArgs = {ApiAccessKeyId, ApiSecretAccessKey, Zone, Options, ApiToken, NewDate, ExpirationSeconds};
-
- false ->
- NewArgs = {CurrentApiAccessKeyId, CurrentApiSecretAccessKey,
+ NewArgs = case SecondsToExpire < 120 of
+ true ->
+ case iam:get_session_token(AccessKeyId, SecretAccessKey) of
+ {error, Reason} ->
+ {error, Reason};
+ NewToken ->
+ ExpirationString = proplists:get_value(
+ expiration, NewToken),
+ ApiAccessKeyId = proplists:get_value(
+ access_key_id, NewToken),
+ ApiSecretAccessKey = proplists:get_value(
+ secret_access_key, NewToken),
+ ApiToken = proplists:get_value(token, NewToken),
+ ExpirationSeconds = calendar:datetime_to_gregorian_seconds(
+ iso8601:parse(ExpirationString)),
+
+ {ApiAccessKeyId, ApiSecretAccessKey, Zone,
+ Options, ApiToken, NewDate, ExpirationSeconds}
+ end;
+ false ->
+ {CurrentApiAccessKeyId, CurrentApiSecretAccessKey,
Zone, Options, CurrentApiToken, NewDate, CurrentExpirationSeconds}
- end,
+ end,
ets:insert(?DINERL_DATA, {?ARGS_KEY, NewArgs}),
{ok, NewArgs}.
View
@@ -13,8 +13,8 @@ get_session_token(AccessKeyId, SecretAccessKey) ->
case fetch_and_return_url(Url) of
{ok, Body} ->
parse_response(Body);
- E ->
- {error, E}
+ Error ->
+ Error
end.
token_url(AccessKeyId, SecretAccessKey, Action) ->
@@ -47,6 +47,6 @@ fetch_and_return_url(Url) ->
case catch(httpc:request(get, {Url, http_client_headers()}, http_options(), [])) of
{ok, {{_, 200, _}, _Headers, Body}} ->
{ok, Body};
- _E ->
- error
+ Error ->
+ Error
end.

0 comments on commit e895a3d

Please sign in to comment.