forked from farhoodlabs/paperclip
fix(plugin): share kubernetes shell quoting helper
This commit is contained in:
@@ -32,6 +32,7 @@ import {
|
||||
SandboxCrTimeoutError,
|
||||
} from "./sandbox-cr-orchestrator.js";
|
||||
import { execInPod } from "./pod-exec.js";
|
||||
import { shellQuoteArg } from "./shell-utils.js";
|
||||
import {
|
||||
deriveCompanySlug,
|
||||
deriveNamespaceName,
|
||||
@@ -113,10 +114,6 @@ export function extractAdapterEnvFromProcess(
|
||||
return out;
|
||||
}
|
||||
|
||||
function shellQuoteArg(arg: string): string {
|
||||
return "'" + arg.replace(/'/g, "'\\''") + "'";
|
||||
}
|
||||
|
||||
export function buildSandboxExecCommand(
|
||||
params: Pick<PluginEnvironmentExecuteParams, "args" | "command">,
|
||||
): string[] {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
import { Exec } from "@kubernetes/client-node";
|
||||
import { PassThrough } from "node:stream";
|
||||
import type { KubeConfig } from "@kubernetes/client-node";
|
||||
import { shellQuoteArg } from "./shell-utils.js";
|
||||
|
||||
type WebSocketLike = {
|
||||
close(): void;
|
||||
@@ -27,10 +28,6 @@ export interface ExecInPodResult {
|
||||
stderr: string;
|
||||
}
|
||||
|
||||
function shQuoteArg(arg: string): string {
|
||||
return "'" + arg.replace(/'/g, "'\\''") + "'";
|
||||
}
|
||||
|
||||
export async function execInPod(
|
||||
kc: KubeConfig,
|
||||
namespace: string,
|
||||
@@ -50,7 +47,7 @@ export async function execInPod(
|
||||
: null;
|
||||
const stdinStream: PassThrough | null = stdinPayload ? new PassThrough() : null;
|
||||
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;
|
||||
|
||||
let stdoutData = "";
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export function shellQuoteArg(arg: string): string {
|
||||
return "'" + arg.replace(/'/g, "'\\''") + "'";
|
||||
}
|
||||
Reference in New Issue
Block a user