Commit 57aa24206293cc39dc6f37544bb52c200d308145

Stephen Moloney 2016-02-12T21:44:23

refactor and new code for webstorage openstack requests

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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
diff --git a/lib/ovh/openstack_api/request.ex b/lib/ovh/openstack_api/request.ex
index f27a84d..c049414 100644
--- a/lib/ovh/openstack_api/request.ex
+++ b/lib/ovh/openstack_api/request.ex
@@ -1,19 +1,21 @@
 defmodule ExOvh.Ovh.OpenstackApi.Request do
   @moduledoc ~s"""
-  Delegate the request to the appropriate module depending on the query uri.
+  Delegate the request to the appropriate module depending on the query uri. <<REMOVE LINE>>
+  Delegate the request to the appropriate module depending on the opts.
 
     For example,
                 /cdn/webstorage ==> ExOvh.Ovh.Openstack.Webstorage.Request
                 /cdn/cloud ==> ExOvh.Ovh.Openstack.Cloud.Request
   """
-  alias ExOvh.Ovh.Openstack.Webstorage.Request, as: WebStorage
+  alias ExOvh.Ovh.OpenstackApi.Webstorage.Request, as: WebStorage
 
 
-  @spec request(client :: atom, query :: ExOvh.Client.raw_query_t)
+  @spec request(client :: atom, query :: ExOvh.Client.raw_query_t, opts :: map)
                 :: {:ok, ExOvh.Client.response_t} | {:error, ExOvh.Client.response_t}
-  def request(client, {method, uri, params} = query) do
-    # cond do --> check for various request types .. raise if none found.
-    WebStorage.request(client, query)
+  def request(client, {method, uri, params} = query, %{ webstorage: service } = opts) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
+    LoggingUtils.log_return("***SERVICE*** #{service}", :warn)
+    WebStorage.request(client, query, service)
   end
 
 
diff --git a/lib/ovh/openstack_api/webstorage/auth.ex b/lib/ovh/openstack_api/webstorage/auth.ex
index bddd485..8c8ce50 100644
--- a/lib/ovh/openstack_api/webstorage/auth.ex
+++ b/lib/ovh/openstack_api/webstorage/auth.ex
@@ -1,7 +1,6 @@
-defmodule ExOvh.Ovh.Openstack.Webstorage.Auth do
-  alias ExOvh.Ovh.OvhApi.Cache, as: ClientCache
-  alias ExOvh.Ovh.Openstack.Webstorage.Cache, as: OpenCache
-  import ExOvh.Query.Ovh.Webstorage
+defmodule ExOvh.Ovh.OpenstackApi.Webstorage.Auth do
+  alias ExOvh.Ovh.OpenstackApi.Webstorage.Cache, as: WebStorageCache
+  # import ExOvh.Query.Ovh.Webstorage, only: []
 
   @methods [:get, :post, :put, :delete]
   @timeout 10_000
@@ -12,22 +11,24 @@ defmodule ExOvh.Ovh.Openstack.Webstorage.Auth do
   ############################
 
 
-  @spec prepare_request(client :: atom, query :: ExOvh.Client.raw_query_t)
+  @spec prepare_request(client :: atom, query :: ExOvh.Client.raw_query_t, service :: String.t)
                      :: ExOvh.Client.query_t
   def prepare_request(client, query)
 
-  def prepare_request(client, {method, uri, params} = query) when method in [:get, :delete] do
-    uri =  OpenCache.get_endpoint(client) <> uri
+  def prepare_request(client, {method, uri, params} = query, service) when method in [:get, :delete] do
+    uri =  WebStorageCache.get_swift_endpoint(client, service) <> uri
     if params !== :nil and params !== "", do: uri = uri <> "?" <> URI.encode_query(params)
-    options = %{ headers: headers(client), timeout: @timeout }
+    options = %{ headers: headers(client, service), timeout: @timeout }
     {method, uri, options}
+    |> LoggingUtils.log_return(:debug)
   end
 
-  def prepare_request(client, {method, uri, params} = query) when method in [:post, :put] do
-    uri =  OpenCache.get_endpoint(client) <> uri
+  def prepare_request(client, {method, uri, params} = query, service) when method in [:post, :put] do
+    uri =  WebStorageCache.get_swift_endpoint(client, service) <> uri
     if params !== "" and params !== :nil and is_map(params), do: params = Poison.encode!(params)
