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.
This commit is contained in:
parent
b3f8204047
commit
21bbcccc30
5 changed files with 9 additions and 51 deletions
|
|
@ -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}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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: ""
|
||||
|
|
|
|||
|
|
@ -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 %>
|
||||
<div class={[
|
||||
"rounded-md p-4",
|
||||
|
|
|
|||
|
|
@ -247,21 +247,5 @@ defmodule Towerops.Preseem.SyncTest do
|
|||
assert length(metrics) == 1
|
||||
assert hd(metrics).avg_latency == 15.0
|
||||
end
|
||||
|
||||
test "uses base_url from integration credentials", %{integration: integration} do
|
||||
# Update integration with a custom base_url
|
||||
integration
|
||||
|> 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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue