From 5fb86c5cb093bd1f652d1d7798b9cf5f294be0eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Tue, 21 Apr 2020 11:18:08 +0200 Subject: [PATCH 1/3] feat(core): add GetSecretKey and GetAccessKey --- scw/client.go | 14 ++++++++++++++ scw/client_test.go | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/scw/client.go b/scw/client.go index 0636dc0b5..fd91fe378 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, true + } + return "", false +} + +func (c *Client) GetAccessKey() (accessKey string, exists bool) { + if token, isToken := c.auth.(*auth.Token); isToken { + return token.AccessKey, true + } + 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..9dfb6179e 100644 --- a/scw/client_test.go +++ b/scw/client_test.go @@ -73,6 +73,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 +119,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") }) } From 6aea89a14c50ebe6a60fa519547bffa17f0cd9cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Tue, 21 Apr 2020 11:40:14 +0200 Subject: [PATCH 2/3] Fix --- scw/client_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scw/client_test.go b/scw/client_test.go index 9dfb6179e..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(), From f4b3607c792f57382fe9caf73bea49ec554d3fd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Tue, 21 Apr 2020 14:42:19 +0200 Subject: [PATCH 3/3] Fix --- scw/client.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scw/client.go b/scw/client.go index fd91fe378..91d90119b 100644 --- a/scw/client.go +++ b/scw/client.go @@ -114,14 +114,14 @@ func (c *Client) GetDefaultZone() (zone Zone, exists bool) { func (c *Client) GetSecretKey() (secretKey string, exists bool) { if token, isToken := c.auth.(*auth.Token); isToken { - return token.SecretKey, true + 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, true + return token.AccessKey, isToken } return "", false }