Commit 7d71e9fd3cb1dc4f5dd613cdd91e6363d89b0d1a

Stephen Moloney 2016-02-12T00:27:50

partial start on ovh cdn webstorage...

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
diff --git a/README.md b/README.md
index cda929d..a251c24 100644
--- a/README.md
+++ b/README.md
@@ -7,6 +7,11 @@ and the [Hubic](https://api.hubic.com/) api.
 
 This is an unofficial client to the OVH api and is not maintained by OVH.
 
+
+## Note
+
+This repository is a work in progress.
+
 ## <<TODO>> Add Proper Readme
 
 
diff --git a/lib/hubic/openstack_api/cache.ex b/lib/hubic/openstack_api/cache.ex
index e2863f1..b8501d3 100644
--- a/lib/hubic/openstack_api/cache.ex
+++ b/lib/hubic/openstack_api/cache.ex
@@ -8,7 +8,7 @@ defmodule ExOvh.Hubic.OpenstackApi.Cache do
   alias ExOvh.Hubic.Request
   @get_credentials_retries 10
   @get_credentials_sleep_interval 150
-  @init_delay 6_000
+  @init_delay 3_000
 
 
   #####################
diff --git a/lib/ovh/openstack_api/auth.ex b/lib/ovh/openstack_api/auth.ex
deleted file mode 100644
index 3de6358..0000000
--- a/lib/ovh/openstack_api/auth.ex
+++ /dev/null
@@ -1,80 +0,0 @@
-defmodule ExOvh.Ovh.Openstack.Auth do
-  alias LoggingUtils
-  alias ExOvh.Ovh.Defaults
-  alias ExOvh.Ovh.OvhApi.Cache
-
-  @default_headers %{ "Content-Type": "application/json; charset=utf-8" }
-  @methods [:get, :post, :put, :delete]
-  @timeout 10_000
-
-
-  ############################
-  # Public
-  ############################
-
-
-  @spec prepare_request(query :: ExOvh.Client.raw_query_t)
-                     :: ExOvh.Client.query_t
-  def prepare_request({method, uri, params} = query), do: prepare_request(ExOvh, query)
-
-  @spec prepare_request(client :: atom, query :: ExOvh.Client.raw_query_t)
-                     :: ExOvh.Client.query_t
-  def prepare_request(client, query)
-
-  def prepare_request(client, {method, uri, params} = query) when method in [:get, :delete] do
-    uri = uri(config, uri)
-    config = config(client)
-    if params !== :nil and params !== "", do: uri = uri <> "?" <> URI.encode_query(params)
-    consumer_key = get_consumer_key(config)
-    opts = [app_secret(config), app_key(config), consumer_key, Atom.to_string(method), uri, ""]
-    options = %{ headers: headers(opts, client), timeout: @timeout }
-    {method, uri, options}
-  end
-
-  def prepare_request(client, {method, uri, params} = query) when method in [:post, :put] do
-    uri = uri(config, uri)
-    config = config(client)
-    consumer_key = get_consumer_key(config)
-    if params !== "" and params !== :nil and is_map(params), do: params = Poison.encode!(params)
-    opts = [app_secret(config), consumer_key, Atom.to_string(method), uri, params]
-    options = %{ body: params, headers: headers(opts, client), timeout: @timeout }
-    {method, uri, options}
-  end
-
-
-
-  ############################
-  # Private
-  ############################
-
-
-  defp headers([app_secret, app_key, consumer_key, method, uri, body] = opts, client) do
-    time = :os.system_time(:seconds) + Cache.get_time_diff(client)
-    Map.merge(@default_headers,
-    %{
-    "X-Ovh-Application": app_key,
-    "X-Ovh-Consumer":    consumer_key,
-    "X-Ovh-Timestamp":   time,
-    "X-Ovh-Signature":   sign_request([app_secret, consumer_key, String.upcase(method), uri, body, time])
-    })
-  end
-
-
-  defp sign_request([app_secret, consumer_key, method, uri, body, time] = opts) do
-    pre_hash = Enum.join(opts, "+") |> LoggingUtils.log_return(:debug)
-    post_hash = :crypto.hash(:sha, pre_hash) |> Base.encode16(case: :lower)
-    "$1$" <> post_hash
-  end
-
-
-  defp config(), do: Cache.get_config(ExOvh)
-  defp config(client), do: Cache.get_config(client)
-  defp endpoint(config), do: Defaults.endpoints()[config[:endpoint]]
-  defp api_version(config), do: config[:api_version]
-  defp uri(config, uri), do: endpoint(config) <> api_version(config) <> uri
-  defp app_secret(config), do: config[:application_secret]
-  defp app_key(config), do: config[:application_key]
-  defp get_consumer_key(config), do: config[:consumer_key]
-
-
-end
diff --git a/lib/ovh/openstack_api/request.ex b/lib/ovh/openstack_api/request.ex
index 372165f..f27a84d 100644
--- a/lib/ovh/openstack_api/request.ex
+++ b/lib/ovh/openstack_api/request.ex
@@ -1,48 +1,20 @@
-defmodule ExOvh.Ovh.Openstack.Request do
-  alias ExOvh.Ovh.Openstack.Auth
-  alias ExOvh.Ovh.OvhApi.Cache, as: ClientCache
-  alias ExOvh.Ovh.Defaults
+defmodule ExOvh.Ovh.OpenstackApi.Request do
+  @moduledoc ~s"""
+  Delegate the request to the appropriate module depending on the query uri.
 
-  ############################
-  # Public
-  ############################
+    For example,
+                /cdn/webstorage ==> ExOvh.Ovh.Openstack.Webstorage.Request
+                /cdn/cloud ==> ExOvh.Ovh.Openstack.Cloud.Request
+  """
+  alias ExOvh.Ovh.Openstack.Webstorage.Request, as: WebStorage
 
 
-  @spec request(query :: ExOvh.Client.raw_query_t)
-               :: {:ok, map} | {:error, map}
-  def request({method, uri, params} = query), do: request(ExOvh, {method, uri, params} = query)
-
-
-  @spec request(client :: atom, query :: ExOvh.Client.query_t)
-               :: {:ok, ExOvh.Client.response_t} | {:error, ExOvh.Client.response_t}
+  @spec request(client :: atom, query :: ExOvh.Client.raw_query_t)
+                :: {:ok, ExOvh.Client.response_t} | {:error, ExOvh.Client.response_t}
   def request(client, {method, uri, params} = query) do
-    config = config(client)
-    {method, uri, options} = Auth.prepare_request(client, query)
-    resp = HTTPotion.request(method, uri, options)
-    resp =
-    %{
-      body: resp.body |> Poison.decode!(),
-      headers: resp.headers,
-      status_code: resp.status_code
-    }
-    if resp.status_code >= 100 and resp.status_code < 300 do
-     {:ok, resp}
-    else
-     {:error, resp}
-    end
+    # cond do --> check for various request types .. raise if none found.
+    WebStorage.request(client, query)
   end
 
 
-  ############################
-  # Private
-  ############################
-
-
-  defp config(), do: ClientCache.get_config(ExOvh)
-  defp config(client), do: ClientCache.get_config(client)
-  defp endpoint(config), do: Defaults.endpoints()[config[:endpoint]]
-  defp api_version(config), do: config[:api_version]
-
-
-end
-
+end
\ No newline at end of file
diff --git a/lib/ovh/openstack_api/webstorage/auth.ex b/lib/ovh/openstack_api/webstorage/auth.ex
new file mode 100644
index 0000000..bddd485
--- /dev/null
+++ b/lib/ovh/openstack_api/webstorage/auth.ex
@@ -0,0 +1,45 @@
+defmodule ExOvh.Ovh.Openstack.Webstorage.Auth do
+  alias ExOvh.Ovh.OvhApi.Cache, as: ClientCache
+  alias ExOvh.Ovh.Openstack.Webstorage.Cache, as: OpenCache
+  import ExOvh.Query.Ovh.Webstorage
+
+  @methods [:get, :post, :put, :delete]
+  @timeout 10_000
+
+
+  ############################
+  # Public
+  ############################
+
+
+  @spec prepare_request(client :: atom, query :: ExOvh.Client.raw_query_t)
+                     :: ExOvh.Client.query_t
+  def prepare_request(client, query)
+
+  def prepare_request(client, {method, uri, params} = query) when method in [:get, :delete] do
+    uri =  OpenCache.get_endpoint(client) <> uri
+    if params !== :nil and params !== "", do: uri = uri <> "?" <> URI.encode_query(params)
+    options = %{ headers: headers(client), timeout: @timeout }
+    {method, uri, options}
+  end
+
+  def prepare_request(client, {method, uri, params} = query) when method in [:post, :put] do
+    uri =  OpenCache.get_endpoint(client) <> uri
+    if params !== "" and params !== :nil and is_map(params), do: params = Poison.encode!(params)
+    options = %{ body: params, headers: headers(client), timeout: @timeout }
+    {method, uri, options}
+  end
+
+
+  ############################
+  # Private
+  ############################
+
+
+  defp headers(client), do: %{ "X-Auth-Token": Cache.get_credentials_token(client) }
+
+  defp config(), do: ClientCache.get_config(ExOvh)
+  defp config(client), do: ClientCache.get_config(client)
+
+
+end
diff --git a/lib/ovh/openstack_api/webstorage/cache.ex b/lib/ovh/openstack_api/webstorage/cache.ex
new file mode 100644
index 0000000..daa8846
--- /dev/null
+++ b/lib/ovh/openstack_api/webstorage/cache.ex
@@ -0,0 +1,217 @@
+defmodule ExOvh.Ovh.OpenstackApi.Webstorage.Cache do
+  @moduledoc """
+  Caches the openstack credentials for access to the openstack api associated with the webstorage cdn.
+
+  Uses the standard Openstack Identity (Keystone) api for auth.
+  """
+  use GenServer
+  alias ExOvh.Hubic.HubicApi.Cache
+  alias ExOvh.Hubic.Request
+  import ExOvh.Query.Ovh.Webstorage
+  @get_credentials_retries 10
+  @get_credentials_sleep_interval 150
+
+
+  #####################
+  # Public
+  #####################
+
+
+  @doc "Starts the genserver"
+  def start_link({client, config, opts}) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
+    GenServer.start_link(__MODULE__, {client, config, opts}, [name: gen_server_name(client)])
+  end
+
+
+  def get_credentials(), do: get_credentials(ExOvh)
+  def get_credentials(client), do: get_credentials(client, 0)
+
+
+  def get_credentials_token(), do: get_credentials_token(ExOvh)
+  def get_credentials_token(client), do: get_credentials(client)["token"]
+
+
+  def get_endpoint(), do: get_endpoint(ExOvh)
+  def get_endpoint(client) do
+    credentials = get_credentials(client)
+    path = URI.parse(credentials["endpoint"])
+    |> Map.get(:path)
+    {version, account} = String.split_at(path, 4)
+    endpoint = List.first(String.split(credentials["endpoint"], account))
+    endpoint
+  end
+
+
+  #####################
+  # Genserver Callbacks
+  #####################
+
+
+  # trap exits so that terminate callback is invoked
+  # the :lock key is to allow for locking during the brief moment that the access token is being refreshed
+  def init({client, config, opts}) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
+    :erlang.process_flag(:trap_exit, :true)
+    create_ets_table(client)
+
+    {:ok, resp} = Request.request(client, {:get, "/account/credentials", ""}, %{})
+    |> LoggingUtils.log_return(:debug)
+
+
+    credentials = Map.put(resp.body, :lock, :false)
+    :ets.insert(ets_tablename(client), {:credentials, credentials})
+    expires = to_seconds(credentials["expires"])
+    Task.start_link(fn -> monitor_expiry(client, expires) end)
+    {:ok, {client, config, credentials}}
+  end
+
+
+  def handle_call(:add_lock, _from, {client, config, credentials}) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
+    new_credentials = Map.put(credentials, :lock, :true)
+    :ets.insert(ets_tablename(client), {:credentials, new_credentials})
+    {:reply, :ok, {client, config, new_credentials}}
+  end
+  def handle_call(:remove_lock, _from, {client, config, credentials}) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
+    new_credentials = Map.put(credentials, :lock, :false)
+    :ets.insert(ets_tablename(client), {:credentials, new_credentials})
+    {:reply, :ok, {client, config, new_credentials}}
+  end
+  def handle_call(:update_credentials, _from, {client, config, credentials}) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
+    {:ok, resp} = Request.request(client, {:get, "/account/credentials", ""}, %{})
+    new_credentials = resp.body
+    |> Map.put(credentials, :lock, :false)
+    :ets.insert(ets_tablename(client), {:credentials, new_credentials})
+    {:reply, :ok, {client, config, new_credentials}}
+  end
+  def handle_call(:stop, _from, state) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
+    {:stop, :shutdown, :ok, state}
+  end
+  def terminate(:shutdown, {client, config, credentials}) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
+    :ets.delete(ets_tablename(client)) # explicilty remove
+    :ok
+  end
+
+
+
+  #####################
+  # Private
+  #####################
+
+  defp gen_server_name(client), do: String.to_atom(Atom.to_string(client) <> Atom.to_string(__MODULE__))
+  defp ets_tablename(client), do: String.to_atom("Ets" <> Atom.to_string(gen_server_name(client)))
+
+
+  #@spec identity(service_name :: String.t, username :: String.t, password :: String.t)
+  #               :: {:ok, map()} | {:error, map()}
+  defp identity(service_name, username, password) do
+    resp = ExOvh.ovh_request(get_webstorage_credentials(service_name), %{})
+    %{
+      "endpoint" => endpoint,
+      "login" => login,
+      "password" => password,
+      "tenant" => tenant
+    } = resp.body
+    params = %{"auth" => %{"passwordCredentials" => %{"username" => login, "password" => password}}}
+    options = %{
+                body: params |> Poison.encode!,
+                headers: %{ "Content-Type": "application/json; charset=utf-8" },
+                timeout: 10_000
+               }
+    resp = HTTPotion.request(:post, endpoint <> "/tokens", options)
+
+    if resp.status_code >= 200 and resp.status_code <= 203 do
+      %{
+         "access" => %{
+                      "metadata" => _metadata,
+                      "serviceCatalog" => _service_catalog,
+                      "token" => %{
+                                  "audit_ids" => _audit_ids,
+                                  "expires" => expires_on, # "2016-02-12T22:12:25Z",
+                                  "id" => token,
+                                  "issued_at" => created_on, # "2016-02-11T22:12:25.214186"
+                                  },
+                      "user" => _user
+                     }
+      }
+      = resp.body
+      {:ok, %{ "token" => token, "expires_on" => expires_on, "created_on" => created_on, "endpoint" => endpoint } }
+    else
+      {:error, resp.body}
+    end
+
+  end
+
+
+  defp get_credentials(client, index) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
+    if ets_tablename(client) in :ets.all() do
+      [credentials: credentials] = :ets.lookup(ets_tablename(client), :credentials)
+      if credentials.lock === :true do
+        if index > @get_credentials_retries do
+          raise "Problem retrieving the openstack credentials from ets table"
+        else
+          :timer.sleep(@get_credentials_sleep_interval)
+          get_credentials(client, index + 1)
+        end
+      else
+        credentials
+      end
+    else
+      if index > @get_credentials_retries do
+        raise "Problem retrieving the openstack credentials from ets table"
+      else
+        :timer.sleep(@get_credentials_sleep_interval)
+        get_credentials(client, index + 1)
+      end
+    end
+  end
+
+
+  defp monitor_expiry(client, expires) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
+    interval = (expires - 30) * 1000
+    :timer.sleep(interval)
+    {:reply, :ok, _credentials} = GenServer.call(gen_server_name(client), :add_lock)
+    {:reply, :ok, _credentials} = GenServer.call(gen_server_name(client), :update_credentials)
+    {:reply, :ok, credentials} = GenServer.call(gen_server_name(client), :remove_lock)
+    expires = to_seconds(credentials["expires"])
+    monitor_expiry(client, expires)
+  end
+
+
+  defp create_ets_table(client) do
+    LoggingUtils.log_mod_func_line(__ENV__, :debug)
+    ets_options = [
+                   :set, # type
+                   :protected, # read - all, write this process only.
+                   :named_table,
+                   {:heir, :none}, # don't let any process inherit the table. when the ets table dies, it dies.
+                   {:write_concurrency, :false},
+                   {:read_concurrency, :true}
+                  ]
+    unless ets_tablename(client) in :ets.all() do
+      :ets.new(ets_tablename(client), ets_options)
+    end
+  end
+
+
+  defp to_seconds(iso_time) do
+    {:ok, expiry_ndt, offset} = Calendar.NaiveDateTime.Parse.iso8601(iso_time)
+    {:ok, expiry_dt_utc} = Calendar.NaiveDateTime.with_offset_to_datetime_utc(expiry_ndt, offset)
+    {:ok, now} = Calendar.DateTime.from_erl(:calendar.universal_time(), "UTC")
+    {:ok, seconds, _microseconds, _when} = Calendar.DateTime.diff(expiry_dt_utc, now)
+    if seconds > 0 do
+      seconds
+    else
+      0
+    end
+  end
+
+
+end
\ No newline at end of file
diff --git a/lib/ovh/openstack_api/webstorage/request.ex b/lib/ovh/openstack_api/webstorage/request.ex
new file mode 100644
index 0000000..f26b437
--- /dev/null
+++ b/lib/ovh/openstack_api/webstorage/request.ex
@@ -0,0 +1,41 @@
+defmodule ExOvh.Ovh.Openstack.Webstorage.Request do
+  alias ExOvh.Ovh.Openstack.Webstorage.Auth
+  alias ExOvh.Ovh.OvhApi.Cache, as: ClientCache
+
+
+  ############################
+  # Public
+  ############################
+
+
+  @spec request(client :: atom, query :: ExOvh.Client.query_t)
+               :: {:ok, ExOvh.Client.response_t} | {:error, ExOvh.Client.response_t}
+  def request(client, {method, uri, params} = query) do
+    config = config(client)
+    {method, uri, options} = Auth.prepare_request(client, query)
+    resp = HTTPotion.request(method, uri, options)
+    resp =
+    %{
+      body: resp.body |> Poison.decode!(),
+      headers: resp.headers,
+      status_code: resp.status_code
+    }
+    if resp.status_code >= 100 and resp.status_code < 300 do
+     {:ok, resp}
+    else
+     {:error, resp}
+    end
+  end
+
+
+  ############################
+  # Private
+  ############################
+
+
+  defp config(), do: ClientCache.get_config(ExOvh)
+  defp config(client), do: ClientCache.get_config(client)
+
+
+end
+
diff --git a/lib/ovh/ovh_api/auth.ex b/lib/ovh/ovh_api/auth.ex
index b79d639..88da4b8 100644
--- a/lib/ovh/ovh_api/auth.ex
+++ b/lib/ovh/ovh_api/auth.ex
@@ -24,7 +24,8 @@ defmodule ExOvh.Ovh.OvhApi.Auth do
   def prepare_request(client, {method, uri, params} = query) when method in [:get, :delete] do
     uri = uri(config, uri)
     config = config(client)
-    if params !== :nil and params !== "", do: uri = uri <> "?" <> URI.encode_query(params)
+    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)
     consumer_key = get_consumer_key(config)
     opts = [app_secret(config), app_key(config), consumer_key, Atom.to_string(method), uri, ""]
     options = %{ headers: headers(opts, client), timeout: @timeout }
