Skip to content

Commit

Permalink
Merge pull request #44 from CargoSense/fix_42
Browse files Browse the repository at this point in the history
Fix 42
  • Loading branch information
benwilson512 committed Jun 29, 2015
2 parents cc0ac7f + 07a9535 commit a551280
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
8 changes: 8 additions & 0 deletions lib/ex_aws/auth.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ defmodule ExAws.Auth do
import ExAws.Auth.Utils
alias Timex.DateFormat

@moduledoc false

def headers(http_method, url, service, config, headers, body) do
now = %{Timex.Date.now | ms: 0}
headers = [
Expand All @@ -22,7 +24,13 @@ defmodule ExAws.Auth do
now)

[{"Authorization", auth_header} | headers ]
|> handle_temp_credentials(config)
end

def handle_temp_credentials(headers, %{security_token: token}) do
[{"X-Amz-Security-Token", token} | headers]
end
def handle_temp_credentials(headers, _), do: headers

def auth_header(access_key, secret_key, http_method, url, region, service, headers, body, now) do
date = DateFormat.format!(now, "%Y%m%d", :strftime)
Expand Down
17 changes: 10 additions & 7 deletions lib/ex_aws/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,28 @@ defmodule ExAws.Config do
def retrieve_runtime_config(%{config: config} = client) do
new_config = config
|> Enum.reduce(%{}, fn {k, v}, config ->
Map.put(config, k, retrieve_runtime_value(k, v, client))
case retrieve_runtime_value(v, client) do
%{} = result -> Map.merge(config, result)
value -> Map.put(config, k, value)
end
end)

%{client | config: new_config}
end

def retrieve_runtime_value(_, {:system, env_key}, _) do
def retrieve_runtime_value({:system, env_key}, _) do
System.get_env(env_key)
end
def retrieve_runtime_value(k, :instance_role, client) do
def retrieve_runtime_value(:instance_role, client) do
client
|> ExAws.Config.AuthCache.get
|> Map.get(k)
|> Map.take([:access_key_id, :secret_access_key, :security_token])
end
def retrieve_runtime_value(key, values, client) when is_list(values) do
def retrieve_runtime_value(values, client) when is_list(values) do
values
|> Stream.map(&retrieve_runtime_value(key, &1, client))
|> Stream.map(&retrieve_runtime_value(&1, client))
|> Enum.find(&(&1))
end
def retrieve_runtime_value(_, value, _), do: value
def retrieve_runtime_value(value, _), do: value

end
1 change: 1 addition & 0 deletions lib/ex_aws/instance_meta.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ defmodule ExAws.InstanceMeta do
%{
access_key_id: result["AccessKeyId"],
secret_access_key: result["SecretAccessKey"],
security_token: result["Token"],
expiration: result["Expiration"]
}
end
Expand Down

0 comments on commit a551280

Please sign in to comment.