feat: add auth extension points and one ssh connect pipeline

This commit is contained in:
LukeGus committed 2026-09-23 00:44:33 -05:00
1 parent d3c209af13
commit d774df8b41
159 files changed
+43243 -7451

No files matched your search

+3
View File
@@ -1,7 +1,10 @@
import type { PluginContext } from "@termix/plugin-sdk/backend";
import { setPluginSsh } from "./ssh.js";
import { startFleetsService, stopFleetsService } from "./routes.js";
export async function activate(ctx: PluginContext) {
setPluginSsh(ctx.ssh);
ctx.disposables.add(() => setPluginSsh(null));
startFleetsService(ctx.http.router());
ctx.log.info("Fleets routes mounted at /plugin-api/fleets");
}
+16 -20
View File
@@ -26,11 +26,7 @@ import {
createCurrentUserRepository,
} from "../../../../src/backend/database/repositories/factory.js";
import { resolveHostById } from "../../../../src/backend/hosts/host-resolver.js";
import {
getFleetPoolKey,
createFleetSshFactory,
} from "../../../../src/backend/hosts/ssh-client-factory.js";
import { withConnection } from "../../../../src/backend/hosts/ssh-connection-pool.js";
import { withSshConnection } from "./ssh.js";
import { execCommand } from "../../../../src/backend/hosts/metrics-shared/common-utils.js";
import { detectPlatform } from "../../../../src/backend/hosts/metrics-shared/platform.js";
import {
@@ -915,9 +911,9 @@ router.post(
inputValues && typeof inputValues === "object" ? inputValues : {},
);
const { stdout, stderr, code } = await withConnection(
getFleetPoolKey(fullHost),
createFleetSshFactory(fullHost),
const { stdout, stderr, code } = await withSshConnection(
fullHost as never,
{ pool: "fleet", purpose: "fleet" },
(client) => execCommand(client, resolvedCommand, 60000),
);
@@ -1017,9 +1013,9 @@ router.post(
return { success: false, error: "Host not found" };
}
await withConnection(
getFleetPoolKey(fullHost),
createFleetSshFactory(fullHost),
await withSshConnection(
fullHost as never,
{ pool: "fleet", purpose: "fleet" },
async (client) => {
const sftp = await getSftp(client);
await sftpWriteFile(sftp, remotePath, file.buffer);
@@ -1112,9 +1108,9 @@ router.post(
return { success: false, error: "Host not found" };
}
const data = await withConnection(
getFleetPoolKey(fullHost),
createFleetSshFactory(fullHost),
const data = await withSshConnection(
fullHost as never,
{ pool: "fleet", purpose: "fleet" },
async (client) => {
const sftp = await getSftp(client);
return sftpReadFile(sftp, remotePath);
@@ -1305,9 +1301,9 @@ router.post(
return { success: false, error: "Host not found" };
}
const record = await withConnection(
getFleetPoolKey(fullHost),
createFleetSshFactory(fullHost),
const record = await withSshConnection(
fullHost as never,
{ pool: "fleet", purpose: "fleet" },
async (client) => {
const platform = await detectPlatform(client);
const { stdout } = await execCommand(
@@ -1418,9 +1414,9 @@ router.post(
return { success: false, error: "Host not found" };
}
return withConnection(
getFleetPoolKey(fullHost),
createFleetSshFactory(fullHost),
return withSshConnection(
fullHost as never,
{ pool: "fleet", purpose: "fleet" },
async (client) => {
const platform = await detectPlatform(client);
// "remove" has no PackageAction counterpart in buildPackageActionCommand
+36
View File
@@ -0,0 +1,36 @@
import type { Client } from "ssh2";
import type {
PluginSsh,
PluginSshConnection,
PluginSshConnectOptions,
PluginSshHost,
} from "@termix/plugin-sdk/backend";
let current: PluginSsh | null = null;
/** Set in activate, cleared on deactivate. */
export function setPluginSsh(ssh: PluginSsh | null): void {
current = ssh;
}
export function pluginSsh(): PluginSsh {
if (!current) throw new Error("The plugin is not active");
return current;
}
/** withConnection with ssh2's Client type filled in. */
export function withSshConnection<T>(
host: number | PluginSshHost,
options: PluginSshConnectOptions & { pool: string },
fn: (client: Client) => Promise<T>,
): Promise<T> {
return pluginSsh().withConnection<T, Client>(host, options, fn);
}
/** connect with ssh2's Client type filled in. */
export function connectSsh(
host: number | PluginSshHost,
options?: PluginSshConnectOptions,
): Promise<PluginSshConnection<Client>> {
return pluginSsh().connect<Client>(host, options);
}