github.com/polarismesh/polaris@v1.17.8/config/config_file_authibility.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 config 19 20 import ( 21 "context" 22 23 apiconfig "github.com/polarismesh/specification/source/go/api/v1/config_manage" 24 25 api "github.com/polarismesh/polaris/common/api/v1" 26 "github.com/polarismesh/polaris/common/model" 27 "github.com/polarismesh/polaris/common/utils" 28 ) 29 30 // CreateConfigFile 创建配置文件 31 func (s *serverAuthability) CreateConfigFile(ctx context.Context, 32 configFile *apiconfig.ConfigFile) *apiconfig.ConfigResponse { 33 authCtx := s.collectConfigFileAuthContext( 34 ctx, []*apiconfig.ConfigFile{configFile}, model.Create, "CreateConfigFile") 35 if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 36 return api.NewConfigResponseWithInfo(convertToErrCode(err), err.Error()) 37 } 38 39 ctx = authCtx.GetRequestContext() 40 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 41 42 return s.targetServer.CreateConfigFile(ctx, configFile) 43 } 44 45 // GetConfigFileRichInfo 获取单个配置文件基础信息,包含发布状态等信息 46 func (s *serverAuthability) GetConfigFileRichInfo(ctx context.Context, 47 req *apiconfig.ConfigFile) *apiconfig.ConfigResponse { 48 49 authCtx := s.collectConfigFileAuthContext( 50 ctx, []*apiconfig.ConfigFile{req}, model.Read, "GetConfigFileRichInfo") 51 if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 52 return api.NewConfigResponseWithInfo(convertToErrCode(err), err.Error()) 53 } 54 ctx = authCtx.GetRequestContext() 55 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 56 return s.targetServer.GetConfigFileRichInfo(ctx, req) 57 } 58 59 // SearchConfigFile 查询配置文件 60 func (s *serverAuthability) SearchConfigFile(ctx context.Context, 61 filter map[string]string) *apiconfig.ConfigBatchQueryResponse { 62 63 authCtx := s.collectConfigFileAuthContext(ctx, nil, model.Read, "SearchConfigFile") 64 if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 65 return api.NewConfigFileBatchQueryResponseWithMessage(convertToErrCode(err), err.Error()) 66 } 67 ctx = authCtx.GetRequestContext() 68 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 69 70 return s.targetServer.SearchConfigFile(ctx, filter) 71 } 72 73 // UpdateConfigFile 更新配置文件 74 func (s *serverAuthability) UpdateConfigFile( 75 ctx context.Context, configFile *apiconfig.ConfigFile) *apiconfig.ConfigResponse { 76 authCtx := s.collectConfigFileAuthContext( 77 ctx, []*apiconfig.ConfigFile{configFile}, model.Modify, "UpdateConfigFile") 78 if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 79 return api.NewConfigResponseWithInfo(convertToErrCode(err), err.Error()) 80 } 81 82 ctx = authCtx.GetRequestContext() 83 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 84 85 return s.targetServer.UpdateConfigFile(ctx, configFile) 86 } 87 88 // DeleteConfigFile 删除配置文件,删除配置文件同时会通知客户端 Not_Found 89 func (s *serverAuthability) DeleteConfigFile(ctx context.Context, 90 req *apiconfig.ConfigFile) *apiconfig.ConfigResponse { 91 92 authCtx := s.collectConfigFileAuthContext(ctx, 93 []*apiconfig.ConfigFile{req}, model.Delete, "DeleteConfigFile") 94 if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 95 return api.NewConfigResponseWithInfo(convertToErrCode(err), err.Error()) 96 } 97 98 ctx = authCtx.GetRequestContext() 99 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 100 101 return s.targetServer.DeleteConfigFile(ctx, req) 102 } 103 104 // BatchDeleteConfigFile 批量删除配置文件 105 func (s *serverAuthability) BatchDeleteConfigFile(ctx context.Context, 106 req []*apiconfig.ConfigFile) *apiconfig.ConfigResponse { 107 108 authCtx := s.collectConfigFileAuthContext(ctx, req, model.Delete, "BatchDeleteConfigFile") 109 if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 110 return api.NewConfigResponseWithInfo(convertToErrCode(err), err.Error()) 111 } 112 113 ctx = authCtx.GetRequestContext() 114 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 115 116 return s.targetServer.BatchDeleteConfigFile(ctx, req) 117 } 118 119 func (s *serverAuthability) ExportConfigFile(ctx context.Context, 120 configFileExport *apiconfig.ConfigFileExportRequest) *apiconfig.ConfigExportResponse { 121 var configFiles []*apiconfig.ConfigFile 122 for _, group := range configFileExport.Groups { 123 configFile := &apiconfig.ConfigFile{ 124 Namespace: configFileExport.Namespace, 125 Group: group, 126 } 127 configFiles = append(configFiles, configFile) 128 } 129 authCtx := s.collectConfigFileAuthContext(ctx, configFiles, model.Read, "ExportConfigFile") 130 if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 131 return api.NewConfigFileExportResponseWithMessage(convertToErrCode(err), err.Error()) 132 } 133 ctx = authCtx.GetRequestContext() 134 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 135 136 return s.targetServer.ExportConfigFile(ctx, configFileExport) 137 } 138 139 func (s *serverAuthability) ImportConfigFile(ctx context.Context, 140 configFiles []*apiconfig.ConfigFile, conflictHandling string) *apiconfig.ConfigImportResponse { 141 authCtx := s.collectConfigFileAuthContext(ctx, configFiles, model.Create, "ImportConfigFile") 142 if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil { 143 return api.NewConfigFileImportResponseWithMessage(convertToErrCode(err), err.Error()) 144 } 145 146 ctx = authCtx.GetRequestContext() 147 ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx) 148 return s.targetServer.ImportConfigFile(ctx, configFiles, conflictHandling) 149 } 150 151 func (s *serverAuthability) GetAllConfigEncryptAlgorithms( 152 ctx context.Context) *apiconfig.ConfigEncryptAlgorithmResponse { 153 return s.targetServer.GetAllConfigEncryptAlgorithms(ctx) 154 }