From 1ab7fc5b258d77c6a4d37a872c35702caff7a41d Mon Sep 17 00:00:00 2001
From: Yordan Kinkov <yordan.kinkov@vereign.com>
Date: Wed, 12 Oct 2022 11:24:19 +0300
Subject: [PATCH] Add nolint rule to allow string usage as key for context
 value

---
 internal/service/policy/service.go      | 5 ++---
 internal/service/policy/service_test.go | 2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/internal/service/policy/service.go b/internal/service/policy/service.go
index 6eea0de5..dbc1d9f5 100644
--- a/internal/service/policy/service.go
+++ b/internal/service/policy/service.go
@@ -283,15 +283,14 @@ func (s *Service) queryCacheKey(group, policyName, version string) string {
 func HeadersMiddleware() func(http.Handler) http.Handler {
 	return func(h http.Handler) http.Handler {
 		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
-			req := r
 			headers := map[string]string{}
 
 			// get all http headers and add them to a newly initialized request context.
 			for name := range r.Header {
 				headers[name] = r.Header.Get(name)
 			}
-			ctx := context.WithValue(r.Context(), HeadersKey, headers)
-			req = r.WithContext(ctx)
+			ctx := context.WithValue(r.Context(), HeadersKey, headers) //nolint:all
+			req := r.WithContext(ctx)
 
 			// call initial handler.
 			h.ServeHTTP(w, req)
diff --git a/internal/service/policy/service_test.go b/internal/service/policy/service_test.go
index 0cb619a4..26167735 100644
--- a/internal/service/policy/service_test.go
+++ b/internal/service/policy/service_test.go
@@ -318,7 +318,7 @@ func TestService_Evaluate(t *testing.T) {
 		},
 		{
 			name: "policy accessing headers is evaluated successfully",
-			ctx:  context.WithValue(context.Background(), policy.HeadersKey, map[string]interface{}{"Authorization": "my-token"}),
+			ctx:  context.WithValue(context.Background(), policy.HeadersKey, map[string]interface{}{"Authorization": "my-token"}), //nolint:all
 			req:  testReq(),
 			regocache: &policyfakes.FakeRegoCache{
 				GetStub: func(key string) (*rego.PreparedEvalQuery, bool) {
-- 
GitLab