Commit fe17ed848daa6169f8d16dc1d86a2b9893aeece2

Stephen Moloney 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
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
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
diff --git a/.gitignore b/.gitignore
index 79a493c..0be0846 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,6 +11,7 @@
 *.ez
 erl_crash.dump
 *.secret.exs
+dev.exs
 .env
 mix.lock
 todo.md
diff --git a/config/config.exs b/config/config.exs
index 86c91eb..d802880 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -11,4 +11,6 @@ if Mix.env == :prod do
     compile_time_purge_level: :warn
 end
 
+config :ex_doc, :markdown_processor, ExDoc.Markdown.Hoedown
+
 import_config "#{Mix.env}.exs"
diff --git a/config/dev.exs b/config/dev.exs
index 4a1a288..7e96bf0 100644
--- a/config/dev.exs
+++ b/config/dev.exs
@@ -4,13 +4,48 @@ config :logger,
   backends: [:console],
   compile_time_purge_level: :debug
 
+
+config :openstex,
+  httpoison: [
+              connect_timeout: 30000, # 30 seconds
+              receive_timeout: (60000 * 30) # 30 minutes
+             ]
+
+
 config :ex_ovh,
-  ovh: %{
+  ovh: [
     application_key: System.get_env("EX_OVH_APPLICATION_KEY"),
     application_secret: System.get_env("EX_OVH_APPLICATION_SECRET"),
     consumer_key: System.get_env("EX_OVH_CONSUMER_KEY"),
     endpoint: System.get_env("EX_OVH_ENDPOINT"),
-    api_version: System.get_env("EX_OVH_API_VERSION") || "1.0",
-    connect_timeout: 30000, # 30 seconds
-    connect_timeout: (60000 * 30) # 30 minutes
-  }
+    api_version: System.get_env("EX_OVH_API_VERSION") || "1.0"
+  ],
+  swift: [
+          webstorage: [ #  <-- :webstorage will be the config_id
+                        cdn_name: System.get_env("EX_OVH_WEBSTORAGE_CDN_NAME"),
+                        type: :ovh_webstorage
+                      ],
+          cloudstorage: [ #  <-- :cloudstorage will be the config_id
+                          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.
+                          region: :nil, # defaults to "SBG1" if set to :nil
+                          type: :ovh_cloudstorage
+                        ]
+         ]
+
+
+
+
+#config :my_app, MyApp.ExOvhClient1,
+#  ... then as above
+
+# SAMPLE CONFIGURATIONS ON A PER APP AND PER API BASIS FOR OPENSTEX
+
+#config :my_app, MyApp.ExOvhClient1.Ovh, <-- For OVH part of the api
+#  httpoison: ... as above
+
+#config :my_app, MyApp.ExOvhClient1.Swift.Webstorage, <-- For Openstack Webstorage part of the api
+#  httpoison: ... as above
+
+#config :my_app, MyApp.ExOvhClient1.Swift.Cloudstorage, <-- <-- For Openstack Cloudstorage part of the api
+#  httpoison: ... as above
diff --git a/config/test.exs b/config/test.exs
index 83948ca..ac0d294 100644
--- a/config/test.exs
+++ b/config/test.exs
@@ -13,4 +13,7 @@ config :ex_ovh,
     api_version: System.get_env("EX_OVH_API_VERSION") || "1.0",
     connect_timeout: 30000, # 30 seconds
     connect_timeout: (60000 * 30) # 30 minutes
-  }
\ No newline at end of file
+  },
+  swift: %{
+          webstorage: "EX_OVH_WEBSTORAGE_CDN_NAME"
+        }
\ No newline at end of file
diff --git a/lib/auth/openstack/supervisor.ex b/lib/auth/openstack/supervisor.ex
new file mode 100644
index 0000000..3595ce8
--- /dev/null
+++ b/lib/auth/openstack/supervisor.ex
@@ -0,0 +1,29 @@
+defmodule ExOvh.Auth.Openstack.Supervisor do
+  @moduledoc :false
+
+  use Supervisor
+  alias ExOvh.Auth.Openstack.Swift.Cache
+
+
+  #  Public
+
+
+  def start_link(client \\ []) do
+    Og.context(__ENV__, :debug)
+    Supervisor.start_link(__MODULE__, client, [name: __MODULE__])
+  end
+
+
+  #  Callbacks
+
+
+  def init(client) do
+    Og.context(__ENV__, :debug)
+    tree = [
+            {Cache, {Cache, :start_link, []}, :transient, 10_000, :worker, []}
+           ]
+    supervise(tree, strategy: :simple_one_for_one)
+  end
+
+
+end
\ No newline at end of file
diff --git a/lib/auth/openstack/swift/auth.ex b/lib/auth/openstack/swift/auth.ex
new file mode 100644
index 0000000..6aca259
--- /dev/null
+++ b/lib/auth/openstack/swift/auth.ex
@@ -0,0 +1,51 @@
+defimpl Openstex.Auth, for: Openstex.Openstack.Swift.Query do
+  @moduledoc :false
+  alias Openstex.Openstack.Swift.Query
+  @default_headers [{"Content-Type", "application/json; charset=utf-8"}]
+
+
+  # Public
+
+
+  @spec prepare_request(Query.t, Keyword.t, atom) :: Openstex.HttpQuery.t
+  def prepare_request(query, httpoison_opts, client)
+
+  def prepare_request(%Query{method: method, uri: uri, params: params}, httpoison_opts, client)
+                                  when method in [:get, :head, :delete] do
+    cache = client.cache()
+    uri = cache.get_swift_endpoint(client) <> uri
+    body = ""
+    headers =  headers(client)
+    default_httpoison_opts = client.httpoison_config()
+    options = Keyword.merge(default_httpoison_opts, httpoison_opts)
+    if params !== :nil and params !== "", do: uri = uri <> "?" <> URI.encode_query(params)
+    %Openstex.HttpQuery{method: method, uri: uri, body: body, headers: headers, options: options, service: :openstack}
+  end
+
+  def prepare_request(%Query{method: method, uri: uri, params: params}, httpoison_opts, client)
+                                  when method in [:post, :put] do
+    cache = client.cache()
+    uri = cache.get_endpoint(client) <> uri
+    headers =  headers(client)
+    default_httpoison_opts = client.httpoison_config()
+    options = Keyword.merge(default_httpoison_opts, httpoison_opts)
+    if params !== "" and params !== :nil and is_map(params), do: params = Poison.encode!(params)
+    body = params || ""
+    %Openstex.HttpQuery{method: method, uri: uri, body: body, headers: headers, options: options, service: :openstack}
+  end
+
+
+  # Private
+
+
+  defp headers(client) do
+    @default_headers ++
+    [
+      {
+        "X-Auth-Token", client.cache().get_xauth_token(client)
+      }
+    ]
+  end
+
+
+end
diff --git a/lib/auth/openstack/swift/cache.ex b/lib/auth/openstack/swift/cache.ex
index 6c4771b..40232ae 100644
--- a/lib/auth/openstack/swift/cache.ex
+++ b/lib/auth/openstack/swift/cache.ex
@@ -1,46 +1,57 @@
 defmodule ExOvh.Auth.Openstack.Swift.Cache do
   @moduledoc :false
-
   use GenServer
-  alias ExOvh.Auth.Supervisor, as: AuthSupervisor
+  use Openstex.Cache
+  alias ExOvh.Auth.Openstack.Swift.Cache.Cloudstorage
+  alias ExOvh.Auth.Openstack.Swift.Cache.Webstorage
+  alias ExOvh.Auth.Openstack.Supervisor, as: OpenstackSupervisor
   alias ExOvh.Utils