diff --git a/lib/ovh/ovh_api/request.ex b/lib/ovh/ovh_api/request.ex
index 3119d63..6e53a7b 100644
--- a/lib/ovh/ovh_api/request.ex
+++ b/lib/ovh/ovh_api/request.ex
@@ -17,9 +17,11 @@ defmodule ExOvh.Ovh.OvhApi.Request do
                :: {:ok, ExOvh.Client.response_t} | {:error, ExOvh.Client.response_t}
   def request(client, {method, uri, params} = query) do
     config = config(client)
+
     {method, uri, options} = Auth.prepare_request(client, query)
-    resp = HTTPotion.request(method, uri, options)
     |> LoggingUtils.log_return(:debug)
+
+    resp = HTTPotion.request(method, uri, options)
     if resp.status_code >= 100 and resp.status_code < 300 do
       {:ok, %{
              body: resp.body |> Poison.decode!(),
diff --git a/lib/query/ovh/webstorage/query.ex b/lib/query/ovh/webstorage/query.ex
new file mode 100644
index 0000000..f7fa779
--- /dev/null
+++ b/lib/query/ovh/webstorage/query.ex
@@ -0,0 +1,118 @@
+defmodule ExOvh.Query.Ovh.Webstorage do
+  @moduledoc ~s"""
+  Helps to build queries for the openstack swift api.
+  The raw query can be passed into a client request.
+
+    ## Example
+
+      ```elixir
+      import ExOvh.Query.Ovh.Webstorage
+      ```
+  """
+  alias ExOvh.Ovh.OvhApi.Cache, as: OvhApiCache
+
+
+
+  @doc ~s"""
+  GET /v1/​cdn/webstorage​, Get a list of all webstorage cdn services available for the client account
+
+  ### Example usage
+
+      ```elixir
+      import ExOvh.Query.Ovh.Webstorage
+      ExOvh.ovh_request(get_all_webstorage(), %{})
+      ```
+  """
+  @spec get_all_webstorage() :: ExOvh.Client.raw_query_t
+  def get_all_webstorage(), do: {:get, "/cdn/webstorage", :nil}
+
+
+
+  @doc ~s"""
+  GET /v1/​cdn/webstorage​/{serviceName}, Get the domain, server and storage limits for a specific webstorage cdn service
+
+  ### Example usage
+
+      ```elixir
+      import ExOvh.Query.Ovh.Webstorage
+      service_name = "cdnwebstorage-????"
+      resp = ExOvh.ovh_request(get_webstorage_service(service_name), %{})
+      %{
+        "domain" => domain,
+        "storageLimit => storage_limit,
+        "server" => server
+       } = resp.body
+      ```
+  """
+  @spec get_webstorage_service(service_name :: String.t)
+                               :: ExOvh.Client.raw_query_t
+  def get_webstorage_service(service_name), do: {:get, "/cdn/webstorage/", service_name}
+
+
+
+  @doc ~s"""
+  GET /v1/​cdn/webstorage​/{serviceName}/serviceInfos, Get a administrative details for a specific webstorage cdn service
+
+  ### Example usage
+
+      ```elixir
+      import ExOvh.Query.Ovh.Webstorage
+      service_name = "cdnwebstorage-????"
+      resp = ExOvh.ovh_request(get_webstorage_service_info(service_name), %{})
+      ```
+  """
+  @spec get_webstorage_service_info(service_name :: String.t)
+                               :: ExOvh.Client.raw_query_t
+  def get_webstorage_service_info(service_name), do: {:get, "/cdn/webstorage/#{service_name}/serviceInfos", :nil}
+
+
+
+  @doc ~s"""
+  GET /v1/​cdn/webstorage​/{serviceName}/statistics, Get statistics for a specific webstorage cdn service
+
+    `period can be "month", "week" or "day"`
+    `type can be "backend", "quota" or "cdn"`
+
+  ### Example usage
+
+      ```elixir
+      import ExOvh.Query.Ovh.Webstorage
+      # service_name = "cdnwebstorage-????"
+      resp = ExOvh.ovh_request(get_webstorage_service_stats(service_name, "month", "backend"), %{})
+      ```
+  """
+  @spec get_webstorage_service_stats(service_name :: String.t, period :: String.t, type :: String.t)
+                               :: ExOvh.Client.raw_query_t
+  def get_webstorage_service_stats(service_name, period \\ "month", type \\ "cdn") do
+    {:get, "/cdn/webstorage/#{service_name}/statistics", %{"period" => period, "type" => type} }
+  end
+
+
+
+  @doc ~s"""
+  GET /v1/​cdn/webstorage​/{serviceName}/credentials, Get credentials for using the swift compliant api
+
+  ### Example usage
+
+      ```elixir
+      import ExOvh.Query.Ovh.Webstorage
+      # service_name = "cdnwebstorage-????"
+      resp = ExOvh.ovh_request(get_webstorage_credentials(service_name), %{})
+      ```
+  """
+  @spec get_webstorage_credentials(service_name :: String.t)
+                               :: ExOvh.Client.raw_query_t
+  def get_webstorage_credentials(service_name), do: {:get, "/cdn/webstorage/#{service_name}/credentials", :nil}
+
+
+
+
+end
+
+
+
+
+
+
+
+