-
Notifications
You must be signed in to change notification settings - Fork 390
/
config_file_authibility.go
154 lines (126 loc) · 6.31 KB
/
config_file_authibility.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/**
* 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_auth
import (
"context"
apiconfig "github.com/polarismesh/specification/source/go/api/v1/config_manage"
api "github.com/polarismesh/polaris/common/api/v1"
"github.com/polarismesh/polaris/common/model"
"github.com/polarismesh/polaris/common/utils"
)
// CreateConfigFile 创建配置文件
func (s *ServerAuthability) CreateConfigFile(ctx context.Context,
configFile *apiconfig.ConfigFile) *apiconfig.ConfigResponse {
authCtx := s.collectConfigFileAuthContext(
ctx, []*apiconfig.ConfigFile{configFile}, model.Create, "CreateConfigFile")
if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil {
return api.NewConfigResponseWithInfo(model.ConvertToErrCode(err), err.Error())
}
ctx = authCtx.GetRequestContext()
ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx)
return s.nextServer.CreateConfigFile(ctx, configFile)
}
// GetConfigFileRichInfo 获取单个配置文件基础信息,包含发布状态等信息
func (s *ServerAuthability) GetConfigFileRichInfo(ctx context.Context,
req *apiconfig.ConfigFile) *apiconfig.ConfigResponse {
authCtx := s.collectConfigFileAuthContext(
ctx, []*apiconfig.ConfigFile{req}, model.Read, "GetConfigFileRichInfo")
if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil {
return api.NewConfigResponseWithInfo(model.ConvertToErrCode(err), err.Error())
}
ctx = authCtx.GetRequestContext()
ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx)
return s.nextServer.GetConfigFileRichInfo(ctx, req)
}
// SearchConfigFile 查询配置文件
func (s *ServerAuthability) SearchConfigFile(ctx context.Context,
filter map[string]string) *apiconfig.ConfigBatchQueryResponse {
authCtx := s.collectConfigFileAuthContext(ctx, nil, model.Read, "SearchConfigFile")
if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil {
return api.NewConfigFileBatchQueryResponseWithMessage(model.ConvertToErrCode(err), err.Error())
}
ctx = authCtx.GetRequestContext()
ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx)
return s.nextServer.SearchConfigFile(ctx, filter)
}
// UpdateConfigFile 更新配置文件
func (s *ServerAuthability) UpdateConfigFile(
ctx context.Context, configFile *apiconfig.ConfigFile) *apiconfig.ConfigResponse {
authCtx := s.collectConfigFileAuthContext(
ctx, []*apiconfig.ConfigFile{configFile}, model.Modify, "UpdateConfigFile")
if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil {
return api.NewConfigResponseWithInfo(model.ConvertToErrCode(err), err.Error())
}
ctx = authCtx.GetRequestContext()
ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx)
return s.nextServer.UpdateConfigFile(ctx, configFile)
}
// DeleteConfigFile 删除配置文件,删除配置文件同时会通知客户端 Not_Found
func (s *ServerAuthability) DeleteConfigFile(ctx context.Context,
req *apiconfig.ConfigFile) *apiconfig.ConfigResponse {
authCtx := s.collectConfigFileAuthContext(ctx,
[]*apiconfig.ConfigFile{req}, model.Delete, "DeleteConfigFile")
if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil {
return api.NewConfigResponseWithInfo(model.ConvertToErrCode(err), err.Error())
}
ctx = authCtx.GetRequestContext()
ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx)
return s.nextServer.DeleteConfigFile(ctx, req)
}
// BatchDeleteConfigFile 批量删除配置文件
func (s *ServerAuthability) BatchDeleteConfigFile(ctx context.Context,
req []*apiconfig.ConfigFile) *apiconfig.ConfigResponse {
authCtx := s.collectConfigFileAuthContext(ctx, req, model.Delete, "BatchDeleteConfigFile")
if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil {
return api.NewConfigResponseWithInfo(model.ConvertToErrCode(err), err.Error())
}
ctx = authCtx.GetRequestContext()
ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx)
return s.nextServer.BatchDeleteConfigFile(ctx, req)
}
func (s *ServerAuthability) ExportConfigFile(ctx context.Context,
configFileExport *apiconfig.ConfigFileExportRequest) *apiconfig.ConfigExportResponse {
var configFiles []*apiconfig.ConfigFile
for _, group := range configFileExport.Groups {
configFile := &apiconfig.ConfigFile{
Namespace: configFileExport.Namespace,
Group: group,
}
configFiles = append(configFiles, configFile)
}
authCtx := s.collectConfigFileAuthContext(ctx, configFiles, model.Read, "ExportConfigFile")
if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil {
return api.NewConfigFileExportResponseWithMessage(model.ConvertToErrCode(err), err.Error())
}
ctx = authCtx.GetRequestContext()
ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx)
return s.nextServer.ExportConfigFile(ctx, configFileExport)
}
func (s *ServerAuthability) ImportConfigFile(ctx context.Context,
configFiles []*apiconfig.ConfigFile, conflictHandling string) *apiconfig.ConfigImportResponse {
authCtx := s.collectConfigFileAuthContext(ctx, configFiles, model.Create, "ImportConfigFile")
if _, err := s.strategyMgn.GetAuthChecker().CheckConsolePermission(authCtx); err != nil {
return api.NewConfigFileImportResponseWithMessage(model.ConvertToErrCode(err), err.Error())
}
ctx = authCtx.GetRequestContext()
ctx = context.WithValue(ctx, utils.ContextAuthContextKey, authCtx)
return s.nextServer.ImportConfigFile(ctx, configFiles, conflictHandling)
}
func (s *ServerAuthability) GetAllConfigEncryptAlgorithms(
ctx context.Context) *apiconfig.ConfigEncryptAlgorithmResponse {
return s.nextServer.GetAllConfigEncryptAlgorithms(ctx)
}