-
Notifications
You must be signed in to change notification settings - Fork 71
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
feat: add seed phrase to backup-keys #128
Conversation
I copied a lot of code over from melt 😂 let me know if there's a nicer way I could organize things or if it's okay |
I noticed hehe I was thinking we can refactor there a bit to make it easier to use these parts as a lib too... will take a look there and ping you once its done :) |
pwderr := &ssh.PassphraseMissingError{} | ||
if errors.As(err, &pwderr) { | ||
pass, err := askKeyPassphrase(path) | ||
if err != nil { | ||
return "", err | ||
} | ||
return backup(path, pass) | ||
} | ||
return "", fmt.Errorf("could not parse key: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pwderr := &ssh.PassphraseMissingError{} | |
if errors.As(err, &pwderr) { | |
pass, err := askKeyPassphrase(path) | |
if err != nil { | |
return "", err | |
} | |
return backup(path, pass) | |
} | |
return "", fmt.Errorf("could not parse key: %w", err) | |
if !errors.Is(err, &ssh.PassphraseMissingError{}) { | |
return "", fmt.Errorf("could not parse key: %w", err) | |
} | |
pass, err := askKeyPassphrase(path) | |
if err != nil { | |
return "", err | |
} | |
return backup(path, pass) |
We can use errors.Is
as we are not using pwderr
for anything else.
By reversing the conditional here, we can reduce nesting, optionally we can encapsulate the logic in a new method askPassphraseAndBackup(path)
fmt.Fprint(os.Stderr, msg) | ||
t, err := tty.Open() | ||
if err != nil { | ||
return nil, fmt.Errorf("could not open tty") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, fmt.Errorf("could not open tty") | |
return nil, errors.New("could not open tty") |
This will save some allocations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its actually missing the parent err:
return nil, fmt.Errorf("could not open tty") | |
return nil, fmt.Errorf("could not open tty: %w", err) |
alternative idea to this: an option to print the key to stdout, so users can pipe into melt (or something else) 🤔 |
review from charmbracelet/charm#128 Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
review from charmbracelet/charm#128 Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
Changes:
Related Issues:
#116