github.com/polarismesh/polaris@v1.17.8/config/test_export.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 "github.com/polarismesh/polaris/auth" 26 "github.com/polarismesh/polaris/cache" 27 "github.com/polarismesh/polaris/common/model" 28 "github.com/polarismesh/polaris/namespace" 29 "github.com/polarismesh/polaris/plugin" 30 "github.com/polarismesh/polaris/store" 31 ) 32 33 // Initialize 初始化配置中心模块 34 func TestInitialize(ctx context.Context, config Config, s store.Store, cacheMgn *cache.CacheManager, 35 namespaceOperator namespace.NamespaceOperateServer, userMgn auth.UserServer, 36 strategyMgn auth.StrategyServer) (ConfigCenterServer, ConfigCenterServer, error) { 37 mockServer := &Server{} 38 if err := mockServer.initialize(ctx, config, s, namespaceOperator, cacheMgn); err != nil { 39 return nil, nil, err 40 } 41 return newServerAuthAbility(mockServer, userMgn, strategyMgn), mockServer, nil 42 } 43 44 func (s *Server) TestCheckClientConfigFile(ctx context.Context, files []*apiconfig.ClientConfigFileInfo, 45 compartor compareFunction) (*apiconfig.ConfigClientResponse, bool) { 46 return s.checkClientConfigFile(ctx, files, compartor) 47 } 48 49 func TestCompareByVersion(clientInfo *apiconfig.ClientConfigFileInfo, file *model.ConfigFileRelease) bool { 50 return compareByVersion(clientInfo, file) 51 } 52 53 func TestCompareByMD5(clientInfo *apiconfig.ClientConfigFileInfo, file *model.ConfigFileRelease) bool { 54 return compareByMD5(clientInfo, file) 55 } 56 57 // TestDecryptConfigFile 解密配置文件 58 func (s *Server) TestDecryptConfigFile(ctx context.Context, configFile *model.ConfigFile) (err error) { 59 for i := range s.chains.chains { 60 chain := s.chains.chains[i] 61 if val, ok := chain.(*CryptoConfigFileChain); ok { 62 if _, err := val.AfterGetFile(ctx, configFile); err != nil { 63 return err 64 } 65 } 66 } 67 return nil 68 } 69 70 // TestEncryptConfigFile 解密配置文件 71 func (s *Server) TestEncryptConfigFile(ctx context.Context, 72 configFile *model.ConfigFile, algorithm string, dataKey string) error { 73 for i := range s.chains.chains { 74 chain := s.chains.chains[i] 75 if val, ok := chain.(*CryptoConfigFileChain); ok { 76 return val.encryptConfigFile(ctx, configFile, algorithm, dataKey) 77 } 78 } 79 return nil 80 } 81 82 // TestMockStore 83 func (s *Server) TestMockStore(ms store.Store) { 84 s.storage = ms 85 } 86 87 // TestMockCryptoManager 获取加密管理 88 func (s *Server) TestMockCryptoManager(mgr plugin.CryptoManager) { 89 s.cryptoManager = mgr 90 }