-  @get_credentials_retries 10
-  @get_credentials_sleep_interval 450
+  alias Openstex.Helpers.V2.Keystone
+  alias Openstex.Helpers.V2.Keystone.Identity
+  import ExOvh.Utils, only: [gen_server_name: 1, ets_tablename: 1]
+  @get_identity_retries 5
+  @get_identity_interval 1000
 
 
   # Public
 
 
-  def start_link({client, config, opts}, service) do
+  def start_link(client) do
     Og.context(__ENV__, :debug)
-    GenServer.start_link(__MODULE__, {client, service}, [name: gen_server_name(client, service)])
+    GenServer.start_link(__MODULE__, client, [name: gen_server_name(client)])
   end
 
+  # Pulic Opestex.Cache callbacks (public 'interface' to the Cache module)
 
-  def get_credentials(client, service) do
-    unless supervisor_exists?(client, service), do: Supervisor.start_child(AuthSupervisor, [service])
-    get_credentials(client, service, 0)
-  end
-
+  def get_swift_account(client) do
+    public_url = get_identity(client)
+    |> Map.get(:service_catalog)
+    |> Enum.find(fn(%Identity.Service{} = service) ->  service.name == "swift" end)
+    |> Map.get(:endpoints)
+    |> List.first()
+    |> Map.get(:public_url)
 
-  def get_credentials_token(client, service), do: get_credentials(client, service).token
+    path = URI.parse(public_url) |> Map.get(:path)
+    {version, account} = String.split_at(path, 4)
+    account
+  end
 
+  def get_swift_endpoint(client) do
+    public_url = get_identity(client)
+    |> Map.get(:service_catalog)
+    |> Enum.find(fn(%Identity.Service{} = service) ->  service.name == "swift" end)
+    |> Map.get(:endpoints)
+    |> List.first()
+    |> Map.get(:public_url)
 
-  def get_swift_endpoint(client, service) do
-    credentials = get_credentials(client, service)
-    path = URI.parse(credentials.swift_endpoint) |> Map.get(:path)
+    path = URI.parse(public_url) |> Map.get(:path)
     {version, account} = String.split_at(path, 4)
-    endpoint = List.first(String.split(credentials.swift_endpoint, account))
+    endpoint = String.split(public_url, account) |> List.first()
     endpoint
   end
 
-
-  def get_account(service), do: get_account(ExOvh, service)
-  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
+  def get_xauth_token(client) do
+    get_identity(client) |> Map.get(:token) |> Map.get(:id)
   end
 
 
@@ -49,40 +60,48 @@ defmodule ExOvh.Auth.Openstack.Swift.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, service}) do
+  def init(client) do
     Og.context(__ENV__, :debug)
     :erlang.process_flag(:trap_exit, :true)
-    create_ets_table(client, service)
+    create_ets_table(client)
+
 
-    {:ok, credentials} = identity(client, service)
 
-    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}}
+    ## Get the client id from the config ??
+    Og.context(__ENV__, :debug)
+    config = get_config(client)
+    |> Og.log_return(__ENV__, :warn)
+
+    {:ok, identity} = create_identity(client, config, config[:type])
+    Og.context(__ENV__, :debug)
+
+    identity = Map.put(identity, :lock, :false)
+    :ets.insert(ets_tablename(client), {:identity, identity})
+    expiry = to_seconds(identity)
+    Task.start_link(fn -> monitor_expiry(expiry) end)
+    {:ok, {client, identity}}
   end
 
-  def handle_call(:add_lock, _from, {client, service, credentials}) do
+  def handle_call(:add_lock, _from, {client, identity}) do
     Og.context(__ENV__, :debug)
-    new_credentials = Map.put(credentials, :lock, :true)
-    :ets.insert(ets_tablename(client, service), {:credentials, new_credentials})
-    {:reply, :ok, {client, service, new_credentials}}
+    new_identity = Map.put(identity, :lock, :true)
+    :ets.insert(ets_tablename(client), {:identity, new_identity})
+    {:reply, :ok, {client, new_identity}}
   end
 
-  def handle_call(:remove_lock, _from, {client, service, credentials}) do
+  def handle_call(:remove_lock, _from, {client, identity}) do
     Og.context(__ENV__, :debug)
-    new_credentials = Map.put(credentials, :lock, :false)
-    :ets.insert(ets_tablename(client, service), {:credentials, new_credentials})
-    {:reply, :ok, {client, service, new_credentials}}
+    new_identity = Map.put(identity, :lock, :false)
+    :ets.insert(ets_tablename(client), {:identity, new_identity})
+    {:reply, :ok, {client, new_identity}}
   end
 
-  def handle_call(:update_credentials, _from, {client, service, credentials}) do
+  def handle_call(:update_identity, _from, {client, identity}) do
     Og.context(__ENV__, :debug)
-    {:ok, new_credentials} = identity(client, service)
-    |> Map.put(credentials, :lock, :false)
-    :ets.insert(ets_tablename(client, service), {:credentials, new_credentials})
-    {:reply, :ok, {client, service, new_credentials}}
+    {:ok, new_identity} = get_identity(client)
+    |> Map.put(identity, :lock, :false)
+    :ets.insert(ets_tablename(client), {:identity, new_identity})
+    {:reply, :ok, {client, new_identity}}
   end
 
   def handle_call(:stop, _from, state) do
@@ -90,167 +109,72 @@ defmodule ExOvh.Auth.Openstack.Swift.Cache do
     {:stop, :shutdown, :ok, state}
   end
 
-  def terminate(:shutdown, {client, service, credentials}) do
+  def terminate(:shutdown, {client, identity}) do
     Og.context(__ENV__, :debug)
-    :ets.delete(ets_tablename(client, service)) # explicilty remove
+    :ets.delete(ets_tablename(client)) # explicilty remove
     :ok
   end
 
 
-  # Private
-
-
-  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)
-
+  # private
 
 
-  def identity(client, {service_name, :webstorage} = service) when is_atom(client) do
-    credentials =  ExOvh.Ovh.V1.Webstorage.Query.get_credentials(service_name) |> client.request!()
-    identity(service_name, credentials, client)
+  defp create_identity(client, config, :webstorage) do
+    Og.context(__ENV__, :debug)
+    Webstorage.create_identity(client, config)
   end
-  def identity(client, {service_name, pcs_service_name, :cloudstorage} = service) when is_atom(client) do
-    credentials = ExOvh.Ovh.V1.Cloudstorage.Query.get_credentials(service_name, pcs_service_name) |> client.request!()
-    identity(service_name, credentials, client)
+  defp create_identity(client, config, :cloudstorage) do
+    Og.context(__ENV__, :debug)
+    Cloudstorage.create_identity(client, config)
   end
-
-
-  def identity(service_name, credentials, client) do
-
-    config = Utils.config(client)
-    q1 = ExOvh.Ovh.V1.Webstorage.Query.get_service(service_name)
-    {:ok, resp} = ExOvh.request(service_name)
-
-    %{
-      "server" => domain,
-      "storageLimit" => storage_limit,
-      "server" => server
-    } = resp.body
-
-
-    {:ok, resp} = ExOvh.request(credentials)
-
-    %{
-      "endpoint" => endpoint,
-      "login" => login,
-      "password" => password,
-      "tenant" => tenant
-    } = resp.body
-
-
-    method = :post
-    uri = endpoint <> "/tokens"
-    body = %{"auth" =>
-                %{
-                "passwordCredentials" => %{"username" => login, "password" => password}
-                }
-        }
-        |> Poison.encode!()
-    headers = [{"Content-Type", "application/json; charset=utf-8"}]
-    options = Utils.set_opts([], config)
-    resp = HTTPoison.request(method, uri, body, headers, 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)
-
-
-    method = :post
-    uri = endpoint <> "/tokens"
-    body = %{
-            "auth" =>
-                      %{
-                      "tenantName" => tenant,
-                      "token" => %{"id" => token}
-                      }
-            }
-    |> Poison.decode!()
-    headers = [{"Content-Type", "application/json; charset=utf-8"}]
-    options = Utils.set_opts([], config)
-    resp = HTTPoison.request(method, uri, body, headers, options)
-
-    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_name,
-            public_url: public_url(domain, swift_endpoint),
-            storage_limit: storage_limit,
-            server: server
-          }
-      }
-
+  defp create_identity(client, config, type) do
+    Og.context(__ENV__, :debug)
+    raise "create_identity/3 is only supported for the :webstorage and :cloudstorage types, #{inspect(type)}"
   end
 
 
