Skip to content

Commit

Permalink
Fix unhandled errors (#97)
Browse files Browse the repository at this point in the history
* Fix unhandled errors

* Add changelog note
  • Loading branch information
tomhjp authored May 24, 2021
1 parent 24ba07d commit ff21e5c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 7 additions & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ff21e5c

Please sign in to comment.