From 83a8c6eb1518ad13e3e5de7428233b33c29db6de Mon Sep 17 00:00:00 2001 From: Richard Kovacs Date: Mon, 27 Feb 2023 21:00:54 +0100 Subject: [PATCH] Format code (#229) * Format code * Fix gosec issue * Fix gosec issue --- pkg/metrics/prometheus_exporter.go | 3 ++- pkg/metrics/stats_reporter.go | 4 +--- providers/debug/main.go | 4 +--- providers/vault/pkg/vault/vault.go | 10 +++++++--- trousseau/pkg/health/health.go | 3 +-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/metrics/prometheus_exporter.go b/pkg/metrics/prometheus_exporter.go index aec1a47..eff6791 100644 --- a/pkg/metrics/prometheus_exporter.go +++ b/pkg/metrics/prometheus_exporter.go @@ -18,7 +18,8 @@ func servePrometheusExporter(metricsAddress string) error { exporter, err := prometheus.InstallNewPipeline(prometheus.Config{ DefaultHistogramBoundaries: []float64{ 0.1, 0.2, 0.3, 0.4, 0.5, 1, 1.5, 2, 2.5, 3.0, 5.0, 10.0, 15.0, 30.0, - }}, + }, + }, ) if err != nil { return fmt.Errorf("failed to register prometheus exporter: %w", err) diff --git a/pkg/metrics/stats_reporter.go b/pkg/metrics/stats_reporter.go index d4a309c..b6412dd 100644 --- a/pkg/metrics/stats_reporter.go +++ b/pkg/metrics/stats_reporter.go @@ -29,9 +29,7 @@ const ( GrpcOperationTypeValue = "grpc" ) -var ( - kmsRequest metric.Float64ValueRecorder -) +var kmsRequest metric.Float64ValueRecorder type reporter struct { meter metric.Meter diff --git a/providers/debug/main.go b/providers/debug/main.go index 602026c..36d0073 100644 --- a/providers/debug/main.go +++ b/providers/debug/main.go @@ -17,9 +17,7 @@ import ( const logEncoder = "console" -var ( - listenAddr = flag.String("listen-addr", "unix:///opt/trousseau-kms/debug/debug.socket", "gRPC listen address") -) +var listenAddr = flag.String("listen-addr", "unix:///opt/trousseau-kms/debug/debug.socket", "gRPC listen address") func main() { flag.Parse() diff --git a/providers/vault/pkg/vault/vault.go b/providers/vault/pkg/vault/vault.go index 855faf1..f0c8856 100644 --- a/providers/vault/pkg/vault/vault.go +++ b/providers/vault/pkg/vault/vault.go @@ -2,14 +2,13 @@ package vault import ( "encoding/base64" + "errors" "fmt" "net/http" "path" "reflect" "sync" - "errors" - vaultapi "github.com/hashicorp/vault/api" "github.com/ondat/trousseau/pkg/logger" "github.com/ondat/trousseau/pkg/providers" @@ -237,7 +236,12 @@ func (c *vaultWrapper) request(requestPath string, data interface{}) (*vaultapi. } else if resp == nil { return nil, fmt.Errorf("no response received for POST request on %s: %w", requestPath, err) } - defer resp.Body.Close() + + defer func() { + if err := resp.Body.Close(); err != nil { + klog.ErrorS(err, "Failed to close body") + } + }() if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("unexpected response code: %v received for POST request to %v", resp.StatusCode, requestPath) diff --git a/trousseau/pkg/health/health.go b/trousseau/pkg/health/health.go index ce51e76..84e6d4a 100644 --- a/trousseau/pkg/health/health.go +++ b/trousseau/pkg/health/health.go @@ -2,13 +2,12 @@ package health import ( "context" + "errors" "fmt" "net/http" "net/url" "time" - "errors" - "github.com/ondat/trousseau/pkg/logger" "github.com/ondat/trousseau/pkg/providers" "github.com/ondat/trousseau/pkg/utils"