-  # private
-
-
-  defp public_url(domain, swift_endpoint) do
-    path = URI.parse(swift_endpoint) |> Map.get(:path)
-    {version, account} = String.split_at(path, 4)
-    domain <> version <> account
+  defp get_identity(client) do
+    if supervisor_exists?(client) do
+      get_identity(client, 0)
+    else
+      case Supervisor.start_child(OpenstackSupervisor, [client]) do
+        {:error, error} -> raise inspect(error)
+        {:ok, _} ->
+          if supervisor_exists?(client) do
+            get_identity(client, 0)
+          else
+            raise Og.log_return("", __ENV__, :error) |> inspect()
+          end
+      end
+    end
   end
-
-  defp get_credentials(client, service, index) do
+  defp get_identity(client, index) do
     Og.context(__ENV__, :debug)
 
-    retry = fn(client, service, index) ->
-      if index > @get_credentials_retries do
-        raise "Cannot retrieve openstack credentials from ets table, #{__ENV__.module}, #{__ENV__.line}"
+    retry = fn(client, index) ->
+      if index > @get_identity_retries do
+        raise "Cannot retrieve openstack identity, #{__ENV__.module}, #{__ENV__.line}, client: #{client}"
       else
-        :timer.sleep(@get_credentials_sleep_interval)
-        get_credentials(client, service, index + 1)
+        :timer.sleep(@get_identity_interval)
+        get_identity(client, index + 1)
       end
     end
 
-    if ets_tablename(client, service) in :ets.all() do
-      table = :ets.lookup(ets_tablename(client, service), :credentials)
+    if ets_tablename(client) in :ets.all() do
+      table = :ets.lookup(ets_tablename(client), :identity)
       case table do
-        [credentials: credentials] ->
-          if credentials.lock === :true do
-            retry.(client, service, index)
+        [identity: identity] ->
+          if identity.lock === :true do
+            retry.(client, index)
           else
-            credentials
+            identity
           end
-        [] -> retry.(client,service,index)
+        [] -> retry.(client, index)
       end
     else
-      retry.(client, service, index)
+      retry.(client, index)
     end
+
   end
 
 
@@ -258,15 +182,16 @@ defmodule ExOvh.Auth.Openstack.Swift.Cache do
     Og.context(__ENV__, :debug)
     interval = (expires - 30) * 1000
     :timer.sleep(interval)
-    {: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"])
+    {:reply, :ok, _identity} = GenServer.call(self(), :add_lock)
+    {:reply, :ok, _identity} = GenServer.call(self(), :update_identity)
+    {:reply, :ok, identity} = GenServer.call(self(), :remove_lock)
+    identity |> Og.log_return(__ENV__, :debug)
+    expires = to_seconds(identity.token.expires)
     monitor_expiry(expires)
   end
 
 
-  defp create_ets_table(client, service) do
+  defp create_ets_table(client) do
     Og.context(__ENV__, :debug)
     ets_options = [
                    :set, # type
@@ -276,13 +201,15 @@ defmodule ExOvh.Auth.Openstack.Swift.Cache do
                    {:write_concurrency, :false},
                    {:read_concurrency, :true}
                   ]
-    unless ets_tablename(client, service) in :ets.all() do
-      :ets.new(ets_tablename(client, service), ets_options)
+    unless ets_tablename(client) in :ets.all() do
+      :ets.new(ets_tablename(client), ets_options)
     end
   end
 
 
-  defp to_seconds(iso_time) do
+  defp to_seconds(identity) do
+    identity |> Og.log_return(__ENV__, :debug)
+    iso_time = identity.token.expires
     {:ok, expiry_ndt, offset} = Calendar.NaiveDateTime.Parse.iso8601(iso_time)
     offset =
     case offset do
@@ -300,17 +227,32 @@ defmodule ExOvh.Auth.Openstack.Swift.Cache do
   end
 
 
-  defp supervisor_exists?(client, service) do
-    case Process.whereis(registered_supervisor_name(client, service)) do
+  defp supervisor_exists?(client) do
+    registered_name = gen_server_name(client)
+    |> Og.log_return(__ENV__, :debug)
+    case Process.whereis(registered_name) do
       :nil -> :false
       _pid -> :true
     end
   end
 
 
-  defp registered_supervisor_name(client, service) do
-    String.to_atom(Atom.to_string(client) <> service)
+  defp get_config(client) do
+    str = Atom.to_string(client) |> String.downcase()
+    config =
+    cond do
+      String.ends_with?(str, "webstorage") ->
+        client.swift_config() |> Keyword.fetch!(:webstorage)
+      String.ends_with?(str, "cloudstorage") ->
+        client.swift_config() |> Keyword.fetch!(:cloudstorage)
+      true ->
+        raise "config not found, #{Og.context(__ENV__, :error)}"
+    end
+    config
   end
 
+  # defp gen_server_name(client, config_id), do:  String.to_atom(Atom.to_string(config_id) <>  "-" <> Atom.to_string(client))
+  # def ets_tablename(client, config_id), do: String.to_atom(Atom.to_string(config_id) <>  "-" <> Atom.to_string(client))
+
 
 end
\ No newline at end of file
diff --git a/lib/auth/openstack/swift/cloudstorage.ex b/lib/auth/openstack/swift/cloudstorage.ex
new file mode 100644
index 0000000..18438c6
--- /dev/null
+++ b/lib/auth/openstack/swift/cloudstorage.ex
@@ -0,0 +1,54 @@
+defmodule ExOvh.Auth.Openstack.Swift.Cache.Cloudstorage do
+  @moduledoc :false
+  alias Openstex.Helpers.V2.Keystone.Identity
+
+  @doc :false
+  @spec create_identity(atom, atom) :: Identity.t | no_return
+  def create_identity(client, config) do
+    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
+      :nil ->
+        user = ExOvh.Ovh.V1.Cloud.Query.get_users(tenant_id)
+        |> ExOvh.request!()
+        |> Map.get(:body)
+        |> Enum.find(:nil,
+          fn(user) -> %{"description" => "ex_ovh"} = user end
+        )
+        if user == :nil do
+          # create user for "ex_ovh" description
+          ExOvh.Ovh.V1.Cloud.Query.create_user(tenant_id, "ex_ovh")
+          |> ExOvh.request!()
+          |> Map.get("id")
+        else
+          user["id"]
+        end
+      user_id -> user_id
+    end
+
+    resp = ExOvh.Ovh.V1.Cloud.Query.regenerate_credentials(tenant_id, user_id) |> ExOvh.request!()
+    password = resp.body["password"]
+    username = resp.body["username"]
+    endpoint = client.ovh_config()[:cloudstorage_endpoint]
+
+    # make sure the regenerate credentials had a chance to take effect
+    :timer.sleep(1000)
+
+    identity = Module.concat(client, Helpers.Keystone).authenticate!(endpoint, username, password, [tenant_id: tenant_id])
+  end
+
+#    token = Openstex.Keystone.V2.Query.get_token(endpoint, username, password)
+#    |> client.request!()
+#    |> Map.get(:body)
+#    |> Map.get("access")
+#    |> Map.get("token")
+#    |> Map.get("id")
+
+#    identity = Openstex.Keystone.V2.Query.get_identity(token, endpoint, tenant)
+#    |> client.request!()
+#    |> Map.get(:body)
+
+end
\ No newline at end of file
diff --git a/lib/auth/openstack/swift/webstorage.ex b/lib/auth/openstack/swift/webstorage.ex
new file mode 100644
index 0000000..6592bed
--- /dev/null
+++ b/lib/auth/openstack/swift/webstorage.ex
@@ -0,0 +1,61 @@
+defmodule ExOvh.Auth.Openstack.Swift.Cache.Webstorage do
+  @moduledoc :false
+  alias Openstex.Helpers.V2.Keystone.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, String.t) :: __MODULE__.t | no_return
+  def webstorage(client, config) do
+    cdn_name = Keyword.fetch!(config, :cdn_name)
+    properties = ExOvh.Ovh.V1.Webstorage.Query.get_service(cdn_name) |> client.request!() |> Map.fetch!(:body)
+    credentials = ExOvh.Ovh.V1.Webstorage.Query.get_credentials(cdn_name) |> client.request!() |> Map.fetch!(:body)
+
+    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) :: Identity.t | no_return
+  def create_identity(client, config_id) do
+    config = client.swift_config() |> Keyword.fetch!(config_id)
+    cdn_name = Keyword.fetch!(config, :cdn_name)
+    webstorage = webstorage(client, cdn_name)
+    %{endpoint: endpoint, username: username, password: password, tenant_name: tenant_name} = webstorage
+    identity = Module.concat(client, Helpers.Keystone).authenticate!(endpoint, username, password, [tenant_name: tenant_name])
+  end
+
+#  token = Openstex.Keystone.V2.Query.get_token(endpoint, username, password)
+#  |> Og.log_return(:warn)
+#  |> client.request!()
+#  |> Og.log_return(:warn)
+#  |> Map.get(:body)
+#  |> Map.get("access")
+#  |> Map.get("token")
+#  |> Map.get("id")
+#  # |> Map.get("body")["access"]["token"]["id"]
+#  # |> Map.get(:body)  |> Og.log_return(:debug) |> Map.get("access") |> Og.log_return(:debug) |> Map.get("token") |> Og.log_return(:debug) |> Map.get("id")
+#
+#  {token, endpoint, tenant} |> Og.log()
+#  identity = Openstex.Keystone.V2.Query.get_identity(token, endpoint, tenant)
+#  |> Og.log_return(:debug)
+#  |> client.request!()
+#  |> Og.log_return(:debug)
+#  |> Keystone.parse_nested_map_into_identity_struct()
+
+end
\ No newline at end of file
diff --git a/lib/auth/ovh/auth.ex b/lib/auth/ovh/auth.ex
index 05a585b..0044826 100644
--- a/lib/auth/ovh/auth.ex
+++ b/lib/auth/ovh/auth.ex
@@ -11,27 +11,28 @@ defimpl Openstex.Auth, for: ExOvh.Ovh.Query do
 
 
   @spec prepare_request(Query.t, Keyword.t, atom) :: Openstex.HttpQuery.t