-    options = %{ body: params, headers: headers(client), timeout: @timeout }
+    options = %{ body: params, headers: headers(client, service), timeout: @timeout }
     {method, uri, options}
+    |> LoggingUtils.log_return(:debug)
   end
 
 
@@ -36,10 +37,12 @@ defmodule ExOvh.Ovh.Openstack.Webstorage.Auth do
   ############################
 
 
-  defp headers(client), do: %{ "X-Auth-Token": Cache.get_credentials_token(client) }
-
-  defp config(), do: ClientCache.get_config(ExOvh)
-  defp config(client), do: ClientCache.get_config(client)
+  defp headers(client, service) do
+    %{
+      "Content-Type": "application/json; charset=utf-8",
+      "X-Auth-Token": WebStorageCache.get_credentials_token(client, service)
+     }
+  end
 
 
 end
diff --git a/lib/ovh/openstack_api/webstorage/cache.ex b/lib/ovh/openstack_api/webstorage/cache.ex
index daa8846..4384d53 100644
--- a/lib/ovh/openstack_api/webstorage/cache.ex
+++ b/lib/ovh/openstack_api/webstorage/cache.ex
@@ -5,9 +5,8 @@ defmodule ExOvh.Ovh.OpenstackApi.Webstorage.Cache do
   Uses the standard Openstack Identity (Keystone) api for auth.
   """
   use GenServer
-  alias ExOvh.Hubic.HubicApi.Cache
-  alias ExOvh.Hubic.Request
-  import ExOvh.Query.Ovh.Webstorage
+  alias ExOvh.Ovh.OpenstackApi.Webstorage.Supervisor, as: WebStorageSupervisor
+  import ExOvh.Query.Ovh.Webstorage, only: [get_webstorage_credentials: 1]
   @get_credentials_retries 10
   @get_credentials_sleep_interval 150
 
@@ -18,31 +17,45 @@ defmodule ExOvh.Ovh.OpenstackApi.Webstorage.Cache do
 
 
   @doc "Starts the genserver"
-  def start_link({client, config, opts}) do
+  def start_link({client, config, opts}, service) do
     LoggingUtils.log_mod_func_line(__ENV__, :debug)
-    GenServer.start_link(__MODULE__, {client, config, opts}, [name: gen_server_name(client)])
+    GenServer.start_link(__MODULE__, {client, service}, [name: gen_server_name(client, service)])
   end
 
 
-  def get_credentials(), do: get_credentials(ExOvh)
-  def get_credentials(client), do: get_credentials(client, 0)
+  def get_credentials(service), do: get_credentials(ExOvh, service)
+  def get_credentials(client, service) do
+    LoggingUtils.log_return("client, service", :warn)
+    LoggingUtils.log_return(client, :warn)
+    LoggingUtils.log_return(service, :warn)
+    unless supervisor_exists?(client, service), do: Supervisor.start_child(WebStorageSupervisor, [service])
+    get_credentials(client, service, 0)
+  end
 
 
-  def get_credentials_token(), do: get_credentials_token(ExOvh)
-  def get_credentials_token(client), do: get_credentials(client)["token"]
+  def get_credentials_token(service), do: get_credentials_token(ExOvh, service)
+  def get_credentials_token(client, service), do: get_credentials(client, service).token
 
 
-  def get_endpoint(), do: get_endpoint(ExOvh)
-  def get_endpoint(client) do
-    credentials = get_credentials(client)
-    path = URI.parse(credentials["endpoint"])
-    |> Map.get(:path)
+  def get_swift_endpoint(service), do: get_swift_endpoint(ExOvh, service)
+  def get_swift_endpoint(client, service) do
+    credentials = get_credentials(client, service)
+    path = URI.parse(credentials.swift_endpoint) |> Map.get(:path)
     {version, account} = String.split_at(path, 4)
-    endpoint = List.first(String.split(credentials["endpoint"], account))
+    endpoint = List.first(String.split(credentials.swift_endpoint, account))
     endpoint
   end
 
 
+  def get_account(service), do: get_account(ExOvh)
+  def get_account(client, service) do
+    credentials = get_credentials(client, service)
+    path = URI.parse(credentials.swift_endpoint) |> Map.get(:path)
+    {version, account} = String.split_at(path, 4)
+    account
+  end
+
+
   #####################
   # Genserver Callbacks
   #####################
@@ -50,50 +63,49 @@ defmodule ExOvh.Ovh.OpenstackApi.Webstorage.Cache do
 
   # trap exits so that terminate callback is invoked
   # the :lock key is to allow for locking during the brief moment that the access token is being refreshed
-  def init({client, config, opts}) do
+  def init({client, service}) do
     LoggingUtils.log_mod_func_line(__ENV__, :debug)
     :erlang.process_flag(:trap_exit, :true)
-    create_ets_table(client)
-
-    {:ok, resp} = Request.request(client, {:get, "/account/credentials", ""}, %{})
+    create_ets_table(client, service)
+    {:ok, credentials} = identity(service)
     |> LoggingUtils.log_return(:debug)
-
-
-    credentials = Map.put(resp.body, :lock, :false)
-    :ets.insert(ets_tablename(client), {:credentials, credentials})
-    expires = to_seconds(credentials["expires"])
-    Task.start_link(fn -> monitor_expiry(client, expires) end)
-    {:ok, {client, config, credentials}}
+    credentials = Map.put(credentials, :lock, :false)
+    :ets.insert(ets_tablename(client, service), {:credentials, credentials})
+    expires = to_seconds(credentials.token_expires_on)
+    Task.start_link(fn -> monitor_expiry(expires) end)
+    {:ok, {client, service, credentials}}
   end
 
-
-  def handle_call(:add_lock, _from, {client, config, credentials}) do
+  def handle_call(:add_lock, _from, {client, service, credentials}) do
     LoggingUtils.log_mod_func_line(__ENV__, :debug)
     new_credentials = Map.put(credentials, :lock, :true)
-    :ets.insert(ets_tablename(client), {:credentials, new_credentials})
-    {:reply, :ok, {client, config, new_credentials}}
+    :ets.insert(ets_tablename(client, service), {:credentials, new_credentials})
+    {:reply, :ok, {client, service, new_credentials}}
   end
-  def handle_call(:remove_lock, _from, {client, config, credentials}) do
+
+  def handle_call(:remove_lock, _from, {client, service, credentials}) do
     LoggingUtils.log_mod_func_line(__ENV__, :debug)
     new_credentials = Map.put(credentials, :lock, :false)
-    :ets.insert(ets_tablename(client), {:credentials, new_credentials})
-    {:reply, :ok, {client, config, new_credentials}}
+    :ets.insert(ets_tablename(client, service), {:credentials, new_credentials})
+    {:reply, :ok, {client, service, new_credentials}}
   end
-  def handle_call(:update_credentials, _from, {client, config, credentials}) do
+
+  def handle_call(:update_credentials, _from, {client, service, credentials}) do
     LoggingUtils.log_mod_func_line(__ENV__, :debug)
-    {:ok, resp} = Request.request(client, {:get, "/account/credentials", ""}, %{})
-    new_credentials = resp.body
+    {:ok, new_credentials} = identity(service)
     |> Map.put(credentials, :lock, :false)
-    :ets.insert(ets_tablename(client), {:credentials, new_credentials})
-    {:reply, :ok, {client, config, new_credentials}}
+    :ets.insert(ets_tablename(client, service), {:credentials, new_credentials})
+    {:reply, :ok, {client, service, new_credentials}}
   end
+
   def handle_call(:stop, _from, state) do
     LoggingUtils.log_mod_func_line(__ENV__, :debug)
     {:stop, :shutdown, :ok, state}
   end
-  def terminate(:shutdown, {client, config, credentials}) do
+
+  def terminate(:shutdown, {client, service, credentials}) do
     LoggingUtils.log_mod_func_line(__ENV__, :debug)
-    :ets.delete(ets_tablename(client)) # explicilty remove
+    :ets.delete(ets_tablename(client, service)) # explicilty remove
     :ok
   end
 
@@ -103,21 +115,54 @@ defmodule ExOvh.Ovh.OpenstackApi.Webstorage.Cache do
   # Private
   #####################
 
-  defp gen_server_name(client), do: String.to_atom(Atom.to_string(client) <> Atom.to_string(__MODULE__))
-  defp ets_tablename(client), do: String.to_atom("Ets" <> Atom.to_string(gen_server_name(client)))
+  defp gen_server_name(client, service), do:  String.to_atom(Atom.to_string(client) <> service)
+  defp ets_tablename(client, service), do: String.to_atom(Atom.to_string(client) <> "-" <> service)
 
 
-  #@spec identity(service_name :: String.t, username :: String.t, password :: String.t)
-  #               :: {:ok, map()} | {:error, map()}
-  defp identity(service_name, username, password) do
-    resp = ExOvh.ovh_request(get_webstorage_credentials(service_name), %{})
+  #@spec identity(service :: String.t, username :: String.t, password :: String.t)
+  #               :: {:ok, map()} | {:error, map()} ??
+  # This function probably should be broken down into smaller parts
+  def identity(service) do
+
+    {:ok, resp} = ExOvh.ovh_request(get_webstorage_credentials(service), %{})
+
     %{
       "endpoint" => endpoint,
       "login" => login,
       "password" => password,
       "tenant" => tenant
     } = resp.body
-    params = %{"auth" => %{"passwordCredentials" => %{"username" => login, "password" => password}}}
+
+    params = %{"auth" =>
+                        %{
+                        "passwordCredentials" => %{"username" => login, "password" => password}
+                        }
+              }
+    options = %{
+                body: params |> Poison.encode!,
+                headers: %{ "Content-Type": "application/json; charset=utf-8" },
+                timeout: 10_000
+               }
+    resp = HTTPotion.request(:post, endpoint <> "/tokens", options)
+
+    unless resp.status_code >= 200 and resp.status_code <= 203, do: raise resp.body
+
+    %{
+      "access" =>
+                  %{
+                    "token" => %{
+                                 "expires" => expires_on,
+                                 "id" => token,
+                                 "issued_at" => created_on
+                                },
+                  }
+      } = Poison.decode!(resp.body)
+
+    params = %{"auth" =>
+                        %{
+                        "tenantName" => tenant,
+                        "token" => %{"id" => token}}
+                        }
     options = %{
                 body: params |> Poison.encode!,
                 headers: %{ "Content-Type": "application/json; charset=utf-8" },
@@ -125,67 +170,79 @@ defmodule ExOvh.Ovh.OpenstackApi.Webstorage.Cache do
                }
     resp = HTTPotion.request(:post, endpoint <> "/tokens", options)
 
-    if resp.status_code >= 200 and resp.status_code <= 203 do
-      %{
-         "access" => %{
-                      "metadata" => _metadata,
-                      "serviceCatalog" => _service_catalog,
-                      "token" => %{
-                                  "audit_ids" => _audit_ids,
-                                  "expires" => expires_on, # "2016-02-12T22:12:25Z",
-                                  "id" => token,
-                                  "issued_at" => created_on, # "2016-02-11T22:12:25.214186"
-                                  },
-                      "user" => _user
-                     }
+    unless resp.status_code >= 200 and resp.status_code <= 203, do: raise resp.body
+
+    %{
+      "serviceCatalog" => [
+                          %{
+                            "endpoints" => [%{"publicURL" => swift_endpoint}],
+                            "name" => "swift",
+                          },
+                          %{
+                            "endpoints" => [%{"publicURL" => identity_endpoint}],
+                            "name" => "keystone",
+                          }
+                         ],
+                          "token" => %{
+                                          "expires" => token_expires_on,
+                                          "id" => token,
+                                          "issued_at" => token_created_on,
+                                        },
+                          "user" => _user
+      } = Poison.decode!(resp.body) |> Map.get("access")
+
+      {:ok,
+          %{
+            token: token,
+            token_expires_on: expires_on,
+            token_created_on: token_created_on,
+            swift_endpoint: swift_endpoint,
+            identity_endpoint: identity_endpoint,
+            service: service
+          }
       }
-      = resp.body
-      {:ok, %{ "token" => token, "expires_on" => expires_on, "created_on" => created_on, "endpoint" => endpoint } }
-    else
-      {:error, resp.body}
-    end
 
   end
 
 
-  defp get_credentials(client, index) do
+  defp get_credentials(client, service, index) do
     LoggingUtils.log_mod_func_line(__ENV__, :debug)
-    if ets_tablename(client) in :ets.all() do
-      [credentials: credentials] = :ets.lookup(ets_tablename(client), :credentials)
+    if ets_tablename(client, service) in :ets.all() do
+      [credentials: credentials] = :ets.lookup(ets_tablename(client, service), :credentials)
       if credentials.lock === :true do
         if index > @get_credentials_retries do
-          raise "Problem retrieving the openstack credentials from ets table"
+          raise "Cannot retrieve openstack credentials from ets table, #{__ENV__.module}, #{__ENV__.line}"
         else
           :timer.sleep(@get_credentials_sleep_interval)
-          get_credentials(client, index + 1)
+          get_credentials(client, service, index + 1)
         end
       else
         credentials
       end
     else
       if index > @get_credentials_retries do
-        raise "Problem retrieving the openstack credentials from ets table"
+        raise "Cannot retrieve openstack credentials from ets table, #{__ENV__.module}, #{__ENV__.line}"
       else
         :timer.sleep(@get_credentials_sleep_interval)
-        get_credentials(client, index + 1)
+        get_credentials(client, service, index + 1)
       end
     end
   end
 
 
-  defp monitor_expiry(client, expires) do
+  defp monitor_expiry(expires) do
     LoggingUtils.log_mod_func_line(__ENV__, :debug)
     interval = (expires - 30) * 1000
     :timer.sleep(interval)
-    {:reply, :ok, _credentials} = GenServer.call(gen_server_name(client), :add_lock)
-    {:reply, :ok, _credentials} = GenServer.call(gen_server_name(client), :update_credentials)
-    {:reply, :ok, credentials} = GenServer.call(gen_server_name(client), :remove_lock)
+    {:reply, :ok, _credentials} = GenServer.call(self(), :add_lock)
+    {:reply, :ok, _credentials} = GenServer.call(self(), :update_credentials)
+    {:reply, :ok, credentials} = GenServer.call(self(), :remove_lock)
     expires = to_seconds(credentials["expires"])
-    monitor_expiry(client, expires)
+    monitor_expiry(expires)
   end
 
 
-  defp create_ets_table(client) do
+  defp create_ets_table(client, service) do
     LoggingUtils.log_mod_func_line(__ENV__, :debug)
     ets_options = [
                    :set, # type
@@ -195,8 +252,8 @@ defmodule ExOvh.Ovh.OpenstackApi.Webstorage.Cache do
                    {:write_concurrency, :false},
                    {:read_concurrency, :true}
                   ]
-    unless ets_tablename(client) in :ets.all() do
-      :ets.new(ets_tablename(client), ets_options)
+    unless ets_tablename(client, service) in :ets.all() do
+      :ets.new(ets_tablename(client, service), ets_options)
     end
   end
 
@@ -214,4 +271,14 @@ defmodule ExOvh.Ovh.OpenstackApi.Webstorage.Cache do
   end
 
 
+  defp supervisor_exists?(client, service) do
+    Process.whereis(registered_supervisor_name(client, service))
+  end
+
+
+  defp registered_supervisor_name(client, service) do
+    String.to_atom(Atom.to_string(client) <> service)
+  end
+
+
 end
\ No newline at end of file
diff --git a/lib/ovh/openstack_api/webstorage/request.ex b/lib/ovh/openstack_api/webstorage/request.ex
index f26b437..21354b2 100644
--- a/lib/ovh/openstack_api/webstorage/request.ex
+++ b/lib/ovh/openstack_api/webstorage/request.ex
@@ -1,18 +1,14 @@
-defmodule ExOvh.Ovh.Openstack.Webstorage.Request do
-  alias ExOvh.Ovh.Openstack.Webstorage.Auth
+defmodule ExOvh.Ovh.OpenstackApi.Webstorage.Request do
+  alias ExOvh.Ovh.OpenstackApi.Webstorage.Auth
   alias ExOvh.Ovh.OvhApi.Cache, as: ClientCache
 
 
-  ############################
-  # Public
-  ############################
-
-
-  @spec request(client :: atom, query :: ExOvh.Client.query_t)
+  @spec request(client :: atom, query :: ExOvh.Client.query_t, service :: String.t)
                :: {:ok, ExOvh.Client.response_t} | {:error, ExOvh.Client.response_t}
-  def request(client, {method, uri, params} = query) do
-    config = config(client)
-    {method, uri, options} = Auth.prepare_request(client, query)
+  def request(client, {method, uri, params} = query, service) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
+
+    {method, uri, options} = Auth.prepare_request(client, query, service)
     resp = HTTPotion.request(method, uri, options)
     resp =
     %{
@@ -20,6 +16,7 @@ defmodule ExOvh.Ovh.Openstack.Webstorage.Request do
       headers: resp.headers,
       status_code: resp.status_code
     }
+
     if resp.status_code >= 100 and resp.status_code < 300 do
      {:ok, resp}
     else
@@ -28,14 +25,5 @@ defmodule ExOvh.Ovh.Openstack.Webstorage.Request do
   end
 
 
-  ############################
-  # Private
-  ############################
-
-
-  defp config(), do: ClientCache.get_config(ExOvh)
-  defp config(client), do: ClientCache.get_config(client)
-
-
 end
 
diff --git a/lib/ovh/openstack_api/webstorage/supervisor.ex b/lib/ovh/openstack_api/webstorage/supervisor.ex
index f3d2dca..454662a 100644
--- a/lib/ovh/openstack_api/webstorage/supervisor.ex
+++ b/lib/ovh/openstack_api/webstorage/supervisor.ex
@@ -1,4 +1,4 @@
-defmodule ExOvh.Ovh.OpenstackApi.Supervisor do
+defmodule ExOvh.Ovh.OpenstackApi.Webstorage.Supervisor do
   @moduledoc ~s"""
   Supervisor for the Ovh Openstack Configurations.
 
