Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var AddKeyCmd = &cobra.Command{ Use: "add-key", Short: "Adds an SSH key to the current user account", Long: `Adds an SSH key to the current user account. If no key is provided, one will be generated.`, Run: func(cmd *cobra.Command, args []string) { key, _ := cmd.Flags().GetString("key") keyFile, _ := cmd.Flags().GetString("key-file") var publicKey []byte var err error if key == "" && keyFile == "" { if !confirmAddKey() { fmt.Println("Operation aborted.") return } keyName := promptKeyName() publicKey, err = GenerateSSHKeyPair(keyName) if err != nil { fmt.Fprintf(os.Stderr, "Failed to generate SSH key: %v\n", err) return } } else if keyFile != "" { publicKey, err = os.ReadFile(keyFile) if err != nil { fmt.Fprintf(os.Stderr, "Failed to read key file: %v\n", err) return } } if err := api.AddPublicSSHKey(publicKey); err != nil { fmt.Fprintf(os.Stderr, "Failed to add the SSH key: %v\n", err) return } fmt.Println("The key has been added to your account.") }, }
View Source
var ListKeysCmd = &cobra.Command{ Use: "list-keys", Short: "List all SSH keys", Long: `List all the SSH keys associated with the current user's account.`, Run: func(cmd *cobra.Command, args []string) { _, keys, err := api.GetPublicSSHKeys() if err != nil { fmt.Fprintf(os.Stderr, "Error getting SSH keys: %v\n", err) return } if len(keys) == 0 { fmt.Println("No SSH keys found.") return } displaySSHKeys(keys) }, }
ListKeysCmd defines the command to list all SSH keys for the current user.
Functions ¶
func GenerateSSHKeyPair ¶
GenerateSSHKeyPair generates an RSA key pair and saves the private key to a file in the user's home directory.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.