@geek-fun/serverlessinsight 0.8.6 → 0.8.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/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +1 -1
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +2 -2
- package/.serverlessinsight/state-insight-poc-app-insight-poc-tencent.json.backup +94 -0
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +47 -27
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +1 -1
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +35 -73
- package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +148 -0
- package/AGENTS.md +29 -0
- package/dist/package.json +1 -1
- package/dist/src/commands/deploy.js +1 -0
- package/dist/src/commands/index.js +6 -2
- package/dist/src/commands/plan.js +1 -0
- package/dist/src/common/aliyunClient/ecsOperations.js +70 -1
- package/dist/src/common/aliyunClient/nasOperations.js +21 -0
- package/dist/src/common/aliyunClient/ramOperations.js +116 -15
- package/dist/src/common/aliyunClient/slsOperations.js +16 -3
- package/dist/src/common/concurrency.js +30 -0
- package/dist/src/common/context.js +3 -0
- package/dist/src/common/dependencyGraph/graph.js +5 -0
- package/dist/src/common/iacHelper.js +3 -1
- package/dist/src/common/iamStatements.js +21 -1
- package/dist/src/common/index.js +5 -0
- package/dist/src/common/nameBuilder.js +12 -1
- package/dist/src/common/planCompare.js +62 -0
- package/dist/src/common/planFormatter.js +15 -3
- package/dist/src/common/refreshCache.js +32 -0
- package/dist/src/common/refreshPlanner.js +105 -0
- package/dist/src/common/tencentClient/camOperations.js +24 -12
- package/dist/src/common/tencentClient/clsOperations.js +27 -3
- package/dist/src/common/tencentClient/tdsqlcOperations.js +22 -0
- package/dist/src/common/throttleRetry.js +56 -0
- package/dist/src/common/volcengineClient/iamOperations.js +15 -11
- package/dist/src/common/volcengineClient/tlsOperations.js +12 -4
- package/dist/src/lang/en.js +23 -0
- package/dist/src/lang/zh-CN.js +22 -0
- package/dist/src/stack/aliyunStack/apigwExecutor.js +5 -5
- package/dist/src/stack/aliyunStack/apigwPlanner.js +75 -7
- package/dist/src/stack/aliyunStack/apigwResource.js +10 -8
- package/dist/src/stack/aliyunStack/apigwTypes.js +86 -5
- package/dist/src/stack/aliyunStack/databasePlanner.js +26 -62
- package/dist/src/stack/aliyunStack/deployer.js +33 -3
- package/dist/src/stack/aliyunStack/esServerlessTypes.js +50 -1
- package/dist/src/stack/aliyunStack/fc3Executor.js +5 -3
- package/dist/src/stack/aliyunStack/fc3Planner.js +299 -12
- package/dist/src/stack/aliyunStack/fc3Resource.js +358 -34
- package/dist/src/stack/aliyunStack/fc3Types.js +61 -1
- package/dist/src/stack/aliyunStack/ossPlanner.js +21 -63
- package/dist/src/stack/aliyunStack/ossTypes.js +25 -1
- package/dist/src/stack/aliyunStack/rdsTypes.js +38 -1
- package/dist/src/stack/aliyunStack/sharedLogProject.js +22 -5
- package/dist/src/stack/aliyunStack/tablestorePlanner.js +20 -74
- package/dist/src/stack/aliyunStack/tablestoreTypes.js +33 -1
- package/dist/src/stack/scfStack/cosPlanner.js +30 -50
- package/dist/src/stack/scfStack/cosTypes.js +29 -1
- package/dist/src/stack/scfStack/esServerlessPlanner.js +21 -54
- package/dist/src/stack/scfStack/esServerlessTypes.js +13 -1
- package/dist/src/stack/scfStack/scfExecutor.js +5 -3
- package/dist/src/stack/scfStack/scfPlanner.js +72 -51
- package/dist/src/stack/scfStack/scfResource.js +109 -12
- package/dist/src/stack/scfStack/scfTypes.js +35 -1
- package/dist/src/stack/scfStack/sharedLogset.js +12 -3
- package/dist/src/stack/scfStack/tdsqlcPlanner.js +37 -55
- package/dist/src/stack/scfStack/tdsqlcTypes.js +21 -1
- package/dist/src/stack/volcengineStack/apigwPlanner.js +59 -8
- package/dist/src/stack/volcengineStack/apigwResource.js +52 -30
- package/dist/src/stack/volcengineStack/apigwTypes.js +44 -8
- package/dist/src/stack/volcengineStack/sharedLogProject.js +9 -3
- package/dist/src/stack/volcengineStack/tosPlanner.js +28 -55
- package/dist/src/stack/volcengineStack/tosTypes.js +18 -1
- package/dist/src/stack/volcengineStack/vefaasExecutor.js +5 -3
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +119 -10
- package/dist/src/stack/volcengineStack/vefaasResource.js +112 -13
- package/dist/src/stack/volcengineStack/vefaasTypes.js +61 -7
- package/dist/src/validator/semanticValidation.js +41 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.createEcsOperations = exports.parseSecurityGroupRule = exports.securityGroupRangeMap = void 0;
|
|
36
|
+
exports.createEcsOperations = exports.parseSecurityGroupRule = exports.canonicalSecurityGroupRule = exports.securityGroupRangeMap = void 0;
|
|
37
37
|
const ecs = __importStar(require("@alicloud/ecs20140526"));
|
|
38
38
|
const logger_1 = require("../logger");
|
|
39
39
|
exports.securityGroupRangeMap = {
|
|
@@ -50,6 +50,14 @@ const transformPortRange = (protocol, portRange) => {
|
|
|
50
50
|
return portRange.includes('/') ? portRange : `${portRange}/${portRange}`;
|
|
51
51
|
};
|
|
52
52
|
const normalizeProtocol = (protocol) => protocol.trim().toUpperCase();
|
|
53
|
+
/**
|
|
54
|
+
* Canonical rule key for config-vs-live comparison (issue #234 M2): protocol
|
|
55
|
+
* normalized, ports in Aliyun wire format, CIDR verbatim — the exact tuple an
|
|
56
|
+
* AuthorizeSecurityGroup call writes and DescribeSecurityGroupAttribute
|
|
57
|
+
* returns.
|
|
58
|
+
*/
|
|
59
|
+
/* istanbul ignore next */ const canonicalSecurityGroupRule = (protocol, portRange, cidr) => `${protocol.toUpperCase()}|${transformPortRange(protocol, portRange)}|${cidr}`;
|
|
60
|
+
exports.canonicalSecurityGroupRule = canonicalSecurityGroupRule;
|
|
53
61
|
/* istanbul ignore next */ const parseSecurityGroupRule = (rule) => {
|
|
54
62
|
const [rawProtocol, second, third, ...rest] = rule.split(':');
|
|
55
63
|
if (rest.length > 0 || !rawProtocol || !second || !third) {
|
|
@@ -159,6 +167,67 @@ const isDuplicateSecurityGroupRuleError = (error) => {
|
|
|
159
167
|
}
|
|
160
168
|
return sg;
|
|
161
169
|
},
|
|
170
|
+
authorizeSecurityGroupRules: async (securityGroupId, direction, rules) => {
|
|
171
|
+
for (const parsed of rules) {
|
|
172
|
+
try {
|
|
173
|
+
if (direction === 'ingress') {
|
|
174
|
+
const request = new ecs.AuthorizeSecurityGroupRequest({
|
|
175
|
+
regionId: context.region,
|
|
176
|
+
securityGroupId,
|
|
177
|
+
ipProtocol: parsed.protocol.toLowerCase(),
|
|
178
|
+
sourceCidrIp: parsed.cidr,
|
|
179
|
+
portRange: transformPortRange(parsed.protocol, parsed.portRange),
|
|
180
|
+
});
|
|
181
|
+
await ecsClient.authorizeSecurityGroup(request);
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
const request = new ecs.AuthorizeSecurityGroupEgressRequest({
|
|
185
|
+
regionId: context.region,
|
|
186
|
+
securityGroupId,
|
|
187
|
+
ipProtocol: parsed.protocol.toLowerCase(),
|
|
188
|
+
destCidrIp: parsed.cidr,
|
|
189
|
+
portRange: transformPortRange(parsed.protocol, parsed.portRange),
|
|
190
|
+
});
|
|
191
|
+
await ecsClient.authorizeSecurityGroupEgress(request);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
if (isDuplicateSecurityGroupRuleError(error)) {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
logger_1.logger.warn(`Failed to authorize ${direction} rule for ${securityGroupId}: ${String(error)}`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
revokeSecurityGroupRules: async (securityGroupId, direction, rules) => {
|
|
203
|
+
for (const parsed of rules) {
|
|
204
|
+
try {
|
|
205
|
+
if (direction === 'ingress') {
|
|
206
|
+
const request = new ecs.RevokeSecurityGroupRequest({
|
|
207
|
+
regionId: context.region,
|
|
208
|
+
securityGroupId,
|
|
209
|
+
ipProtocol: parsed.protocol.toLowerCase(),
|
|
210
|
+
sourceCidrIp: parsed.cidr,
|
|
211
|
+
portRange: transformPortRange(parsed.protocol, parsed.portRange),
|
|
212
|
+
});
|
|
213
|
+
await ecsClient.revokeSecurityGroup(request);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
const request = new ecs.RevokeSecurityGroupEgressRequest({
|
|
217
|
+
regionId: context.region,
|
|
218
|
+
securityGroupId,
|
|
219
|
+
ipProtocol: parsed.protocol.toLowerCase(),
|
|
220
|
+
destCidrIp: parsed.cidr,
|
|
221
|
+
portRange: transformPortRange(parsed.protocol, parsed.portRange),
|
|
222
|
+
});
|
|
223
|
+
await ecsClient.revokeSecurityGroupEgress(request);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
logger_1.logger.warn(`Failed to revoke ${direction} rule for ${securityGroupId}: ${String(error)}`);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
},
|
|
162
231
|
getSecurityGroupRules: async (securityGroupId) => {
|
|
163
232
|
const ingressRules = [];
|
|
164
233
|
const egressRules = [];
|
|
@@ -34,6 +34,7 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.createNasOperations = void 0;
|
|
37
|
+
const logger_1 = require("../logger");
|
|
37
38
|
const nas = __importStar(require("@alicloud/nas20170626"));
|
|
38
39
|
const types_1 = require("../../types");
|
|
39
40
|
const storageClassMap = {
|
|
@@ -204,6 +205,26 @@ const createNasOperations = (nasClient) => {
|
|
|
204
205
|
accessGroupName,
|
|
205
206
|
};
|
|
206
207
|
},
|
|
208
|
+
listMountTargets: async (fileSystemId) => {
|
|
209
|
+
try {
|
|
210
|
+
const request = new nas.DescribeMountTargetsRequest({
|
|
211
|
+
fileSystemId,
|
|
212
|
+
});
|
|
213
|
+
const response = await nasClient.describeMountTargets(request);
|
|
214
|
+
const raw = response?.body?.mountTargets?.mountTarget ?? [];
|
|
215
|
+
return raw
|
|
216
|
+
.filter((mt) => mt.mountTargetDomain)
|
|
217
|
+
.map((mt) => ({
|
|
218
|
+
fileSystemId,
|
|
219
|
+
mountTargetDomain: mt.mountTargetDomain,
|
|
220
|
+
status: mt.status,
|
|
221
|
+
}));
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
logger_1.logger.debug(`Failed to list mount targets: ${String(error)}`);
|
|
225
|
+
return [];
|
|
226
|
+
}
|
|
227
|
+
},
|
|
207
228
|
getMountTarget: async (fileSystemId, mountTargetDomain) => {
|
|
208
229
|
try {
|
|
209
230
|
const request = new nas.DescribeMountTargetsRequest({
|
|
@@ -33,11 +33,12 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.createRamOperations = void 0;
|
|
36
|
+
exports.createRamOperations = exports.buildFc3ExecutionPolicyDocument = void 0;
|
|
37
37
|
const ram = __importStar(require("@alicloud/ram20150501"));
|
|
38
38
|
const lang_1 = require("../../lang");
|
|
39
39
|
const logger_1 = require("../logger");
|
|
40
40
|
const iamStatements_1 = require("../iamStatements");
|
|
41
|
+
const nameBuilder_1 = require("../nameBuilder");
|
|
41
42
|
const buildAssumeRolePolicy = (trustedServices) => JSON.stringify({
|
|
42
43
|
Version: '1',
|
|
43
44
|
Statement: [
|
|
@@ -109,18 +110,24 @@ const mapToAliyunStatement = (stmt) => {
|
|
|
109
110
|
}
|
|
110
111
|
return result;
|
|
111
112
|
};
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
/** @public Exec policy document from a derived baseline; falls back to the static FC_EXECUTION_STATEMENTS when omitted. */
|
|
114
|
+
const buildFc3ExecutionPolicyDocument = (executionStatements, customStatements) => {
|
|
115
|
+
const nativeBaseline = executionStatements
|
|
116
|
+
? executionStatements.map(mapToAliyunStatement)
|
|
117
|
+
: FC_EXECUTION_STATEMENTS;
|
|
118
|
+
const merged = (0, iamStatements_1.mergePolicyStatements)(nativeBaseline, customStatements, mapToAliyunStatement);
|
|
114
119
|
return (0, iamStatements_1.buildPolicyDocument)(merged, { version: '1' });
|
|
115
120
|
};
|
|
121
|
+
exports.buildFc3ExecutionPolicyDocument = buildFc3ExecutionPolicyDocument;
|
|
122
|
+
const buildExecutionPolicy = (executionStatements, customStatements) => (0, exports.buildFc3ExecutionPolicyDocument)(executionStatements, customStatements);
|
|
116
123
|
/* istanbul ignore next */ const createRamOperations = (ramClient) => {
|
|
117
|
-
const attachRolePolicyForFc = async (roleName, customStatements) => {
|
|
118
|
-
const policyName =
|
|
124
|
+
const attachRolePolicyForFc = async (roleName, customStatements, executionStatements) => {
|
|
125
|
+
const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
|
|
119
126
|
// Create policy
|
|
120
127
|
try {
|
|
121
128
|
const createPolicyRequest = new ram.CreatePolicyRequest({
|
|
122
129
|
policyName,
|
|
123
|
-
policyDocument: buildExecutionPolicy(customStatements),
|
|
130
|
+
policyDocument: buildExecutionPolicy(executionStatements, customStatements),
|
|
124
131
|
description: `FC execution policy for ${roleName}`,
|
|
125
132
|
});
|
|
126
133
|
await ramClient.createPolicy(createPolicyRequest);
|
|
@@ -215,8 +222,95 @@ const buildExecutionPolicy = (customStatements) => {
|
|
|
215
222
|
return [];
|
|
216
223
|
}
|
|
217
224
|
};
|
|
225
|
+
const readExecutionPolicyDocument = async (policyName) => {
|
|
226
|
+
try {
|
|
227
|
+
const getPolicyResponse = await ramClient.getPolicy(new ram.GetPolicyRequest({ policyName, policyType: 'Custom' }));
|
|
228
|
+
const defaultVersionId = getPolicyResponse.body?.policy?.defaultVersion;
|
|
229
|
+
if (!defaultVersionId) {
|
|
230
|
+
return { found: true };
|
|
231
|
+
}
|
|
232
|
+
const versionResponse = await ramClient.getPolicyVersion(new ram.GetPolicyVersionRequest({
|
|
233
|
+
policyName,
|
|
234
|
+
policyType: 'Custom',
|
|
235
|
+
versionId: defaultVersionId,
|
|
236
|
+
}));
|
|
237
|
+
return { found: true, document: versionResponse.body?.policyVersion?.policyDocument };
|
|
238
|
+
}
|
|
239
|
+
catch (error) {
|
|
240
|
+
if (error &&
|
|
241
|
+
typeof error === 'object' &&
|
|
242
|
+
'code' in error &&
|
|
243
|
+
error.code === 'EntityNotExist.Policy') {
|
|
244
|
+
return { found: false };
|
|
245
|
+
}
|
|
246
|
+
throw error;
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
const updateExecutionPolicyDocumentFn = async (roleName, policyDocument) => {
|
|
250
|
+
const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
|
|
251
|
+
const ensureAttached = async () => {
|
|
252
|
+
try {
|
|
253
|
+
await ramClient.attachPolicyToRole(new ram.AttachPolicyToRoleRequest({ policyType: 'Custom', policyName, roleName }));
|
|
254
|
+
}
|
|
255
|
+
catch (error) {
|
|
256
|
+
if (!(error &&
|
|
257
|
+
typeof error === 'object' &&
|
|
258
|
+
'code' in error &&
|
|
259
|
+
error.code === 'EntityAlreadyExists.Role.Policy')) {
|
|
260
|
+
throw error;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
const readResult = await readExecutionPolicyDocument(policyName);
|
|
265
|
+
if (!readResult.found) {
|
|
266
|
+
try {
|
|
267
|
+
await ramClient.createPolicy(new ram.CreatePolicyRequest({
|
|
268
|
+
policyName,
|
|
269
|
+
policyDocument,
|
|
270
|
+
description: `FC execution policy for ${roleName}`,
|
|
271
|
+
}));
|
|
272
|
+
}
|
|
273
|
+
catch (error2) {
|
|
274
|
+
if (!(error2 &&
|
|
275
|
+
typeof error2 === 'object' &&
|
|
276
|
+
'code' in error2 &&
|
|
277
|
+
error2.code === 'EntityAlreadyExists.Policy')) {
|
|
278
|
+
throw error2;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
await ensureAttached();
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const currentDocument = readResult.document;
|
|
285
|
+
if (currentDocument === policyDocument) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
try {
|
|
289
|
+
const listResponse = await ramClient.listPolicyVersions(new ram.ListPolicyVersionsRequest({ policyName, policyType: 'Custom' }));
|
|
290
|
+
const versions = listResponse.body?.policyVersions?.policyVersion ?? [];
|
|
291
|
+
const keepBeforeCreate = 4;
|
|
292
|
+
const toDelete = versions
|
|
293
|
+
.filter((v) => !v.isDefaultVersion)
|
|
294
|
+
.sort((a, b) => (a.createDate ?? '').localeCompare(b.createDate ?? ''))
|
|
295
|
+
.slice(0, Math.max(0, versions.length - keepBeforeCreate));
|
|
296
|
+
for (const version of toDelete) {
|
|
297
|
+
if (version.versionId) {
|
|
298
|
+
await ramClient.deletePolicyVersion(new ram.DeletePolicyVersionRequest({ policyName, versionId: version.versionId }));
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
catch (error) {
|
|
303
|
+
logger_1.logger.warn(lang_1.lang.__('RAM_POLICY_VERSION_PRUNE_FAILED', { policyName, error: String(error) }));
|
|
304
|
+
}
|
|
305
|
+
await ramClient.createPolicyVersion(new ram.CreatePolicyVersionRequest({
|
|
306
|
+
policyName,
|
|
307
|
+
policyDocument,
|
|
308
|
+
setAsDefault: true,
|
|
309
|
+
}));
|
|
310
|
+
await ensureAttached();
|
|
311
|
+
};
|
|
218
312
|
return {
|
|
219
|
-
createRole: async (roleName, trustedServices, description, customStatements, managedPolicies) => {
|
|
313
|
+
createRole: async (roleName, trustedServices, description, customStatements, managedPolicies, executionStatements) => {
|
|
220
314
|
const assumeRolePolicy = buildAssumeRolePolicy(trustedServices);
|
|
221
315
|
try {
|
|
222
316
|
const request = new ram.CreateRoleRequest({
|
|
@@ -235,7 +329,7 @@ const buildExecutionPolicy = (customStatements) => {
|
|
|
235
329
|
maxSessionDuration: response.body?.role?.maxSessionDuration,
|
|
236
330
|
assumeRolePolicyDocument: assumeRolePolicy,
|
|
237
331
|
};
|
|
238
|
-
const policyName = await attachRolePolicyForFc(roleName, customStatements);
|
|
332
|
+
const policyName = await attachRolePolicyForFc(roleName, customStatements, executionStatements);
|
|
239
333
|
if (managedPolicies && managedPolicies.length > 0) {
|
|
240
334
|
await attachManagedPoliciesFn(roleName, managedPolicies);
|
|
241
335
|
}
|
|
@@ -255,7 +349,8 @@ const buildExecutionPolicy = (customStatements) => {
|
|
|
255
349
|
newAssumeRolePolicyDocument: assumeRolePolicy,
|
|
256
350
|
});
|
|
257
351
|
await ramClient.updateRole(updateRequest);
|
|
258
|
-
const policyName =
|
|
352
|
+
const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
|
|
353
|
+
await updateExecutionPolicyDocumentFn(roleName, (0, exports.buildFc3ExecutionPolicyDocument)(executionStatements, customStatements));
|
|
259
354
|
if (managedPolicies && managedPolicies.length > 0) {
|
|
260
355
|
await attachManagedPoliciesFn(roleName, managedPolicies);
|
|
261
356
|
}
|
|
@@ -297,7 +392,7 @@ const buildExecutionPolicy = (customStatements) => {
|
|
|
297
392
|
updateDate: getResponse.body?.role?.updateDate,
|
|
298
393
|
maxSessionDuration: getResponse.body?.role?.maxSessionDuration,
|
|
299
394
|
assumeRolePolicyDocument: assumeRolePolicy,
|
|
300
|
-
policyName:
|
|
395
|
+
policyName: (0, nameBuilder_1.buildRolePolicyName)(roleName),
|
|
301
396
|
};
|
|
302
397
|
const updateRequest = new ram.UpdateRoleRequest({
|
|
303
398
|
roleName,
|
|
@@ -317,8 +412,8 @@ const buildExecutionPolicy = (customStatements) => {
|
|
|
317
412
|
throw error;
|
|
318
413
|
}
|
|
319
414
|
},
|
|
320
|
-
updateRolePolicy: async (roleName, customStatements) => {
|
|
321
|
-
const policyName =
|
|
415
|
+
updateRolePolicy: async (roleName, customStatements, executionStatements) => {
|
|
416
|
+
const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
|
|
322
417
|
try {
|
|
323
418
|
await ramClient.detachPolicyFromRole(new ram.DetachPolicyFromRoleRequest({ policyType: 'Custom', policyName, roleName }));
|
|
324
419
|
}
|
|
@@ -334,7 +429,7 @@ const buildExecutionPolicy = (customStatements) => {
|
|
|
334
429
|
try {
|
|
335
430
|
await ramClient.createPolicy(new ram.CreatePolicyRequest({
|
|
336
431
|
policyName,
|
|
337
|
-
policyDocument: buildExecutionPolicy(customStatements),
|
|
432
|
+
policyDocument: buildExecutionPolicy(executionStatements, customStatements),
|
|
338
433
|
description: `FC execution policy for ${roleName}`,
|
|
339
434
|
}));
|
|
340
435
|
}
|
|
@@ -362,6 +457,12 @@ const buildExecutionPolicy = (customStatements) => {
|
|
|
362
457
|
throw error;
|
|
363
458
|
}
|
|
364
459
|
},
|
|
460
|
+
updateExecutionPolicyDocument: updateExecutionPolicyDocumentFn,
|
|
461
|
+
getExecutionPolicyDocument: async (roleName) => {
|
|
462
|
+
const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
|
|
463
|
+
const readResult = await readExecutionPolicyDocument(policyName);
|
|
464
|
+
return readResult.found ? readResult.document : undefined;
|
|
465
|
+
},
|
|
365
466
|
getRole: async (roleName) => {
|
|
366
467
|
try {
|
|
367
468
|
const request = new ram.GetRoleRequest({
|
|
@@ -380,7 +481,7 @@ const buildExecutionPolicy = (customStatements) => {
|
|
|
380
481
|
updateDate: response.body.role.updateDate,
|
|
381
482
|
maxSessionDuration: response.body.role.maxSessionDuration,
|
|
382
483
|
assumeRolePolicyDocument: response.body.role.assumeRolePolicyDocument,
|
|
383
|
-
policyName:
|
|
484
|
+
policyName: (0, nameBuilder_1.buildRolePolicyName)(roleName),
|
|
384
485
|
};
|
|
385
486
|
}
|
|
386
487
|
catch (error) {
|
|
@@ -394,7 +495,7 @@ const buildExecutionPolicy = (customStatements) => {
|
|
|
394
495
|
}
|
|
395
496
|
},
|
|
396
497
|
deleteRole: async (roleName, managedPolicies) => {
|
|
397
|
-
const policyName =
|
|
498
|
+
const policyName = (0, nameBuilder_1.buildRolePolicyName)(roleName);
|
|
398
499
|
if (managedPolicies && managedPolicies.length > 0) {
|
|
399
500
|
await detachManagedPoliciesFn(roleName, managedPolicies);
|
|
400
501
|
}
|
|
@@ -33,10 +33,15 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.createSlsOperations = void 0;
|
|
36
|
+
exports.createSlsOperations = exports.SLS_LOGSTORE_SHARDS = exports.SLS_LOGSTORE_TTL = void 0;
|
|
37
37
|
const sls = __importStar(require("@alicloud/sls20201230"));
|
|
38
38
|
const logger_1 = require("../logger");
|
|
39
39
|
const polling_1 = require("../polling");
|
|
40
|
+
// The logstore attributes si creates with (issue #234 M1): `fn.log` is a
|
|
41
|
+
// boolean — these are stack constants, so live values differing from them are
|
|
42
|
+
// out-of-band drift.
|
|
43
|
+
exports.SLS_LOGSTORE_TTL = 30;
|
|
44
|
+
exports.SLS_LOGSTORE_SHARDS = 2;
|
|
40
45
|
const waitForSlsProject = async (getProject, projectName) => {
|
|
41
46
|
try {
|
|
42
47
|
const project = await (0, polling_1.pollUntil)({
|
|
@@ -149,11 +154,11 @@ const createSlsOperations = (slsClient) => {
|
|
|
149
154
|
value: tagResource.tagValue ?? '',
|
|
150
155
|
}));
|
|
151
156
|
},
|
|
152
|
-
createLogstore: async (projectName, logstoreName, ttl =
|
|
157
|
+
createLogstore: async (projectName, logstoreName, ttl = exports.SLS_LOGSTORE_TTL) => {
|
|
153
158
|
const request = new sls.CreateLogStoreRequest({
|
|
154
159
|
logstoreName,
|
|
155
160
|
ttl,
|
|
156
|
-
shardCount:
|
|
161
|
+
shardCount: exports.SLS_LOGSTORE_SHARDS,
|
|
157
162
|
});
|
|
158
163
|
await slsClient.createLogStore(projectName, request);
|
|
159
164
|
// Wait for logstore to be ready
|
|
@@ -184,6 +189,14 @@ const createSlsOperations = (slsClient) => {
|
|
|
184
189
|
throw error;
|
|
185
190
|
}
|
|
186
191
|
},
|
|
192
|
+
updateLogstore: async (projectName, logstoreName, ttl, shardCount) => {
|
|
193
|
+
const request = new sls.UpdateLogStoreRequest({
|
|
194
|
+
logstoreName,
|
|
195
|
+
ttl,
|
|
196
|
+
shardCount,
|
|
197
|
+
});
|
|
198
|
+
await slsClient.updateLogStore(projectName, logstoreName, request);
|
|
199
|
+
},
|
|
187
200
|
deleteLogstore: async (projectName, logstoreName) => {
|
|
188
201
|
await slsClient.deleteLogStore(projectName, logstoreName);
|
|
189
202
|
},
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mapWithConcurrency = exports.PLAN_READ_CONCURRENCY = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Bounded-concurrency map for planner read fan-outs (issue #234 rate-limit
|
|
6
|
+
* mitigation): each planner probes resources concurrently, and a naive
|
|
7
|
+
* Promise.all burst can exceed provider management-API QPS (e.g. Tencent CAM
|
|
8
|
+
* GetRole at 20/s). The limit is deliberately provider-neutral and coarse —
|
|
9
|
+
* ~10 in-flight reads per planner group — since provider quota tables are
|
|
10
|
+
* partially unpublished (Volcengine, Aliyun OSS management plane).
|
|
11
|
+
*/
|
|
12
|
+
exports.PLAN_READ_CONCURRENCY = 10;
|
|
13
|
+
const mapWithConcurrency = async (items, limit, fn) => {
|
|
14
|
+
const results = new Array(items.length);
|
|
15
|
+
let nextIndex = 0;
|
|
16
|
+
const workerCount = Math.min(limit, items.length);
|
|
17
|
+
const workers = Array.from({ length: workerCount }, async () => {
|
|
18
|
+
while (true) {
|
|
19
|
+
const index = nextIndex;
|
|
20
|
+
nextIndex += 1;
|
|
21
|
+
if (index >= items.length) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
results[index] = await fn(items[index], index);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
await Promise.all(workers);
|
|
28
|
+
return results;
|
|
29
|
+
};
|
|
30
|
+
exports.mapWithConcurrency = mapWithConcurrency;
|
|
@@ -9,6 +9,7 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
9
9
|
const credentials_1 = require("./credentials");
|
|
10
10
|
const imsClient_1 = require("./imsClient");
|
|
11
11
|
const providerEnum_1 = require("./providerEnum");
|
|
12
|
+
const refreshCache_1 = require("./refreshCache");
|
|
12
13
|
let context;
|
|
13
14
|
const DEFAULT_IAC_FILES = [
|
|
14
15
|
'serverlessinsight.yml',
|
|
@@ -84,6 +85,8 @@ const setContext = async (config, reaValToken = false) => {
|
|
|
84
85
|
...acc,
|
|
85
86
|
[stage]: Object.entries(parameters).map(([key, value]) => ({ key, value })),
|
|
86
87
|
}), {}),
|
|
88
|
+
refreshCache: (0, refreshCache_1.createRefreshCache)(),
|
|
89
|
+
refresh: config.refresh ?? true,
|
|
87
90
|
};
|
|
88
91
|
if (reaValToken) {
|
|
89
92
|
const iamInfo = await (0, imsClient_1.getIamInfo)(newContext);
|
|
@@ -16,6 +16,11 @@ const RESOURCE_TYPE_PREFIX_MAP = {
|
|
|
16
16
|
SCF: 'functions',
|
|
17
17
|
COS_BUCKET: 'buckets',
|
|
18
18
|
TDSQL_C_SERVERLESS: 'databases',
|
|
19
|
+
TENCENT_ES_SERVERLESS: 'databases',
|
|
20
|
+
// Volcengine resource types (as emitted by planners)
|
|
21
|
+
VOLCENGINE_VEFAAS: 'functions',
|
|
22
|
+
VOLCENGINE_TOS_BUCKET: 'buckets',
|
|
23
|
+
VOLCENGINE_APIGW: 'events',
|
|
19
24
|
};
|
|
20
25
|
const RESOURCE_DEPENDENCY_ORDER = {
|
|
21
26
|
databases: 0,
|
|
@@ -98,7 +98,9 @@ const getIacDefinition = (iac, rawValue) => {
|
|
|
98
98
|
if (matchFn?.length) {
|
|
99
99
|
return iac.functions?.find((fc) => fc.key === matchFn[1]);
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
// Bare values are the function's deployed NAME, never its key — resolving by
|
|
102
|
+
// key here would reintroduce the issue #227 trust-policy incident.
|
|
103
|
+
return iac.functions?.find((fc) => fc.name === rawValue);
|
|
102
104
|
};
|
|
103
105
|
exports.getIacDefinition = getIacDefinition;
|
|
104
106
|
/* istanbul ignore next */
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// These functions operate on raw statement arrays and never import
|
|
4
4
|
// provider-specific modules — consumers supply their own map functions.
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.buildPolicyDocument = exports.parseBuiltInStatements = exports.mergePolicyStatements = void 0;
|
|
6
|
+
exports.buildPolicyDocument = exports.parseBuiltInStatements = exports.unionPolicyStatements = exports.mergePolicyStatements = void 0;
|
|
7
7
|
/**
|
|
8
8
|
* Merge built-in native statements with optional custom user statements.
|
|
9
9
|
* Returns a NEW array — the input arrays are never mutated.
|
|
@@ -21,6 +21,26 @@ const mergePolicyStatements = (nativeBuiltIn, custom, mapFn) => {
|
|
|
21
21
|
return [...nativeBuiltIn, ...mappedCustom];
|
|
22
22
|
};
|
|
23
23
|
exports.mergePolicyStatements = mergePolicyStatements;
|
|
24
|
+
/**
|
|
25
|
+
* Union statement lists (e.g. the derived baselines of several functions
|
|
26
|
+
* sharing one legacy role), deduplicating identical statements. Returns a NEW
|
|
27
|
+
* array — the inputs are never mutated.
|
|
28
|
+
*/
|
|
29
|
+
const unionPolicyStatements = (statementLists) => {
|
|
30
|
+
const seen = new Set();
|
|
31
|
+
const merged = [];
|
|
32
|
+
for (const list of statementLists) {
|
|
33
|
+
for (const statement of list) {
|
|
34
|
+
const fingerprint = JSON.stringify(statement);
|
|
35
|
+
if (seen.has(fingerprint))
|
|
36
|
+
continue;
|
|
37
|
+
seen.add(fingerprint);
|
|
38
|
+
merged.push(statement);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return merged;
|
|
42
|
+
};
|
|
43
|
+
exports.unionPolicyStatements = unionPolicyStatements;
|
|
24
44
|
/**
|
|
25
45
|
* Parse a provider's built-in policy JSON string into its raw Statement array.
|
|
26
46
|
* Returns an empty array when the JSON is invalid or has no Statement field.
|
package/dist/src/common/index.js
CHANGED
|
@@ -38,3 +38,8 @@ __exportStar(require("./apiClient"), exports);
|
|
|
38
38
|
__exportStar(require("./triggerMapper"), exports);
|
|
39
39
|
__exportStar(require("./nameBuilder"), exports);
|
|
40
40
|
__exportStar(require("./providerNames"), exports);
|
|
41
|
+
__exportStar(require("./refreshCache"), exports);
|
|
42
|
+
__exportStar(require("./concurrency"), exports);
|
|
43
|
+
__exportStar(require("./throttleRetry"), exports);
|
|
44
|
+
__exportStar(require("./planCompare"), exports);
|
|
45
|
+
__exportStar(require("./refreshPlanner"), exports);
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
* deploy set are additionally rejected up-front by semantic validation.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.CONSTRAINT_NAME_LIMITS = exports.buildConstrainedName = exports.stableHash = exports.DEFAULT_HASH_LENGTH = void 0;
|
|
19
|
+
exports.buildRolePolicyName = exports.buildFunctionRoleName = exports.CONSTRAINT_NAME_LIMITS = exports.buildConstrainedName = exports.stableHash = exports.DEFAULT_HASH_LENGTH = void 0;
|
|
20
20
|
const FNV_OFFSET_BASIS = 0x811c9dc5;
|
|
21
21
|
const FNV_PRIME = 0x01000193;
|
|
22
22
|
const SANITISERS = {
|
|
@@ -77,4 +77,15 @@ exports.CONSTRAINT_NAME_LIMITS = {
|
|
|
77
77
|
ALIYUN_CREATE_API_NAME: 50,
|
|
78
78
|
ALIYUN_API_GROUP_NAME: 50,
|
|
79
79
|
VOLCENGINE_ROUTE_NAME: 63,
|
|
80
|
+
FUNCTION_ROLE_NAME: 64,
|
|
80
81
|
};
|
|
82
|
+
/** Single source of truth for per-function execution role names across all providers. */
|
|
83
|
+
const buildFunctionRoleName = (serviceName, stage, fnKey) => (0, exports.buildConstrainedName)({
|
|
84
|
+
parts: [serviceName, stage, fnKey, 'role'],
|
|
85
|
+
maxLength: exports.CONSTRAINT_NAME_LIMITS.FUNCTION_ROLE_NAME,
|
|
86
|
+
charset: 'hyphen',
|
|
87
|
+
});
|
|
88
|
+
exports.buildFunctionRoleName = buildFunctionRoleName;
|
|
89
|
+
/** Single source of truth for the execution policy name attached to a role. */
|
|
90
|
+
const buildRolePolicyName = (roleName) => `${roleName}-policy`;
|
|
91
|
+
exports.buildRolePolicyName = buildRolePolicyName;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.jsonDocumentDiffers = exports.remoteDiffersFromDesired = void 0;
|
|
4
|
+
const hashUtils_1 = require("./hashUtils");
|
|
5
|
+
/**
|
|
6
|
+
* A desired value "declares" a dimension only when the executor would write it:
|
|
7
|
+
* `undefined`/`null` mean unset, and an empty plain object means the executor
|
|
8
|
+
* omits the field entirely (e.g. fc3 `environment: {}`, oss
|
|
9
|
+
* `websiteConfiguration: {}`) — so cloud-side values in that dimension can
|
|
10
|
+
* never be cleared and are not drift. Arrays and empty strings stay declared:
|
|
11
|
+
* the executor writes them explicitly.
|
|
12
|
+
*/
|
|
13
|
+
const isDeclared = (value) => {
|
|
14
|
+
if (value === undefined || value === null) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
if (typeof value === 'object' &&
|
|
18
|
+
!Array.isArray(value) &&
|
|
19
|
+
Object.keys(value).length === 0) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* One-directional live-drift check (issue #234 Phase 1 contract):
|
|
26
|
+
* compares only the attributes a cloud->definition mapper emits (remote) that
|
|
27
|
+
* the desired definition actually declares. A desired value with no matching
|
|
28
|
+
* cloud value IS drift (the executor sets it on update); a cloud-only extra
|
|
29
|
+
* the config never asked for is ignored (the executor may not clear it).
|
|
30
|
+
* Unreadable/config-only keys never appear in `remote` — so matching reality
|
|
31
|
+
* stays `noop` instead of phantom-drifting every plan.
|
|
32
|
+
*/
|
|
33
|
+
const remoteDiffersFromDesired = (remote, desired) => Object.entries(remote).some(([key]) => {
|
|
34
|
+
const desiredValue = desired[key];
|
|
35
|
+
if (!isDeclared(desiredValue)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
return !(0, hashUtils_1.attributesEqual)({ [key]: remote[key] }, { [key]: desiredValue });
|
|
39
|
+
});
|
|
40
|
+
exports.remoteDiffersFromDesired = remoteDiffersFromDesired;
|
|
41
|
+
/**
|
|
42
|
+
* Canonical JSON document compare (issue #234 phase 3): providers return
|
|
43
|
+
* policy documents as parsed objects (or re-serialized strings) whose key
|
|
44
|
+
* order and formatting differ from what the config serialized, so byte-level
|
|
45
|
+
* string comparison false-drifts. Parses both sides and compares
|
|
46
|
+
* key-order-insensitively. Undeclared (null) desired or unreadable cloud
|
|
47
|
+
* values are not drift — only a parseable pair with different content is.
|
|
48
|
+
*/
|
|
49
|
+
const jsonDocumentDiffers = (desired, cloud) => {
|
|
50
|
+
if (desired === null || cloud === undefined || cloud === null) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const desiredObj = JSON.parse(desired);
|
|
55
|
+
const cloudObj = typeof cloud === 'string' ? JSON.parse(cloud) : cloud;
|
|
56
|
+
return !(0, hashUtils_1.attributesEqual)({ doc: cloudObj }, { doc: desiredObj });
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
exports.jsonDocumentDiffers = jsonDocumentDiffers;
|
|
@@ -216,8 +216,13 @@ const formatPlanItem = (item, config = DEFAULT_CONFIG) => {
|
|
|
216
216
|
const symbol = ACTION_SYMBOL[item.action] ?? ' ';
|
|
217
217
|
const symbolColor = ACTION_COLOR[item.action] ?? 'RESET';
|
|
218
218
|
const resourceLine = colorize(` ${symbol} ${item.logicalId}:`, symbolColor, config.colorize);
|
|
219
|
+
// A drifted update is caused by an out-of-config cloud edit — surface that
|
|
220
|
+
// so it doesn't read like an ordinary config change.
|
|
221
|
+
const driftedLine = item.drifted && item.action !== 'delete'
|
|
222
|
+
? [colorize(` # ${lang_1.lang.__('PLAN_DRIFTED_MARKER')}`, 'CYAN', config.colorize)]
|
|
223
|
+
: [];
|
|
219
224
|
if (!item.changes) {
|
|
220
|
-
return [headerLine, resourceLine].join('\n');
|
|
225
|
+
return [headerLine, resourceLine, ...driftedLine].join('\n');
|
|
221
226
|
}
|
|
222
227
|
const { diffs, unchangedCount } = (0, exports.computeAttributeDiffs)(item.changes.before, item.changes.after);
|
|
223
228
|
const keyWidth = Math.max(config.keyAlignWidth, computeMaxKeyWidth(diffs, config.indentSize));
|
|
@@ -229,7 +234,7 @@ const formatPlanItem = (item, config = DEFAULT_CONFIG) => {
|
|
|
229
234
|
colorize(` # ${lang_1.lang.__('PLAN_UNCHANGED_ATTRS', { count: String(unchangedCount) })}`, 'DIM', config.colorize),
|
|
230
235
|
]
|
|
231
236
|
: [];
|
|
232
|
-
return [headerLine, resourceLine, ...attrLines, ...hiddenLine].join('\n');
|
|
237
|
+
return [headerLine, resourceLine, ...driftedLine, ...attrLines, ...hiddenLine].join('\n');
|
|
233
238
|
};
|
|
234
239
|
exports.formatPlanItem = formatPlanItem;
|
|
235
240
|
/* istanbul ignore next */
|
|
@@ -257,12 +262,19 @@ const formatPlan = (items, config = DEFAULT_CONFIG) => {
|
|
|
257
262
|
'',
|
|
258
263
|
];
|
|
259
264
|
const itemLines = actionItems.flatMap((item) => [(0, exports.formatPlanItem)(item, config), '']);
|
|
265
|
+
const driftedCount = items.filter((i) => i.drifted && i.action !== 'delete').length;
|
|
266
|
+
const driftedSummary = driftedCount > 0
|
|
267
|
+
? [
|
|
268
|
+
colorize(lang_1.lang.__('PLAN_DRIFTED_SUMMARY', { driftedCount: String(driftedCount) }), 'CYAN', config.colorize),
|
|
269
|
+
'',
|
|
270
|
+
]
|
|
271
|
+
: [];
|
|
260
272
|
const summary = lang_1.lang.__('PLAN_SUMMARY', {
|
|
261
273
|
createCount: String(createItems.length),
|
|
262
274
|
updateCount: String(updateItems.length),
|
|
263
275
|
deleteCount: String(deleteItems.length),
|
|
264
276
|
});
|
|
265
|
-
return [...header, ...itemLines, summary].join('\n');
|
|
277
|
+
return [...header, ...itemLines, ...driftedSummary, summary].join('\n');
|
|
266
278
|
};
|
|
267
279
|
exports.formatPlan = formatPlan;
|
|
268
280
|
/* istanbul ignore next */
|