@geek-fun/serverlessinsight 0.7.6 → 0.7.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/README.md +155 -409
- package/dist/package.json +2 -1
- package/dist/src/common/aliyunClient/ossOperations.js +41 -0
- package/dist/src/common/aliyunClient/ramOperations.js +161 -7
- package/dist/src/common/iamStatements.js +48 -0
- package/dist/src/common/tencentClient/camOperations.js +317 -0
- package/dist/src/common/tencentClient/cosOperations.js +67 -0
- package/dist/src/common/tencentClient/index.js +18 -0
- package/dist/src/common/tencentClient/scfOperations.js +2 -0
- package/dist/src/common/volcengineClient/iamOperations.js +133 -47
- package/dist/src/common/volcengineClient/tosOperations.js +79 -0
- package/dist/src/lang/en.js +24 -0
- package/dist/src/lang/zh-CN.js +24 -0
- package/dist/src/parser/bucketParser.js +31 -0
- package/dist/src/parser/functionParser.js +34 -0
- package/dist/src/stack/aliyunStack/fc3Planner.js +2 -1
- package/dist/src/stack/aliyunStack/fc3Resource.js +72 -14
- package/dist/src/stack/aliyunStack/ossResource.js +63 -0
- package/dist/src/stack/aliyunStack/ossTypes.js +9 -0
- package/dist/src/stack/localStack/aliyunFc.js +6 -1
- package/dist/src/stack/scfStack/cosResource.js +58 -0
- package/dist/src/stack/scfStack/cosTypes.js +9 -0
- package/dist/src/stack/scfStack/scfPlanner.js +1 -1
- package/dist/src/stack/scfStack/scfResource.js +195 -22
- package/dist/src/stack/scfStack/scfTypes.js +6 -4
- package/dist/src/stack/volcengineStack/tosResource.js +56 -0
- package/dist/src/stack/volcengineStack/tosTypes.js +9 -0
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +2 -1
- package/dist/src/stack/volcengineStack/vefaasResource.js +46 -5
- package/dist/src/types/domains/state.js +2 -0
- package/dist/src/validator/bucketSchema.js +45 -0
- package/dist/src/validator/functionSchema.js +43 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/samples/aliyun-poc-api-cdn.yml +75 -0
|
@@ -555,6 +555,73 @@ const createCosOperations = (cosClient, region, dnsOps) => {
|
|
|
555
555
|
bindCustomDomain,
|
|
556
556
|
unbindCustomDomain,
|
|
557
557
|
getCosEndpoint,
|
|
558
|
+
putBucketPolicy: async (bucketName, region, policy) => {
|
|
559
|
+
await new Promise((resolve, reject) => {
|
|
560
|
+
cosClient.putBucketPolicy({
|
|
561
|
+
Bucket: bucketName,
|
|
562
|
+
Region: region,
|
|
563
|
+
Policy: policy,
|
|
564
|
+
}, (err) => {
|
|
565
|
+
if (err)
|
|
566
|
+
reject(err);
|
|
567
|
+
else
|
|
568
|
+
resolve();
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
logger_1.logger.info(lang_1.lang.__('COS_BUCKET_POLICY_SET', { bucketName }));
|
|
572
|
+
},
|
|
573
|
+
getBucketPolicy: async (bucketName, region) => {
|
|
574
|
+
try {
|
|
575
|
+
const result = await new Promise((resolve, reject) => {
|
|
576
|
+
cosClient.getBucketPolicy({
|
|
577
|
+
Bucket: bucketName,
|
|
578
|
+
Region: region,
|
|
579
|
+
}, (err, data) => {
|
|
580
|
+
if (err)
|
|
581
|
+
reject(err);
|
|
582
|
+
else
|
|
583
|
+
resolve(data);
|
|
584
|
+
});
|
|
585
|
+
});
|
|
586
|
+
if (result.Policy) {
|
|
587
|
+
return typeof result.Policy === 'string' ? JSON.parse(result.Policy) : result.Policy;
|
|
588
|
+
}
|
|
589
|
+
return null;
|
|
590
|
+
}
|
|
591
|
+
catch (err) {
|
|
592
|
+
const e = err;
|
|
593
|
+
if (e.statusCode === 404 || e.statusCode === 403 || e.code === 'NoSuchBucketPolicy') {
|
|
594
|
+
return null;
|
|
595
|
+
}
|
|
596
|
+
throw err;
|
|
597
|
+
}
|
|
598
|
+
},
|
|
599
|
+
deleteBucketPolicy: async (bucketName, region) => {
|
|
600
|
+
try {
|
|
601
|
+
// COS SDK doesn't have a direct deleteBucketPolicy method.
|
|
602
|
+
// We delete by setting an empty policy.
|
|
603
|
+
const emptyPolicy = {
|
|
604
|
+
version: '2.0',
|
|
605
|
+
statement: [],
|
|
606
|
+
};
|
|
607
|
+
await new Promise((resolve, reject) => {
|
|
608
|
+
cosClient.putBucketPolicy({
|
|
609
|
+
Bucket: bucketName,
|
|
610
|
+
Region: region,
|
|
611
|
+
Policy: emptyPolicy,
|
|
612
|
+
}, (err) => {
|
|
613
|
+
if (err)
|
|
614
|
+
reject(err);
|
|
615
|
+
else
|
|
616
|
+
resolve();
|
|
617
|
+
});
|
|
618
|
+
});
|
|
619
|
+
logger_1.logger.info(lang_1.lang.__('COS_BUCKET_POLICY_DELETED', { bucketName }));
|
|
620
|
+
}
|
|
621
|
+
catch {
|
|
622
|
+
// Best effort cleanup
|
|
623
|
+
}
|
|
624
|
+
},
|
|
558
625
|
};
|
|
559
626
|
};
|
|
560
627
|
exports.createCosOperations = createCosOperations;
|
|
@@ -42,11 +42,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
42
42
|
exports.createTencentClient = void 0;
|
|
43
43
|
const tencentcloud = __importStar(require("tencentcloud-sdk-nodejs-scf"));
|
|
44
44
|
const cynosdb = __importStar(require("tencentcloud-sdk-nodejs-cynosdb"));
|
|
45
|
+
const tencentCam = __importStar(require("tencentcloud-sdk-nodejs-cam"));
|
|
45
46
|
const tencentEs = __importStar(require("tencentcloud-sdk-nodejs-es"));
|
|
46
47
|
const tencentSsl = __importStar(require("tencentcloud-sdk-nodejs-ssl"));
|
|
47
48
|
const cos_nodejs_sdk_v5_1 = __importDefault(require("cos-nodejs-sdk-v5"));
|
|
48
49
|
const scfOperations_1 = require("./scfOperations");
|
|
49
50
|
const cosOperations_1 = require("./cosOperations");
|
|
51
|
+
const camOperations_1 = require("./camOperations");
|
|
50
52
|
const tdsqlcOperations_1 = require("./tdsqlcOperations");
|
|
51
53
|
const esOperations_1 = require("./esOperations");
|
|
52
54
|
const dnspodOperations_1 = require("./dnspodOperations");
|
|
@@ -54,6 +56,7 @@ const sslOperations_1 = require("./sslOperations");
|
|
|
54
56
|
__exportStar(require("./types"), exports);
|
|
55
57
|
const ScfClient = tencentcloud.scf.v20180416.Client;
|
|
56
58
|
const CynosdbClient = cynosdb.cynosdb.v20190107.Client;
|
|
59
|
+
const CamClient = tencentCam.cam.v20190116.Client;
|
|
57
60
|
const EsClient = tencentEs.es.v20180416.Client;
|
|
58
61
|
const SslClient = tencentSsl.ssl.v20191205.Client;
|
|
59
62
|
// Initialize SDK clients (internal)
|
|
@@ -114,6 +117,19 @@ const initializeSdkClients = (context) => {
|
|
|
114
117
|
},
|
|
115
118
|
};
|
|
116
119
|
const sslClient = new SslClient(sslClientConfig);
|
|
120
|
+
const camClientConfig = {
|
|
121
|
+
credential: {
|
|
122
|
+
secretId: context.accessKeyId,
|
|
123
|
+
secretKey: context.accessKeySecret,
|
|
124
|
+
},
|
|
125
|
+
region: context.region,
|
|
126
|
+
profile: {
|
|
127
|
+
httpProfile: {
|
|
128
|
+
endpoint: 'cam.tencentcloudapi.com',
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
const camClient = new CamClient(camClientConfig);
|
|
117
133
|
return {
|
|
118
134
|
scf: scfClient,
|
|
119
135
|
cos: cosClient,
|
|
@@ -121,6 +137,7 @@ const initializeSdkClients = (context) => {
|
|
|
121
137
|
es: esClient,
|
|
122
138
|
ssl: sslClient,
|
|
123
139
|
dns: (0, dnspodOperations_1.createDnsClient)(context),
|
|
140
|
+
cam: camClient,
|
|
124
141
|
};
|
|
125
142
|
};
|
|
126
143
|
const createTencentClient = (context) => {
|
|
@@ -129,6 +146,7 @@ const createTencentClient = (context) => {
|
|
|
129
146
|
return {
|
|
130
147
|
scf: (0, scfOperations_1.createScfOperations)(sdkClients.scf),
|
|
131
148
|
cos: (0, cosOperations_1.createCosOperations)(sdkClients.cos, context.region, dnsOps),
|
|
149
|
+
cam: (0, camOperations_1.createCamOperations)(sdkClients.cam),
|
|
132
150
|
tdsqlc: (0, tdsqlcOperations_1.createTdsqlcOperations)(sdkClients.cynosdb, context),
|
|
133
151
|
es: (0, esOperations_1.createTencentEsOperations)(sdkClients.es, context),
|
|
134
152
|
ssl: (0, sslOperations_1.createSslOperations)(sdkClients.ssl),
|
|
@@ -12,6 +12,7 @@ const createScfOperations = (scfClient) => ({
|
|
|
12
12
|
Runtime: config.Runtime,
|
|
13
13
|
MemorySize: config.MemorySize,
|
|
14
14
|
Timeout: config.Timeout,
|
|
15
|
+
...(config.Role && { Role: config.Role }),
|
|
15
16
|
...(config.Environment && { Environment: config.Environment }),
|
|
16
17
|
};
|
|
17
18
|
await scfClient.CreateFunction(params);
|
|
@@ -120,6 +121,7 @@ const createScfOperations = (scfClient) => ({
|
|
|
120
121
|
Runtime: config.Runtime,
|
|
121
122
|
MemorySize: config.MemorySize,
|
|
122
123
|
Timeout: config.Timeout,
|
|
124
|
+
...(config.Role && { Role: config.Role }),
|
|
123
125
|
...(config.Environment && { Environment: config.Environment }),
|
|
124
126
|
};
|
|
125
127
|
await scfClient.UpdateFunctionConfiguration(params);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createIamOperations = void 0;
|
|
4
|
+
const iamStatements_1 = require("../iamStatements");
|
|
4
5
|
const logger_1 = require("../logger");
|
|
5
6
|
const lang_1 = require("../../lang");
|
|
6
7
|
const DEFAULT_TRUST_POLICY_SERVICES = ['vefaas.volcengine.com'];
|
|
@@ -41,8 +42,24 @@ const VEFAAS_EXECUTION_POLICY = JSON.stringify({
|
|
|
41
42
|
},
|
|
42
43
|
],
|
|
43
44
|
});
|
|
45
|
+
const VEFAAS_EXECUTION_STATEMENTS = (0, iamStatements_1.parseBuiltInStatements)(VEFAAS_EXECUTION_POLICY);
|
|
46
|
+
const mapToVolcengineStatement = (stmt) => {
|
|
47
|
+
const result = {
|
|
48
|
+
Effect: stmt.effect,
|
|
49
|
+
Action: stmt.action,
|
|
50
|
+
Resource: stmt.resource,
|
|
51
|
+
};
|
|
52
|
+
if (stmt.sid) {
|
|
53
|
+
result.Sid = stmt.sid;
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
};
|
|
57
|
+
const buildExecutionPolicy = (customStatements) => {
|
|
58
|
+
const merged = (0, iamStatements_1.mergePolicyStatements)(VEFAAS_EXECUTION_STATEMENTS, customStatements, mapToVolcengineStatement);
|
|
59
|
+
return (0, iamStatements_1.buildPolicyDocument)(merged);
|
|
60
|
+
};
|
|
44
61
|
const createIamOperations = (iamClient) => {
|
|
45
|
-
const createAndAttachPolicy = async (roleName) => {
|
|
62
|
+
const createAndAttachPolicy = async (roleName, customStatements) => {
|
|
46
63
|
const policyName = `${roleName}-policy`;
|
|
47
64
|
try {
|
|
48
65
|
await iamClient.fetchOpenAPI({
|
|
@@ -52,7 +69,7 @@ const createIamOperations = (iamClient) => {
|
|
|
52
69
|
headers: { 'content-type': 'application/json' },
|
|
53
70
|
data: {
|
|
54
71
|
PolicyName: policyName,
|
|
55
|
-
PolicyDocument:
|
|
72
|
+
PolicyDocument: buildExecutionPolicy(customStatements),
|
|
56
73
|
Description: `veFaaS execution policy for ${roleName}`,
|
|
57
74
|
},
|
|
58
75
|
});
|
|
@@ -132,9 +149,80 @@ const createIamOperations = (iamClient) => {
|
|
|
132
149
|
// Ignore if policy doesn't exist
|
|
133
150
|
}
|
|
134
151
|
};
|
|
152
|
+
const attachRolePolicyImpl = async (roleName, policyName, policyType) => {
|
|
153
|
+
try {
|
|
154
|
+
await iamClient.fetchOpenAPI({
|
|
155
|
+
Action: 'AttachRolePolicy',
|
|
156
|
+
Version: '2024-01-01',
|
|
157
|
+
method: 'POST',
|
|
158
|
+
headers: { 'content-type': 'application/json' },
|
|
159
|
+
data: {
|
|
160
|
+
RoleName: roleName,
|
|
161
|
+
PolicyName: policyName,
|
|
162
|
+
PolicyType: policyType,
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
logger_1.logger.info(lang_1.lang.__('IAM_POLICY_ATTACHED', { policyName, roleName }));
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
if (error && typeof error === 'object' && 'code' in error) {
|
|
169
|
+
if (error.code === 'PolicyAlreadyAttached' || error.code === 'Conflict') {
|
|
170
|
+
logger_1.logger.info(lang_1.lang.__('IAM_POLICY_ALREADY_ATTACHED', { policyName, roleName }));
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
throw error;
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
const detachRolePolicyImpl = async (roleName, policyName, policyType = 'Custom') => {
|
|
178
|
+
try {
|
|
179
|
+
await iamClient.fetchOpenAPI({
|
|
180
|
+
Action: 'DetachRolePolicy',
|
|
181
|
+
Version: '2024-01-01',
|
|
182
|
+
method: 'POST',
|
|
183
|
+
headers: { 'content-type': 'application/json' },
|
|
184
|
+
data: {
|
|
185
|
+
RoleName: roleName,
|
|
186
|
+
PolicyName: policyName,
|
|
187
|
+
PolicyType: policyType,
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
logger_1.logger.info(lang_1.lang.__('IAM_POLICY_DETACHED', { policyName, roleName }));
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
if (error &&
|
|
194
|
+
typeof error === 'object' &&
|
|
195
|
+
'code' in error &&
|
|
196
|
+
(error.code === 'PolicyNotAttached' || error.code === 'NoSuchEntity')) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
logger_1.logger.warn(lang_1.lang.__('IAM_POLICY_DETACH_FAILED', { policyName, roleName, error: String(error) }));
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
const listAttachedRolePoliciesImpl = async (roleName) => {
|
|
203
|
+
try {
|
|
204
|
+
const response = await iamClient.fetchOpenAPI({
|
|
205
|
+
Action: 'ListAttachedRolePolicies',
|
|
206
|
+
Version: '2024-01-01',
|
|
207
|
+
method: 'POST',
|
|
208
|
+
headers: { 'content-type': 'application/json' },
|
|
209
|
+
data: { RoleName: roleName },
|
|
210
|
+
});
|
|
211
|
+
const result = (response.Result || {});
|
|
212
|
+
const attachedPolicies = result.AttachedRolePolicies;
|
|
213
|
+
if (!attachedPolicies) {
|
|
214
|
+
return [];
|
|
215
|
+
}
|
|
216
|
+
return attachedPolicies.filter((p) => p.PolicyName).map((p) => p.PolicyName);
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
return [];
|
|
220
|
+
}
|
|
221
|
+
};
|
|
135
222
|
return {
|
|
136
223
|
createRole: async (config) => {
|
|
137
224
|
const roleName = config.roleName;
|
|
225
|
+
const customStatements = config.customStatements;
|
|
138
226
|
const trustedServices = config.trustPolicy.Statement[0]?.Principal.Service || DEFAULT_TRUST_POLICY_SERVICES;
|
|
139
227
|
const trustPolicyDocument = buildTrustPolicyDocument(trustedServices);
|
|
140
228
|
try {
|
|
@@ -153,7 +241,12 @@ const createIamOperations = (iamClient) => {
|
|
|
153
241
|
});
|
|
154
242
|
const data = (response.Result || {});
|
|
155
243
|
const roleData = (data.Role || {});
|
|
156
|
-
const policyName = await createAndAttachPolicy(roleName);
|
|
244
|
+
const policyName = await createAndAttachPolicy(roleName, customStatements);
|
|
245
|
+
if (config.managedPolicies && config.managedPolicies.length > 0) {
|
|
246
|
+
for (const policyArn of config.managedPolicies) {
|
|
247
|
+
await attachRolePolicyImpl(roleName, policyArn, 'System');
|
|
248
|
+
}
|
|
249
|
+
}
|
|
157
250
|
logger_1.logger.info(lang_1.lang.__('IAM_ROLE_CREATED', { roleName }));
|
|
158
251
|
return {
|
|
159
252
|
roleName: roleData.RoleName,
|
|
@@ -164,6 +257,7 @@ const createIamOperations = (iamClient) => {
|
|
|
164
257
|
maxSessionDuration: roleData.MaxSessionDuration,
|
|
165
258
|
trustPolicyDocument,
|
|
166
259
|
policyName,
|
|
260
|
+
managedPolicies: config.managedPolicies,
|
|
167
261
|
};
|
|
168
262
|
}
|
|
169
263
|
catch (error) {
|
|
@@ -189,6 +283,11 @@ const createIamOperations = (iamClient) => {
|
|
|
189
283
|
},
|
|
190
284
|
});
|
|
191
285
|
const policyName = await createAndAttachPolicy(roleName);
|
|
286
|
+
if (config.managedPolicies && config.managedPolicies.length > 0) {
|
|
287
|
+
for (const policyArn of config.managedPolicies) {
|
|
288
|
+
await attachRolePolicyImpl(roleName, policyArn, 'System');
|
|
289
|
+
}
|
|
290
|
+
}
|
|
192
291
|
const roleData = (existingRole.Result || {})
|
|
193
292
|
.Role;
|
|
194
293
|
return {
|
|
@@ -200,6 +299,7 @@ const createIamOperations = (iamClient) => {
|
|
|
200
299
|
maxSessionDuration: roleData?.MaxSessionDuration,
|
|
201
300
|
trustPolicyDocument,
|
|
202
301
|
policyName,
|
|
302
|
+
managedPolicies: config.managedPolicies,
|
|
203
303
|
};
|
|
204
304
|
}
|
|
205
305
|
catch (recoveryError) {
|
|
@@ -273,6 +373,11 @@ const createIamOperations = (iamClient) => {
|
|
|
273
373
|
}
|
|
274
374
|
},
|
|
275
375
|
deleteRole: async (roleName) => {
|
|
376
|
+
// Detach managed policies before cleaning up custom policies and role
|
|
377
|
+
const currentManagedPolicies = await listAttachedRolePoliciesImpl(roleName);
|
|
378
|
+
for (const policyName of currentManagedPolicies) {
|
|
379
|
+
await detachRolePolicyImpl(roleName, policyName, 'System');
|
|
380
|
+
}
|
|
276
381
|
await detachAndDeletePolicy(roleName);
|
|
277
382
|
try {
|
|
278
383
|
await iamClient.fetchOpenAPI({
|
|
@@ -295,53 +400,34 @@ const createIamOperations = (iamClient) => {
|
|
|
295
400
|
}
|
|
296
401
|
},
|
|
297
402
|
attachRolePolicy: async (roleName, policyName, policyType) => {
|
|
298
|
-
|
|
299
|
-
await iamClient.fetchOpenAPI({
|
|
300
|
-
Action: 'AttachRolePolicy',
|
|
301
|
-
Version: '2024-01-01',
|
|
302
|
-
method: 'POST',
|
|
303
|
-
headers: { 'content-type': 'application/json' },
|
|
304
|
-
data: {
|
|
305
|
-
RoleName: roleName,
|
|
306
|
-
PolicyName: policyName,
|
|
307
|
-
PolicyType: policyType,
|
|
308
|
-
},
|
|
309
|
-
});
|
|
310
|
-
logger_1.logger.info(lang_1.lang.__('IAM_POLICY_ATTACHED', { policyName, roleName }));
|
|
311
|
-
}
|
|
312
|
-
catch (error) {
|
|
313
|
-
if (error && typeof error === 'object' && 'code' in error) {
|
|
314
|
-
if (error.code === 'PolicyAlreadyAttached' || error.code === 'Conflict') {
|
|
315
|
-
logger_1.logger.info(lang_1.lang.__('IAM_POLICY_ALREADY_ATTACHED', { policyName, roleName }));
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
throw error;
|
|
320
|
-
}
|
|
403
|
+
await attachRolePolicyImpl(roleName, policyName, policyType);
|
|
321
404
|
},
|
|
322
405
|
detachRolePolicy: async (roleName, policyName) => {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
406
|
+
await detachRolePolicyImpl(roleName, policyName);
|
|
407
|
+
},
|
|
408
|
+
updateRolePolicy: async (roleName, customStatements) => {
|
|
409
|
+
await detachAndDeletePolicy(roleName);
|
|
410
|
+
await createAndAttachPolicy(roleName, customStatements);
|
|
411
|
+
logger_1.logger.info(lang_1.lang.__('IAM_ROLE_POLICY_UPDATED', { roleName }));
|
|
412
|
+
},
|
|
413
|
+
listAttachedRolePolicies: async (roleName) => {
|
|
414
|
+
return listAttachedRolePoliciesImpl(roleName);
|
|
415
|
+
},
|
|
416
|
+
updateManagedPolicies: async (roleName, desiredPolicies) => {
|
|
417
|
+
const currentPolicies = await listAttachedRolePoliciesImpl(roleName);
|
|
418
|
+
const currentSet = new Set(currentPolicies);
|
|
419
|
+
const desiredSet = new Set(desiredPolicies);
|
|
420
|
+
const toAttach = desiredPolicies.filter((p) => !currentSet.has(p));
|
|
421
|
+
const toDetach = currentPolicies.filter((p) => !desiredSet.has(p));
|
|
422
|
+
for (const policyName of toDetach) {
|
|
423
|
+
logger_1.logger.info(lang_1.lang.__('DETACHING_MANAGED_POLICY', { policyArn: policyName, roleName }));
|
|
424
|
+
await detachRolePolicyImpl(roleName, policyName, 'System');
|
|
425
|
+
logger_1.logger.info(lang_1.lang.__('MANAGED_POLICY_DETACHED', { policyArn: policyName, roleName }));
|
|
336
426
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
(error.code === 'PolicyNotAttached' || error.code === 'NoSuchEntity')) {
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
logger_1.logger.warn(lang_1.lang.__('IAM_POLICY_DETACH_FAILED', { policyName, roleName, error: String(error) }));
|
|
427
|
+
for (const policyName of toAttach) {
|
|
428
|
+
logger_1.logger.info(lang_1.lang.__('ATTACHING_MANAGED_POLICY', { policyArn: policyName, roleName }));
|
|
429
|
+
await attachRolePolicyImpl(roleName, policyName, 'System');
|
|
430
|
+
logger_1.logger.info(lang_1.lang.__('MANAGED_POLICY_ATTACHED', { policyArn: policyName, roleName }));
|
|
345
431
|
}
|
|
346
432
|
},
|
|
347
433
|
};
|
|
@@ -380,6 +380,85 @@ const createTosOperations = (client, _region) => {
|
|
|
380
380
|
},
|
|
381
381
|
});
|
|
382
382
|
},
|
|
383
|
+
putBucketPolicy: async (bucketName, policy) => {
|
|
384
|
+
if (!client) {
|
|
385
|
+
throw new Error(lang_1.lang.__('VOLCENGINE_TOS_CLIENT_NOT_INITIALIZED'));
|
|
386
|
+
}
|
|
387
|
+
await client.fetchOpenAPI({
|
|
388
|
+
Action: 'PutBucketPolicy',
|
|
389
|
+
Version: '2018-08-01',
|
|
390
|
+
method: 'PUT',
|
|
391
|
+
headers: {
|
|
392
|
+
'content-type': 'application/json',
|
|
393
|
+
},
|
|
394
|
+
query: {
|
|
395
|
+
Bucket: bucketName,
|
|
396
|
+
},
|
|
397
|
+
data: policy,
|
|
398
|
+
});
|
|
399
|
+
logger_1.logger.info(lang_1.lang.__('TOS_BUCKET_POLICY_SET', { bucketName }));
|
|
400
|
+
},
|
|
401
|
+
getBucketPolicy: async (bucketName) => {
|
|
402
|
+
if (!client) {
|
|
403
|
+
throw new Error(lang_1.lang.__('VOLCENGINE_TOS_CLIENT_NOT_INITIALIZED'));
|
|
404
|
+
}
|
|
405
|
+
try {
|
|
406
|
+
const response = await client.fetchOpenAPI({
|
|
407
|
+
Action: 'GetBucketPolicy',
|
|
408
|
+
Version: '2018-08-01',
|
|
409
|
+
method: 'GET',
|
|
410
|
+
query: {
|
|
411
|
+
Bucket: bucketName,
|
|
412
|
+
},
|
|
413
|
+
});
|
|
414
|
+
// The response may contain the policy document in the Result
|
|
415
|
+
const result = (response.Result || {});
|
|
416
|
+
if (result.Policy) {
|
|
417
|
+
return typeof result.Policy === 'string'
|
|
418
|
+
? JSON.parse(result.Policy)
|
|
419
|
+
: result.Policy;
|
|
420
|
+
}
|
|
421
|
+
// Some TOS responses return the policy directly on the result
|
|
422
|
+
if (result.Statement || result.Version) {
|
|
423
|
+
return result;
|
|
424
|
+
}
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
catch (error) {
|
|
428
|
+
if (error &&
|
|
429
|
+
typeof error === 'object' &&
|
|
430
|
+
'code' in error &&
|
|
431
|
+
(error.code === 'NoSuchBucketPolicy' || error.code === 'ResourceNotFound')) {
|
|
432
|
+
return null;
|
|
433
|
+
}
|
|
434
|
+
throw error;
|
|
435
|
+
}
|
|
436
|
+
},
|
|
437
|
+
deleteBucketPolicy: async (bucketName) => {
|
|
438
|
+
if (!client) {
|
|
439
|
+
throw new Error(lang_1.lang.__('VOLCENGINE_TOS_CLIENT_NOT_INITIALIZED'));
|
|
440
|
+
}
|
|
441
|
+
try {
|
|
442
|
+
await client.fetchOpenAPI({
|
|
443
|
+
Action: 'DeleteBucketPolicy',
|
|
444
|
+
Version: '2018-08-01',
|
|
445
|
+
method: 'DELETE',
|
|
446
|
+
query: {
|
|
447
|
+
Bucket: bucketName,
|
|
448
|
+
},
|
|
449
|
+
});
|
|
450
|
+
logger_1.logger.info(lang_1.lang.__('TOS_BUCKET_POLICY_DELETED', { bucketName }));
|
|
451
|
+
}
|
|
452
|
+
catch (error) {
|
|
453
|
+
if (error &&
|
|
454
|
+
typeof error === 'object' &&
|
|
455
|
+
'code' in error &&
|
|
456
|
+
(error.code === 'NoSuchBucketPolicy' || error.code === 'ResourceNotFound')) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
throw error;
|
|
460
|
+
}
|
|
461
|
+
},
|
|
383
462
|
uploadFiles: async (bucketName, sourcePath) => {
|
|
384
463
|
if (!client) {
|
|
385
464
|
throw new Error(lang_1.lang.__('VOLCENGINE_TOS_CLIENT_NOT_INITIALIZED'));
|
package/dist/src/lang/en.js
CHANGED
|
@@ -608,6 +608,7 @@ exports.en = {
|
|
|
608
608
|
'The role existed in the cloud but recovery operations failed. ' +
|
|
609
609
|
'To fix: manually verify the role in the cloud console, remove it from state, and redeploy.',
|
|
610
610
|
IAM_ROLE_TRUST_POLICY_UPDATED: 'IAM role {{roleName}} trust policy updated',
|
|
611
|
+
IAM_ROLE_POLICY_UPDATED: 'IAM role {{roleName}} execution policy updated',
|
|
611
612
|
IAM_POLICY_ALREADY_EXISTS: 'IAM policy {{policyName}} already exists, reusing',
|
|
612
613
|
IAM_POLICY_ALREADY_ATTACHED: 'IAM policy {{policyName}} already attached to role {{roleName}}',
|
|
613
614
|
IAM_POLICY_ATTACHED: 'IAM policy {{policyName}} attached to role {{roleName}}',
|
|
@@ -618,6 +619,19 @@ exports.en = {
|
|
|
618
619
|
CREATING_IAM_ROLE: 'Creating IAM role: {{roleName}}',
|
|
619
620
|
DELETING_IAM_ROLE: 'Deleting IAM role: {{id}}',
|
|
620
621
|
IAM_POLICY_DETACH_FAILED: 'Failed to detach IAM policy {{policyName}} from role {{roleName}}: {{error}}',
|
|
622
|
+
// Tencent CAM role messages
|
|
623
|
+
ATTACHING_MANAGED_POLICY: 'Attaching managed policy {{policyArn}} to role {{roleName}}',
|
|
624
|
+
DETACHING_MANAGED_POLICY: 'Detaching managed policy {{policyArn}} from role {{roleName}}',
|
|
625
|
+
MANAGED_POLICY_ATTACHED: 'Managed policy {{policyArn}} attached to role {{roleName}}',
|
|
626
|
+
MANAGED_POLICY_DETACHED: 'Managed policy {{policyArn}} detached from role {{roleName}}',
|
|
627
|
+
USING_EXISTING_ROLE: 'Using existing role {{roleArn}} for function',
|
|
628
|
+
TENCENT_CAM_ROLE_CREATED: 'Tencent CAM role {{roleName}} created',
|
|
629
|
+
TENCENT_CAM_ROLE_DELETED: 'Tencent CAM role {{roleName}} deleted',
|
|
630
|
+
TENCENT_CAM_ROLE_NOT_FOUND: 'Tencent CAM role {{roleName}} not found in cloud provider',
|
|
631
|
+
TENCENT_CAM_ROLE_ALREADY_EXISTS: 'Tencent CAM role {{roleName}} already exists',
|
|
632
|
+
TENCENT_CAM_ROLE_DRIFT_RECOVERY_FAILED: 'Tencent CAM role drift recovery failed for {{roleName}}: {{error}}',
|
|
633
|
+
TENCENT_CAM_POLICY_ALREADY_ATTACHED: 'Policy already attached to CAM role {{roleName}}',
|
|
634
|
+
TENCENT_CAM_POLICY_ALREADY_EXISTS: 'Tencent CAM policy already exists',
|
|
621
635
|
// Volcengine TLS (Log Service) messages
|
|
622
636
|
TLS_PROJECT_CREATED: 'TLS project {{projectName}} created successfully',
|
|
623
637
|
TLS_PROJECT_DELETED: 'TLS project {{projectName}} deleted successfully',
|
|
@@ -657,4 +671,14 @@ exports.en = {
|
|
|
657
671
|
FAILED_TO_UPLOAD_BUCKET_FILES: 'Failed to upload files to bucket, but bucket was created and saved to state: {{error}}',
|
|
658
672
|
FAILED_TO_ENABLE_ACCELERATION: 'Failed to enable transfer acceleration for bucket {{bucketName}}',
|
|
659
673
|
CDN_ACCELERATE_CONFIG_CHANGED: 'Cannot change CDN/accelerate settings for bucket {{bucketName}} via update. Use destroy+recreate to change CDN or acceleration configuration.',
|
|
674
|
+
// Bucket IAM Policy messages
|
|
675
|
+
BUCKET_POLICY_APPLYING: 'Applying IAM bucket policy to bucket {{bucketName}}',
|
|
676
|
+
BUCKET_POLICY_APPLIED: 'IAM bucket policy applied to bucket {{bucketName}}',
|
|
677
|
+
BUCKET_POLICY_DELETED: 'IAM bucket policy removed from bucket {{bucketName}}',
|
|
678
|
+
OSS_BUCKET_POLICY_SET: 'OSS bucket policy set for {{bucketName}}',
|
|
679
|
+
OSS_BUCKET_POLICY_DELETED: 'OSS bucket policy deleted for {{bucketName}}',
|
|
680
|
+
COS_BUCKET_POLICY_SET: 'COS bucket policy set for {{bucketName}}',
|
|
681
|
+
COS_BUCKET_POLICY_DELETED: 'COS bucket policy deleted for {{bucketName}}',
|
|
682
|
+
TOS_BUCKET_POLICY_SET: 'TOS bucket policy set for {{bucketName}}',
|
|
683
|
+
TOS_BUCKET_POLICY_DELETED: 'TOS bucket policy deleted for {{bucketName}}',
|
|
660
684
|
};
|
package/dist/src/lang/zh-CN.js
CHANGED
|
@@ -602,6 +602,7 @@ exports.zhCN = {
|
|
|
602
602
|
'角色在云端存在但恢复操作失败。' +
|
|
603
603
|
'修复方法:在云控制台手动确认角色状态,从状态中移除该角色并重新部署。',
|
|
604
604
|
IAM_ROLE_TRUST_POLICY_UPDATED: 'IAM 角色 {{roleName}} 信任策略已更新',
|
|
605
|
+
IAM_ROLE_POLICY_UPDATED: 'IAM 角色 {{roleName}} 执行策略已更新',
|
|
605
606
|
IAM_POLICY_ALREADY_EXISTS: 'IAM 策略 {{policyName}} 已存在,复用现有策略',
|
|
606
607
|
IAM_POLICY_ALREADY_ATTACHED: 'IAM 策略 {{policyName}} 已附加到角色 {{roleName}}',
|
|
607
608
|
IAM_POLICY_ATTACHED: 'IAM 策略 {{policyName}} 已附加到角色 {{roleName}}',
|
|
@@ -612,6 +613,19 @@ exports.zhCN = {
|
|
|
612
613
|
CREATING_IAM_ROLE: '正在创建 IAM 角色:{{roleName}}',
|
|
613
614
|
DELETING_IAM_ROLE: '正在删除 IAM 角色:{{id}}',
|
|
614
615
|
IAM_POLICY_DETACH_FAILED: '从角色 {{roleName}} 解除 IAM 策略 {{policyName}} 失败:{{error}}',
|
|
616
|
+
// Tencent CAM role messages
|
|
617
|
+
ATTACHING_MANAGED_POLICY: '正在为角色 {{roleName}} 附加托管策略 {{policyArn}}',
|
|
618
|
+
DETACHING_MANAGED_POLICY: '正在从角色 {{roleName}} 解除托管策略 {{policyArn}}',
|
|
619
|
+
MANAGED_POLICY_ATTACHED: '托管策略 {{policyArn}} 已附加到角色 {{roleName}}',
|
|
620
|
+
MANAGED_POLICY_DETACHED: '托管策略 {{policyArn}} 已从角色 {{roleName}} 解除',
|
|
621
|
+
USING_EXISTING_ROLE: '为函数使用已有角色 {{roleArn}}',
|
|
622
|
+
TENCENT_CAM_ROLE_CREATED: '腾讯云 CAM 角色 {{roleName}} 创建成功',
|
|
623
|
+
TENCENT_CAM_ROLE_DELETED: '腾讯云 CAM 角色 {{roleName}} 删除成功',
|
|
624
|
+
TENCENT_CAM_ROLE_NOT_FOUND: '腾讯云 CAM 角色 {{roleName}} 在云服务商中未找到',
|
|
625
|
+
TENCENT_CAM_ROLE_ALREADY_EXISTS: '腾讯云 CAM 角色 {{roleName}} 已存在',
|
|
626
|
+
TENCENT_CAM_ROLE_DRIFT_RECOVERY_FAILED: '腾讯云 CAM 角色 {{roleName}} 状态漂移恢复失败:{{error}}',
|
|
627
|
+
TENCENT_CAM_POLICY_ALREADY_ATTACHED: 'CAM 角色 {{roleName}} 已附加该策略',
|
|
628
|
+
TENCENT_CAM_POLICY_ALREADY_EXISTS: '腾讯云 CAM 策略已存在',
|
|
615
629
|
// Volcengine TLS (Log Service) messages
|
|
616
630
|
TLS_PROJECT_CREATED: 'TLS 项目 {{projectName}} 创建成功',
|
|
617
631
|
TLS_PROJECT_DELETED: 'TLS 项目 {{projectName}} 删除成功',
|
|
@@ -651,4 +665,14 @@ exports.zhCN = {
|
|
|
651
665
|
FAILED_TO_UPLOAD_BUCKET_FILES: '上传文件到存储桶失败,但存储桶已创建并保存到状态:{{error}}',
|
|
652
666
|
FAILED_TO_ENABLE_ACCELERATION: '无法为存储桶 {{bucketName}} 开启传输加速',
|
|
653
667
|
CDN_ACCELERATE_CONFIG_CHANGED: '无法通过更新操作更改存储桶 {{bucketName}} 的 CDN/加速配置。请使用销毁重建操作来更改 CDN 或加速配置。',
|
|
668
|
+
// Bucket IAM Policy messages
|
|
669
|
+
BUCKET_POLICY_APPLYING: '正在为存储桶 {{bucketName}} 应用 IAM 策略',
|
|
670
|
+
BUCKET_POLICY_APPLIED: 'IAM 策略已应用于存储桶 {{bucketName}}',
|
|
671
|
+
BUCKET_POLICY_DELETED: 'IAM 策略已从存储桶 {{bucketName}} 移除',
|
|
672
|
+
OSS_BUCKET_POLICY_SET: 'OSS 存储桶 {{bucketName}} 策略已设置',
|
|
673
|
+
OSS_BUCKET_POLICY_DELETED: 'OSS 存储桶 {{bucketName}} 策略已删除',
|
|
674
|
+
COS_BUCKET_POLICY_SET: 'COS 存储桶 {{bucketName}} 策略已设置',
|
|
675
|
+
COS_BUCKET_POLICY_DELETED: 'COS 存储桶 {{bucketName}} 策略已删除',
|
|
676
|
+
TOS_BUCKET_POLICY_SET: 'TOS 存储桶 {{bucketName}} 策略已设置',
|
|
677
|
+
TOS_BUCKET_POLICY_DELETED: 'TOS 存储桶 {{bucketName}} 策略已删除',
|
|
654
678
|
};
|
|
@@ -106,6 +106,36 @@ const parseBucket = (buckets) => {
|
|
|
106
106
|
domainParsed = parseDomainConfig(structuredDomain, undefined);
|
|
107
107
|
}
|
|
108
108
|
const websiteDomain = parseWebsiteDomain(bucket.website?.domain);
|
|
109
|
+
// Parse IAM policy statements
|
|
110
|
+
let iam;
|
|
111
|
+
if (bucket.iam?.resource?.statements && Array.isArray(bucket.iam.resource.statements)) {
|
|
112
|
+
iam = {
|
|
113
|
+
resource: {
|
|
114
|
+
statements: bucket.iam.resource.statements.map((stmt) => {
|
|
115
|
+
const actionRaw = stmt.action;
|
|
116
|
+
const actions = Array.isArray(actionRaw) ? actionRaw.map(String) : [String(actionRaw)];
|
|
117
|
+
const resourceRaw = stmt.resource;
|
|
118
|
+
const resources = Array.isArray(resourceRaw)
|
|
119
|
+
? resourceRaw.map(String)
|
|
120
|
+
: [String(resourceRaw)];
|
|
121
|
+
const principal = {};
|
|
122
|
+
for (const [key, val] of Object.entries(stmt.principal || {})) {
|
|
123
|
+
principal[key] = val;
|
|
124
|
+
}
|
|
125
|
+
const parsedStmt = {
|
|
126
|
+
effect: stmt.effect,
|
|
127
|
+
principal: principal,
|
|
128
|
+
action: actions,
|
|
129
|
+
resource: resources,
|
|
130
|
+
};
|
|
131
|
+
if (stmt.condition != null) {
|
|
132
|
+
parsedStmt.condition = stmt.condition;
|
|
133
|
+
}
|
|
134
|
+
return parsedStmt;
|
|
135
|
+
}),
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
109
139
|
return {
|
|
110
140
|
key,
|
|
111
141
|
name: String(bucket.name),
|
|
@@ -135,6 +165,7 @@ const parseBucket = (buckets) => {
|
|
|
135
165
|
: undefined,
|
|
136
166
|
// Parsed top-level domain config
|
|
137
167
|
domain: domainParsed,
|
|
168
|
+
iam,
|
|
138
169
|
website: bucket.website
|
|
139
170
|
? {
|
|
140
171
|
code: String(bucket.website.code),
|
|
@@ -27,6 +27,40 @@ const parseFunction = (functions) => {
|
|
|
27
27
|
memory: (0, parseUtils_1.parseNumber)(func.memory),
|
|
28
28
|
gpu: func.gpu,
|
|
29
29
|
timeout: (0, parseUtils_1.parseNumber)(func.timeout),
|
|
30
|
+
iam: func.iam
|
|
31
|
+
? {
|
|
32
|
+
role: func.iam.role !== undefined
|
|
33
|
+
? typeof func.iam.role === 'string'
|
|
34
|
+
? func.iam.role
|
|
35
|
+
: {
|
|
36
|
+
...(func.iam.role.name !== undefined
|
|
37
|
+
? { name: String(func.iam.role.name) }
|
|
38
|
+
: {}),
|
|
39
|
+
...(func.iam.role.managed_policies !== undefined
|
|
40
|
+
? { managed_policies: func.iam.role.managed_policies.map(String) }
|
|
41
|
+
: {}),
|
|
42
|
+
...(func.iam.role.statements !== undefined
|
|
43
|
+
? {
|
|
44
|
+
statements: func.iam.role.statements.map((s) => {
|
|
45
|
+
const rawAction = s.action;
|
|
46
|
+
const rawResource = s.resource;
|
|
47
|
+
return {
|
|
48
|
+
sid: s.sid,
|
|
49
|
+
effect: s.effect,
|
|
50
|
+
action: Array.isArray(rawAction)
|
|
51
|
+
? rawAction.map(String)
|
|
52
|
+
: [String(rawAction)],
|
|
53
|
+
resource: Array.isArray(rawResource)
|
|
54
|
+
? rawResource.map(String)
|
|
55
|
+
: [String(rawResource)],
|
|
56
|
+
};
|
|
57
|
+
}),
|
|
58
|
+
}
|
|
59
|
+
: {}),
|
|
60
|
+
}
|
|
61
|
+
: undefined,
|
|
62
|
+
}
|
|
63
|
+
: undefined,
|
|
30
64
|
environment: func.environment,
|
|
31
65
|
log: (0, parseUtils_1.parseBoolean)(func.log),
|
|
32
66
|
network: func.network,
|