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
defmodule ExOvh.Auth.Openstack.Swift.Cache.Webstorage do
@moduledoc :false
alias Openstex.Keystone.V2.Helpers, as: Keystone
alias Openstex.Keystone.V2.Helpers.Identity
defstruct [ :domain, :storage_limit, :server, :endpoint, :username, :password, :tenant_name ]
@type t :: %__MODULE__{domain: String.t, storage_limit: String.t, server: String.t, endpoint: String.t,
username: String.t, password: String.t, tenant_name: String.t}
use ExConstructor
@doc :false
@spec webstorage({atom, atom}, String.t) :: __MODULE__.t | no_return
def webstorage(ovh_client, cdn_name) do
Og.context(__ENV__, :debug)
properties = ExOvh.Ovh.V1.Webstorage.Query.get_service(cdn_name) |> ovh_client.request!() |> Map.fetch!(:body)
|> Og.log_return(__ENV__, :debug)
credentials = ExOvh.Ovh.V1.Webstorage.Query.get_credentials(cdn_name) |> ovh_client.request!() |> Map.fetch!(:body)
|> Og.log_return(__ENV__, :debug)
webstorage =
%{
"domain" => domain,
"storageLimit" => storage_limit,
"server" => server,
"endpoint" => endpoint,
"login" => username,
"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)
end
@doc :false
@spec create_identity({atom, atom}, Keyword.t) :: Identity.t | no_return
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)
end
end