@@ -19,11 +19,7 @@ defmodule ExOvh.Ovh.OpenstackApi.Supervisor do
   """
   def start_link({client, config, opts}) do
     LoggingUtils.log_mod_func_line(__ENV__, :debug)
-
-    LoggingUtils.log_return("starting dynamic supervisor", :warn)
-
-    {:ok, sup_pid} = Supervisor.start_link(__MODULE__, {client, config, opts}, [name: __MODULE__])
-    |> LoggingUtils.log_return(:warn)
+    Supervisor.start_link(__MODULE__, {client, config, opts}, [name: __MODULE__])
   end
 
 
diff --git a/lib/ovh/ovh_api/request.ex b/lib/ovh/ovh_api/request.ex
index 6e53a7b..ef1ee77 100644
--- a/lib/ovh/ovh_api/request.ex
+++ b/lib/ovh/ovh_api/request.ex
@@ -8,14 +8,10 @@ defmodule ExOvh.Ovh.OvhApi.Request do
   ############################
 
 
-  @spec request(query :: ExOvh.Client.raw_query_t)
-               :: {:ok, map} | {:error, map}
-  def request({method, uri, params} = query), do: request(ExOvh, {method, uri, params} = query)
-
-
   @spec request(client :: atom, query :: ExOvh.Client.query_t)
                :: {:ok, ExOvh.Client.response_t} | {:error, ExOvh.Client.response_t}
   def request(client, {method, uri, params} = query) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
     config = config(client)
 
     {method, uri, options} = Auth.prepare_request(client, query)
diff --git a/lib/ovh/request.ex b/lib/ovh/request.ex
index ac345f1..7524f6a 100644
--- a/lib/ovh/request.ex
+++ b/lib/ovh/request.ex
@@ -20,7 +20,7 @@ defmodule ExOvh.Ovh.Request do
 
   @spec request(client :: atom, query :: ExOvh.Client.raw_query_t, opts :: map)
                 :: {:ok, ExOvh.Client.response_t} | {:error, ExOvh.Client.response_t}
-  def request(client, {method, uri, params} = query, %{ openstack: :true } = opts), do: Open.request(client, query)
+  def request(client, {method, uri, params} = query, %{ openstack: :true } = opts), do: Open.request(client, query, opts)
   def request(client, {method, uri, params} = query, opts), do: Ovh.request(client, query)
 
   ###################
diff --git a/lib/ovh/supervisor.ex b/lib/ovh/supervisor.ex
index 66a0baf..2c7f4f6 100644
--- a/lib/ovh/supervisor.ex
+++ b/lib/ovh/supervisor.ex
@@ -4,6 +4,7 @@ defmodule ExOvh.Ovh.Supervisor do
   """
   use Supervisor
   alias ExOvh.Ovh.OvhApi.Cache
