fix(plugin): share kubernetes shell quoting helper
This commit is contained in:
@@ -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 = "";
|
||||
|
||||
Reference in New Issue
Block a user