Skip to content

Commit

Permalink
ref: (BREAKING) Use map for Client.GetSSHKeys(...) response (#28)
Browse files Browse the repository at this point in the history
* Use map for Client.GetSSHKeys(...) response

* Add optional skip

* Update test/integration/sshkeys_test.go

Co-authored-by: Ye Chen <127243817+yec-akamai@users.noreply.github.com>

---------

Co-authored-by: Ye Chen <127243817+yec-akamai@users.noreply.github.com>
  • Loading branch information
lgarber-akamai and yec-akamai authored Jan 22, 2024
1 parent 0c5e7be commit 9093622
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
8 changes: 1 addition & 7 deletions sshkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@ package metadata

import "context"

// SSHKeysUserData contains per-user SSH public keys
// specified during Linode instance/disk creation.
type SSHKeysUserData struct {
Root []string `json:"root"`
}

// SSHKeysData contains information about SSH keys
// relevant to the current Linode instance.
type SSHKeysData struct {
Users SSHKeysUserData `json:"users"`
Users map[string][]string `json:"users"`
}

// GetSSHKeys gets all SSH keys for the current instance.
Expand Down
24 changes: 24 additions & 0 deletions test/integration/sshkeys_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package integration

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetSSHKeys(t *testing.T) {
t.Parallel()

sshKeys, err := metadataClient.GetSSHKeys(context.Background())
assert.NoError(t, err)

if len(sshKeys.Users) < 1 {
t.Skip(
"The current instance does not have any SSH keys configured, skipping...")
}

for _, v := range sshKeys.Users {
assert.Greater(t, len(v), 0)
}
}

0 comments on commit 9093622

Please sign in to comment.