Skip to content

Commit

Permalink
feat: bcs-webconsole支持泳道特性
Browse files Browse the repository at this point in the history
  • Loading branch information
LidolLxf committed Jan 20, 2025
1 parent 6d5fb52 commit 96ca27f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
5 changes: 5 additions & 0 deletions bcs-services/bcs-webconsole/console/components/bcs/bcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"fmt"
"time"

"github.com/Tencent/bk-bcs/bcs-common/pkg/header"

"github.com/Tencent/bk-bcs/bcs-services/bcs-webconsole/console/components"
"github.com/Tencent/bk-bcs/bcs-services/bcs-webconsole/console/config"
)
Expand Down Expand Up @@ -61,6 +63,7 @@ func ListClusters(ctx context.Context, projectId string) ([]*Cluster, error) {

resp, err := components.GetClient().R().
SetContext(ctx).
SetHeaders(header.GetLaneIDByCtx(ctx)).
SetAuthToken(config.G.BCS.Token).
SetQueryParam("projectID", projectId).
Get(url)
Expand All @@ -83,6 +86,7 @@ func GetCluster(ctx context.Context, projectId, clusterId string) (*Cluster, err

resp, err := components.GetClient().R().
SetContext(ctx).
SetHeaders(header.GetLaneIDByCtx(ctx)).
SetAuthToken(config.G.BCS.Token).
Get(url)

Expand Down Expand Up @@ -128,6 +132,7 @@ func CreateTempToken(ctx context.Context, username, clusterId string) (*Token, e
}
resp, err := components.GetClient().R().
SetContext(ctx).
SetHeaders(header.GetLaneIDByCtx(ctx)).
SetAuthToken(config.G.BCS.Token).
SetBody(data).
Post(url)
Expand Down
3 changes: 3 additions & 0 deletions bcs-services/bcs-webconsole/console/components/bcs/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"fmt"
"time"

"github.com/Tencent/bk-bcs/bcs-common/pkg/header"

"github.com/Tencent/bk-bcs/bcs-services/bcs-webconsole/console/components"
"github.com/Tencent/bk-bcs/bcs-services/bcs-webconsole/console/config"
"github.com/Tencent/bk-bcs/bcs-services/bcs-webconsole/console/storage"
Expand Down Expand Up @@ -62,6 +64,7 @@ func GetProject(ctx context.Context, bcsConf *config.BCSConf, projectIDOrCode st
url := fmt.Sprintf("%s/bcsapi/v4/bcsproject/v1/projects/%s", bcsConf.InnerHost, projectIDOrCode)
resp, err := components.GetClient().R().
SetContext(ctx).
SetHeaders(header.GetLaneIDByCtx(ctx)).
SetAuthToken(bcsConf.Token).
Get(url)

Expand Down
5 changes: 4 additions & 1 deletion bcs-services/bcs-webconsole/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/go-micro/plugins/v4/config/encoder/yaml v1.1.0
github.com/go-micro/plugins/v4/registry/etcd v1.1.0
github.com/go-micro/plugins/v4/server/http v1.1.1
github.com/go-redis/redis/v8 v8.11.4
github.com/go-redis/redis/v8 v8.11.5
github.com/go-resty/resty/v2 v2.12.0
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
Expand Down Expand Up @@ -92,6 +92,7 @@ require (
github.com/google/gofuzz v1.2.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
Expand Down Expand Up @@ -153,6 +154,7 @@ require (
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 // indirect
google.golang.org/protobuf v1.33.0 // indirect
Expand All @@ -169,6 +171,7 @@ require (
)

replace (
github.com/Tencent/bk-bcs/bcs-common => github.com/LidolLxf/bk-bcs/bcs-common v0.0.0-20250120075906-fd5988c50f3f
// 修复 IPv6 单栈 Bug
github.com/go-micro/plugins/v4/server/http => github.com/ifooth/go-micro-plugins/v4/server/http v0.0.0-20230207124152-a253b0517244
github.com/go-resty/resty/v2 => github.com/ifooth/resty/v2 v2.0.0-20230223083514-3015979960de
Expand Down
12 changes: 7 additions & 5 deletions bcs-services/bcs-webconsole/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/LidolLxf/bk-bcs/bcs-common v0.0.0-20250120075906-fd5988c50f3f h1:D4LsEhjZDXlZtWeqUrcZKlAwie3oFjxrFgpqIhtWlDI=
github.com/LidolLxf/bk-bcs/bcs-common v0.0.0-20250120075906-fd5988c50f3f/go.mod h1:Qp0cPdRU1wRBuv355f5MfVXqsvm97ICuD3suUOz6XOg=
github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA=
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
Expand All @@ -90,8 +92,6 @@ github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWX
github.com/Shopify/sarama v1.30.0/go.mod h1:zujlQQx1kzHsh4jfV1USnptCQrHAEZ2Hk8fTKCulPVs=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/Shopify/toxiproxy/v2 v2.1.6-0.20210914104332-15ea381dcdae/go.mod h1:/cvHQkZ1fst0EmZnA5dFtiQdWCNCFYzb+uE2vqVgvx0=
github.com/Tencent/bk-bcs/bcs-common v0.0.0-20240506114534-2223209a5716 h1:haBEaGtA9wk1HUqcRW9LGE7imCGyh/bkk7GgXQHWM4A=
github.com/Tencent/bk-bcs/bcs-common v0.0.0-20240506114534-2223209a5716/go.mod h1:BpINYXjhHwE2FCY6WeNHN5c5t7i2KNDSfCKTb1xM2oI=
github.com/Tencent/bk-bcs/bcs-services/pkg v0.0.0-20240506114534-2223209a5716 h1:PgkcHLBnwIsv6+KEBgGTaao6+SfQ77YGpAu6VCBgOvw=
github.com/Tencent/bk-bcs/bcs-services/pkg v0.0.0-20240506114534-2223209a5716/go.mod h1:SfBCJ6XeMiGD5e6fMmm617RCEqHoZ6SIFXs4p9hqE3s=
github.com/TencentBlueKing/bk-audit-go-sdk v0.0.6 h1:egd1gt7REtUB+fAGY1f5JoKZ6hN+B7TjslaIKUnwh4A=
Expand Down Expand Up @@ -158,7 +158,6 @@ github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY=
Expand Down Expand Up @@ -383,8 +382,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4=
github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
github.com/go-redis/redis/v8 v8.11.4 h1:kHoYkfZP6+pe04aFTnhDH6GDROa5yJdHJVNxV3F46Tg=
github.com/go-redis/redis/v8 v8.11.4/go.mod h1:2Z2wHZXdQpCDXEGzqMockDpNyYvi2l4Pxt6RJr792+w=
github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI=
github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
Expand Down Expand Up @@ -559,6 +558,7 @@ github.com/grpc-ecosystem/go-grpc-middleware v1.0.1-0.20190118093823-f849b5445de
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.14.6/go.mod h1:zdiPV4Yse/1gnckTHtghG4GkDEdKCRJduHpTxT3/jcw=
github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 h1:YBftPWNWd4WwGqtY2yeZL2ef8rHAxPBD8KFhJpmcqms=
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0/go.mod h1:YN5jB8ie0yfIUg6VvR9Kz84aCaG7AsGZnLjhHbUqwPg=
Expand Down Expand Up @@ -1549,6 +1549,8 @@ google.golang.org/genproto v0.0.0-20210310155132-4ce2db91004e/go.mod h1:FWY/as6D
google.golang.org/genproto v0.0.0-20210319143718-93e7006c17a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A=
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0=
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 h1:KAeGQVN3M9nD0/bQXnr/ClcEMJ968gUXJQ9pwfSynuQ=
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80/go.mod h1:cc8bqMqtv9gMOr0zHg2Vzff5ULhhL2IXP4sbcn32Dro=
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237 h1:RFiFrvy37/mpSpdySBDrUdipW/dHwsRwh3J3+A9VgT4=
google.golang.org/genproto/googleapis/api v0.0.0-20240318140521-94a12d6c2237/go.mod h1:Z5Iiy3jtmioajWHDGFk7CeugTyHtPvMHA4UTmUkyalE=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240318140521-94a12d6c2237 h1:NnYq6UN9ReLM9/Y01KWNOWyI5xQ9kbIms5GGJVwS/Yc=
Expand Down
9 changes: 7 additions & 2 deletions bcs-services/bcs-webconsole/route/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"strings"
"time"

"github.com/Tencent/bk-bcs/bcs-common/pkg/header"
"github.com/gin-gonic/gin"
"github.com/golang-jwt/jwt/v4"
"github.com/google/uuid"
Expand Down Expand Up @@ -82,7 +83,9 @@ func WebAuthRequired() gin.HandlerFunc {
}
c.Set("auth_context", authCtx)

c.Request = c.Request.WithContext(components.WithRequestIDValue(c.Request.Context(), authCtx.RequestId))
// 新增泳道特性
ctx := header.WithLaneIdCtx(c.Request.Context(), c.Request.Header)
c.Request = c.Request.WithContext(components.WithRequestIDValue(ctx, authCtx.RequestId))

c.Next()
}
Expand All @@ -97,7 +100,9 @@ func APIAuthRequired() gin.HandlerFunc {
}
c.Set("auth_context", authCtx)

c.Request = c.Request.WithContext(components.WithRequestIDValue(c.Request.Context(), authCtx.RequestId))
// 新增泳道特性
ctx := header.WithLaneIdCtx(c.Request.Context(), c.Request.Header)
c.Request = c.Request.WithContext(components.WithRequestIDValue(ctx, authCtx.RequestId))

if c.Request.Method == http.MethodOptions {
c.Next()
Expand Down

0 comments on commit 96ca27f

Please sign in to comment.