-  def prepare_request(query, opts, client)
+  def prepare_request(query, httpoison_opts, client)
 
-  def prepare_request(%Query{method: method, uri: uri, params: params}, opts, client) when method in [:get, :head, :delete] do
-    config = Utils.config(client)
-    if params !== :nil and params !== "" and is_map(params), do: uri = uri <> "?" <> URI.encode_query(params)
-    if params !== :nil and params !== "" and is_map(params) === :false, do: uri = uri <> URI.encode_www_form(params)
-    uri = Utils.uri(uri, config)
+  def prepare_request(%Query{method: method, uri: uri, params: params}, httpoison_opts, client) when method in [:get, :head, :delete] do
+    uri = if params !== :nil and params !== "" and is_map(params), do: uri <> "?" <> URI.encode_query(params), else: uri
+    uri = if params !== :nil and params !== "" and is_map(params) === :false, do: uri <> URI.encode_www_form(params), else: uri
+    ovh_config = client.ovh_config()
+    uri = ovh_config[:endpoint] <> ovh_config[:api_version] <> uri
     body = params || ""
-    headers = headers([Utils.app_secret(config), Utils.app_key(config), Utils.get_consumer_key(config), Atom.to_string(method), uri, ""], client)
-    options = Utils.set_opts(opts, config)
+    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)
     %Openstex.HttpQuery{method: method, uri: uri, body: body, headers: headers, options: options, service: :ovh}
   end
 
-  def prepare_request(%Query{method: method, uri: uri, params: params}, opts, client) when method in [:post, :put] do
-    config = Utils.config(client)
+  def prepare_request(%Query{method: method, uri: uri, params: params}, httpoison_opts, client) when method in [:post, :put] do
     if params !== "" and params !== :nil and is_map(params), do: params = Poison.encode!(params)
-    uri = Utils.uri(uri, config)
+    ovh_config = client.ovh_config()
+    uri = ovh_config[:endpoint] <> ovh_config[:api_version] <> uri
     body = params || ""
-    header_opts = [Utils.app_secret(config), Utils.app_key(config), Utils.get_consumer_key(config), Atom.to_string(method), uri, params]
-    headers = headers([Utils.app_secret(config), Utils.app_key(config), Utils.get_consumer_key(config), Atom.to_string(method), uri, ""], client)
-    options = Utils.set_opts(opts, config)
+    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)
     %Openstex.HttpQuery{method: method, uri: uri, body: body, headers: headers, options: options, service: :ovh}
   end
 
diff --git a/lib/auth/ovh/cache.ex b/lib/auth/ovh/cache.ex
index 9671384..dae9031 100644
--- a/lib/auth/ovh/cache.ex
+++ b/lib/auth/ovh/cache.ex
@@ -8,26 +8,18 @@ defmodule ExOvh.Auth.Ovh.Cache do
   # Public
 
 
-  def start_link({client, config, opts}) do
+  def start_link({client, ovh_config, opts}) do
     Og.context(__ENV__, :debug)
-    client
-    |> Og.log_return(__ENV__, :warn)
-    GenServer.start_link(__MODULE__, {client, config, opts}, [name: gen_server_name(client)])
+    GenServer.start_link(__MODULE__, {client, ovh_config}, [name: gen_server_name(client)])
   end
 
 
   @doc "Retrieves the ovh api time diff from the state"
   def get_time_diff(client) do
-    client |> Og.log_return(__ENV__, :warn)
-    gen_server_name(client) |> Og.log_return(__ENV__, :warn)
-
     GenServer.call(gen_server_name(client), :get_diff)
   end
   @doc "Retrieves the ovh config map"
-  def get_config(client) do
-    client |> Og.log_return(__ENV__, :warn)
-    gen_server_name(client) |> Og.log_return(__ENV__, :warn)
-
+  def get_ovh_config(client) do
     GenServer.call(gen_server_name(client), :get_config)
   end
 
@@ -35,25 +27,25 @@ defmodule ExOvh.Auth.Ovh.Cache do
   # Genserver Callbacks
 
 
-  def init({client, config, opts}) do
+  def init({client, ovh_config}) do
     Og.context(__ENV__, :debug)
-    diff = calculate_diff(config)
-    {:ok, {config, diff}}
+    diff = calculate_diff(client, ovh_config)
+    {:ok, {ovh_config, diff}}
   end
 
-  def handle_call(:get_diff, _from, {config, diff}) do
+  def handle_call(:get_diff, _from, {ovh_config, diff}) do
     Og.context(__ENV__, :debug)
-    {:reply, diff, {config, diff}}
+    {:reply, diff, {ovh_config, diff}}
   end
 
-  def handle_call(:get_config, _from, {config, diff}) do
+  def handle_call(:get_config, _from, {ovh_config, diff}) do
     Og.context(__ENV__, :debug)
