diff --git a/internal/pkg/vault/secrets.go b/internal/pkg/vault/secrets.go index f2a84a62..a8ea55c5 100644 --- a/internal/pkg/vault/secrets.go +++ b/internal/pkg/vault/secrets.go @@ -374,6 +374,10 @@ func (c *Client) getAllKeys(subPath string) (map[string]string, error) { _ = resp.Body.Close() }() + if resp.StatusCode == 404 { + return nil, pkg.NewErrPathNotFound(fmt.Sprintf("Received a '%d' response from the secret store", resp.StatusCode)) + } + if resp.StatusCode < 200 || resp.StatusCode > 299 { return nil, pkg.NewErrSecretStore(fmt.Sprintf("Received a '%d' response from the secret store", resp.StatusCode)) } diff --git a/internal/pkg/vault/secrets_test.go b/internal/pkg/vault/secrets_test.go index 9d1e9ee1..b55a8a0d 100644 --- a/internal/pkg/vault/secrets_test.go +++ b/internal/pkg/vault/secrets_test.go @@ -381,6 +381,7 @@ func TestConcurrentSecretClientTokenRenewals(t *testing.T) { func TestHttpSecretStoreManager_GetValue(t *testing.T) { TestConnError := pkg.NewErrSecretStore("testing conn error") + TestConnErrorPathNotFound := pkg.NewErrPathNotFound("testing path error") testData := getTestSecretsData() tests := []struct { name string @@ -465,16 +466,17 @@ func TestHttpSecretStoreManager_GetValue(t *testing.T) { }, }, { - name: "Handle HTTP error", + name: "Handle HTTP no path error", path: testPath, keys: []string{"Does not exist"}, expectedValues: nil, expectError: true, - expectedErrorType: TestConnError, + expectedErrorType: TestConnErrorPathNotFound, expectedDoCallNum: 1, caller: &ErrorMockCaller{ - ReturnError: true, + ReturnError: false, StatusCode: 404, + ErrorType: pkg.NewErrPathNotFound("Not found"), }, }, { @@ -487,7 +489,8 @@ func TestHttpSecretStoreManager_GetValue(t *testing.T) { expectedDoCallNum: 1, caller: &ErrorMockCaller{ ReturnError: false, - StatusCode: 404, + StatusCode: 400, + ErrorType: pkg.NewErrSecretStore("Error"), }, }, { @@ -496,7 +499,7 @@ func TestHttpSecretStoreManager_GetValue(t *testing.T) { keys: []string{"one"}, expectedValues: nil, expectError: true, - expectedErrorType: TestConnError, + expectedErrorType: TestConnErrorPathNotFound, expectedDoCallNum: 1, caller: &InMemoryMockCaller{ Data: testData, @@ -790,6 +793,7 @@ type ErrorMockCaller struct { StatusCode int ReturnError bool DoCallCount int + ErrorType error } func (emc *ErrorMockCaller) Do(_ *http.Request) (*http.Response, error) { @@ -797,7 +801,7 @@ func (emc *ErrorMockCaller) Do(_ *http.Request) (*http.Response, error) { if emc.ReturnError { return &http.Response{ StatusCode: emc.StatusCode, - }, pkg.NewErrSecretStore("testing conn error") + }, emc.ErrorType } return &http.Response{ diff --git a/pkg/errors.go b/pkg/errors.go index e3c923a7..ea19e098 100644 --- a/pkg/errors.go +++ b/pkg/errors.go @@ -46,3 +46,17 @@ func (scnf ErrSecretsNotFound) Error() string { func NewErrSecretsNotFound(keys []string) ErrSecretsNotFound { return ErrSecretsNotFound{keys: keys} } + +// ErrPathNotFound error when a secret path cannot be found. +type ErrPathNotFound struct { + description string +} + +func (e ErrPathNotFound) Error() string { + return fmt.Sprintf("Error retreiving secret path: '%s'", e.description) +} + +// NewErrPathNotFound creates a new ErrSecretsNotFound error. +func NewErrPathNotFound(description string) ErrPathNotFound { + return ErrPathNotFound{description: description} +}