From a611d544f13c90ce52e31adeb145be2ce3f81f88 Mon Sep 17 00:00:00 2001 From: Simon Barendse Date: Mon, 4 Mar 2019 15:59:31 +0100 Subject: [PATCH 01/20] Add more linters --- .golangci.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index 88c5abe4..3b88deb7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,4 +5,18 @@ linters: - golint - staticcheck - vet + - unused + - gosimple + - stylecheck + - structcheck + - varcheck + - interfacer + - unconvert + - ineffassign + - deadcode + - gocyclo + - typecheck + - depguard + - unparam + - nakedret disable-all: true From 392ca236a59f650d2ab06ce99d889d22de60d6e3 Mon Sep 17 00:00:00 2001 From: Simon Barendse Date: Mon, 4 Mar 2019 16:00:46 +0100 Subject: [PATCH 02/20] Add gofmt linter and fix issues found --- .golangci.yml | 1 + pkg/secrethub/org_test.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 3b88deb7..0b76924f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -19,4 +19,5 @@ linters: - depguard - unparam - nakedret + - gofmt disable-all: true diff --git a/pkg/secrethub/org_test.go b/pkg/secrethub/org_test.go index a592d2f0..86f107b8 100644 --- a/pkg/secrethub/org_test.go +++ b/pkg/secrethub/org_test.go @@ -38,7 +38,7 @@ func TestCreateOrg(t *testing.T) { Description: descr, CreatedAt: now, Members: []*api.OrgMember{ - &api.OrgMember{ + { OrgID: orgID, AccountID: accountID, Role: "admin", From 831c313464ebeb3c3e8ecb36e1ffc7fb2c6e7093 Mon Sep 17 00:00:00 2001 From: Simon Barendse Date: Mon, 4 Mar 2019 16:07:06 +0100 Subject: [PATCH 03/20] Add misspell linter and fix issues found --- .golangci.yml | 1 + internals/crypto/scrypt.go | 6 +++--- internals/crypto/scrypt_test.go | 2 +- pkg/secrethub/account.go | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 0b76924f..d9c17350 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -20,4 +20,5 @@ linters: - unparam - nakedret - gofmt + - misspell disable-all: true diff --git a/internals/crypto/scrypt.go b/internals/crypto/scrypt.go index abe8dd38..4e2e7897 100644 --- a/internals/crypto/scrypt.go +++ b/internals/crypto/scrypt.go @@ -33,7 +33,7 @@ const ( // Read more about the parameters, how they work and how to determine their values // in this blog post: https://blog.filippo.io/the-scrypt-parameters/ // - // Also, this the value recommented in the official GoDocs. + // Also, this the value recommended in the official GoDocs. DefaultScryptN = 1 << 15 // DefaultScryptR determines the sequential read size of the scrypt @@ -44,7 +44,7 @@ const ( // different memory characteristics. Use the N parameter instead to // increase or decrease work. // - // The value has been set to 8, which is the value recommented in + // The value has been set to 8, which is the value recommended in // the official GoDocs. DefaultScryptR = 8 @@ -54,7 +54,7 @@ const ( // be used to decrease the wall-clock-time of the key derivation // function. Use the N parameter for that. // - // The value has been set to 1, which is the value recommented in + // The value has been set to 1, which is the value recommended in // the official GoDocs. DefaultScryptP = 1 ) diff --git a/internals/crypto/scrypt_test.go b/internals/crypto/scrypt_test.go index dab7483a..bf02e37a 100644 --- a/internals/crypto/scrypt_test.go +++ b/internals/crypto/scrypt_test.go @@ -321,7 +321,7 @@ func TestIsPowerOfTwo(t *testing.T) { } } -// Below we test the assumption that increasing the salt lenght does +// Below we test the assumption that increasing the salt length does // not significantly increase the execution time of key derivation // function. The output of the benchmarks is documented below: // diff --git a/pkg/secrethub/account.go b/pkg/secrethub/account.go index 6c0dc2bf..75280959 100644 --- a/pkg/secrethub/account.go +++ b/pkg/secrethub/account.go @@ -42,7 +42,7 @@ func (s accountService) Keys() AccountKeyService { // createAccountKey creates a new intermediate key wrapped in the supplied credential. // The public key of the intermediate key is returned. // The intermediate key is returned in an CreateAccountKeyRequest ready to be sent to the API. -// If an error has occured, it will be returned and the other result should be considered invalid. +// If an error has occurred, it will be returned and the other result should be considered invalid. func (c *client) createAccountKeyRequest(credential Credential, accountKey crypto.RSAPrivateKey) (*api.CreateAccountKeyRequest, error) { publicAccountKey, err := accountKey.Public().Export() if err != nil { From eda6960e3baf9696411da021597b6ca27a412832 Mon Sep 17 00:00:00 2001 From: Simon Barendse Date: Mon, 4 Mar 2019 16:12:12 +0100 Subject: [PATCH 04/20] Add prealloc linter and fix issues found --- .golangci.yml | 1 + internals/crypto/ciphertext.go | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index d9c17350..4072efd7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -21,4 +21,5 @@ linters: - nakedret - gofmt - misspell + - prealloc disable-all: true diff --git a/internals/crypto/ciphertext.go b/internals/crypto/ciphertext.go index 21853c04..56178dc6 100644 --- a/internals/crypto/ciphertext.go +++ b/internals/crypto/ciphertext.go @@ -104,9 +104,11 @@ func newEncodedCiphertextMetadata(metadataList map[string]string) encodedCiphert metadata := "" // Sort all the keys of the metadataList so that metadata is always in alphabetical order. - var keys []string + keys := make([]string, len(metadataList)) + i := 0 for k := range metadataList { - keys = append(keys, k) + keys[i] = k + i++ } sort.Strings(keys) From 81840ffc13149e15fa5700ebb4317db3e63357d9 Mon Sep 17 00:00:00 2001 From: Simon Barendse Date: Mon, 4 Mar 2019 16:15:43 +0100 Subject: [PATCH 05/20] Add goconst linter and fix issues found --- .golangci.yml | 1 + pkg/secrethub/user_test.go | 18 ++++++------------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 4072efd7..242ef1df 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -22,4 +22,5 @@ linters: - gofmt - misspell - prealloc + - goconst disable-all: true diff --git a/pkg/secrethub/user_test.go b/pkg/secrethub/user_test.go index 78ab7b12..7396ee61 100644 --- a/pkg/secrethub/user_test.go +++ b/pkg/secrethub/user_test.go @@ -15,6 +15,12 @@ import ( "github.com/secrethub/secrethub-go/internals/crypto" ) +const ( + username = "dev1" + fullName = "Developer Uno" + email = "dev1@testing.com" +) + func TestSignup(t *testing.T) { // Arrange @@ -25,10 +31,6 @@ func TestSignup(t *testing.T) { client: newClient(cred1, opts), } - username := "dev1" - fullName := "Developer Uno" - email := "dev1@testing.com" - expectedCreateUserRequest := api.CreateUserRequest{ Username: username, FullName: fullName, @@ -155,10 +157,6 @@ func TestGetUser(t *testing.T) { newClient(cred1, opts), ) - username := "dev1" - fullName := "Developer Uno" - email := "dev1@testing.com" - now := time.Now().UTC() expectedResponse := &api.User{ AccountID: uuid.New(), @@ -241,10 +239,6 @@ func TestGetMyUser(t *testing.T) { newClient(cred1, opts), ) - username := "dev1" - fullName := "Developer Uno" - email := "dev1@testing.com" - now := time.Now().UTC() expected := &api.User{ AccountID: uuid.New(), From b9122d1d884b4bf1aa4ee21315273eebac5c5c54 Mon Sep 17 00:00:00 2001 From: Simon Barendse Date: Wed, 6 Mar 2019 16:18:56 +0100 Subject: [PATCH 06/20] Rename metadataList variable Because it is a map, not a list. --- internals/crypto/ciphertext.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/internals/crypto/ciphertext.go b/internals/crypto/ciphertext.go index 56178dc6..b952bb42 100644 --- a/internals/crypto/ciphertext.go +++ b/internals/crypto/ciphertext.go @@ -100,27 +100,26 @@ func (ec encodedCiphertext) metadata() (encodedCiphertextMetadata, error) { // newEncodedCiphertextMetadata creates a new encodedCiphertextMetadata from a map of metadata. // Input of {"param": "foo", "second": "bar"} outputs "param=foo,second=bar". -func newEncodedCiphertextMetadata(metadataList map[string]string) encodedCiphertextMetadata { - metadata := "" - +func newEncodedCiphertextMetadata(metadata map[string]string) encodedCiphertextMetadata { // Sort all the keys of the metadataList so that metadata is always in alphabetical order. - keys := make([]string, len(metadataList)) + keys := make([]string, len(metadata)) i := 0 - for k := range metadataList { + for k := range metadata { keys[i] = k i++ } sort.Strings(keys) + res := "" for _, k := range keys { separator := "" - if len(metadata) > 0 { + if len(res) > 0 { separator = "," } - metadata = fmt.Sprintf("%s%s%s=%s", metadata, separator, k, metadataList[k]) + res = fmt.Sprintf("%s%s%s=%s", res, separator, k, metadata[k]) } - return encodedCiphertextMetadata(metadata) + return encodedCiphertextMetadata(res) } // getValue returns a value from metadata. From 5c187937043fffbebe3a2ede564ba2e98ca28951 Mon Sep 17 00:00:00 2001 From: Simon Barendse Date: Thu, 7 Mar 2019 11:46:41 +0100 Subject: [PATCH 07/20] Create encode and decode functions for ciphertexts The encode and decode functions work on strings, where the marshal json functions work on bytes. These bytes also differ in that they contain quotes around the string, which the strings of encode and decode do not. --- internals/crypto/rsa.go | 124 ++++++++++++++++++----------- internals/crypto/rsa_test.go | 10 ++- internals/crypto/symmetric.go | 63 +++++++++------ internals/crypto/symmetric_test.go | 22 ++++- 4 files changed, 145 insertions(+), 74 deletions(-) diff --git a/internals/crypto/rsa.go b/internals/crypto/rsa.go index 4419ef81..028249dc 100644 --- a/internals/crypto/rsa.go +++ b/internals/crypto/rsa.go @@ -358,8 +358,8 @@ type CiphertextRSAAES struct { rsa CiphertextRSA } -// MarshalJSON encodes the ciphertext in a string. -func (ct CiphertextRSAAES) MarshalJSON() ([]byte, error) { +// Encode encodes the ciphertext in a string. +func (ct CiphertextRSAAES) Encode() string { data := base64.StdEncoding.EncodeToString(ct.aes.Data) metadata := newEncodedCiphertextMetadata(map[string]string{ @@ -367,64 +367,79 @@ func (ct CiphertextRSAAES) MarshalJSON() ([]byte, error) { "key": base64.StdEncoding.EncodeToString(ct.rsa.Data), }) - return json.Marshal(fmt.Sprintf("%s$%s$%s", algorithmRSAAES, data, metadata)) + return fmt.Sprintf("%s$%s$%s", algorithmRSAAES, data, metadata) } -// UnmarshalJSON decodes a string into a ciphertext. -func (ct *CiphertextRSAAES) UnmarshalJSON(b []byte) error { - var s string - err := json.Unmarshal(b, &s) - if err != nil { - return err - } - - if s == "" { - return nil - } +// MarshalJSON encodes the ciphertext in JSON. +func (ct CiphertextRSAAES) MarshalJSON() ([]byte, error) { + return json.Marshal(ct.Encode()) +} - encoded, err := newEncodedCiphertext(s) +// DecodeCiphertextRSAAES decodes an encoded ciphertext string to an CiphertextRSAAES. +func DecodeCiphertextRSAAES(ct string) (CiphertextRSAAES, error) { + encoded, err := newEncodedCiphertext(ct) if err != nil { - return err + return CiphertextRSAAES{}, err } algorithm, err := encoded.algorithm() if err != nil { - return errio.Error(err) + return CiphertextRSAAES{}, errio.Error(err) } if algorithm != algorithmRSAAES { - return ErrWrongAlgorithm + return CiphertextRSAAES{}, ErrWrongAlgorithm } encryptedData, err := encoded.data() if err != nil { - return errio.Error(err) + return CiphertextRSAAES{}, errio.Error(err) } metadata, err := encoded.metadata() if err != nil { - return errio.Error(err) + return CiphertextRSAAES{}, errio.Error(err) } aesNonce, err := metadata.getDecodedValue("nonce") if err != nil { - return errio.Error(err) + return CiphertextRSAAES{}, errio.Error(err) } aesKey, err := metadata.getDecodedValue("key") if err != nil { - return errio.Error(err) + return CiphertextRSAAES{}, errio.Error(err) } - ct.aes = CiphertextAES{ - Data: encryptedData, - Nonce: aesNonce, + return CiphertextRSAAES{ + aes: CiphertextAES{ + Data: encryptedData, + Nonce: aesNonce, + }, + rsa: CiphertextRSA{ + Data: aesKey, + }, + }, nil +} + +// UnmarshalJSON decodes JSON into a ciphertext. +func (ct *CiphertextRSAAES) UnmarshalJSON(b []byte) error { + if len(b) == 0 { + return nil } - ct.rsa = CiphertextRSA{ - Data: aesKey, + var s string + err := json.Unmarshal(b, &s) + if err != nil { + return err } + ciphertext, err := DecodeCiphertextRSAAES(s) + if err != nil { + return err + } + + *ct = ciphertext return nil } @@ -433,45 +448,60 @@ type CiphertextRSA struct { Data []byte } -// MarshalJSON encodes the ciphertext in a string. -func (ct CiphertextRSA) MarshalJSON() ([]byte, error) { +// Encode encodes the ciphertext in a string. +func (ct CiphertextRSA) Encode() string { encodedKey := base64.StdEncoding.EncodeToString(ct.Data) + return fmt.Sprintf("%s$%s$", algorithmRSA, encodedKey) +} - return json.Marshal(fmt.Sprintf("%s$%s$", algorithmRSA, encodedKey)) +// MarshalJSON encodes the ciphertext in JSON. +func (ct CiphertextRSA) MarshalJSON() ([]byte, error) { + return json.Marshal(ct.Encode()) } -// UnmarshalJSON decodes a string into a ciphertext. -func (ct *CiphertextRSA) UnmarshalJSON(b []byte) error { - var s string - err := json.Unmarshal(b, &s) +// DecodeCiphertextRSA decodes an encoded ciphertext string to an CiphertextRSA. +func DecodeCiphertextRSA(ct string) (CiphertextRSA, error) { + encoded, err := newEncodedCiphertext(ct) if err != nil { - return err + return CiphertextRSA{}, err } - if s == "" { - return nil + algorithm, err := encoded.algorithm() + if err != nil { + return CiphertextRSA{}, errio.Error(err) } - encoded, err := newEncodedCiphertext(s) - if err != nil { - return err + if algorithm != algorithmRSA { + return CiphertextRSA{}, ErrWrongAlgorithm } - algorithm, err := encoded.algorithm() + encryptedData, err := encoded.data() if err != nil { - return errio.Error(err) + return CiphertextRSA{}, errio.Error(err) } - if algorithm != algorithmRSA { - return ErrWrongAlgorithm + return CiphertextRSA{ + Data: encryptedData, + }, nil +} + +// UnmarshalJSON decodes JSON into a ciphertext. +func (ct *CiphertextRSA) UnmarshalJSON(b []byte) error { + if len(b) == 0 { + return nil } - encryptedData, err := encoded.data() + var s string + err := json.Unmarshal(b, &s) if err != nil { - return errio.Error(err) + return err } - ct.Data = encryptedData + ciphertext, err := DecodeCiphertextRSA(s) + if err != nil { + return err + } + *ct = ciphertext return nil } diff --git a/internals/crypto/rsa_test.go b/internals/crypto/rsa_test.go index 2341d511..12a1e8e4 100644 --- a/internals/crypto/rsa_test.go +++ b/internals/crypto/rsa_test.go @@ -233,7 +233,15 @@ func TestCiphertextRSA_MarshalJSON(t *testing.T) { } for name, tc := range cases { - t.Run(name, func(t *testing.T) { + t.Run(name+" encoded", func(t *testing.T) { + // Act + actual := tc.ciphertext.Encode() + + // Assert + assert.Equal(t, actual, tc.expected) + }) + + t.Run(name+" json", func(t *testing.T) { // Act actual, err := tc.ciphertext.MarshalJSON() assert.OK(t, err) diff --git a/internals/crypto/symmetric.go b/internals/crypto/symmetric.go index 09772d4d..198993f7 100644 --- a/internals/crypto/symmetric.go +++ b/internals/crypto/symmetric.go @@ -143,62 +143,79 @@ type CiphertextAES struct { Nonce []byte } -// MarshalJSON encodes the ciphertext in a string. -func (ct CiphertextAES) MarshalJSON() ([]byte, error) { +// Encode encodes the ciphertext in a string. +func (ct CiphertextAES) Encode() string { data := base64.StdEncoding.EncodeToString(ct.Data) metadata := newEncodedCiphertextMetadata(map[string]string{ "nonce": base64.StdEncoding.EncodeToString(ct.Nonce), }) - return json.Marshal(fmt.Sprintf("%s$%s$%s", algorithmAES, data, metadata)) + return fmt.Sprintf("%s$%s$%s", algorithmAES, data, metadata) } -// UnmarshalJSON decodes a string into a ciphertext. -func (ct *CiphertextAES) UnmarshalJSON(b []byte) error { - var s string - err := json.Unmarshal(b, &s) - if err != nil { - return err - } - - if s == "" { - return nil - } +// MarshalJSON encodes the ciphertext in JSON. +func (ct CiphertextAES) MarshalJSON() ([]byte, error) { + return json.Marshal(ct.Encode()) +} - encoded, err := newEncodedCiphertext(s) +// DecodeCiphertextAES decodes an encoded ciphertext string to an CiphertextAES. +func DecodeCiphertextAES(ct string) (CiphertextAES, error) { + encoded, err := newEncodedCiphertext(ct) if err != nil { - return err + return CiphertextAES{}, err } algorithm, err := encoded.algorithm() if err != nil { - return errio.Error(err) + return CiphertextAES{}, errio.Error(err) } if algorithm != algorithmAES { - return ErrWrongAlgorithm + return CiphertextAES{}, ErrWrongAlgorithm } encryptedData, err := encoded.data() if err != nil { - return errio.Error(err) + return CiphertextAES{}, errio.Error(err) } metadata, err := encoded.metadata() if err != nil { - return errio.Error(err) + return CiphertextAES{}, errio.Error(err) } aesNonce, err := metadata.getDecodedValue("nonce") if err != nil { - return errio.Error(err) + return CiphertextAES{}, errio.Error(err) } - ct.Data = encryptedData - ct.Nonce = aesNonce + return CiphertextAES{ + Data: encryptedData, + Nonce: aesNonce, + }, nil +} +// UnmarshalJSON decodes JSON into a ciphertext. +func (ct *CiphertextAES) UnmarshalJSON(b []byte) error { + if len(b) == 0 { + return nil + } + + var s string + err := json.Unmarshal(b, &s) + if err != nil { + return err + } + + ciphertext, err := DecodeCiphertextAES(s) + if err != nil { + return err + } + + *ct = ciphertext return nil + } // generateNonce generates a nonce of a given length. diff --git a/internals/crypto/symmetric_test.go b/internals/crypto/symmetric_test.go index b3ba4afc..3945671f 100644 --- a/internals/crypto/symmetric_test.go +++ b/internals/crypto/symmetric_test.go @@ -52,7 +52,7 @@ func TestSymmetricKey_HMAC(t *testing.T) { } } -func TestCiphertextAES_MarshallJSON(t *testing.T) { +func TestCiphertextAES_MarshalJSON(t *testing.T) { cases := map[string]struct { ciphertext CiphertextAES expected string @@ -67,7 +67,15 @@ func TestCiphertextAES_MarshallJSON(t *testing.T) { } for name, tc := range cases { - t.Run(name, func(t *testing.T) { + t.Run(name+" encoded", func(t *testing.T) { + // Act + actual := tc.ciphertext.Encode() + + // Assert + assert.Equal(t, actual, tc.expected) + }) + + t.Run(name+" json", func(t *testing.T) { // Act actual, err := tc.ciphertext.MarshalJSON() assert.OK(t, err) @@ -100,7 +108,15 @@ func TestCiphertextRSAAES_MarshalJSON(t *testing.T) { } for name, tc := range cases { - t.Run(name, func(t *testing.T) { + t.Run(name+" encoded", func(t *testing.T) { + // Act + actual := tc.ciphertext.Encode() + + // Assert + assert.Equal(t, actual, tc.expected) + }) + + t.Run(name+" json", func(t *testing.T) { // Act actual, err := tc.ciphertext.MarshalJSON() assert.OK(t, err) From 1730a86e012d53e039f101d3071cee8700742d28 Mon Sep 17 00:00:00 2001 From: Simon Barendse Date: Thu, 7 Mar 2019 15:34:26 +0100 Subject: [PATCH 08/20] Add FromString and ToString to encode/decode functions To make it more explicit that they accept and return strings, not bytes. --- internals/crypto/rsa.go | 24 ++++++++++++------------ internals/crypto/rsa_test.go | 2 +- internals/crypto/symmetric.go | 12 ++++++------ internals/crypto/symmetric_test.go | 4 ++-- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/internals/crypto/rsa.go b/internals/crypto/rsa.go index 028249dc..0aead837 100644 --- a/internals/crypto/rsa.go +++ b/internals/crypto/rsa.go @@ -358,8 +358,8 @@ type CiphertextRSAAES struct { rsa CiphertextRSA } -// Encode encodes the ciphertext in a string. -func (ct CiphertextRSAAES) Encode() string { +// EncodeToString encodes the ciphertext in a string. +func (ct CiphertextRSAAES) EncodeToString() string { data := base64.StdEncoding.EncodeToString(ct.aes.Data) metadata := newEncodedCiphertextMetadata(map[string]string{ @@ -372,11 +372,11 @@ func (ct CiphertextRSAAES) Encode() string { // MarshalJSON encodes the ciphertext in JSON. func (ct CiphertextRSAAES) MarshalJSON() ([]byte, error) { - return json.Marshal(ct.Encode()) + return json.Marshal(ct.EncodeToString()) } -// DecodeCiphertextRSAAES decodes an encoded ciphertext string to an CiphertextRSAAES. -func DecodeCiphertextRSAAES(ct string) (CiphertextRSAAES, error) { +// DecodeCiphertextRSAAESFromString decodes an encoded ciphertext string to an CiphertextRSAAES. +func DecodeCiphertextRSAAESFromString(ct string) (CiphertextRSAAES, error) { encoded, err := newEncodedCiphertext(ct) if err != nil { return CiphertextRSAAES{}, err @@ -434,7 +434,7 @@ func (ct *CiphertextRSAAES) UnmarshalJSON(b []byte) error { return err } - ciphertext, err := DecodeCiphertextRSAAES(s) + ciphertext, err := DecodeCiphertextRSAAESFromString(s) if err != nil { return err } @@ -448,19 +448,19 @@ type CiphertextRSA struct { Data []byte } -// Encode encodes the ciphertext in a string. -func (ct CiphertextRSA) Encode() string { +// EncodeToString encodes the ciphertext in a string. +func (ct CiphertextRSA) EncodeToString() string { encodedKey := base64.StdEncoding.EncodeToString(ct.Data) return fmt.Sprintf("%s$%s$", algorithmRSA, encodedKey) } // MarshalJSON encodes the ciphertext in JSON. func (ct CiphertextRSA) MarshalJSON() ([]byte, error) { - return json.Marshal(ct.Encode()) + return json.Marshal(ct.EncodeToString()) } -// DecodeCiphertextRSA decodes an encoded ciphertext string to an CiphertextRSA. -func DecodeCiphertextRSA(ct string) (CiphertextRSA, error) { +// DecodeCiphertextRSAFromString decodes an encoded ciphertext string to an CiphertextRSA. +func DecodeCiphertextRSAFromString(ct string) (CiphertextRSA, error) { encoded, err := newEncodedCiphertext(ct) if err != nil { return CiphertextRSA{}, err @@ -497,7 +497,7 @@ func (ct *CiphertextRSA) UnmarshalJSON(b []byte) error { return err } - ciphertext, err := DecodeCiphertextRSA(s) + ciphertext, err := DecodeCiphertextRSAFromString(s) if err != nil { return err } diff --git a/internals/crypto/rsa_test.go b/internals/crypto/rsa_test.go index 12a1e8e4..1b906610 100644 --- a/internals/crypto/rsa_test.go +++ b/internals/crypto/rsa_test.go @@ -235,7 +235,7 @@ func TestCiphertextRSA_MarshalJSON(t *testing.T) { for name, tc := range cases { t.Run(name+" encoded", func(t *testing.T) { // Act - actual := tc.ciphertext.Encode() + actual := tc.ciphertext.EncodeToString() // Assert assert.Equal(t, actual, tc.expected) diff --git a/internals/crypto/symmetric.go b/internals/crypto/symmetric.go index 198993f7..f845b7f4 100644 --- a/internals/crypto/symmetric.go +++ b/internals/crypto/symmetric.go @@ -143,8 +143,8 @@ type CiphertextAES struct { Nonce []byte } -// Encode encodes the ciphertext in a string. -func (ct CiphertextAES) Encode() string { +// EncodeToString encodes the ciphertext in a string. +func (ct CiphertextAES) EncodeToString() string { data := base64.StdEncoding.EncodeToString(ct.Data) metadata := newEncodedCiphertextMetadata(map[string]string{ @@ -156,11 +156,11 @@ func (ct CiphertextAES) Encode() string { // MarshalJSON encodes the ciphertext in JSON. func (ct CiphertextAES) MarshalJSON() ([]byte, error) { - return json.Marshal(ct.Encode()) + return json.Marshal(ct.EncodeToString()) } -// DecodeCiphertextAES decodes an encoded ciphertext string to an CiphertextAES. -func DecodeCiphertextAES(ct string) (CiphertextAES, error) { +// DecodeCiphertextAESFromString decodes an encoded ciphertext string to an CiphertextAES. +func DecodeCiphertextAESFromString(ct string) (CiphertextAES, error) { encoded, err := newEncodedCiphertext(ct) if err != nil { return CiphertextAES{}, err @@ -208,7 +208,7 @@ func (ct *CiphertextAES) UnmarshalJSON(b []byte) error { return err } - ciphertext, err := DecodeCiphertextAES(s) + ciphertext, err := DecodeCiphertextAESFromString(s) if err != nil { return err } diff --git a/internals/crypto/symmetric_test.go b/internals/crypto/symmetric_test.go index 3945671f..27382f7e 100644 --- a/internals/crypto/symmetric_test.go +++ b/internals/crypto/symmetric_test.go @@ -69,7 +69,7 @@ func TestCiphertextAES_MarshalJSON(t *testing.T) { for name, tc := range cases { t.Run(name+" encoded", func(t *testing.T) { // Act - actual := tc.ciphertext.Encode() + actual := tc.ciphertext.EncodeToString() // Assert assert.Equal(t, actual, tc.expected) @@ -110,7 +110,7 @@ func TestCiphertextRSAAES_MarshalJSON(t *testing.T) { for name, tc := range cases { t.Run(name+" encoded", func(t *testing.T) { // Act - actual := tc.ciphertext.Encode() + actual := tc.ciphertext.EncodeToString() // Assert assert.Equal(t, actual, tc.expected) From 5dc7306b8a1acdb0396135783e540ce0b9c3e8de Mon Sep 17 00:00:00 2001 From: Simon Barendse Date: Thu, 7 Mar 2019 16:20:53 +0100 Subject: [PATCH 09/20] Rename variables of strings to decode to s instead of ct --- internals/crypto/rsa.go | 8 ++++---- internals/crypto/symmetric.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internals/crypto/rsa.go b/internals/crypto/rsa.go index 0aead837..c892326b 100644 --- a/internals/crypto/rsa.go +++ b/internals/crypto/rsa.go @@ -376,8 +376,8 @@ func (ct CiphertextRSAAES) MarshalJSON() ([]byte, error) { } // DecodeCiphertextRSAAESFromString decodes an encoded ciphertext string to an CiphertextRSAAES. -func DecodeCiphertextRSAAESFromString(ct string) (CiphertextRSAAES, error) { - encoded, err := newEncodedCiphertext(ct) +func DecodeCiphertextRSAAESFromString(s string) (CiphertextRSAAES, error) { + encoded, err := newEncodedCiphertext(s) if err != nil { return CiphertextRSAAES{}, err } @@ -460,8 +460,8 @@ func (ct CiphertextRSA) MarshalJSON() ([]byte, error) { } // DecodeCiphertextRSAFromString decodes an encoded ciphertext string to an CiphertextRSA. -func DecodeCiphertextRSAFromString(ct string) (CiphertextRSA, error) { - encoded, err := newEncodedCiphertext(ct) +func DecodeCiphertextRSAFromString(s string) (CiphertextRSA, error) { + encoded, err := newEncodedCiphertext(s) if err != nil { return CiphertextRSA{}, err } diff --git a/internals/crypto/symmetric.go b/internals/crypto/symmetric.go index f845b7f4..56536600 100644 --- a/internals/crypto/symmetric.go +++ b/internals/crypto/symmetric.go @@ -160,8 +160,8 @@ func (ct CiphertextAES) MarshalJSON() ([]byte, error) { } // DecodeCiphertextAESFromString decodes an encoded ciphertext string to an CiphertextAES. -func DecodeCiphertextAESFromString(ct string) (CiphertextAES, error) { - encoded, err := newEncodedCiphertext(ct) +func DecodeCiphertextAESFromString(s string) (CiphertextAES, error) { + encoded, err := newEncodedCiphertext(s) if err != nil { return CiphertextAES{}, err } From 0700d69467be6d1efe4180e7b3fd103968dc4e49 Mon Sep 17 00:00:00 2001 From: Simon Barendse Date: Thu, 7 Mar 2019 16:52:11 +0100 Subject: [PATCH 10/20] Make the fields of CiphertextRSAAES public --- internals/crypto/ciphertext_test.go | 2 +- internals/crypto/rsa.go | 22 +++++++++++----------- internals/crypto/symmetric_test.go | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/internals/crypto/ciphertext_test.go b/internals/crypto/ciphertext_test.go index 8378c415..a455fc45 100644 --- a/internals/crypto/ciphertext_test.go +++ b/internals/crypto/ciphertext_test.go @@ -36,7 +36,7 @@ func TestRSAAES_Success(t *testing.T) { t.Fatal(err) } - if bytes.Equal(ciphertext.aes.Data, input) { + if bytes.Equal(ciphertext.AES.Data, input) { t.Error("encrypted data equals the original data") } diff --git a/internals/crypto/rsa.go b/internals/crypto/rsa.go index c892326b..0d79d335 100644 --- a/internals/crypto/rsa.go +++ b/internals/crypto/rsa.go @@ -73,8 +73,8 @@ func (pub RSAPublicKey) Encrypt(data []byte) (CiphertextRSAAES, error) { } return CiphertextRSAAES{ - aes: aesData, - rsa: rsaData, + AES: aesData, + RSA: rsaData, }, nil } @@ -229,12 +229,12 @@ func NewRSAPrivateKey(privateKey *rsa.PrivateKey) RSAPrivateKey { // then uses the decrypted symmetric key to decrypt the rest of the ciphertext // with the AES-GCM algorithm. func (prv RSAPrivateKey) Decrypt(ciphertext CiphertextRSAAES) ([]byte, error) { - aesKeyData, err := prv.Unwrap(ciphertext.rsa) + aesKeyData, err := prv.Unwrap(ciphertext.RSA) if err != nil { return nil, err } - return NewSymmetricKey(aesKeyData).Decrypt(ciphertext.aes) + return NewSymmetricKey(aesKeyData).Decrypt(ciphertext.AES) } // Unwrap uses the private key to decrypt a small ciphertext that has been encrypted @@ -354,17 +354,17 @@ func (prv RSAPrivateKey) ExportPrivateKeyWithPassphrase(pass string) ([]byte, er // CiphertextRSAAES represents data encrypted with AES-GCM, where the AES key is encrypted with RSA-OAEP. type CiphertextRSAAES struct { - aes CiphertextAES - rsa CiphertextRSA + AES CiphertextAES + RSA CiphertextRSA } // EncodeToString encodes the ciphertext in a string. func (ct CiphertextRSAAES) EncodeToString() string { - data := base64.StdEncoding.EncodeToString(ct.aes.Data) + data := base64.StdEncoding.EncodeToString(ct.AES.Data) metadata := newEncodedCiphertextMetadata(map[string]string{ - "nonce": base64.StdEncoding.EncodeToString(ct.aes.Nonce), - "key": base64.StdEncoding.EncodeToString(ct.rsa.Data), + "nonce": base64.StdEncoding.EncodeToString(ct.AES.Nonce), + "key": base64.StdEncoding.EncodeToString(ct.RSA.Data), }) return fmt.Sprintf("%s$%s$%s", algorithmRSAAES, data, metadata) @@ -412,11 +412,11 @@ func DecodeCiphertextRSAAESFromString(s string) (CiphertextRSAAES, error) { } return CiphertextRSAAES{ - aes: CiphertextAES{ + AES: CiphertextAES{ Data: encryptedData, Nonce: aesNonce, }, - rsa: CiphertextRSA{ + RSA: CiphertextRSA{ Data: aesKey, }, }, nil diff --git a/internals/crypto/symmetric_test.go b/internals/crypto/symmetric_test.go index 27382f7e..7bd05883 100644 --- a/internals/crypto/symmetric_test.go +++ b/internals/crypto/symmetric_test.go @@ -95,11 +95,11 @@ func TestCiphertextRSAAES_MarshalJSON(t *testing.T) { }{ "success": { ciphertext: CiphertextRSAAES{ - aes: CiphertextAES{ + AES: CiphertextAES{ Data: []byte("aes_data"), Nonce: []byte("nonce_data"), }, - rsa: CiphertextRSA{ + RSA: CiphertextRSA{ Data: []byte("rsa_data"), }, }, From a8019c179240c43b3d1b7ab16c760c909757becb Mon Sep 17 00:00:00 2001 From: Marc Mackenbach Date: Fri, 8 Mar 2019 10:35:20 +0100 Subject: [PATCH 11/20] move gopher and change introduction --- README.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a01eb61e..0b2b59e8 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,16 @@ -# Go SecretHub +
Gopher
+ +# Go client for SecretHub [![GoDoc](http://img.shields.io/badge/godoc-reference-blue.svg)][godoc] [![Travis CI](https://travis-ci.org/secrethub/secrethub-go.svg?branch=master)][travis-ci] [![GolangCI](https://golangci.com/badges/github.com/secrethub/secrethub-go.svg)][golang-ci] [![Go Report Card](https://goreportcard.com/badge/github.com/secrethub/secrethub-go)][goreportcard] -The official [SecretHub][secrethub] Go client library. +[SecretHub][secrethub] is a developer tool to help you keep database passwords, API tokens, and other secrets out of IT automation scripts. -> SecretHub is a developer tool to help you keep database passwords, API tokens, and other secrets out of IT automation scripts. +Packages in `secrethub-go` provide clients for various SecretHub APIs. -Gopher ## Installation From 2fb1524cfb03ca5bfbfd074ca9860104c920da64 Mon Sep 17 00:00:00 2001 From: Marc Mackenbach Date: Fri, 8 Mar 2019 10:40:17 +0100 Subject: [PATCH 12/20] align gopher right --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 0b2b59e8..184843ec 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -
Gopher
- # Go client for SecretHub [![GoDoc](http://img.shields.io/badge/godoc-reference-blue.svg)][godoc] @@ -11,6 +9,7 @@ Packages in `secrethub-go` provide clients for various SecretHub APIs. +Gopher ## Installation From 2d96d48c52d71cdc4684e4b7cd4161a44158af24 Mon Sep 17 00:00:00 2001 From: Marc Mackenbach Date: Fri, 8 Mar 2019 10:45:13 +0100 Subject: [PATCH 13/20] shrink and center gopher --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 184843ec..709ca7c0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +

+ Gopher +

+ # Go client for SecretHub [![GoDoc](http://img.shields.io/badge/godoc-reference-blue.svg)][godoc] @@ -9,7 +13,7 @@ Packages in `secrethub-go` provide clients for various SecretHub APIs. -Gopher + ## Installation From 62caf00303ad1559a353ab11ec0170c683596470 Mon Sep 17 00:00:00 2001 From: Marc Mackenbach Date: Fri, 8 Mar 2019 11:56:52 +0100 Subject: [PATCH 14/20] rephrase intro --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 709ca7c0..2d812868 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ [SecretHub][secrethub] is a developer tool to help you keep database passwords, API tokens, and other secrets out of IT automation scripts. -Packages in `secrethub-go` provide clients for various SecretHub APIs. +`secrethub-go` provides a client for various SecretHub APIs. From f2fee6c64d4b31691f0ff89f0f94616b7337b227 Mon Sep 17 00:00:00 2001 From: Simon Barendse Date: Fri, 8 Mar 2019 15:28:42 +0100 Subject: [PATCH 15/20] Add EmailVerified field to api.User This will be returned in the next version of the server. --- internals/api/user.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/internals/api/user.go b/internals/api/user.go index 23a39344..f6def74e 100644 --- a/internals/api/user.go +++ b/internals/api/user.go @@ -39,13 +39,14 @@ var ( // User represents a SecretHub user. type User struct { - AccountID *uuid.UUID `json:"account_id"` - PublicKey []byte `json:"public_key"` - Username string `json:"username"` - FullName string `json:"full_name"` - Email string `json:"user_email,omitempty"` // Optional, private information is only returned for yourself - CreatedAt *time.Time `json:"created_at,omitempty"` // Optional, private information is only returned for yourself - LastLoginAt *time.Time `json:"last_login_at,omitempty"` // Optional, private information is only returned for yourself + AccountID *uuid.UUID `json:"account_id"` + PublicKey []byte `json:"public_key"` + Username string `json:"username"` + FullName string `json:"full_name"` + Email string `json:"user_email,omitempty"` // Optional, private information is only returned for yourself + EmailVerified bool `json:"email_verified,omitempty"` // Optional, private information is only returned for yourself + CreatedAt *time.Time `json:"created_at,omitempty"` // Optional, private information is only returned for yourself + LastLoginAt *time.Time `json:"last_login_at,omitempty"` // Optional, private information is only returned for yourself } // PrettyName returns a printable string with the username and full name. From 27e6e14ef28c3a7c498e51ae049860b37a7acd10 Mon Sep 17 00:00:00 2001 From: Marc Mackenbach Date: Fri, 8 Mar 2019 16:17:08 +0100 Subject: [PATCH 16/20] move image back down to look more familiar --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 2d812868..ba72281d 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,6 @@ -

- Gopher -

- # Go client for SecretHub + [![GoDoc](http://img.shields.io/badge/godoc-reference-blue.svg)][godoc] [![Travis CI](https://travis-ci.org/secrethub/secrethub-go.svg?branch=master)][travis-ci] [![GolangCI](https://golangci.com/badges/github.com/secrethub/secrethub-go.svg)][golang-ci] @@ -13,7 +10,7 @@ `secrethub-go` provides a client for various SecretHub APIs. - +Gopher ## Installation From 5c3ee88d15e43372e1b1bfeb112c78f9084bae5a Mon Sep 17 00:00:00 2001 From: Simon Barendse Date: Mon, 18 Mar 2019 14:29:44 +0100 Subject: [PATCH 17/20] Create a client.Me() service to retrieve own user and repos --- pkg/secrethub/client.go | 9 ++++++++ pkg/secrethub/fakeclient/client.go | 5 +++++ pkg/secrethub/me.go | 33 ++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 pkg/secrethub/me.go diff --git a/pkg/secrethub/client.go b/pkg/secrethub/client.go index c55abd10..8db3b6ad 100644 --- a/pkg/secrethub/client.go +++ b/pkg/secrethub/client.go @@ -11,6 +11,7 @@ type Client interface { AccessRules() AccessRuleService Accounts() AccountService Dirs() DirService + Me() MeService Orgs() OrgService Repos() RepoService Secrets() SecretService @@ -45,6 +46,14 @@ func (c clientAdapter) Dirs() DirService { return newDirService(c.client) } +// Me returns a MeService. +func (c clientAdapter) Me() MeService { + return newMeService( + newRepoService(c.client), + newUserService(c.client), + ) +} + // Orgs returns an OrgService. func (c clientAdapter) Orgs() OrgService { return newOrgService(c.client) diff --git a/pkg/secrethub/fakeclient/client.go b/pkg/secrethub/fakeclient/client.go index 9994c660..e146e88a 100644 --- a/pkg/secrethub/fakeclient/client.go +++ b/pkg/secrethub/fakeclient/client.go @@ -29,6 +29,11 @@ func (c Client) Dirs() secrethub.DirService { return c.DirService } +// Me implements the secrethub.Client interface. +func (c Client) Me() secrethub.MeService { + return nil +} + // Orgs implements the secrethub.Client interface. func (c Client) Orgs() secrethub.OrgService { return c.OrgService diff --git a/pkg/secrethub/me.go b/pkg/secrethub/me.go new file mode 100644 index 00000000..cc7dce41 --- /dev/null +++ b/pkg/secrethub/me.go @@ -0,0 +1,33 @@ +package secrethub + +import "github.com/secrethub/secrethub-go/internals/api" + +// MeService handles operations on the authenticated account. +type MeService interface { + // Repos retrieves all repositories of the current user. + Repos() ([]*api.Repo, error) + // User retrieves the current users details. + User() (*api.User, error) +} + +type meService struct { + repoService RepoService + userService UserService +} + +func newMeService(repoService RepoService, userService UserService) MeService { + return meService{ + repoService: repoService, + userService: userService, + } +} + +// Repos retrieves all repositories of the current user. +func (ms meService) Repos() ([]*api.Repo, error) { + return ms.repoService.ListMine() +} + +// User retrieves the current users details. +func (ms meService) User() (*api.User, error) { + return ms.userService.Me() +} From 3a7cceac804fb901f4c9e30271deea249cda0aae Mon Sep 17 00:00:00 2001 From: Simon Barendse Date: Mon, 18 Mar 2019 14:55:44 +0100 Subject: [PATCH 18/20] Add SendVerificationEmail function to the MeService --- pkg/secrethub/client.go | 1 + pkg/secrethub/http.go | 14 +++++++++++--- pkg/secrethub/me.go | 13 ++++++++++++- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/pkg/secrethub/client.go b/pkg/secrethub/client.go index 8db3b6ad..7cb6b38e 100644 --- a/pkg/secrethub/client.go +++ b/pkg/secrethub/client.go @@ -49,6 +49,7 @@ func (c clientAdapter) Dirs() DirService { // Me returns a MeService. func (c clientAdapter) Me() MeService { return newMeService( + c.client, newRepoService(c.client), newUserService(c.client), ) diff --git a/pkg/secrethub/http.go b/pkg/secrethub/http.go index fda48df1..af2f8518 100644 --- a/pkg/secrethub/http.go +++ b/pkg/secrethub/http.go @@ -22,9 +22,10 @@ const ( baseURLPath = "/v1" // Current account - pathMeUser = "%s/me/user" - pathMeRepos = "%s/me/repos" - pathMeKey = "%s/me/key" + pathMeUser = "%s/me/user" + pathMeRepos = "%s/me/repos" + pathMeKey = "%s/me/key" + pathMeEmailVerification = "%s/me/user/verification-email" // Account pathAccount = "%s/account/%s" @@ -153,6 +154,13 @@ func (c *httpClient) GetMyUser() (*api.User, error) { return out, errio.Error(err) } +// SendVerificationEmail sends an email to the users registered email address for them to prove they +// own that email address. +func (c *httpClient) SendVerificationEmail() error { + rawURL := fmt.Sprintf(pathMeEmailVerification, c.base) + return c.post(rawURL, http.StatusCreated, nil, nil) +} + // Accounts // GetAccount returns the account for a name diff --git a/pkg/secrethub/me.go b/pkg/secrethub/me.go index cc7dce41..a729b095 100644 --- a/pkg/secrethub/me.go +++ b/pkg/secrethub/me.go @@ -8,15 +8,20 @@ type MeService interface { Repos() ([]*api.Repo, error) // User retrieves the current users details. User() (*api.User, error) + // SendVerificationEmail sends an email to the authenticated user's registered email address + // for them to prove they own that email address. + SendVerificationEmail() error } type meService struct { + client client repoService RepoService userService UserService } -func newMeService(repoService RepoService, userService UserService) MeService { +func newMeService(client client, repoService RepoService, userService UserService) MeService { return meService{ + client: client, repoService: repoService, userService: userService, } @@ -31,3 +36,9 @@ func (ms meService) Repos() ([]*api.Repo, error) { func (ms meService) User() (*api.User, error) { return ms.userService.Me() } + +// SendVerificationEmail sends an email to the authenticated user's registered email address +// for them to prove they own that email address. +func (ms meService) SendVerificationEmail() error { + return ms.client.httpClient.SendVerificationEmail() +} From 8c70d3167d90a5c36075ea31e73be0018deb730f Mon Sep 17 00:00:00 2001 From: Simon Barendse Date: Tue, 19 Mar 2019 09:34:33 +0100 Subject: [PATCH 19/20] Rename functions on the me-service to use verbs for actions --- pkg/secrethub/me.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/secrethub/me.go b/pkg/secrethub/me.go index cc7dce41..17c27979 100644 --- a/pkg/secrethub/me.go +++ b/pkg/secrethub/me.go @@ -4,10 +4,10 @@ import "github.com/secrethub/secrethub-go/internals/api" // MeService handles operations on the authenticated account. type MeService interface { - // Repos retrieves all repositories of the current user. - Repos() ([]*api.Repo, error) - // User retrieves the current users details. - User() (*api.User, error) + // ListRepos retrieves all repositories of the current user. + ListRepos() ([]*api.Repo, error) + // GetUser retrieves the current users details. + GetUser() (*api.User, error) } type meService struct { @@ -22,12 +22,12 @@ func newMeService(repoService RepoService, userService UserService) MeService { } } -// Repos retrieves all repositories of the current user. -func (ms meService) Repos() ([]*api.Repo, error) { +// ListRepos retrieves all repositories of the current user. +func (ms meService) ListRepos() ([]*api.Repo, error) { return ms.repoService.ListMine() } -// User retrieves the current users details. -func (ms meService) User() (*api.User, error) { +// GetUser retrieves the current users details. +func (ms meService) GetUser() (*api.User, error) { return ms.userService.Me() } From b904aa31ba9a83a7fd3d3e704de22943539586ed Mon Sep 17 00:00:00 2001 From: Simon Barendse Date: Tue, 19 Mar 2019 10:21:03 +0100 Subject: [PATCH 20/20] Construct the new repo- and userservices inside the me service constructor --- pkg/secrethub/client.go | 6 +----- pkg/secrethub/me.go | 6 +++--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/pkg/secrethub/client.go b/pkg/secrethub/client.go index 7cb6b38e..b918d91d 100644 --- a/pkg/secrethub/client.go +++ b/pkg/secrethub/client.go @@ -48,11 +48,7 @@ func (c clientAdapter) Dirs() DirService { // Me returns a MeService. func (c clientAdapter) Me() MeService { - return newMeService( - c.client, - newRepoService(c.client), - newUserService(c.client), - ) + return newMeService(c.client) } // Orgs returns an OrgService. diff --git a/pkg/secrethub/me.go b/pkg/secrethub/me.go index 80c2112e..174cec06 100644 --- a/pkg/secrethub/me.go +++ b/pkg/secrethub/me.go @@ -19,11 +19,11 @@ type meService struct { userService UserService } -func newMeService(client client, repoService RepoService, userService UserService) MeService { +func newMeService(client client) MeService { return meService{ client: client, - repoService: repoService, - userService: userService, + repoService: newRepoService(client), + userService: newUserService(client), } }