@cloudbase/manager-node 4.11.0-alpha.7 → 4.11.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/environment.js +5 -0
- package/lib/index.js +3 -0
- package/lib/log/index.js +48 -0
- package/lib/permission/index.js +313 -0
- package/lib/permission/types.js +2 -0
- package/package.json +1 -1
- package/types/environment.d.ts +3 -0
- package/types/index.d.ts +2 -0
- package/types/log/index.d.ts +32 -0
- package/types/permission/index.d.ts +31 -0
- package/types/permission/types.d.ts +127 -0
package/lib/environment.js
CHANGED
|
@@ -18,6 +18,7 @@ const access_1 = require("./access");
|
|
|
18
18
|
const user_1 = require("./user");
|
|
19
19
|
const cloudBaseRun_1 = require("./cloudBaseRun");
|
|
20
20
|
const mysql_1 = require("./mysql");
|
|
21
|
+
const permission_1 = require("./permission");
|
|
21
22
|
class Environment {
|
|
22
23
|
constructor(context, envId) {
|
|
23
24
|
this.inited = false;
|
|
@@ -39,6 +40,7 @@ class Environment {
|
|
|
39
40
|
this.userService = new user_1.UserService(this);
|
|
40
41
|
this.cloudBaseRunService = new cloudBaseRun_1.CloudBaseRunService(this);
|
|
41
42
|
this.mysqlService = new mysql_1.MysqlService(this);
|
|
43
|
+
this.permissionService = new permission_1.PermissionService(this);
|
|
42
44
|
}
|
|
43
45
|
async lazyInit() {
|
|
44
46
|
if (!this.inited) {
|
|
@@ -101,6 +103,9 @@ class Environment {
|
|
|
101
103
|
getMysqlService() {
|
|
102
104
|
return this.mysqlService;
|
|
103
105
|
}
|
|
106
|
+
getPermissionService() {
|
|
107
|
+
return this.permissionService;
|
|
108
|
+
}
|
|
104
109
|
getCommonService(serviceType = 'tcb', serviceVersion) {
|
|
105
110
|
return new common_1.CommonService(this, serviceType, serviceVersion);
|
|
106
111
|
}
|
package/lib/index.js
CHANGED
|
@@ -88,6 +88,9 @@ class CloudBase {
|
|
|
88
88
|
get user() {
|
|
89
89
|
return this.currentEnvironment().getUserService();
|
|
90
90
|
}
|
|
91
|
+
get permission() {
|
|
92
|
+
return this.currentEnvironment().getPermissionService();
|
|
93
|
+
}
|
|
91
94
|
get docs() {
|
|
92
95
|
if (!this.docsService) {
|
|
93
96
|
this.docsService = new docs_1.DocsService();
|
package/lib/log/index.js
CHANGED
|
@@ -15,14 +15,62 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.LogService = void 0;
|
|
18
|
+
exports.isLogServiceEnabled = isLogServiceEnabled;
|
|
18
19
|
const utils_1 = require("../utils");
|
|
19
20
|
__exportStar(require("./types"), exports);
|
|
21
|
+
/**
|
|
22
|
+
* 纯函数:根据 DescribeEnvs 返回的 LogServices 列表判断日志服务是否已开通。
|
|
23
|
+
* 已开通条件:至少一个条目有有效的 TopicId。
|
|
24
|
+
*/
|
|
25
|
+
function isLogServiceEnabled(logServices) {
|
|
26
|
+
if (!logServices || logServices.length === 0)
|
|
27
|
+
return false;
|
|
28
|
+
return logServices.some(svc => !!svc.TopicId);
|
|
29
|
+
}
|
|
20
30
|
class LogService {
|
|
21
31
|
constructor(environment) {
|
|
22
32
|
this.envId = environment.getEnvId();
|
|
23
33
|
this.cloudService = new utils_1.CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08');
|
|
24
34
|
this.tcbrService = new utils_1.CloudService(environment.cloudBaseContext, 'tcbr', '2022-02-17');
|
|
25
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* 检查当前环境的日志服务是否已开通
|
|
38
|
+
*
|
|
39
|
+
* 通过 DescribeEnvs 接口获取环境信息,判断 LogServices 字段中是否包含有效的
|
|
40
|
+
* 日志主题(TopicId 不为空)。
|
|
41
|
+
*
|
|
42
|
+
* @returns true 表示已开通,false 表示未开通或开通中
|
|
43
|
+
*/
|
|
44
|
+
async checkLogServiceEnabled() {
|
|
45
|
+
var _a;
|
|
46
|
+
const res = await this.cloudService.request('DescribeEnvs', {
|
|
47
|
+
EnvId: this.envId
|
|
48
|
+
});
|
|
49
|
+
const envInfo = (_a = res === null || res === void 0 ? void 0 : res.EnvList) === null || _a === void 0 ? void 0 : _a[0];
|
|
50
|
+
if (!envInfo) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
const logServices = envInfo.LogServices;
|
|
54
|
+
if (!logServices || logServices.length === 0) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
// 已开通:LogServiceInfo 中存在有效的日志主题 ID
|
|
58
|
+
return isLogServiceEnabled(logServices);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 开通环境日志服务(异步操作)
|
|
62
|
+
*
|
|
63
|
+
* 调用 CreateEnvResource 接口开通日志资源。
|
|
64
|
+
* 注意:接口调用成功不代表日志资源立即可用,需通过 checkLogServiceEnabled() 轮询确认。
|
|
65
|
+
*
|
|
66
|
+
* @returns 请求 ID
|
|
67
|
+
*/
|
|
68
|
+
async createLogService() {
|
|
69
|
+
return this.cloudService.request('CreateEnvResource', {
|
|
70
|
+
EnvId: this.envId,
|
|
71
|
+
Resources: ['log']
|
|
72
|
+
});
|
|
73
|
+
}
|
|
26
74
|
/**
|
|
27
75
|
* 搜索 CLS 日志
|
|
28
76
|
*
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.PermissionService = void 0;
|
|
10
|
+
const utils_1 = require("../utils");
|
|
11
|
+
const PERMISSION_BY_RESOURCE = {
|
|
12
|
+
function: ['CUSTOM'],
|
|
13
|
+
storage: ['READONLY', 'PRIVATE', 'ADMINWRITE', 'ADMINONLY', 'CUSTOM'],
|
|
14
|
+
table: ['READONLY', 'PRIVATE', 'ADMINWRITE', 'ADMINONLY'],
|
|
15
|
+
collection: ['READONLY', 'PRIVATE', 'ADMINWRITE', 'ADMINONLY', 'CUSTOM']
|
|
16
|
+
};
|
|
17
|
+
class PermissionService {
|
|
18
|
+
constructor(environment) {
|
|
19
|
+
this.environment = environment;
|
|
20
|
+
this.tcbService = new utils_1.CloudService(environment.cloudBaseContext, 'tcb', '2018-06-08');
|
|
21
|
+
}
|
|
22
|
+
async modifyResourcePermission(options) {
|
|
23
|
+
const { EnvId } = this.environment.lazyEnvironmentConfig;
|
|
24
|
+
const { resourceType, resource, permission, securityRule } = options;
|
|
25
|
+
if (!resourceType || !PERMISSION_BY_RESOURCE[resourceType]) {
|
|
26
|
+
throw new Error('Invalid resourceType');
|
|
27
|
+
}
|
|
28
|
+
if (typeof resource !== 'string' || resource.trim().length === 0) {
|
|
29
|
+
throw new Error('Invalid resource');
|
|
30
|
+
}
|
|
31
|
+
const allowed = PERMISSION_BY_RESOURCE[resourceType];
|
|
32
|
+
if (!allowed.includes(permission)) {
|
|
33
|
+
throw new Error(`Permission ${permission} is not allowed for resourceType ${resourceType}`);
|
|
34
|
+
}
|
|
35
|
+
if (permission === 'CUSTOM') {
|
|
36
|
+
if (typeof securityRule !== 'string' || securityRule.trim().length === 0) {
|
|
37
|
+
throw new Error('securityRule is required when permission is CUSTOM');
|
|
38
|
+
}
|
|
39
|
+
// // 校验 JSON 字符串合法性
|
|
40
|
+
// try {
|
|
41
|
+
// JSON.parse(securityRule)
|
|
42
|
+
// } catch {
|
|
43
|
+
// throw new Error('securityRule must be a valid JSON string')
|
|
44
|
+
// }
|
|
45
|
+
}
|
|
46
|
+
const reqData = {
|
|
47
|
+
EnvId,
|
|
48
|
+
ResourceType: resourceType,
|
|
49
|
+
Resource: resource,
|
|
50
|
+
Permission: permission
|
|
51
|
+
};
|
|
52
|
+
if (permission === 'CUSTOM') {
|
|
53
|
+
reqData.SecurityRule = securityRule;
|
|
54
|
+
}
|
|
55
|
+
return this.tcbService.request('ModifyResourcePermission', reqData);
|
|
56
|
+
}
|
|
57
|
+
async describeResourcePermission(options) {
|
|
58
|
+
const { EnvId } = this.environment.lazyEnvironmentConfig;
|
|
59
|
+
const { resourceType, resources } = options;
|
|
60
|
+
if (!resourceType || !PERMISSION_BY_RESOURCE[resourceType]) {
|
|
61
|
+
throw new Error('Invalid resourceType');
|
|
62
|
+
}
|
|
63
|
+
if (resources !== undefined) {
|
|
64
|
+
if (!Array.isArray(resources)) {
|
|
65
|
+
throw new Error('Invalid resources');
|
|
66
|
+
}
|
|
67
|
+
if (resources.length > 100) {
|
|
68
|
+
throw new Error('resources length must be <= 100');
|
|
69
|
+
}
|
|
70
|
+
const invalid = resources.find(item => typeof item !== 'string' || item.trim().length === 0);
|
|
71
|
+
if (invalid !== undefined) {
|
|
72
|
+
throw new Error('resources contains invalid item');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return this.tcbService.request('DescribeResourcePermission', Object.assign({ EnvId, ResourceType: resourceType }, (resources !== undefined ? { Resources: resources } : {})));
|
|
76
|
+
}
|
|
77
|
+
async createRole(options) {
|
|
78
|
+
const { EnvId } = this.environment.lazyEnvironmentConfig;
|
|
79
|
+
const { roleName, roleIdentity, description, memberUids, policies } = options;
|
|
80
|
+
// RoleName 校验:非空,2-32字符,中文/字母/数字/_-:@.,必须以字母或中文开头
|
|
81
|
+
if (typeof roleName !== 'string' || roleName.trim().length === 0) {
|
|
82
|
+
throw new Error('roleName is required');
|
|
83
|
+
}
|
|
84
|
+
if (roleName.length < 2 || roleName.length > 32) {
|
|
85
|
+
throw new Error('roleName length must be between 2 and 32');
|
|
86
|
+
}
|
|
87
|
+
if (!/^[\u4e00-\u9fa5a-zA-Z]/.test(roleName)) {
|
|
88
|
+
throw new Error('roleName must start with a letter or Chinese character');
|
|
89
|
+
}
|
|
90
|
+
if (!/^[\u4e00-\u9fa5a-zA-Z0-9\-_:@.]+$/.test(roleName)) {
|
|
91
|
+
throw new Error('roleName can only contain Chinese, letters, digits, and -_:@.');
|
|
92
|
+
}
|
|
93
|
+
// RoleIdentity 校验:非空,字母/数字/_-:@.,不能与默认角色标识重复
|
|
94
|
+
if (typeof roleIdentity !== 'string' || roleIdentity.trim().length === 0) {
|
|
95
|
+
throw new Error('roleIdentity is required');
|
|
96
|
+
}
|
|
97
|
+
if (!/^[a-zA-Z0-9\-_:@.]+$/.test(roleIdentity)) {
|
|
98
|
+
throw new Error('roleIdentity can only contain letters, digits, and -_:@.');
|
|
99
|
+
}
|
|
100
|
+
// Description 校验
|
|
101
|
+
if (description !== undefined && description.length > 255) {
|
|
102
|
+
throw new Error('description length must be <= 255');
|
|
103
|
+
}
|
|
104
|
+
// MemberUids 校验
|
|
105
|
+
if (memberUids !== undefined) {
|
|
106
|
+
if (!Array.isArray(memberUids)) {
|
|
107
|
+
throw new Error('memberUids must be an array');
|
|
108
|
+
}
|
|
109
|
+
if (memberUids.length > 100) {
|
|
110
|
+
throw new Error('memberUids length must be <= 100');
|
|
111
|
+
}
|
|
112
|
+
const invalidUid = memberUids.find(uid => typeof uid !== 'string' || uid.trim().length === 0);
|
|
113
|
+
if (invalidUid !== undefined) {
|
|
114
|
+
throw new Error('memberUids contains invalid item');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
// Policies 校验
|
|
118
|
+
if (policies !== undefined) {
|
|
119
|
+
if (!Array.isArray(policies)) {
|
|
120
|
+
throw new Error('policies must be an array');
|
|
121
|
+
}
|
|
122
|
+
if (policies.length > 50) {
|
|
123
|
+
throw new Error('policies length must be <= 50');
|
|
124
|
+
}
|
|
125
|
+
const invalidPolicy = policies.find(policy => !policy.ResourceType || !policy.Resource);
|
|
126
|
+
if (invalidPolicy !== undefined) {
|
|
127
|
+
throw new Error('each policy must have ResourceType and Resource');
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const reqData = {
|
|
131
|
+
EnvId,
|
|
132
|
+
RoleName: roleName,
|
|
133
|
+
RoleIdentity: roleIdentity
|
|
134
|
+
};
|
|
135
|
+
if (description !== undefined) {
|
|
136
|
+
reqData.Description = description;
|
|
137
|
+
}
|
|
138
|
+
if (memberUids !== undefined && memberUids.length > 0) {
|
|
139
|
+
reqData.MemberUids = memberUids;
|
|
140
|
+
}
|
|
141
|
+
if (policies !== undefined && policies.length > 0) {
|
|
142
|
+
reqData.Policies = policies;
|
|
143
|
+
}
|
|
144
|
+
return this.tcbService.request('CreateRole', reqData);
|
|
145
|
+
}
|
|
146
|
+
async describeRoleList(options = {}) {
|
|
147
|
+
const { EnvId } = this.environment.lazyEnvironmentConfig;
|
|
148
|
+
const { pageNumber, pageSize, roleId, roleIdentity, roleName, loadDetails } = options;
|
|
149
|
+
// PageNumber 校验:从1开始
|
|
150
|
+
if (pageNumber !== undefined && (pageNumber < 1 || !Number.isInteger(pageNumber))) {
|
|
151
|
+
throw new Error('pageNumber must be a positive integer');
|
|
152
|
+
}
|
|
153
|
+
// PageSize 校验:默认10,最大100
|
|
154
|
+
if (pageSize !== undefined && (pageSize < 1 || pageSize > 100 || !Number.isInteger(pageSize))) {
|
|
155
|
+
throw new Error('pageSize must be an integer between 1 and 100');
|
|
156
|
+
}
|
|
157
|
+
// RoleId 校验
|
|
158
|
+
if (roleId !== undefined && (typeof roleId !== 'string' || roleId.trim().length === 0)) {
|
|
159
|
+
throw new Error('Invalid roleId');
|
|
160
|
+
}
|
|
161
|
+
// RoleIdentity 校验
|
|
162
|
+
if (roleIdentity !== undefined && (typeof roleIdentity !== 'string' || roleIdentity.trim().length === 0)) {
|
|
163
|
+
throw new Error('Invalid roleIdentity');
|
|
164
|
+
}
|
|
165
|
+
// RoleName 校验
|
|
166
|
+
if (roleName !== undefined && (typeof roleName !== 'string' || roleName.trim().length === 0)) {
|
|
167
|
+
throw new Error('Invalid roleName');
|
|
168
|
+
}
|
|
169
|
+
const reqData = { EnvId };
|
|
170
|
+
if (pageNumber !== undefined) {
|
|
171
|
+
reqData.PageNumber = pageNumber;
|
|
172
|
+
}
|
|
173
|
+
if (pageSize !== undefined) {
|
|
174
|
+
reqData.PageSize = pageSize;
|
|
175
|
+
}
|
|
176
|
+
if (roleId !== undefined) {
|
|
177
|
+
reqData.RoleId = roleId;
|
|
178
|
+
}
|
|
179
|
+
if (roleIdentity !== undefined) {
|
|
180
|
+
reqData.RoleIdentity = roleIdentity;
|
|
181
|
+
}
|
|
182
|
+
if (roleName !== undefined) {
|
|
183
|
+
reqData.RoleName = roleName;
|
|
184
|
+
}
|
|
185
|
+
if (loadDetails !== undefined) {
|
|
186
|
+
reqData.LoadDetails = loadDetails;
|
|
187
|
+
}
|
|
188
|
+
return this.tcbService.request('DescribeRoleList', reqData);
|
|
189
|
+
}
|
|
190
|
+
async modifyRole(options) {
|
|
191
|
+
const { EnvId } = this.environment.lazyEnvironmentConfig;
|
|
192
|
+
const { roleId, roleName, description, addMemberUids, removeMemberUids, addPolicies, removePolicies } = options;
|
|
193
|
+
// RoleId 校验:必填
|
|
194
|
+
if (typeof roleId !== 'string' || roleId.trim().length === 0) {
|
|
195
|
+
throw new Error('roleId is required');
|
|
196
|
+
}
|
|
197
|
+
// RoleName 校验:不传或传空 => 不修改;非空时校验规则
|
|
198
|
+
if (roleName !== undefined && roleName !== '') {
|
|
199
|
+
if (roleName.length < 2 || roleName.length > 32) {
|
|
200
|
+
throw new Error('roleName length must be between 2 and 32');
|
|
201
|
+
}
|
|
202
|
+
if (!/^[\u4e00-\u9fa5a-zA-Z]/.test(roleName)) {
|
|
203
|
+
throw new Error('roleName must start with a letter or Chinese character');
|
|
204
|
+
}
|
|
205
|
+
if (!/^[\u4e00-\u9fa5a-zA-Z0-9\-_:@.]+$/.test(roleName)) {
|
|
206
|
+
throw new Error('roleName can only contain Chinese, letters, digits, and -_:@.');
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// Description 校验
|
|
210
|
+
if (description !== undefined && description.length > 255) {
|
|
211
|
+
throw new Error('description length must be <= 255');
|
|
212
|
+
}
|
|
213
|
+
// AddMemberUids 校验
|
|
214
|
+
if (addMemberUids !== undefined) {
|
|
215
|
+
if (!Array.isArray(addMemberUids)) {
|
|
216
|
+
throw new Error('addMemberUids must be an array');
|
|
217
|
+
}
|
|
218
|
+
const invalidUid = addMemberUids.find(uid => typeof uid !== 'string' || uid.trim().length === 0);
|
|
219
|
+
if (invalidUid !== undefined) {
|
|
220
|
+
throw new Error('addMemberUids contains invalid item');
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
// RemoveMemberUids 校验
|
|
224
|
+
if (removeMemberUids !== undefined) {
|
|
225
|
+
if (!Array.isArray(removeMemberUids)) {
|
|
226
|
+
throw new Error('removeMemberUids must be an array');
|
|
227
|
+
}
|
|
228
|
+
const invalidUid = removeMemberUids.find(uid => typeof uid !== 'string' || uid.trim().length === 0);
|
|
229
|
+
if (invalidUid !== undefined) {
|
|
230
|
+
throw new Error('removeMemberUids contains invalid item');
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
// AddPolicies 校验
|
|
234
|
+
if (addPolicies !== undefined) {
|
|
235
|
+
if (!Array.isArray(addPolicies)) {
|
|
236
|
+
throw new Error('addPolicies must be an array');
|
|
237
|
+
}
|
|
238
|
+
const invalidPolicy = addPolicies.find(policy => !policy.ResourceType || !policy.Resource);
|
|
239
|
+
if (invalidPolicy !== undefined) {
|
|
240
|
+
throw new Error('each addPolicy must have ResourceType and Resource');
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
// RemovePolicies 校验
|
|
244
|
+
if (removePolicies !== undefined) {
|
|
245
|
+
if (!Array.isArray(removePolicies)) {
|
|
246
|
+
throw new Error('removePolicies must be an array');
|
|
247
|
+
}
|
|
248
|
+
const invalidPolicy = removePolicies.find(policy => !policy.ResourceType || !policy.Resource);
|
|
249
|
+
if (invalidPolicy !== undefined) {
|
|
250
|
+
throw new Error('each removePolicy must have ResourceType and Resource');
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
const reqData = { EnvId, RoleId: roleId };
|
|
254
|
+
// RoleName:不传或传空 => 不修改(不下发)
|
|
255
|
+
if (roleName !== undefined && roleName !== '') {
|
|
256
|
+
reqData.RoleName = roleName;
|
|
257
|
+
}
|
|
258
|
+
if (description !== undefined) {
|
|
259
|
+
reqData.Description = description;
|
|
260
|
+
}
|
|
261
|
+
if (addMemberUids !== undefined) {
|
|
262
|
+
reqData.AddMemberUids = addMemberUids;
|
|
263
|
+
}
|
|
264
|
+
if (removeMemberUids !== undefined) {
|
|
265
|
+
reqData.RemoveMemberUids = removeMemberUids;
|
|
266
|
+
}
|
|
267
|
+
if (addPolicies !== undefined) {
|
|
268
|
+
reqData.AddPolicies = addPolicies;
|
|
269
|
+
}
|
|
270
|
+
if (removePolicies !== undefined) {
|
|
271
|
+
reqData.RemovePolicies = removePolicies;
|
|
272
|
+
}
|
|
273
|
+
return this.tcbService.request('ModifyRole', reqData);
|
|
274
|
+
}
|
|
275
|
+
async deleteRoles(options) {
|
|
276
|
+
const { EnvId } = this.environment.lazyEnvironmentConfig;
|
|
277
|
+
const { roleIds } = options;
|
|
278
|
+
// RoleIds 校验:必填数组,最多100个
|
|
279
|
+
if (!Array.isArray(roleIds) || roleIds.length === 0) {
|
|
280
|
+
throw new Error('roleIds is required and must be a non-empty array');
|
|
281
|
+
}
|
|
282
|
+
if (roleIds.length > 100) {
|
|
283
|
+
throw new Error('roleIds length must be <= 100');
|
|
284
|
+
}
|
|
285
|
+
const invalidId = roleIds.find(id => typeof id !== 'string' || id.trim().length === 0);
|
|
286
|
+
if (invalidId !== undefined) {
|
|
287
|
+
throw new Error('roleIds contains invalid item');
|
|
288
|
+
}
|
|
289
|
+
return this.tcbService.request('DeleteRoles', {
|
|
290
|
+
EnvId,
|
|
291
|
+
RoleIds: roleIds
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
exports.PermissionService = PermissionService;
|
|
296
|
+
__decorate([
|
|
297
|
+
(0, utils_1.preLazy)()
|
|
298
|
+
], PermissionService.prototype, "modifyResourcePermission", null);
|
|
299
|
+
__decorate([
|
|
300
|
+
(0, utils_1.preLazy)()
|
|
301
|
+
], PermissionService.prototype, "describeResourcePermission", null);
|
|
302
|
+
__decorate([
|
|
303
|
+
(0, utils_1.preLazy)()
|
|
304
|
+
], PermissionService.prototype, "createRole", null);
|
|
305
|
+
__decorate([
|
|
306
|
+
(0, utils_1.preLazy)()
|
|
307
|
+
], PermissionService.prototype, "describeRoleList", null);
|
|
308
|
+
__decorate([
|
|
309
|
+
(0, utils_1.preLazy)()
|
|
310
|
+
], PermissionService.prototype, "modifyRole", null);
|
|
311
|
+
__decorate([
|
|
312
|
+
(0, utils_1.preLazy)()
|
|
313
|
+
], PermissionService.prototype, "deleteRoles", null);
|
package/package.json
CHANGED
package/types/environment.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { UserService } from './user';
|
|
|
14
14
|
import { CloudBaseRunService } from './cloudBaseRun';
|
|
15
15
|
import { MysqlService } from './mysql';
|
|
16
16
|
import { EnvInfo } from './interfaces';
|
|
17
|
+
import { PermissionService } from './permission';
|
|
17
18
|
export declare class Environment {
|
|
18
19
|
inited: boolean;
|
|
19
20
|
cloudBaseContext: CloudBaseContext;
|
|
@@ -33,6 +34,7 @@ export declare class Environment {
|
|
|
33
34
|
private userService;
|
|
34
35
|
private cloudBaseRunService;
|
|
35
36
|
private mysqlService;
|
|
37
|
+
private permissionService;
|
|
36
38
|
constructor(context: CloudBaseContext, envId: string);
|
|
37
39
|
lazyInit(): Promise<any>;
|
|
38
40
|
getEnvId(): string;
|
|
@@ -50,6 +52,7 @@ export declare class Environment {
|
|
|
50
52
|
getUserService(): UserService;
|
|
51
53
|
getCloudBaseRunService(): CloudBaseRunService;
|
|
52
54
|
getMysqlService(): MysqlService;
|
|
55
|
+
getPermissionService(): PermissionService;
|
|
53
56
|
getCommonService(serviceType: string, serviceVersion: any): CommonService;
|
|
54
57
|
getServicesEnvInfo(): Promise<any>;
|
|
55
58
|
getAuthConfig(): {
|
package/types/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { UserService } from './user';
|
|
|
15
15
|
import { CloudBaseRunService } from './cloudBaseRun';
|
|
16
16
|
import { MysqlService } from './mysql';
|
|
17
17
|
import { DocsService } from './docs';
|
|
18
|
+
import { PermissionService } from './permission';
|
|
18
19
|
interface CloudBaseConfig {
|
|
19
20
|
secretId?: string;
|
|
20
21
|
secretKey?: string;
|
|
@@ -58,6 +59,7 @@ declare class CloudBase {
|
|
|
58
59
|
get log(): LogService;
|
|
59
60
|
get third(): ThirdService;
|
|
60
61
|
get user(): UserService;
|
|
62
|
+
get permission(): PermissionService;
|
|
61
63
|
get docs(): DocsService;
|
|
62
64
|
getEnvironmentManager(): EnvironmentManager;
|
|
63
65
|
getManagerConfig(): CloudBaseConfig;
|
package/types/log/index.d.ts
CHANGED
|
@@ -1,11 +1,43 @@
|
|
|
1
1
|
import { Environment } from '../environment';
|
|
2
2
|
import { ISearchClsLogParams, ISearchClsLogResponse } from './types';
|
|
3
3
|
export * from './types';
|
|
4
|
+
export interface ICreateEnvResourceResponse {
|
|
5
|
+
RequestId: string;
|
|
6
|
+
}
|
|
7
|
+
export interface ILogServiceEntry {
|
|
8
|
+
LogsetId?: string;
|
|
9
|
+
TopicId?: string;
|
|
10
|
+
TopicName?: string;
|
|
11
|
+
Region?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 纯函数:根据 DescribeEnvs 返回的 LogServices 列表判断日志服务是否已开通。
|
|
15
|
+
* 已开通条件:至少一个条目有有效的 TopicId。
|
|
16
|
+
*/
|
|
17
|
+
export declare function isLogServiceEnabled(logServices?: ILogServiceEntry[]): boolean;
|
|
4
18
|
export declare class LogService {
|
|
5
19
|
private envId;
|
|
6
20
|
private cloudService;
|
|
7
21
|
private tcbrService;
|
|
8
22
|
constructor(environment: Environment);
|
|
23
|
+
/**
|
|
24
|
+
* 检查当前环境的日志服务是否已开通
|
|
25
|
+
*
|
|
26
|
+
* 通过 DescribeEnvs 接口获取环境信息,判断 LogServices 字段中是否包含有效的
|
|
27
|
+
* 日志主题(TopicId 不为空)。
|
|
28
|
+
*
|
|
29
|
+
* @returns true 表示已开通,false 表示未开通或开通中
|
|
30
|
+
*/
|
|
31
|
+
checkLogServiceEnabled(): Promise<boolean>;
|
|
32
|
+
/**
|
|
33
|
+
* 开通环境日志服务(异步操作)
|
|
34
|
+
*
|
|
35
|
+
* 调用 CreateEnvResource 接口开通日志资源。
|
|
36
|
+
* 注意:接口调用成功不代表日志资源立即可用,需通过 checkLogServiceEnabled() 轮询确认。
|
|
37
|
+
*
|
|
38
|
+
* @returns 请求 ID
|
|
39
|
+
*/
|
|
40
|
+
createLogService(): Promise<ICreateEnvResourceResponse>;
|
|
9
41
|
/**
|
|
10
42
|
* 搜索 CLS 日志
|
|
11
43
|
*
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Environment } from '../environment';
|
|
2
|
+
import { ModifyResourcePermissionOptions, ModifyResourcePermissionResp, DescribeResourcePermissionOptions, DescribeResourcePermissionResp, CreateRoleOptions, CreateRoleResp, DescribeRoleListOptions, DescribeRoleListResp, ModifyRoleOptions, ModifyRoleResp, DeleteRolesOptions, DeleteRolesResp } from './types';
|
|
3
|
+
export declare class PermissionService {
|
|
4
|
+
private environment;
|
|
5
|
+
private tcbService;
|
|
6
|
+
constructor(environment: Environment);
|
|
7
|
+
modifyResourcePermission(options: ModifyResourcePermissionOptions): Promise<{
|
|
8
|
+
Data: ModifyResourcePermissionResp;
|
|
9
|
+
RequestId: string;
|
|
10
|
+
}>;
|
|
11
|
+
describeResourcePermission(options: DescribeResourcePermissionOptions): Promise<{
|
|
12
|
+
Data: DescribeResourcePermissionResp;
|
|
13
|
+
RequestId: string;
|
|
14
|
+
}>;
|
|
15
|
+
createRole(options: CreateRoleOptions): Promise<{
|
|
16
|
+
Data: CreateRoleResp;
|
|
17
|
+
RequestId: string;
|
|
18
|
+
}>;
|
|
19
|
+
describeRoleList(options?: DescribeRoleListOptions): Promise<{
|
|
20
|
+
Data: DescribeRoleListResp;
|
|
21
|
+
RequestId: string;
|
|
22
|
+
}>;
|
|
23
|
+
modifyRole(options: ModifyRoleOptions): Promise<{
|
|
24
|
+
Data: ModifyRoleResp;
|
|
25
|
+
RequestId: string;
|
|
26
|
+
}>;
|
|
27
|
+
deleteRoles(options: DeleteRolesOptions): Promise<{
|
|
28
|
+
Data: DeleteRolesResp;
|
|
29
|
+
RequestId: string;
|
|
30
|
+
}>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
export type PermissionResourceType = 'function' | 'storage' | 'table' | 'collection';
|
|
2
|
+
export type BasePermission = 'READONLY' | 'PRIVATE' | 'ADMINWRITE' | 'ADMINONLY' | 'CUSTOM';
|
|
3
|
+
export interface ModifyResourcePermissionOptions {
|
|
4
|
+
resourceType: PermissionResourceType;
|
|
5
|
+
resource: string;
|
|
6
|
+
permission: BasePermission;
|
|
7
|
+
securityRule?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ModifyResourcePermissionResp {
|
|
10
|
+
Success: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface DescribeResourcePermissionOptions {
|
|
13
|
+
resourceType: PermissionResourceType;
|
|
14
|
+
resources?: string[];
|
|
15
|
+
}
|
|
16
|
+
export interface ResourcePermission {
|
|
17
|
+
ResourceType?: PermissionResourceType;
|
|
18
|
+
Resource?: string;
|
|
19
|
+
Permission?: BasePermission | string;
|
|
20
|
+
SecurityRule?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface DescribeResourcePermissionResp {
|
|
23
|
+
TotalCount: number;
|
|
24
|
+
PermissionList: ResourcePermission[];
|
|
25
|
+
}
|
|
26
|
+
export type QueryConditionRel = 'eq' | 'neq' | 'lt' | 'gt' | 'gte' | 'lte' | 'in' | 'nin' | 'search';
|
|
27
|
+
export interface QueryConditionItem {
|
|
28
|
+
Key: string;
|
|
29
|
+
Rel: QueryConditionRel;
|
|
30
|
+
Val: string;
|
|
31
|
+
ValueType?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface QueryCondition {
|
|
34
|
+
Key: string;
|
|
35
|
+
Value: string;
|
|
36
|
+
QueryConditions?: QueryConditionItem[];
|
|
37
|
+
}
|
|
38
|
+
export interface WorkBenchFeatureItem {
|
|
39
|
+
Code?: string;
|
|
40
|
+
Name?: string;
|
|
41
|
+
IsAccess?: boolean;
|
|
42
|
+
ParentCode?: string;
|
|
43
|
+
SubPermissions?: WorkBenchFeatureItem[];
|
|
44
|
+
}
|
|
45
|
+
export interface WorkBenchPermission {
|
|
46
|
+
AllPermission?: boolean;
|
|
47
|
+
PartPermission?: boolean;
|
|
48
|
+
Permissions?: WorkBenchFeatureItem[];
|
|
49
|
+
}
|
|
50
|
+
export interface PermissionPolicyItem {
|
|
51
|
+
ResourceType: string;
|
|
52
|
+
Resource: string;
|
|
53
|
+
ResourceName?: string;
|
|
54
|
+
Permission?: string;
|
|
55
|
+
Effect?: string;
|
|
56
|
+
IsBindAllAccess?: boolean;
|
|
57
|
+
SubResourceIdList?: string[];
|
|
58
|
+
RowPermission?: QueryCondition[];
|
|
59
|
+
FeatureAuth?: WorkBenchPermission;
|
|
60
|
+
GatewayPolicyCode?: string;
|
|
61
|
+
GatewayPolicyName?: string;
|
|
62
|
+
GatewayPolicyDescription?: string;
|
|
63
|
+
GatewayPolicyExpression?: string;
|
|
64
|
+
}
|
|
65
|
+
export interface CreateRoleOptions {
|
|
66
|
+
roleName: string;
|
|
67
|
+
roleIdentity: string;
|
|
68
|
+
description?: string;
|
|
69
|
+
memberUids?: string[];
|
|
70
|
+
policies?: PermissionPolicyItem[];
|
|
71
|
+
}
|
|
72
|
+
export interface CreateRoleResp {
|
|
73
|
+
RoleId?: string;
|
|
74
|
+
MemberUids?: string[];
|
|
75
|
+
Policies?: PermissionPolicyItem[];
|
|
76
|
+
}
|
|
77
|
+
export interface MemberInfo {
|
|
78
|
+
Uid?: string;
|
|
79
|
+
Name?: string;
|
|
80
|
+
NickName?: string;
|
|
81
|
+
}
|
|
82
|
+
export interface RoleItem {
|
|
83
|
+
RoleId?: string;
|
|
84
|
+
RoleIdentity?: string;
|
|
85
|
+
RoleName?: string;
|
|
86
|
+
RoleType?: 'system' | 'custom';
|
|
87
|
+
Description?: string;
|
|
88
|
+
Members?: MemberInfo[];
|
|
89
|
+
Policies?: PermissionPolicyItem[];
|
|
90
|
+
}
|
|
91
|
+
export interface DescribeRoleListOptions {
|
|
92
|
+
pageNumber?: number;
|
|
93
|
+
pageSize?: number;
|
|
94
|
+
roleId?: string;
|
|
95
|
+
roleIdentity?: string;
|
|
96
|
+
roleName?: string;
|
|
97
|
+
loadDetails?: boolean;
|
|
98
|
+
}
|
|
99
|
+
export interface DescribeRoleListResp {
|
|
100
|
+
TotalCount?: number;
|
|
101
|
+
CustomTotalCount?: number;
|
|
102
|
+
SystemRoles?: RoleItem[];
|
|
103
|
+
CustomRoles?: RoleItem[];
|
|
104
|
+
}
|
|
105
|
+
export interface ModifyRoleOptions {
|
|
106
|
+
roleId: string;
|
|
107
|
+
roleName?: string;
|
|
108
|
+
description?: string;
|
|
109
|
+
addMemberUids?: string[];
|
|
110
|
+
removeMemberUids?: string[];
|
|
111
|
+
addPolicies?: PermissionPolicyItem[];
|
|
112
|
+
removePolicies?: PermissionPolicyItem[];
|
|
113
|
+
}
|
|
114
|
+
export interface ModifyRoleResp {
|
|
115
|
+
Success?: boolean;
|
|
116
|
+
AddedMemberUids?: string[];
|
|
117
|
+
RemovedMemberUids?: string[];
|
|
118
|
+
AddedPolicies?: PermissionPolicyItem[];
|
|
119
|
+
RemovedPolicies?: PermissionPolicyItem[];
|
|
120
|
+
}
|
|
121
|
+
export interface DeleteRolesOptions {
|
|
122
|
+
roleIds: string[];
|
|
123
|
+
}
|
|
124
|
+
export interface DeleteRolesResp {
|
|
125
|
+
SuccessCount?: number;
|
|
126
|
+
FailedCount?: number;
|
|
127
|
+
}
|