Commit 174d3a15d69560032d5aa9b0c3b2a2c6413a2717

Stephen Moloney 2016-05-23T12:12:36

tidy up compilation errors

diff --git a/docs/getting_started_advanced.md b/docs/getting_started_advanced.md
index edfbd1f..6063aac 100644
--- a/docs/getting_started_advanced.md
+++ b/docs/getting_started_advanced.md
@@ -75,6 +75,7 @@ config :ex_ovh,
         cloudstorage: [
                         tenant_id: System.get_env("MY_APP_OVH_CLIENT_CLOUDSTORAGE_TENANT_ID"), # mandatory, corresponds to a project id
                         user_id: System.get_env("MY_APP_OVH_CLIENT_CLOUDSTORAGE_USER_ID"), # optional, if absent a user will be created using the ovh api.
+                        account_temp_url_key: System.get_env("MY_APP_OVH_CLIENT_CLOUDSTORAGE_TEMP_URL_KEY"), # defaults to :nil if absent and won't be added if == :nil.
                         keystone_endpoint: "https://auth.cloud.ovh.net/v2.0", # default endpoint for keystone (identity) auth
                         region: :nil, # defaults to "SBG1" if set to :nil
                         type: :cloudstorage
diff --git a/docs/getting_started_basic.md b/docs/getting_started_basic.md
index f0897d5..a764f8d 100644
--- a/docs/getting_started_basic.md
+++ b/docs/getting_started_basic.md
@@ -72,6 +72,7 @@ config :ex_ovh,
         cloudstorage: [
                         tenant_id: System.get_env("EX_OVH_CLOUDSTORAGE_TENANT_ID"), # mandatory, corresponds to a project id
                         user_id: System.get_env("EX_OVH_CLOUDSTORAGE_USER_ID"), # optional, if absent a user will be created using the ovh api.
+                        account_temp_url_key: System.get_env("EX_OVH_CLOUDSTORAGE_TEMP_URL_KEY"), # defaults to :nil if absent and won't be added if == :nil.
                         keystone_endpoint: "https://auth.cloud.ovh.net/v2.0", # default endpoint for keystone (identity) auth
                         region: :nil, # defaults to "SBG1" if set to :nil
                         type: :cloudstorage
diff --git a/lib/auth/openstack/swift/cache.ex b/lib/auth/openstack/swift/cache.ex
index e0b1ce6..bffeb86 100644
--- a/lib/auth/openstack/swift/cache.ex
+++ b/lib/auth/openstack/swift/cache.ex
@@ -4,7 +4,6 @@ defmodule ExOvh.Auth.Openstack.Swift.Cache do
   use Openstex.Cache
   alias ExOvh.Auth.Openstack.Swift.Cache.Cloudstorage
   alias ExOvh.Auth.Openstack.Swift.Cache.Webstorage
-  alias Openstex.Keystone.V2.Helpers, as: Keystone
   alias Openstex.Keystone.V2.Helpers.Identity
   import ExOvh.Utils, only: [ets_tablename: 1]
   @get_identity_retries 5
@@ -22,7 +21,7 @@ defmodule ExOvh.Auth.Openstack.Swift.Cache do
   # Pulic Opestex.Cache callbacks (public 'interface' to the Cache module)
 
   def get_swift_public_url(swift_client) do
-    public_url = get_identity(swift_client)
+    get_identity(swift_client)
     |> Map.get(:service_catalog)
     |> Enum.find(fn(%Identity.Service{} = service) ->  service.name == "swift" end)
     |> Map.get(:endpoints)
@@ -88,7 +87,7 @@ defmodule ExOvh.Auth.Openstack.Swift.Cache do
     {:stop, :shutdown, :ok, state}
   end
 
-  def terminate(:shutdown, {swift_client, identity}) do
+  def terminate(:shutdown, {swift_client, _identity}) do
     Og.context(__ENV__, :debug)
     :ets.delete(ets_tablename(swift_client)) # explicilty remove
     :ok
@@ -106,7 +105,7 @@ defmodule ExOvh.Auth.Openstack.Swift.Cache do
     Og.context(__ENV__, :debug)
     Cloudstorage.create_identity({ovh_client, swift_client}, config)
   end
-  defp create_identity({ovh_client, swift_client}, config, type) do
+  defp create_identity({_ovh_client, _swift_client}, _config, type) do
     Og.context(__ENV__, :debug)
     raise "create_identity/3 is only supported for the :webstorage and :cloudstorage types, #{inspect(type)}"
   end
diff --git a/lib/auth/openstack/swift/cloudstorage.ex b/lib/auth/openstack/swift/cloudstorage.ex
index 6352da3..fd846c6 100644
--- a/lib/auth/openstack/swift/cloudstorage.ex
+++ b/lib/auth/openstack/swift/cloudstorage.ex
@@ -6,12 +6,11 @@ defmodule ExOvh.Auth.Openstack.Swift.Cache.Cloudstorage do
 
   @doc :false
   @spec create_identity({atom, atom}, Keyword.t) :: Identity.t | no_return
-  def create_identity({ovh_client, swift_client}, config) do
+  def create_identity({ovh_client, _swift_client}, config) do
     Og.context(__ENV__, :debug)
 
     tenant_id = Keyword.fetch!(config, :tenant_id)
     user_id = Keyword.get(config, :user_id, :nil)
-    region = Keyword.get(config, :region, "SBG1")
 
     user_id =
     case user_id do
@@ -41,7 +40,7 @@ defmodule ExOvh.Auth.Openstack.Swift.Cache.Cloudstorage do
     # make sure the regenerate credentials (in the external ovh api) had a chance to take effect
     :timer.sleep(1000)
 
-    identity = Keystone.authenticate!(endpoint, username, password, [tenant_id: tenant_id])
+    Keystone.authenticate!(endpoint, username, password, [tenant_id: tenant_id])
   end
 
 
diff --git a/lib/auth/openstack/swift/webstorage.ex b/lib/auth/openstack/swift/webstorage.ex
index 005307e..b2cfb33 100644
--- a/lib/auth/openstack/swift/webstorage.ex
+++ b/lib/auth/openstack/swift/webstorage.ex
@@ -20,33 +20,30 @@ defmodule ExOvh.Auth.Openstack.Swift.Cache.Webstorage do
 
     webstorage =
     %{
-      "domain" => domain,
-      "storageLimit" => storage_limit,
-      "server" => server,
-      "endpoint" => endpoint,
+      "domain" => _domain,
+      "storageLimit" => _storage_limit,
+      "server" => _server,
+      "endpoint" => _endpoint,
       "login" => username,
-      "password" => password,
+      "password" => _password,
       "tenant" => tenant_name
     } = Map.merge(properties, credentials)
     webstorage = webstorage
     |> Map.delete("tenant") |> Map.delete("login")
     |> Map.put("username", username) |> Map.put("tenantName", tenant_name)
-    webstorage = __MODULE__.new(webstorage)
+    __MODULE__.new(webstorage)
   end
 
 
   @doc :false
   @spec create_identity({atom, atom}, Keyword.t) :: Identity.t | no_return
-  def create_identity({ovh_client, swift_client}, config) do
+  def create_identity({ovh_client, _swift_client}, config) do
     Og.context(__ENV__, :debug)
 
     cdn_name = Keyword.fetch!(config, :cdn_name)
     webstorage = webstorage(ovh_client, cdn_name)
-    |> Og.log_return(__ENV__, :debug)
     %{endpoint: endpoint, username: username, password: password, tenant_name: tenant_name} = webstorage
-    |> Og.log_return(__ENV__, :debug)
-    identity = Keystone.authenticate!(endpoint, username, password, [tenant_name: tenant_name])
-    |> Og.log_return(__ENV__, :debug)
+    Keystone.authenticate!(endpoint, username, password, [tenant_name: tenant_name])
   end
 
 
diff --git a/lib/auth/ovh/auth.ex b/lib/auth/ovh/auth.ex
index 941604e..957d87e 100644
--- a/lib/auth/ovh/auth.ex
+++ b/lib/auth/ovh/auth.ex
@@ -1,7 +1,6 @@
 defimpl Openstex.Auth, for: ExOvh.Ovh.Query do
   @moduledoc :false
 
-  alias ExOvh.Utils
   alias ExOvh.Ovh.Query
   alias ExOvh.Auth.Ovh.Cache
   @default_headers [{"Content-Type", "application/json; charset=utf-8"}]
@@ -40,7 +39,7 @@ defimpl Openstex.Auth, for: ExOvh.Ovh.Query do
   # Private
 
 
-  defp headers([app_secret, app_key, consumer_key, method, uri, body] = opts, client) do
+  defp headers([app_secret, app_key, consumer_key, method, uri, body] = _opts, client) do
     time = :os.system_time(:seconds) + Cache.get_time_diff(client)
     headers = [
                 {"X-Ovh-Application", app_key},
@@ -53,7 +52,7 @@ defimpl Openstex.Auth, for: ExOvh.Ovh.Query do
   end
 
 
-  defp sign_request([app_secret, consumer_key, method, uri, body, time] = opts) do
+  defp sign_request([_app_secret, _consumer_key, _method, _uri, _body, _time] = opts) do
     pre_hash = Enum.join(opts, "+")
     post_hash = :crypto.hash(:sha, pre_hash) |> Base.encode16(case: :lower)
     "$1$" <> post_hash
diff --git a/lib/auth/ovh/cache.ex b/lib/auth/ovh/cache.ex
index cc43cda..3e03e99 100644
--- a/lib/auth/ovh/cache.ex
+++ b/lib/auth/ovh/cache.ex
@@ -33,7 +33,7 @@ defmodule ExOvh.Auth.Ovh.Cache do
     {:reply, diff, diff}
   end
 
-  def terminate(:shutdown, state) do
+  def terminate(:shutdown, _state) do
     Og.context(__ENV__, :warn)
     Og.log_return(__ENV__, "gen_server #{__MODULE__} shutting down", :warn)
     :ok
@@ -63,7 +63,7 @@ defmodule ExOvh.Auth.Ovh.Cache do
     httpoison_opts = client.httpoison_config()
     options = httpoison_opts
     resp = HTTPoison.request!(method, uri, body, headers, options)
-    api_time = Poison.decode!(resp.body)
+    Poison.decode!(resp.body)
   end
 
 
diff --git a/lib/client.ex b/lib/client.ex
index 10e256c..e812f87 100644
--- a/lib/client.ex
+++ b/lib/client.ex
@@ -67,6 +67,7 @@ defmodule ExOvh.Client do
                 cloudstorage: [
                                 tenant_id: System.get_env("MY_APP_MY_CLIENT_CLOUDSTORAGE_TENANT_ID"), # mandatory, corresponds to a project id
                                 user_id: System.get_env("MY_APP_MY_CLIENT_CLOUDSTORAGE_USER_ID"), # optional, if absent a user will be created using the ovh api.
+                                account_temp_url_key: System.get_env("MY_APP_MY_CLIENT_CLOUDSTORAGE_TEMP_URL_KEY"), # defaults to :nil if absent and won't be added if == :nil.
                                 keystone_endpoint: "https://auth.cloud.ovh.net/v2.0", # default endpoint for keystone (identity) auth
                                 region: :nil, # defaults to "SBG1" if set to :nil
                                 type: :cloudstorage
@@ -129,30 +130,39 @@ defmodule ExOvh.Client do
       defmodule Swift.Webstorage do
         @moduledoc ExOvh.Client.swift_docs()
         use Openstex.Client, client: __MODULE__
+        use Openstex.Swift.V1.Helpers, client: __MODULE__
+
+        @doc :false
         def cache(), do: ExOvh.Auth.Openstack.Swift.Cache
+
         @doc :false
         def config(), do: List.last(__ENV__.context_modules).config() |> Keyword.fetch!(:swift) |> Keyword.fetch!(:webstorage)
-        use Openstex.Swift.V1.Helpers, client: __MODULE__
+
         @doc "Returns the swift account string."
         @spec account() :: String.t
         def account(), do: __MODULE__.cache().get_swift_account(__MODULE__)
+
       end
 
       defmodule Swift.Cloudstorage do
         @moduledoc ExOvh.Client.swift_docs()
         use Openstex.Client, client: __MODULE__
+        use Openstex.Swift.V1.Helpers, client: __MODULE__
+
+        @doc :false
         def cache(), do: ExOvh.Auth.Openstack.Swift.Cache
+
         @doc :false
         def config() do
           List.last(__ENV__.context_modules).config() |> Keyword.fetch!(:swift) |> Keyword.fetch!(:cloudstorage)
           |> Keyword.merge(Defaults.cloudstorage(), fn(_k, v1, v2) -> if v1 == :nil, do: v2, else: v1 end)
         end
-        use Openstex.Swift.V1.Helpers, client: __MODULE__
+
         @doc "Returns the swift account string."
         @spec account() :: String.t
         def account(), do: __MODULE__.cache().get_swift_account(__MODULE__)
-      end
 
+      end
 
     end
   end
diff --git a/lib/mix/tasks/ovh.ex b/lib/mix/tasks/ovh.ex
index 2689828..4660cf4 100644
--- a/lib/mix/tasks/ovh.ex
+++ b/lib/mix/tasks/ovh.ex
@@ -35,7 +35,6 @@ defmodule Mix.Tasks.Ovh do
   [mix task advanced](https://hexdocs.pm/ex_ovh/doc/mix_task_advanced.md.html) for practical steps involved in running the hubic mix task.
   """
   use Mix.Task
-  alias ExOvh.Utils
   alias ExOvh.Ovh.Defaults
   @default_headers [{"Content-Type", "application/json; charset=utf-8"}]
   @default_options [ timeout: 30000, recv_timeout: (60000 * 1) ]
@@ -77,7 +76,7 @@ defmodule Mix.Tasks.Ovh do
 
   defp parse_args(args) do
     {opts, _, _} = OptionParser.parse(args)
-    {opts, opts_map } = opts
+    {_opts, opts_map} = opts
     |> has_required_args()
     |> parsers_login()
     |> parsers_password()
@@ -112,7 +111,7 @@ defmodule Mix.Tasks.Ovh do
 
   defp parsers_login({opts, acc}), do: {opts, Map.merge(acc, %{login: Keyword.fetch!(opts, :login)}) }
   defp parsers_password({opts, acc}), do: {opts, Map.merge(acc, %{ password: Keyword.fetch!(opts, :password)}) }
-  defp parsers_app_name({opts, acc}), do: {opts, Map.merge(acc, %{ application_name: Keyword.fetch!(opts, :appname)}) }
+  # defp parsers_app_name({opts, acc}), do: {opts, Map.merge(acc, %{ application_name: Keyword.fetch!(opts, :appname)}) }
   defp parsers_endpoint({opts, acc}) do
     endpoint = Keyword.get(opts, :endpoint, :nil)
     endpoint =
@@ -331,7 +330,7 @@ defmodule Mix.Tasks.Ovh do
     inputs = Floki.find(resp_body, "form input") ++
     Floki.find(resp_body, "form select")
     |> List.flatten()
-    |> Enum.filter(fn({type, input, options}) ->
+    |> Enum.filter(fn({_type, input, _options}) ->
       :proplists.get_value("name", input) !== "identifiant"
     end)
     if Enum.any?(inputs, fn(input) -> input === [] end), do: raise "Inputs should not be empty"
@@ -339,11 +338,11 @@ defmodule Mix.Tasks.Ovh do
   end
 
 
-  defp build_ck_binding_request(inputs, %{login: login, password: password} = opts_map) do
+  defp build_ck_binding_request(inputs, %{login: login, password: password} = _opts_map) do
     Og.context(__ENV__, :debug)
 
     {acc, _index, _max} =
-    Enum.reduce(inputs, {"", 1, Enum.count(inputs)}, fn({type, input, options}, acc) ->
+    Enum.reduce(inputs, {"", 1, Enum.count(inputs)}, fn({type, input, _options}, acc) ->
       {name_val, value} =
       cond do
         type == "input" &&  {"name", "credentialToken"} in input ->
diff --git a/lib/ovh/v1/cloud/query.ex b/lib/ovh/v1/cloud/query.ex
index 828d6d2..c342932 100644
--- a/lib/ovh/v1/cloud/query.ex
+++ b/lib/ovh/v1/cloud/query.ex
@@ -307,10 +307,13 @@ defmodule ExOvh.Ovh.V1.Cloud.Query do
   """
   @spec get_prices(String.t | :nil, String.t | :nil) :: Query.t
   def get_prices(region \\ :nil, flavor_id \\ :nil) do
-    params = if region == :nil and flavor_id == :nil, do: :nil
-    params = if region != :nil and flavor_id == :nil, do: %{ "region" => region }
-    params = if region == :nil and flavor_id != :nil, do: %{ "flavorId" => flavor_id }
-    params = if region != :nil and flavor_id != :nil, do: %{ "region" => region, "flavorId" => flavor_id }
+    params =
+    cond do
+      region == :nil and flavor_id == :nil -> :nil
+      region != :nil and flavor_id == :nil -> %{"region" => region}
+      region == :nil and flavor_id != :nil -> %{"flavorId" => flavor_id}
+      region != :nil and flavor_id != :nil -> %{ "region" => region, "flavorId" => flavor_id }
+    end
     %Query{
           method: :get,
           uri: "/cloud/createProject",
@@ -494,7 +497,7 @@ defmodule ExOvh.Ovh.V1.Cloud.Query do
   @spec project_consumption(String.t, String.t, String.t) :: Query.t
   def project_consumption(service_name, date_from \\ :nil, date_to \\ :nil) do
     date_from = if date_from == :nil, do: Calendar.DateTime.now_utc!() |> Calendar.DateTime.add!(-(60*60*24*28)) |> Calendar.DateTime.Format.rfc3339(), else: date_from
-    date_to = if date_from == :nil, do: Calendar.DateTime.now_utc!() |> Calendar.DateTime.Format.rfc3339(), else: date_from
+    date_to = if date_to == :nil, do: Calendar.DateTime.now_utc!() |> Calendar.DateTime.Format.rfc3339(), else: date_to
     %Query{
           method: :get,
           uri: "/cloud/project/#{service_name}/consumption",
@@ -523,7 +526,7 @@ defmodule ExOvh.Ovh.V1.Cloud.Query do
   @spec project_bills(String.t, String.t, String.t) :: Query.t
   def project_bills(service_name, date_from \\ :nil, date_to \\ :nil) do
     date_from = if date_from == :nil, do: Calendar.DateTime.now_utc!() |> Calendar.DateTime.add!(-(60*60*24*28)) |> Calendar.DateTime.Format.rfc3339(), else: date_from
-    date_to = if date_from == :nil, do: Calendar.DateTime.now_utc!() |> Calendar.DateTime.Format.rfc3339(), else: date_from
+    date_to = if date_to == :nil, do: Calendar.DateTime.now_utc!() |> Calendar.DateTime.Format.rfc3339(), else: date_to
     %Query{
           method: :get,
           uri: "/cloud/project/#{service_name}/bill",
diff --git a/lib/supervisor.ex b/lib/supervisor.ex
index a925057..9a176e5 100644
--- a/lib/supervisor.ex
+++ b/lib/supervisor.ex
@@ -11,7 +11,7 @@ defmodule ExOvh.Supervisor do
   #  Public
 
 
-  def start_link(client, opts) do
+  def start_link(client, _opts) do
     Og.context(__ENV__, :debug)
     Supervisor.start_link(__MODULE__, client, [name: client])
   end
@@ -38,7 +38,7 @@ defmodule ExOvh.Supervisor do
       :nil ->
         Og.log("No webstorage config found. Skipping initiation of OVH webstorage cdn service", :debug)
         sup_tree
-      webstorage_config ->
+      _webstorage_config ->
         webstorage_client = Module.concat(client, Swift.Webstorage)
         sup_tree ++
         [{webstorage_client, {SwiftCache, :start_link, [{ovh_client, webstorage_client}]}, :permanent, 10_000, :worker, [SwiftCache]}]
@@ -49,7 +49,7 @@ defmodule ExOvh.Supervisor do
       :nil ->
         Og.log("No cloudstorage config found. Skipping initiation of OVH cloudstorage service", :debug)
         sup_tree
-      cloudstorage_config ->
+      _cloudstorage_config ->
         cloudstorage_client = Module.concat(client, Swift.Cloudstorage)
         sup_tree ++
         [{cloudstorage_client, {SwiftCache, :start_link, [{ovh_client, cloudstorage_client}]}, :permanent, 10_000, :worker, [SwiftCache]}]
diff --git a/lib/utils/utils.ex b/lib/utils/utils.ex
index 9971c5c..ecfa238 100644
--- a/lib/utils/utils.ex
+++ b/lib/utils/utils.ex
@@ -1,9 +1,5 @@
 defmodule ExOvh.Utils do
   @moduledoc false
-  alias ExOvh.Auth.Ovh.Cache, as: OvhCache
-  alias ExOvh.Auth.Openstack.Swift.Cache, as: SwiftCache
-  alias ExOvh.Ovh.Defaults
-
 
   @doc """
   For naming an ets table to incorporate the name of the client.