Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSH requesting access message #137

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/commands/shared/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,14 @@ export const request =
}>,
authn?: Authn,
options?: {
accessMessage?: string;
message?: "all" | "approval-required" | "none";
}
): Promise<RequestResponse<T> | undefined> => {
const resolvedAuthn = authn ?? (await authenticate());
const { userCredential } = resolvedAuthn;
const data = await spinUntil(
"Requesting access",
options?.accessMessage ? options.accessMessage : "Requesting access",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be dependent on the type union? "all" | "approval-required" | "none"

So if we see: "approval-required" we can still say: "requesting access" 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since "approval-required" is hardcoded for the ssh session request, I don't think we can use it to change the message in this case. I think the request would still have approval-required even if the user already had been approved in the past?

https://github.com/p0-security/p0cli/pull/137/files#diff-c16738fe5df540e2a49c613e959ebaa27241c6ce8389095b737f76c65bc44f8eL125

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I see 🤔 .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can make it dependent like this:

const accessMessage = (message?: string) => {
  switch (message) {
    case "approval-required":
      return "Requesting access";
    default:
      return "Requesting access";
  }
};

then here

Suggested change
options?.accessMessage ? options.accessMessage : "Requesting access",
accessMessage(options?.message),,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this change, but the "approval-required" message type will return an accessMessage of Checking for access in P0.

This makes this change apply to p0 kubeconfig as well which I think is desirable since it's similar flow to starting an ssh session.

const accessMessage = (message?: string) => {
  switch (message) {
    case "approval-required":
     return "Checking for access in P0";;
    default:
      return "Requesting access";
  }
};

fetchCommand<RequestResponse<T>>(resolvedAuthn, args, [
command,
...args.arguments,
Expand Down
3 changes: 2 additions & 1 deletion src/commands/shared/ssh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const provisionRequest = async (
wait: true,
},
authn,
{ message: "approval-required" }
{ accessMessage: "Checking for access in P0", message: "approval-required" }
);

if (!response) {
Expand All @@ -131,6 +131,7 @@ export const provisionRequest = async (
}
const { id, isPreexisting } = response;
if (!isPreexisting) print2("Waiting for access to be provisioned");
else print2("Existing access found. Connecting to node.");
MichaelDimitras marked this conversation as resolved.
Show resolved Hide resolved

const provisionedRequest = await waitForProvisioning<PluginSshRequest>(
authn,
Expand Down
Loading