fix(nextcloud): issue with self signed certificates (#2760)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import fsSync from "node:fs";
|
import fsSync from "node:fs";
|
||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import { Agent } from "node:https";
|
import { Agent as HttpsAgent } from "node:https";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { rootCertificates } from "node:tls";
|
import { rootCertificates } from "node:tls";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
@@ -70,12 +70,16 @@ export const createCertificateAgentAsync = async () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createAxiosCertificateInstanceAsync = async () => {
|
export const createHttpsAgentAsync = async () => {
|
||||||
const customCertificates = await loadCustomRootCertificatesAsync();
|
const customCertificates = await loadCustomRootCertificatesAsync();
|
||||||
|
return new HttpsAgent({
|
||||||
|
ca: rootCertificates.concat(customCertificates.map((cert) => cert.content)),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createAxiosCertificateInstanceAsync = async () => {
|
||||||
return axios.create({
|
return axios.create({
|
||||||
httpsAgent: new Agent({
|
httpsAgent: await createHttpsAgentAsync(),
|
||||||
ca: rootCertificates.concat(customCertificates.map((cert) => cert.content)),
|
|
||||||
}),
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ import objectSupport from "dayjs/plugin/objectSupport";
|
|||||||
import utc from "dayjs/plugin/utc";
|
import utc from "dayjs/plugin/utc";
|
||||||
import * as ical from "node-ical";
|
import * as ical from "node-ical";
|
||||||
import { DAVClient } from "tsdav";
|
import { DAVClient } from "tsdav";
|
||||||
|
import type { RequestInit as UndiciFetchRequestInit } from "undici";
|
||||||
|
|
||||||
|
import { createCertificateAgentAsync } from "@homarr/certificates/server";
|
||||||
import { logger } from "@homarr/log";
|
import { logger } from "@homarr/log";
|
||||||
|
|
||||||
import { Integration } from "../base/integration";
|
import { Integration } from "../base/integration";
|
||||||
@@ -14,12 +16,12 @@ dayjs.extend(objectSupport);
|
|||||||
|
|
||||||
export class NextcloudIntegration extends Integration {
|
export class NextcloudIntegration extends Integration {
|
||||||
public async testConnectionAsync(): Promise<void> {
|
public async testConnectionAsync(): Promise<void> {
|
||||||
const client = this.createCalendarClient();
|
const client = await this.createCalendarClientAsync();
|
||||||
await client.login();
|
await client.login();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getCalendarEventsAsync(start: Date, end: Date): Promise<CalendarEvent[]> {
|
public async getCalendarEventsAsync(start: Date, end: Date): Promise<CalendarEvent[]> {
|
||||||
const client = this.createCalendarClient();
|
const client = await this.createCalendarClientAsync();
|
||||||
await client.login();
|
await client.login();
|
||||||
|
|
||||||
const calendars = await client.fetchCalendars();
|
const calendars = await client.fetchCalendars();
|
||||||
@@ -83,7 +85,7 @@ export class NextcloudIntegration extends Integration {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private createCalendarClient() {
|
private async createCalendarClientAsync() {
|
||||||
return new DAVClient({
|
return new DAVClient({
|
||||||
serverUrl: this.integration.url,
|
serverUrl: this.integration.url,
|
||||||
credentials: {
|
credentials: {
|
||||||
@@ -92,6 +94,10 @@ export class NextcloudIntegration extends Integration {
|
|||||||
},
|
},
|
||||||
authMethod: "Basic",
|
authMethod: "Basic",
|
||||||
defaultAccountType: "caldav",
|
defaultAccountType: "caldav",
|
||||||
|
fetchOptions: {
|
||||||
|
// We can use the undici options as the global fetch is used instead of the polyfilled.
|
||||||
|
dispatcher: await createCertificateAgentAsync(),
|
||||||
|
} satisfies UndiciFetchRequestInit as RequestInit,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user