+  alias ExOvh.Ovh.OpenstackApi.Webstorage.Supervisor, as: Webstorage
 
   #####################
   #  Public
@@ -24,10 +25,11 @@ defmodule ExOvh.Ovh.Supervisor do
 
   def init({client, config, opts}) do
     LoggingUtils.log_mod_func_line(__ENV__, :debug)
-    workers = [
-               {Cache, {Cache, :start_link, [{client, config, opts}]}, :permanent, 10_000, :worker, [Cache]}
-              ]
-    supervise(workers, strategy: :one_for_one, max_restarts: 20)
+    tree = [
+            {Cache, {Cache, :start_link, [{client, config, opts}]}, :permanent, 10_000, :worker, [Cache]},
+            {Webstorage, {Webstorage, :start_link, [{client, config, opts}]}, :permanent, 10_000, :supervisor, [Webstorage]}
+           ]
+    supervise(tree, strategy: :one_for_one, max_restarts: 20)
   end
 
   defp supervisor_name(client), do: String.to_atom(Atom.to_string(client) <> Atom.to_string(__MODULE__))
diff --git a/lib/query/openstack/swift/query.ex b/lib/query/openstack/swift/query.ex
index e9a94fb..1079e9b 100644
--- a/lib/query/openstack/swift/query.ex
+++ b/lib/query/openstack/swift/query.ex
@@ -29,7 +29,8 @@ defmodule ExOvh.Query.Openstack.Swift do
       import ExOvh.Query.Openstack.Swift
       alias ExOvh.Hubic.OpenstackApi.Cache, as: OpenCache
       client = ExOvh
