Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add GetSecretKey and GetAccessKey #386

Merged
merged 3 commits into from
Apr 21, 2020
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
14 changes: 14 additions & 0 deletions scw/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,20 @@ func (c *Client) GetDefaultZone() (zone Zone, exists bool) {
return Zone(""), false
}

func (c *Client) GetSecretKey() (secretKey string, exists bool) {
if token, isToken := c.auth.(*auth.Token); isToken {
return token.SecretKey, isToken
}
return "", false
}

func (c *Client) GetAccessKey() (accessKey string, exists bool) {
if token, isToken := c.auth.(*auth.Token); isToken {
return token.AccessKey, isToken
}
return "", false
}

// GetDefaultPageSize returns the default page size of the client.
// This value can be set in the client option
// WithDefaultPageSize(). Be aware this value can be empty.
Expand Down
31 changes: 31 additions & 0 deletions scw/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ const (
testInsecure = true
)

func TestNewClientWithNoAuth(t *testing.T) {
t.Run("Basic", func(t *testing.T) {
client, err := NewClient()
testhelpers.AssertNoError(t, err)

secretKey, exist := client.GetSecretKey()
testhelpers.Equals(t, "", secretKey)
testhelpers.Assert(t, !exist, "secretKey must not exist")

accessKey, exist := client.GetAccessKey()
testhelpers.Equals(t, "", accessKey)
testhelpers.Assert(t, !exist, "accessKey must not exist")
})
}

func TestNewClientWithDefaults(t *testing.T) {
options := []ClientOption{
WithInsecure(),
Expand Down Expand Up @@ -73,6 +88,14 @@ func TestNewClientWithOptions(t *testing.T) {
defaultPageSize, exist := client.GetDefaultPageSize()
testhelpers.Equals(t, testDefaultPageSize, defaultPageSize)
testhelpers.Assert(t, exist, "defaultPageSize must exist")

secretKey, exist := client.GetSecretKey()
testhelpers.Equals(t, testSecretKey, secretKey)
testhelpers.Assert(t, exist, "secretKey must exist")

accessKey, exist := client.GetAccessKey()
testhelpers.Equals(t, testAccessKey, accessKey)
testhelpers.Assert(t, exist, "accessKey must exist")
})

t.Run("With custom profile", func(t *testing.T) {
Expand Down Expand Up @@ -111,6 +134,14 @@ func TestNewClientWithOptions(t *testing.T) {

_, exist = client.GetDefaultPageSize()
testhelpers.Assert(t, !exist, "defaultPageSize must not exist")

secretKey, exist := client.GetSecretKey()
testhelpers.Equals(t, testSecretKey, secretKey)
testhelpers.Assert(t, exist, "secretKey must exist")

accessKey, exist := client.GetAccessKey()
testhelpers.Equals(t, testAccessKey, accessKey)
testhelpers.Assert(t, exist, "accessKey must exist")
})
}

Expand Down