From 86d3808e544c7d9035a93573843c4b5f4605c023 Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Wed, 29 May 2024 16:25:27 -0400 Subject: [PATCH] Update server list dynamically --- lib/chronoscope/nts.ex | 2 ++ lib/chronoscope_web/live/index_live.ex | 4 +-- lib/chronoscope_web/live/index_live.html.heex | 27 +++++++++++++++---- test/chronoscope/gemini_test.exs | 1 - .../controllers/page_controller_test.exs | 11 +++++++- 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/lib/chronoscope/nts.ex b/lib/chronoscope/nts.ex index 5866dde..09193a7 100644 --- a/lib/chronoscope/nts.ex +++ b/lib/chronoscope/nts.ex @@ -12,6 +12,7 @@ defmodule Chronoscope.NTS do @registry Application.compile_env(:chronoscope, :registry, Registry) @genserver Application.compile_env(:chronoscope, :gen_server, GenServer) @dynamic_supervisor Application.compile_env(:chronoscope, :dynamic_supervisor, DynamicSupervisor) + @topic "nts-servers" def healthy?() do true @@ -37,6 +38,7 @@ defmodule Chronoscope.NTS do %{host: host, port: port} |> client_pid() |> @genserver.call(:key_establishment) + |> tap(fn _ -> ChronoscopeWeb.Endpoint.broadcast(@topic, "", "") end) end defp client_pid(server) do diff --git a/lib/chronoscope_web/live/index_live.ex b/lib/chronoscope_web/live/index_live.ex index de8ec66..995671d 100644 --- a/lib/chronoscope_web/live/index_live.ex +++ b/lib/chronoscope_web/live/index_live.ex @@ -10,7 +10,7 @@ defmodule ChronoscopeWeb.IndexLive do {:ok, assign(socket, %{servers: NTS.list()})} end - def handle_info(%{topic: @topic, payload: servers}, socket) do - {:noreply, assign(socket, %{servers: servers})} + def handle_info(%{topic: @topic}, socket) do + {:noreply, assign(socket, %{servers: NTS.list()})} end end diff --git a/lib/chronoscope_web/live/index_live.html.heex b/lib/chronoscope_web/live/index_live.html.heex index cc7b4c5..b4f3152 100644 --- a/lib/chronoscope_web/live/index_live.html.heex +++ b/lib/chronoscope_web/live/index_live.html.heex @@ -1,21 +1,27 @@ - - - - - + + @@ -38,6 +44,12 @@ + + <% else %> + + + <% end %> diff --git a/test/chronoscope/gemini_test.exs b/test/chronoscope/gemini_test.exs index 9cb0a79..af0ac15 100644 --- a/test/chronoscope/gemini_test.exs +++ b/test/chronoscope/gemini_test.exs @@ -8,7 +8,6 @@ defmodule Chronoscope.GeminiTest do import Mox - setup :verify_on_exit! describe "Chronoscope.Gemini.healthy?()" do test "is healthy" do diff --git a/test/chronoscope_web/controllers/page_controller_test.exs b/test/chronoscope_web/controllers/page_controller_test.exs index e11c7c9..6b920f1 100644 --- a/test/chronoscope_web/controllers/page_controller_test.exs +++ b/test/chronoscope_web/controllers/page_controller_test.exs @@ -1,8 +1,17 @@ defmodule ChronoscopeWeb.PageControllerTest do use ChronoscopeWeb.ConnCase, async: true + alias Chronoscope.DynamicSupervisorMock + + import Mox + + setup :verify_on_exit! + test "GET /", %{conn: conn} do + DynamicSupervisorMock + |> expect(:which_children, fn _ -> [] end) + conn = get(conn, ~p"/") - assert html_response(conn, 200) =~ "Peace of mind from prototype to production" + assert html_response(conn, 200) =~ "Chronoscope" end end
+ Host + Status + Algorithm + Cookies + Cookie Length + Certificate Expiration + + Last Check +
<%= response.cookie_length %> + <%= response.cert_expiration %> + + <%= server.last_key_establishment %> + @@ -54,6 +66,11 @@ - - - - + <%= server.last_key_establishment %> +