Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pkg/commands/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/scaleway/scaleway-cli/vendor/github.com/kardianos/osext"

"github.com/scaleway/scaleway-cli/pkg/config"
"github.com/scaleway/scaleway-cli/pkg/utils"
)

// InfoArgs are flags for the `RunInfo` function
Expand Down Expand Up @@ -41,5 +42,23 @@ func RunInfo(ctx CommandContext, args InfoArgs) error {
fmt.Fprintf(ctx.Stdout, " Snapshots: %d\n", ctx.API.Cache.GetNbSnapshots())
fmt.Fprintf(ctx.Stdout, " Volumes: %d\n", ctx.API.Cache.GetNbVolumes())
fmt.Fprintf(ctx.Stdout, " Bootscripts: %d\n", ctx.API.Cache.GetNbBootscripts())
user, err := ctx.API.GetUser()
if err != nil {
return fmt.Errorf("Unable to get your SSH Keys")
} else {
if len(user.SSHPublicKeys) == 0 {
fmt.Fprintln(ctx.Stdout, "You have no ssh keys")
} else {
fmt.Fprintln(ctx.Stdout, "SSH Keys:")
for id, key := range user.SSHPublicKeys {
fingerprint, err := utils.SSHGetFingerprint(key.Key)
if err != nil {
return err
} else {
fmt.Fprintf(ctx.Stdout, " [%d] %s", id, fingerprint)
}
}
}
}
return nil
}
23 changes: 23 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"os"
"os/exec"
Expand Down Expand Up @@ -211,3 +212,25 @@ However, you can access your serial using a web browser:
}
return nil
}

func SSHGetFingerprint(key string) (string, error) {
tmp, err := ioutil.TempFile("", ".tmp")
if err != nil {
return "", fmt.Errorf("Unable to create a tempory file: %v", err)
}
defer os.Remove(tmp.Name())
buff := []byte(key)
bytesWritten := 0
for bytesWritten < len(buff) {
nb, err := tmp.Write(buff[bytesWritten:])
if err != nil {
return "", fmt.Errorf("Unable to write: %v", err)
}
bytesWritten += nb
}
ret, err := exec.Command("ssh-keygen", "-l", "-f", tmp.Name()).Output()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create an issue for later: do not use external program to compute the fingerprint

if err != nil {
return "", fmt.Errorf("Unable to run ssh-keygen: %v", err)
}
return string(ret), nil
}