merge ensureAuthorizedKeys into checkAuthorizedKeys
This commit is contained in:
parent
ae3aacb964
commit
37f8039f76
3 changed files with 10 additions and 19 deletions
|
|
@ -209,8 +209,13 @@ func ask(qs []*survey.Question, response interface{}) error {
|
|||
// checkAuthorizedKeys reports an error if the user has not registered any SSH keys;
|
||||
// see https://github.com/cli/cli/v2/issues/166#issuecomment-921769703.
|
||||
// The check is not required for security but it improves the error message.
|
||||
func checkAuthorizedKeys(ctx context.Context, client apiClient, user string) error {
|
||||
keys, err := client.AuthorizedKeys(ctx, user)
|
||||
func checkAuthorizedKeys(ctx context.Context, client apiClient) error {
|
||||
user, err := client.GetUser(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting user: %w", err)
|
||||
}
|
||||
|
||||
keys, err := client.AuthorizedKeys(ctx, user.Login)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read GitHub-authorized SSH keys for %s: %w", user, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,14 +41,9 @@ func (a *App) Logs(ctx context.Context, codespaceName string, follow bool) (err
|
|||
return fmt.Errorf("get or choose codespace: %w", err)
|
||||
}
|
||||
|
||||
user, err := a.apiClient.GetUser(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getting user: %w", err)
|
||||
}
|
||||
|
||||
authkeys := make(chan error, 1)
|
||||
go func() {
|
||||
authkeys <- checkAuthorizedKeys(ctx, a.apiClient, user.Login)
|
||||
authkeys <- checkAuthorizedKeys(ctx, a.apiClient)
|
||||
}()
|
||||
|
||||
session, err := codespaces.ConnectToLiveshare(ctx, a, noopLogger(), a.apiClient, codespace)
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ func (a *App) SSH(ctx context.Context, sshArgs []string, opts sshOptions) (err e
|
|||
// That lets us report a more useful error message if they don't.
|
||||
authkeys := make(chan error, 1)
|
||||
go func() {
|
||||
authkeys <- a.ensureAuthorizedKeys(ctx)
|
||||
authkeys <- checkAuthorizedKeys(ctx, a.apiClient)
|
||||
}()
|
||||
|
||||
session, err := a.openSSHSession(ctx, codespace, liveshareLogger)
|
||||
|
|
@ -240,7 +240,7 @@ func (a *App) printOpenSSHConfig(ctx context.Context, opts configOptions, execut
|
|||
|
||||
// While the above fetches are running, ensure that the user has keys installed.
|
||||
// That lets us report a more useful error message if they don't.
|
||||
if err = a.ensureAuthorizedKeys(ctx); err != nil {
|
||||
if err = checkAuthorizedKeys(ctx, a.apiClient); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -311,15 +311,6 @@ func (a *App) openSSHSession(ctx context.Context, codespace *api.Codespace, live
|
|||
return session, nil
|
||||
}
|
||||
|
||||
func (a *App) ensureAuthorizedKeys(ctx context.Context) error {
|
||||
user, err := a.apiClient.GetUser(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting user: %w", err)
|
||||
}
|
||||
|
||||
return checkAuthorizedKeys(ctx, a.apiClient, user.Login)
|
||||
}
|
||||
|
||||
type cpOptions struct {
|
||||
sshOptions
|
||||
recursive bool // -r
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue