Commit 4a6e1ae5a2eda64e4ffb663c296bd894b4225c10

Stephen Moloney 2016-06-07T18:19:28

modify as now using ex_ovh in openstex with adapter.

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
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
diff --git a/lib/ex_ovh/cache.ex b/lib/ex_ovh/cache.ex
deleted file mode 100644
index 86b623b..0000000
--- a/lib/ex_ovh/cache.ex
+++ /dev/null
@@ -1,63 +0,0 @@
-defmodule ExOvh.Cache do
-  @moduledoc :false # Stores the time diff in state of the gen_server - later used in authentication headers for every request
-  use GenServer
-
-
-  # Public
-
-
-  def start_link(client) do
-    Og.context(__ENV__, :debug)
-    GenServer.start_link(__MODULE__, client, [name: client])
-  end
-
-
-  @doc "Retrieves the ovh api time diff from the state"
-  def get_time_diff(client) do
-    GenServer.call(client, :get_diff)
-  end
-
-
-  # Genserver Callbacks
-
-
-  def init(client) do
-    diff = calculate_diff(client)
-    {:ok, diff}
-  end
-
-  def handle_call(:get_diff, _from, diff) do
-    {:reply, diff, diff}
-  end
-
-  def terminate(:shutdown, _state) do
-    Og.log_return("gen_server #{__MODULE__} shutting down", __ENV__, :warn)
-    :ok
-  end
-
-
-  # Private
-
-
-  defp calculate_diff(client) do
-    api_time = api_time_request(client)
-    os_t = :os.system_time(:seconds)
-    os_t - api_time
-  end
-
-
-  defp api_time_request(client) do
-    ovh_config = client.ovh_config()
-    method = :get
-    uri = ovh_config[:endpoint] <> ovh_config[:api_version] <> "/auth/time"
-    body = ""
-    headers = [{"Content-Type", "application/json; charset=utf-8"}]
-    client
-    httpoison_opts = client.httpoison_config()
-    options = httpoison_opts
-    resp = HTTPoison.request!(method, uri, body, headers, options)
-    Poison.decode!(resp.body)
-  end
-
-
-end
\ No newline at end of file
diff --git a/lib/ex_ovh/client.ex b/lib/ex_ovh/client.ex
index 5ce00d1..c4c2921 100644
--- a/lib/ex_ovh/client.ex
+++ b/lib/ex_ovh/client.ex
@@ -13,56 +13,25 @@ defmodule ExOvh.Client do
       @doc "Starts the client supervision tree"
       def start_link(sup_opts \\ []) do
         client = unquote(opts) |> Keyword.fetch!(:client)
-        ExOvh.Supervisor.start_link(client, sup_opts)
+        otp_app = unquote(opts) |> Keyword.fetch!(:otp_app)
+        ExOvh.Supervisor.start_link(client, [otp_app: otp_app])
       end
 
-
       @doc "Gets all the application configuration settings"
       @spec config() :: Keyword.t
       def config() do
-        otp_app = unquote(opts) |> Keyword.fetch!(:otp_app)
         client = unquote(opts) |> Keyword.fetch!(:client)
-        case otp_app do
-          :ex_ovh -> Application.get_all_env(otp_app)
-          _ ->
-            case Application.get_env(otp_app, client) do
-              :nil ->
-                temp_client = Module.split(client) |> List.delete_at(-1) |> Enum.join(".") |> String.to_atom()
-                temp_client = Module.concat(Elixir, temp_client)
-                Application.get_env(otp_app, temp_client)
-              config -> Application.get_env(otp_app, client)
-            end
-        end
+        unless agent_exists?(client), do: __MODULE__.start_link([])
+        ExOvh.Config.config(client)
       end
 
-
       @doc "Gets all the `:ovh` configuration settings"
       @spec ovh_config() :: Keyword.t
-      def ovh_config() do
-        config()
-        |> Keyword.fetch!(:ovh)
-        |> Keyword.merge(Defaults.ovh(), fn(k, v1, v2) ->
-          case {k, v1} do
-            {_, :nil} -> v2
-            {:endpoint, v1} -> Defaults.endpoints()[v1]
-            _ -> v1
-          end
-        end)
-      end
-
+      def ovh_config(), do: config() |> Keyword.fetch!(:ovh)
 
       @doc "Gets all the `:httpoison` configuration settings"
       @spec httpoison_config() :: Keyword.t
