Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Manual token input during login. #124

Merged
merged 1 commit into from
Sep 15, 2020
Merged

Manual token input during login. #124

merged 1 commit into from
Sep 15, 2020

Conversation

creack
Copy link
Contributor

@creack creack commented Sep 7, 2020

Loosely based on how concourse ci handles it.

Fixes #107. This makes for a better experience when using the cli over ssh.

Notable change: use the full URL given by the user instead of trimming down the path. This allows for path based reverse proxies.

@creack creack requested review from coadler and cmoog September 7, 2020 20:45
Copy link
Contributor

@cmoog cmoog left a comment

Choose a reason for hiding this comment

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

First pass. Good thinking with keeping the full URL in the config.

Comment on lines +41 to +42
// From this point, the commandline is correct.
// Don't return errors as it would print the usage.
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 what you're getting at here... not sure this is the best approach though. Because usage errors seem like the outlier, we could set SilenceUsage: true and only print the usage when needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seem a bit outside the scope of this PR as it is the way all commands are set. We can create a new PR to improve error management everywhere at once.

case <-ctx.Done():
t.Fatal("Timeout waiting for the input.")
case err := <-errChan:
t.Fatalf("ReadLine returned before we got the token (%v).", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

slogtest.Fatal(t, "ReadLine returned before we got the token", slog.Error(err))... same for all other logs.

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 think we should stick with stdlib and standard widely used and supported instead of using custom ones. Unless there is some value I am missing? Integration with our co/monitoring/alerting maybe?

Copy link
Contributor

Choose a reason for hiding this comment

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

I enjoy using slog since it's able to print the stack frames from the provided error, though I can't say there's much consistency in either direction atm.

case <-ctx.Done():
t.Fatal("Timeout waiting for readline to finish.")
case err := <-errChan:
require.NoError(t, err, "Error reading the line.")
Copy link
Contributor

Choose a reason for hiding this comment

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

assert.Success

return xerrors.Errorf("store config: %w", err)
}

flog.Success("Logged in.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be precede this with a newline? Right now, the output is:

$ coder login https://master.cdr.dev
or enter token manually: 2020-09-08 16:04:30 SUCCESS    Logged in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a newline in the prompt before this line. Otherwise, flog's prefix still is on he previous line.

buf := bufio.NewReader(r)

retry:
_, _ = fmt.Fprintf(w, "or enter token manually: ") // Best effort. Can only fail on custom writers.
Copy link
Contributor

Choose a reason for hiding this comment

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

This message doesn't seem descriptive enough... maybe we should include specific direction so the user knows to paste the contents of the URL bar.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the same message that concourse ci uses, with the same formatting. We expect most people to not require this part, so I think it might be good enough? I am not really good with words ^^, If you have a suggestion for better wording, I'd be happy to update.

case <-ctx.Done():
t.Fatal("Timeout waiting for the input.")
case err := <-errChan:
t.Fatalf("ReadLine returned before we got the token (%v).", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

I enjoy using slog since it's able to print the stack frames from the provided error, though I can't say there's much consistency in either direction atm.

if err != nil {
return xerrors.Errorf("parse url: %v", err)
if l, err = net.Listen("tcp6", "[::1]:0"); err != nil {
return nil, xerrors.Errorf("failed to listen on a port: %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nil, xerrors.Errorf("failed to listen on a port: %s", err)
return nil, xerrors.Errorf("listen on a port: %w", err)

@creack creack force-pushed the 107-auth-input-fallback branch 2 times, most recently from 09a3d77 to aafc42a Compare September 15, 2020 17:36
@creack creack requested a review from cmoog September 15, 2020 17:37
- Support path based reverse proxy.

Signed-off-by: Guillaume J. Charmes <[email protected]>
@creack creack force-pushed the 107-auth-input-fallback branch from aafc42a to 8b35b02 Compare September 15, 2020 17:40
Copy link
Contributor

@cmoog cmoog left a comment

Choose a reason for hiding this comment

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

The language of or enter token manually is a bit off, but I don't have any better ideas at the moment. I'd be curious to hear what others think when they try it out after this lands.

@creack creack merged commit 2edd14e into master Sep 15, 2020
@creack creack deleted the 107-auth-input-fallback branch September 15, 2020 20:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add input while waiting for oauth callback to allow ssh
3 participants