-    {:reply, config, {config, diff}}
+    {:reply, ovh_config, {ovh_config, diff}}
   end
 
-  def handle_cast({:set_diff, new_diff}, {config, diff}) do
+  def handle_cast({:set_diff, new_diff}, {ovh_config, diff}) do
     Og.context(__ENV__, :debug)
-    {:noreply, {config, new_diff}}
+    {:noreply, {ovh_config, new_diff}}
   end
 
   def terminate(:shutdown, state) do
@@ -66,19 +58,21 @@ defmodule ExOvh.Auth.Ovh.Cache do
   # Private
 
 
-  defp api_time_request(config) do
+  defp api_time_request(client, ovh_config) do
+    Og.context(__ENV__, :debug)
     method = :get
-    uri = Utils.endpoint(config) <> Utils.api_version(config) <> "/auth/time"
+    uri = ovh_config[:endpoint] <> ovh_config[:api_version] <> "/auth/time"
     body = ""
     headers = [{"Content-Type", "application/json; charset=utf-8"}]
-    options = Utils.set_opts([], config)
+    httpoison_config = client.httpoison_config()
+    options = httpoison_config
     resp = HTTPoison.request!(method, uri, body, headers, options)
     api_time = Poison.decode!(resp.body)
   end
 
 
-  defp calculate_diff(config) do
-    api_time = api_time_request(config)
+  defp calculate_diff(client, ovh_config) do
+    api_time = api_time_request(client, ovh_config)
     os_t = :os.system_time(:seconds)
     os_t - api_time
   end
@@ -86,11 +80,11 @@ defmodule ExOvh.Auth.Ovh.Cache do
 
   #Caches the ovh api time diff
   defp set_time_diff(client) do
-    config = get_config(client)
-    set_time_diff(client, config)
+    ovh_config = get_config(client)
+    set_time_diff(client, ovh_config)
   end
-  defp set_time_diff(client, config) when is_map(config) do
-    diff = calculate_diff(config)
+  defp set_time_diff(client, ovh_config) when is_list(ovh_config) do
+    diff = calculate_diff(client, ovh_config)
     GenServer.cast(gen_server_name(client), {:set_diff, diff})
   end
 
diff --git a/lib/auth/supervisor.ex b/lib/auth/supervisor.ex
index 78f45c7..6db5329 100644
--- a/lib/auth/supervisor.ex
+++ b/lib/auth/supervisor.ex
@@ -4,35 +4,30 @@ defmodule ExOvh.Auth.Supervisor do
   use Supervisor
   import ExOvh.Utils, only: [supervisor_name: 1]
   alias ExOvh.Auth.Ovh.Cache, as: OvhCache
-  alias ExOvh.Auth.Openstack.Swift.Cache, as: SwiftCache
+  alias ExOvh.Auth.Openstack.Supervisor, as: OpenstackSupervisor
 
 
   #  Public
 
 
-  @doc ~S"""
-  Starts the OVH supervisor.
-  """
-  def start_link(client, config, opts) do
+  def start_link(client, ovh_config, opts) do
     Og.context(__ENV__, :debug)
-    Supervisor.start_link(__MODULE__, {client, config, opts}, [name: supervisor_name(client)])
+    Supervisor.start_link(__MODULE__, {client, ovh_config, opts}, [name: supervisor_name(client)])
   end
 
 
   # Supervisor Callbacks
 
 
-  def init({client, config, opts}) do
+  def init({client, ovh_config, opts}) do
     Og.context(__ENV__, :debug)
-    Og.log({client, config, opts}, __ENV__, :debug)
 
     tree = [
             {OvhCache,
-              {OvhCache, :start_link, [{client, config, opts}]}, :transient, 10_000, :worker, [OvhCache]},
-#            {SwiftCache,
-#              {SwiftCache, :start_link, [{client, config, opts}]}, :permanent, 10_000, :worker, [SwiftCache]}
+              {OvhCache, :start_link, [{client, ovh_config, opts}]}, :permanent, 10_000, :worker, [OvhCache]},
+            {OpenstackSupervisor,
+              {OpenstackSupervisor, :start_link, []}, :permanent, 10_000, :supervisor, [OpenstackSupervisor]}
            ]
-
     supervise(tree, strategy: :one_for_one)
   end
 
diff --git a/lib/client.ex b/lib/client.ex
index f556248..6d7e1db 100644
--- a/lib/client.ex
+++ b/lib/client.ex
@@ -1,39 +1,85 @@
 defmodule ExOvh.Client do
-  @moduledoc ~S"""
-  """
-  alias ExOvh.Defaults
-
+  @moduledoc :false
 
   defmacro __using__(opts) do
     quote bind_quoted: [opts: opts] do
-      @otp_app Keyword.get(opts, :otp_app, :ex_ovh)
-
-      use Openstex.Client, client: __MODULE__, swift_cache: __MODULE__.Auth.Openstack.Swift.Cache
-
-      # Incorporation of the Swift Oject Storage Helpers modules.
-      defmodule Helpers.Swift do
-        %Macro.Env{context_modules: [_, client_module]} = __ENV__
-         use Openstex.Helpers.V1.Swift, client: client_module
-       end
-
-      # Incorporation of the Custom Ovh Helpers modules.
-      defmodule Helpers.Ovh do
-       %Macro.Env{context_modules: [_, _, client_module]} = __ENV__
-        use ExOvh.Ovh.V1.Webstorage.Helpers, client: client_module
+    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
 
-      if (@otp_app != :ex_ovh)  do
-        def config(), do: Application.get_env(@otp_app, __MODULE__)
-        |> Keyword.fetch!(:ovh)
-      else
-        def config(), do: Application.get_all_env(@otp_app)
-        |> Keyword.fetch!(:ovh)
+      def swift_config() do
+        config() |> Keyword.fetch!(:swift)
       end
 
 
-      def start_link(opts \\ []) do
-        ExOvh.Supervisor.start_link(__MODULE__, config(), opts)
+      def start_link(sup_opts \\ []) do
+        ExOvh.Supervisor.start_link(__MODULE__, ovh_config(), sup_opts)
       end
 
 
@@ -41,16 +87,29 @@ defmodule ExOvh.Client do
   end
 
 
-  @doc ~s"""
-  Starts the ovh supervisors.
-  """
   @callback start_link() :: :ok | {:error, {:already_started, pid}} | {:error, term}
-
-
-  @doc ~s"""
-  Gets the ovh config from the application environment.
-  """
-  @callback config() :: :nil | map
-
+  @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
\ No newline at end of file
diff --git a/lib/defaults.ex b/lib/defaults.ex
index 03958ae..d0bcdf7 100644
--- a/lib/defaults.ex
+++ b/lib/defaults.ex
@@ -6,7 +6,8 @@ defmodule ExOvh.Defaults do
   def ovh() do
     %{
       endpoint: "ovh-eu",
-      api_version: "1.0"
+      api_version: "1.0",
+      cloudstorage_endpoint: "https://auth.cloud.ovh.net/v2.0"
     }
   end
 
@@ -25,6 +26,15 @@ defmodule ExOvh.Defaults do
     }
   end
 
+  @doc "Returns the default suffix for creating a new application in ovh"
+  @spec create_app_uri_suffix() :: String.t
+  def create_app_uri_suffix(), do: "createApp/"
+
+
+  @doc "Returns the default suffix for getting the consumer key in ovh"
+  @spec consumer_key_suffix() :: String.t
+  def consumer_key_suffix(), do: "/auth/credential/"
+
 
   @doc "Returns the default access rules (all methods and paths by default)"
   @spec access_rules() :: [map]
