From 6589586f985b466194a6553c50ab3f7419a13b7f Mon Sep 17 00:00:00 2001 From: Lindolfo 'Lorn' Rodrigues Date: Tue, 17 Mar 2020 19:30:34 -0300 Subject: Timeout option Now, you need to pass the timeout for the PowerDNS API in seconds We need to add the timeout to the GenServer.call function --- lib/powerdnsex.ex | 2 +- lib/powerdnsex/config.ex | 5 ++++- lib/powerdnsex/http_client.ex | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/powerdnsex.ex b/lib/powerdnsex.ex index 6568319..86628b7 100644 --- a/lib/powerdnsex.ex +++ b/lib/powerdnsex.ex @@ -98,5 +98,5 @@ defmodule PowerDNSex do # Private # ########### - defp call(params), do: GenServer.call(@name, params) + defp call(params), do: GenServer.call(@name, params, Config.powerdns_timeout) end diff --git a/lib/powerdnsex/config.ex b/lib/powerdnsex/config.ex index 34d5889..1302524 100644 --- a/lib/powerdnsex/config.ex +++ b/lib/powerdnsex/config.ex @@ -1,6 +1,7 @@ defmodule PowerDNSex.Config do defstruct url: "", - token: "" + token: "", + timeout: "60" alias PowerDNSex.Config @@ -20,6 +21,8 @@ defmodule PowerDNSex.Config do def powerdns_token, do: data().token + def powerdns_timeout, do: :timer.seconds(data().timeout) + def valid?(), do: powerdns_url() && powerdns_token() ### diff --git a/lib/powerdnsex/http_client.ex b/lib/powerdnsex/http_client.ex index 13e5023..3431795 100644 --- a/lib/powerdnsex/http_client.ex +++ b/lib/powerdnsex/http_client.ex @@ -13,4 +13,10 @@ defmodule PowerDNSex.HttpClient do custom = ["X-API-Key": Config.powerdns_token()] Keyword.merge(headers, custom) end + + def process_request_options(options) do + custom_options = [ssl: [{:versions, [:'tlsv1.1']}], recv_timeout: Config.powerdns_timeout()] + Keyword.merge(options, custom_options) + end + end -- cgit v1.2.3