fix(plugin): share kubernetes shell quoting helper

This commit is contained in:
Dotta
2026-05-13 13:01:39 -05:00
committed by Chris Farhood
parent 58d1b19206
commit 713fb6eb4e
3 changed files with 6 additions and 9 deletions
@@ -32,6 +32,7 @@ import {
SandboxCrTimeoutError, SandboxCrTimeoutError,
} from "./sandbox-cr-orchestrator.js"; } from "./sandbox-cr-orchestrator.js";
import { execInPod } from "./pod-exec.js"; import { execInPod } from "./pod-exec.js";
import { shellQuoteArg } from "./shell-utils.js";
import { import {
deriveCompanySlug, deriveCompanySlug,
deriveNamespaceName, deriveNamespaceName,
@@ -113,10 +114,6 @@ export function extractAdapterEnvFromProcess(
return out; return out;
} }
function shellQuoteArg(arg: string): string {
return "'" + arg.replace(/'/g, "'\\''") + "'";
}
export function buildSandboxExecCommand( export function buildSandboxExecCommand(
params: Pick<PluginEnvironmentExecuteParams, "args" | "command">, params: Pick<PluginEnvironmentExecuteParams, "args" | "command">,
): string[] { ): string[] {
@@ -13,6 +13,7 @@
import { Exec } from "@kubernetes/client-node"; import { Exec } from "@kubernetes/client-node";
import { PassThrough } from "node:stream"; import { PassThrough } from "node:stream";
import type { KubeConfig } from "@kubernetes/client-node"; import type { KubeConfig } from "@kubernetes/client-node";
import { shellQuoteArg } from "./shell-utils.js";
type WebSocketLike = { type WebSocketLike = {
close(): void; close(): void;
@@ -27,10 +28,6 @@ export interface ExecInPodResult {
stderr: string; stderr: string;
} }
function shQuoteArg(arg: string): string {
return "'" + arg.replace(/'/g, "'\\''") + "'";
}
export async function execInPod( export async function execInPod(
kc: KubeConfig, kc: KubeConfig,
namespace: string, namespace: string,
@@ -50,7 +47,7 @@ export async function execInPod(
: null; : null;
const stdinStream: PassThrough | null = stdinPayload ? new PassThrough() : null; const stdinStream: PassThrough | null = stdinPayload ? new PassThrough() : null;
const effectiveCommand = stdinPayload const effectiveCommand = stdinPayload
? ["/bin/sh", "-c", `head -c ${stdinPayload.length} | ${command.map(shQuoteArg).join(" ")}`] ? ["/bin/sh", "-c", `head -c ${stdinPayload.length} | ${command.map(shellQuoteArg).join(" ")}`]
: command; : command;
let stdoutData = ""; let stdoutData = "";
@@ -0,0 +1,3 @@
export function shellQuoteArg(arg: string): string {
return "'" + arg.replace(/'/g, "'\\''") + "'";
}