diff --git a/lib/ex_ovh.ex b/lib/ex_ovh.ex
index 4919798..4b3d8e3 100644
--- a/lib/ex_ovh.ex
+++ b/lib/ex_ovh.ex
@@ -1,10 +1,13 @@
 defmodule ExOvh do
   @moduledoc :false
-  @ex_ovh_config Application.get_all_env(:ex_ovh) |> Keyword.get(:ovh, :nil)
 
-  # Define a standard ExOvh client only if the user has entered a config :ex_ovh, ex_ovh: %{...} into the configuration file.
-  unless  @ex_ovh_config in [%{}, :nil] do
-    use ExOvh.Client, otp_app: :ex_ovh
-  end
+  use ExOvh.Client, otp_app: :ex_ovh
+
+end
+
+# The following way multiple clients to be configured and created.
+#defmodule MyApp.ExOvhClient1 do
+#  @moduledoc :false
+#  use ExOvh.Client, otp_app: :my_app
+#end
 
-end
\ No newline at end of file
diff --git a/lib/mix/tasks/ovh.ex b/lib/mix/tasks/ovh.ex
index c835415..ae18dec 100644
--- a/lib/mix/tasks/ovh.ex
+++ b/lib/mix/tasks/ovh.ex
@@ -70,6 +70,7 @@ defmodule Mix.Tasks.Ovh do
   """
   use Mix.Task
   alias ExOvh.Utils
+  alias ExOvh.Defaults
 
 
   @default_headers [{"Content-Type", "application/json; charset=utf-8"}]
@@ -112,7 +113,6 @@ defmodule Mix.Tasks.Ovh do
 
   defp parse_args(args) do
     {opts, _, _} = OptionParser.parse(args)
-    Og.log_return(opts, :debug)
     {opts, opts_map } = opts
     |> has_required_args()
     |> parsers_login()
@@ -187,7 +187,7 @@ defmodule Mix.Tasks.Ovh do
   defp parsers_access_rules({opts, acc}) do
     access_rules = Keyword.get(opts, :accessrules, :nil)
     if access_rules === :nil do
-      access_rules = Utils.access_rules()
+      access_rules = Defaults.access_rules()
     else
       access_rules = access_rules
       |> String.split("::")
@@ -220,7 +220,7 @@ defmodule Mix.Tasks.Ovh do
     Og.context(__ENV__, :debug)
 
     method = :get
-    uri = Utils.default_create_app_uri(opts_map)
+    uri = opts_map[:endpoint] <> Defaults.create_app_uri_suffix()
     body = ""
     headers = []
     options = @default_options
@@ -231,6 +231,7 @@ defmodule Mix.Tasks.Ovh do
 
   defp get_create_app_inputs(resp_body) do
     Og.context(__ENV__, :debug)
+
     inputs = Floki.find(resp_body, "form input")
     |> List.flatten()
     if Enum.any?(inputs, fn(input) -> input === [] end), do: raise "Empty input found"
@@ -240,6 +241,7 @@ defmodule Mix.Tasks.Ovh do
 
   defp build_app_request(inputs, %{login: login, password: password} = opts_map) do
     Og.context(__ENV__, :debug)
+
     {acc, _index, _max} =
     Enum.reduce(inputs, {"", 1, Enum.count(inputs)}, fn({"input", input, _}, acc) ->
       name = :proplists.get_value("name", input)
@@ -273,16 +275,12 @@ defmodule Mix.Tasks.Ovh do
     Og.context(__ENV__, :debug)
 
     method = :post
-    uri = Utils.endpoints()[opts_map.endpoint] <> "createApp/"
+    uri = opts_map[:endpoint] <> "createApp/"
     body = req_body
     headers = [{"Content-Type", "application/x-www-form-urlencoded"}]
     options = @default_options
     resp = HTTPoison.request!(method, uri, body, headers, options)
 
-    resp.body
-    |> Og.log_return(__ENV__, :warn)
-
-    error_msg1 =
     # Error checking
     cond do
      String.contains?(resp.body, msg = "There is already an application with that name for that Account ID") ->
@@ -325,9 +323,9 @@ defmodule Mix.Tasks.Ovh do
     Og.context(__ENV__, :debug)
 
     method = :post
-    uri = Utils.consumer_key_uri(opts_map)
+    uri = opts_map[:endpoint] <> opts_map[:api_version] <> Defaults.consumer_key_suffix()
     body = %{ accessRules: access_rules, redirection: redirect_uri } |> Poison.encode!()
-    headers = Map.merge(Enum.into(@default_headers, %{}), Enum.into([{"X-Ovh-Application", Utils.app_key(opts_map)}], %{})) |> Enum.into([])
+    headers = Map.merge(Enum.into(@default_headers, %{}), Enum.into([{"X-Ovh-Application", opts_map[:application_key]}], %{})) |> Enum.into([])
     options = @default_options
     resp = HTTPoison.request!(method, uri, body, headers, options)
 
@@ -337,6 +335,7 @@ defmodule Mix.Tasks.Ovh do
 
 
   defp bind_consumer_key_to_app({ck, validation_url}, opts_map) do
+    Og.context(__ENV__, :debug)
 
     method = :get
     uri = validation_url
@@ -353,6 +352,8 @@ defmodule Mix.Tasks.Ovh do
 
 
   defp get_bind_ck_to_app_inputs(resp_body) do
+    Og.context(__ENV__, :debug)
+
     inputs = Floki.find(resp_body, "form input") ++
     Floki.find(resp_body, "form select")
     |> List.flatten()
@@ -366,6 +367,7 @@ defmodule Mix.Tasks.Ovh 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) ->
       {name_val, value} =
@@ -405,7 +407,6 @@ defmodule Mix.Tasks.Ovh do
   defp send_ck_binding_request(req_body, validation_url, ck) do
     Og.context(__ENV__, :debug)
 
-
     method = :post
     uri = validation_url
     body = req_body
@@ -428,6 +429,8 @@ defmodule Mix.Tasks.Ovh do
 
 
   defp get_credentials(opts_map) do
+    Og.context(__ENV__, :debug)
+
     create_app_body = get_app_create_page(opts_map) |> get_create_app_inputs() |> build_app_request(opts_map) |> send_app_request(opts_map)
     opts_map = Map.merge(opts_map, %{
       application_key: get_application_key(create_app_body),
@@ -447,6 +450,8 @@ defmodule Mix.Tasks.Ovh do
 
 
   defp config_names(client_name) do
+    Og.context(__ENV__, :debug)
+
     {config_header, mod_client_name} =
     case client_name  do
       "ex_ovh" ->
@@ -488,6 +493,8 @@ defmodule Mix.Tasks.Ovh do
 
 
   defp print_config(options) do
+    Og.context(__ENV__, :debug)
+
     client_name = options.client_name
     {config_header, mod_client_name} = config_names(client_name)
 
diff --git a/lib/ovh/v1/cloud/cloudstorage/query.ex b/lib/ovh/v1/cloud/cloudstorage/query.ex
new file mode 100644
index 0000000..ba0c579
--- /dev/null
+++ b/lib/ovh/v1/cloud/cloudstorage/query.ex
@@ -0,0 +1,92 @@
+defmodule ExOvh.Ovh.V1.Cloud.Cloudstorage.Query do
+  @moduledoc ~s"""
+  Helper functions for building `queries directed at the `/cloud` part of the custom ovh api and for cloudstorage in particular.
+  See `ExOvh.Ovh.V1.Cloud.Query` for generic cloud requests.
+
+
+  ## Notes
+
+  Coverage for the following ovh api requests:
+
+
+      | Function | OVH API call |
+      |---|---|
+      | get_containers(service_name) | GET /cloud/project/{serviceName}/storage Get storage containers |
+      | create_container(service_name, container_name, region \\ "SBG1") | POST /cloud/project/{serviceName}/storage Create container |
+      |  |  |
+      |  |  |
+      |  |  |
+      |  |  |
+      |  |  |
+      |  |  |
+      |  |  |
+
+
+#  GET /cloud/project/{serviceName}/storage/access Access to storage API
+#  GET /cloud/project/{serviceName}/storage/{containerId} Get storage container
+#  DELETE /cloud/project/{serviceName}/storage/{containerId} Delete container
+#  POST /cloud/project/{serviceName}/storage/{containerId}/cors Add CORS support on your container
+#  POST /cloud/project/{serviceName}/storage/{containerId}/static Deploy your container files as a static web site
+#  POST /cloud/project/{serviceName}/terminate
+
+
+  ## Example
+
+      ExOvh.Ovh.V1.Cloud.Cloudstorage.Query.get_containers(service_name) |> ExOvh.request!()
+  """
+  alias ExOvh.Ovh.Query
+
+
+  @doc ~s"""
+  GET /cloud/project/{serviceName}/storage Get storage containers
+
+  ## Arguments
+
+  - service_name: service name for the ovh cloud service
+
+
+  ## Example
+
+      ExOvh.Ovh.V1.Cloud.Cloudstorage.Query.get_containers(service_name) |> ExOvh.request!()
+  """
+  @spec get_containers(String.t) :: Query.t
+  def get_containers(service_name) do
+    %Query{
+          method: :get,
+          uri: "/cloud/project/#{service_name}/storage",
+          params: :nil
+          }
+  end
+
+
+  @doc ~s"""
+  POST /cloud/project/{serviceName}/storage Create container
+
+  ## Arguments
+
+  - service_name: service name for the ovh cloud service
+  - container_name: name for the new container
+  - region: region for the new container, defaults to "SBG1". See regions by running:
+  Currently can choose from "GRA1", "BHS1", "SBG1".
+
+
+  ## Example
+
+      ExOvh.Ovh.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
+    # POST /cloud/project/{serviceName}/storage Create container
+    %Query{
+          method: :post,
+          uri: "/cloud/project/#{service_name}/storage",
+          params: %{
+                    "containerName" => container_name,
+                    "region" => region
+                  } |> Poison.encode!()
+          }
+  end
+
+
+
+end
diff --git a/lib/ovh/v1/cloud/query.ex b/lib/ovh/v1/cloud/query.ex
new file mode 100644
index 0000000..c7595ba
--- /dev/null
+++ b/lib/ovh/v1/cloud/query.ex
@@ -0,0 +1,189 @@
+defmodule ExOvh.Ovh.V1.Cloud.Query do
+  @moduledoc ~s"""
+  Helper functions for building queries directed at the `/cloud` part of the ovh api.
+
+  ## Notes
+
+  | Function | Description | OVH API call |
+  |---|---|---|
+  | `list_services/0` | <small>List available services</small> | <sub><sup>GET /cloud/project</sup></sub> |
+  | `get_users/1` | <small>Get all users</small> | <sub><sup>GET /cloud/project/{serviceName}/user</sup></sub> |
+  | `create_user/2` | <small>Create user</small> | <sub><sup>POST /cloud/project/{serviceName}/user</sup></sub> |
+  | `get_user_details/2` | <small>Get user details</small> | <sub><sup>GET /cloud/project/{serviceName}/user/{userId}</sup></sub> |
+  | `delete_user/2` | <small>Delete user</small> | <sub><sup>DELETE /cloud/project/{serviceName}/user/{userId}</sup></sub> |
+  | `download_openrc_script/3` | <small>Get RC file of OpenStack</small> | <sub><sup>GET /cloud/project/{serviceName}/user/{userId}/openrc</sup></sub> |
+  | `regenerate_credentials/2`  | <small>Regenerate user credentials including password</small> | <sub><sup>POST /cloud/project/{serviceName}/user/{userId}/regeneratePassword</sup></sub> |
+  | `swift_identity/3` | <small>Gets a json object similar to that returned by Keystone Identity. Includes the 'X-Auth-Token'</small> | <sub><sup>POST /cloud/project/{serviceName}/user/{userId}/token</sup></sub> |
+
+
+  ## TODO
+
+  POST /cloud/createProject Start a new cloud project
+  GET /cloud/price Get services prices
+  GET /cloud/project/{serviceName} Get this object properties
+  PUT /cloud/project/{serviceName} Alter this object properties
+  GET /cloud/project/{serviceName}/acl Get ACL on your cloud project
+  POST /cloud/project/{serviceName}/acl
+  GET /cloud/project/{serviceName}/serviceInfos
+  GET /cloud/project/{serviceName}/quota Get project quotas
+  GET /cloud/project/{serviceName}/region Get regions
+  GET /cloud/project/{serviceName}/region/{regionName}
+  GET /cloud/project/{serviceName}/consumption
+  GET /cloud/project/{serviceName}/bill
+
+
+  ## Example
+
+      ExOvh.Ovh.V1.Cloud.Cloudstorage.Query.get_containers(service_name) |> ExOvh.request!()
+  """
+  alias ExOvh.Ovh.Query
+
+
+  @doc ~s"""
+  GET /cloud/project List available services
+
+  ## Example
+
+      ExOvh.Ovh.V1.Cloud.Query.list_services() |> ExOvh.request!()
+  """
+  @spec list_services() :: Query.t
+  def list_services() do
+    %Query{
+          method: :get,
+          uri: "/cloud/services",
+          params: :nil
+          }
+  end
+
+
+  @doc ~s"""
+  GET /cloud/project/{serviceName}/user Get all users
+
+  ## Example
+
+      ExOvh.Ovh.V1.Cloud.Query.get_users(service_name) |> ExOvh.request!()
+  """
+  @spec get_users(String.t) :: Query.t
+  def get_users(service_name) do
+    %Query{
+          method: :get,
+          uri: "/cloud/project/#{service_name}/user",
+          params: :nil
+          }
+  end
+
+
+  @doc ~s"""
+  POST /cloud/project/{serviceName}/user Create user
+
+  ## Example
+
+      ExOvh.Ovh.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
+    %Query{
+          method: :get,
+          uri: "/cloud/project/#{service_name}/user",
+          params: %{
+                    "description" => description
+                  }
+                  |> Poison.encode!()
+          }
+  end
+
+
+  @doc ~s"""
+  GET /cloud/project/{serviceName}/user/{userId} Get user details
+
+  ## Example
+
+      ExOvh.Ovh.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
+    %Query{
+          method: :get,
+          uri: "/cloud/project/#{service_name}/user/#{user_id}",
+          params: :nil
+          }
+  end
+
+
+  @doc ~s"""
+  DELETE /cloud/project/{serviceName}/user/{userId} Delete user
+
+  ## Example
+
+      ExOvh.Ovh.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
+    %Query{
+          method: :delete,
+          uri: "/cloud/project/#{service_name}/user/#{user_id}",
+          params: :nil
+          }
+  end
+
+
+  @doc ~s"""
+  GET /cloud/project/{serviceName}/user/{userId}/openrc Get RC file of OpenStack
+
+  ## Example
+
+      ExOvh.Ovh.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
+    %Query{
+          method: :get,
+          uri: "/cloud/project/#{service_name}/user/#{user_id}/openrc",
+          params: %{
+                    region: region
+                  }
+          }
+  end
+
+
+  @doc ~s"""
+  POST /cloud/project/{serviceName}/user/{userId}/regeneratePassword Regenerate user password
+
+  ## Example
+
+      ExOvh.Ovh.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
+    %Query{
+          method: :post,
+          uri: "/cloud/project/#{service_name}/user/#{user_id}/regeneratePassword",
+          params: :nil
+          }
+  end
+
+
+  @doc ~s"""
+  POST /cloud/project/{serviceName}/user/{userId}/token  Get the token for the user (very similar to
+  keystone identity)
+
+  ## Example
+
+      ExOvh.Ovh.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
+    %Query{
+          method: :post,
+          uri: "/cloud/project/#{service_name}/user/#{user_id}/token",
+          params: %{
+                  "password" => password
+                  }
+                  |> Poison.encode!()
+          }
+  end
+
+
+
+
+end
\ No newline at end of file
diff --git a/lib/ovh/v1/webstorage/helpers.ex b/lib/ovh/v1/webstorage/helpers.ex
deleted file mode 100644
index 679eef8..0000000
--- a/lib/ovh/v1/webstorage/helpers.ex
+++ /dev/null
@@ -1,16 +0,0 @@
-defmodule ExOvh.Ovh.V1.Webstorage.Helpers do
-  @moduledoc :false
-  # alias ExOvh.Ovh.V1.Webstorage.Query
-  # alias Openstex.Response
-
-  defmacro __using__(opts) do
-    quote bind_quoted: [opts: opts] do
-      @client Keyword.fetch!(opts, :client)
-
-      # No helpers yet
-
-    end
-  end
-
-
-end
diff --git a/lib/request/ovh/request.ex b/lib/request/ovh/request.ex
index f7aa6a2..f7cee64 100644
--- a/lib/request/ovh/request.ex
+++ b/lib/request/ovh/request.ex
@@ -9,17 +9,17 @@ defimpl Openstex.Request, for: ExOvh.Ovh.Query do
 
 
   @spec request(Query.t, Keyword.t, atom) :: {:ok, Response.t} | {:error, Response.t}
-  def request(query, opts, client) do
+  def request(query, httpoison_opts, client) do
     Og.context(__ENV__, :debug)
 
-    q = Auth.prepare_request(query, opts, client) |> Map.from_struct()
+    q = Auth.prepare_request(query, httpoison_opts, client) |> Map.from_struct()
 
-    options = set_opts(q.options, opts)
+    options = Keyword.merge(q.options, httpoison_opts)
     case HTTPoison.request(q.method, q.uri, q.body, q.headers, options) do
       {:ok, resp} ->
         body = parse_body(resp)
         resp = %Response{ body: body, headers: resp.headers |> Enum.into(%{}), status_code: resp.status_code }
-        if resp.status_code >= 100 and resp.status_code < 300 do
+        if resp.status_code >= 100 and resp.status_code < 400 do
           {:ok, resp}
         else
           {:error, resp}
@@ -34,7 +34,7 @@ defimpl Openstex.Request, for: ExOvh.Ovh.Query do
   # private
 
 
-  def parse_body(resp) do
+  defp parse_body(resp) do
     try do
        resp.body |> Poison.decode!()
     rescue
@@ -44,9 +44,6 @@ defimpl Openstex.Request, for: ExOvh.Ovh.Query do
   end
 
 
-  defp set_opts(query_opts, opts), do: Keyword.merge(query_opts, opts)
-
-
 end
 
 
diff --git a/lib/supervisor.ex b/lib/supervisor.ex
index 8dbada8..bdd4bb2 100644
--- a/lib/supervisor.ex
+++ b/lib/supervisor.ex
@@ -9,25 +9,25 @@ defmodule ExOvh.Supervisor do
   #  Public
 
 
-  def start_link(client, config, opts) do
+  def start_link(client, ovh_config, opts) do
     Og.context(__ENV__, :debug)
-    Supervisor.start_link(__MODULE__, {client, config, opts}, [name: client])
+    Supervisor.start_link(__MODULE__, {client, ovh_config, opts}, [name: client])
   end
 
 
   #  Callbacks
 
 
-  def init({client, config, opts}) do
+  def init({client, ovh_config, opts}) do
     Og.context(__ENV__, :debug)
     sup_tree =
-    case ovh_config(config, client) do
+    case ovh_config(ovh_config, client) do
       {:error, :config_not_found} ->
         Og.log("No ovh config found. Ovh supervisor will not be started for client #{client}", :error)
         []
-      valid_config ->
+      valid_ovh_config ->
         [{AuthSupervisor,
-         {AuthSupervisor, :start_link, [client, valid_config, opts]}, :permanent, 10_000, :supervisor, [AuthSupervisor]}]
+         {AuthSupervisor, :start_link, [client, valid_ovh_config, opts]}, :permanent, 10_000, :supervisor, [AuthSupervisor]}]
     end
     if sup_tree === [] do
         raise "No configuration found for ovh."
@@ -36,14 +36,12 @@ defmodule ExOvh.Supervisor do
   end
 
 
-  @doc """
-  Gets the ovh config settings.
-  """
-  @spec ovh_config(config :: map, client :: atom) :: map | {:error, atom}
-  def ovh_config(config, client) do
-    case config do
+  @doc "Gets the ovh config settings."
+  @spec ovh_config(map, atom) :: map | {:error, :config_not_found}
+  def ovh_config(ovh_config, client) do
+    case ovh_config do
       :nil -> {:error, :config_not_found}
-      _ -> Map.merge(Defaults.ovh(), client.config())
+      _ -> Map.merge(Defaults.ovh(), client.ovh_config())
     end
   end
 
diff --git a/lib/utils/utils.ex b/lib/utils/utils.ex
index bed4f44..c74cb97 100644
--- a/lib/utils/utils.ex
+++ b/lib/utils/utils.ex
@@ -1,7 +1,8 @@
 defmodule ExOvh.Utils do
   @moduledoc false
 
-  alias ExOvh.Auth.Ovh.Cache
+  alias ExOvh.Auth.Ovh.Cache, as: OvhCache
+  alias ExOvh.Auth.Openstack.Swift.Cache, as: SwiftCache
   alias ExOvh.Defaults
 
 
@@ -94,21 +95,4 @@ defmodule ExOvh.Utils do
   end
 
 
-  def config(client), do: Cache.get_config(client)
-  def endpoints(), do: Defaults.endpoints()
-  def endpoint(config), do: Defaults.endpoints()[config[:endpoint]]
-  def api_version(config), do: config[:api_version]
-  def uri(uri, config), do: endpoint(config) <> api_version(config) <> uri
-  def app_secret(config), do: config[:application_secret]
-  def app_key(config), do: config[:application_key]
-  def get_consumer_key(config), do: config[:consumer_key]
-  def connect_timeout(config), do: config[:connect_timeout]
-  def receive_timeout(config), do: config[:receive_timeout]
-  def set_opts(opts, config), do: Keyword.merge([ timeout: connect_timeout(config), recv_timeout: receive_timeout(config) ], opts)
-  def access_rules(), do: Defaults.access_rules()
-  def access_rules(config), do: config[:access_rules]
-  def default_create_app_uri(config), do: endpoint(config) <> "createApp/"
-  def consumer_key_uri(config), do: endpoint(config) <> api_version(config) <> "/auth/credential/"
-
-
 end
diff --git a/mix.exs b/mix.exs
index ca70f13..3df52ab 100644
--- a/mix.exs
+++ b/mix.exs
@@ -12,7 +12,12 @@ defmodule ExOvh.Mixfile do
       start_permanent: Mix.env == :prod,
       description: description(),
       package: package(),
-      deps: deps()
+      deps: deps(),
+      docs: [
+        main: "README.md",
+        extra_section: "Readme",
+        extras: ["README.md": [path: "README.md", title: "Readme"]]
+      ]
      ]
   end
 
@@ -31,8 +36,7 @@ defmodule ExOvh.Mixfile do
       {:og, "~> 0.1"},
       # {:openstex, github: "stephenmoloney/openstex", branch: "master"}, # incorporates :poison and httpoison
       {:openstex, path: "../openstex"},
-
-      {:earmark, "~> 0.2.1", only: :dev},
+      {:markdown, github: "devinus/markdown"},
       {:ex_doc,  "~> 0.11", only: :dev}
     ]
   end