Skip to content

Commit

Permalink
SSH: add support for ssh -N
Browse files Browse the repository at this point in the history
  • Loading branch information
GGonryun committed Feb 29, 2024
1 parent 13c78e5 commit ff8881b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
16 changes: 11 additions & 5 deletions src/commands/ssh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import yargs from "yargs";
export type SshCommandArgs = {
destination: string;
command?: string;
L?: string; // port forwarding option
L?: string; // Port forwarding option
N?: boolean; // No remote command
arguments: string[];
reason?: string;
};
Expand Down Expand Up @@ -74,16 +75,21 @@ export const sshCommand = (yargs: yargs.Argv) =>
INVALID_PORT_FORWARD_FORMAT_ERROR_MESSAGE
);
})
// Match `p0 request --reason`
.option("reason", {
describe: "Reason access is needed",
type: "string",
})
.option("L", {
type: "string",
describe:
// the order of the sockets in the address matches the ssh man page
"Forward a local port to the remote host; `local_socket:remote_socket`",
})
// Match `p0 request --reason`
.option("reason", {
describe: "Reason access is needed",
type: "string",
.option("N", {
type: "boolean",
describe:
"Do not execute a remote command. Useful for forwarding ports.",
}),
guard(ssh)
);
Expand Down
17 changes: 12 additions & 5 deletions src/plugins/aws/ssm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type SsmArgs = {
requestId: string;
documentName: string;
command?: string;
noRemoteCommands?: boolean;
forwardPortAddress?: string;
};

Expand Down Expand Up @@ -147,17 +148,22 @@ const createPortForwardingCommand = (args: Omit<SsmArgs, "requestId">) => {
const createSsmCommands = (
args: Omit<SsmArgs, "requestId">
): { command: string[]; subcommand?: string[] } => {
const command = createInteractiveShellCommand(args);
const interactiveShellCommand = createInteractiveShellCommand(args);

if (args.forwardPortAddress) {
if (!args.forwardPortAddress) {
return {
command,
subcommand: createPortForwardingCommand(args),
command: interactiveShellCommand,
};
}

const portForwardingCommand = createPortForwardingCommand(args);
if (args.noRemoteCommands) {
return { command: portForwardingCommand };
}

return {
command,
command: interactiveShellCommand,
subcommand: portForwardingCommand,
};
};

Expand Down Expand Up @@ -368,6 +374,7 @@ export const ssm = async (
region: region!,
documentName: request.generated.documentName,
requestId: request.id,
noRemoteCommands: args.N,
forwardPortAddress: args.L,
command: commandParameter(args),
};
Expand Down

0 comments on commit ff8881b

Please sign in to comment.