Hash :
fe17ed84
Author :
Date :
2016-05-01T14:43:49
design change. add additional client per swift service.
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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
defmodule ExOvh.Client do
@moduledoc :false
defmacro __using__(opts) do
quote bind_quoted: [opts: opts] do
opts |> Og.log_return(__ENV__, :debug)
# client definitions
#
# defmodule Ovh do
# otp_app = Keyword.fetch!(opts, :otp_app)
# use Openstex.Client, otp_app: otp_app, client: __MODULE__
# def cache(), do: ExOvh.Auth.Ovh.Cache
# end
# defmodule Swift.Webstorage do
# defstruct []
# otp_app = Keyword.fetch!(opts, :otp_app)
# use Openstex.Client, otp_app: otp_app, client: __MODULE__
# def cache(), do: ExOvh.Auth.Openstack.Swift.Cache
# # use Openstex.Swift.V1.Helpers, client: client, config_id: :webstorage
# end
#
# defmodule Swift.Cloudstorage do
# defstruct []
# otp_app = Keyword.fetch!(opts, :otp_app)
# use Openstex.Client, otp_app: otp_app, client: __MODULE__
# def cache(), do: ExOvh.Auth.Openstack.Swift.Cache
# # use Openstex.Swift.V1.Helpers, client: client, config_id: :cloudstorage
# end
# swift_mods =
# if (otp_app != :ex_ovh) do
# Application.get_env(otp_app, __MODULE__)
# else
# Application.get_all_env(otp_app)
# end
# |> Keyword.fetch!(:swift)
# |> Keyword.keys()
# ** THIS IS READY TO GO ONCE SOLVE PROBLEM INSIDE IT **
# for mod <- swift_mods do
# defmodule Module.concat(Helpers.Swift, Utils.module_name(mod)) do
# mod |> Og.log_return(:debug)
# Utils.module_name(mod) |> Og.log_return(:debug)
# Module.concat(Helpers.Swift, Utils.module_name(mod)) |> Og.log_return(:debug)
# use Openstex.Swift.V1.Helpers, client: client, cache: mod
# end
# end
# defmodule Helpers.Keystone do
# use Openstex.Helpers.V2.Keystone, client: Keyword.fetch!(opts, :client)
# end
# public functions
def config() do
otp_app = unquote(opts) |> Keyword.fetch!(:otp_app)
if (otp_app != :ex_ovh) do
Application.get_env(otp_app, __MODULE__)
else
Application.get_all_env(:ex_ovh)
end
end
def ovh_config() do
config() |> Keyword.fetch!(:ovh)
end
def swift_config() do
config() |> Keyword.fetch!(:swift)
end
def start_link(sup_opts \\ []) do
ExOvh.Supervisor.start_link(__MODULE__, ovh_config(), sup_opts)
end
end
end
@callback start_link() :: :ok | {:error, {:already_started, pid}} | {:error, term}
@callback config() :: :nil | Keyword.t
@callback ovh_config() :: :nil | map
@callback swift_config() :: :nil | map
end
#
#def ovh_config() do
# otp_app = Keyword.get(unquote(opts), :otp_app, :ex_ovh)
# if (otp_app != :ex_ovh) do
# Application.get_env(otp_app, __MODULE__) |> Keyword.fetch!(:ovh)
# else
# Application.get_all_env(otp_app) |> Keyword.fetch!(:ovh)
# end
#end
#
#def swift_config() do
# otp_app = Keyword.get(unquote(opts), :otp_app, :ex_ovh)
# if (otp_app != :ex_ovh) do
# Application.get_env(otp_app, __MODULE__) |> Keyword.fetch!(:swift)
# else
# Application.get_all_env(otp_app) |> Keyword.fetch!(:swift)
# end
# config() |> Keyword.fetch!(:swift)
#end