Inspect for n8n and Home Assistant
Both read through the shared HTTP helper but were missing from the web list of inspectable kinds, so no Inspect button showed. Home Assistant's reader was named listEntities, which the inspect route doesn't recognise; it now also answers to read. Test and INTEGRATIONS.md updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8ffae62281
commit
386d77b351
4 files changed
+36
-4
No files matched your search
+1
-1
@@ -34,7 +34,7 @@ The numbers an integration reports — queries a day and how many were blocked (
|
|||||||
|
|
||||||
### Checking what an integration can read
|
### Checking what an integration can read
|
||||||
|
|
||||||
On the Integrations page an administrator has an **Inspect** button on each integration that reads through the shared HTTP helper (Authentik, Immich, Jellyfin, NetBox, Nextcloud, Paperless-ngx, Prometheus, Hetzner Cloud, Hetzner Robot, Speedtest Tracker, Fragnet, Sonarr, Radarr, Prowlarr, Lidarr, Readarr, qBittorrent, SABnzbd, AdGuard Home, Technitium DNS and Grafana). It runs the integration's reader once and shows:
|
On the Integrations page an administrator has an **Inspect** button on each integration that reads through the shared HTTP helper (Authentik, Immich, Jellyfin, NetBox, Nextcloud, Paperless-ngx, Prometheus, Hetzner Cloud, Hetzner Robot, Speedtest Tracker, Fragnet, Sonarr, Radarr, Prowlarr, Lidarr, Readarr, qBittorrent, SABnzbd, AdGuard Home, Technitium DNS, Grafana, n8n and Home Assistant). It runs the integration's reader once and shows:
|
||||||
|
|
||||||
- **what was asked** — each request, its path (with the *names* of the query parameters, not their values), the status, how long it took and how many bytes;
|
- **what was asked** — each request, its path (with the *names* of the query parameters, not their values), the status, how long it took and how many bytes;
|
||||||
- **what came back** — the *shape* of each JSON answer to three levels: the names of the fields and the kind of each (`string`, `number`, `array(12) of { … }`), with a `?` on a field that only some items of a list have. Never a value, never a token, so the report can be copied into a message;
|
- **what came back** — the *shape* of each JSON answer to three levels: the names of the fields and the kind of each (`string`, `number`, `array(12) of { … }`), with a `?` on a field that only some items of a list have. Never a value, never a token, so the report can be copied into a message;
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ export interface HaEntity {
|
|||||||
export interface HomeAssistantAdapter {
|
export interface HomeAssistantAdapter {
|
||||||
ping(): Promise<{ ok: boolean; latencyMs?: number; error?: string }>;
|
ping(): Promise<{ ok: boolean; latencyMs?: number; error?: string }>;
|
||||||
listEntities(): Promise<HaEntity[]>;
|
listEntities(): Promise<HaEntity[]>;
|
||||||
|
/** The same read under the name the inspector looks for. */
|
||||||
|
read(): Promise<HaEntity[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const obj = (v: unknown): Record<string, unknown> => (v !== null && typeof v === "object" && !Array.isArray(v) ? (v as Record<string, unknown>) : {});
|
const obj = (v: unknown): Record<string, unknown> => (v !== null && typeof v === "object" && !Array.isArray(v) ? (v as Record<string, unknown>) : {});
|
||||||
@@ -87,5 +89,5 @@ export function createHomeAssistantAdapter(config: HomeAssistantConfig): HomeAss
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return withDiagLogging("homeassistant", { ping, listEntities });
|
return withDiagLogging("homeassistant", { ping, listEntities, read: listEntities });
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
import { test, describe, before, after } from "node:test";
|
import { test, describe, before, after } from "node:test";
|
||||||
import assert from "node:assert/strict";
|
import assert from "node:assert/strict";
|
||||||
import { createServer as createHttpServer, type Server } from "node:http";
|
import { createServer as createHttpServer, type Server } from "node:http";
|
||||||
import { mkdtempSync, rmSync } from "node:fs";
|
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import type { AddressInfo } from "node:net";
|
import type { AddressInfo } from "node:net";
|
||||||
@@ -201,4 +201,34 @@ describe("the route", () => {
|
|||||||
assert.equal(entries.length, 2, "the two that ran");
|
assert.equal(entries.length, 2, "the two that ran");
|
||||||
assert.deepEqual(entries.map((e) => [e.category, e.targetType]), [["integration", "integration"], ["integration", "integration"]]);
|
assert.deepEqual(entries.map((e) => [e.category, e.targetType]), [["integration", "integration"], ["integration", "integration"]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("n8n and Home Assistant can be inspected too, and the web page offers the button for both", async () => {
|
||||||
|
const other = createHttpServer((req, res) => {
|
||||||
|
res.setHeader("content-type", "application/json");
|
||||||
|
const u = new URL(req.url ?? "", "http://x");
|
||||||
|
if (u.pathname === "/api/v1/workflows") return void res.end(JSON.stringify({ data: [{ id: "1", name: "Backup", active: true }], nextCursor: null }));
|
||||||
|
if (u.pathname === "/api/v1/executions") return void res.end(JSON.stringify({ data: [{ workflowId: "1", status: "success", stoppedAt: "2026-01-01T00:00:00Z" }] }));
|
||||||
|
if (u.pathname === "/api/states") return void res.end(JSON.stringify([{ entity_id: "sensor.t", state: "21.5", attributes: { friendly_name: "Temp", unit_of_measurement: "°C" }, last_changed: "2026-01-01T00:00:00Z" }]));
|
||||||
|
res.statusCode = 404;
|
||||||
|
res.end("{}");
|
||||||
|
});
|
||||||
|
await new Promise<void>((r) => other.listen(0, "127.0.0.1", r));
|
||||||
|
try {
|
||||||
|
const url = `http://127.0.0.1:${(other.address() as AddressInfo).port}`;
|
||||||
|
const n8nId = (await db.insert(integrations).values({ type: "n8n", name: "Flows", baseUrl: url, config: JSON.stringify({ url, apiKey: "n8n_secret" }) }).returning({ id: integrations.id }))[0].id;
|
||||||
|
const haId = (await db.insert(integrations).values({ type: "homeassistant", name: "Home", baseUrl: url, config: JSON.stringify({ url, token: "ha_secret" }) }).returning({ id: integrations.id }))[0].id;
|
||||||
|
for (const [id, path] of [[n8nId, "/api/v1/workflows"], [haId, "/api/states"]] as const) {
|
||||||
|
const text = await (await call("admin", id)).text();
|
||||||
|
assert.doesNotMatch(text, /n8n_secret|ha_secret/);
|
||||||
|
const body = JSON.parse(text) as { ok: boolean; calls: { path: string; status: number }[] };
|
||||||
|
assert.equal(body.ok, true, text);
|
||||||
|
assert.ok(body.calls.some((c) => c.path.startsWith(path) && c.status === 200), path);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
other.close();
|
||||||
|
}
|
||||||
|
const types = readFileSync(new URL("../../web/src/utils/integrationTypes.ts", import.meta.url), "utf8");
|
||||||
|
const list = types.match(/INSPECTABLE[^=]*=\s*\[([^\]]*)\]/)?.[1] ?? "";
|
||||||
|
for (const kind of ["n8n", "homeassistant"]) assert.ok(list.includes(`"${kind}"`), kind);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -91,7 +91,7 @@ export const TYPE_GROUPS: { id: string; label: string; types: IntegrationType[]
|
|||||||
];
|
];
|
||||||
|
|
||||||
/** The kinds whose reader can be inspected (Settings → Integrations → Check what can be read): the ones that read through the shared HTTP helper and have a reader to run. */
|
/** The kinds whose reader can be inspected (Settings → Integrations → Check what can be read): the ones that read through the shared HTTP helper and have a reader to run. */
|
||||||
export const INSPECTABLE: IntegrationType[] = ["authentik", "immich", "jellyfin", "netbox", "nextcloud", "paperless", "prometheus", "hetzner", "speedtest", "fragnet", "sonarr", "radarr", "prowlarr", "lidarr", "readarr", "qbittorrent", "sabnzbd", "hetznerrobot", "adguard", "technitium", "grafana"];
|
export const INSPECTABLE: IntegrationType[] = ["authentik", "immich", "jellyfin", "netbox", "nextcloud", "paperless", "prometheus", "hetzner", "speedtest", "fragnet", "sonarr", "radarr", "prowlarr", "lidarr", "readarr", "qbittorrent", "sabnzbd", "hetznerrobot", "adguard", "technitium", "grafana", "n8n", "homeassistant"];
|
||||||
|
|
||||||
/** The group a kind belongs to; a kind nobody has placed yet falls in "Other" rather than vanishing. */
|
/** The group a kind belongs to; a kind nobody has placed yet falls in "Other" rather than vanishing. */
|
||||||
export function groupOfType(type: IntegrationType): { id: string; label: string } {
|
export function groupOfType(type: IntegrationType): { id: string; label: string } {
|
||||||
|
|||||||
Reference in new issue
Block a user