From bf7747514e9c19fbd9b3f81df7f3bdfd0a65b501 Mon Sep 17 00:00:00 2001 From: Tom Proctor Date: Tue, 18 May 2021 14:32:41 +0100 Subject: [PATCH 1/2] Fix unhandled errors --- Makefile | 5 ++++- internal/config/config_test.go | 1 + internal/provider/provider.go | 8 +++++++- main.go | 7 ++++++- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 5c4b095..21d8bb4 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,10 @@ lint: --timeout 10m \ --enable gofmt \ --enable gosimple \ - --enable govet + --enable govet \ + --enable errcheck \ + --enable ineffassign \ + --enable unused test: gotestsum --format=short-verbose $(CI_TEST_ARGS) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 07e8fed..69016bb 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -48,6 +48,7 @@ func TestParseParametersFromYaml(t *testing.T) { err := yaml.Unmarshal([]byte(certsSPCYaml), &secretProviderClass) require.NoError(t, err) paramsBytes, err := json.Marshal(secretProviderClass.Spec.Parameters) + require.NoError(t, err) // This is now the form the provider receives the data in. params, err := parseParameters(hclog.NewNullLogger(), string(paramsBytes)) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 56b2ed6..9909dba 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -142,7 +142,10 @@ func generateRequest(client *api.Client, secret config.Secret) (*api.Request, er req.Params = queryParams } if secret.SecretArgs != nil { - req.SetJSONBody(secret.SecretArgs) + err := req.SetJSONBody(secret.SecretArgs) + if err != nil { + return nil, err + } } return req, nil @@ -174,6 +177,9 @@ func (p *provider) getSecret(ctx context.Context, client *api.Client, secretConf key := cacheKey{secretPath: secretConfig.SecretPath, method: secretConfig.Method} if secret, cached = p.cache[key]; !cached { req, err := generateRequest(client, secretConfig) + if err != nil { + return "", err + } p.logger.Debug("Requesting secret", "secretConfig", secretConfig, "method", req.Method, "path", req.URL.Path, "params", req.Params) secret, err = vaultclient.Do(ctx, client, req) diff --git a/main.go b/main.go index 4587be8..738d5b4 100644 --- a/main.go +++ b/main.go @@ -93,7 +93,12 @@ func realMain(logger hclog.Logger) error { Addr: *healthAddr, Handler: mux, } - defer ms.Shutdown(context.Background()) + defer func() { + err := ms.Shutdown(context.Background()) + if err != nil { + logger.Error("Error shutting down health handler", "err", err) + } + }() mux.HandleFunc("/health/ready", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusOK) From cbb5754257778feb65746deb90a753a73db03629 Mon Sep 17 00:00:00 2001 From: Tom Proctor Date: Tue, 18 May 2021 14:51:08 +0100 Subject: [PATCH 2/2] Add changelog note --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c26d4fe..3639ceb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Unreleased +BUGS: + +* Added missing error handling when transforming SecretProviderClass config to a Vault request [[GH-97](https://github.com/hashicorp/vault-csi-provider/pull/97)] + ## 0.2.0 (April 14th, 2021) FEATURES: