diff --git a/apiserver/httpserver/utils/handler_test.go b/apiserver/httpserver/utils/handler_test.go index 8b4d69108..2df994fa9 100644 --- a/apiserver/httpserver/utils/handler_test.go +++ b/apiserver/httpserver/utils/handler_test.go @@ -19,7 +19,6 @@ package utils import ( "fmt" - "github.com/stretchr/testify/assert" "net/http" "net/http/httptest" "strings" @@ -28,6 +27,7 @@ import ( "github.com/emicklei/go-restful/v3" "github.com/golang/protobuf/ptypes/wrappers" apimodel "github.com/polarismesh/specification/source/go/api/v1/model" + "github.com/stretchr/testify/assert" "github.com/polarismesh/polaris/apiserver/httpserver/i18n" api "github.com/polarismesh/polaris/common/api/v1" diff --git a/auth/user/helper.go b/auth/user/helper.go index b55c2c69b..dcb55418b 100644 --- a/auth/user/helper.go +++ b/auth/user/helper.go @@ -21,9 +21,10 @@ import ( "context" "errors" - "github.com/polarismesh/polaris/common/utils" apisecurity "github.com/polarismesh/specification/source/go/api/v1/security" "go.uber.org/zap" + + "github.com/polarismesh/polaris/common/utils" ) var ( @@ -98,7 +99,11 @@ func (helper *DefaultUserHelper) GetUser(ctx context.Context, user *apisecurity. func (helper *DefaultUserHelper) GetUserByID(ctx context.Context, id string) *apisecurity.User { cacheMgr := helper.svr.cacheMgr - return cacheMgr.User().GetUserByID(id).ToSpec() + saveUser := cacheMgr.User().GetUserByID(id) + if saveUser == nil { + saveUser, _ = helper.svr.storage.GetUser(id) + } + return saveUser.ToSpec() } // GetGroup 查询用户组信息 diff --git a/auth/user/inteceptor/auth/server.go b/auth/user/inteceptor/auth/server.go index fa37c4b54..38171005b 100644 --- a/auth/user/inteceptor/auth/server.go +++ b/auth/user/inteceptor/auth/server.go @@ -102,6 +102,9 @@ func (svr *Server) UpdateUser(ctx context.Context, user *apisecurity.User) *apis } helper := svr.GetUserHelper() targetUser := helper.GetUserByID(ctx, user.GetId().GetValue()) + if targetUser == nil { + return api.NewAuthResponse(apimodel.Code_NotFoundUser) + } if !checkUserViewPermission(ctx, targetUser) { return api.NewAuthResponse(apimodel.Code_NotAllowedAccess) } @@ -116,6 +119,9 @@ func (svr *Server) UpdateUserPassword(ctx context.Context, req *apisecurity.Modi } helper := svr.GetUserHelper() targetUser := helper.GetUserByID(ctx, req.GetId().GetValue()) + if targetUser == nil { + return api.NewAuthResponse(apimodel.Code_NotFoundUser) + } if !checkUserViewPermission(ctx, targetUser) { return api.NewAuthResponse(apimodel.Code_NotAllowedAccess) } @@ -130,6 +136,18 @@ func (svr *Server) DeleteUsers(ctx context.Context, users []*apisecurity.User) * api.Collect(resp, rsp) return resp } + for i := range users { + user := users[i] + helper := svr.GetUserHelper() + targetUser := helper.GetUserByID(ctx, user.GetId().GetValue()) + // 已经删除的用户没必要在删除一次 + if targetUser == nil { + continue + } + if !checkUserViewPermission(ctx, targetUser) { + return api.NewAuthBatchWriteResponse(apimodel.Code_NotAllowedAccess) + } + } return svr.nextSvr.DeleteUsers(ctx, users) } @@ -406,7 +424,8 @@ func checkUserViewPermission(ctx context.Context, user *apisecurity.User) bool { zap.Any("user", user), zap.String("owner", user.GetOwner().GetValue()), zap.String("operator", userId)) return true } - + log.Warn("check user view permission", utils.RequestID(ctx), + zap.Any("user", user), zap.String("owner", user.GetOwner().GetValue()), zap.String("operator", userId)) return false } diff --git a/auth/user/user_test.go b/auth/user/user_test.go index af0a5d533..93219e528 100644 --- a/auth/user/user_test.go +++ b/auth/user/user_test.go @@ -394,7 +394,7 @@ func Test_server_UpdateUser(t *testing.T) { Comment: &wrappers.StringValue{Value: "update owner account info"}, } - userTest.storage.EXPECT().GetUser(gomock.Any()).Return(userTest.users[2], nil) + userTest.storage.EXPECT().GetUser(gomock.Any()).Return(userTest.users[2], nil).AnyTimes() reqCtx := context.WithValue(context.Background(), utils.ContextAuthTokenKey, userTest.users[1].Token) resp := userTest.svr.UpdateUser(reqCtx, req) @@ -562,7 +562,7 @@ func Test_server_UpdateUserPassword(t *testing.T) { NewPassword: &wrappers.StringValue{Value: "users[2].Password"}, } - userTest.storage.EXPECT().GetUser(gomock.Any()).Return(userTest.users[2], nil) + userTest.storage.EXPECT().GetUser(gomock.Any()).Return(userTest.users[2], nil).AnyTimes() reqCtx := context.WithValue(context.Background(), utils.ContextAuthTokenKey, userTest.users[1].Token) resp := userTest.svr.UpdateUserPassword(reqCtx, req) @@ -605,7 +605,7 @@ func Test_server_DeleteUser(t *testing.T) { reqCtx := context.WithValue(context.Background(), utils.ContextAuthTokenKey, userTest.users[0].Token) resp := userTest.svr.DeleteUsers(reqCtx, []*apisecurity.User{ - &apisecurity.User{ + { Id: utils.NewStringValue(uid), }, }) @@ -623,7 +623,7 @@ func Test_server_DeleteUser(t *testing.T) { reqCtx := context.WithValue(context.Background(), utils.ContextAuthTokenKey, userTest.users[0].Token) resp := userTest.svr.DeleteUsers(reqCtx, []*apisecurity.User{ - &apisecurity.User{ + { Id: utils.NewStringValue(userTest.users[1].ID), }, }) @@ -805,7 +805,7 @@ func Test_server_RefreshUserToken(t *testing.T) { t.Run("主账户刷新别的主账户的Token", func(t *testing.T) { reqCtx := context.WithValue(context.Background(), utils.ContextAuthTokenKey, userTest.ownerOne.Token) - userTest.storage.EXPECT().GetUser(gomock.Any()).Return(userTest.ownerTwo, nil) + userTest.storage.EXPECT().GetUser(gomock.Any()).Return(userTest.ownerTwo, nil).AnyTimes() resp := userTest.svr.ResetUserToken(reqCtx, &apisecurity.User{ Id: utils.NewStringValue(userTest.ownerTwo.ID), }) @@ -815,7 +815,7 @@ func Test_server_RefreshUserToken(t *testing.T) { t.Run("主账户刷新不属于自己子账户的Token", func(t *testing.T) { reqCtx := context.WithValue(context.Background(), utils.ContextAuthTokenKey, userTest.ownerOne.Token) - userTest.storage.EXPECT().GetUser(gomock.Any()).Return(userTest.newUsers[1], nil) + userTest.storage.EXPECT().GetUser(gomock.Any()).Return(userTest.newUsers[1], nil).AnyTimes() resp := userTest.svr.ResetUserToken(reqCtx, &apisecurity.User{ Id: utils.NewStringValue(userTest.newUsers[1].ID), }) @@ -872,7 +872,7 @@ func Test_server_UpdateUserToken(t *testing.T) { t.Logf("operator-id : %s, user-two-owner : %s", userTest.ownerOne.ID, userTest.ownerTwo.ID) - userTest.storage.EXPECT().GetUser(gomock.Eq(userTest.ownerTwo.ID)).Return(userTest.ownerTwo, nil) + userTest.storage.EXPECT().GetUser(gomock.Eq(userTest.ownerTwo.ID)).Return(userTest.ownerTwo, nil).AnyTimes() resp := userTest.svr.UpdateUserToken(reqCtx, &apisecurity.User{ Id: utils.NewStringValue(userTest.ownerTwo.ID), }) @@ -886,7 +886,7 @@ func Test_server_UpdateUserToken(t *testing.T) { _ = userTest.cacheMgn.TestUpdate() reqCtx := context.WithValue(context.Background(), utils.ContextAuthTokenKey, userTest.ownerOne.Token) - userTest.storage.EXPECT().GetUser(gomock.Eq(userTest.newUsers[3].ID)).Return(userTest.newUsers[3], nil) + userTest.storage.EXPECT().GetUser(gomock.Eq(userTest.newUsers[3].ID)).Return(userTest.newUsers[3], nil).AnyTimes() resp := userTest.svr.UpdateUserToken(reqCtx, &apisecurity.User{ Id: utils.NewStringValue(userTest.newUsers[3].ID), }) diff --git a/common/utils/common.go b/common/utils/common.go index 176fa1f05..d835e0d05 100644 --- a/common/utils/common.go +++ b/common/utils/common.go @@ -587,7 +587,7 @@ func CheckContractInterfaceTetrad(contractId string, source apiservice.Interface func CalculateContractID(namespace, service, name, protocol, version string) (string, error) { h := sha1.New() - str := fmt.Sprintf("%s##%s##%s##%s##%d", namespace, service, name, protocol, version) + str := fmt.Sprintf("%s##%s##%s##%s##%s", namespace, service, name, protocol, version) if _, err := io.WriteString(h, str); err != nil { return "", err diff --git a/config/interceptor/paramcheck/config_file_check.go b/config/interceptor/paramcheck/config_file_check.go index ba1f42d67..7790694ab 100644 --- a/config/interceptor/paramcheck/config_file_check.go +++ b/config/interceptor/paramcheck/config_file_check.go @@ -55,8 +55,8 @@ func (s *Server) SearchConfigFile(ctx context.Context, return out } searchFilters := map[string]string{ - "offset": strconv.Itoa(int(offset)), - "limit": strconv.Itoa(int(limit)), + "offset": strconv.FormatInt(int64(offset), 10), + "limit": strconv.FormatInt(int64(limit), 10), } for k, v := range filter { // 无效查询参数自动忽略 diff --git a/config/interceptor/paramcheck/config_file_group_check.go b/config/interceptor/paramcheck/config_file_group_check.go index 4dc649c10..fd8ec15f3 100644 --- a/config/interceptor/paramcheck/config_file_group_check.go +++ b/config/interceptor/paramcheck/config_file_group_check.go @@ -49,8 +49,8 @@ func (s *Server) QueryConfigFileGroups(ctx context.Context, } searchFilters := map[string]string{ - "offset": strconv.Itoa(int(offset)), - "limit": strconv.Itoa(int(limit)), + "offset": strconv.FormatInt(int64(offset), 10), + "limit": strconv.FormatInt(int64(limit), 10), } for k, v := range filter { if newK, ok := availableSearch["config_file_group"][k]; ok { diff --git a/config/interceptor/paramcheck/config_file_release_check.go b/config/interceptor/paramcheck/config_file_release_check.go index 6b1f93e6e..00535ac76 100644 --- a/config/interceptor/paramcheck/config_file_release_check.go +++ b/config/interceptor/paramcheck/config_file_release_check.go @@ -107,8 +107,8 @@ func (s *Server) GetConfigFileReleases(ctx context.Context, } searchFilters := map[string]string{ - "offset": strconv.Itoa(int(offset)), - "limit": strconv.Itoa(int(limit)), + "offset": strconv.FormatInt(int64(offset), 10), + "limit": strconv.FormatInt(int64(limit), 10), } for k, v := range filters { if nK, ok := availableSearch["config_file_release"][k]; ok { diff --git a/config/interceptor/paramcheck/config_file_release_history_check.go b/config/interceptor/paramcheck/config_file_release_history_check.go index 144bee2a8..a46157ff3 100644 --- a/config/interceptor/paramcheck/config_file_release_history_check.go +++ b/config/interceptor/paramcheck/config_file_release_history_check.go @@ -38,8 +38,8 @@ func (s *Server) GetConfigFileReleaseHistories(ctx context.Context, } searchFilters := map[string]string{ - "offset": strconv.Itoa(int(offset)), - "limit": strconv.Itoa(int(limit)), + "offset": strconv.FormatInt(int64(offset), 10), + "limit": strconv.FormatInt(int64(limit), 10), } for k, v := range filter { diff --git a/service/interceptor/paramcheck/check.go b/service/interceptor/paramcheck/check.go index 553bc8632..c17ad6f15 100644 --- a/service/interceptor/paramcheck/check.go +++ b/service/interceptor/paramcheck/check.go @@ -1,3 +1,20 @@ +/** + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package paramcheck import ( @@ -12,162 +29,195 @@ import ( ) // AppendServiceContractInterfaces implements service.DiscoverServer. -func (svr *Server) AppendServiceContractInterfaces(ctx context.Context, contract *service_manage.ServiceContract, source service_manage.InterfaceDescriptor_Source) *service_manage.Response { +func (svr *Server) AppendServiceContractInterfaces(ctx context.Context, + contract *service_manage.ServiceContract, + source service_manage.InterfaceDescriptor_Source) *service_manage.Response { return svr.nextSvr.AppendServiceContractInterfaces(ctx, contract, source) } // CreateCircuitBreakerRules implements service.DiscoverServer. -func (svr *Server) CreateCircuitBreakerRules(ctx context.Context, request []*fault_tolerance.CircuitBreakerRule) *service_manage.BatchWriteResponse { +func (svr *Server) CreateCircuitBreakerRules(ctx context.Context, + request []*fault_tolerance.CircuitBreakerRule) *service_manage.BatchWriteResponse { return svr.nextSvr.CreateCircuitBreakerRules(ctx, request) } // CreateCircuitBreakerVersions implements service.DiscoverServer. -func (svr *Server) CreateCircuitBreakerVersions(ctx context.Context, req []*fault_tolerance.CircuitBreaker) *service_manage.BatchWriteResponse { +func (svr *Server) CreateCircuitBreakerVersions(ctx context.Context, + req []*fault_tolerance.CircuitBreaker) *service_manage.BatchWriteResponse { return svr.nextSvr.CreateCircuitBreakerVersions(ctx, req) } // CreateCircuitBreakers implements service.DiscoverServer. -func (svr *Server) CreateCircuitBreakers(ctx context.Context, req []*fault_tolerance.CircuitBreaker) *service_manage.BatchWriteResponse { +func (svr *Server) CreateCircuitBreakers(ctx context.Context, + req []*fault_tolerance.CircuitBreaker) *service_manage.BatchWriteResponse { return svr.nextSvr.CreateCircuitBreakers(ctx, req) } // CreateFaultDetectRules implements service.DiscoverServer. -func (svr *Server) CreateFaultDetectRules(ctx context.Context, request []*fault_tolerance.FaultDetectRule) *service_manage.BatchWriteResponse { +func (svr *Server) CreateFaultDetectRules(ctx context.Context, + request []*fault_tolerance.FaultDetectRule) *service_manage.BatchWriteResponse { return svr.nextSvr.CreateFaultDetectRules(ctx, request) } // CreateInstances implements service.DiscoverServer. -func (svr *Server) CreateInstances(ctx context.Context, reqs []*service_manage.Instance) *service_manage.BatchWriteResponse { +func (svr *Server) CreateInstances(ctx context.Context, + reqs []*service_manage.Instance) *service_manage.BatchWriteResponse { return svr.nextSvr.CreateInstances(ctx, reqs) } // CreateRateLimits implements service.DiscoverServer. -func (svr *Server) CreateRateLimits(ctx context.Context, request []*traffic_manage.Rule) *service_manage.BatchWriteResponse { +func (svr *Server) CreateRateLimits(ctx context.Context, + request []*traffic_manage.Rule) *service_manage.BatchWriteResponse { return svr.nextSvr.CreateRateLimits(ctx, request) } // CreateRoutingConfigs implements service.DiscoverServer. -func (svr *Server) CreateRoutingConfigs(ctx context.Context, req []*traffic_manage.Routing) *service_manage.BatchWriteResponse { +func (svr *Server) CreateRoutingConfigs(ctx context.Context, + req []*traffic_manage.Routing) *service_manage.BatchWriteResponse { return svr.nextSvr.CreateRoutingConfigs(ctx, req) } // CreateRoutingConfigsV2 implements service.DiscoverServer. -func (svr *Server) CreateRoutingConfigsV2(ctx context.Context, req []*traffic_manage.RouteRule) *service_manage.BatchWriteResponse { +func (svr *Server) CreateRoutingConfigsV2(ctx context.Context, + req []*traffic_manage.RouteRule) *service_manage.BatchWriteResponse { return svr.nextSvr.CreateRoutingConfigsV2(ctx, req) } // CreateServiceAlias implements service.DiscoverServer. -func (svr *Server) CreateServiceAlias(ctx context.Context, req *service_manage.ServiceAlias) *service_manage.Response { +func (svr *Server) CreateServiceAlias(ctx context.Context, + req *service_manage.ServiceAlias) *service_manage.Response { return svr.nextSvr.CreateServiceAlias(ctx, req) } // CreateServiceContractInterfaces implements service.DiscoverServer. -func (svr *Server) CreateServiceContractInterfaces(ctx context.Context, contract *service_manage.ServiceContract, source service_manage.InterfaceDescriptor_Source) *service_manage.Response { +func (svr *Server) CreateServiceContractInterfaces(ctx context.Context, + contract *service_manage.ServiceContract, source service_manage.InterfaceDescriptor_Source) *service_manage.Response { return svr.nextSvr.CreateServiceContractInterfaces(ctx, contract, source) } // CreateServiceContracts implements service.DiscoverServer. -func (svr *Server) CreateServiceContracts(ctx context.Context, req []*service_manage.ServiceContract) *service_manage.BatchWriteResponse { +func (svr *Server) CreateServiceContracts(ctx context.Context, + req []*service_manage.ServiceContract) *service_manage.BatchWriteResponse { return svr.nextSvr.CreateServiceContracts(ctx, req) } // CreateServices implements service.DiscoverServer. -func (svr *Server) CreateServices(ctx context.Context, req []*service_manage.Service) *service_manage.BatchWriteResponse { +func (svr *Server) CreateServices(ctx context.Context, + req []*service_manage.Service) *service_manage.BatchWriteResponse { return svr.nextSvr.CreateServices(ctx, req) } // DeleteCircuitBreakerRules implements service.DiscoverServer. -func (svr *Server) DeleteCircuitBreakerRules(ctx context.Context, request []*fault_tolerance.CircuitBreakerRule) *service_manage.BatchWriteResponse { +func (svr *Server) DeleteCircuitBreakerRules(ctx context.Context, + request []*fault_tolerance.CircuitBreakerRule) *service_manage.BatchWriteResponse { return svr.nextSvr.DeleteCircuitBreakerRules(ctx, request) } // DeleteCircuitBreakers implements service.DiscoverServer. -func (svr *Server) DeleteCircuitBreakers(ctx context.Context, req []*fault_tolerance.CircuitBreaker) *service_manage.BatchWriteResponse { +func (svr *Server) DeleteCircuitBreakers(ctx context.Context, + req []*fault_tolerance.CircuitBreaker) *service_manage.BatchWriteResponse { return svr.nextSvr.DeleteCircuitBreakers(ctx, req) } // DeleteFaultDetectRules implements service.DiscoverServer. -func (svr *Server) DeleteFaultDetectRules(ctx context.Context, request []*fault_tolerance.FaultDetectRule) *service_manage.BatchWriteResponse { +func (svr *Server) DeleteFaultDetectRules(ctx context.Context, + request []*fault_tolerance.FaultDetectRule) *service_manage.BatchWriteResponse { return svr.nextSvr.DeleteFaultDetectRules(ctx, request) } // DeleteInstances implements service.DiscoverServer. -func (svr *Server) DeleteInstances(ctx context.Context, req []*service_manage.Instance) *service_manage.BatchWriteResponse { +func (svr *Server) DeleteInstances(ctx context.Context, + req []*service_manage.Instance) *service_manage.BatchWriteResponse { return svr.nextSvr.DeleteInstances(ctx, req) } // DeleteInstancesByHost implements service.DiscoverServer. -func (svr *Server) DeleteInstancesByHost(ctx context.Context, req []*service_manage.Instance) *service_manage.BatchWriteResponse { +func (svr *Server) DeleteInstancesByHost(ctx context.Context, + req []*service_manage.Instance) *service_manage.BatchWriteResponse { return svr.nextSvr.DeleteInstancesByHost(ctx, req) } // DeleteRateLimits implements service.DiscoverServer. -func (svr *Server) DeleteRateLimits(ctx context.Context, request []*traffic_manage.Rule) *service_manage.BatchWriteResponse { +func (svr *Server) DeleteRateLimits(ctx context.Context, + request []*traffic_manage.Rule) *service_manage.BatchWriteResponse { return svr.nextSvr.DeleteRateLimits(ctx, request) } // DeleteRoutingConfigs implements service.DiscoverServer. -func (svr *Server) DeleteRoutingConfigs(ctx context.Context, req []*traffic_manage.Routing) *service_manage.BatchWriteResponse { +func (svr *Server) DeleteRoutingConfigs(ctx context.Context, + req []*traffic_manage.Routing) *service_manage.BatchWriteResponse { return svr.nextSvr.DeleteRoutingConfigs(ctx, req) } // DeleteRoutingConfigsV2 implements service.DiscoverServer. -func (svr *Server) DeleteRoutingConfigsV2(ctx context.Context, req []*traffic_manage.RouteRule) *service_manage.BatchWriteResponse { +func (svr *Server) DeleteRoutingConfigsV2(ctx context.Context, + req []*traffic_manage.RouteRule) *service_manage.BatchWriteResponse { return svr.nextSvr.DeleteRoutingConfigsV2(ctx, req) } // DeleteServiceAliases implements service.DiscoverServer. -func (svr *Server) DeleteServiceAliases(ctx context.Context, req []*service_manage.ServiceAlias) *service_manage.BatchWriteResponse { +func (svr *Server) DeleteServiceAliases(ctx context.Context, + req []*service_manage.ServiceAlias) *service_manage.BatchWriteResponse { return svr.nextSvr.DeleteServiceAliases(ctx, req) } // DeleteServiceContractInterfaces implements service.DiscoverServer. -func (svr *Server) DeleteServiceContractInterfaces(ctx context.Context, contract *service_manage.ServiceContract) *service_manage.Response { +func (svr *Server) DeleteServiceContractInterfaces(ctx context.Context, + contract *service_manage.ServiceContract) *service_manage.Response { return svr.nextSvr.DeleteServiceContractInterfaces(ctx, contract) } // DeleteServiceContracts implements service.DiscoverServer. -func (svr *Server) DeleteServiceContracts(ctx context.Context, req []*service_manage.ServiceContract) *service_manage.BatchWriteResponse { +func (svr *Server) DeleteServiceContracts(ctx context.Context, + req []*service_manage.ServiceContract) *service_manage.BatchWriteResponse { return svr.nextSvr.DeleteServiceContracts(ctx, req) } // DeleteServices implements service.DiscoverServer. -func (svr *Server) DeleteServices(ctx context.Context, req []*service_manage.Service) *service_manage.BatchWriteResponse { +func (svr *Server) DeleteServices(ctx context.Context, + req []*service_manage.Service) *service_manage.BatchWriteResponse { return svr.nextSvr.DeleteServices(ctx, req) } // EnableCircuitBreakerRules implements service.DiscoverServer. -func (svr *Server) EnableCircuitBreakerRules(ctx context.Context, request []*fault_tolerance.CircuitBreakerRule) *service_manage.BatchWriteResponse { +func (svr *Server) EnableCircuitBreakerRules(ctx context.Context, + request []*fault_tolerance.CircuitBreakerRule) *service_manage.BatchWriteResponse { return svr.nextSvr.EnableCircuitBreakerRules(ctx, request) } // EnableRateLimits implements service.DiscoverServer. -func (svr *Server) EnableRateLimits(ctx context.Context, request []*traffic_manage.Rule) *service_manage.BatchWriteResponse { +func (svr *Server) EnableRateLimits(ctx context.Context, + request []*traffic_manage.Rule) *service_manage.BatchWriteResponse { return svr.nextSvr.EnableRateLimits(ctx, request) } // EnableRoutings implements service.DiscoverServer. -func (svr *Server) EnableRoutings(ctx context.Context, req []*traffic_manage.RouteRule) *service_manage.BatchWriteResponse { +func (svr *Server) EnableRoutings(ctx context.Context, + req []*traffic_manage.RouteRule) *service_manage.BatchWriteResponse { return svr.nextSvr.EnableRoutings(ctx, req) } // GetAllServices implements service.DiscoverServer. -func (svr *Server) GetAllServices(ctx context.Context, query map[string]string) *service_manage.BatchQueryResponse { +func (svr *Server) GetAllServices(ctx context.Context, + query map[string]string) *service_manage.BatchQueryResponse { return svr.nextSvr.GetAllServices(ctx, query) } // GetCircuitBreaker implements service.DiscoverServer. -func (svr *Server) GetCircuitBreaker(ctx context.Context, query map[string]string) *service_manage.BatchQueryResponse { +func (svr *Server) GetCircuitBreaker(ctx context.Context, + query map[string]string) *service_manage.BatchQueryResponse { return svr.nextSvr.GetCircuitBreaker(ctx, query) } // GetCircuitBreakerByService implements service.DiscoverServer. -func (svr *Server) GetCircuitBreakerByService(ctx context.Context, query map[string]string) *service_manage.BatchQueryResponse { +func (svr *Server) GetCircuitBreakerByService(ctx context.Context, + query map[string]string) *service_manage.BatchQueryResponse { return svr.nextSvr.GetCircuitBreakerByService(ctx, query) } // GetCircuitBreakerRules implements service.DiscoverServer. -func (svr *Server) GetCircuitBreakerRules(ctx context.Context, query map[string]string) *service_manage.BatchQueryResponse { +func (svr *Server) GetCircuitBreakerRules(ctx context.Context, + query map[string]string) *service_manage.BatchQueryResponse { return svr.nextSvr.GetCircuitBreakerRules(ctx, query) } diff --git a/service/interceptor/paramcheck/client.go b/service/interceptor/paramcheck/client.go index 74a12b9fa..c829f6b6c 100644 --- a/service/interceptor/paramcheck/client.go +++ b/service/interceptor/paramcheck/client.go @@ -1,3 +1,20 @@ +/** + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package paramcheck import ( @@ -42,7 +59,8 @@ func (s *Server) GetServiceWithCache(ctx context.Context, req *apiservice.Servic } // ServiceInstancesCache Used for client acquisition service instance information -func (s *Server) ServiceInstancesCache(ctx context.Context, filter *apiservice.DiscoverFilter, req *apiservice.Service) *apiservice.DiscoverResponse { +func (s *Server) ServiceInstancesCache(ctx context.Context, filter *apiservice.DiscoverFilter, + req *apiservice.Service) *apiservice.DiscoverResponse { resp := service.CreateCommonDiscoverResponse(req, apiservice.DiscoverResponse_INSTANCE) namespaceName := req.GetNamespace().GetValue() diff --git a/store/mysql/lane.go b/store/mysql/lane.go index b446fafca..068cd3603 100644 --- a/store/mysql/lane.go +++ b/store/mysql/lane.go @@ -1,3 +1,20 @@ +/** + * Tencent is pleased to support the open source community by making Polaris available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * Licensed under the BSD 3-Clause License (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://opensource.org/licenses/BSD-3-Clause + * + * Unless required by applicable law or agreed to in writing, software distributed + * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + * CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ + package sqldb import ( diff --git a/store/mysql/service_contract.go b/store/mysql/service_contract.go index 617714bf7..b8615b095 100644 --- a/store/mysql/service_contract.go +++ b/store/mysql/service_contract.go @@ -311,7 +311,7 @@ func (s *serviceContractStore) GetServiceContracts(ctx context.Context, filter m _ = rows.Close() }() - contractIds := make([]interface{}, 0, limit) + contractIds := make([]interface{}, 0, 32) err = transferEnrichServiceContract(rows, func(contract *model.EnrichServiceContract) { list = append(list, contract) contractIds = append(contractIds, contract.ID)