Skip to content

Commit

Permalink
ssh: Add --reason
Browse files Browse the repository at this point in the history
This is necessary for any orgs that require reasons, but also just
useful in general.

Fixes ENG-1670.
  • Loading branch information
nbrahms committed Feb 28, 2024
1 parent e9712e6 commit 0bec19e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/commands/__tests__/__snapshots__/ssh.test.ts.snap
Original file line number Diff line number Diff line change
@@ -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`] = `
[
[
Expand All @@ -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`] = `
[
[
Expand Down
6 changes: 6 additions & 0 deletions src/commands/__tests__/ssh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 13 additions & 1 deletion src/commands/ssh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
);
Expand Down Expand Up @@ -149,7 +155,13 @@ const ssh = async (args: yargs.ArgumentsCamelCase<SshCommandArgs>) => {
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,
Expand Down

0 comments on commit 0bec19e

Please sign in to comment.