fix adapter issue
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
diff --git a/lib/mix/tasks/ovh.ex b/lib/mix/tasks/ovh.ex
index ec1a6a3..5cd4dbe 100644
--- a/lib/mix/tasks/ovh.ex
+++ b/lib/mix/tasks/ovh.ex
@@ -27,7 +27,7 @@ defmodule Mix.Tasks.Ovh do
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")
- ]
+ ]
See the [mix task documentation]((https://github.com/stephenmoloney/ex_ovh/blob/master/docs/mix_task.md).
"""
@@ -35,7 +35,7 @@ defmodule Mix.Tasks.Ovh do
alias ExOvh.Defaults
@default_headers [{"Content-Type", "application/json; charset=utf-8"}]
@default_adapter HTTPipe.Adapters.Hackney
- @default_hackney_options [ timeout: 30000, recv_timeout: (60000 * 1) ]
+ @default_hackney_options [timeout: 30000, recv_timeout: (60000 * 1)]
@default_name "ex_ovh"
@default_description "ex_ovh application"
@default_redirect_uri ""
@@ -112,9 +112,9 @@ defmodule Mix.Tasks.Ovh do
end
- defp parsers_login({opts, acc}), do: {opts, Map.merge(acc, %{login: Keyword.fetch!(opts, :login)}) }
- defp parsers_password({opts, acc}), do: {opts, Map.merge(acc, %{ password: Keyword.fetch!(opts, :password)}) }
- # defp parsers_app_name({opts, acc}), do: {opts, Map.merge(acc, %{ application_name: Keyword.fetch!(opts, :appname)}) }
+ defp parsers_login({opts, acc}), do: {opts, Map.merge(acc, %{login: Keyword.fetch!(opts, :login)})}
+ defp parsers_password({opts, acc}), do: {opts, Map.merge(acc, %{password: Keyword.fetch!(opts, :password)})}
+ # defp parsers_app_name({opts, acc}), do: {opts, Map.merge(acc, %{application_name: Keyword.fetch!(opts, :appname)})}
defp parsers_endpoint({opts, acc}) do
endpoint = Keyword.get(opts, :endpoint, :nil)
endpoint =
@@ -122,7 +122,7 @@ defmodule Mix.Tasks.Ovh do
:nil -> "ovh-eu"
_ -> endpoint
end
- {opts, Map.merge(acc, %{ endpoint: endpoint }) }
+ {opts, Map.merge(acc, %{endpoint: endpoint})}
end
defp parsers_api_version({opts, acc}) do
api_version = Keyword.get(opts, :apiversion, :nil)
@@ -131,33 +131,26 @@ defmodule Mix.Tasks.Ovh do
:nil -> "1.0"
_ -> api_version
end
- {opts, Map.merge(acc, %{ api_version: api_version }) }
+ {opts, Map.merge(acc, %{api_version: api_version})}
end
defp parsers_redirect_uri({opts, acc}) do
redirect_uri = Keyword.get(opts, :redirecturi, @default_redirect_uri)
- {opts, Map.merge(acc, %{ redirect_uri: redirect_uri }) }
+ {opts, Map.merge(acc, %{redirect_uri: redirect_uri})}
end
defp parsers_client_name({opts, acc}) do
client_name = Keyword.get(opts, :clientname, :nil)
- {opts, Map.merge(acc, %{ client_name: client_name }) }
+ {opts, Map.merge(acc, %{client_name: client_name})}
end
defp parsers_app_name({opts, acc}) do
application_name = Keyword.get(opts, :appname, @default_name)
- application_name =
- case application_name do
- :nil -> "ex_ovh"
- _ -> application_name
- end
- {opts, Map.merge(acc, %{ application_name: application_name }) }
+ application_name = application_name && application_name || @default_name
+ {opts, Map.merge(acc, %{application_name: application_name})}
end
defp parsers_app_desc({opts, acc}) do
application_description = Keyword.get(opts, :appdescription, :nil)
- application_description =
- case application_description do
- :nil -> Keyword.get(opts, :appname, @default_description)
- _ -> application_description
- end
- {opts, Map.merge(acc, %{ application_description: application_description }) }
+ application_description = application_description && application_description ||
+ Keyword.get(opts, :appname, @default_description)
+ {opts, Map.merge(acc, %{application_description: application_description})}
end
defp parsers_access_rules({opts, acc}) do
access_rules = Keyword.get(opts, :accessrules, :nil)
@@ -181,13 +174,13 @@ defmodule Mix.Tasks.Ovh do
%{
method: String.upcase(method),
path: path
- }
+ }
end)
List.insert_at(acc, -1, new_rules)
end)
|> List.flatten()
end
- {opts, Map.merge(acc, %{access_rules: access_rules}) }
+ {opts, Map.merge(acc, %{access_rules: access_rules})}
end
@@ -204,10 +197,10 @@ defmodule Mix.Tasks.Ovh do
url: url,
body: body,
headers: headers
- },
+ },
adapter: @default_adapter,
adapter_options: options
- }
+ }
{:ok, conn} = HTTPipe.Conn.execute(conn)
conn.response.body
@@ -261,10 +254,10 @@ defmodule Mix.Tasks.Ovh do
url: url,
body: body,
headers: headers
- },
+ },
adapter: @default_adapter,
adapter_options: options
- }
+ }
{:ok, conn} = HTTPipe.Conn.execute(conn)
body = conn.response.body
@@ -307,7 +300,7 @@ defmodule Mix.Tasks.Ovh do
defp get_consumer_key(%{access_rules: access_rules, redirect_uri: redirect_uri} = opts_map) do
method = :post
url = Defaults.endpoints()[opts_map[:endpoint]] <> opts_map[:api_version] <> Defaults.consumer_key_suffix()
- body = %{ accessRules: access_rules, redirection: redirect_uri } |> Poison.encode!()
+ body = %{accessRules: access_rules, redirection: redirect_uri} |> Poison.encode!()
headers = Map.merge(Enum.into(@default_headers, %{}), Enum.into([{"X-Ovh-Application", opts_map[:application_key]}], %{})) |> Enum.into([])
options = @default_hackney_options
@@ -317,10 +310,10 @@ defmodule Mix.Tasks.Ovh do
url: url,
body: body,
headers: headers
- },
+ },
adapter: @default_adapter,
adapter_options: options
- }
+ }
{:ok, conn} = HTTPipe.Conn.execute(conn)
body = Poison.decode!(conn.response.body)
@@ -341,10 +334,10 @@ defmodule Mix.Tasks.Ovh do
url: url,
body: body,
headers: headers
- },
+ },
adapter: @default_adapter,
adapter_options: options
- }
+ }
{:ok, conn} = HTTPipe.Conn.execute(conn)
conn.response.body
@@ -412,10 +405,10 @@ defmodule Mix.Tasks.Ovh do
url: url,
body: body,
headers: headers
- },
+ },
adapter: @default_adapter,
adapter_options: options
- }
+ }
{:ok, conn} = HTTPipe.Conn.execute(conn)
case check_for_successful_binding(conn.response, validation_url, ck) do
@@ -493,10 +486,10 @@ defmodule Mix.Tasks.Ovh do
url: url,
body: body,
headers: headers
- },
+ },
adapter: @default_adapter,
adapter_options: options
- }
+ }
{:ok, conn} = HTTPipe.Conn.execute(conn)
error_msg = "function check_for_successful_binding seems to be entering an error loop"
@@ -515,9 +508,9 @@ defmodule Mix.Tasks.Ovh do
application_secret: get_application_secret(create_app_body),
application_name: get_application_name(create_app_body),
application_description: get_application_description(create_app_body)
- })
+ })
ck = get_consumer_key(opts_map) |> bind_consumer_key_to_app(opts_map)
- Map.merge(opts_map, %{ consumer_key: ck })
+ Map.merge(opts_map, %{consumer_key: ck})
|> Map.delete(:login) |> Map.delete(:password)
end
@@ -537,17 +530,13 @@ defmodule Mix.Tasks.Ovh do
{
":" <> app_name,
"EX_OVH_"
- }
+ }
other ->
- client_name =
- case client_name do
- :nil -> "OvhClient"
- client_name -> client_name
- end
+ client_name = client_name && client_name || "OvhClient"
{
":" <> app_name <> ", " <> Macro.camelize(app_name) <> "." <> client_name,
String.upcase(other) <> "_" <> String.upcase(Macro.underscore(client_name)) <>"_"
- }
+ }
end
{config_header, mod_client_name}
end
@@ -594,7 +583,7 @@ defmodule Mix.Tasks.Ovh do
consumer_key: System.get_env(\"#{mod_client_name <> "CONSUMER_KEY"}\"),
endpoint: \"#{options.endpoint}\",
api_version: \"#{options.api_version}\"
- ]
+ ]
"""
end
diff --git a/mix.lock b/mix.lock
index 2bf2e2f..dff676a 100644
--- a/mix.lock
+++ b/mix.lock
@@ -1,8 +1,8 @@
%{"calendar": {:hex, :calendar, "0.17.2", "d6b7bccc29c72203b076d4e488d967780bf2d123a96fafdbf45746fdc2fa342c", [:mix], [{:tzdata, "~> 0.5.8 or ~> 0.1.201603", [hex: :tzdata, optional: false]}]},
"certifi": {:hex, :certifi, "1.0.0", "1c787a85b1855ba354f0b8920392c19aa1d06b0ee1362f9141279620a5be2039", [:rebar3], []},
"earmark": {:hex, :earmark, "1.2.0", "bf1ce17aea43ab62f6943b97bd6e3dc032ce45d4f787504e3adf738e54b42f3a", [:mix], []},
- "ex_doc": {:hex, :ex_doc, "0.15.0", "e73333785eef3488cf9144a6e847d3d647e67d02bd6fdac500687854dd5c599f", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]},
- "floki": {:hex, :floki, "0.15.0", "c5b7ac5d585c93da4cec61fc9bac7b8c2655883a085d740871057aa30a0f1258", [:mix], [{:mochiweb, "~> 2.15", [hex: :mochiweb, optional: false]}]},
+ "ex_doc": {:hex, :ex_doc, "0.15.1", "d5f9d588fd802152516fccfdb96d6073753f77314fcfee892b15b6724ca0d596", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]},
+ "floki": {:hex, :floki, "0.17.0", "ee23700dac178f601ae8cd05f8d8890a3dfd131fba8972dd3676bcedcb14a18d", [:mix], [{:mochiweb, "~> 2.15", [hex: :mochiweb, optional: false]}]},
"hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, optional: false]}, {:idna, "4.0.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]},
"hoedown": {:git, "https://github.com/hoedown/hoedown.git", "980b9c549b4348d50b683ecee6abee470b98acda", []},
"httpipe": {:hex, :httpipe, "0.9.0", "4db66493b0ec2a86d142ea959a62e221d6ddb23ab48a676b691be3a16c38a415", [:mix], []},
@@ -14,4 +14,4 @@
"mochiweb": {:hex, :mochiweb, "2.15.0", "e1daac474df07651e5d17cc1e642c4069c7850dc4508d3db7263a0651330aacc", [:rebar3], []},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], []},
- "tzdata": {:hex, :tzdata, "0.5.11", "3d5469a9f46bdf4a8760333dbdabdcc4751325035c454b10521f71e7c611ae50", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, optional: false]}]}}
+ "tzdata": {:hex, :tzdata, "0.5.12", "1c17b68692c6ba5b6ab15db3d64cc8baa0f182043d5ae9d4b6d35d70af76f67b", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, optional: false]}]}}