Fix Proxmox connection by using undici's fetch instead of Node's global fetch
Node's global fetch is backed by an internal undici version bundled with Node itself, which differs from the 'undici' npm package used for the insecure Agent (needed for Proxmox's self-signed cert). Passing an Agent from one undici version as the dispatcher for the other's fetch trips an internal handler-shape check, producing 'invalid onRequestStart method'. Importing fetch from the same undici package as the Agent keeps both on the same internal interface.
This commit is contained in:
parent
cbd666fe60
commit
da8555d817
1 changed files with 3 additions and 3 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { Agent } from 'undici'
|
import { Agent, fetch } from 'undici'
|
||||||
import type { IntegrationAdapter, Resource } from './types.js'
|
import type { IntegrationAdapter, Resource } from './types.js'
|
||||||
|
|
||||||
interface ProxmoxResourceEntry {
|
interface ProxmoxResourceEntry {
|
||||||
|
|
@ -37,7 +37,7 @@ export const proxmox: IntegrationAdapter = {
|
||||||
const res = await fetch(`${baseUrl}/api2/json/version`, {
|
const res = await fetch(`${baseUrl}/api2/json/version`, {
|
||||||
headers: authHeader(apiKey),
|
headers: authHeader(apiKey),
|
||||||
dispatcher: insecureDispatcher,
|
dispatcher: insecureDispatcher,
|
||||||
} as RequestInit)
|
})
|
||||||
if (!res.ok) return { ok: false, message: `HTTP ${res.status}` }
|
if (!res.ok) return { ok: false, message: `HTTP ${res.status}` }
|
||||||
return { ok: true, message: 'Connected' }
|
return { ok: true, message: 'Connected' }
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -52,7 +52,7 @@ export const proxmox: IntegrationAdapter = {
|
||||||
const res = await fetch(`${baseUrl}/api2/json/cluster/resources?type=vm`, {
|
const res = await fetch(`${baseUrl}/api2/json/cluster/resources?type=vm`, {
|
||||||
headers: authHeader(apiKey),
|
headers: authHeader(apiKey),
|
||||||
dispatcher: insecureDispatcher,
|
dispatcher: insecureDispatcher,
|
||||||
} as RequestInit)
|
})
|
||||||
if (!res.ok) return []
|
if (!res.ok) return []
|
||||||
const body = (await res.json()) as { data: ProxmoxResourceEntry[] }
|
const body = (await res.json()) as { data: ProxmoxResourceEntry[] }
|
||||||
return body.data.map((entry) => ({
|
return body.data.map((entry) => ({
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue