bug fix. get_token, get_credentials. client needed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
diff --git a/lib/hubic/hubic_api/auth.ex b/lib/hubic/hubic_api/auth.ex
index 1d90c0e..fa0b7cb 100644
--- a/lib/hubic/hubic_api/auth.ex
+++ b/lib/hubic/hubic_api/auth.ex
@@ -24,7 +24,7 @@ defmodule ExOvh.Hubic.HubicApi.Auth do
uri = uri(config, uri)
if params !== :nil and params !== "" and is_map(params), do: uri = uri <> "?" <> URI.encode_query(params)
if params !== :nil and params !== "" and is_map(params) === :false, do: uri = uri <> URI.encode_www_form(params)
- options = %{ headers: headers(method), timeout: @timeout }
+ options = %{ headers: headers(client, method), timeout: @timeout }
{method, uri, options}
end
@@ -32,7 +32,7 @@ defmodule ExOvh.Hubic.HubicApi.Auth do
config = config(client)
uri = uri(config, uri)
if params !== "" and params !== :nil and is_map(params), do: params = Poison.encode!(params)
- options = %{ body: params, headers: headers(method), timeout: @timeout }
+ options = %{ body: params, headers: headers(client, method), timeout: @timeout }
{method, uri, options}
end
@@ -78,12 +78,11 @@ defmodule ExOvh.Hubic.HubicApi.Auth do
# Private
###################
- defp default_headers(), do: %{ "Authorization": "Bearer " <> Cache.get_token() }
- defp headers(method) when method in [:post, :put] do
- Map.merge(default_headers(), %{ "Content-Type": "application/json;charset=utf-8" })
+ defp default_headers(client), do: %{ "Authorization": "Bearer " <> Cache.get_token(client) }
+ defp headers(client, method) when method in [:post, :put] do
+ Map.merge(default_headers(client), %{ "Content-Type": "application/json;charset=utf-8" })
end
- defp headers(method) when method in [:get, :delete], do: default_headers()
-
+ defp headers(client, method) when method in [:get, :delete], do: default_headers(client)
defp config(), do: Cache.get_config(ExOvh)
defp config(client), do: Cache.get_config(client)
diff --git a/lib/hubic/hubic_api/cache.ex b/lib/hubic/hubic_api/cache.ex
index 6295c25..ce507c4 100644
--- a/lib/hubic/hubic_api/cache.ex
+++ b/lib/hubic/hubic_api/cache.ex
@@ -136,7 +136,7 @@ defmodule ExOvh.Hubic.HubicApi.Cache do
raise "Problem retrieving the access token from ets table"
else
:timer.sleep(@get_token_sleep_interval)
- get_token(index + 1)
+ get_token(client, index + 1)
end
else
tokens["access_token"]
@@ -146,7 +146,7 @@ defmodule ExOvh.Hubic.HubicApi.Cache do
raise "Problem retrieving the access token from ets table"
else
:timer.sleep(@get_token_sleep_interval)
- get_token(index + 1)
+ get_token(client, index + 1)
end
end
end
diff --git a/lib/hubic/openstack_api/cache.ex b/lib/hubic/openstack_api/cache.ex
index a4265ab..e2863f1 100644
--- a/lib/hubic/openstack_api/cache.ex
+++ b/lib/hubic/openstack_api/cache.ex
@@ -124,7 +124,7 @@ defmodule ExOvh.Hubic.OpenstackApi.Cache do
raise "Problem retrieving the openstack credentials from ets table"
else
:timer.sleep(@get_credentials_sleep_interval)
- get_credentials(index + 1)
+ get_credentials(client, index + 1)
end
else
credentials
@@ -134,7 +134,7 @@ defmodule ExOvh.Hubic.OpenstackApi.Cache do
raise "Problem retrieving the openstack credentials from ets table"
else
:timer.sleep(@get_credentials_sleep_interval)
- get_credentials(index + 1)
+ get_credentials(client, index + 1)
end
end
end