From 5964f9268297b34daf5fae9aed4753e7c478825f Mon Sep 17 00:00:00 2001 From: Connor Rigby Date: Fri, 14 Jun 2024 06:45:09 -0700 Subject: [PATCH] Cleanup unused code, add whenwhere docs Signed-off-by: Connor Rigby --- lib/vintage_net/connectivity/when_where.ex | 23 ++++++++++++------- mix.exs | 7 ++---- .../connectivity/when_where_test.exs | 16 ------------- 3 files changed, 17 insertions(+), 29 deletions(-) diff --git a/lib/vintage_net/connectivity/when_where.ex b/lib/vintage_net/connectivity/when_where.ex index 72a8ece1..bf8173d4 100644 --- a/lib/vintage_net/connectivity/when_where.ex +++ b/lib/vintage_net/connectivity/when_where.ex @@ -6,18 +6,28 @@ defmodule VintageNet.Connectivity.WhenWhere do This connectivity checker requires the following options: - * `:url` - Required. HTTP URL for an Internet-reachable host + * `:url` - Required. HTTP URL for an Internet-reachable whenwhere server * `:max_response_size` - Optional max response size in bytes. Defaults to 1024 bytes. * `:timeout_millis` - Optional time to wait for a response in milliseconds. Defaults to 5000 ms. + + Upon success, this check will place the following properties in the property table: + + * `["interface", ifname, "connection", "now"]` - ISO8601 DateTime. + * `["interface", ifname, "connection", "time_zone"]` - Detected Timezone. + * `["interface", ifname, "connection", "latitude"]` - Geolocation latitude. + * `["interface", ifname, "connection", "longitude"]` - Geolocation longitude. + * `["interface", ifname, "connection", "country"]` - Geolocation country code. + * `["interface", ifname, "connection", "country_region"]` - Geolocation country_region code. + * `["interface", ifname, "connection", "city"]` - Geolocation city name. + * `["interface", ifname, "connection", "address"]` - Public IP Address used to access the server. """ @behaviour VintageNet.Connectivity.Check import VintageNet.Connectivity.WebRequest, only: [validate_url: 1] alias VintageNet.Connectivity.HTTPClient - require Logger - @default_max_response_size 1024 + @max_response_size 1024 @default_timeout_millis 5_000 @impl VintageNet.Connectivity.Check @@ -27,9 +37,7 @@ defmodule VintageNet.Connectivity.WhenWhere do :ok <- validate_url(url) do {:ok, {__MODULE__, - url: url, - max_response_size: Keyword.get(options, :max_response_size, @default_max_response_size), - timeout_millis: Keyword.get(options, :timeout_millis, @default_timeout_millis)}} + url: url, timeout_millis: Keyword.get(options, :timeout_millis, @default_timeout_millis)}} else _ -> :error end @@ -67,9 +75,8 @@ defmodule VintageNet.Connectivity.WhenWhere do request_headers = [{"Content-Type", "application/x-erlang-binary"}] request = HTTPClient.create_request(url, ifname, request_headers) - case HTTPClient.make_request(request, options[:max_response_size], options[:timeout_millis]) do + case HTTPClient.make_request(request, @max_response_size, options[:timeout_millis]) do {:ok, {{_version, 200, _status_message}, headers, body}} -> - Logger.debug(%{term: inspect(body)}) {:ok, headers, :erlang.binary_to_term(body, [:safe])} error -> diff --git a/mix.exs b/mix.exs index 6c0be431..84f15f61 100644 --- a/mix.exs +++ b/mix.exs @@ -8,7 +8,7 @@ defmodule VintageNet.MixProject do [ app: :vintage_net, version: @version, - elixir: "~> 1.13", + elixir: "~> 1.11", elixirc_paths: elixirc_paths(Mix.env()), start_permanent: Mix.env() == :prod, compilers: [:elixir_make | Mix.compilers()], @@ -61,9 +61,6 @@ defmodule VintageNet.MixProject do url: "http://www.msftconnecttest.com/connecttest.txt", match: "Microsoft Connect Test"}, {:whenwhere, url: "https://whenwhere.nerves-project.org"} ], - internet_hostname_list: [ - {"google.com", 443} - ], regulatory_domain: "00", # Contain processes in cgroups by setting to: # [cgroup_base: "vintage_net", cgroup_controllers: ["cpu"]] @@ -71,7 +68,7 @@ defmodule VintageNet.MixProject do power_managers: [], route_metric_fun: &VintageNet.Route.DefaultMetric.compute_metric/2 ], - extra_applications: [:logger, :crypto, :ssl, :public_key, :inets], + extra_applications: [:logger, :crypto], mod: {VintageNet.Application, []} ] end diff --git a/test/vintage_net/connectivity/when_where_test.exs b/test/vintage_net/connectivity/when_where_test.exs index df49da78..174b541f 100644 --- a/test/vintage_net/connectivity/when_where_test.exs +++ b/test/vintage_net/connectivity/when_where_test.exs @@ -33,20 +33,4 @@ defmodule VintageNet.Connectivity.WhenWhereTest do end) end end - - test "when/where no cname" do - ifname = Utils.get_ifname_for_tests() - - {:ok, normalized_whenwhere} = - WhenWhere.normalize({WhenWhere, url: "http://dnlawqcegshx3.cloudfront.net"}) - - assert {:ok, {:internet, properties}} = WhenWhere.check(ifname, normalized_whenwhere) - - for property <- @properties do - assert Enum.find(properties, fn - {^property, _} -> true - _ -> false - end) - end - end end