add docs for mix tasks
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
diff --git a/lib/mix/tasks/hubic.ex b/lib/mix/tasks/hubic.ex
index 8755faa..e9f1b28 100644
--- a/lib/mix/tasks/hubic.ex
+++ b/lib/mix/tasks/hubic.ex
@@ -1,8 +1,53 @@
defmodule Mix.Tasks.Hubic do
@moduledoc ~S"""
- Gets the access and refresh token for access the hubic api
- and returns them as a map to assist setting up the
- configuration file `secret.prod.exs`
+ Generates the hubic application refresh token on the user's behalf.
+
+ ## Steps
+
+ - The user needs to go to https://hubic.com/ and set up an account and retrieve a username and password.
+ - Then the user is prompted to do some activations.
+ - Upon completion of activations, the user needs to create an application in the hubic website.
+ - With the username, password, client_id, client_secret and redirect url from the recently created application,
+ a mixtask can be run which will apply the scope of the user and get the refresh_token on the user's behalf.
+
+ The mix task can be run as follows in a linux terminal:
+
+ ```shell
+ mix hubic
+ --login=<login>
+ --password=<password>
+ --clientid=<client_id>
+ --clientsecret=<client_secret>
+ --redirecturi=<uri>
+ ```
+
+ - A map is printed to the shell as follows:
+
+ ```elixir
+ %{
+ client_id: "<client_id>",
+ client_secret: "<client_secret>",
+ refresh_token: "<refresh_token>",
+ redirect_uri: "<uri>"
+ }
+ ```
+
+ ## Shell Output
+
+ This map can then be manually added by the user to the `config/prod.secret.exs` file
+
+ ```
+ config :test_os, TestOs.ExOvh,
+ ovh: :nil
+ hubic: %{
+ client_id: "<client_id>",
+ client_secret: "<client_secret>",
+ refresh_token: "<refresh_token>",
+ redirect_uri: "<uri>"
+ }
+ ```
+
+ - Then the hubic configuration is complete. Start up the app and the hubic wrapper is ready.
"""
use Mix.Task
alias ExOvh.Hubic.Defaults
diff --git a/lib/mix/tasks/ovh.ex b/lib/mix/tasks/ovh.ex
index 05f68b0..f6d0e7a 100644
--- a/lib/mix/tasks/ovh.ex
+++ b/lib/mix/tasks/ovh.ex
@@ -1,11 +1,121 @@
defmodule Mix.Tasks.Ovh do
+ @moduledoc ~S"""
+ Generates the hubic application refresh token on the user's behalf.
+
+ ## Steps
+
+ - The user needs to set up an ovh account at https://www.ovh.co.uk/ and retrieve a username (nic-handle) and password.
+
+ - Then the user is prompted to do some activations.
+
+ - Upon completion of activations, the user needs to create an application in the ovh website.
+
+ - Then the user can create an application at `https://eu.api.ovh.com/createApp/` or
+ alternatively the user can use this mix task to generate the application:
+
+ ## Example
+
+ Create an app with access to all apis:
+
+
+ ```shell
+ mix ovh
+ --login=<username>
+ --password=<password>
+ ```
+
+ Uses defaults:
+ ```
+ app name - ex_ovh,
+ app description - ex_ovh,
+ redirect_uri - "",
+ api_version - "1.0",
+ endpoint - "ovh-eu"
+ ```
+
+
+ ## Example
+
+ Create an app with access to all apis with specific app name and description:
+
+
+ ```shell
+ mix ovh
+ --login=<username>
+ --password=<password>
+ --appname='My app'
+ --appdesc='my app for api'
+ ```
+
+ Uses defaults:
+ ```
+ redirect_uri - "",
+ api_version - "1.0",
+ endpoint - "ovh-eu"
+ ```
+
+ ## Example
+
+ Create an app with access to all apis with specific everything:
+
+
+ ```shell
+ mix ovh
+ --login=<username>
+ --password=<password>
+ --appname='My app'
+ --appdesc='my app for api'
+ --endpoint=ovh-eu
+ --apiversion=1.0
+ --redirect_uri='http://localhost:4000/',
+ --accessrules='get-[/*]::put-[/me,/cdn]::post-[/me,/cdn]::delete-[]'
+ ```
+
+
+ A note on access rules:
+
+ The default for access rules will give your ovh application access to *all* of the api calls.
+ More than likely this is not a good idea. To limit the number of api endpoints available, generate access
+ rules using the commandline arguments as seen in the example above.
+
+
+ ## Shell Output
+
+ A map is printed to the shell as follows:
+
+ ```elixir
+ %{
+ application_key: "<app_key>",
+ application_secret: "<app_secret>",
+ consumer_key: "<consumer_secret>",
+ endpoint: "ovh-eu",
+ api_version: "1.0"
+ }
+ ```
+
+ - This map can then be manually added by the user to the `config/prod.secret.exs` file
+
+ ```
+ config :test_os, TestOs.ExOvh,
+ ovh: %{
+ application_key: "<app_key>",
+ application_secret: "<app_secret>",
+ consumer_key: "<consumer_secret>",
+ endpoint: "ovh-eu",
+ api_version: "1.0"
+ },
+ hubic: :nil
+ ```
+
+ - Then the ovh configuration is complete. Start up the app and the ovh wrapper is ready.
+ """
use Mix.Task
alias ExOvh.Ovh.Defaults
alias ExOvh.Ovh.Auth
import ExOvh.Query.Ovh.Webstorage, only: [get_all_webstorage: 0]
@shortdoc "Create a new app and new credentials for accessing ovh api"
- @default_headers ["Content-Type": "application/json; charset=utf-8"]
+ @default_headers %{ "Content-Type": "application/json; charset=utf-8" }
@timeout 10_000
defp endpoint(config), do: Defaults.endpoints()[config[:endpoint]]
@@ -243,10 +353,14 @@ defmodule Mix.Tasks.Ovh do
defp get_consumer_key(%{access_rules: access_rules, redirect_uri: redirect_uri} = opts_map) do
LoggingUtils.log_mod_func_line(__ENV__, :debug)
body = %{ accessRules: access_rules, redirection: redirect_uri }
- query = {:post, consumer_key_uri(opts_map), body}
- {method, uri, options} = Auth.ovh_prepare_request(opts_map, query)
- options = Map.put(options, :headers, Map.merge(@default_headers, %{ "X-Ovh-Application": app_key(opts_map)}))
- body = HTTPotion.request(method, consumer_key_uri(opts_map), options) |> Map.get(:body) |> Poison.decode!()
+ # {method, uri, options} = Auth.ovh_prepare_request(ExOvh, query, %{})
+ options = %{ body: Poison.encode!(body), headers: Map.merge(@default_headers, %{ "X-Ovh-Application": app_key(opts_map) } ), timeout: @timeout }
+ |> LoggingUtils.log_return(:debug)
+
+ LoggingUtils.log_return(consumer_key_uri(opts_map), :debug)
+ LoggingUtils.log_return(options, :debug)
+
+ body = HTTPotion.request(:post, consumer_key_uri(opts_map), options) |> Map.get(:body) |> Poison.decode!()
{Map.get(body, "consumerKey"), Map.get(body, "validationUrl")}
end