Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions library/agent/getAPIURL.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
import { extractRegionFromToken } from "./extractRegionFromToken";
import { getDefaultZenAPIURL } from "./getDefaultZenAPIURL";

export function getAPIURL() {
if (process.env.AIKIDO_ENDPOINT) {
return new URL(process.env.AIKIDO_ENDPOINT);
}

const region = extractRegionFromToken(process.env.AIKIDO_TOKEN || "");

if (region === "US") {
return new URL("https://guard.us.aikido.dev");
}

if (region === "ME") {
return new URL("https://guard.me.aikido.dev");
}

if (region === "AU") {
return new URL("https://guard.au.aikido.dev");
}

return new URL("https://guard.aikido.dev");
return getDefaultZenAPIURL();
}
19 changes: 19 additions & 0 deletions library/agent/getDefaultZenAPIURL.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { extractRegionFromToken } from "./extractRegionFromToken";

export function getDefaultZenAPIURL() {
const region = extractRegionFromToken(process.env.AIKIDO_TOKEN || "");

if (region === "US") {
return new URL("https://guard.us.aikido.dev");
}

if (region === "ME") {
return new URL("https://guard.me.aikido.dev");
}

if (region === "AU") {
return new URL("https://guard.au.aikido.dev");
}

return new URL("https://guard.aikido.dev");
}
4 changes: 3 additions & 1 deletion library/agent/realtime/getRealtimeURL.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { getDefaultZenAPIURL } from "../getDefaultZenAPIURL";

export function getRealtimeURL() {
if (process.env.AIKIDO_REALTIME_ENDPOINT) {
return new URL(process.env.AIKIDO_REALTIME_ENDPOINT);
}

return new URL("https://runtime.aikido.dev");
return getDefaultZenAPIURL();
}
26 changes: 13 additions & 13 deletions library/agent/realtime/pollForChanges.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ t.test("it checks for config updates", async () => {
method: params.method,
});

if (params.url.hostname.startsWith("runtime")) {
if (params.url.pathname === "/config") {
return {
body: JSON.stringify({
configUpdatedAt: configUpdatedAt,
Expand All @@ -44,7 +44,7 @@ t.test("it checks for config updates", async () => {
};
}

if (params.url.hostname.startsWith("guard")) {
if (params.url.pathname === "/api/runtime/config") {
return {
body: JSON.stringify({
endpoints: [],
Expand All @@ -55,7 +55,7 @@ t.test("it checks for config updates", async () => {
};
}

throw new Error(`Unknown hostname: ${params.url.hostname}`);
throw new Error(`Unknown path: ${params.url.pathname}`);
};
});

Expand All @@ -78,7 +78,7 @@ t.test("it checks for config updates", async () => {
t.same(configUpdates, []);
t.same(calls, [
{
url: "https://runtime.aikido.dev/config",
url: "https://guard.aikido.dev/config",
method: "GET",
},
]);
Expand All @@ -95,11 +95,11 @@ t.test("it checks for config updates", async () => {
]);
t.same(calls, [
{
url: "https://runtime.aikido.dev/config",
url: "https://guard.aikido.dev/config",
method: "GET",
},
{
url: "https://runtime.aikido.dev/config",
url: "https://guard.aikido.dev/config",
method: "GET",
},
{
Expand All @@ -119,19 +119,19 @@ t.test("it checks for config updates", async () => {
]);
t.same(calls, [
{
url: "https://runtime.aikido.dev/config",
url: "https://guard.aikido.dev/config",
method: "GET",
},
{
url: "https://runtime.aikido.dev/config",
url: "https://guard.aikido.dev/config",
method: "GET",
},
{
url: "https://guard.aikido.dev/api/runtime/config",
method: "GET",
},
{
url: "https://runtime.aikido.dev/config",
url: "https://guard.aikido.dev/config",
method: "GET",
},
]);
Expand All @@ -153,23 +153,23 @@ t.test("it checks for config updates", async () => {
]);
t.same(calls, [
{
url: "https://runtime.aikido.dev/config",
url: "https://guard.aikido.dev/config",
method: "GET",
},
{
url: "https://runtime.aikido.dev/config",
url: "https://guard.aikido.dev/config",
method: "GET",
},
{
url: "https://guard.aikido.dev/api/runtime/config",
method: "GET",
},
{
url: "https://runtime.aikido.dev/config",
url: "https://guard.aikido.dev/config",
method: "GET",
},
{
url: "https://runtime.aikido.dev/config",
url: "https://guard.aikido.dev/config",
method: "GET",
},
{
Expand Down
Loading