Skip to content

Commit

Permalink
add "ssh-key get --project-id $ID"
Browse files Browse the repository at this point in the history
Signed-off-by: Marques Johansson <[email protected]>
  • Loading branch information
displague committed Oct 6, 2021
1 parent 10e9e19 commit 0b1afd2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
8 changes: 6 additions & 2 deletions docs/metal_ssh-key_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ metal ssh-key get
Retrieve a specific SSH key:
metal ssh-key get --id [ssh-key_UUID]

Retrieve all project SSH keys
metal ssh-key get --project-id [project_UUID]



```
Expand All @@ -21,8 +24,9 @@ metal ssh-key get [flags]
### Options

```
-h, --help help for get
-i, --id string UUID of the SSH key
-h, --help help for get
-i, --id string UUID of the SSH key
-p, --project-id string List SSH Keys for the project identified by Project ID
```

### Options inherited from parent commands
Expand Down
23 changes: 22 additions & 1 deletion internal/ssh/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
package ssh

import (
"fmt"

"github.com/packethost/packngo"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
Expand All @@ -44,10 +47,27 @@ metal ssh-key get
Retrieve a specific SSH key:
metal ssh-key get --id [ssh-key_UUID]
Retrieve all project SSH keys
metal ssh-key get --project-id [project_UUID]
`,
RunE: func(cmd *cobra.Command, args []string) error {
if sshKeyID == "" {
sshKeys, _, err := c.Service.List()
projectID, _ := cmd.LocalFlags().GetString("project-id")
fmt.Println(cmd.LocalFlags())
listFn := func() ([]packngo.SSHKey, *packngo.Response, error) {
fmt.Println("foooo")
return c.Service.List()
}

if projectID != "" && cmd.Flag("project-id").Changed {
listFn = func() ([]packngo.SSHKey, *packngo.Response, error) {
fmt.Println("baaar")
return c.Service.ProjectList(projectID)
}
}
sshKeys, _, err := listFn()

if err != nil {
return errors.Wrap(err, "Could not list SSH Keys")
}
Expand Down Expand Up @@ -76,6 +96,7 @@ metal ssh-key get --id [ssh-key_UUID]
},
}

retrieveSSHKeysCmd.Flags().StringP("project-id", "p", "", "List SSH Keys for the project identified by Project ID")
retrieveSSHKeysCmd.Flags().StringVarP(&sshKeyID, "id", "i", "", "UUID of the SSH key")
return retrieveSSHKeysCmd
}

0 comments on commit 0b1afd2

Please sign in to comment.