From 21bbcccc301c920b59694a088d4aab273b164e77 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 13 Feb 2026 10:12:43 -0600 Subject: [PATCH] fix preseem api base url and remove base_url override the default base url was pointing at the docs site (apidocs.preseem.com) instead of the actual api endpoint (api.preseem.com), causing all api calls to fail with unauthorized. removed the unnecessary base_url user override since the api endpoint is fixed. --- lib/towerops/preseem/client.ex | 20 +++++++------------ lib/towerops/preseem/sync.ex | 8 +------- .../live/org/integrations_live.ex | 8 +------- .../live/org/integrations_live.html.heex | 8 -------- test/towerops/preseem/sync_test.exs | 16 --------------- 5 files changed, 9 insertions(+), 51 deletions(-) diff --git a/lib/towerops/preseem/client.ex b/lib/towerops/preseem/client.ex index d9bcce2f..ae8200b6 100644 --- a/lib/towerops/preseem/client.ex +++ b/lib/towerops/preseem/client.ex @@ -7,17 +7,15 @@ defmodule Towerops.Preseem.Client do require Logger - @default_base_url "https://apidocs.preseem.com/model/v1" + @base_url "https://api.preseem.com/model/v1" @doc """ Tests the connection to the Preseem API by fetching account info. Returns `{:ok, body}` on success, `{:error, reason}` on failure. """ - def test_connection(api_key, opts \\ []) do - base_url = Keyword.get(opts, :base_url, @default_base_url) - - case request(:get, "#{base_url}/account", api_key) do + def test_connection(api_key) do + case request(:get, "#{@base_url}/account", api_key) do {:ok, %{status: status, body: body}} when status in 200..299 -> {:ok, body} @@ -42,10 +40,8 @@ defmodule Towerops.Preseem.Client do Returns `{:ok, [access_point]}` on success. """ - def list_access_points(api_key, opts \\ []) do - base_url = Keyword.get(opts, :base_url, @default_base_url) - - case request(:get, "#{base_url}/access_points", api_key) do + def list_access_points(api_key) do + case request(:get, "#{@base_url}/access_points", api_key) do {:ok, %{status: status, body: %{"data" => data}}} when status in 200..299 -> {:ok, data} @@ -68,10 +64,8 @@ defmodule Towerops.Preseem.Client do Returns `{:ok, metrics_map}` on success. """ - def get_access_point_metrics(api_key, ap_id, opts \\ []) do - base_url = Keyword.get(opts, :base_url, @default_base_url) - - case request(:get, "#{base_url}/access_points/#{ap_id}/metrics", api_key) do + def get_access_point_metrics(api_key, ap_id) do + case request(:get, "#{@base_url}/access_points/#{ap_id}/metrics", api_key) do {:ok, %{status: status, body: %{"data" => data}}} when status in 200..299 -> {:ok, data} diff --git a/lib/towerops/preseem/sync.ex b/lib/towerops/preseem/sync.ex index ffcdb138..cab2eacc 100644 --- a/lib/towerops/preseem/sync.ex +++ b/lib/towerops/preseem/sync.ex @@ -29,13 +29,7 @@ defmodule Towerops.Preseem.Sync do api_key = integration.credentials["api_key"] org_id = integration.organization_id - opts = - case integration.credentials["base_url"] do - nil -> [] - base_url -> [base_url: base_url] - end - - case Client.list_access_points(api_key, opts) do + case Client.list_access_points(api_key) do {:ok, ap_list} -> handle_successful_sync(integration, org_id, ap_list, start_time) diff --git a/lib/towerops_web/live/org/integrations_live.ex b/lib/towerops_web/live/org/integrations_live.ex index 1379db44..286abf80 100644 --- a/lib/towerops_web/live/org/integrations_live.ex +++ b/lib/towerops_web/live/org/integrations_live.ex @@ -159,14 +159,8 @@ defmodule ToweropsWeb.Org.IntegrationsLive do defp normalize_params(params) do api_key = Map.get(params, "api_key", "") - base_url = Map.get(params, "base_url", "") - credentials = - then(%{"api_key" => api_key}, fn creds -> - if base_url == "", do: creds, else: Map.put(creds, "base_url", base_url) - end) - - %{credentials: credentials} + %{credentials: %{"api_key" => api_key}} end defp get_credential(nil, _key), do: "" diff --git a/lib/towerops_web/live/org/integrations_live.html.heex b/lib/towerops_web/live/org/integrations_live.html.heex index dd1e0f38..678330b9 100644 --- a/lib/towerops_web/live/org/integrations_live.html.heex +++ b/lib/towerops_web/live/org/integrations_live.html.heex @@ -150,14 +150,6 @@ value={get_credential(@integrations[provider.id], "api_key")} /> - <.input - field={@form[:base_url]} - type="text" - label="Base URL (optional)" - placeholder="https://apidocs.preseem.com/model/v1" - value={get_credential(@integrations[provider.id], "base_url")} - /> - <%= if @test_result do %>
Ecto.Changeset.change(%{ - credentials: %{"api_key" => "test-key", "base_url" => "https://custom.preseem.com/v1"} - }) - |> Repo.update!() - - Req.Test.stub(Client, fn conn -> - Req.Test.json(conn, %{"data" => []}) - end) - - assert {:ok, result} = Sync.sync_organization(Repo.reload!(integration)) - assert result.synced == 0 - end end end