diff --git a/src/commands/__tests__/__snapshots__/ssh.test.ts.snap b/src/commands/__tests__/__snapshots__/ssh.test.ts.snap index 92c7b4a..f5c5689 100644 --- a/src/commands/__tests__/__snapshots__/ssh.test.ts.snap +++ b/src/commands/__tests__/__snapshots__/ssh.test.ts.snap @@ -1,5 +1,23 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`ssh ephemeral access should call p0 request with reason arg: args 1`] = ` +{ + "$0": "/Users/nathanbrahms/dev/p0cli/node_modules/.bin/jest", + "_": [ + "ssh", + ], + "arguments": [ + "ssh", + "some-instance", + "--provider", + "aws", + "--reason", + "reason", + ], + "wait": true, +} +`; + exports[`ssh ephemeral access should call ssm: stderr 1`] = ` [ [ @@ -17,6 +35,24 @@ exports[`ssh ephemeral access should call ssm: stderr 1`] = ` ] `; +exports[`ssh persistent access should call p0 request with reason arg: args 1`] = ` +{ + "$0": "/Users/nathanbrahms/dev/p0cli/node_modules/.bin/jest", + "_": [ + "ssh", + ], + "arguments": [ + "ssh", + "some-instance", + "--provider", + "aws", + "--reason", + "reason", + ], + "wait": true, +} +`; + exports[`ssh persistent access should call ssm: stderr 1`] = ` [ [ diff --git a/src/commands/__tests__/ssh.test.ts b/src/commands/__tests__/ssh.test.ts index b01a462..3a6ccd0 100644 --- a/src/commands/__tests__/ssh.test.ts +++ b/src/commands/__tests__/ssh.test.ts @@ -57,6 +57,12 @@ describe("ssh", () => { }); }); + it("should call p0 request with reason arg", async () => { + void sshCommand(yargs()).parse(`ssh some-instance --reason reason`); + await sleep(100); + expect(mockFetchCommand.mock.calls[0][1]).toMatchSnapshot("args"); + }); + it("should wait for access grant", async () => { const promise = sshCommand(yargs()).parse(`ssh some-instance`); const wait = sleep(100); diff --git a/src/commands/ssh.ts b/src/commands/ssh.ts index 2033a0a..0889848 100644 --- a/src/commands/ssh.ts +++ b/src/commands/ssh.ts @@ -32,6 +32,7 @@ export type SshCommandArgs = { command?: string; L?: string; // port forwarding option arguments: string[]; + reason?: string; }; // Matches strings with the pattern "digits:digits" (e.g. 1234:5678) @@ -75,6 +76,11 @@ export const sshCommand = (yargs: yargs.Argv) => 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", }), guard(ssh) ); @@ -149,7 +155,13 @@ const ssh = async (args: yargs.ArgumentsCamelCase) => { const response = await request( { ...pick(args, "$0", "_"), - arguments: ["ssh", args.destination, "--provider", "aws"], + arguments: [ + "ssh", + args.destination, + "--provider", + "aws", + ...(args.reason ? ["--reason", args.reason] : []), + ], wait: true, }, authn,