Skip to content
Snippets Groups Projects
Commit 1ab7fc5b authored by Yordan Kinkov's avatar Yordan Kinkov
Browse files

Add nolint rule to allow string usage as key for context value

parent f31bc4f6
Branches
Tags
No related merge requests found
...@@ -283,15 +283,14 @@ func (s *Service) queryCacheKey(group, policyName, version string) string { ...@@ -283,15 +283,14 @@ func (s *Service) queryCacheKey(group, policyName, version string) string {
func HeadersMiddleware() func(http.Handler) http.Handler { func HeadersMiddleware() func(http.Handler) http.Handler {
return func(h http.Handler) http.Handler { return func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
req := r
headers := map[string]string{} headers := map[string]string{}
// get all http headers and add them to a newly initialized request context. // get all http headers and add them to a newly initialized request context.
for name := range r.Header { for name := range r.Header {
headers[name] = r.Header.Get(name) headers[name] = r.Header.Get(name)
} }
ctx := context.WithValue(r.Context(), HeadersKey, headers) ctx := context.WithValue(r.Context(), HeadersKey, headers) //nolint:all
req = r.WithContext(ctx) req := r.WithContext(ctx)
// call initial handler. // call initial handler.
h.ServeHTTP(w, req) h.ServeHTTP(w, req)
......
...@@ -318,7 +318,7 @@ func TestService_Evaluate(t *testing.T) { ...@@ -318,7 +318,7 @@ func TestService_Evaluate(t *testing.T) {
}, },
{ {
name: "policy accessing headers is evaluated successfully", 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(), req: testReq(),
regocache: &policyfakes.FakeRegoCache{ regocache: &policyfakes.FakeRegoCache{
GetStub: func(key string) (*rego.PreparedEvalQuery, bool) { GetStub: func(key string) (*rego.PreparedEvalQuery, bool) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment