Skip to content

Commit 0bec19e

Browse files
committed
ssh: Add --reason
This is necessary for any orgs that require reasons, but also just useful in general. Fixes ENG-1670.
1 parent e9712e6 commit 0bec19e

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

src/commands/__tests__/__snapshots__/ssh.test.ts.snap

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`ssh ephemeral access should call p0 request with reason arg: args 1`] = `
4+
{
5+
"$0": "/Users/nathanbrahms/dev/p0cli/node_modules/.bin/jest",
6+
"_": [
7+
"ssh",
8+
],
9+
"arguments": [
10+
"ssh",
11+
"some-instance",
12+
"--provider",
13+
"aws",
14+
"--reason",
15+
"reason",
16+
],
17+
"wait": true,
18+
}
19+
`;
20+
321
exports[`ssh ephemeral access should call ssm: stderr 1`] = `
422
[
523
[
@@ -17,6 +35,24 @@ exports[`ssh ephemeral access should call ssm: stderr 1`] = `
1735
]
1836
`;
1937

38+
exports[`ssh persistent access should call p0 request with reason arg: args 1`] = `
39+
{
40+
"$0": "/Users/nathanbrahms/dev/p0cli/node_modules/.bin/jest",
41+
"_": [
42+
"ssh",
43+
],
44+
"arguments": [
45+
"ssh",
46+
"some-instance",
47+
"--provider",
48+
"aws",
49+
"--reason",
50+
"reason",
51+
],
52+
"wait": true,
53+
}
54+
`;
55+
2056
exports[`ssh persistent access should call ssm: stderr 1`] = `
2157
[
2258
[

src/commands/__tests__/ssh.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ describe("ssh", () => {
5757
});
5858
});
5959

60+
it("should call p0 request with reason arg", async () => {
61+
void sshCommand(yargs()).parse(`ssh some-instance --reason reason`);
62+
await sleep(100);
63+
expect(mockFetchCommand.mock.calls[0][1]).toMatchSnapshot("args");
64+
});
65+
6066
it("should wait for access grant", async () => {
6167
const promise = sshCommand(yargs()).parse(`ssh some-instance`);
6268
const wait = sleep(100);

src/commands/ssh.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export type SshCommandArgs = {
3232
command?: string;
3333
L?: string; // port forwarding option
3434
arguments: string[];
35+
reason?: string;
3536
};
3637

3738
// Matches strings with the pattern "digits:digits" (e.g. 1234:5678)
@@ -75,6 +76,11 @@ export const sshCommand = (yargs: yargs.Argv) =>
7576
describe:
7677
// the order of the sockets in the address matches the ssh man page
7778
"Forward a local port to the remote host; `local_socket:remote_socket`",
79+
})
80+
// Match `p0 request --reason`
81+
.option("reason", {
82+
describe: "Reason access is needed",
83+
type: "string",
7884
}),
7985
guard(ssh)
8086
);
@@ -149,7 +155,13 @@ const ssh = async (args: yargs.ArgumentsCamelCase<SshCommandArgs>) => {
149155
const response = await request(
150156
{
151157
...pick(args, "$0", "_"),
152-
arguments: ["ssh", args.destination, "--provider", "aws"],
158+
arguments: [
159+
"ssh",
160+
args.destination,
161+
"--provider",
162+
"aws",
163+
...(args.reason ? ["--reason", args.reason] : []),
164+
],
153165
wait: true,
154166
},
155167
authn,

0 commit comments

Comments
 (0)