github.com/polarismesh/polaris@v1.17.8/service/faultdetect_config_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 apifault "github.com/polarismesh/specification/source/go/api/v1/fault_tolerance" 24 apiservice "github.com/polarismesh/specification/source/go/api/v1/service_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 func (svr *serverAuthAbility) CreateFaultDetectRules( 32 ctx context.Context, request []*apifault.FaultDetectRule) *apiservice.BatchWriteResponse { 33 34 authCtx := svr.collectFaultDetectAuthContext(ctx, request, model.Read, "CreateFaultDetectRules") 35 if _, err := svr.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 36 return api.NewBatchWriteResponse(convertToErrCode(err)) 37 } 38 ctx = authCtx.GetRequestContext() 39 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 40 return svr.targetServer.CreateFaultDetectRules(ctx, request) 41 } 42 43 func (svr *serverAuthAbility) DeleteFaultDetectRules( 44 ctx context.Context, request []*apifault.FaultDetectRule) *apiservice.BatchWriteResponse { 45 46 authCtx := svr.collectFaultDetectAuthContext(ctx, request, model.Read, "DeleteFaultDetectRules") 47 if _, err := svr.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 48 return api.NewBatchWriteResponse(convertToErrCode(err)) 49 } 50 ctx = authCtx.GetRequestContext() 51 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 52 return svr.targetServer.DeleteFaultDetectRules(ctx, request) 53 } 54 55 func (svr *serverAuthAbility) UpdateFaultDetectRules( 56 ctx context.Context, request []*apifault.FaultDetectRule) *apiservice.BatchWriteResponse { 57 58 authCtx := svr.collectFaultDetectAuthContext(ctx, request, model.Read, "UpdateFaultDetectRules") 59 if _, err := svr.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 60 return api.NewBatchWriteResponse(convertToErrCode(err)) 61 } 62 ctx = authCtx.GetRequestContext() 63 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 64 return svr.targetServer.UpdateFaultDetectRules(ctx, request) 65 } 66 67 func (svr *serverAuthAbility) GetFaultDetectRules( 68 ctx context.Context, query map[string]string) *apiservice.BatchQueryResponse { 69 authCtx := svr.collectFaultDetectAuthContext(ctx, nil, model.Read, "GetFaultDetectRules") 70 if _, err := svr.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 71 return api.NewBatchQueryResponse(convertToErrCode(err)) 72 } 73 ctx = authCtx.GetRequestContext() 74 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 75 return svr.targetServer.GetFaultDetectRules(ctx, query) 76 }