diff --git a/scw/client.go b/scw/client.go index 0636dc0b5..91d90119b 100644 --- a/scw/client.go +++ b/scw/client.go @@ -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. diff --git a/scw/client_test.go b/scw/client_test.go index fa93c5f23..4e119dc3b 100644 --- a/scw/client_test.go +++ b/scw/client_test.go @@ -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(), @@ -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) { @@ -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") }) }