-      def httpoison_config() do
-        default_opts = [connect_timeout: 30000, receive_timeout: (60000 * 30)]
-        httpoison = Keyword.get(config(), :httpoison, default_opts)
-        httpoison
-        |> Keyword.put(:timeout, httpoison[:connect_timeout])
-        |> Keyword.put(:recv_timeout, httpoison[:receive_timeout])
-        |> Keyword.delete(:connect_timeout)
-        |> Keyword.delete(:receive_timeout)
-      end
-
+      def httpoison_config(), do: config() |> Keyword.fetch!(:httpoison)
 
       @doc "Prepares a request prior to sending by adding metadata such as authorization headers."
       @spec prepare_request(Query.t, Keyword.t) :: {:ok, Response.t} | {:error, Response.t}
@@ -87,48 +56,23 @@ defmodule ExOvh.Client do
         end
       end
 
-#      defoverridable [
-#                ovh_config: 0,
-#                httpoison_config: 0,
-#                start_link: 0, start_link: 1,
-#                request: 1, request: 2,
-#                request!: 1, request!: 2,
-#                prepare_request: 1, prepare_request: 2
-#               ]
-
-      defoverridable [
-                ovh_config: 0,
-                httpoison_config: 0,
-                start_link: 1,
-                request: 2,
-                request!: 2,
-                prepare_request: 2
-               ]
+      defp agent_name(client) do
+        Module.concat(ExOvh.Config, client)
+      end
 
+      defp agent_exists?(client) do
+        agent_name(client) in Process.registered()
+      end
 
     end
   end
 
-
-#  @callback start_link() :: {:ok, pid} | {:error, atom}
-#  @callback start_link(sup_opts :: list) :: {:ok, pid} | {:error, atom}
-#  @callback ovh_config() :: Keyword.t
-#  @callback httpoison_config() :: Keyword.t
-#  @callback prepare_request(query :: Query.t) :: Query.t | no_return
-#  @callback prepare_request(query :: Query.t, httpoison_opts :: Keyword.t) :: Query.t | no_return
-#  @callback request(query :: Query.t | HttpQuery.t) :: {:ok, Response.t} | {:error, Response.t}
-#  @callback request(query :: Query.t | HttpQuery.t, httpoison_opts :: Keyword.t) :: {:ok, Response.t} | {:error, Response.t}
-#  @callback request!(query :: Query.t | HttpQuery.t) :: {:ok, Response.t} | no_return
-#  @callback request!(query :: Query.t | HttpQuery.t, httpoison_opts :: Keyword.t) :: {:ok, Response.t} | no_return
-
-
   @callback start_link(sup_opts :: list) :: {:ok, pid} | {:error, atom}
+  @callback config() :: Keyword.t
   @callback ovh_config() :: Keyword.t
   @callback httpoison_config() :: Keyword.t
   @callback prepare_request(query :: Query.t, httpoison_opts :: Keyword.t) :: Query.t | no_return
   @callback request(query :: Query.t | HttpQuery.t, httpoison_opts :: Keyword.t) :: {:ok, Response.t} | {:error, Response.t}
   @callback request!(query :: Query.t | HttpQuery.t, httpoison_opts :: Keyword.t) :: {:ok, Response.t} | no_return
 
-
-
 end
