()
| 12 | ) |
| 13 | |
| 14 | func (r *RootCmd) publickey() *serpent.Command { |
| 15 | var reset bool |
| 16 | cmd := &serpent.Command{ |
| 17 | Use: "publickey", |
| 18 | Aliases: []string{"pubkey"}, |
| 19 | Short: "Output your Coder public key used for Git operations", |
| 20 | Handler: func(inv *serpent.Invocation) error { |
| 21 | client, err := r.InitClient(inv) |
| 22 | if err != nil { |
| 23 | return err |
| 24 | } |
| 25 | if reset { |
| 26 | // Confirm prompt if using --reset. We don't want to accidentally |
| 27 | // reset our public key. |
| 28 | _, err := cliui.Prompt(inv, cliui.PromptOptions{ |
| 29 | Text: "Confirm regenerate a new sshkey for your workspaces? This will require updating the key " + |
| 30 | "on any services it is registered with. This action cannot be reverted.", |
| 31 | IsConfirm: true, |
| 32 | }) |
| 33 | if err != nil { |
| 34 | return err |
| 35 | } |
| 36 | |
| 37 | // Reset the public key, let the retrieve re-read it. |
| 38 | _, err = client.RegenerateGitSSHKey(inv.Context(), codersdk.Me) |
| 39 | if err != nil { |
| 40 | return err |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | key, err := client.GitSSHKey(inv.Context(), codersdk.Me) |
| 45 | if err != nil { |
| 46 | return xerrors.Errorf("create codersdk client: %w", err) |
| 47 | } |
| 48 | |
| 49 | cliui.Info(inv.Stdout, |
| 50 | "This is your public key for using "+pretty.Sprint(cliui.DefaultStyles.Field, "git")+" in "+ |
| 51 | "Coder. All clones with SSH will be authenticated automatically 🪄.", |
| 52 | ) |
| 53 | cliui.Info(inv.Stdout, pretty.Sprint(cliui.DefaultStyles.Code, strings.TrimSpace(key.PublicKey))+"\n") |
| 54 | cliui.Info(inv.Stdout, "Add to GitHub and GitLab:") |
| 55 | cliui.Info(inv.Stdout, "> https://github.com/settings/ssh/new") |
| 56 | cliui.Info(inv.Stdout, "> https://gitlab.com/-/profile/keys") |
| 57 | |
| 58 | return nil |
| 59 | }, |
| 60 | } |
| 61 | |
| 62 | cmd.Options = serpent.OptionSet{ |
| 63 | { |
| 64 | Flag: "reset", |
| 65 | Description: "Regenerate your public key. This will require updating the key on any services it's registered with.", |
| 66 | Value: serpent.BoolOf(&reset), |
| 67 | }, |
| 68 | cliui.SkipPromptOption(), |
| 69 | } |
| 70 | |
| 71 | return cmd |
no test coverage detected