refactor: let integrations own HTTP authentication
This commit is contained in:
1 parent
8157a43b9b
commit
db4b6bf4b5
46 files changed
+425
-447
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
import { ParseError } from "@homarr/common/server";
|
import { ParseError } from "@homarr/common/server";
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -10,6 +11,10 @@ import type { DnsHoleSummary } from "../interfaces/dns-hole-summary/dns-hole-sum
|
|||||||
import { filteringStatusSchema, statsResponseSchema, statusResponseSchema } from "./adguard-home-types";
|
import { filteringStatusSchema, statsResponseSchema, statusResponseSchema } from "./adguard-home-types";
|
||||||
|
|
||||||
export class AdGuardHomeIntegration extends Integration implements DnsHoleSummaryIntegration {
|
export class AdGuardHomeIntegration extends Integration implements DnsHoleSummaryIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return { headers: { Authorization: `Basic ${this.getAuthorizationHeaderValue()}` } };
|
||||||
|
}
|
||||||
|
|
||||||
public async getSummaryAsync(): Promise<DnsHoleSummary> {
|
public async getSummaryAsync(): Promise<DnsHoleSummary> {
|
||||||
const headers = {
|
const headers = {
|
||||||
Authorization: `Basic ${this.getAuthorizationHeaderValue()}`,
|
Authorization: `Basic ${this.getAuthorizationHeaderValue()}`,
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { ResponseError } from "@homarr/common/server";
|
|||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
|
import { bearerAuth } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -14,11 +16,13 @@ import type { AnchorNote, AnchorNotesListInput, AnchorNoteSummary, AnchorNoteUpd
|
|||||||
const logger = createLogger({ module: "anchorIntegration" });
|
const logger = createLogger({ module: "anchorIntegration" });
|
||||||
|
|
||||||
export class AnchorIntegration extends Integration {
|
export class AnchorIntegration extends Integration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return bearerAuth(this.integration);
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const response = await input.fetchAsync(this.url("/api/notes", { limit: 1 }), {
|
const response = await input.fetchAsync(this.url("/api/notes", { limit: 1 }), {
|
||||||
headers: {
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
Authorization: `Bearer ${this.getSecretValue("apiKey")}`,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) return TestConnectionError.StatusResult(response);
|
if (!response.ok) return TestConnectionError.StatusResult(response);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { z } from "zod/v4";
|
|||||||
|
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -36,6 +37,10 @@ interface WarriorSnapshotState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ArchiveTeamWarriorIntegration extends Integration {
|
export class ArchiveTeamWarriorIntegration extends Integration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return { headers: this.createAuthHeaders() };
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const response = await input.fetchAsync(this.url("/index.html"), {
|
const response = await input.fetchAsync(this.url("/index.html"), {
|
||||||
headers: this.createAuthHeaders(),
|
headers: this.createAuthHeaders(),
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ResponseError } from "@homarr/common/server";
|
import { ResponseError } from "@homarr/common/server";
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -26,6 +27,10 @@ const mediaTypeCountField = {
|
|||||||
>;
|
>;
|
||||||
|
|
||||||
export class AudiobookshelfIntegration extends Integration {
|
export class AudiobookshelfIntegration extends Integration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return { headers: this.getAuthHeaders(), redactValues: [] };
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const healthResponse = await input.fetchAsync(this.url("/healthcheck"));
|
const healthResponse = await input.fetchAsync(this.url("/healthcheck"));
|
||||||
|
|
||||||
|
|||||||
@@ -1,296 +1,120 @@
|
|||||||
|
import { isHttpIntegrationKind } from "@homarr/definitions";
|
||||||
import type { IntegrationKind } from "@homarr/definitions";
|
import type { IntegrationKind } from "@homarr/definitions";
|
||||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||||
import { ErrorWithMetadata } from "@homarr/core/infrastructure/logs/error";
|
import { ErrorWithMetadata } from "@homarr/core/infrastructure/logs/error";
|
||||||
|
|
||||||
import {
|
import { clientAuthentication } from "../http-auth";
|
||||||
withHttpAuthentication,
|
|
||||||
apiKeyAuth,
|
|
||||||
bearerAuth,
|
|
||||||
basicAuth,
|
|
||||||
headerAuth,
|
|
||||||
queryAuth,
|
|
||||||
noAuth,
|
|
||||||
optionalAuth,
|
|
||||||
alternativeAuth,
|
|
||||||
rpcAuth,
|
|
||||||
feedAuth,
|
|
||||||
secret,
|
|
||||||
clientAuthentication,
|
|
||||||
} from "../http-auth";
|
|
||||||
import type { IntegrationHttpAuthentication } from "../http-auth";
|
|
||||||
import type { Integration, IntegrationInput } from "./integration";
|
import type { Integration, IntegrationInput } from "./integration";
|
||||||
|
|
||||||
const logger = createLogger({ module: "integrationFactory" });
|
const logger = createLogger({ module: "integrationFactory" });
|
||||||
|
|
||||||
// Keep each import path explicit so Node and Turbopack can discover every lazy integration chunk.
|
// Keep each import path explicit so Node and Turbopack can discover every lazy integration chunk.
|
||||||
const integrationCreators = {
|
const integrationCreators = {
|
||||||
anchor: withHttpAuthentication(
|
anchor: async (input: IntegrationInput) =>
|
||||||
async (input: IntegrationInput) => new (await import("../anchor/anchor-integration")).AnchorIntegration(input),
|
new (await import("../anchor/anchor-integration")).AnchorIntegration(input),
|
||||||
bearerAuth,
|
piHole: async (input: IntegrationInput) =>
|
||||||
),
|
(await import("../pi-hole/pi-hole-integration-factory")).createPiHoleIntegrationAsync(input),
|
||||||
piHole: withHttpAuthentication(
|
adGuardHome: async (input: IntegrationInput) =>
|
||||||
async (input: IntegrationInput) =>
|
new (await import("../adguard-home/adguard-home-integration")).AdGuardHomeIntegration(input),
|
||||||
(await import("../pi-hole/pi-hole-integration-factory")).createPiHoleIntegrationAsync(input),
|
technitiumDns: async (input: IntegrationInput) =>
|
||||||
clientAuthentication,
|
(await import("../technitium/technitium-integration-factory")).createTechnitiumDnsIntegrationAsync(input),
|
||||||
),
|
homeAssistant: async (input: IntegrationInput) =>
|
||||||
adGuardHome: withHttpAuthentication(
|
new (await import("../homeassistant/homeassistant-integration")).HomeAssistantIntegration(input),
|
||||||
async (input: IntegrationInput) =>
|
jellyfin: async (input: IntegrationInput) =>
|
||||||
new (await import("../adguard-home/adguard-home-integration")).AdGuardHomeIntegration(input),
|
new (await import("../jellyfin/jellyfin-integration")).JellyfinIntegration(input),
|
||||||
basicAuth(),
|
plex: async (input: IntegrationInput) => new (await import("../plex/plex-integration")).PlexIntegration(input),
|
||||||
),
|
sonarr: async (input: IntegrationInput) =>
|
||||||
technitiumDns: withHttpAuthentication(
|
new (await import("../media-organizer/sonarr/sonarr-integration")).SonarrIntegration(input),
|
||||||
async (input: IntegrationInput) =>
|
radarr: async (input: IntegrationInput) =>
|
||||||
(await import("../technitium/technitium-integration-factory")).createTechnitiumDnsIntegrationAsync(input),
|
new (await import("../media-organizer/radarr/radarr-integration")).RadarrIntegration(input),
|
||||||
clientAuthentication,
|
sabNzbd: async (input: IntegrationInput) =>
|
||||||
),
|
new (await import("../download-client/sabnzbd/sabnzbd-integration")).SabnzbdIntegration(input),
|
||||||
homeAssistant: withHttpAuthentication(
|
nzbGet: async (input: IntegrationInput) =>
|
||||||
async (input: IntegrationInput) =>
|
new (await import("../download-client/nzbget/nzbget-integration")).NzbGetIntegration(input),
|
||||||
new (await import("../homeassistant/homeassistant-integration")).HomeAssistantIntegration(input),
|
qBittorrent: async (input: IntegrationInput) =>
|
||||||
bearerAuth,
|
new (await import("../download-client/qbittorrent/qbittorrent-integration")).QBitTorrentIntegration(input),
|
||||||
),
|
deluge: async (input: IntegrationInput) =>
|
||||||
jellyfin: withHttpAuthentication(
|
new (await import("../download-client/deluge/deluge-integration")).DelugeIntegration(input),
|
||||||
async (input: IntegrationInput) =>
|
transmission: async (input: IntegrationInput) =>
|
||||||
new (await import("../jellyfin/jellyfin-integration")).JellyfinIntegration(input),
|
new (await import("../download-client/transmission/transmission-integration")).TransmissionIntegration(input),
|
||||||
clientAuthentication,
|
slskd: async (input: IntegrationInput) =>
|
||||||
),
|
new (await import("../download-client/slskd/slskd-integration")).SlskdIntegration(input),
|
||||||
plex: withHttpAuthentication(
|
aria2: async (input: IntegrationInput) =>
|
||||||
async (input: IntegrationInput) => new (await import("../plex/plex-integration")).PlexIntegration(input),
|
new (await import("../download-client/aria2/aria2-integration")).Aria2Integration(input),
|
||||||
headerAuth("X-Plex-Token"),
|
jellyseerr: async (input: IntegrationInput) =>
|
||||||
),
|
new (await import("../jellyseerr/jellyseerr-integration")).JellyseerrIntegration(input),
|
||||||
sonarr: withHttpAuthentication(
|
seerr: async (input: IntegrationInput) => new (await import("../seerr/seerr-integration")).SeerrIntegration(input),
|
||||||
async (input: IntegrationInput) =>
|
overseerr: async (input: IntegrationInput) =>
|
||||||
new (await import("../media-organizer/sonarr/sonarr-integration")).SonarrIntegration(input),
|
new (await import("../overseerr/overseerr-integration")).OverseerrIntegration(input),
|
||||||
apiKeyAuth,
|
prowlarr: async (input: IntegrationInput) =>
|
||||||
),
|
new (await import("../prowlarr/prowlarr-integration")).ProwlarrIntegration(input),
|
||||||
radarr: withHttpAuthentication(
|
openmediavault: async (input: IntegrationInput) =>
|
||||||
async (input: IntegrationInput) =>
|
new (await import("../openmediavault/openmediavault-integration")).OpenMediaVaultIntegration(input),
|
||||||
new (await import("../media-organizer/radarr/radarr-integration")).RadarrIntegration(input),
|
lidarr: async (input: IntegrationInput) =>
|
||||||
apiKeyAuth,
|
new (await import("../media-organizer/lidarr/lidarr-integration")).LidarrIntegration(input),
|
||||||
),
|
readarr: async (input: IntegrationInput) =>
|
||||||
sabNzbd: withHttpAuthentication(
|
new (await import("../media-organizer/readarr/readarr-integration")).ReadarrIntegration(input),
|
||||||
async (input: IntegrationInput) =>
|
dashDot: async (input: IntegrationInput) =>
|
||||||
new (await import("../download-client/sabnzbd/sabnzbd-integration")).SabnzbdIntegration(input),
|
new (await import("../dashdot/dashdot-integration")).DashDotIntegration(input),
|
||||||
queryAuth("apikey"),
|
tdarr: async (input: IntegrationInput) =>
|
||||||
),
|
new (await import("../media-transcoding/tdarr-integration")).TdarrIntegration(input),
|
||||||
nzbGet: withHttpAuthentication(
|
proxmox: async (input: IntegrationInput) =>
|
||||||
async (input: IntegrationInput) =>
|
new (await import("../proxmox/proxmox-integration")).ProxmoxIntegration(input),
|
||||||
new (await import("../download-client/nzbget/nzbget-integration")).NzbGetIntegration(input),
|
emby: async (input: IntegrationInput) => new (await import("../emby/emby-integration")).EmbyIntegration(input),
|
||||||
basicAuth(),
|
nextcloud: async (input: IntegrationInput) =>
|
||||||
),
|
new (await import("../nextcloud/nextcloud.integration")).NextcloudIntegration(input),
|
||||||
qBittorrent: withHttpAuthentication(
|
unifiController: async (input: IntegrationInput) =>
|
||||||
async (input: IntegrationInput) =>
|
new (await import("../unifi-controller/unifi-controller-integration")).UnifiControllerIntegration(input),
|
||||||
new (await import("../download-client/qbittorrent/qbittorrent-integration")).QBitTorrentIntegration(input),
|
opnsense: async (input: IntegrationInput) =>
|
||||||
clientAuthentication,
|
new (await import("../opnsense/opnsense-integration")).OPNsenseIntegration(input),
|
||||||
),
|
ical: async (input: IntegrationInput) => new (await import("../ical/ical-integration")).ICalIntegration(input),
|
||||||
deluge: withHttpAuthentication(
|
ntfy: async (input: IntegrationInput) => new (await import("../ntfy/ntfy-integration")).NTFYIntegration(input),
|
||||||
async (input: IntegrationInput) =>
|
gotify: async (input: IntegrationInput) =>
|
||||||
new (await import("../download-client/deluge/deluge-integration")).DelugeIntegration(input),
|
new (await import("../gotify/gotify-integration")).GotifyIntegration(input),
|
||||||
clientAuthentication,
|
|
||||||
),
|
|
||||||
transmission: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) =>
|
|
||||||
new (await import("../download-client/transmission/transmission-integration")).TransmissionIntegration(input),
|
|
||||||
clientAuthentication,
|
|
||||||
),
|
|
||||||
slskd: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) =>
|
|
||||||
new (await import("../download-client/slskd/slskd-integration")).SlskdIntegration(input),
|
|
||||||
apiKeyAuth,
|
|
||||||
),
|
|
||||||
aria2: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) =>
|
|
||||||
new (await import("../download-client/aria2/aria2-integration")).Aria2Integration(input),
|
|
||||||
optionalAuth(rpcAuth),
|
|
||||||
),
|
|
||||||
jellyseerr: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) =>
|
|
||||||
new (await import("../jellyseerr/jellyseerr-integration")).JellyseerrIntegration(input),
|
|
||||||
apiKeyAuth,
|
|
||||||
),
|
|
||||||
seerr: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) => new (await import("../seerr/seerr-integration")).SeerrIntegration(input),
|
|
||||||
apiKeyAuth,
|
|
||||||
),
|
|
||||||
overseerr: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) =>
|
|
||||||
new (await import("../overseerr/overseerr-integration")).OverseerrIntegration(input),
|
|
||||||
apiKeyAuth,
|
|
||||||
),
|
|
||||||
prowlarr: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) =>
|
|
||||||
new (await import("../prowlarr/prowlarr-integration")).ProwlarrIntegration(input),
|
|
||||||
apiKeyAuth,
|
|
||||||
),
|
|
||||||
openmediavault: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) =>
|
|
||||||
new (await import("../openmediavault/openmediavault-integration")).OpenMediaVaultIntegration(input),
|
|
||||||
clientAuthentication,
|
|
||||||
),
|
|
||||||
lidarr: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) =>
|
|
||||||
new (await import("../media-organizer/lidarr/lidarr-integration")).LidarrIntegration(input),
|
|
||||||
apiKeyAuth,
|
|
||||||
),
|
|
||||||
readarr: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) =>
|
|
||||||
new (await import("../media-organizer/readarr/readarr-integration")).ReadarrIntegration(input),
|
|
||||||
apiKeyAuth,
|
|
||||||
),
|
|
||||||
dashDot: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) => new (await import("../dashdot/dashdot-integration")).DashDotIntegration(input),
|
|
||||||
noAuth,
|
|
||||||
),
|
|
||||||
tdarr: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) =>
|
|
||||||
new (await import("../media-transcoding/tdarr-integration")).TdarrIntegration(input),
|
|
||||||
optionalAuth(apiKeyAuth),
|
|
||||||
),
|
|
||||||
proxmox: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) => new (await import("../proxmox/proxmox-integration")).ProxmoxIntegration(input),
|
|
||||||
(input) => ({
|
|
||||||
headers: {
|
|
||||||
Authorization: `PVEAPIToken=${secret(input, "username")}@${secret(input, "realm")}!${secret(input, "tokenId")}=${secret(input, "apiKey")}`,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
emby: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) => new (await import("../emby/emby-integration")).EmbyIntegration(input),
|
|
||||||
headerAuth("X-Emby-Token"),
|
|
||||||
),
|
|
||||||
nextcloud: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) =>
|
|
||||||
new (await import("../nextcloud/nextcloud.integration")).NextcloudIntegration(input),
|
|
||||||
basicAuth("username", "password", { "OCS-APIRequest": "true" }),
|
|
||||||
),
|
|
||||||
unifiController: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) =>
|
|
||||||
new (await import("../unifi-controller/unifi-controller-integration")).UnifiControllerIntegration(input),
|
|
||||||
clientAuthentication,
|
|
||||||
),
|
|
||||||
opnsense: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) =>
|
|
||||||
new (await import("../opnsense/opnsense-integration")).OPNsenseIntegration(input),
|
|
||||||
basicAuth("opnsenseApiKey", "opnsenseApiSecret"),
|
|
||||||
),
|
|
||||||
ical: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) => new (await import("../ical/ical-integration")).ICalIntegration(input),
|
|
||||||
feedAuth,
|
|
||||||
),
|
|
||||||
ntfy: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) => new (await import("../ntfy/ntfy-integration")).NTFYIntegration(input),
|
|
||||||
optionalAuth(bearerAuth),
|
|
||||||
),
|
|
||||||
gotify: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) => new (await import("../gotify/gotify-integration")).GotifyIntegration(input),
|
|
||||||
basicAuth(),
|
|
||||||
),
|
|
||||||
mock: async (input: IntegrationInput) => new (await import("../mock/mock-integration")).MockIntegration(input),
|
mock: async (input: IntegrationInput) => new (await import("../mock/mock-integration")).MockIntegration(input),
|
||||||
truenas: async (input: IntegrationInput) =>
|
truenas: async (input: IntegrationInput) =>
|
||||||
new (await import("../truenas/truenas-integration")).TrueNasIntegration(input),
|
new (await import("../truenas/truenas-integration")).TrueNasIntegration(input),
|
||||||
synology: withHttpAuthentication(
|
synology: async (input: IntegrationInput) =>
|
||||||
async (input: IntegrationInput) =>
|
new (await import("../synology/synology-integration")).SynologyIntegration(input),
|
||||||
new (await import("../synology/synology-integration")).SynologyIntegration(input),
|
unraid: async (input: IntegrationInput) =>
|
||||||
clientAuthentication,
|
new (await import("../unraid/unraid-integration")).UnraidIntegration(input),
|
||||||
),
|
coolify: async (input: IntegrationInput) =>
|
||||||
unraid: withHttpAuthentication(
|
new (await import("../coolify/coolify-integration")).CoolifyIntegration(input),
|
||||||
async (input: IntegrationInput) => new (await import("../unraid/unraid-integration")).UnraidIntegration(input),
|
tracearr: async (input: IntegrationInput) =>
|
||||||
apiKeyAuth,
|
new (await import("../tracearr/tracearr-integration")).TracearrIntegration(input),
|
||||||
),
|
glances: async (input: IntegrationInput) =>
|
||||||
coolify: withHttpAuthentication(
|
new (await import("../glances/glances-integration")).GlancesIntegration(input),
|
||||||
async (input: IntegrationInput) => new (await import("../coolify/coolify-integration")).CoolifyIntegration(input),
|
immich: async (input: IntegrationInput) =>
|
||||||
bearerAuth,
|
new (await import("../immich/immich-integration")).ImmichIntegration(input),
|
||||||
),
|
paperlessNgx: async (input: IntegrationInput) =>
|
||||||
tracearr: withHttpAuthentication(
|
new (await import("../paperless-ngx/paperless-ngx-integration")).PaperlessNgxIntegration(input),
|
||||||
async (input: IntegrationInput) =>
|
patchmon: async (input: IntegrationInput) =>
|
||||||
new (await import("../tracearr/tracearr-integration")).TracearrIntegration(input),
|
new (await import("../patchmon/patchmon-integration")).PatchMonIntegration(input),
|
||||||
bearerAuth,
|
speedtestTracker: async (input: IntegrationInput) =>
|
||||||
),
|
new (await import("../speedtest-tracker/speedtest-tracker-integration")).SpeedtestTrackerIntegration(input),
|
||||||
glances: withHttpAuthentication(
|
audiobookshelf: async (input: IntegrationInput) =>
|
||||||
async (input: IntegrationInput) => new (await import("../glances/glances-integration")).GlancesIntegration(input),
|
new (await import("../audiobookshelf/audiobookshelf-integration")).AudiobookshelfIntegration(input),
|
||||||
noAuth,
|
navidrome: async (input: IntegrationInput) =>
|
||||||
),
|
new (await import("../navidrome/navidrome-integration")).NavidromeIntegration(input),
|
||||||
immich: withHttpAuthentication(
|
umami: async (input: IntegrationInput) => new (await import("../umami/umami-integration")).UmamiIntegration(input),
|
||||||
async (input: IntegrationInput) => new (await import("../immich/immich-integration")).ImmichIntegration(input),
|
gluetun: async (input: IntegrationInput) =>
|
||||||
apiKeyAuth,
|
new (await import("../gluetun/gluetun-integration")).GluetunIntegration(input),
|
||||||
),
|
archiveTeamWarrior: async (input: IntegrationInput) =>
|
||||||
paperlessNgx: withHttpAuthentication(
|
new (await import("../archive-team-warrior/archive-team-warrior-integration")).ArchiveTeamWarriorIntegration(input),
|
||||||
async (input: IntegrationInput) =>
|
uptimeKuma: async (input: IntegrationInput) =>
|
||||||
new (await import("../paperless-ngx/paperless-ngx-integration")).PaperlessNgxIntegration(input),
|
new (await import("../uptime-kuma/uptime-kuma-integration")).UptimeKumaIntegration(input),
|
||||||
headerAuth("Authorization", "Token "),
|
peaNut: async (input: IntegrationInput) =>
|
||||||
),
|
new (await import("../peanut/peanut-integration")).PeaNutIntegration(input),
|
||||||
patchmon: withHttpAuthentication(
|
beszel: async (input: IntegrationInput) =>
|
||||||
async (input: IntegrationInput) =>
|
new (await import("../beszel/beszel-integration")).BeszelIntegration(input),
|
||||||
new (await import("../patchmon/patchmon-integration")).PatchMonIntegration(input),
|
bazarr: async (input: IntegrationInput) =>
|
||||||
basicAuth("patchmonApiKey", "patchmonApiSecret"),
|
new (await import("../bazarr/bazarr-integration")).BazarrIntegration(input),
|
||||||
),
|
traefik: async (input: IntegrationInput) =>
|
||||||
speedtestTracker: withHttpAuthentication(
|
new (await import("../traefik/traefik-integration")).TraefikIntegration(input),
|
||||||
async (input: IntegrationInput) =>
|
wud: async (input: IntegrationInput) => new (await import("../wud/wud-integration")).WudIntegration(input),
|
||||||
new (await import("../speedtest-tracker/speedtest-tracker-integration")).SpeedtestTrackerIntegration(input),
|
llamacpp: async (input: IntegrationInput) =>
|
||||||
bearerAuth,
|
new (await import("../llama-cpp/llamacpp-integration")).LlamacppIntegration(input),
|
||||||
),
|
} satisfies Record<IntegrationKind, (input: IntegrationInput) => Promise<Integration>>;
|
||||||
audiobookshelf: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) =>
|
|
||||||
new (await import("../audiobookshelf/audiobookshelf-integration")).AudiobookshelfIntegration(input),
|
|
||||||
bearerAuth,
|
|
||||||
),
|
|
||||||
navidrome: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) =>
|
|
||||||
new (await import("../navidrome/navidrome-integration")).NavidromeIntegration(input),
|
|
||||||
clientAuthentication,
|
|
||||||
),
|
|
||||||
umami: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) => new (await import("../umami/umami-integration")).UmamiIntegration(input),
|
|
||||||
clientAuthentication,
|
|
||||||
),
|
|
||||||
gluetun: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) => new (await import("../gluetun/gluetun-integration")).GluetunIntegration(input),
|
|
||||||
alternativeAuth(apiKeyAuth),
|
|
||||||
),
|
|
||||||
archiveTeamWarrior: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) =>
|
|
||||||
new (await import("../archive-team-warrior/archive-team-warrior-integration")).ArchiveTeamWarriorIntegration(
|
|
||||||
input,
|
|
||||||
),
|
|
||||||
optionalAuth(basicAuth(), ["username", "password"]),
|
|
||||||
),
|
|
||||||
uptimeKuma: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) =>
|
|
||||||
new (await import("../uptime-kuma/uptime-kuma-integration")).UptimeKumaIntegration(input),
|
|
||||||
noAuth,
|
|
||||||
),
|
|
||||||
peaNut: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) => new (await import("../peanut/peanut-integration")).PeaNutIntegration(input),
|
|
||||||
optionalAuth(basicAuth(), ["username", "password"]),
|
|
||||||
),
|
|
||||||
beszel: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) => new (await import("../beszel/beszel-integration")).BeszelIntegration(input),
|
|
||||||
clientAuthentication,
|
|
||||||
),
|
|
||||||
bazarr: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) => new (await import("../bazarr/bazarr-integration")).BazarrIntegration(input),
|
|
||||||
apiKeyAuth,
|
|
||||||
),
|
|
||||||
traefik: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) => new (await import("../traefik/traefik-integration")).TraefikIntegration(input),
|
|
||||||
clientAuthentication,
|
|
||||||
),
|
|
||||||
wud: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) => new (await import("../wud/wud-integration")).WudIntegration(input),
|
|
||||||
optionalAuth(basicAuth(), ["username", "password"]),
|
|
||||||
),
|
|
||||||
llamacpp: withHttpAuthentication(
|
|
||||||
async (input: IntegrationInput) =>
|
|
||||||
new (await import("../llama-cpp/llamacpp-integration")).LlamacppIntegration(input),
|
|
||||||
noAuth,
|
|
||||||
),
|
|
||||||
} satisfies {
|
|
||||||
[Kind in IntegrationKind]: ((input: IntegrationInput) => Promise<Integration>) &
|
|
||||||
(Kind extends "truenas" | "mock"
|
|
||||||
? unknown
|
|
||||||
: {
|
|
||||||
authenticate(input: IntegrationInput): IntegrationHttpAuthentication | Promise<IntegrationHttpAuthentication>;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
type IntegrationCreators = typeof integrationCreators;
|
type IntegrationCreators = typeof integrationCreators;
|
||||||
type IntegrationInstanceOfKind<TKind extends keyof IntegrationCreators> = Awaited<
|
type IntegrationInstanceOfKind<TKind extends keyof IntegrationCreators> = Awaited<
|
||||||
@@ -341,10 +165,7 @@ export async function createIntegrationAsync(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getIntegrationHttpAuthenticationAsync(
|
export async function getIntegrationHttpAuthenticationAsync(integration: IntegrationInput & { kind: IntegrationKind }) {
|
||||||
integration: IntegrationInput & { kind: IntegrationKind },
|
if (!isHttpIntegrationKind(integration.kind)) throw new Error("This integration does not use HTTP");
|
||||||
): Promise<IntegrationHttpAuthentication> {
|
return clientAuthentication(() => createIntegrationAsync(integration));
|
||||||
const creator = integrationCreators[integration.kind];
|
|
||||||
if (!("authenticate" in creator)) throw new Error("This integration does not use HTTP");
|
|
||||||
return creator.authenticate(integration);
|
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ import { removeTrailingSlash } from "@homarr/common";
|
|||||||
import { createAxiosCertificateInstanceAsync, createCertificateAgentAsync } from "@homarr/core/infrastructure/http";
|
import { createAxiosCertificateInstanceAsync, createCertificateAgentAsync } from "@homarr/core/infrastructure/http";
|
||||||
import type { IntegrationKind, IntegrationSecretKind } from "@homarr/definitions";
|
import type { IntegrationKind, IntegrationSecretKind } from "@homarr/definitions";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import { HandleIntegrationErrors } from "./errors/decorator";
|
import { HandleIntegrationErrors } from "./errors/decorator";
|
||||||
import { TestConnectionError } from "./test-connection/test-connection-error";
|
import { TestConnectionError } from "./test-connection/test-connection-error";
|
||||||
import type { TestingResult } from "./test-connection/test-connection-service";
|
import type { TestingResult } from "./test-connection/test-connection-service";
|
||||||
@@ -36,6 +37,8 @@ export interface IntegrationTestingInput {
|
|||||||
export abstract class Integration {
|
export abstract class Integration {
|
||||||
constructor(protected integration: IntegrationInput) {}
|
constructor(protected integration: IntegrationInput) {}
|
||||||
|
|
||||||
|
public abstract getHttpAuthenticationAsync(refresh?: boolean): Promise<IntegrationHttpAuthentication>;
|
||||||
|
|
||||||
public get publicIntegration() {
|
public get publicIntegration() {
|
||||||
return {
|
return {
|
||||||
id: this.integration.id,
|
id: this.integration.id,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -8,6 +9,10 @@ import type { BazarrBadges } from "./bazarr-types";
|
|||||||
import { bazarrBadgesSchema, bazarrSystemStatusSchema } from "./bazarr-types";
|
import { bazarrBadgesSchema, bazarrSystemStatusSchema } from "./bazarr-types";
|
||||||
|
|
||||||
export class BazarrIntegration extends Integration {
|
export class BazarrIntegration extends Integration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return { headers: this.getAuthHeaders(), redactValues: [] };
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const response = await input.fetchAsync(this.url("/api/system/status"), {
|
const response = await input.fetchAsync(this.url("/api/system/status"), {
|
||||||
headers: this.getAuthHeaders(),
|
headers: this.getAuthHeaders(),
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ResponseError } from "@homarr/common/server";
|
import { ResponseError } from "@homarr/common/server";
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import type { TestingResult } from "../base/test-connection/test-connection-service";
|
import type { TestingResult } from "../base/test-connection/test-connection-service";
|
||||||
@@ -32,6 +33,10 @@ import {
|
|||||||
} from "./coolify-types";
|
} from "./coolify-types";
|
||||||
|
|
||||||
export class CoolifyIntegration extends Integration {
|
export class CoolifyIntegration extends Integration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return { headers: this.getAuthHeaders() };
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const healthUrl = this.url("/api/health");
|
const healthUrl = this.url("/api/health");
|
||||||
const healthResponse = await input.fetchAsync(healthUrl, {});
|
const healthResponse = await input.fetchAsync(healthUrl, {});
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { z } from "zod/v4";
|
|||||||
|
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import { createChannelEventHistoryOld } from "../../../redis/src/lib/channel";
|
import { createChannelEventHistoryOld } from "../../../redis/src/lib/channel";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
@@ -14,6 +15,10 @@ import type { ISystemHealthMonitoringIntegration } from "../interfaces/health-mo
|
|||||||
import type { SystemHealthMonitoring } from "../interfaces/health-monitoring/health-monitoring-types";
|
import type { SystemHealthMonitoring } from "../interfaces/health-monitoring/health-monitoring-types";
|
||||||
|
|
||||||
export class DashDotIntegration extends Integration implements ISystemHealthMonitoringIntegration {
|
export class DashDotIntegration extends Integration implements ISystemHealthMonitoringIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const response = await input.fetchAsync(this.url("/info"));
|
const response = await input.fetchAsync(this.url("/info"));
|
||||||
if (!response.ok) return TestConnectionError.StatusResult(response);
|
if (!response.ok) return TestConnectionError.StatusResult(response);
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import type { fetch as undiciFetch } from "undici";
|
|||||||
import { ResponseError } from "@homarr/common/server";
|
import { ResponseError } from "@homarr/common/server";
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../../http-auth";
|
||||||
import { Integration } from "../../base/integration";
|
import { Integration } from "../../base/integration";
|
||||||
import type { IntegrationTestingInput } from "../../base/integration";
|
import type { IntegrationTestingInput } from "../../base/integration";
|
||||||
import type { TestingResult } from "../../base/test-connection/test-connection-service";
|
import type { TestingResult } from "../../base/test-connection/test-connection-service";
|
||||||
@@ -13,6 +14,27 @@ import type { DownloadClientItem } from "../../interfaces/downloads/download-cli
|
|||||||
import type { Aria2Download, Aria2GetClient } from "./aria2-types";
|
import type { Aria2Download, Aria2GetClient } from "./aria2-types";
|
||||||
|
|
||||||
export class Aria2Integration extends Integration implements IDownloadClientIntegration {
|
export class Aria2Integration extends Integration implements IDownloadClientIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
if (!this.hasSecretValue("apiKey") || !this.getSecretValue("apiKey")) return {};
|
||||||
|
return {
|
||||||
|
transformBody: (body) => {
|
||||||
|
const authenticate = (value: unknown): unknown => {
|
||||||
|
if (Array.isArray(value)) return value.map(authenticate);
|
||||||
|
if (!value || typeof value !== "object") throw new Error("Expected a JSON-RPC request body");
|
||||||
|
const request = value as { method?: string; methodName?: string; params?: unknown[] };
|
||||||
|
const method = request.method ?? request.methodName;
|
||||||
|
const params = request.params ?? [];
|
||||||
|
if (!Array.isArray(params)) throw new Error("JSON-RPC params must be an array");
|
||||||
|
if (method === "system.multicall") return { ...request, params: [authenticate(params[0])] };
|
||||||
|
if (method === "system.listMethods" || method === "system.listNotifications") return request;
|
||||||
|
if (typeof params[0] === "string" && params[0].startsWith("token:")) params.shift();
|
||||||
|
return { ...request, params: [`token:${this.getSecretValue("apiKey")}`, ...params] };
|
||||||
|
};
|
||||||
|
return JSON.stringify(authenticate(JSON.parse(body ?? "null")));
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
public async getClientJobsAndStatusAsync(input: { limit: number }): Promise<DownloadClientJobsAndStatus> {
|
public async getClientJobsAndStatusAsync(input: { limit: number }): Promise<DownloadClientJobsAndStatus> {
|
||||||
const client = this.getClient();
|
const client = this.getClient();
|
||||||
const keys: (keyof Aria2Download)[] = [
|
const keys: (keyof Aria2Download)[] = [
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import type { fetch as undiciFetch } from "undici";
|
|||||||
import { ResponseError } from "@homarr/common/server";
|
import { ResponseError } from "@homarr/common/server";
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../../http-auth";
|
||||||
|
import { basicAuth } from "../../http-auth";
|
||||||
import { Integration } from "../../base/integration";
|
import { Integration } from "../../base/integration";
|
||||||
import type { IntegrationTestingInput } from "../../base/integration";
|
import type { IntegrationTestingInput } from "../../base/integration";
|
||||||
import type { TestingResult } from "../../base/test-connection/test-connection-service";
|
import type { TestingResult } from "../../base/test-connection/test-connection-service";
|
||||||
@@ -14,6 +16,10 @@ import type { DownloadClientStatus } from "../../interfaces/downloads/download-c
|
|||||||
import type { NzbGetClient } from "./nzbget-types";
|
import type { NzbGetClient } from "./nzbget-types";
|
||||||
|
|
||||||
export class NzbGetIntegration extends Integration implements IDownloadClientIntegration {
|
export class NzbGetIntegration extends Integration implements IDownloadClientIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return basicAuth()(this.integration);
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
await this.nzbGetApiCallWithCustomFetchAsync(input.fetchAsync, "version");
|
await this.nzbGetApiCallWithCustomFetchAsync(input.fetchAsync, "version");
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import type { fetch as undiciFetch } from "undici";
|
|||||||
import { ResponseError } from "@homarr/common/server";
|
import { ResponseError } from "@homarr/common/server";
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../../http-auth";
|
||||||
|
import { queryAuth } from "../../http-auth";
|
||||||
import { Integration } from "../../base/integration";
|
import { Integration } from "../../base/integration";
|
||||||
import type { IntegrationTestingInput } from "../../base/integration";
|
import type { IntegrationTestingInput } from "../../base/integration";
|
||||||
import type { TestingResult } from "../../base/test-connection/test-connection-service";
|
import type { TestingResult } from "../../base/test-connection/test-connection-service";
|
||||||
@@ -17,6 +19,10 @@ import { historySchema, queueSchema } from "./sabnzbd-schema";
|
|||||||
dayjs.extend(duration);
|
dayjs.extend(duration);
|
||||||
|
|
||||||
export class SabnzbdIntegration extends Integration implements IDownloadClientIntegration {
|
export class SabnzbdIntegration extends Integration implements IDownloadClientIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return queryAuth("apikey")(this.integration);
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
//This is the one call that uses the least amount of data while requiring the api key
|
//This is the one call that uses the least amount of data while requiring the api key
|
||||||
await this.sabNzbApiCallWithCustomFetchAsync(input.fetchAsync, "translate", { value: "ping" });
|
await this.sabNzbApiCallWithCustomFetchAsync(input.fetchAsync, "translate", { value: "ping" });
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/h
|
|||||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||||
import { ErrorWithMetadata } from "@homarr/core/infrastructure/logs/error";
|
import { ErrorWithMetadata } from "@homarr/core/infrastructure/logs/error";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../../http-auth";
|
||||||
|
import { apiKeyAuth } from "../../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../../base/integration";
|
import type { IntegrationTestingInput } from "../../base/integration";
|
||||||
import { Integration } from "../../base/integration";
|
import { Integration } from "../../base/integration";
|
||||||
import { TestConnectionError } from "../../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../../base/test-connection/test-connection-error";
|
||||||
@@ -49,6 +51,10 @@ const logger = createLogger({ module: "slskd-integration" });
|
|||||||
* Slskd integration cannot pause or stop downloads, it can only list downloads.
|
* Slskd integration cannot pause or stop downloads, it can only list downloads.
|
||||||
*/
|
*/
|
||||||
export class SlskdIntegration extends Integration implements IDownloadClientIntegration {
|
export class SlskdIntegration extends Integration implements IDownloadClientIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return apiKeyAuth(this.integration);
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-restricted-syntax
|
// eslint-disable-next-line no-restricted-syntax
|
||||||
public pauseQueueAsync(): Promise<void> {
|
public pauseQueueAsync(): Promise<void> {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
@@ -76,9 +82,7 @@ export class SlskdIntegration extends Integration implements IDownloadClientInte
|
|||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const response = await input.fetchAsync(this.url("/api/v0/server"), {
|
const response = await input.fetchAsync(this.url("/api/v0/server"), {
|
||||||
headers: {
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
"X-API-Key": this.getSecretValue("apiKey"),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -148,9 +152,7 @@ export class SlskdIntegration extends Integration implements IDownloadClientInte
|
|||||||
): Promise<unknown> {
|
): Promise<unknown> {
|
||||||
const response = await fetchWithTrustedCertificatesAsync(this.url(path), {
|
const response = await fetchWithTrustedCertificatesAsync(this.url(path), {
|
||||||
...options,
|
...options,
|
||||||
headers: {
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
"X-API-Key": this.getSecretValue("apiKey"),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { z } from "zod/v4";
|
|||||||
import { ResponseError } from "@homarr/common/server";
|
import { ResponseError } from "@homarr/common/server";
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
|
import { headerAuth } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -90,6 +92,10 @@ const userSchema = z.object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export class EmbyIntegration extends Integration implements IMediaServerIntegration, IMediaReleasesIntegration {
|
export class EmbyIntegration extends Integration implements IMediaServerIntegration, IMediaReleasesIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return headerAuth("X-Emby-Token")(this.integration);
|
||||||
|
}
|
||||||
|
|
||||||
private static readonly apiKeyHeader = "X-Emby-Token";
|
private static readonly apiKeyHeader = "X-Emby-Token";
|
||||||
private static readonly deviceId = "homarr-emby-integration";
|
private static readonly deviceId = "homarr-emby-integration";
|
||||||
private static readonly authorizationHeaderValue = `Emby Client="Dashboard", Device="Homarr", DeviceId="${EmbyIntegration.deviceId}", Version="0.0.1"`;
|
private static readonly authorizationHeaderValue = `Emby Client="Dashboard", Device="Homarr", DeviceId="${EmbyIntegration.deviceId}", Version="0.0.1"`;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { z } from "zod/v4";
|
|||||||
import { ResponseError } from "@homarr/common/server";
|
import { ResponseError } from "@homarr/common/server";
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import type { IntegrationInput, IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationInput, IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import type { SessionStore } from "../base/session-store";
|
import type { SessionStore } from "../base/session-store";
|
||||||
@@ -14,6 +15,10 @@ import type { ISystemHealthMonitoringIntegration } from "../interfaces/health-mo
|
|||||||
import type { SystemHealthMonitoring } from "../types";
|
import type { SystemHealthMonitoring } from "../types";
|
||||||
|
|
||||||
export class GlancesIntegration extends Integration implements ISystemHealthMonitoringIntegration {
|
export class GlancesIntegration extends Integration implements ISystemHealthMonitoringIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
private readonly sessionStore: SessionStore<{ version: string }>;
|
private readonly sessionStore: SessionStore<{ version: string }>;
|
||||||
|
|
||||||
constructor(integration: IntegrationInput) {
|
constructor(integration: IntegrationInput) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ResponseError } from "@homarr/common/server";
|
import { ResponseError } from "@homarr/common/server";
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -16,6 +17,10 @@ import {
|
|||||||
import type { GluetunDnsStatus, GluetunPublicIp, GluetunVpnSettings, GluetunVpnStatus } from "./gluetun-types";
|
import type { GluetunDnsStatus, GluetunPublicIp, GluetunVpnSettings, GluetunVpnStatus } from "./gluetun-types";
|
||||||
|
|
||||||
export class GluetunIntegration extends Integration implements VpnSummaryIntegration {
|
export class GluetunIntegration extends Integration implements VpnSummaryIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return { headers: this.getAuthHeaders() };
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const authHeaders = this.getAuthHeaders();
|
const authHeaders = this.getAuthHeaders();
|
||||||
const url = this.url("/v1/vpn/status");
|
const url = this.url("/v1/vpn/status");
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { ResponseError } from "@homarr/common/server";
|
|||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
import { ImageProxy } from "@homarr/image-proxy";
|
import { ImageProxy } from "@homarr/image-proxy";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import type { TestingResult } from "../base/test-connection/test-connection-service";
|
import type { TestingResult } from "../base/test-connection/test-connection-service";
|
||||||
@@ -10,6 +11,10 @@ import type { INotificationsIntegration } from "../interfaces/notifications/noti
|
|||||||
import { gotifyApplicationsResponseSchema, gotifyMessagesResponseSchema } from "./gotify-schema";
|
import { gotifyApplicationsResponseSchema, gotifyMessagesResponseSchema } from "./gotify-schema";
|
||||||
|
|
||||||
export class GotifyIntegration extends Integration implements INotificationsIntegration {
|
export class GotifyIntegration extends Integration implements INotificationsIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return { headers: this.getHeaders() };
|
||||||
|
}
|
||||||
|
|
||||||
public async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
public async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
await input.fetchAsync(this.url("/health"), { headers: this.getHeaders() });
|
await input.fetchAsync(this.url("/health"), { headers: this.getHeaders() });
|
||||||
return { success: true };
|
return { success: true };
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/h
|
|||||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||||
import { ErrorWithMetadata } from "@homarr/core/infrastructure/logs/error";
|
import { ErrorWithMetadata } from "@homarr/core/infrastructure/logs/error";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -17,6 +18,10 @@ import { calendarEventSchema, calendarsSchema, entityStateSchema } from "./homea
|
|||||||
const logger = createLogger({ module: "homeAssistantIntegration" });
|
const logger = createLogger({ module: "homeAssistantIntegration" });
|
||||||
|
|
||||||
export class HomeAssistantIntegration extends Integration implements ISmartHomeIntegration, ICalendarIntegration {
|
export class HomeAssistantIntegration extends Integration implements ISmartHomeIntegration, ICalendarIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return { headers: this.getAuthHeaders() };
|
||||||
|
}
|
||||||
|
|
||||||
public async getEntityStateAsync(entityId: string) {
|
public async getEntityStateAsync(entityId: string) {
|
||||||
try {
|
try {
|
||||||
const response = await this.getAsync(`/api/states/${entityId}`);
|
const response = await this.getAsync(`/api/states/${entityId}`);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export interface IntegrationHttpAuthentication {
|
|||||||
refreshAsync?(): Promise<IntegrationHttpAuthentication>;
|
refreshAsync?(): Promise<IntegrationHttpAuthentication>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function secret(input: IntegrationInput, kind: IntegrationSecretKind) {
|
function secret(input: IntegrationInput, kind: IntegrationSecretKind) {
|
||||||
const value = input.decryptedSecrets.find((entry) => entry.kind === kind)?.value;
|
const value = input.decryptedSecrets.find((entry) => entry.kind === kind)?.value;
|
||||||
if (!value) throw new Error(`Integration credential ${kind} is missing`);
|
if (!value) throw new Error(`Integration credential ${kind} is missing`);
|
||||||
return value;
|
return value;
|
||||||
@@ -41,83 +41,28 @@ export const basicAuth =
|
|||||||
export const queryAuth =
|
export const queryAuth =
|
||||||
(name: string, kind: IntegrationSecretKind = "apiKey") =>
|
(name: string, kind: IntegrationSecretKind = "apiKey") =>
|
||||||
(input: IntegrationInput): IntegrationHttpAuthentication => ({ query: { [name]: secret(input, kind) } });
|
(input: IntegrationInput): IntegrationHttpAuthentication => ({ query: { [name]: secret(input, kind) } });
|
||||||
export const noAuth = (): IntegrationHttpAuthentication => ({});
|
export const clientAuthentication = async (
|
||||||
export const optionalAuth =
|
create: () => Promise<{ getHttpAuthenticationAsync(refresh?: boolean): Promise<IntegrationHttpAuthentication> }>,
|
||||||
(
|
) =>
|
||||||
resolve: (input: IntegrationInput) => IntegrationHttpAuthentication,
|
withAuthTimeout(async () => {
|
||||||
required: IntegrationSecretKind[] = ["apiKey"],
|
const client = await create();
|
||||||
) =>
|
const resolve = async (refresh = false): Promise<IntegrationHttpAuthentication> => {
|
||||||
(input: IntegrationInput) => {
|
const auth = await client.getHttpAuthenticationAsync(refresh);
|
||||||
if (
|
const values = [...Object.values(auth.headers ?? {}), ...Object.values(auth.query ?? {})];
|
||||||
!required.every((requiredKind) =>
|
for (const [name, value] of Object.entries(auth.headers ?? {})) {
|
||||||
input.decryptedSecrets.some(({ kind, value }) => kind === requiredKind && value),
|
if (name.toLowerCase() === "cookie") {
|
||||||
)
|
for (const cookie of value.split(";")) values.push(cookie.slice(cookie.indexOf("=") + 1).trim());
|
||||||
)
|
}
|
||||||
return noAuth();
|
if (name.toLowerCase() === "authorization") values.push(value.slice(value.indexOf(" ") + 1));
|
||||||
return resolve(input);
|
|
||||||
};
|
|
||||||
export const alternativeAuth =
|
|
||||||
(
|
|
||||||
apiKey: (input: IntegrationInput) => IntegrationHttpAuthentication,
|
|
||||||
fallback = optionalAuth(basicAuth(), ["username", "password"]),
|
|
||||||
) =>
|
|
||||||
(input: IntegrationInput) => {
|
|
||||||
if (input.decryptedSecrets.some(({ kind, value }) => kind === "apiKey" && value)) return apiKey(input);
|
|
||||||
return fallback(input);
|
|
||||||
};
|
|
||||||
export const rpcAuth = (input: IntegrationInput): IntegrationHttpAuthentication => ({
|
|
||||||
transformBody(body) {
|
|
||||||
const authenticate = (value: unknown): unknown => {
|
|
||||||
if (Array.isArray(value)) return value.map(authenticate);
|
|
||||||
if (!value || typeof value !== "object") throw new Error("Expected a JSON-RPC request body");
|
|
||||||
const request = value as { method?: string; methodName?: string; params?: unknown[] };
|
|
||||||
const method = request.method ?? request.methodName;
|
|
||||||
const params = request.params ?? [];
|
|
||||||
if (!Array.isArray(params)) throw new Error("JSON-RPC params must be an array");
|
|
||||||
if (method === "system.multicall") return { ...request, params: [authenticate(params[0])] };
|
|
||||||
if (method === "system.listMethods" || method === "system.listNotifications") return request;
|
|
||||||
if (typeof params[0] === "string" && params[0].startsWith("token:")) params.shift();
|
|
||||||
return { ...request, params: [`token:${secret(input, "apiKey")}`, ...params] };
|
|
||||||
};
|
|
||||||
return JSON.stringify(authenticate(JSON.parse(body ?? "null")));
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export function withHttpAuthentication<T>(
|
|
||||||
create: (input: IntegrationInput) => Promise<T>,
|
|
||||||
authenticate: (
|
|
||||||
input: IntegrationInput,
|
|
||||||
create: () => Promise<T>,
|
|
||||||
) => IntegrationHttpAuthentication | Promise<IntegrationHttpAuthentication>,
|
|
||||||
) {
|
|
||||||
return Object.assign(create, {
|
|
||||||
authenticate: (input: IntegrationInput) => withAuthTimeout(() => authenticate(input, () => create(input))),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
export const clientAuthentication = async <
|
|
||||||
T extends { getHttpAuthenticationAsync(refresh?: boolean): Promise<IntegrationHttpAuthentication> },
|
|
||||||
>(
|
|
||||||
_input: IntegrationInput,
|
|
||||||
create: () => Promise<T>,
|
|
||||||
) => {
|
|
||||||
const client = await create();
|
|
||||||
const resolve = async (refresh = false): Promise<IntegrationHttpAuthentication> => {
|
|
||||||
const auth = await client.getHttpAuthenticationAsync(refresh);
|
|
||||||
const values = [...Object.values(auth.headers ?? {}), ...Object.values(auth.query ?? {})];
|
|
||||||
for (const [name, value] of Object.entries(auth.headers ?? {})) {
|
|
||||||
if (name.toLowerCase() === "cookie") {
|
|
||||||
for (const cookie of value.split(";")) values.push(cookie.slice(cookie.indexOf("=") + 1).trim());
|
|
||||||
}
|
}
|
||||||
if (name.toLowerCase() === "authorization") values.push(value.slice(value.indexOf(" ") + 1));
|
return {
|
||||||
}
|
...auth,
|
||||||
return {
|
redactValues: auth.redactValues ?? values,
|
||||||
...auth,
|
refreshAsync: () => withAuthTimeout(() => resolve(true)),
|
||||||
redactValues: auth.redactValues ?? values,
|
};
|
||||||
refreshAsync: () => withAuthTimeout(() => resolve(true)),
|
|
||||||
};
|
};
|
||||||
};
|
return resolve();
|
||||||
return resolve();
|
});
|
||||||
};
|
|
||||||
|
|
||||||
async function withAuthTimeout<T>(resolve: () => T | Promise<T>): Promise<T> {
|
async function withAuthTimeout<T>(resolve: () => T | Promise<T>): Promise<T> {
|
||||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||||
@@ -132,17 +77,3 @@ async function withAuthTimeout<T>(resolve: () => T | Promise<T>): Promise<T> {
|
|||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const feedAuth = (input: IntegrationInput): IntegrationHttpAuthentication => {
|
|
||||||
const baseUrl = secret(input, "url");
|
|
||||||
const base = new URL(baseUrl);
|
|
||||||
return {
|
|
||||||
baseUrl,
|
|
||||||
redactValues: [...base.searchParams.values()],
|
|
||||||
transformUrl(url) {
|
|
||||||
// The stored feed URL is a complete endpoint, so the root request uses it exactly.
|
|
||||||
if (url.pathname === `${base.pathname}/`) url.pathname = base.pathname;
|
|
||||||
for (const [name, value] of base.searchParams) url.searchParams.set(name, value);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
@@ -2,6 +2,7 @@ import ICAL from "ical.js";
|
|||||||
|
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -10,6 +11,20 @@ import type { ICalendarIntegration } from "../interfaces/calendar/calendar-integ
|
|||||||
import type { CalendarEvent } from "../interfaces/calendar/calendar-types";
|
import type { CalendarEvent } from "../interfaces/calendar/calendar-types";
|
||||||
|
|
||||||
export class ICalIntegration extends Integration implements ICalendarIntegration {
|
export class ICalIntegration extends Integration implements ICalendarIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
const baseUrl = this.getSecretValue("url");
|
||||||
|
const base = new URL(baseUrl);
|
||||||
|
return {
|
||||||
|
baseUrl,
|
||||||
|
redactValues: [...base.searchParams.values()],
|
||||||
|
transformUrl(url) {
|
||||||
|
// The stored feed URL is a complete endpoint, so the root request uses it exactly.
|
||||||
|
if (url.pathname === `${base.pathname}/`) url.pathname = base.pathname;
|
||||||
|
for (const [name, value] of base.searchParams) url.searchParams.set(name, value);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
async getCalendarEventsAsync(start: Date, end: Date): Promise<CalendarEvent[]> {
|
async getCalendarEventsAsync(start: Date, end: Date): Promise<CalendarEvent[]> {
|
||||||
const response = await fetchWithTrustedCertificatesAsync(super.getSecretValue("url"));
|
const response = await fetchWithTrustedCertificatesAsync(super.getSecretValue("url"));
|
||||||
const result = await response.text();
|
const result = await response.text();
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/h
|
|||||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||||
import { ImageProxy } from "@homarr/image-proxy";
|
import { ImageProxy } from "@homarr/image-proxy";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
|
import { apiKeyAuth } from "../http-auth";
|
||||||
import type { IntegrationInput, IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationInput, IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import type { TestingResult } from "../base/test-connection/test-connection-service";
|
import type { TestingResult } from "../base/test-connection/test-connection-service";
|
||||||
@@ -48,6 +50,10 @@ const logger = createLogger({ module: "immich-integration" });
|
|||||||
const carouselPhotoCount = 50;
|
const carouselPhotoCount = 50;
|
||||||
|
|
||||||
export class ImmichIntegration extends Integration {
|
export class ImmichIntegration extends Integration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return apiKeyAuth(this.integration);
|
||||||
|
}
|
||||||
|
|
||||||
constructor(integration: IntegrationInput) {
|
constructor(integration: IntegrationInput) {
|
||||||
super(integration);
|
super(integration);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
|
import { apiKeyAuth } from "../http-auth";
|
||||||
import type { MediaAvailability } from "../interfaces/media-requests/media-request-types";
|
import type { MediaAvailability } from "../interfaces/media-requests/media-request-types";
|
||||||
import { UpstreamMediaAvailability } from "../interfaces/media-requests/media-request-types";
|
import { UpstreamMediaAvailability } from "../interfaces/media-requests/media-request-types";
|
||||||
import { OverseerrIntegration } from "../overseerr/overseerr-integration";
|
import { OverseerrIntegration } from "../overseerr/overseerr-integration";
|
||||||
|
|
||||||
export class JellyseerrIntegration extends OverseerrIntegration {
|
export class JellyseerrIntegration extends OverseerrIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return apiKeyAuth(this.integration);
|
||||||
|
}
|
||||||
|
|
||||||
protected override mapAvailability(availability: UpstreamMediaAvailability, inProgress: boolean): MediaAvailability {
|
protected override mapAvailability(availability: UpstreamMediaAvailability, inProgress: boolean): MediaAvailability {
|
||||||
// Availability statuses are not exactly the same between Jellyseerr and Overseerr (Jellyseerr has "blacklisted" additionally (deleted is the same value in overseerr))
|
// Availability statuses are not exactly the same between Jellyseerr and Overseerr (Jellyseerr has "blacklisted" additionally (deleted is the same value in overseerr))
|
||||||
if (availability === UpstreamMediaAvailability.JellyseerrBlacklistedOrOverseerrDeleted) return "blacklisted";
|
if (availability === UpstreamMediaAvailability.JellyseerrBlacklistedOrOverseerrDeleted) return "blacklisted";
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ParseError, ResponseError } from "@homarr/common/server";
|
import { ParseError, ResponseError } from "@homarr/common/server";
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -22,6 +23,10 @@ import {
|
|||||||
const LLMACPP_REQUEST_TIMEOUT_MS = 10_000;
|
const LLMACPP_REQUEST_TIMEOUT_MS = 10_000;
|
||||||
|
|
||||||
export class LlamacppIntegration extends Integration {
|
export class LlamacppIntegration extends Integration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const response = await input.fetchAsync(this.url("/health"), {
|
const response = await input.fetchAsync(this.url("/health"), {
|
||||||
signal: AbortSignal.timeout(LLMACPP_REQUEST_TIMEOUT_MS),
|
signal: AbortSignal.timeout(LLMACPP_REQUEST_TIMEOUT_MS),
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import { z } from "zod/v4";
|
|||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../../http-auth";
|
||||||
|
import { apiKeyAuth } from "../../http-auth";
|
||||||
import { Integration } from "../../base/integration";
|
import { Integration } from "../../base/integration";
|
||||||
import type { IntegrationTestingInput } from "../../base/integration";
|
import type { IntegrationTestingInput } from "../../base/integration";
|
||||||
import { TestConnectionError } from "../../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../../base/test-connection/test-connection-error";
|
||||||
@@ -14,9 +16,13 @@ import { mediaOrganizerPriorities } from "../media-organizer";
|
|||||||
const logger = createLogger({ module: "lidarrIntegration" });
|
const logger = createLogger({ module: "lidarrIntegration" });
|
||||||
|
|
||||||
export class LidarrIntegration extends Integration implements ICalendarIntegration {
|
export class LidarrIntegration extends Integration implements ICalendarIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return apiKeyAuth(this.integration);
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const response = await input.fetchAsync(this.url("/api"), {
|
const response = await input.fetchAsync(this.url("/api"), {
|
||||||
headers: { "X-Api-Key": super.getSecretValue("apiKey") },
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) return TestConnectionError.StatusResult(response);
|
if (!response.ok) return TestConnectionError.StatusResult(response);
|
||||||
@@ -39,9 +45,7 @@ export class LidarrIntegration extends Integration implements ICalendarIntegrati
|
|||||||
});
|
});
|
||||||
|
|
||||||
const response = await fetchWithTrustedCertificatesAsync(url, {
|
const response = await fetchWithTrustedCertificatesAsync(url, {
|
||||||
headers: {
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
"X-Api-Key": super.getSecretValue("apiKey"),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
const lidarrCalendarEvents = await z.array(lidarrCalendarEventSchema).parseAsync(await response.json());
|
const lidarrCalendarEvents = await z.array(lidarrCalendarEventSchema).parseAsync(await response.json());
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import { z } from "zod/v4";
|
|||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../../http-auth";
|
||||||
|
import { apiKeyAuth } from "../../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../../base/integration";
|
import type { IntegrationTestingInput } from "../../base/integration";
|
||||||
import { Integration } from "../../base/integration";
|
import { Integration } from "../../base/integration";
|
||||||
import { TestConnectionError } from "../../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../../base/test-connection/test-connection-error";
|
||||||
@@ -17,6 +19,10 @@ import { mediaOrganizerPriorities } from "../media-organizer";
|
|||||||
const logger = createLogger({ module: "radarrIntegration" });
|
const logger = createLogger({ module: "radarrIntegration" });
|
||||||
|
|
||||||
export class RadarrIntegration extends Integration implements ICalendarIntegration, IMediaOrganizerIntegration {
|
export class RadarrIntegration extends Integration implements ICalendarIntegration, IMediaOrganizerIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return apiKeyAuth(this.integration);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the events in the Radarr calendar between two dates.
|
* Gets the events in the Radarr calendar between two dates.
|
||||||
* @param start The start date
|
* @param start The start date
|
||||||
@@ -31,9 +37,7 @@ export class RadarrIntegration extends Integration implements ICalendarIntegrati
|
|||||||
});
|
});
|
||||||
|
|
||||||
const response = await fetchWithTrustedCertificatesAsync(url, {
|
const response = await fetchWithTrustedCertificatesAsync(url, {
|
||||||
headers: {
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
"X-Api-Key": super.getSecretValue("apiKey"),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
const radarrCalendarEvents = await z.array(radarrCalendarEventSchema).parseAsync(await response.json());
|
const radarrCalendarEvents = await z.array(radarrCalendarEventSchema).parseAsync(await response.json());
|
||||||
|
|
||||||
@@ -122,7 +126,7 @@ export class RadarrIntegration extends Integration implements ICalendarIntegrati
|
|||||||
});
|
});
|
||||||
|
|
||||||
const response = await fetchWithTrustedCertificatesAsync(url, {
|
const response = await fetchWithTrustedCertificatesAsync(url, {
|
||||||
headers: { "X-Api-Key": super.getSecretValue("apiKey") },
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
});
|
});
|
||||||
const data = await z
|
const data = await z
|
||||||
.object({
|
.object({
|
||||||
@@ -154,7 +158,7 @@ export class RadarrIntegration extends Integration implements ICalendarIntegrati
|
|||||||
});
|
});
|
||||||
|
|
||||||
const response = await fetchWithTrustedCertificatesAsync(url, {
|
const response = await fetchWithTrustedCertificatesAsync(url, {
|
||||||
headers: { "X-Api-Key": super.getSecretValue("apiKey") },
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
});
|
});
|
||||||
const data = await z
|
const data = await z
|
||||||
.object({
|
.object({
|
||||||
@@ -188,7 +192,7 @@ export class RadarrIntegration extends Integration implements ICalendarIntegrati
|
|||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const response = await input.fetchAsync(this.url("/api"), {
|
const response = await input.fetchAsync(this.url("/api"), {
|
||||||
headers: { "X-Api-Key": super.getSecretValue("apiKey") },
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) return TestConnectionError.StatusResult(response);
|
if (!response.ok) return TestConnectionError.StatusResult(response);
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import { z } from "zod/v4";
|
|||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../../http-auth";
|
||||||
|
import { apiKeyAuth } from "../../http-auth";
|
||||||
import { Integration } from "../../base/integration";
|
import { Integration } from "../../base/integration";
|
||||||
import type { IntegrationTestingInput } from "../../base/integration";
|
import type { IntegrationTestingInput } from "../../base/integration";
|
||||||
import { TestConnectionError } from "../../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../../base/test-connection/test-connection-error";
|
||||||
@@ -14,9 +16,13 @@ import { mediaOrganizerPriorities } from "../media-organizer";
|
|||||||
const logger = createLogger({ module: "readarrIntegration" });
|
const logger = createLogger({ module: "readarrIntegration" });
|
||||||
|
|
||||||
export class ReadarrIntegration extends Integration implements ICalendarIntegration {
|
export class ReadarrIntegration extends Integration implements ICalendarIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return apiKeyAuth(this.integration);
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const response = await input.fetchAsync(this.url("/api"), {
|
const response = await input.fetchAsync(this.url("/api"), {
|
||||||
headers: { "X-Api-Key": super.getSecretValue("apiKey") },
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) return TestConnectionError.StatusResult(response);
|
if (!response.ok) return TestConnectionError.StatusResult(response);
|
||||||
@@ -45,9 +51,7 @@ export class ReadarrIntegration extends Integration implements ICalendarIntegrat
|
|||||||
});
|
});
|
||||||
|
|
||||||
const response = await fetchWithTrustedCertificatesAsync(url, {
|
const response = await fetchWithTrustedCertificatesAsync(url, {
|
||||||
headers: {
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
"X-Api-Key": super.getSecretValue("apiKey"),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
const readarrCalendarEvents = await z.array(readarrCalendarEventSchema).parseAsync(await response.json());
|
const readarrCalendarEvents = await z.array(readarrCalendarEventSchema).parseAsync(await response.json());
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ import { z } from "zod/v4";
|
|||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../../http-auth";
|
||||||
|
import { apiKeyAuth } from "../../http-auth";
|
||||||
import { Integration } from "../../base/integration";
|
import { Integration } from "../../base/integration";
|
||||||
import type { IntegrationTestingInput } from "../../base/integration";
|
import type { IntegrationTestingInput } from "../../base/integration";
|
||||||
import { TestConnectionError } from "../../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../../base/test-connection/test-connection-error";
|
||||||
@@ -16,6 +18,10 @@ import { mediaOrganizerPriorities } from "../media-organizer";
|
|||||||
const logger = createLogger({ module: "sonarrIntegration" });
|
const logger = createLogger({ module: "sonarrIntegration" });
|
||||||
|
|
||||||
export class SonarrIntegration extends Integration implements ICalendarIntegration, IMediaOrganizerIntegration {
|
export class SonarrIntegration extends Integration implements ICalendarIntegration, IMediaOrganizerIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return apiKeyAuth(this.integration);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the events in the Sonarr calendar between two dates.
|
* Gets the events in the Sonarr calendar between two dates.
|
||||||
* @param start The start date
|
* @param start The start date
|
||||||
@@ -33,9 +39,7 @@ export class SonarrIntegration extends Integration implements ICalendarIntegrati
|
|||||||
});
|
});
|
||||||
|
|
||||||
const response = await fetchWithTrustedCertificatesAsync(url, {
|
const response = await fetchWithTrustedCertificatesAsync(url, {
|
||||||
headers: {
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
"X-Api-Key": super.getSecretValue("apiKey"),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
const sonarrCalendarEvents = await z.array(sonarrCalendarEventSchema).parseAsync(await response.json());
|
const sonarrCalendarEvents = await z.array(sonarrCalendarEventSchema).parseAsync(await response.json());
|
||||||
|
|
||||||
@@ -119,7 +123,7 @@ export class SonarrIntegration extends Integration implements ICalendarIntegrati
|
|||||||
});
|
});
|
||||||
|
|
||||||
const response = await fetchWithTrustedCertificatesAsync(url, {
|
const response = await fetchWithTrustedCertificatesAsync(url, {
|
||||||
headers: { "X-Api-Key": super.getSecretValue("apiKey") },
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
});
|
});
|
||||||
const data = await z
|
const data = await z
|
||||||
.object({
|
.object({
|
||||||
@@ -157,7 +161,7 @@ export class SonarrIntegration extends Integration implements ICalendarIntegrati
|
|||||||
});
|
});
|
||||||
|
|
||||||
const response = await fetchWithTrustedCertificatesAsync(url, {
|
const response = await fetchWithTrustedCertificatesAsync(url, {
|
||||||
headers: { "X-Api-Key": super.getSecretValue("apiKey") },
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
});
|
});
|
||||||
const data = await z
|
const data = await z
|
||||||
.object({
|
.object({
|
||||||
@@ -193,7 +197,7 @@ export class SonarrIntegration extends Integration implements ICalendarIntegrati
|
|||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const response = await input.fetchAsync(this.url("/api"), {
|
const response = await input.fetchAsync(this.url("/api"), {
|
||||||
headers: { "X-Api-Key": super.getSecretValue("apiKey") },
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) return TestConnectionError.StatusResult(response);
|
if (!response.ok) return TestConnectionError.StatusResult(response);
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
|
import { apiKeyAuth } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -9,12 +11,17 @@ import type { TdarrQueue, TdarrStatistics, TdarrWorker } from "../interfaces/med
|
|||||||
import { getNodesResponseSchema, getStatisticsSchema, getStatusTableSchema } from "./tdarr-validation-schemas";
|
import { getNodesResponseSchema, getStatisticsSchema, getStatusTableSchema } from "./tdarr-validation-schemas";
|
||||||
|
|
||||||
export class TdarrIntegration extends Integration implements IMediaTranscodingIntegration {
|
export class TdarrIntegration extends Integration implements IMediaTranscodingIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
if (!this.hasSecretValue("apiKey") || !this.getSecretValue("apiKey")) return {};
|
||||||
|
return apiKeyAuth(this.integration);
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const response = await input.fetchAsync(this.url("/api/v2/is-server-alive"), {
|
const response = await input.fetchAsync(this.url("/api/v2/is-server-alive"), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
accept: "application/json",
|
accept: "application/json",
|
||||||
"X-Api-Key": super.hasSecretValue("apiKey") ? super.getSecretValue("apiKey") : "",
|
...(await this.getHttpAuthenticationAsync()).headers,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -30,7 +37,7 @@ export class TdarrIntegration extends Integration implements IMediaTranscodingIn
|
|||||||
const headerParams = {
|
const headerParams = {
|
||||||
accept: "application/json",
|
accept: "application/json",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
...(super.hasSecretValue("apiKey") ? { "X-Api-Key": super.getSecretValue("apiKey") } : {}),
|
...(await this.getHttpAuthenticationAsync()).headers,
|
||||||
};
|
};
|
||||||
|
|
||||||
const response = await fetchWithTrustedCertificatesAsync(url, {
|
const response = await fetchWithTrustedCertificatesAsync(url, {
|
||||||
@@ -76,7 +83,7 @@ export class TdarrIntegration extends Integration implements IMediaTranscodingIn
|
|||||||
const url = this.url("/api/v2/get-nodes");
|
const url = this.url("/api/v2/get-nodes");
|
||||||
const headerParams = {
|
const headerParams = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
...(super.hasSecretValue("apiKey") ? { "X-Api-Key": super.getSecretValue("apiKey") } : {}),
|
...(await this.getHttpAuthenticationAsync()).headers,
|
||||||
};
|
};
|
||||||
const response = await fetchWithTrustedCertificatesAsync(url, {
|
const response = await fetchWithTrustedCertificatesAsync(url, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
@@ -120,7 +127,7 @@ export class TdarrIntegration extends Integration implements IMediaTranscodingIn
|
|||||||
const url = this.url("/api/v2/client/status-tables");
|
const url = this.url("/api/v2/client/status-tables");
|
||||||
const headerParams = {
|
const headerParams = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
...(super.hasSecretValue("apiKey") ? { "X-Api-Key": super.getSecretValue("apiKey") } : {}),
|
...(await this.getHttpAuthenticationAsync()).headers,
|
||||||
};
|
};
|
||||||
const response = await fetchWithTrustedCertificatesAsync(url, {
|
const response = await fetchWithTrustedCertificatesAsync(url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@@ -159,7 +166,7 @@ export class TdarrIntegration extends Integration implements IMediaTranscodingIn
|
|||||||
const url = this.url("/api/v2/client/status-tables");
|
const url = this.url("/api/v2/client/status-tables");
|
||||||
const headerParams = {
|
const headerParams = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
...(super.hasSecretValue("apiKey") ? { "X-Api-Key": super.getSecretValue("apiKey") } : {}),
|
...(await this.getHttpAuthenticationAsync()).headers,
|
||||||
};
|
};
|
||||||
const response = await fetchWithTrustedCertificatesAsync(url, {
|
const response = await fetchWithTrustedCertificatesAsync(url, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import type { TestingResult } from "../base/test-connection/test-connection-service";
|
import type { TestingResult } from "../base/test-connection/test-connection-service";
|
||||||
@@ -52,6 +53,10 @@ export class MockIntegration
|
|||||||
ISmartHomeIntegration,
|
ISmartHomeIntegration,
|
||||||
IUpsSummaryIntegration
|
IUpsSummaryIntegration
|
||||||
{
|
{
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
throw new Error("This integration does not use HTTP");
|
||||||
|
}
|
||||||
|
|
||||||
private static readonly dnsHole = new DnsHoleMockService();
|
private static readonly dnsHole = new DnsHoleMockService();
|
||||||
private static readonly calendar = new CalendarMockService();
|
private static readonly calendar = new CalendarMockService();
|
||||||
private static readonly downloadClient = new DownloadClientMockService();
|
private static readonly downloadClient = new DownloadClientMockService();
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import { ResponseError } from "@homarr/common/server";
|
|||||||
import { createHttpsAgentAsync, fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { createHttpsAgentAsync, fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
|
import { basicAuth } from "../http-auth";
|
||||||
import { HandleIntegrationErrors } from "../base/errors/decorator";
|
import { HandleIntegrationErrors } from "../base/errors/decorator";
|
||||||
import { integrationTsdavHttpErrorHandler } from "../base/errors/http";
|
import { integrationTsdavHttpErrorHandler } from "../base/errors/http";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
@@ -57,6 +59,10 @@ dayjs.extend(timezone);
|
|||||||
|
|
||||||
@HandleIntegrationErrors([integrationTsdavHttpErrorHandler])
|
@HandleIntegrationErrors([integrationTsdavHttpErrorHandler])
|
||||||
export class NextcloudIntegration extends Integration implements ICalendarIntegration, INotificationsIntegration {
|
export class NextcloudIntegration extends Integration implements ICalendarIntegration, INotificationsIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return basicAuth("username", "password", { "OCS-APIRequest": "true" })(this.integration);
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const client = await this.createCalendarClientAsync(await createHttpsAgentAsync(input.options));
|
const client = await this.createCalendarClientAsync(await createHttpsAgentAsync(input.options));
|
||||||
await client.login();
|
await client.login();
|
||||||
@@ -168,12 +174,7 @@ export class NextcloudIntegration extends Integration implements ICalendarIntegr
|
|||||||
public async getNotificationsAsync(): Promise<Notification[]> {
|
public async getNotificationsAsync(): Promise<Notification[]> {
|
||||||
const url = this.url("/ocs/v2.php/apps/notifications/api/v2/notifications", { format: "json" });
|
const url = this.url("/ocs/v2.php/apps/notifications/api/v2/notifications", { format: "json" });
|
||||||
const response = await fetchWithTrustedCertificatesAsync(url, {
|
const response = await fetchWithTrustedCertificatesAsync(url, {
|
||||||
headers: {
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
Authorization: `Basic ${Buffer.from(
|
|
||||||
`${this.getSecretValue("username")}:${this.getSecretValue("password")}`,
|
|
||||||
).toString("base64")}`,
|
|
||||||
"OCS-APIRequest": "true",
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) throw new ResponseError(response);
|
if (!response.ok) throw new ResponseError(response);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ResponseError } from "@homarr/common/server";
|
import { ResponseError } from "@homarr/common/server";
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import type { TestingResult } from "../base/test-connection/test-connection-service";
|
import type { TestingResult } from "../base/test-connection/test-connection-service";
|
||||||
@@ -9,6 +10,10 @@ import type { INotificationsIntegration } from "../interfaces/notifications/noti
|
|||||||
import { ntfyNotificationSchema } from "./ntfy-schema";
|
import { ntfyNotificationSchema } from "./ntfy-schema";
|
||||||
|
|
||||||
export class NTFYIntegration extends Integration implements INotificationsIntegration {
|
export class NTFYIntegration extends Integration implements INotificationsIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return { headers: this.getHeaders() };
|
||||||
|
}
|
||||||
|
|
||||||
public async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
public async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
await input.fetchAsync(this.url("/v1/account"), { headers: this.getHeaders() });
|
await input.fetchAsync(this.url("/v1/account"), { headers: this.getHeaders() });
|
||||||
return { success: true };
|
return { success: true };
|
||||||
@@ -17,7 +22,7 @@ export class NTFYIntegration extends Integration implements INotificationsIntegr
|
|||||||
private getTopicURL() {
|
private getTopicURL() {
|
||||||
return this.url(`/${encodeURIComponent(super.getSecretValue("topic"))}/json`, { poll: 1 });
|
return this.url(`/${encodeURIComponent(super.getSecretValue("topic"))}/json`, { poll: 1 });
|
||||||
}
|
}
|
||||||
private getHeaders() {
|
private getHeaders(): Record<string, string> {
|
||||||
return this.hasSecretValue("apiKey") ? { Authorization: `Bearer ${super.getSecretValue("apiKey")}` } : {};
|
return this.hasSecretValue("apiKey") ? { Authorization: `Bearer ${super.getSecretValue("apiKey")}` } : {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ParseError, ResponseError } from "@homarr/common/server";
|
import { ParseError, ResponseError } from "@homarr/common/server";
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import { createChannelEventHistoryOld } from "../../../redis/src/lib/channel";
|
import { createChannelEventHistoryOld } from "../../../redis/src/lib/channel";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
@@ -22,6 +23,10 @@ import {
|
|||||||
} from "./opnsense-types";
|
} from "./opnsense-types";
|
||||||
|
|
||||||
export class OPNsenseIntegration extends Integration implements FirewallSummaryIntegration {
|
export class OPNsenseIntegration extends Integration implements FirewallSummaryIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return { headers: { Authorization: this.getAuthHeaders() } };
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const response = await input.fetchAsync(this.url("/api/diagnostics/system/system_information"), {
|
const response = await input.fetchAsync(this.url("/api/diagnostics/system/system_information"), {
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { ResponseError } from "@homarr/common/server";
|
|||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
|
import { apiKeyAuth } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import type { ISearchableIntegration } from "../base/searchable-integration";
|
import type { ISearchableIntegration } from "../base/searchable-integration";
|
||||||
@@ -40,11 +42,13 @@ export class OverseerrIntegration
|
|||||||
extends Integration
|
extends Integration
|
||||||
implements IMediaRequestIntegration, ISearchableIntegration<OverseerrSearchResult>
|
implements IMediaRequestIntegration, ISearchableIntegration<OverseerrSearchResult>
|
||||||
{
|
{
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return apiKeyAuth(this.integration);
|
||||||
|
}
|
||||||
|
|
||||||
public async searchAsync(query: string) {
|
public async searchAsync(query: string) {
|
||||||
const response = await fetchWithTrustedCertificatesAsync(this.url("/api/v1/search", { query }), {
|
const response = await fetchWithTrustedCertificatesAsync(this.url("/api/v1/search", { query }), {
|
||||||
headers: {
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
"X-Api-Key": this.getSecretValue("apiKey"),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
const schemaData = await searchSchema.parseAsync(await response.json());
|
const schemaData = await searchSchema.parseAsync(await response.json());
|
||||||
|
|
||||||
@@ -69,9 +73,7 @@ export class OverseerrIntegration
|
|||||||
public async getSeriesInformationAsync(mediaType: "movie" | "tv", id: number) {
|
public async getSeriesInformationAsync(mediaType: "movie" | "tv", id: number) {
|
||||||
const url = mediaType === "tv" ? this.url(`/api/v1/tv/${id}`) : this.url(`/api/v1/movie/${id}`);
|
const url = mediaType === "tv" ? this.url(`/api/v1/tv/${id}`) : this.url(`/api/v1/movie/${id}`);
|
||||||
const response = await fetchWithTrustedCertificatesAsync(url, {
|
const response = await fetchWithTrustedCertificatesAsync(url, {
|
||||||
headers: {
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
"X-Api-Key": this.getSecretValue("apiKey"),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
const data = await mediaInformationSchema.parseAsync(await response.json());
|
const data = await mediaInformationSchema.parseAsync(await response.json());
|
||||||
const requestedSeasons = [
|
const requestedSeasons = [
|
||||||
@@ -110,9 +112,7 @@ export class OverseerrIntegration
|
|||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const response = await input.fetchAsync(this.url("/api/v1/auth/me"), {
|
const response = await input.fetchAsync(this.url("/api/v1/auth/me"), {
|
||||||
headers: {
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
"X-Api-Key": this.getSecretValue("apiKey"),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) return TestConnectionError.StatusResult(response);
|
if (!response.ok) return TestConnectionError.StatusResult(response);
|
||||||
@@ -126,18 +126,14 @@ export class OverseerrIntegration
|
|||||||
const pendingRequests = await fetchWithTrustedCertificatesAsync(
|
const pendingRequests = await fetchWithTrustedCertificatesAsync(
|
||||||
this.url("/api/v1/request", { take: 20, filter: "pending" }),
|
this.url("/api/v1/request", { take: 20, filter: "pending" }),
|
||||||
{
|
{
|
||||||
headers: {
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
"X-Api-Key": this.getSecretValue("apiKey"),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const allRequests = await fetchWithTrustedCertificatesAsync(
|
const allRequests = await fetchWithTrustedCertificatesAsync(
|
||||||
this.url("/api/v1/request", { take: 20, sort: "modified" }),
|
this.url("/api/v1/request", { take: 20, sort: "modified" }),
|
||||||
{
|
{
|
||||||
headers: {
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
"X-Api-Key": this.getSecretValue("apiKey"),
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -234,18 +230,14 @@ export class OverseerrIntegration
|
|||||||
|
|
||||||
public async getStatsAsync(): Promise<RequestStats> {
|
public async getStatsAsync(): Promise<RequestStats> {
|
||||||
const response = await fetchWithTrustedCertificatesAsync(this.url("/api/v1/request/count"), {
|
const response = await fetchWithTrustedCertificatesAsync(this.url("/api/v1/request/count"), {
|
||||||
headers: {
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
"X-Api-Key": this.getSecretValue("apiKey"),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
return await getStatsSchema.parseAsync(await response.json());
|
return await getStatsSchema.parseAsync(await response.json());
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getUsersAsync(): Promise<RequestUser[]> {
|
public async getUsersAsync(): Promise<RequestUser[]> {
|
||||||
const response = await fetchWithTrustedCertificatesAsync(this.url("/api/v1/user", { take: 10, sort: "requests" }), {
|
const response = await fetchWithTrustedCertificatesAsync(this.url("/api/v1/user", { take: 10, sort: "requests" }), {
|
||||||
headers: {
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
"X-Api-Key": this.getSecretValue("apiKey"),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
const users = (await getUsersSchema.parseAsync(await response.json())).results;
|
const users = (await getUsersSchema.parseAsync(await response.json())).results;
|
||||||
return users.map((user): RequestUser => {
|
return users.map((user): RequestUser => {
|
||||||
@@ -261,9 +253,7 @@ export class OverseerrIntegration
|
|||||||
logger.info("Approving media request", { requestId, integration: this.integration.name });
|
logger.info("Approving media request", { requestId, integration: this.integration.name });
|
||||||
const response = await fetchWithTrustedCertificatesAsync(this.url(`/api/v1/request/${requestId}/approve`), {
|
const response = await fetchWithTrustedCertificatesAsync(this.url(`/api/v1/request/${requestId}/approve`), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
"X-Api-Key": this.getSecretValue("apiKey"),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
if (!response.ok) throw new ResponseError(response);
|
if (!response.ok) throw new ResponseError(response);
|
||||||
logger.info("Successfully approved media request", { requestId, integration: this.integration.name });
|
logger.info("Successfully approved media request", { requestId, integration: this.integration.name });
|
||||||
@@ -274,9 +264,7 @@ export class OverseerrIntegration
|
|||||||
|
|
||||||
const response = await fetchWithTrustedCertificatesAsync(this.url(`/api/v1/request/${requestId}/decline`), {
|
const response = await fetchWithTrustedCertificatesAsync(this.url(`/api/v1/request/${requestId}/decline`), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
"X-Api-Key": this.getSecretValue("apiKey"),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
if (!response.ok) throw new ResponseError(response);
|
if (!response.ok) throw new ResponseError(response);
|
||||||
logger.info("Successfully declined media request", { requestId, integration: this.integration.name });
|
logger.info("Successfully declined media request", { requestId, integration: this.integration.name });
|
||||||
@@ -284,9 +272,7 @@ export class OverseerrIntegration
|
|||||||
|
|
||||||
private async getItemInformationAsync(id: number, type: MediaRequest["type"]): Promise<MediaInformation> {
|
private async getItemInformationAsync(id: number, type: MediaRequest["type"]): Promise<MediaInformation> {
|
||||||
const response = await fetchWithTrustedCertificatesAsync(this.url(`/api/v1/${type}/${id}`), {
|
const response = await fetchWithTrustedCertificatesAsync(this.url(`/api/v1/${type}/${id}`), {
|
||||||
headers: {
|
headers: (await this.getHttpAuthenticationAsync()).headers,
|
||||||
"X-Api-Key": this.getSecretValue("apiKey"),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ResponseError } from "@homarr/common/server";
|
import { ResponseError } from "@homarr/common/server";
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -9,6 +10,10 @@ import type { PaperlessNgxStats } from "./paperless-ngx-types";
|
|||||||
import { paperlessNgxPaginatedCountSchema, paperlessNgxStatisticsSchema } from "./paperless-ngx-types";
|
import { paperlessNgxPaginatedCountSchema, paperlessNgxStatisticsSchema } from "./paperless-ngx-types";
|
||||||
|
|
||||||
export class PaperlessNgxIntegration extends Integration {
|
export class PaperlessNgxIntegration extends Integration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return { headers: this.getAuthHeaders() };
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const statisticsUrl = this.url("/api/statistics/");
|
const statisticsUrl = this.url("/api/statistics/");
|
||||||
const statisticsResponse = await input.fetchAsync(statisticsUrl, {
|
const statisticsResponse = await input.fetchAsync(statisticsUrl, {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ParseError, ResponseError } from "@homarr/common/server";
|
import { ParseError, ResponseError } from "@homarr/common/server";
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -11,6 +12,10 @@ import { mapPatchMonStats, parsePatchMonStatsResponseAsync } from "./patchmon-ty
|
|||||||
const STATS_REQUEST_TIMEOUT_MS = 10_000;
|
const STATS_REQUEST_TIMEOUT_MS = 10_000;
|
||||||
|
|
||||||
export class PatchMonIntegration extends Integration {
|
export class PatchMonIntegration extends Integration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return { headers: this.getAuthHeaders() };
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const response = await input.fetchAsync(this.url("/api/v1/gethomepage/stats"), {
|
const response = await input.fetchAsync(this.url("/api/v1/gethomepage/stats"), {
|
||||||
headers: this.getAuthHeaders(),
|
headers: this.getAuthHeaders(),
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ResponseError } from "@homarr/common/server";
|
import { ResponseError } from "@homarr/common/server";
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -11,6 +12,10 @@ import type { PeaNutDevice } from "./peanut-types";
|
|||||||
import { peaNutDevicesSchema } from "./peanut-types";
|
import { peaNutDevicesSchema } from "./peanut-types";
|
||||||
|
|
||||||
export class PeaNutIntegration extends Integration implements IUpsSummaryIntegration {
|
export class PeaNutIntegration extends Integration implements IUpsSummaryIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return { headers: this.getAuthHeaders() };
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const response = await input.fetchAsync(this.url("/api/v1/devices"), {
|
const response = await input.fetchAsync(this.url("/api/v1/devices"), {
|
||||||
headers: this.getAuthHeaders(),
|
headers: this.getAuthHeaders(),
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/h
|
|||||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||||
import { ImageProxy } from "@homarr/image-proxy";
|
import { ImageProxy } from "@homarr/image-proxy";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
|
import { headerAuth } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -50,6 +52,10 @@ function isStreamDirect(decision: string | undefined): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class PlexIntegration extends Integration implements IMediaServerIntegration, IMediaReleasesIntegration {
|
export class PlexIntegration extends Integration implements IMediaServerIntegration, IMediaReleasesIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return headerAuth("X-Plex-Token")(this.integration);
|
||||||
|
}
|
||||||
|
|
||||||
public async getCurrentSessionsAsync(_options: CurrentSessionsInput): Promise<StreamSession[]> {
|
public async getCurrentSessionsAsync(_options: CurrentSessionsInput): Promise<StreamSession[]> {
|
||||||
const token = super.getSecretValue("apiKey");
|
const token = super.getSecretValue("apiKey");
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import { z } from "zod/v4";
|
|||||||
|
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
|
import { apiKeyAuth } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -11,6 +13,10 @@ import type { Indexer } from "../interfaces/indexer-manager/indexer-manager-type
|
|||||||
import { indexerResponseSchema, statusResponseSchema } from "./prowlarr-types";
|
import { indexerResponseSchema, statusResponseSchema } from "./prowlarr-types";
|
||||||
|
|
||||||
export class ProwlarrIntegration extends Integration implements IIndexerManagerIntegration {
|
export class ProwlarrIntegration extends Integration implements IIndexerManagerIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return apiKeyAuth(this.integration);
|
||||||
|
}
|
||||||
|
|
||||||
public async getIndexersAsync(): Promise<Indexer[]> {
|
public async getIndexersAsync(): Promise<Indexer[]> {
|
||||||
const apiKey = super.getSecretValue("apiKey");
|
const apiKey = super.getSecretValue("apiKey");
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import proxmoxApi from "proxmox-api";
|
|||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import { HandleIntegrationErrors } from "../base/errors/decorator";
|
import { HandleIntegrationErrors } from "../base/errors/decorator";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
@@ -23,6 +24,14 @@ const logger = createLogger({ module: "proxmoxIntegration" });
|
|||||||
|
|
||||||
@HandleIntegrationErrors([new ProxmoxApiErrorHandler()])
|
@HandleIntegrationErrors([new ProxmoxApiErrorHandler()])
|
||||||
export class ProxmoxIntegration extends Integration implements IClusterHealthMonitoringIntegration {
|
export class ProxmoxIntegration extends Integration implements IClusterHealthMonitoringIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return {
|
||||||
|
headers: {
|
||||||
|
Authorization: `PVEAPIToken=${this.getSecretValue("username")}@${this.getSecretValue("realm")}!${this.getSecretValue("tokenId")}=${this.getSecretValue("apiKey")}`,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const proxmox = this.getPromoxApi(input.fetchAsync);
|
const proxmox = this.getPromoxApi(input.fetchAsync);
|
||||||
await proxmox.nodes.$get();
|
await proxmox.nodes.$get();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ResponseError } from "@homarr/common/server";
|
import { ResponseError } from "@homarr/common/server";
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -18,6 +19,10 @@ import type {
|
|||||||
} from "./speedtest-tracker-types";
|
} from "./speedtest-tracker-types";
|
||||||
|
|
||||||
export class SpeedtestTrackerIntegration extends Integration {
|
export class SpeedtestTrackerIntegration extends Integration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return { headers: this.getAuthHeaders(), redactValues: [] };
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const url = this.url("/api/v1/results/latest");
|
const url = this.url("/api/v1/results/latest");
|
||||||
const response = await input.fetchAsync(url, {
|
const response = await input.fetchAsync(url, {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { ResponseError } from "@homarr/common/server";
|
|||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
import { ImageProxy } from "@homarr/image-proxy";
|
import { ImageProxy } from "@homarr/image-proxy";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import type { TestingResult } from "../base/test-connection/test-connection-service";
|
import type { TestingResult } from "../base/test-connection/test-connection-service";
|
||||||
@@ -17,6 +18,10 @@ import type {
|
|||||||
} from "./tracearr-types";
|
} from "./tracearr-types";
|
||||||
|
|
||||||
export class TracearrIntegration extends Integration {
|
export class TracearrIntegration extends Integration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return { headers: this.getAuthHeaders() };
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const healthUrl = this.url("/api/v1/public/health");
|
const healthUrl = this.url("/api/v1/public/health");
|
||||||
const healthResponse = await input.fetchAsync(healthUrl, {
|
const healthResponse = await input.fetchAsync(healthUrl, {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import z from "zod";
|
|||||||
|
|
||||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import type { TestingResult } from "../base/test-connection/test-connection-service";
|
import type { TestingResult } from "../base/test-connection/test-connection-service";
|
||||||
@@ -32,6 +33,10 @@ const describeRequestError = (error: unknown) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export class TrueNasIntegration extends Integration implements ISystemHealthMonitoringIntegration {
|
export class TrueNasIntegration extends Integration implements ISystemHealthMonitoringIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
throw new Error("This integration does not use HTTP");
|
||||||
|
}
|
||||||
|
|
||||||
private client?: TrueNasClient;
|
private client?: TrueNasClient;
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ import { ResponseError } from "@homarr/common/server";
|
|||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
import { createLogger } from "@homarr/core/infrastructure/logs";
|
import { createLogger } from "@homarr/core/infrastructure/logs";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
|
import { apiKeyAuth } from "../http-auth";
|
||||||
import { HandleIntegrationErrors } from "../base/errors/decorator";
|
import { HandleIntegrationErrors } from "../base/errors/decorator";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
@@ -18,6 +20,10 @@ const logger = createLogger({ module: "UnraidIntegration" });
|
|||||||
|
|
||||||
@HandleIntegrationErrors([])
|
@HandleIntegrationErrors([])
|
||||||
export class UnraidIntegration extends Integration implements ISystemHealthMonitoringIntegration {
|
export class UnraidIntegration extends Integration implements ISystemHealthMonitoringIntegration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return apiKeyAuth(this.integration);
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
await this.queryGraphQLAsync<{ info: UnraidSystemInfo }>(
|
await this.queryGraphQLAsync<{ info: UnraidSystemInfo }>(
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { ParseError, ResponseError } from "@homarr/common/server";
|
import { ParseError, ResponseError } from "@homarr/common/server";
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -13,6 +14,10 @@ import {
|
|||||||
import type { UptimeKumaDashboardData, UptimeKumaMonitor, UptimeKumaMonitorCategory } from "./uptime-kuma-types";
|
import type { UptimeKumaDashboardData, UptimeKumaMonitor, UptimeKumaMonitorCategory } from "./uptime-kuma-types";
|
||||||
|
|
||||||
export class UptimeKumaIntegration extends Integration {
|
export class UptimeKumaIntegration extends Integration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const statusPageResponse = await input.fetchAsync(this.statusPageUrl());
|
const statusPageResponse = await input.fetchAsync(this.statusPageUrl());
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Buffer } from "node:buffer";
|
|||||||
import { ParseError, ResponseError } from "@homarr/common/server";
|
import { ParseError, ResponseError } from "@homarr/common/server";
|
||||||
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
import { fetchWithTrustedCertificatesAsync } from "@homarr/core/infrastructure/http";
|
||||||
|
|
||||||
|
import type { IntegrationHttpAuthentication } from "../http-auth";
|
||||||
import type { IntegrationTestingInput } from "../base/integration";
|
import type { IntegrationTestingInput } from "../base/integration";
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
import { TestConnectionError } from "../base/test-connection/test-connection-error";
|
||||||
@@ -13,6 +14,10 @@ import { mapWudStats, parseWudContainersResponseAsync } from "./wud-types";
|
|||||||
const CONTAINERS_REQUEST_TIMEOUT_MS = 10_000;
|
const CONTAINERS_REQUEST_TIMEOUT_MS = 10_000;
|
||||||
|
|
||||||
export class WudIntegration extends Integration {
|
export class WudIntegration extends Integration {
|
||||||
|
public async getHttpAuthenticationAsync(): Promise<IntegrationHttpAuthentication> {
|
||||||
|
return { headers: this.getAuthHeaders() };
|
||||||
|
}
|
||||||
|
|
||||||
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
protected async testingAsync(input: IntegrationTestingInput): Promise<TestingResult> {
|
||||||
const response = await input.fetchAsync(this.url("/api/containers"), {
|
const response = await input.fetchAsync(this.url("/api/containers"), {
|
||||||
headers: this.getAuthHeaders(),
|
headers: this.getAuthHeaders(),
|
||||||
|
|||||||
@@ -45,6 +45,9 @@ describe("Base integration", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
class FakeIntegration extends Integration {
|
class FakeIntegration extends Integration {
|
||||||
|
public async getHttpAuthenticationAsync() {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
constructor(
|
constructor(
|
||||||
private testingResult?: TestingResult,
|
private testingResult?: TestingResult,
|
||||||
private error?: Error,
|
private error?: Error,
|
||||||
|
|||||||
Reference in new issue
Block a user