-      ExOvh.hubic_request(account_info(OpenCache.get_account(client)), %{ openstack: :true })
+      account = OpenCache.get_account(client)
+      ExOvh.hubic_request(account_info(account), %{ openstack: :true })
       ```
   """
   @spec account_info(account :: String.t) :: [map]
@@ -45,7 +46,8 @@ defmodule ExOvh.Query.Openstack.Swift do
       import ExOvh.Query.Openstack.Swift
       alias ExOvh.Hubic.OpenstackApi.Cache, as: OpenCache
       client = ExOvh
-      ExOvh.hubic_request(create_container(OpenCache.get_account(client), "new_container"), %{ openstack: :true })
+      account = OpenCache.get_account(client)
+      ExOvh.hubic_request(create_container(account, "new_container"), %{ openstack: :true })
       ```
   """
   @spec create_container(account :: String.t, container :: String.t)
@@ -62,7 +64,8 @@ defmodule ExOvh.Query.Openstack.Swift do
       import ExOvh.Query.Openstack.Swift
       alias ExOvh.Hubic.OpenstackApi.Cache, as: OpenCache
       client = ExOvh
-      ExOvh.hubic_request(delete_container(OpenCache.get_account(client), "new_container"), %{ openstack: :true })
+      account = OpenCache.get_account(client)
+      ExOvh.hubic_request(delete_container(account, "new_container"), %{ openstack: :true })
       ```
   """
   @spec delete_container(account :: String.t, container :: String.t)
@@ -84,7 +87,8 @@ defmodule ExOvh.Query.Openstack.Swift do
       import ExOvh.Query.Openstack.Swift
       alias ExOvh.Hubic.OpenstackApi.Cache, as: OpenCache
       client = ExOvh
-      ExOvh.hubic_request(get_objects(OpenCache.get_account(client), "default"), %{ openstack: :true })
+      account = OpenCache.get_account(client)
+      ExOvh.hubic_request(get_objects(account, "default"), %{ openstack: :true })
       ```
   """
   @spec get_objects(account :: String.t, container :: String.t)
@@ -104,7 +108,8 @@ defmodule ExOvh.Query.Openstack.Swift do
       client = ExOvh
       file = "server_file.txt"
       container = "new_container"
-      ExOvh.hubic_request(get_object(OpenCache.get_account(client), container, file), %{ openstack: :true })
+      account = OpenCache.get_account(client)
+      ExOvh.hubic_request(get_object(account, container, file), %{ openstack: :true })
       ```
   """
   @spec get_object(account :: String.t, container :: String.t, object :: String.t)