forked from polarismesh/polaris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_export.go
110 lines (96 loc) · 3.48 KB
/
test_export.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* 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 config
import (
"context"
"fmt"
apiconfig "github.com/polarismesh/specification/source/go/api/v1/config_manage"
"go.uber.org/zap"
"github.com/polarismesh/polaris/auth"
"github.com/polarismesh/polaris/cache"
"github.com/polarismesh/polaris/common/model"
"github.com/polarismesh/polaris/namespace"
"github.com/polarismesh/polaris/plugin"
"github.com/polarismesh/polaris/store"
)
// Initialize 初始化配置中心模块
func TestInitialize(ctx context.Context, config Config, s store.Store, cacheMgn *cache.CacheManager,
namespaceOperator namespace.NamespaceOperateServer, userMgn auth.UserServer,
strategyMgn auth.StrategyServer) (ConfigCenterServer, *Server, error) {
mockServer := &Server{
initialized: true,
}
log.Info("Config.TestInitialize", zap.Any("entries", testConfigCacheEntries))
_ = cacheMgn.OpenResourceCache(testConfigCacheEntries...)
if err := mockServer.initialize(ctx, config, s, namespaceOperator, cacheMgn); err != nil {
return nil, nil, err
}
var proxySvr ConfigCenterServer
proxySvr = mockServer
// 需要返回包装代理的 ConfigCenterServer
order := config.Interceptors
for i := range order {
factory, exist := serverProxyFactories[order[i]]
if !exist {
return nil, nil, fmt.Errorf("name(%s) not exist in serverProxyFactories", order[i])
}
tmpSvr, err := factory(cacheMgn, s, proxySvr, config)
if err != nil {
return nil, nil, err
}
proxySvr = tmpSvr
}
return proxySvr, mockServer, nil
}
func (s *Server) TestCheckClientConfigFile(ctx context.Context, files []*apiconfig.ClientConfigFileInfo,
compartor CompareFunction) (*apiconfig.ConfigClientResponse, bool) {
return s.checkClientConfigFile(ctx, files, compartor)
}
func TestCompareByVersion(clientInfo *apiconfig.ClientConfigFileInfo, file *model.ConfigFileRelease) bool {
return CompareByVersion(clientInfo, file)
}
// TestDecryptConfigFile 解密配置文件
func (s *Server) TestDecryptConfigFile(ctx context.Context, configFile *model.ConfigFile) (err error) {
for i := range s.chains.chains {
chain := s.chains.chains[i]
if val, ok := chain.(*CryptoConfigFileChain); ok {
if _, err := val.AfterGetFile(ctx, configFile); err != nil {
return err
}
}
}
return nil
}
// TestEncryptConfigFile 解密配置文件
func (s *Server) TestEncryptConfigFile(ctx context.Context,
configFile *model.ConfigFile, algorithm string, dataKey string) error {
for i := range s.chains.chains {
chain := s.chains.chains[i]
if val, ok := chain.(*CryptoConfigFileChain); ok {
return val.encryptConfigFile(ctx, configFile, algorithm, dataKey)
}
}
return nil
}
// TestMockStore
func (s *Server) TestMockStore(ms store.Store) {
s.storage = ms
}
// TestMockCryptoManager 获取加密管理
func (s *Server) TestMockCryptoManager(mgr plugin.CryptoManager) {
s.cryptoManager = mgr
}