\ No newline at end of file
diff --git a/lib/ex_ovh/config.ex b/lib/ex_ovh/config.ex
new file mode 100644
index 0000000..4c519e6
--- /dev/null
+++ b/lib/ex_ovh/config.ex
@@ -0,0 +1,114 @@
+defmodule ExOvh.Config do
+  @moduledoc :false
+  @default_httpoison_opts [connect_timeout: 20000, receive_timeout: 180000]
+  alias ExOvh.Defaults
+
+  @doc "Starts an agent for the storage of credentials in memory"
+  def start_agent(client, opts) do
+    Og.context(__ENV__, :debug)
+    otp_app = Keyword.get(opts, :otp_app, :false) || Og.log_return(__ENV__, :error) |> raise()
+    Agent.start_link(fn -> config(client, otp_app) end, name: agent_name(client))
+  end
+
+  @doc "Gets all the config.exs environment variables"
+  def get_config_from_env(client, otp_app) do
+    config = Application.get_env(otp_app, client)
+    case otp_app do
+      :ex_ovh -> Application.get_all_env(otp_app)
+      _ ->
+        case config do
+          :nil ->
+            temp_client = Module.split(client) |> List.delete_at(-1) |> Enum.join(".") |> String.to_atom()
+            temp_client = Module.concat(Elixir, temp_client)
+            Application.get_env(otp_app, temp_client)
+          config -> config
+        end
+    end
+  end
+
+  @doc "Gets the httpoison config.exs environment variables"
+  def get_ovh_config_from_env(client, otp_app) do
+    try do
+      get_config_from_env(client, otp_app) |> Keyword.fetch!(:ovh)
+      |> Keyword.merge(Defaults.ovh(), fn(k, v1, v2) ->
+        case {k, v1} do
+          {_, :nil} -> v2
+          {:endpoint, v1} -> Defaults.endpoints()[v1]
+          _ -> v1
+        end
+      end)
+    rescue
+      _error -> Og.log_return("No ovh_config was found. ",  __ENV__, :warn) |> raise()
+    end
+  end
+
+  @doc "Gets the httpoison config.exs environment variables"
+  def get_httpoison_config_from_env(client, otp_app) do
+    try do
+      get_config_from_env(client, otp_app) |> Keyword.fetch!(:httpoison)
+    rescue
+      _error ->
+        Og.log_return("No httpoison_config was found. " <>
+                      "Falling back to default httpoison settings #{@default_httpoison_opts}", __ENV__, :warn)
+        @default_httpoison_opts
+    end
+  end
+
+  @doc "Gets all the config variables from a supervised Agent"
+  def config(client) do
+    Agent.get(agent_name(client), fn(config) -> config end)
+  end
+
+  @doc "Gets the ovh related config variables from a supervised Agent"
+  def ovh_config(client) do
+    Agent.get(agent_name(client), fn(config) -> config[:ovh] end)
+  end
+
+  @doc "Gets the httpoison_config related config variables from a supervised Agent"
+  def httpoison_config(client) do
+    Agent.get(agent_name(client), fn(config) -> config[:httpoison] end)
+  end
+
+  @doc "Gets the diff"
+  def get_diff(client) do
+    Agent.get(agent_name(client), fn(config) -> config[:ovh][:diff] end)
+  end
+
+  defp config(client, otp_app) do
+    diff = calculate_diff(client, otp_app)
+    ovh_config = get_ovh_config_from_env(client, otp_app)
+    |> Keyword.put(:diff, diff)
+    [
+    ovh: ovh_config,
+    httpoison: get_httpoison_config_from_env(client, otp_app)
+    ]
+  end
+
+  defp agent_name(client) do
+    Module.concat(__MODULE__, client)
+  end
+
+  defp calculate_diff(client, otp_app) do
+    api_time = api_time_request(client, otp_app)
+    os_t = :os.system_time(:seconds)
+    os_t - api_time
+  end
+
+  defp api_time_request(client, otp_app) do
+    ovh_config = get_ovh_config_from_env(client, otp_app)
+    method = :get
+    uri = ovh_config[:endpoint] <> ovh_config[:api_version] <> "/auth/time"
+    body = ""
+    headers = [{"Content-Type", "application/json; charset=utf-8"}]
+    options = get_httpoison_config_from_env(client, otp_app)
+    resp = HTTPoison.request!(method, uri, body, headers, options)
+    Poison.decode!(resp.body)
+  end
+
+end
+
+
+
+
+
+
diff --git a/lib/ex_ovh/defaults.ex b/lib/ex_ovh/defaults.ex
index 3a57994..aa67b63 100644
--- a/lib/ex_ovh/defaults.ex
+++ b/lib/ex_ovh/defaults.ex
@@ -10,14 +10,6 @@ defmodule ExOvh.Defaults do
   end
 
 
