github.com/polarismesh/polaris@v1.17.8/service/routing_config_v2_authability.go (about) 1 /** 2 * Tencent is pleased to support the open source community by making Polaris available. 3 * 4 * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. 5 * 6 * Licensed under the BSD 3-Clause License (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * https://opensource.org/licenses/BSD-3-Clause 11 * 12 * Unless required by applicable law or agreed to in writing, software distributed 13 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 14 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 15 * specific language governing permissions and limitations under the License. 16 */ 17 18 package service 19 20 import ( 21 "context" 22 23 apiservice "github.com/polarismesh/specification/source/go/api/v1/service_manage" 24 apitraffic "github.com/polarismesh/specification/source/go/api/v1/traffic_manage" 25 26 api "github.com/polarismesh/polaris/common/api/v1" 27 "github.com/polarismesh/polaris/common/model" 28 "github.com/polarismesh/polaris/common/utils" 29 ) 30 31 // CreateRoutingConfigsV2 批量创建路由配置 32 func (svr *serverAuthAbility) CreateRoutingConfigsV2(ctx context.Context, 33 req []*apitraffic.RouteRule) *apiservice.BatchWriteResponse { 34 35 // TODO not support RouteRuleV2 resource auth, so we set op is read 36 authCtx := svr.collectRouteRuleV2AuthContext(ctx, req, model.Read, "CreateRoutingConfigsV2") 37 if _, err := svr.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 38 return api.NewBatchWriteResponse(convertToErrCode(err)) 39 } 40 ctx = authCtx.GetRequestContext() 41 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 42 return svr.targetServer.CreateRoutingConfigsV2(ctx, req) 43 } 44 45 // DeleteRoutingConfigsV2 批量删除路由配置 46 func (svr *serverAuthAbility) DeleteRoutingConfigsV2(ctx context.Context, 47 req []*apitraffic.RouteRule) *apiservice.BatchWriteResponse { 48 49 authCtx := svr.collectRouteRuleV2AuthContext(ctx, req, model.Read, "DeleteRoutingConfigsV2") 50 if _, err := svr.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 51 return api.NewBatchWriteResponse(convertToErrCode(err)) 52 } 53 ctx = authCtx.GetRequestContext() 54 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 55 return svr.targetServer.DeleteRoutingConfigsV2(ctx, req) 56 } 57 58 // UpdateRoutingConfigsV2 批量更新路由配置 59 func (svr *serverAuthAbility) UpdateRoutingConfigsV2(ctx context.Context, 60 req []*apitraffic.RouteRule) *apiservice.BatchWriteResponse { 61 62 authCtx := svr.collectRouteRuleV2AuthContext(ctx, req, model.Read, "UpdateRoutingConfigsV2") 63 if _, err := svr.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 64 return api.NewBatchWriteResponse(convertToErrCode(err)) 65 } 66 ctx = authCtx.GetRequestContext() 67 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 68 return svr.targetServer.UpdateRoutingConfigsV2(ctx, req) 69 } 70 71 // EnableRoutings batch enable routing rules 72 func (svr *serverAuthAbility) EnableRoutings(ctx context.Context, 73 req []*apitraffic.RouteRule) *apiservice.BatchWriteResponse { 74 75 authCtx := svr.collectRouteRuleV2AuthContext(ctx, req, model.Read, "EnableRoutings") 76 if _, err := svr.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 77 return api.NewBatchWriteResponse(convertToErrCode(err)) 78 } 79 ctx = authCtx.GetRequestContext() 80 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 81 return svr.targetServer.EnableRoutings(ctx, req) 82 } 83 84 // QueryRoutingConfigsV2 提供给OSS的查询路由配置的接口 85 func (svr *serverAuthAbility) QueryRoutingConfigsV2(ctx context.Context, 86 query map[string]string) *apiservice.BatchQueryResponse { 87 88 return svr.targetServer.QueryRoutingConfigsV2(ctx, query) 89 }