From 518da0f766fcc3a51a4263771ccad80b7281de73 Mon Sep 17 00:00:00 2001 From: Daniel Adam Date: Wed, 4 Sep 2024 22:44:59 +0200 Subject: [PATCH] Upgrade to github.com/grpc-ecosystem/go-grpc-middleware/v2 --- go.mod | 11 +- go.sum | 29 +--- pkg/net/grpc/auth.go | 10 +- pkg/net/grpc/authFromOutgoingMD.go | 8 +- pkg/net/grpc/interceptor.go | 2 +- pkg/net/grpc/server/makeDefaultOptions.go | 174 ++++++++-------------- 6 files changed, 84 insertions(+), 150 deletions(-) diff --git a/go.mod b/go.mod index 3836b8b02..63349cf85 100644 --- a/go.mod +++ b/go.mod @@ -18,7 +18,7 @@ require ( github.com/google/uuid v1.6.0 github.com/gorilla/mux v1.8.1 github.com/gorilla/websocket v1.5.3 - github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 + github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 github.com/hashicorp/go-multierror v1.1.1 github.com/helm/chart-testing/v3 v3.11.0 @@ -56,12 +56,12 @@ require ( go.uber.org/zap v1.27.0 golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 golang.org/x/net v0.28.0 - golang.org/x/oauth2 v0.22.0 + golang.org/x/oauth2 v0.23.0 golang.org/x/sync v0.8.0 google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 google.golang.org/grpc v1.66.0 - google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.4.0 + google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1 google.golang.org/protobuf v1.34.2 gopkg.in/yaml.v3 v3.0.1 ) @@ -85,7 +85,6 @@ require ( github.com/goccy/go-json v0.10.3 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.5.4 // indirect - github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 // indirect github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect @@ -140,8 +139,8 @@ require ( go.opentelemetry.io/proto/otlp v1.3.1 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.26.0 // indirect - golang.org/x/sys v0.24.0 // indirect - golang.org/x/text v0.17.0 // indirect + golang.org/x/sys v0.25.0 // indirect + golang.org/x/text v0.18.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/go.sum b/go.sum index 87eb5f9de..2fa430fa9 100644 --- a/go.sum +++ b/go.sum @@ -13,7 +13,6 @@ github.com/Masterminds/sprig v2.15.0+incompatible h1:0gSxPGWS9PAr7U2NsQ2YQg6juRD github.com/Masterminds/sprig v2.15.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o= github.com/aokoli/goutils v1.0.1 h1:7fpzNGoJ3VA8qcrm++XEE1QUe0mIwNeLa02Nwq7RDkg= github.com/aokoli/goutils v1.0.1/go.mod h1:SijmP0QR8LtwsmDs8Yii5Z/S4trXFGFC2oO5g9DP+DQ= -github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY= github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= @@ -73,9 +72,7 @@ github.com/go-co-op/gocron/v2 v2.11.0/go.mod h1:xY7bJxGazKam1cz04EebrlP4S9q4iWdi github.com/go-json-experiment/json v0.0.0-20240815174924-0599f16bf0e2 h1:T01ryfhob+ta3ADOh2B2FLA1cFLVOaQJH/iwh22rIFM= github.com/go-json-experiment/json v0.0.0-20240815174924-0599f16bf0e2/go.mod h1:uDEMZSTQMj7V6Lxdrx4ZwchmHEGdICbjuY+GQd7j9LM= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -137,8 +134,6 @@ github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWS github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/go-grpc-middleware v1.2.0/go.mod h1:mJzapYve32yjrKlk9GbyCZHuPgZsrbyIbyKhSzOpg6s= -github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI= -github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8= github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 h1:pRhl55Yx1eC7BZ1N+BBWwnKaMyD8uC+34TLdndZMAKk= github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0/go.mod h1:XKMd7iuf/RGPSMJ/U4HP0zS2Z9Fh8Ps9a+6X26m/tmI= github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjwqUPTYmYuemVOx+Ys= @@ -389,21 +384,17 @@ go.opentelemetry.io/proto/otlp v1.3.1 h1:TrMUixzpM0yuc/znrFTP9MMRh8trP93mkCiDVeX go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR0XqQ7niQU+8= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= -go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU= -go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc= -go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -464,8 +455,8 @@ golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= -golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= +golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -490,7 +481,6 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -501,8 +491,8 @@ golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg= -golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -525,8 +515,8 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= -golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= -golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -537,7 +527,6 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191029190741-b9c20aec41a5/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200417140056-c07e33ef3290/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= @@ -555,7 +544,6 @@ google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9Ywl google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto/googleapis/api v0.0.0-20240903143218-8af14fe29dc1 h1:hjSy6tcFQZ171igDaN5QHOw2n6vx40juYbC/x67CEhc= @@ -570,8 +558,8 @@ google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3Iji google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM= google.golang.org/grpc v1.66.0 h1:DibZuoBznOxbDQxRINckZcUvnCEvrW9pcWIE2yF9r1c= google.golang.org/grpc v1.66.0/go.mod h1:s3/l6xSSCURdVfAnL+TqCNMyTDAGN6+lZeVxnZR128Y= -google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.4.0 h1:9SxA29VM43MF5Z9dQu694wmY5t8E/Gxr7s+RSxiIDmc= -google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.4.0/go.mod h1:yZOK5zhQMiALmuweVdIVoQPa6eIJyXn2B9g5dJDhqX4= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1 h1:F29+wU6Ee6qgu9TddPgooOdaqsxTMunOoj8KA5yuS5A= +google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.5.1/go.mod h1:5KF+wpkbTSbGcR9zteSqZV6fqFOWBl4Yde8En8MryZA= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -602,7 +590,6 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/pkg/net/grpc/auth.go b/pkg/net/grpc/auth.go index 4bf60c16b..f867b20bb 100644 --- a/pkg/net/grpc/auth.go +++ b/pkg/net/grpc/auth.go @@ -5,8 +5,8 @@ import ( "fmt" "github.com/golang-jwt/jwt/v5" - grpc_auth "github.com/grpc-ecosystem/go-grpc-middleware/auth" - "github.com/grpc-ecosystem/go-grpc-middleware/util/metautils" + "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/auth" + "github.com/grpc-ecosystem/go-grpc-middleware/v2/metadata" pkgJwt "github.com/plgd-dev/hub/v2/pkg/security/jwt" "google.golang.org/grpc" "google.golang.org/grpc/codes" @@ -49,7 +49,7 @@ type ( func ValidateJWTWithValidator(validator Validator, claims ClaimsFunc) Interceptor { return func(ctx context.Context, method string) (context.Context, error) { - token, err := grpc_auth.AuthFromMD(ctx, "bearer") + token, err := auth.AuthFromMD(ctx, "bearer") if err != nil { return nil, err } @@ -63,14 +63,14 @@ func ValidateJWTWithValidator(validator Validator, claims ClaimsFunc) Intercepto // CtxWithToken stores token to ctx of request. func CtxWithToken(ctx context.Context, token string) context.Context { - niceMD := metautils.ExtractOutgoing(ctx) + niceMD := metadata.ExtractOutgoing(ctx) niceMD.Set(authorizationKey, fmt.Sprintf("%s %s", "bearer", token)) return niceMD.ToOutgoing(ctx) } // CtxWithIncomingToken stores token to ctx of response. func CtxWithIncomingToken(ctx context.Context, token string) context.Context { - niceMD := metautils.ExtractIncoming(ctx) + niceMD := metadata.ExtractIncoming(ctx) niceMD.Set(authorizationKey, fmt.Sprintf("%s %s", "bearer", token)) return niceMD.ToIncoming(ctx) } diff --git a/pkg/net/grpc/authFromOutgoingMD.go b/pkg/net/grpc/authFromOutgoingMD.go index afe52dc75..9e406983a 100644 --- a/pkg/net/grpc/authFromOutgoingMD.go +++ b/pkg/net/grpc/authFromOutgoingMD.go @@ -4,8 +4,8 @@ import ( "context" "strings" - grpc_auth "github.com/grpc-ecosystem/go-grpc-middleware/auth" - "github.com/grpc-ecosystem/go-grpc-middleware/util/metautils" + "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/auth" + "github.com/grpc-ecosystem/go-grpc-middleware/v2/metadata" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) @@ -21,7 +21,7 @@ func errUnauthenticated(scheme string) error { // TokenFromOutgoingMD extracts token stored by CtxWithToken. func TokenFromOutgoingMD(ctx context.Context) (string, error) { expectedScheme := "bearer" - val := metautils.ExtractOutgoing(ctx).Get(headerAuthorize) + val := metadata.ExtractOutgoing(ctx).Get(headerAuthorize) if val == "" { return "", errUnauthenticated(expectedScheme) } @@ -37,7 +37,7 @@ func TokenFromOutgoingMD(ctx context.Context) (string, error) { // TokenFromMD is a helper function for extracting the :authorization header from the gRPC metadata of the request. func TokenFromMD(ctx context.Context) (string, error) { - return grpc_auth.AuthFromMD(ctx, "bearer") + return auth.AuthFromMD(ctx, "bearer") } // OwnerFromOutgoingTokenMD extracts ownerClaim from token stored by CtxWithToken. diff --git a/pkg/net/grpc/interceptor.go b/pkg/net/grpc/interceptor.go index 7408f60e8..b674de08d 100644 --- a/pkg/net/grpc/interceptor.go +++ b/pkg/net/grpc/interceptor.go @@ -3,7 +3,7 @@ package grpc import ( "context" - grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" + grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware/v2" "google.golang.org/grpc" ) diff --git a/pkg/net/grpc/server/makeDefaultOptions.go b/pkg/net/grpc/server/makeDefaultOptions.go index d5c8cbdb3..5666efcad 100644 --- a/pkg/net/grpc/server/makeDefaultOptions.go +++ b/pkg/net/grpc/server/makeDefaultOptions.go @@ -4,19 +4,14 @@ import ( context "context" "math" "strings" - "time" "github.com/golang-jwt/jwt/v5" - grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware" - "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap" - grpc_ctxtags "github.com/grpc-ecosystem/go-grpc-middleware/tags" - "github.com/plgd-dev/hub/v2/grpc-gateway/pb" + "github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/logging" "github.com/plgd-dev/hub/v2/http-gateway/serverMux" pkgMath "github.com/plgd-dev/hub/v2/internal/math" "github.com/plgd-dev/hub/v2/pkg/log" pkgGrpc "github.com/plgd-dev/hub/v2/pkg/net/grpc" pkgJwt "github.com/plgd-dev/hub/v2/pkg/security/jwt" - "github.com/plgd-dev/hub/v2/resource-aggregate/commands" "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" @@ -31,6 +26,10 @@ const ( requestKey = "request" ) +type loggerCtxMarker struct{} + +var loggerCtxMarkerKey = &loggerCtxMarker{} + var defaultCodeToLevel = map[codes.Code]zapcore.Level{ codes.OK: log.DebugLevel, codes.Canceled: log.DebugLevel, @@ -60,82 +59,59 @@ func DefaultCodeToLevel(code codes.Code) zapcore.Level { return log.ErrorLevel } -func setLogBasicLabels(m map[string]interface{}, req interface{}) { - if d, ok := req.(interface{ GetDeviceId() string }); ok && d.GetDeviceId() != "" { - log.SetLogValue(m, log.DeviceIDKey, d.GetDeviceId()) - } - if r, ok := req.(interface{ GetResourceId() *commands.ResourceId }); ok { - log.SetLogValue(m, log.DeviceIDKey, r.GetResourceId().GetDeviceId()) - log.SetLogValue(m, log.ResourceHrefKey, r.GetResourceId().GetHref()) - } - if r, ok := req.(interface{ GetCorrelationId() string }); ok && r.GetCorrelationId() != "" { - log.SetLogValue(m, log.CorrelationIDKey, r.GetCorrelationId()) - } -} - -func setLogFilterLabels(m map[string]interface{}, req interface{}) { - if req == nil { - return - } - if r, ok := req.(interface { - GetCommandFilter() []pb.GetPendingCommandsRequest_Command - }); ok { - commandFiler := make([]string, 0, len(r.GetCommandFilter())) - for _, f := range r.GetCommandFilter() { - commandFiler = append(commandFiler, f.String()) +func toZapFields(fields logging.Fields) []zap.Field { + fs := make([]zap.Field, 0, len(fields)/2) + fieldsIterator := fields.Iterator() + for fieldsIterator.Next() { + key, value := fieldsIterator.At() + switch v := value.(type) { + case string: + fs = append(fs, zap.String(key, v)) + case int: + fs = append(fs, zap.Int(key, v)) + case bool: + fs = append(fs, zap.Bool(key, v)) + default: + fs = append(fs, zap.Any(key, v)) } - log.SetLogValue(m, log.CommandFilterKey, commandFiler) - } - if r, ok := req.(interface{ GetResourceIdFilter() []string }); ok { - log.SetLogValue(m, log.ResourceIDFilterKey, r.GetResourceIdFilter()) - } - if r, ok := req.(interface{ GetDeviceIdFilter() []string }); ok { - log.SetLogValue(m, log.DeviceIDFilterKey, r.GetDeviceIdFilter()) - } - if r, ok := req.(interface{ GetTypeFilter() []string }); ok { - log.SetLogValue(m, log.TypeFilterKey, r.GetTypeFilter()) } + return fs } -func setLogSubscriptionLabels(m map[string]interface{}, sub *pb.SubscribeToEvents) { - switch sub.GetAction().(type) { - case *pb.SubscribeToEvents_CreateSubscription_: - m[log.SubActionKey] = "createSubscription" - case *pb.SubscribeToEvents_CancelSubscription_: - m[log.SubActionKey] = "cancelSubscription" - } - setLogFilterLabels(m, sub.GetCreateSubscription()) - eventFilter := make([]string, 0, len(sub.GetCreateSubscription().GetEventFilter())) - for _, e := range sub.GetCreateSubscription().GetEventFilter() { - eventFilter = append(eventFilter, e.String()) - } - log.SetLogValue(m, log.EventFilterKey, eventFilter) - log.SetLogValue(m, log.CorrelationIDKey, sub.GetCorrelationId()) -} - -// CodeGenRequestFieldExtractor is a function that relies on code-generated functions that export log fields from requests. -// These are usually coming from a protoc-plugin that generates additional information based on custom field options. -func CodeGenRequestFieldExtractor(fullMethod string, req interface{}) map[string]interface{} { - m := grpc_ctxtags.CodeGenRequestFieldExtractor(fullMethod, req) - if m == nil { - m = make(map[string]interface{}) +func defaultMessageFields(ctx context.Context, req, resp map[string]interface{}, duration zapcore.Field) logging.Fields { + fields := logging.ExtractFields(ctx) + var newFields logging.Fields + newFields = append(newFields, log.DurationMSKey, math.Float32frombits(pkgMath.CastTo[uint32](duration.Integer))) + newFields = append(newFields, log.ProtocolKey, "GRPC") + fieldsIterator := fields.Iterator() + for fieldsIterator.Next() { + k, v := fieldsIterator.At() + if strings.EqualFold(k, grpcPrefixKey+"."+requestKey+"."+log.StartTimeKey) { + newFields = append(newFields, log.StartTimeKey, v) + continue + } + if strings.EqualFold(k, grpcPrefixKey+"."+requestKey+"."+log.DeviceIDKey) { + newFields = append(newFields, log.DeviceIDKey, v) + continue + } + if strings.EqualFold(k, grpcPrefixKey+"."+requestKey+"."+log.CorrelationIDKey) { + newFields = append(newFields, log.CorrelationIDKey, v) + continue + } + if strings.HasPrefix(k, grpcPrefixKey+"."+requestKey+".") { + req[strings.TrimPrefix(k, grpcPrefixKey+"."+requestKey+".")] = v + } } - setLogBasicLabels(m, req) - setLogFilterLabels(m, req) - if sub, ok := req.(*pb.SubscribeToEvents); ok { - setLogSubscriptionLabels(m, sub) + if len(req) > 0 { + newFields = append(newFields, log.RequestKey, req) } - method := strings.SplitAfterN(fullMethod, "/", 3) - if len(method) == 3 { - m["service"] = strings.ReplaceAll(method[1], "/", "") - m[log.MethodKey] = strings.ReplaceAll(method[2], "/", "") + if len(resp) > 0 { + newFields = append(newFields, log.ResponseKey, resp) } - m[log.StartTimeKey] = time.Now() - - if len(m) > 0 { - return m + if deadline, ok := ctx.Deadline(); ok { + newFields = append(newFields, log.DeadlineKey, deadline) } - return nil + return newFields } func defaultMessageProducer(ctx context.Context, ctxLogger context.Context, msg string, level zapcore.Level, code codes.Code, err error, duration zapcore.Field) { @@ -156,43 +132,19 @@ func defaultMessageProducer(ctx context.Context, ctxLogger context.Context, msg log.SubKey: sub, } } - tags := grpc_ctxtags.Extract(ctx) - newTags := grpc_ctxtags.NewTags() - newTags.Set(log.DurationMSKey, math.Float32frombits(pkgMath.CastTo[uint32](duration.Integer))) - newTags.Set(log.ProtocolKey, "GRPC") - for k, v := range tags.Values() { - if strings.EqualFold(k, grpcPrefixKey+"."+requestKey+"."+log.StartTimeKey) { - newTags.Set(log.StartTimeKey, v) - continue - } - if strings.EqualFold(k, grpcPrefixKey+"."+requestKey+"."+log.DeviceIDKey) { - newTags.Set(log.DeviceIDKey, v) - continue - } - if strings.EqualFold(k, grpcPrefixKey+"."+requestKey+"."+log.CorrelationIDKey) { - newTags.Set(log.CorrelationIDKey, v) - continue - } - if strings.HasPrefix(k, grpcPrefixKey+"."+requestKey+".") { - req[strings.TrimPrefix(k, grpcPrefixKey+"."+requestKey+".")] = v - } - } - if len(req) > 0 { - newTags.Set(log.RequestKey, req) - } - if len(resp) > 0 { - newTags.Set(log.ResponseKey, resp) - } - if deadline, ok := ctx.Deadline(); ok { - newTags.Set(log.DeadlineKey, deadline) - } - ctx = grpc_ctxtags.SetInContext(ctxLogger, newTags) - ctxzap.Extract(ctx).Check(level, msg).Write() + logging.InjectFields(ctxLogger, defaultMessageFields(ctx, req, resp, duration)) + + logger, ok := ctx.Value(loggerCtxMarkerKey).(*zap.Logger) + if !ok || logger == nil { + return + } + loggerWithFields := logger.With(toZapFields(logging.ExtractFields(ctx))...) + loggerWithFields.Check(level, msg).Write() } func MakeDefaultMessageProducer(logger *zap.Logger) func(ctx context.Context, msg string, level zapcore.Level, code codes.Code, err error, duration zapcore.Field) { - ctxLogger := ctxzap.ToContext(context.Background(), logger) + ctxLogger := context.WithValue(context.Background(), loggerCtxMarkerKey, logger) return func(ctx context.Context, msg string, level zapcore.Level, code codes.Code, err error, duration zapcore.Field) { defaultMessageProducer(ctx, ctxLogger, msg, level, code, err, duration) } @@ -270,12 +222,8 @@ func MakeDefaultOptions(auth pkgGrpc.AuthInterceptors, logger log.Logger, tracer return []grpc.ServerOption{ grpc.StatsHandler(otelgrpc.NewServerHandler(otelgrpc.WithTracerProvider(tracerProvider))), - grpc.StreamInterceptor(grpc_middleware.ChainStreamServer( - streamInterceptors..., - )), - grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer( - unaryInterceptors..., - )), + grpc.ChainStreamInterceptor(streamInterceptors...), + grpc.ChainUnaryInterceptor(unaryInterceptors...), }, nil }