-  def cloudstorage() do
-    [
-     keystone_endpoint: "https://auth.cloud.ovh.net/v2.0", # default endpoint for keystone (identity) auth
-     region: "SBG1"
-    ]
-  end
-
-
   def endpoints() do
     %{
       "ovh-eu"        => "https://eu.api.ovh.com/",
diff --git a/lib/ex_ovh/docs/cloudstorage_query.ex b/lib/ex_ovh/docs/cloudstorage_query.ex
index c5119ac..2af193a 100644
--- a/lib/ex_ovh/docs/cloudstorage_query.ex
+++ b/lib/ex_ovh/docs/cloudstorage_query.ex
@@ -23,7 +23,7 @@ defmodule ExOvh.Services.V1.Cloud.Cloudstorage.Query.Docs do
 
     ## Example
 
-        ExOvh.Services.V1.Cloud.Cloudstorage.Query.get_containers(service_name) |> ExOvh.Ovh.request!()
+        ExOvh.Services.V1.Cloud.Cloudstorage.Query.get_containers(service_name) |> ExOvh.request!()
     """
   end
 
diff --git a/lib/ex_ovh/services/v1/cloud/cloudstorage/query.ex b/lib/ex_ovh/services/v1/cloud/cloudstorage/query.ex
index 4b5d3c2..0aa4ded 100644
--- a/lib/ex_ovh/services/v1/cloud/cloudstorage/query.ex
+++ b/lib/ex_ovh/services/v1/cloud/cloudstorage/query.ex
@@ -16,7 +16,7 @@ defmodule ExOvh.Services.V1.Cloud.Cloudstorage.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Cloudstorage.Query.get_containers(service_name) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Cloudstorage.Query.get_containers(service_name) |> ExOvh.request!()
   """
   @spec get_containers(String.t) :: Query.t
   def get_containers(service_name) do
@@ -45,7 +45,7 @@ defmodule ExOvh.Services.V1.Cloud.Cloudstorage.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Cloudstorage.Query.create_container(service_name, "test_container") |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Cloudstorage.Query.create_container(service_name, "test_container") |> ExOvh.request!()
   """
   @spec create_container(String.t, String.t, String.t) :: Query.t
   def create_container(service_name, container_name, region \\ "SBG1") do
@@ -76,7 +76,7 @@ defmodule ExOvh.Services.V1.Cloud.Cloudstorage.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Cloudstorage.Query.get_access(service_name) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Cloudstorage.Query.get_access(service_name) |> ExOvh.request!()
   """
   @spec get_access(String.t) :: Query.t
   def get_access(service_name) do
@@ -107,7 +107,7 @@ defmodule ExOvh.Services.V1.Cloud.Cloudstorage.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Cloudstorage.Query.container_info(service_name, container_id) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Cloudstorage.Query.container_info(service_name, container_id) |> ExOvh.request!()
   """
   @spec container_info(String.t, String.t) :: Query.t
   def container_info(service_name, container_id) do
@@ -135,7 +135,7 @@ defmodule ExOvh.Services.V1.Cloud.Cloudstorage.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Cloudstorage.Query.delete_container(service_name, container_id) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Cloudstorage.Query.delete_container(service_name, container_id) |> ExOvh.request!()
   """
   @spec delete_container(String.t, String.t) :: Query.t
   def delete_container(service_name, container_id) do
@@ -173,7 +173,7 @@ defmodule ExOvh.Services.V1.Cloud.Cloudstorage.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Cloudstorage.Query.modify_container_cors(service_name, container_id, "http://localhost:4001/") |> ExOvh.Ovh.prepare_request() |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Cloudstorage.Query.modify_container_cors(service_name, container_id, "http://localhost:4001/") |> ExOvh.Ovh.prepare_request() |> ExOvh.request!()
 
   ## Notes
 
@@ -218,7 +218,7 @@ defmodule ExOvh.Services.V1.Cloud.Cloudstorage.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Cloudstorage.Query.modify_container_cors(service_name, container_id, "http://localhost:4001/") |> ExOvh.Ovh.prepare_request() |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Cloudstorage.Query.modify_container_cors(service_name, container_id, "http://localhost:4001/") |> ExOvh.Ovh.prepare_request() |> ExOvh.request!()
 
   ## Notes
 
diff --git a/lib/ex_ovh/services/v1/cloud/query.ex b/lib/ex_ovh/services/v1/cloud/query.ex
index 910af93..4a56d3e 100644
--- a/lib/ex_ovh/services/v1/cloud/query.ex
+++ b/lib/ex_ovh/services/v1/cloud/query.ex
@@ -12,13 +12,13 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.list_services() |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.list_services() |> ExOvh.request!()
   """
   @spec list_services() :: Query.t
   def list_services() do
     %Query{
           method: :get,
-          uri: "/cloud/services",
+          uri: "/cloud/project",
           params: :nil
           }
   end
@@ -37,7 +37,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.get_users(service_name) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.get_users(service_name) |> ExOvh.request!()
   """
   @spec get_users(String.t) :: Query.t
   def get_users(service_name) do
@@ -63,7 +63,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.create_user(service_name, "ex_ovh") |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.create_user(service_name, "ex_ovh") |> ExOvh.request!()
   """
   @spec create_user(String.t, String.t) :: Query.t
   def create_user(service_name, description) do
@@ -92,7 +92,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.get_user_details(service_name, user_id) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.get_user_details(service_name, user_id) |> ExOvh.request!()
   """
   @spec get_user_details(String.t, String.t) :: Query.t
   def get_user_details(service_name, user_id) do
@@ -118,7 +118,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.delete_user(service_name, user_id) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.delete_user(service_name, user_id) |> ExOvh.request!()
   """
   @spec delete_user(String.t, String.t) :: Query.t
   def delete_user(service_name, user_id) do
@@ -146,7 +146,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.download_openrc_script(service_name, user_id, "SBG1") |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.download_openrc_script(service_name, user_id, "SBG1") |> ExOvh.request!()
   """
   @spec download_openrc_script(String.t, String.t, String.t) :: Query.t
   def download_openrc_script(service_name, user_id, region \\ "SBG1") do
@@ -174,7 +174,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.regenerate_credentials(service_name, user_id) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.regenerate_credentials(service_name, user_id) |> ExOvh.request!()
   """
   @spec regenerate_credentials(String.t, String.t) :: Query.t
   def regenerate_credentials(service_name, user_id) do
@@ -201,7 +201,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.swift_identity(service_name, user_id) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.swift_identity(service_name, user_id) |> ExOvh.request!()
   """
   @spec swift_identity(String.t, String.t, String.t) :: Query.t
   def swift_identity(service_name, user_id, password) do
@@ -230,7 +230,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.create_project(description, voucher) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.create_project(description, voucher) |> ExOvh.request!()
   """
   @spec create_project(String.t, String.t) :: Query.t
   def create_project(description, voucher) do
@@ -260,7 +260,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.get_prices() |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.get_prices() |> ExOvh.request!()
   """
   @spec get_prices(String.t | :nil, String.t | :nil) :: Query.t
   def get_prices(region \\ :nil, flavor_id \\ :nil) do
@@ -292,7 +292,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.project_info(service_name) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.project_info(service_name) |> ExOvh.request!()
   """
   @spec project_info(String.t) :: Query.t
   def project_info(service_name) do
@@ -317,7 +317,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.modify_project(service_name, new_description) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.modify_project(service_name, new_description) |> ExOvh.request!()
   """
   @spec modify_project(String.t, String.t) :: Query.t
   def modify_project(service_name, new_description) do
@@ -345,7 +345,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.project_administrative_info(service_name) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.project_administrative_info(service_name) |> ExOvh.request!()
   """
   @spec project_administrative_info(String.t) :: Query.t
   def project_administrative_info(service_name) do
@@ -370,7 +370,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.project_quotas(service_name) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.project_quotas(service_name) |> ExOvh.request!()
   """
   @spec project_quotas(String.t) :: Query.t
   def project_quotas(service_name) do
@@ -395,7 +395,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.project_regions(service_name) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.project_regions(service_name) |> ExOvh.request!()
   """
   @spec project_regions(String.t) :: Query.t
   def project_regions(service_name) do
@@ -420,7 +420,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.project_region_info(service_name) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.project_region_info(service_name) |> ExOvh.request!()
   """
   @spec project_region_info(String.t, String.t) :: Query.t
   def project_region_info(service_name, region_name) do
@@ -449,7 +449,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.project_consumption(service_name) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.project_consumption(service_name) |> ExOvh.request!()
   """
   @spec project_consumption(String.t, String.t, String.t) :: Query.t
   def project_consumption(service_name, date_from \\ :nil, date_to \\ :nil) do
@@ -478,7 +478,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.project_bills(service_name) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.project_bills(service_name) |> ExOvh.request!()
   """
   @spec project_bills(String.t, String.t, String.t) :: Query.t
   def project_bills(service_name, date_from \\ :nil, date_to \\ :nil) do
@@ -505,7 +505,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.get_project_alerts(service_name) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.get_project_alerts(service_name) |> ExOvh.request!()
   """
   @spec get_project_alerts(String.t) :: Query.t
   def get_project_alerts(service_name) do
@@ -537,7 +537,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.create_project_alert(service_name, "email_address@email.email", 5) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.create_project_alert(service_name, "email_address@email.email", 5) |> ExOvh.request!()
   """
   @spec create_project_alert(String.t, String.t, integer, String.t) :: Query.t | no_return
   def create_project_alert(service_name, email, monthly_threshold, delay \\ "3600") do
@@ -568,7 +568,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.get_project_alert_info(service_name, alert_id) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.get_project_alert_info(service_name, alert_id) |> ExOvh.request!()
   """
   @spec get_project_alert_info(String.t, String.t) :: Query.t
   def get_project_alert_info(service_name, alert_id) do
@@ -597,7 +597,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.modify_project_alert(service_name, alert_id, "email_address@email.email", 5) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.modify_project_alert(service_name, alert_id, "email_address@email.email", 5) |> ExOvh.request!()
   """
   @spec modify_project_alert(String.t, String.t, String.t, integer, String.t) :: Query.t
   def modify_project_alert(service_name, alert_id, email, monthly_threshold, delay \\ "3600") do
@@ -628,7 +628,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.get_project_alert_info(service_name, alert_id) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.get_project_alert_info(service_name, alert_id) |> ExOvh.request!()
   """
   @spec delete_project_alert(String.t, String.t) :: Query.t
   def delete_project_alert(service_name, alert_id) do
@@ -653,7 +653,7 @@ defmodule ExOvh.Services.V1.Cloud.Query do
 
   ## Example
 
-      ExOvh.Services.V1.Cloud.Query.terminate_project(service_name) |> ExOvh.Ovh.request!()
+      ExOvh.Services.V1.Cloud.Query.terminate_project(service_name) |> ExOvh.request!()
   """
   @spec terminate_project(String.t) :: Query.t
   def terminate_project(service_name) do
diff --git a/lib/ex_ovh/supervisor.ex b/lib/ex_ovh/supervisor.ex
index 4d8fe29..ca35781 100644
--- a/lib/ex_ovh/supervisor.ex
+++ b/lib/ex_ovh/supervisor.ex
@@ -6,18 +6,21 @@ 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)
+    Supervisor.start_link(__MODULE__,  {client, opts})
   end
 
 
   #  Callbacks
 
 
-  def init(client) do
+  def init({client, opts}) do
     Og.context(__ENV__, :debug)
-    sup_tree = [{client, {ExOvh.Cache, :start_link, [client]}, :permanent, 10_000, :worker, [ExOvh.Cache]}]
+    sup_tree =
+    [
+    {client, {ExOvh.Config, :start_agent, [client, opts]}, :permanent, 10_000, :worker, [ExOvh.Config]}
+    ]
     supervise(sup_tree, strategy: :one_for_one, max_restarts: 30)
   end
 
diff --git a/lib/ex_ovh/transformation.ex b/lib/ex_ovh/transformation.ex
index 542ad79..a5e2d2e 100644
--- a/lib/ex_ovh/transformation.ex
+++ b/lib/ex_ovh/transformation.ex
@@ -1,6 +1,6 @@
 defmodule ExOvh.Transformation do
   @moduledoc :false
-  alias ExOvh.{Cache, HttpQuery, Query}
+  alias ExOvh.{Config, HttpQuery, Query}
   @default_headers [{"Content-Type", "application/json; charset=utf-8"}]
 
 
@@ -21,7 +21,7 @@ defmodule ExOvh.Transformation do
     body = params || ""
     headers = headers ++ headers([ovh_config[:application_secret], ovh_config[:application_key], ovh_config[:consumer_key], Atom.to_string(method), uri, ""], client)
     default_httpoison_opts = client.httpoison_config()
-    options = Keyword.merge(default_httpoison_opts, httpoison_opts)
+    options = merge_options(default_httpoison_opts, httpoison_opts)
     %HttpQuery{method: method, uri: uri, body: body, headers: headers, options: options, service: :ovh}
   end
 
@@ -30,7 +30,7 @@ defmodule ExOvh.Transformation 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)
+    time = :os.system_time(:seconds) + Config.get_diff(client)
     headers = [
                 {"X-Ovh-Application", app_key},
                 {"X-Ovh-Consumer", consumer_key},
@@ -48,5 +48,12 @@ defmodule ExOvh.Transformation do
     "$1$" <> post_hash
   end
 
+  defp merge_options(opts1, opts2) do
+    opts1 = Enum.into(opts1, %{})
+    opts2 = Enum.into(opts2, %{})
+    opts = Map.merge(opts1, opts2)
+    Enum.into(opts, [])
+  end
+
 
 end