@geek-fun/serverlessinsight 0.9.2 → 0.9.4
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 +4 -8
- package/.serverlessinsight/state-insight-poc-app-log-insight-poc-tencent-log.json.backup +3 -8
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +4 -4
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +1 -1
- package/.serverlessinsight/state-insight-poc-timer-app-insight-poc-timer.json.backup +28 -5
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +2 -2
- package/.serverlessinsight/state-insight-volc-nested-app-insight-volc-nested.json.backup +3 -3
- package/.serverlessinsight/state-nested-drift-app-nested-drift-service.json.backup +20 -5
- package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +3 -3
- package/AGENTS.md +10 -0
- package/CHANGELOG.md +62 -0
- package/README.md +256 -175
- package/README.zh-CN.md +249 -159
- package/dist/package.json +22 -19
- package/dist/src/commands/index.js +21 -52
- package/dist/src/commands/local.js +16 -3
- package/dist/src/commands/plan.js +35 -4
- package/dist/src/common/aliyunClient/apigwOperations.js +48 -9
- package/dist/src/common/aliyunClient/fc3Operations.js +7 -1
- package/dist/src/common/aliyunClient/ossOperations.js +214 -221
- package/dist/src/common/bucketPolicy.js +63 -0
- package/dist/src/common/domainUtils.js +4 -1
- package/dist/src/common/functionDefinition.js +25 -0
- package/dist/src/common/index.js +4 -0
- package/dist/src/common/jsonOutput.js +6 -1
- package/dist/src/common/nameBuilder.js +3 -1
- package/dist/src/common/planCapabilities.js +119 -0
- package/dist/src/common/planCompare.js +119 -66
- package/dist/src/common/planFormatter.js +22 -14
- package/dist/src/common/planRedaction.js +26 -0
- package/dist/src/common/refreshPlanner.js +66 -21
- package/dist/src/common/tencentClient/cosOperations.js +326 -322
- package/dist/src/common/tencentClient/scfOperations.js +9 -2
- package/dist/src/common/tencentClient/tdsqlcOperations.js +6 -11
- package/dist/src/common/triggerMapper.js +16 -1
- package/dist/src/common/volcengineClient/apigwOperations.js +82 -0
- package/dist/src/common/volcengineClient/iamOperations.js +27 -3
- package/dist/src/common/volcengineClient/tosOperations.js +62 -56
- package/dist/src/lang/en.js +33 -8
- package/dist/src/lang/index.js +28 -14
- package/dist/src/lang/zh-CN.js +33 -8
- package/dist/src/parser/eventParser.js +1 -0
- package/dist/src/parser/functionParser.js +1 -1
- package/dist/src/stack/aliyunStack/apigwDomainPlan.js +82 -0
- package/dist/src/stack/aliyunStack/apigwExecutor.js +4 -1
- package/dist/src/stack/aliyunStack/apigwPlanner.js +165 -25
- package/dist/src/stack/aliyunStack/apigwResource.js +172 -126
- package/dist/src/stack/aliyunStack/apigwTypes.js +3 -7
- package/dist/src/stack/aliyunStack/deployer.js +2 -0
- package/dist/src/stack/aliyunStack/esServerlessTypes.js +8 -4
- package/dist/src/stack/aliyunStack/fc3Executor.js +7 -3
- package/dist/src/stack/aliyunStack/fc3Planner.js +124 -155
- package/dist/src/stack/aliyunStack/fc3Resource.js +48 -52
- package/dist/src/stack/aliyunStack/fc3Types.js +30 -16
- package/dist/src/stack/aliyunStack/ossPlanner.js +15 -1
- package/dist/src/stack/aliyunStack/ossResource.js +113 -102
- package/dist/src/stack/aliyunStack/ossTypes.js +20 -20
- package/dist/src/stack/localStack/aliyunFc.js +1 -6
- package/dist/src/stack/localStack/event.js +31 -60
- package/dist/src/stack/localStack/function.js +24 -65
- package/dist/src/stack/localStack/functionRunner.js +10 -2
- package/dist/src/stack/localStack/httpAdapter.js +54 -0
- package/dist/src/stack/localStack/httpError.js +5 -0
- package/dist/src/stack/localStack/legacyLambda.js +26 -0
- package/dist/src/stack/localStack/localContext.js +29 -0
- package/dist/src/stack/localStack/localRoute.js +12 -0
- package/dist/src/stack/localStack/localRuntimes.js +22 -0
- package/dist/src/stack/localStack/localServer.js +8 -3
- package/dist/src/stack/localStack/requestBody.js +24 -0
- package/dist/src/stack/localStack/requestId.js +18 -0
- package/dist/src/stack/localStack/tencent.js +147 -0
- package/dist/src/stack/localStack/timer.js +23 -2
- package/dist/src/stack/localStack/volcengine.js +68 -0
- package/dist/src/stack/scfStack/cosPlanner.js +9 -14
- package/dist/src/stack/scfStack/cosResource.js +42 -50
- package/dist/src/stack/scfStack/cosTypes.js +19 -14
- package/dist/src/stack/scfStack/deployer.js +2 -0
- package/dist/src/stack/scfStack/scfExecutor.js +7 -3
- package/dist/src/stack/scfStack/scfHttpTrigger.js +106 -0
- package/dist/src/stack/scfStack/scfPlanner.js +67 -16
- package/dist/src/stack/scfStack/scfResource.js +170 -321
- package/dist/src/stack/scfStack/scfTypes.js +4 -3
- package/dist/src/stack/scfStack/tdsqlcPlanner.js +10 -13
- package/dist/src/stack/volcengineStack/apigwDomains.js +64 -0
- package/dist/src/stack/volcengineStack/apigwPlanner.js +71 -15
- package/dist/src/stack/volcengineStack/apigwResource.js +60 -24
- package/dist/src/stack/volcengineStack/apigwTypes.js +5 -1
- package/dist/src/stack/volcengineStack/deployer.js +6 -0
- package/dist/src/stack/volcengineStack/tosPlanner.js +8 -13
- package/dist/src/stack/volcengineStack/tosResource.js +22 -35
- package/dist/src/stack/volcengineStack/tosTypes.js +5 -8
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +142 -49
- package/dist/src/stack/volcengineStack/vefaasResource.js +17 -12
- package/dist/src/stack/volcengineStack/vefaasTypes.js +6 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +22 -19
- package/release-notes.md +53 -0
- package/samples/README_TENCENT_COS.md +3 -3
- package/samples/README_TENCENT_SCF.md +3 -3
- package/samples/tencent-local/index.js +13 -0
- package/samples/tencent-local/serverlessinsight.yml +23 -0
- package/samples/volcengine-local/index.js +13 -0
- package/samples/volcengine-local/serverlessinsight.yml +28 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertSupportedPlanUpdate = exports.assertPlanIdentity = void 0;
|
|
4
|
+
const lang_1 = require("../lang");
|
|
5
|
+
const planCompare_1 = require("./planCompare");
|
|
6
|
+
const UPDATE_FIELDS = {
|
|
7
|
+
VOLCENGINE_VEFAAS: [
|
|
8
|
+
'codeHash',
|
|
9
|
+
'runtime',
|
|
10
|
+
'handler',
|
|
11
|
+
'memorySize',
|
|
12
|
+
'timeout',
|
|
13
|
+
'environment',
|
|
14
|
+
'description',
|
|
15
|
+
'role',
|
|
16
|
+
'iam',
|
|
17
|
+
'vpcConfig',
|
|
18
|
+
'tosMountConfig',
|
|
19
|
+
'logConfig',
|
|
20
|
+
'logEnabled',
|
|
21
|
+
'timers',
|
|
22
|
+
],
|
|
23
|
+
ALIYUN_RDS_SERVERLESS: ['serverlessConfig', 'securityIPList'],
|
|
24
|
+
ALIYUN_ES_SERVERLESS: ['description', 'authentication'],
|
|
25
|
+
TDSQL_C_SERVERLESS: ['minCpu', 'maxCpu', 'autoPause', 'autoPauseDelay'],
|
|
26
|
+
TENCENT_ES_SERVERLESS: ['spaceName', 'kibanaWhiteIpList'],
|
|
27
|
+
ALIYUN_TABLESTORE_TABLE: ['reservedThroughput', 'tableOptions'],
|
|
28
|
+
SCF: [
|
|
29
|
+
'codeHash',
|
|
30
|
+
'memorySize',
|
|
31
|
+
'timeout',
|
|
32
|
+
'environment',
|
|
33
|
+
'iam',
|
|
34
|
+
'logConfig',
|
|
35
|
+
'logEnabled',
|
|
36
|
+
'http',
|
|
37
|
+
'domain',
|
|
38
|
+
'timers',
|
|
39
|
+
],
|
|
40
|
+
ALIYUN_OSS_BUCKET: [
|
|
41
|
+
'acl',
|
|
42
|
+
'websiteConfiguration',
|
|
43
|
+
'websiteCodeHash',
|
|
44
|
+
'domain',
|
|
45
|
+
'wwwBindApex',
|
|
46
|
+
'domainCertificateId',
|
|
47
|
+
'domainCertificateBody',
|
|
48
|
+
'domainCertificatePrivateKey',
|
|
49
|
+
'domainProtocol',
|
|
50
|
+
'policy',
|
|
51
|
+
'cdnType',
|
|
52
|
+
'cdnScope',
|
|
53
|
+
'cdnCacheTtl',
|
|
54
|
+
'cdnIgnoreQueryString',
|
|
55
|
+
'cdnOriginProtocol',
|
|
56
|
+
'cdnCompression',
|
|
57
|
+
'cdnForceRedirectHttps',
|
|
58
|
+
],
|
|
59
|
+
COS_BUCKET: [
|
|
60
|
+
'acl',
|
|
61
|
+
'websiteConfiguration',
|
|
62
|
+
'domain',
|
|
63
|
+
'wwwBindApex',
|
|
64
|
+
'domainCertificateId',
|
|
65
|
+
'domainCertificateBody',
|
|
66
|
+
'domainCertificatePrivateKey',
|
|
67
|
+
'domainProtocol',
|
|
68
|
+
'policy',
|
|
69
|
+
],
|
|
70
|
+
VOLCENGINE_TOS_BUCKET: ['acl', 'websiteConfiguration', 'websiteCodeHash', 'policy'],
|
|
71
|
+
};
|
|
72
|
+
const IDENTITY_FIELDS = {
|
|
73
|
+
ALIYUN_FC3: ['functionName'],
|
|
74
|
+
SCF: ['functionName'],
|
|
75
|
+
VOLCENGINE_VEFAAS: ['functionName'],
|
|
76
|
+
ALIYUN_OSS_BUCKET: ['bucketName'],
|
|
77
|
+
COS_BUCKET: ['bucket', 'region'],
|
|
78
|
+
VOLCENGINE_TOS_BUCKET: ['bucketName'],
|
|
79
|
+
ALIYUN_RDS_SERVERLESS: [],
|
|
80
|
+
ALIYUN_ES_SERVERLESS: ['appName'],
|
|
81
|
+
TDSQL_C_SERVERLESS: [],
|
|
82
|
+
TENCENT_ES_SERVERLESS: [],
|
|
83
|
+
ALIYUN_TABLESTORE_TABLE: ['instanceName', 'tableName'],
|
|
84
|
+
ALIYUN_APIGW: ['groupName'],
|
|
85
|
+
VOLCENGINE_APIGW: ['gatewayName'],
|
|
86
|
+
};
|
|
87
|
+
const assertPlanIdentity = (logicalId, resourceType, stored, desired) => {
|
|
88
|
+
const changed = (IDENTITY_FIELDS[resourceType] ?? []).filter((key) => stored[key] !== undefined &&
|
|
89
|
+
(0, planCompare_1.definitionsDiffer)({ [key]: stored[key] }, { [key]: desired[key] }));
|
|
90
|
+
if (changed.length) {
|
|
91
|
+
throw new Error(lang_1.lang.__('PLAN_REPLACEMENT_REQUIRED', { logicalId, fields: changed.join(', ') }));
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
exports.assertPlanIdentity = assertPlanIdentity;
|
|
95
|
+
const assertSupportedPlanUpdate = (logicalId, resourceType, before, desired) => {
|
|
96
|
+
if (resourceType === 'ALIYUN_FC3' &&
|
|
97
|
+
Array.isArray(before.nasStorage) &&
|
|
98
|
+
Array.isArray(desired.nasStorage)) {
|
|
99
|
+
const oldClasses = before.nasStorage.map((entry) => entry.storage_class);
|
|
100
|
+
const newClasses = desired.nasStorage.map((entry) => entry.storage_class);
|
|
101
|
+
if (JSON.stringify(oldClasses) !== JSON.stringify(newClasses)) {
|
|
102
|
+
throw new Error(lang_1.lang.__('PLAN_UPDATE_NOT_SUPPORTED', { logicalId, fields: 'nasStorage.storage_class' }));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (resourceType === 'ALIYUN_OSS_BUCKET' &&
|
|
106
|
+
(before.cdnEnabled === true || before.accelerateEnabled === true) &&
|
|
107
|
+
(0, planCompare_1.definitionsDiffer)({ domain: before.domain }, { domain: desired.domain })) {
|
|
108
|
+
throw new Error(lang_1.lang.__('PLAN_UPDATE_NOT_SUPPORTED', { logicalId, fields: 'domain' }));
|
|
109
|
+
}
|
|
110
|
+
const supported = UPDATE_FIELDS[resourceType];
|
|
111
|
+
if (!supported)
|
|
112
|
+
return;
|
|
113
|
+
const changed = Object.keys((0, planCompare_1.managedDefinition)(desired)).filter((key) => !supported.includes(key) &&
|
|
114
|
+
(0, planCompare_1.definitionsDiffer)({ [key]: before[key] }, { [key]: desired[key] }));
|
|
115
|
+
if (changed.length) {
|
|
116
|
+
throw new Error(lang_1.lang.__('PLAN_UPDATE_NOT_SUPPORTED', { logicalId, fields: changed.join(', ') }));
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
exports.assertSupportedPlanUpdate = assertSupportedPlanUpdate;
|
|
@@ -1,92 +1,145 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.computeRevertKeys = exports.mergeLiveBefore = exports.jsonDocumentDiffers = exports.remoteDiffersFromDesired = void 0;
|
|
3
|
+
exports.mergeManagedIntent = exports.computeRevertKeys = exports.mergeLiveBefore = exports.jsonDocumentDiffers = exports.remoteDiffersFromDesired = exports.definitionsDiffer = exports.managedDefinition = void 0;
|
|
4
4
|
const hashUtils_1 = require("./hashUtils");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
6
|
+
const isDeclared = (value) => value !== undefined && value !== null && (!isRecord(value) || Object.keys(value).length > 0);
|
|
7
|
+
// Membership lists are sets; command arguments, routes and mount sequences are not.
|
|
8
|
+
const SET_FIELDS = new Set([
|
|
9
|
+
'vSwitchIds',
|
|
10
|
+
'subnetIds',
|
|
11
|
+
'securityGroupIds',
|
|
12
|
+
'subnet_ids',
|
|
13
|
+
'managed_policies',
|
|
14
|
+
'kibanaWhiteIpList',
|
|
15
|
+
'ips',
|
|
16
|
+
'timers',
|
|
17
|
+
'methods',
|
|
18
|
+
'domainProtocol',
|
|
19
|
+
'statements',
|
|
20
|
+
'action',
|
|
21
|
+
'resource',
|
|
22
|
+
'Service',
|
|
23
|
+
'AWS',
|
|
24
|
+
'qcs',
|
|
25
|
+
]);
|
|
26
|
+
const canonicalValue = (value, key, policyDocument = false) => {
|
|
27
|
+
const policyScope = policyDocument || key === 'policy';
|
|
28
|
+
if (key === 'policy' && (value === null || value === 'null'))
|
|
29
|
+
return 'null';
|
|
30
|
+
if (key === 'policy' && typeof value === 'string') {
|
|
31
|
+
try {
|
|
32
|
+
return canonicalValue(JSON.parse(value), '', true);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
16
37
|
}
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
38
|
+
if (Array.isArray(value)) {
|
|
39
|
+
const entries = value.map((entry) => canonicalValue(entry, '', policyScope));
|
|
40
|
+
return policyScope || SET_FIELDS.has(key)
|
|
41
|
+
? [
|
|
42
|
+
...new Map(entries.map((entry) => [JSON.stringify(entry) ?? 'null', entry])).values(),
|
|
43
|
+
].sort((a, b) => (JSON.stringify(a) ?? 'null').localeCompare(JSON.stringify(b) ?? 'null'))
|
|
44
|
+
: entries;
|
|
45
|
+
}
|
|
46
|
+
if (isRecord(value)) {
|
|
47
|
+
return Object.fromEntries(Object.entries(value)
|
|
48
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
49
|
+
.map(([name, entry]) => [name, canonicalValue(entry, name, policyScope)]));
|
|
21
50
|
}
|
|
22
|
-
return
|
|
51
|
+
return value;
|
|
23
52
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return false;
|
|
53
|
+
const projectValue = (actual, desired, key) => {
|
|
54
|
+
if (key === 'policy')
|
|
55
|
+
return canonicalValue(actual, key);
|
|
56
|
+
if (Array.isArray(actual) && Array.isArray(desired) && !SET_FIELDS.has(key)) {
|
|
57
|
+
return actual.map((entry, index) => index < desired.length ? projectValue(entry, desired[index], '') : canonicalValue(entry, ''));
|
|
58
|
+
}
|
|
59
|
+
// An environment declaration replaces the entire map, including removal of
|
|
60
|
+
// cloud-only entries. Structural configs write only their declared members.
|
|
61
|
+
if (isRecord(desired) && isRecord(actual) && key !== 'environment') {
|
|
62
|
+
return Object.fromEntries(Object.entries(desired)
|
|
63
|
+
.filter(([, value]) => isDeclared(value))
|
|
64
|
+
.map(([name, value]) => [name, projectValue(actual[name], value, name)]));
|
|
37
65
|
}
|
|
38
|
-
return
|
|
39
|
-
}
|
|
66
|
+
return canonicalValue(actual, key);
|
|
67
|
+
};
|
|
68
|
+
/** The fields the current configuration actually manages, in comparison form. */
|
|
69
|
+
const managedDefinition = (actual, desired = actual) => Object.fromEntries(Object.entries(desired)
|
|
70
|
+
.filter(([, value]) => isDeclared(value))
|
|
71
|
+
.map(([key, value]) => [key, projectValue(actual[key], value, key)]));
|
|
72
|
+
exports.managedDefinition = managedDefinition;
|
|
73
|
+
const definitionsDiffer = (actual, desired) => !(0, hashUtils_1.attributesEqual)((0, exports.managedDefinition)(actual, desired), (0, exports.managedDefinition)(desired));
|
|
74
|
+
exports.definitionsDiffer = definitionsDiffer;
|
|
75
|
+
/** Only mapper-emitted fields are readable. Explicit null means known absence. */
|
|
76
|
+
const remoteDiffersFromDesired = (remote, desired) => Object.keys(remote).some((key) => remote[key] !== undefined &&
|
|
77
|
+
isDeclared(desired[key]) &&
|
|
78
|
+
!(0, hashUtils_1.attributesEqual)({ value: projectValue(remote[key], desired[key], key) }, { value: projectValue(desired[key], desired[key], key) }));
|
|
40
79
|
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
|
-
*/
|
|
80
|
+
/** Undefined is unavailable; null is a successfully read, absent policy. */
|
|
49
81
|
const jsonDocumentDiffers = (desired, cloud) => {
|
|
50
|
-
if (desired === null || cloud === undefined
|
|
82
|
+
if (desired === null || cloud === undefined) {
|
|
51
83
|
return false;
|
|
52
84
|
}
|
|
85
|
+
if (cloud === null) {
|
|
86
|
+
return desired !== 'null';
|
|
87
|
+
}
|
|
53
88
|
try {
|
|
54
89
|
const desiredObj = JSON.parse(desired);
|
|
55
90
|
const cloudObj = typeof cloud === 'string' ? JSON.parse(cloud) : cloud;
|
|
56
|
-
return !(0, hashUtils_1.attributesEqual)({ doc:
|
|
91
|
+
return !(0, hashUtils_1.attributesEqual)({ doc: desiredObj }, { doc: cloudObj });
|
|
57
92
|
}
|
|
58
93
|
catch {
|
|
59
94
|
return false;
|
|
60
95
|
}
|
|
61
96
|
};
|
|
62
97
|
exports.jsonDocumentDiffers = jsonDocumentDiffers;
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const mergeLiveBefore = (stored, live) => ({ ...stored, ...live });
|
|
98
|
+
/** Live values override stored intent only inside currently managed dimensions. */
|
|
99
|
+
const mergeLiveBefore = (stored, live, desired) => {
|
|
100
|
+
const before = {
|
|
101
|
+
...stored,
|
|
102
|
+
...Object.fromEntries(Object.entries(live).filter(([, value]) => value !== undefined)),
|
|
103
|
+
};
|
|
104
|
+
return desired ? (0, exports.managedDefinition)(before, desired) : before;
|
|
105
|
+
};
|
|
72
106
|
exports.mergeLiveBefore = mergeLiveBefore;
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
107
|
+
const revertPaths = (stored, live, desired, path) => {
|
|
108
|
+
if ((0, hashUtils_1.attributesEqual)({ value: live }, { value: desired })) {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
if (isRecord(live) && isRecord(desired)) {
|
|
112
|
+
const saved = isRecord(stored) ? stored : {};
|
|
113
|
+
return [...new Set([...Object.keys(live), ...Object.keys(desired)])].flatMap((key) => revertPaths(saved[key], live[key], desired[key], `${path}.${key}`));
|
|
114
|
+
}
|
|
115
|
+
return (0, hashUtils_1.attributesEqual)({ value: stored }, { value: desired }) ? [path] : [];
|
|
116
|
+
};
|
|
80
117
|
const computeRevertKeys = (stored, live, desired) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
118
|
+
const saved = (0, exports.managedDefinition)(stored, desired);
|
|
119
|
+
const current = (0, exports.managedDefinition)(live, desired);
|
|
120
|
+
const target = (0, exports.managedDefinition)(desired);
|
|
84
121
|
return Object.keys(live)
|
|
85
|
-
.filter((key) =>
|
|
86
|
-
|
|
87
|
-
const liveMatchesDesired = (0, hashUtils_1.attributesEqual)({ [key]: live[key] }, { [key]: desired[key] });
|
|
88
|
-
return storedMatchesDesired && !liveMatchesDesired;
|
|
89
|
-
})
|
|
122
|
+
.filter((key) => live[key] !== undefined && isDeclared(desired[key]))
|
|
123
|
+
.flatMap((key) => revertPaths(saved[key], current[key], target[key], key))
|
|
90
124
|
.sort((a, b) => a.localeCompare(b));
|
|
91
125
|
};
|
|
92
126
|
exports.computeRevertKeys = computeRevertKeys;
|
|
127
|
+
const mergeIntentValue = (stored, desired) => {
|
|
128
|
+
if (!isDeclared(desired))
|
|
129
|
+
return stored ?? desired;
|
|
130
|
+
if (!isRecord(desired))
|
|
131
|
+
return desired;
|
|
132
|
+
const previous = isRecord(stored) ? stored : {};
|
|
133
|
+
return Object.fromEntries([...new Set([...Object.keys(previous), ...Object.keys(desired)])].map((key) => [
|
|
134
|
+
key,
|
|
135
|
+
mergeIntentValue(previous[key], desired[key]),
|
|
136
|
+
]));
|
|
137
|
+
};
|
|
138
|
+
/** Retain unmanaged history so unrelated writes cannot erase dependency configuration. */
|
|
139
|
+
const mergeManagedIntent = (stored, desired) => Object.fromEntries([...new Set([...Object.keys(stored), ...Object.keys(desired)])].map((key) => [
|
|
140
|
+
key,
|
|
141
|
+
key === 'environment' && isDeclared(desired[key])
|
|
142
|
+
? desired[key]
|
|
143
|
+
: mergeIntentValue(stored[key], desired[key]),
|
|
144
|
+
]));
|
|
145
|
+
exports.mergeManagedIntent = mergeManagedIntent;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.displayPlan = exports.formatPlan = exports.formatPlanItem = exports.isRecreate = exports.computeAttributeDiffs = void 0;
|
|
4
|
+
const planRedaction_1 = require("./planRedaction");
|
|
4
5
|
const hashUtils_1 = require("./hashUtils");
|
|
5
6
|
const lang_1 = require("../lang");
|
|
6
7
|
const logger_1 = require("./logger");
|
|
@@ -141,15 +142,18 @@ const computeMaxKeyWidth = (diffs, baseIndent) => diffs.reduce((maxWidth, diff)
|
|
|
141
142
|
: 0;
|
|
142
143
|
return Math.max(maxWidth, keyWidth, childWidth);
|
|
143
144
|
}, 0);
|
|
144
|
-
const formatAttributeLines = (diff, indent, config, keyWidth, revertKeys) => {
|
|
145
|
+
const formatAttributeLines = (diff, indent, config, keyWidth, revertKeys, parentPath = '', inheritedRevert = false) => {
|
|
145
146
|
const spaces = ' '.repeat(indent);
|
|
146
147
|
const alignedKey = (diff.key + ':').padEnd(keyWidth);
|
|
148
|
+
const fieldPath = parentPath ? `${parentPath}.${diff.key}` : diff.key;
|
|
149
|
+
const reverted = inheritedRevert || revertKeys?.has(fieldPath);
|
|
150
|
+
const marker = { add: '+', remove: '-', change: '~' }[diff.action];
|
|
147
151
|
// Issue #246: a field whose stored value already matched the config while
|
|
148
152
|
// the cloud diverged is annotated at the line level — the resource block
|
|
149
153
|
// stays in place, only this line explains why it appears. Only leaf lines
|
|
150
154
|
// reach suffix (parent cases early-return on children), so a revert key
|
|
151
155
|
// with nested children never carries the annotation.
|
|
152
|
-
const suffix = (line) =>
|
|
156
|
+
const suffix = (line) => reverted
|
|
153
157
|
? `${line} ${colorize(lang_1.lang.__('PLAN_REVERT_ANNOTATION'), 'CYAN', config.colorize)}`
|
|
154
158
|
: line;
|
|
155
159
|
switch (diff.action) {
|
|
@@ -157,39 +161,41 @@ const formatAttributeLines = (diff, indent, config, keyWidth, revertKeys) => {
|
|
|
157
161
|
if (diff.children && diff.children.length > 0) {
|
|
158
162
|
const childKeyWidth = computeMaxKeyWidth(diff.children, indent);
|
|
159
163
|
return [
|
|
160
|
-
colorize(`${spaces}${alignedKey}`, 'GREEN', config.colorize),
|
|
161
|
-
...diff.children.flatMap((child) => formatAttributeLines(child, indent + config.indentSize, config, childKeyWidth)),
|
|
164
|
+
colorize(`${spaces}${marker} ${alignedKey}`, 'GREEN', config.colorize),
|
|
165
|
+
...diff.children.flatMap((child) => formatAttributeLines(child, indent + config.indentSize, config, childKeyWidth, revertKeys, fieldPath, reverted)),
|
|
162
166
|
];
|
|
163
167
|
}
|
|
164
168
|
const value = diff.isComputed
|
|
165
169
|
? colorize(lang_1.lang.__('PLAN_COMPUTED_VALUE'), 'CYAN', config.colorize)
|
|
166
170
|
: formatValue(diff.after);
|
|
167
|
-
return [
|
|
171
|
+
return [
|
|
172
|
+
suffix(colorize(`${spaces}${marker} ${alignedKey} ${value}`, 'GREEN', config.colorize)),
|
|
173
|
+
];
|
|
168
174
|
}
|
|
169
175
|
case 'remove': {
|
|
170
176
|
if (diff.children && diff.children.length > 0) {
|
|
171
177
|
const childKeyWidth = computeMaxKeyWidth(diff.children, indent);
|
|
172
178
|
return [
|
|
173
|
-
colorize(`${spaces}${alignedKey}`, 'RED', config.colorize),
|
|
174
|
-
...diff.children.flatMap((child) => formatAttributeLines(child, indent + config.indentSize, config, childKeyWidth)),
|
|
179
|
+
colorize(`${spaces}${marker} ${alignedKey}`, 'RED', config.colorize),
|
|
180
|
+
...diff.children.flatMap((child) => formatAttributeLines(child, indent + config.indentSize, config, childKeyWidth, revertKeys, fieldPath, reverted)),
|
|
175
181
|
];
|
|
176
182
|
}
|
|
177
183
|
return [
|
|
178
|
-
suffix(colorize(`${spaces}${alignedKey} ${formatValue(diff.before)}`, 'RED', config.colorize)),
|
|
184
|
+
suffix(colorize(`${spaces}${marker} ${alignedKey} ${formatValue(diff.before)}`, 'RED', config.colorize)),
|
|
179
185
|
];
|
|
180
186
|
}
|
|
181
187
|
case 'change': {
|
|
182
188
|
if (diff.children && diff.children.length > 0) {
|
|
183
189
|
const childKeyWidth = computeMaxKeyWidth(diff.children, indent);
|
|
184
190
|
return [
|
|
185
|
-
colorize(`${spaces}${alignedKey}`, 'YELLOW', config.colorize),
|
|
186
|
-
...diff.children.flatMap((child) => formatAttributeLines(child, indent + config.indentSize, config, childKeyWidth)),
|
|
191
|
+
colorize(`${spaces}${marker} ${alignedKey}`, 'YELLOW', config.colorize),
|
|
192
|
+
...diff.children.flatMap((child) => formatAttributeLines(child, indent + config.indentSize, config, childKeyWidth, revertKeys, fieldPath, reverted)),
|
|
187
193
|
];
|
|
188
194
|
}
|
|
189
195
|
const beforeStr = formatValue(diff.before);
|
|
190
196
|
const afterStr = formatValue(diff.after);
|
|
191
197
|
return [
|
|
192
|
-
suffix(colorize(`${spaces}${alignedKey} ${beforeStr} -> ${afterStr}`, 'YELLOW', config.colorize)),
|
|
198
|
+
suffix(colorize(`${spaces}${marker} ${alignedKey} ${beforeStr} -> ${afterStr}`, 'YELLOW', config.colorize)),
|
|
193
199
|
];
|
|
194
200
|
}
|
|
195
201
|
}
|
|
@@ -223,7 +229,9 @@ const formatPlanItem = (item, config = DEFAULT_CONFIG) => {
|
|
|
223
229
|
if (item.action === 'noop') {
|
|
224
230
|
// Unchanged resources are not rendered as blocks — they only surface in
|
|
225
231
|
// the plan summary count (issue #246 display spec).
|
|
226
|
-
return
|
|
232
|
+
return item.stateUpdate
|
|
233
|
+
? ` # ${lang_1.lang.__('PLAN_STATE_ONLY', { logicalId: item.logicalId })}`
|
|
234
|
+
: '';
|
|
227
235
|
}
|
|
228
236
|
const recreate = (0, exports.isRecreate)(item);
|
|
229
237
|
const descKey = recreate ? 'PLAN_WILL_RECREATE' : (ACTION_DESC[item.action] ?? 'PLAN_NO_CHANGES');
|
|
@@ -246,7 +254,7 @@ const formatPlanItem = (item, config = DEFAULT_CONFIG) => {
|
|
|
246
254
|
const keyWidth = Math.max(config.keyAlignWidth, computeMaxKeyWidth(diffs, config.indentSize));
|
|
247
255
|
const revertKeys = new Set(item.revertKeys ?? []);
|
|
248
256
|
const attrLines = diffs.length > 0
|
|
249
|
-
? diffs.flatMap((diff) => formatAttributeLines(diff, config.indentSize, config, keyWidth, revertKeys))
|
|
257
|
+
? (0, planRedaction_1.redactAttributeDiffs)(diffs).flatMap((diff) => formatAttributeLines(diff, config.indentSize, config, keyWidth, revertKeys))
|
|
250
258
|
: [];
|
|
251
259
|
const hiddenLine = unchangedCount > 0
|
|
252
260
|
? [
|
|
@@ -274,7 +282,7 @@ const formatPlan = (items, config = DEFAULT_CONFIG) => {
|
|
|
274
282
|
// resources only surface in the summary count.
|
|
275
283
|
const unchangedCount = items.filter((i) => i.action === 'noop').length;
|
|
276
284
|
const itemLines = items
|
|
277
|
-
.filter((i) => i.action !== 'noop')
|
|
285
|
+
.filter((i) => i.action !== 'noop' || i.stateUpdate)
|
|
278
286
|
.flatMap((item) => {
|
|
279
287
|
const block = (0, exports.formatPlanItem)(item, config);
|
|
280
288
|
return block ? [block, ''] : [];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.redactAttributeDiffs = void 0;
|
|
4
|
+
const lang_1 = require("../lang");
|
|
5
|
+
const SENSITIVE_FIELDS = new Set([
|
|
6
|
+
'authentication',
|
|
7
|
+
'credentials',
|
|
8
|
+
'domainCertificatePrivateKey',
|
|
9
|
+
'certificatePrivateKey',
|
|
10
|
+
]);
|
|
11
|
+
/** Comparison markers never become public credential values in human or JSON plans. */
|
|
12
|
+
const redactAttributeDiffs = (diffs) => diffs.map((diff) => {
|
|
13
|
+
if (SENSITIVE_FIELDS.has(diff.key)) {
|
|
14
|
+
const { children: _children, before, after, ...rest } = diff;
|
|
15
|
+
return {
|
|
16
|
+
...rest,
|
|
17
|
+
...(before !== undefined ? { before: lang_1.lang.__('PLAN_SENSITIVE_VALUE') } : {}),
|
|
18
|
+
...(after !== undefined ? { after: lang_1.lang.__('PLAN_SENSITIVE_VALUE') } : {}),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
...diff,
|
|
23
|
+
...(diff.children ? { children: (0, exports.redactAttributeDiffs)(diff.children) } : {}),
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
exports.redactAttributeDiffs = redactAttributeDiffs;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.planRefreshedResource = exports.decideRefreshedExistsAction = void 0;
|
|
3
|
+
exports.applyPlanStateUpdates = exports.planRefreshedResource = exports.decideRefreshedExistsAction = void 0;
|
|
4
4
|
const hashUtils_1 = require("./hashUtils");
|
|
5
|
+
const planCapabilities_1 = require("./planCapabilities");
|
|
6
|
+
const stateManager_1 = require("./stateManager");
|
|
5
7
|
const planCompare_1 = require("./planCompare");
|
|
6
8
|
const logger_1 = require("./logger");
|
|
7
9
|
const lang_1 = require("../lang");
|
|
@@ -15,18 +17,27 @@ const decideRefreshedExistsAction = async (args) => {
|
|
|
15
17
|
attributes = await args.enrichRemoteAttributes(remote, attributes);
|
|
16
18
|
}
|
|
17
19
|
const remoteDiffers = (0, planCompare_1.remoteDiffersFromDesired)(attributes, args.desiredDefinition);
|
|
18
|
-
|
|
19
|
-
return { action: 'update', drifted: true, liveAttributes: attributes };
|
|
20
|
-
}
|
|
20
|
+
const effectiveChanged = (0, planCompare_1.definitionsDiffer)((0, planCompare_1.mergeLiveBefore)(args.storedDefinition, attributes, args.desiredDefinition), args.desiredDefinition);
|
|
21
21
|
const extra = await args.extraUpdate?.();
|
|
22
|
-
if (extra?.update) {
|
|
22
|
+
if (effectiveChanged || extra?.update) {
|
|
23
|
+
const drifted = (0, planCompare_1.remoteDiffersFromDesired)(attributes, (0, planCompare_1.managedDefinition)(args.storedDefinition, args.desiredDefinition)) ||
|
|
24
|
+
(extra?.update === true && extra.drifted === true);
|
|
23
25
|
return {
|
|
24
26
|
action: 'update',
|
|
25
|
-
drifted
|
|
27
|
+
drifted,
|
|
26
28
|
liveAttributes: attributes,
|
|
27
|
-
...(extra
|
|
29
|
+
...(extra?.reasons?.length || extra?.reason
|
|
30
|
+
? {
|
|
31
|
+
driftReasons: [
|
|
32
|
+
...new Set([...(extra?.reasons ?? []), ...(extra?.reason ? [extra.reason] : [])]),
|
|
33
|
+
],
|
|
34
|
+
}
|
|
35
|
+
: {}),
|
|
28
36
|
};
|
|
29
37
|
}
|
|
38
|
+
if (args.definitionChanged && !remoteDiffers) {
|
|
39
|
+
return { action: 'state', liveAttributes: attributes };
|
|
40
|
+
}
|
|
30
41
|
return { action: 'noop' };
|
|
31
42
|
};
|
|
32
43
|
exports.decideRefreshedExistsAction = decideRefreshedExistsAction;
|
|
@@ -42,8 +53,31 @@ exports.decideRefreshedExistsAction = decideRefreshedExistsAction;
|
|
|
42
53
|
* renders a complete live→desired field diff, and `revertKeys` marks the
|
|
43
54
|
* fields whose difference is purely an out-of-config cloud edit.
|
|
44
55
|
*/
|
|
45
|
-
const
|
|
56
|
+
const withRemovedDependents = (item, removed, desired) => {
|
|
57
|
+
if (Object.keys(removed).length === 0 || item.action === 'create' || item.action === 'delete') {
|
|
58
|
+
return item;
|
|
59
|
+
}
|
|
60
|
+
const { stateUpdate: _stateUpdate, ...rest } = item;
|
|
61
|
+
return {
|
|
62
|
+
...rest,
|
|
63
|
+
action: 'update',
|
|
64
|
+
changes: {
|
|
65
|
+
before: { ...(item.changes?.before ?? {}), ...removed },
|
|
66
|
+
after: item.changes?.after ?? (0, planCompare_1.managedDefinition)(desired),
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
const planRefreshedResource = async (args) => withRemovedDependents(await planRefreshedResourceCore(args), args.currentState ? (args.removedDependents ?? {}) : {}, args.desiredDefinition);
|
|
71
|
+
exports.planRefreshedResource = planRefreshedResource;
|
|
72
|
+
const planRefreshedResourceCore = async (args) => {
|
|
46
73
|
const { logicalId, resourceType, currentState, desiredDefinition } = args;
|
|
74
|
+
if (currentState) {
|
|
75
|
+
if (currentState.metadata?.resourceType &&
|
|
76
|
+
currentState.metadata.resourceType !== resourceType) {
|
|
77
|
+
throw new Error(lang_1.lang.__('PLAN_REPLACEMENT_REQUIRED', { logicalId, fields: 'resourceType' }));
|
|
78
|
+
}
|
|
79
|
+
(0, planCapabilities_1.assertPlanIdentity)(logicalId, resourceType, currentState.definition || {}, desiredDefinition);
|
|
80
|
+
}
|
|
47
81
|
if (!currentState || currentState.status === 'tainted') {
|
|
48
82
|
const probeRead = args.probeRead ?? args.read;
|
|
49
83
|
const remote = await probeRead();
|
|
@@ -59,8 +93,8 @@ const planRefreshedResource = async (args) => {
|
|
|
59
93
|
}
|
|
60
94
|
const normalize = args.normalizeForDisplay ?? ((d) => d);
|
|
61
95
|
const currentDefinition = currentState.definition || {};
|
|
62
|
-
const normalizedCurrent = normalize(currentDefinition);
|
|
63
|
-
const normalizedDesired = normalize(desiredDefinition);
|
|
96
|
+
const normalizedCurrent = (0, planCompare_1.managedDefinition)(normalize(currentDefinition), normalize(desiredDefinition));
|
|
97
|
+
const normalizedDesired = (0, planCompare_1.managedDefinition)(normalize(desiredDefinition));
|
|
64
98
|
const definitionChanged = !(0, hashUtils_1.attributesEqual)(normalizedCurrent, normalizedDesired);
|
|
65
99
|
const refreshEnabled = args.refresh ?? true;
|
|
66
100
|
try {
|
|
@@ -69,6 +103,7 @@ const planRefreshedResource = async (args) => {
|
|
|
69
103
|
if (!definitionChanged) {
|
|
70
104
|
return { logicalId, action: 'noop', resourceType };
|
|
71
105
|
}
|
|
106
|
+
(0, planCapabilities_1.assertSupportedPlanUpdate)(logicalId, resourceType, { ...currentDefinition, ...normalizedCurrent }, normalizedDesired);
|
|
72
107
|
return {
|
|
73
108
|
logicalId,
|
|
74
109
|
action: 'update',
|
|
@@ -78,9 +113,10 @@ const planRefreshedResource = async (args) => {
|
|
|
78
113
|
}
|
|
79
114
|
const decision = await (0, exports.decideRefreshedExistsAction)({
|
|
80
115
|
read: args.read,
|
|
81
|
-
cloudToDefinition: args.cloudToDefinition,
|
|
116
|
+
cloudToDefinition: (remote) => normalize(args.cloudToDefinition(remote)),
|
|
82
117
|
enrichRemoteAttributes: args.enrichRemoteAttributes,
|
|
83
|
-
desiredDefinition,
|
|
118
|
+
desiredDefinition: normalizedDesired,
|
|
119
|
+
storedDefinition: normalizedCurrent,
|
|
84
120
|
definitionChanged,
|
|
85
121
|
extraUpdate: args.extraUpdate,
|
|
86
122
|
});
|
|
@@ -96,14 +132,19 @@ const planRefreshedResource = async (args) => {
|
|
|
96
132
|
drifted: true,
|
|
97
133
|
};
|
|
98
134
|
}
|
|
135
|
+
if (decision.action === 'state') {
|
|
136
|
+
return { logicalId, action: 'noop', resourceType, stateUpdate: desiredDefinition };
|
|
137
|
+
}
|
|
99
138
|
const normalizedLive = normalize(decision.liveAttributes);
|
|
139
|
+
const before = (0, planCompare_1.mergeLiveBefore)(normalizedCurrent, normalizedLive, normalizedDesired);
|
|
140
|
+
(0, planCapabilities_1.assertSupportedPlanUpdate)(logicalId, resourceType, { ...currentDefinition, ...before }, normalizedDesired);
|
|
100
141
|
const revertKeys = (0, planCompare_1.computeRevertKeys)(normalizedCurrent, normalizedLive, normalizedDesired);
|
|
101
142
|
return {
|
|
102
143
|
logicalId,
|
|
103
144
|
action: 'update',
|
|
104
145
|
resourceType,
|
|
105
146
|
changes: {
|
|
106
|
-
before
|
|
147
|
+
before,
|
|
107
148
|
after: normalizedDesired,
|
|
108
149
|
},
|
|
109
150
|
...(decision.drifted ? { drifted: true } : {}),
|
|
@@ -116,13 +157,17 @@ const planRefreshedResource = async (args) => {
|
|
|
116
157
|
logicalId,
|
|
117
158
|
error: error instanceof Error ? error.message : String(error),
|
|
118
159
|
}));
|
|
119
|
-
|
|
120
|
-
logicalId,
|
|
121
|
-
action: 'create',
|
|
122
|
-
resourceType,
|
|
123
|
-
changes: { before: normalizedCurrent, after: normalizedDesired },
|
|
124
|
-
drifted: true,
|
|
125
|
-
};
|
|
160
|
+
throw error;
|
|
126
161
|
}
|
|
127
162
|
};
|
|
128
|
-
|
|
163
|
+
/** Applied only under the deployment lock, never by the read-only plan command. */
|
|
164
|
+
const applyPlanStateUpdates = (state, items) => items.reduce((current, item) => {
|
|
165
|
+
const resource = (0, stateManager_1.getResource)(current, item.logicalId);
|
|
166
|
+
if (item.action !== 'noop' || !item.stateUpdate || !resource)
|
|
167
|
+
return current;
|
|
168
|
+
return (0, stateManager_1.setResource)(current, item.logicalId, {
|
|
169
|
+
...resource,
|
|
170
|
+
definition: (0, planCompare_1.mergeManagedIntent)(resource.definition ?? {}, item.stateUpdate),
|
|
171
|
+
});
|
|
172
|
+
}, state);
|
|
173
|
+
exports.applyPlanStateUpdates = applyPlanStateUpdates;
|