@geek-fun/serverlessinsight 0.9.6 → 0.9.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/AGENTS.md +1 -0
- package/CHANGELOG.md +68 -0
- package/README.md +52 -11
- package/README.zh-CN.md +44 -10
- package/dist/package.json +2 -1
- package/dist/src/commands/deploy.js +3 -1
- package/dist/src/commands/destroy.js +3 -1
- package/dist/src/commands/forceUnlock.js +2 -2
- package/dist/src/commands/index.js +28 -8
- package/dist/src/commands/local.js +3 -2
- package/dist/src/commands/login.js +120 -37
- package/dist/src/commands/logout.js +3 -5
- package/dist/src/commands/migrate.js +17 -10
- package/dist/src/commands/plan.js +5 -1
- package/dist/src/commands/show.js +3 -1
- package/dist/src/commands/whoami.js +24 -6
- package/dist/src/common/aliyunClient/cdnOperations.js +64 -29
- package/dist/src/common/aliyunClient/dnsOperations.js +10 -0
- package/dist/src/common/aliyunClient/fc3Operations.js +36 -7
- package/dist/src/common/apiClient.js +1 -0
- package/dist/src/common/bindingReconcile.js +182 -0
- package/dist/src/common/cdnCapabilities.js +80 -0
- package/dist/src/common/certUtils.js +44 -5
- package/dist/src/common/consoleLines.js +126 -0
- package/dist/src/common/constants.js +4 -2
- package/dist/src/common/credentialStore.js +136 -39
- package/dist/src/common/domainUtils.js +23 -4
- package/dist/src/common/functionDefinition.js +4 -1
- package/dist/src/common/functionDomainCapabilities.js +28 -0
- package/dist/src/common/functionDomainReconcile.js +197 -0
- package/dist/src/common/lineContext.js +164 -0
- package/dist/src/common/planCapabilities.js +14 -27
- package/dist/src/common/planCompare.js +8 -7
- package/dist/src/common/planFormatter.js +71 -37
- package/dist/src/common/stateBackend/cosStateBackend.js +0 -46
- package/dist/src/common/stateBackend/index.js +24 -16
- package/dist/src/common/stateBackend/ossStateBackend.js +0 -25
- package/dist/src/common/stateBackend/remoteStateBackend.js +5 -22
- package/dist/src/common/stateBackend/saasStateBackend.js +46 -53
- package/dist/src/common/stateBackend/tosStateBackend.js +100 -0
- package/dist/src/common/stateBackend/types.js +0 -9
- package/dist/src/common/tencentClient/cdnOperations.js +165 -0
- package/dist/src/common/tencentClient/cosOperations.js +18 -2
- package/dist/src/common/tencentClient/dnspodOperations.js +12 -0
- package/dist/src/common/tencentClient/index.js +16 -0
- package/dist/src/common/tencentClient/scfOperations.js +23 -1
- package/dist/src/common/tencentClient/sslOperations.js +147 -77
- package/dist/src/common/volcengineClient/cdnOperations.js +221 -0
- package/dist/src/common/volcengineClient/dnsOperations.js +132 -0
- package/dist/src/common/volcengineClient/index.js +28 -0
- package/dist/src/common/volcengineClient/tosOperations.js +131 -1
- package/dist/src/lang/en.js +89 -12
- package/dist/src/lang/zh-CN.js +90 -11
- package/dist/src/parser/bucketParser.js +22 -79
- package/dist/src/parser/functionParser.js +13 -9
- package/dist/src/stack/aliyunStack/apigwResource.js +2 -1
- package/dist/src/stack/aliyunStack/fc3Planner.js +32 -12
- package/dist/src/stack/aliyunStack/fc3Resource.js +169 -121
- package/dist/src/stack/aliyunStack/ossPlanner.js +12 -4
- package/dist/src/stack/aliyunStack/ossResource.js +484 -501
- package/dist/src/stack/aliyunStack/ossTypes.js +21 -67
- package/dist/src/stack/localStack/aliyunFc.js +59 -9
- package/dist/src/stack/localStack/bucket.js +75 -28
- package/dist/src/stack/localStack/event.js +33 -24
- package/dist/src/stack/localStack/httpAdapter.js +1 -13
- package/dist/src/stack/localStack/index.js +2 -2
- package/dist/src/stack/localStack/localServer.js +85 -7
- package/dist/src/stack/scfStack/cosPlanner.js +11 -3
- package/dist/src/stack/scfStack/cosResource.js +339 -161
- package/dist/src/stack/scfStack/cosTypes.js +25 -34
- package/dist/src/stack/scfStack/scfPlanner.js +26 -8
- package/dist/src/stack/scfStack/scfResource.js +191 -124
- package/dist/src/stack/volcengineStack/tosPlanner.js +13 -1
- package/dist/src/stack/volcengineStack/tosResource.js +398 -7
- package/dist/src/stack/volcengineStack/tosTypes.js +27 -0
- package/dist/src/stack/volcengineStack/vefaasTypes.js +1 -1
- package/dist/src/types/domains/state.js +6 -0
- package/dist/src/validator/bucketSchema.js +35 -113
- package/dist/src/validator/cdnSchema.js +30 -0
- package/dist/src/validator/eventSchema.js +2 -20
- package/dist/src/validator/functionSchema.js +55 -8
- package/dist/src/validator/rootSchema.js +3 -3
- package/dist/src/validator/semanticValidation.js +504 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/release-notes.md +82 -6
- package/samples/aliyun-poc-api-cdn.yml +1 -1
- package/samples/aliyun-poc-bucket-cdn.yml +28 -26
- package/samples/aliyun-poc-domain.yml +2 -1
- package/samples/volcengine-poc-tos-state.yml +36 -0
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.resolveLineContext = void 0;
|
|
37
|
+
const readline = __importStar(require("node:readline"));
|
|
38
|
+
const logger_1 = require("./logger");
|
|
39
|
+
const lang_1 = require("../lang");
|
|
40
|
+
const consoleLines_1 = require("./consoleLines");
|
|
41
|
+
const credentialStore_1 = require("./credentialStore");
|
|
42
|
+
const readInput = async (query) => {
|
|
43
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
44
|
+
const answer = await new Promise((resolve) => {
|
|
45
|
+
rl.question(query, (value) => resolve(value));
|
|
46
|
+
});
|
|
47
|
+
rl.close();
|
|
48
|
+
return answer;
|
|
49
|
+
};
|
|
50
|
+
const isInteractive = () => process.stdin.isTTY === true;
|
|
51
|
+
const lineConflict = (source, line, resolvedLine) => new Error(lang_1.lang.__('SAAS_LINE_CONFLICT', { source, line, resolvedLine }));
|
|
52
|
+
/** Prompt among stored profiles; returns the chosen key or null to abort. */
|
|
53
|
+
const promptProfile = async (profileKeys, operation) => {
|
|
54
|
+
logger_1.logger.info(lang_1.lang.__('SAAS_LINE_PROMPT_HEADER', { operation: operation ?? 'this command' }));
|
|
55
|
+
profileKeys.forEach((key, index) => {
|
|
56
|
+
logger_1.logger.info(lang_1.lang.__('SAAS_LINE_PROMPT_OPTION', { index: String(index + 1), profileKey: key }));
|
|
57
|
+
});
|
|
58
|
+
const answer = await readInput(lang_1.lang.__('SAAS_LINE_PROMPT_SELECT', { count: String(profileKeys.length) }));
|
|
59
|
+
const index = Number.parseInt(answer.trim(), 10);
|
|
60
|
+
if (Number.isNaN(index) || index < 1 || index > profileKeys.length) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return profileKeys[index - 1] ?? null;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Key segments pin the line. A line flag disambiguates org slugs, and a
|
|
67
|
+
* legacy key can use the transition hint before looking up stored profiles.
|
|
68
|
+
* A stored profile supplies identity only when it owns the effective key.
|
|
69
|
+
*/
|
|
70
|
+
const resolveLineContext = async (params) => {
|
|
71
|
+
const file = (0, credentialStore_1.loadCredentialsFile)();
|
|
72
|
+
const profiles = file?.profiles ?? {};
|
|
73
|
+
const activeKey = file?.active;
|
|
74
|
+
const active = activeKey ? (0, consoleLines_1.splitProfileKey)(activeKey) : null;
|
|
75
|
+
const targetSlug = params.declaredOrg ?? params.orgFlag;
|
|
76
|
+
const explicitKey = params.siApiKey ?? process.env.SI_API_KEY;
|
|
77
|
+
const keySource = params.siApiKey !== undefined ? 'flag' : explicitKey !== undefined ? 'env' : 'profile';
|
|
78
|
+
const keyLine = explicitKey ? (0, consoleLines_1.parseApiKeyLine)(explicitKey) : null;
|
|
79
|
+
const flagLine = (0, consoleLines_1.assertLineFlag)(params.lineFlag);
|
|
80
|
+
if (keyLine && flagLine && keyLine !== flagLine) {
|
|
81
|
+
throw lineConflict('the API key', keyLine, flagLine);
|
|
82
|
+
}
|
|
83
|
+
const legacyLine = explicitKey && !keyLine && !flagLine ? (0, consoleLines_1.normalizeLineName)(process.env.SI_CONSOLE_LINE) : null;
|
|
84
|
+
if (legacyLine) {
|
|
85
|
+
logger_1.logger.warn(lang_1.lang.__('SAAS_LINE_ENV_DEPRECATED'));
|
|
86
|
+
}
|
|
87
|
+
let line = keyLine ?? flagLine ?? legacyLine;
|
|
88
|
+
let lineSource = keyLine
|
|
89
|
+
? 'key-segment'
|
|
90
|
+
: flagLine
|
|
91
|
+
? 'flag'
|
|
92
|
+
: 'env-legacy';
|
|
93
|
+
let profileKey;
|
|
94
|
+
if (targetSlug) {
|
|
95
|
+
const matches = (0, credentialStore_1.findProfilesBySlug)({ profiles }, targetSlug);
|
|
96
|
+
if (line) {
|
|
97
|
+
profileKey = matches.find((key) => (0, consoleLines_1.splitProfileKey)(key)?.line === line);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
const lines = [...new Set(matches.map((key) => (0, consoleLines_1.splitProfileKey)(key).line))];
|
|
101
|
+
if (lines.length > 1) {
|
|
102
|
+
throw new Error(lang_1.lang.__('SAAS_LINE_AMBIGUOUS_ORG', { org: targetSlug, lines: lines.join(', ') }));
|
|
103
|
+
}
|
|
104
|
+
if (lines[0]) {
|
|
105
|
+
line = lines[0];
|
|
106
|
+
lineSource = params.declaredOrg ? 'yml-org' : 'flag';
|
|
107
|
+
profileKey = matches[0];
|
|
108
|
+
}
|
|
109
|
+
else if (explicitKey === undefined) {
|
|
110
|
+
const saved = Object.values(profiles);
|
|
111
|
+
if (saved.length === 1)
|
|
112
|
+
(0, consoleLines_1.assertOrgMatches)(targetSlug, saved[0]?.orgSlug);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (!line && active) {
|
|
117
|
+
line = active.line;
|
|
118
|
+
lineSource = 'active';
|
|
119
|
+
}
|
|
120
|
+
if (!line && isInteractive()) {
|
|
121
|
+
const candidates = Object.keys(profiles).filter((key) => (0, consoleLines_1.splitProfileKey)(key) && (!targetSlug || !profiles[key]?.orgSlug));
|
|
122
|
+
const chosen = candidates.length > 0 ? await promptProfile(candidates, params.operation) : null;
|
|
123
|
+
if (chosen) {
|
|
124
|
+
profileKey = chosen;
|
|
125
|
+
line = (0, consoleLines_1.splitProfileKey)(chosen).line;
|
|
126
|
+
lineSource = 'prompt';
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
if (!line) {
|
|
130
|
+
throw new Error(lang_1.lang.__('SAAS_LINE_UNRESOLVED', { operation: params.operation ?? 'this command' }));
|
|
131
|
+
}
|
|
132
|
+
if (!profileKey && !targetSlug && active && activeKey) {
|
|
133
|
+
if (active.line === line) {
|
|
134
|
+
profileKey = activeKey;
|
|
135
|
+
}
|
|
136
|
+
else if (keyLine) {
|
|
137
|
+
profileKey = (0, consoleLines_1.toProfileKey)(line, active.orgSlug);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// A legacy active profile has no verified slug until the first validate call.
|
|
141
|
+
if (!profileKey && activeKey && active?.line === line && !profiles[activeKey]?.orgSlug) {
|
|
142
|
+
profileKey = activeKey;
|
|
143
|
+
}
|
|
144
|
+
const profile = profileKey ? profiles[profileKey] : undefined;
|
|
145
|
+
const apiKey = explicitKey ?? profile?.apiKey;
|
|
146
|
+
if (!apiKey) {
|
|
147
|
+
throw new Error(lang_1.lang.__('SAAS_BACKEND_NO_CREDENTIALS'));
|
|
148
|
+
}
|
|
149
|
+
const identity = profile?.apiKey === apiKey ? profile : undefined;
|
|
150
|
+
(0, consoleLines_1.assertOrgMatches)(targetSlug, identity?.orgSlug);
|
|
151
|
+
return {
|
|
152
|
+
line,
|
|
153
|
+
consoleUrl: (0, consoleLines_1.consoleOriginFor)(line),
|
|
154
|
+
apiKey,
|
|
155
|
+
...(identity?.orgId ? { orgId: identity.orgId } : {}),
|
|
156
|
+
...(identity?.orgSlug ? { orgSlug: identity.orgSlug } : {}),
|
|
157
|
+
...(identity?.orgName ? { orgName: identity.orgName } : {}),
|
|
158
|
+
...(identity?.userEmail ? { userEmail: identity.userEmail } : {}),
|
|
159
|
+
...(identity ? { profileKey } : {}),
|
|
160
|
+
keySource,
|
|
161
|
+
lineSource,
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
exports.resolveLineContext = resolveLineContext;
|
|
@@ -34,40 +34,32 @@ const UPDATE_FIELDS = {
|
|
|
34
34
|
'logConfig',
|
|
35
35
|
'logEnabled',
|
|
36
36
|
'http',
|
|
37
|
-
'
|
|
37
|
+
'domains',
|
|
38
38
|
'timers',
|
|
39
39
|
],
|
|
40
|
+
// v1 (issue #279): domain bindings live in the `domains` list and are
|
|
41
|
+
// reconciled per binding by the executors (add/remove/update in place).
|
|
42
|
+
// `accelerate` is enable-only via update — disabling still requires
|
|
43
|
+
// destroy+recreate and fails at execution.
|
|
40
44
|
ALIYUN_OSS_BUCKET: [
|
|
41
45
|
'acl',
|
|
42
46
|
'websiteConfiguration',
|
|
43
47
|
'websiteCodeHash',
|
|
44
|
-
'
|
|
45
|
-
'
|
|
46
|
-
'domainCertificateId',
|
|
47
|
-
'domainCertificateBody',
|
|
48
|
-
'domainCertificatePrivateKey',
|
|
49
|
-
'domainProtocol',
|
|
48
|
+
'domains',
|
|
49
|
+
'accelerate',
|
|
50
50
|
'policy',
|
|
51
|
-
'cdnType',
|
|
52
|
-
'cdnScope',
|
|
53
|
-
'cdnCacheTtl',
|
|
54
|
-
'cdnIgnoreQueryString',
|
|
55
|
-
'cdnOriginProtocol',
|
|
56
|
-
'cdnCompression',
|
|
57
|
-
'cdnForceRedirectHttps',
|
|
58
51
|
],
|
|
59
|
-
COS_BUCKET: [
|
|
52
|
+
COS_BUCKET: ['acl', 'websiteConfiguration', 'domains', 'policy'],
|
|
53
|
+
// issue #294: domain bindings are reconciled per binding by the executor;
|
|
54
|
+
// `accelerate` is enable-only via update (disable fails at execution).
|
|
55
|
+
VOLCENGINE_TOS_BUCKET: [
|
|
60
56
|
'acl',
|
|
61
57
|
'websiteConfiguration',
|
|
62
|
-
'
|
|
63
|
-
'
|
|
64
|
-
'
|
|
65
|
-
'domainCertificateBody',
|
|
66
|
-
'domainCertificatePrivateKey',
|
|
67
|
-
'domainProtocol',
|
|
58
|
+
'websiteCodeHash',
|
|
59
|
+
'domains',
|
|
60
|
+
'accelerate',
|
|
68
61
|
'policy',
|
|
69
62
|
],
|
|
70
|
-
VOLCENGINE_TOS_BUCKET: ['acl', 'websiteConfiguration', 'websiteCodeHash', 'policy'],
|
|
71
63
|
};
|
|
72
64
|
const IDENTITY_FIELDS = {
|
|
73
65
|
ALIYUN_FC3: ['functionName'],
|
|
@@ -102,11 +94,6 @@ const assertSupportedPlanUpdate = (logicalId, resourceType, before, desired) =>
|
|
|
102
94
|
throw new Error(lang_1.lang.__('PLAN_UPDATE_NOT_SUPPORTED', { logicalId, fields: 'nasStorage.storage_class' }));
|
|
103
95
|
}
|
|
104
96
|
}
|
|
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
97
|
const supported = UPDATE_FIELDS[resourceType];
|
|
111
98
|
if (!supported)
|
|
112
99
|
return;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mergeManagedIntent = exports.computeRevertKeys = exports.mergeLiveBefore = exports.jsonDocumentDiffers = exports.remoteDiffersFromDesired = exports.definitionsDiffer = exports.managedDefinition = void 0;
|
|
3
|
+
exports.mergeManagedIntent = exports.computeRevertKeys = exports.mergeLiveBefore = exports.jsonDocumentDiffers = exports.remoteDiffersFromDesired = exports.definitionsDiffer = exports.managedDefinition = exports.canonicalValue = void 0;
|
|
4
4
|
const hashUtils_1 = require("./hashUtils");
|
|
5
5
|
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
6
6
|
const isDeclared = (value) => value !== undefined && value !== null && (!isRecord(value) || Object.keys(value).length > 0);
|
|
@@ -29,14 +29,14 @@ const canonicalValue = (value, key, policyDocument = false) => {
|
|
|
29
29
|
return 'null';
|
|
30
30
|
if (key === 'policy' && typeof value === 'string') {
|
|
31
31
|
try {
|
|
32
|
-
return canonicalValue(JSON.parse(value), '', true);
|
|
32
|
+
return (0, exports.canonicalValue)(JSON.parse(value), '', true);
|
|
33
33
|
}
|
|
34
34
|
catch {
|
|
35
35
|
return value;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
if (Array.isArray(value)) {
|
|
39
|
-
const entries = value.map((entry) => canonicalValue(entry, '', policyScope));
|
|
39
|
+
const entries = value.map((entry) => (0, exports.canonicalValue)(entry, '', policyScope));
|
|
40
40
|
return policyScope || SET_FIELDS.has(key)
|
|
41
41
|
? [
|
|
42
42
|
...new Map(entries.map((entry) => [JSON.stringify(entry) ?? 'null', entry])).values(),
|
|
@@ -46,15 +46,16 @@ const canonicalValue = (value, key, policyDocument = false) => {
|
|
|
46
46
|
if (isRecord(value)) {
|
|
47
47
|
return Object.fromEntries(Object.entries(value)
|
|
48
48
|
.sort(([a], [b]) => a.localeCompare(b))
|
|
49
|
-
.map(([name, entry]) => [name, canonicalValue(entry, name, policyScope)]));
|
|
49
|
+
.map(([name, entry]) => [name, (0, exports.canonicalValue)(entry, name, policyScope)]));
|
|
50
50
|
}
|
|
51
51
|
return value;
|
|
52
52
|
};
|
|
53
|
+
exports.canonicalValue = canonicalValue;
|
|
53
54
|
const projectValue = (actual, desired, key) => {
|
|
54
55
|
if (key === 'policy')
|
|
55
|
-
return canonicalValue(actual, key);
|
|
56
|
+
return (0, exports.canonicalValue)(actual, key);
|
|
56
57
|
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
|
+
return actual.map((entry, index) => index < desired.length ? projectValue(entry, desired[index], '') : (0, exports.canonicalValue)(entry, ''));
|
|
58
59
|
}
|
|
59
60
|
// An environment declaration replaces the entire map, including removal of
|
|
60
61
|
// cloud-only entries. Structural configs write only their declared members.
|
|
@@ -63,7 +64,7 @@ const projectValue = (actual, desired, key) => {
|
|
|
63
64
|
.filter(([, value]) => isDeclared(value))
|
|
64
65
|
.map(([name, value]) => [name, projectValue(actual[name], value, name)]));
|
|
65
66
|
}
|
|
66
|
-
return canonicalValue(actual, key);
|
|
67
|
+
return (0, exports.canonicalValue)(actual, key);
|
|
67
68
|
};
|
|
68
69
|
/** The fields the current configuration actually manages, in comparison form. */
|
|
69
70
|
const managedDefinition = (actual, desired = actual) => Object.fromEntries(Object.entries(desired)
|
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.displayPlan = exports.formatPlan = exports.formatPlanItem = exports.isRecreate = exports.computeAttributeDiffs = void 0;
|
|
4
4
|
const planRedaction_1 = require("./planRedaction");
|
|
5
5
|
const hashUtils_1 = require("./hashUtils");
|
|
6
|
+
const planCompare_1 = require("./planCompare");
|
|
6
7
|
const lang_1 = require("../lang");
|
|
7
8
|
const logger_1 = require("./logger");
|
|
8
9
|
const noColor_1 = require("./noColor");
|
|
@@ -38,6 +39,39 @@ const isSimpleObject = (val) => {
|
|
|
38
39
|
const obj = val;
|
|
39
40
|
return Object.values(obj).every((v) => typeof v !== 'object' || v === null);
|
|
40
41
|
};
|
|
42
|
+
const hasObjectEntry = (value) => Array.isArray(value) && value.some((entry) => isObject(entry));
|
|
43
|
+
const diffArrayEntries = (before, after) => {
|
|
44
|
+
const keyOf = (entry) => JSON.stringify((0, planCompare_1.canonicalValue)(entry, ''));
|
|
45
|
+
const tally = (keys) => keys.reduce((counts, key) => new Map(counts).set(key, (counts.get(key) ?? 0) + 1), new Map());
|
|
46
|
+
const unmatched = (entries, counterpart) => entries.filter((entry) => {
|
|
47
|
+
const key = keyOf(entry);
|
|
48
|
+
const available = counterpart.get(key) ?? 0;
|
|
49
|
+
if (available <= 0)
|
|
50
|
+
return true;
|
|
51
|
+
counterpart.set(key, available - 1);
|
|
52
|
+
return false;
|
|
53
|
+
});
|
|
54
|
+
return [
|
|
55
|
+
...unmatched(before, tally(after.map(keyOf))).map((entry) => ({
|
|
56
|
+
key: '',
|
|
57
|
+
before: entry,
|
|
58
|
+
action: 'remove',
|
|
59
|
+
isComputed: false,
|
|
60
|
+
})),
|
|
61
|
+
...unmatched(after, tally(before.map(keyOf))).map((entry) => ({
|
|
62
|
+
key: '',
|
|
63
|
+
after: entry,
|
|
64
|
+
action: 'add',
|
|
65
|
+
isComputed: false,
|
|
66
|
+
})),
|
|
67
|
+
];
|
|
68
|
+
};
|
|
69
|
+
const entryArrayChildren = (before, after) => {
|
|
70
|
+
if (!hasObjectEntry(before) && !hasObjectEntry(after))
|
|
71
|
+
return undefined;
|
|
72
|
+
const children = diffArrayEntries(Array.isArray(before) ? before : [], Array.isArray(after) ? after : []);
|
|
73
|
+
return children.length > 0 ? children : undefined;
|
|
74
|
+
};
|
|
41
75
|
/* istanbul ignore next */
|
|
42
76
|
const computeAttributeDiffs = (before, after) => {
|
|
43
77
|
if (!before && !after)
|
|
@@ -50,9 +84,10 @@ const computeAttributeDiffs = (before, after) => {
|
|
|
50
84
|
after: value,
|
|
51
85
|
action: 'add',
|
|
52
86
|
isComputed: COMPUTED_ATTRIBUTES.has(key),
|
|
53
|
-
children:
|
|
54
|
-
|
|
55
|
-
|
|
87
|
+
children: entryArrayChildren(undefined, value) ??
|
|
88
|
+
(isObject(value) && !isSimpleObject(value)
|
|
89
|
+
? (0, exports.computeAttributeDiffs)(undefined, value).diffs
|
|
90
|
+
: undefined),
|
|
56
91
|
}))
|
|
57
92
|
.sort((a, b) => a.key.localeCompare(b.key)),
|
|
58
93
|
unchangedCount: 0,
|
|
@@ -66,9 +101,10 @@ const computeAttributeDiffs = (before, after) => {
|
|
|
66
101
|
before: value,
|
|
67
102
|
action: 'remove',
|
|
68
103
|
isComputed: COMPUTED_ATTRIBUTES.has(key),
|
|
69
|
-
children:
|
|
70
|
-
|
|
71
|
-
|
|
104
|
+
children: entryArrayChildren(value, undefined) ??
|
|
105
|
+
(isObject(value) && !isSimpleObject(value)
|
|
106
|
+
? (0, exports.computeAttributeDiffs)(value, undefined).diffs
|
|
107
|
+
: undefined),
|
|
72
108
|
}))
|
|
73
109
|
.sort((a, b) => a.key.localeCompare(b.key)),
|
|
74
110
|
unchangedCount: 0,
|
|
@@ -105,9 +141,10 @@ const computeAttributeDiffs = (before, after) => {
|
|
|
105
141
|
before: oldVal,
|
|
106
142
|
after: newVal,
|
|
107
143
|
action: 'change',
|
|
108
|
-
children:
|
|
109
|
-
|
|
110
|
-
|
|
144
|
+
children: entryArrayChildren(oldVal, newVal) ??
|
|
145
|
+
(bothObjects
|
|
146
|
+
? (0, exports.computeAttributeDiffs)(oldVal, newVal).diffs
|
|
147
|
+
: undefined),
|
|
111
148
|
};
|
|
112
149
|
});
|
|
113
150
|
const diffs = [...addDiffs, ...removeDiffs, ...changeDiffs].sort((a, b) => a.key.localeCompare(b.key));
|
|
@@ -144,59 +181,56 @@ const computeMaxKeyWidth = (diffs, baseIndent) => diffs.reduce((maxWidth, diff)
|
|
|
144
181
|
}, 0);
|
|
145
182
|
const formatAttributeLines = (diff, indent, config, keyWidth, revertKeys, parentPath = '', inheritedRevert = false) => {
|
|
146
183
|
const spaces = ' '.repeat(indent);
|
|
147
|
-
const alignedKey =
|
|
184
|
+
const alignedKey = `${diff.key}:`.padEnd(keyWidth);
|
|
148
185
|
const fieldPath = parentPath ? `${parentPath}.${diff.key}` : diff.key;
|
|
149
186
|
const reverted = inheritedRevert || revertKeys?.has(fieldPath);
|
|
150
187
|
const marker = { add: '+', remove: '-', change: '~' }[diff.action];
|
|
151
188
|
// Issue #246: a field whose stored value already matched the config while
|
|
152
189
|
// the cloud diverged is annotated at the line level — the resource block
|
|
153
|
-
// stays in place, only this line explains why it appears.
|
|
154
|
-
// reach suffix (parent cases early-return on children), so a revert key
|
|
155
|
-
// with nested children never carries the annotation.
|
|
190
|
+
// stays in place, only this line explains why it appears.
|
|
156
191
|
const suffix = (line) => reverted
|
|
157
192
|
? `${line} ${colorize(lang_1.lang.__('PLAN_REVERT_ANNOTATION'), 'CYAN', config.colorize)}`
|
|
158
193
|
: line;
|
|
194
|
+
const leafLine = (value) => diff.key ? `${spaces}${marker} ${alignedKey} ${value}` : `${spaces}${marker} ${value}`;
|
|
195
|
+
const entrySummary = (children) => {
|
|
196
|
+
const entries = children.filter((child) => child.key === '');
|
|
197
|
+
if (!diff.key || entries.length === 0)
|
|
198
|
+
return '';
|
|
199
|
+
const added = entries.filter((child) => child.action === 'add').length;
|
|
200
|
+
const removed = entries.filter((child) => child.action === 'remove').length;
|
|
201
|
+
return ` ${lang_1.lang.__('PLAN_ARRAY_ENTRY_SUMMARY', { added: String(added), removed: String(removed) })}`;
|
|
202
|
+
};
|
|
203
|
+
const childLines = (children) => {
|
|
204
|
+
const childKeyWidth = computeMaxKeyWidth(children, indent);
|
|
205
|
+
return children.flatMap((child) => formatAttributeLines(child, indent + config.indentSize, config, childKeyWidth, revertKeys, fieldPath, child.key === '' ? false : reverted));
|
|
206
|
+
};
|
|
207
|
+
const parentWithChildren = (children, color) => [
|
|
208
|
+
suffix(colorize(`${spaces}${marker} ${alignedKey}${entrySummary(children)}`, color, config.colorize)),
|
|
209
|
+
...childLines(children),
|
|
210
|
+
];
|
|
159
211
|
switch (diff.action) {
|
|
160
212
|
case 'add': {
|
|
161
213
|
if (diff.children && diff.children.length > 0) {
|
|
162
|
-
|
|
163
|
-
return [
|
|
164
|
-
colorize(`${spaces}${marker} ${alignedKey}`, 'GREEN', config.colorize),
|
|
165
|
-
...diff.children.flatMap((child) => formatAttributeLines(child, indent + config.indentSize, config, childKeyWidth, revertKeys, fieldPath, reverted)),
|
|
166
|
-
];
|
|
214
|
+
return parentWithChildren(diff.children, 'GREEN');
|
|
167
215
|
}
|
|
168
216
|
const value = diff.isComputed
|
|
169
217
|
? colorize(lang_1.lang.__('PLAN_COMPUTED_VALUE'), 'CYAN', config.colorize)
|
|
170
218
|
: formatValue(diff.after);
|
|
171
|
-
return [
|
|
172
|
-
suffix(colorize(`${spaces}${marker} ${alignedKey} ${value}`, 'GREEN', config.colorize)),
|
|
173
|
-
];
|
|
219
|
+
return [suffix(colorize(leafLine(value), 'GREEN', config.colorize))];
|
|
174
220
|
}
|
|
175
221
|
case 'remove': {
|
|
176
222
|
if (diff.children && diff.children.length > 0) {
|
|
177
|
-
|
|
178
|
-
return [
|
|
179
|
-
colorize(`${spaces}${marker} ${alignedKey}`, 'RED', config.colorize),
|
|
180
|
-
...diff.children.flatMap((child) => formatAttributeLines(child, indent + config.indentSize, config, childKeyWidth, revertKeys, fieldPath, reverted)),
|
|
181
|
-
];
|
|
223
|
+
return parentWithChildren(diff.children, 'RED');
|
|
182
224
|
}
|
|
183
|
-
return [
|
|
184
|
-
suffix(colorize(`${spaces}${marker} ${alignedKey} ${formatValue(diff.before)}`, 'RED', config.colorize)),
|
|
185
|
-
];
|
|
225
|
+
return [suffix(colorize(leafLine(formatValue(diff.before)), 'RED', config.colorize))];
|
|
186
226
|
}
|
|
187
227
|
case 'change': {
|
|
188
228
|
if (diff.children && diff.children.length > 0) {
|
|
189
|
-
|
|
190
|
-
return [
|
|
191
|
-
colorize(`${spaces}${marker} ${alignedKey}`, 'YELLOW', config.colorize),
|
|
192
|
-
...diff.children.flatMap((child) => formatAttributeLines(child, indent + config.indentSize, config, childKeyWidth, revertKeys, fieldPath, reverted)),
|
|
193
|
-
];
|
|
229
|
+
return parentWithChildren(diff.children, 'YELLOW');
|
|
194
230
|
}
|
|
195
231
|
const beforeStr = formatValue(diff.before);
|
|
196
232
|
const afterStr = formatValue(diff.after);
|
|
197
|
-
return [
|
|
198
|
-
suffix(colorize(`${spaces}${marker} ${alignedKey} ${beforeStr} -> ${afterStr}`, 'YELLOW', config.colorize)),
|
|
199
|
-
];
|
|
233
|
+
return [suffix(colorize(leafLine(`${beforeStr} -> ${afterStr}`), 'YELLOW', config.colorize))];
|
|
200
234
|
}
|
|
201
235
|
}
|
|
202
236
|
};
|
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createCosStateBackend = exports.createCosStorageAdapter = void 0;
|
|
7
7
|
const cos_nodejs_sdk_v5_1 = __importDefault(require("cos-nodejs-sdk-v5"));
|
|
8
|
-
const types_1 = require("./types");
|
|
9
8
|
const remoteStateBackend_1 = require("./remoteStateBackend");
|
|
10
9
|
const constants_1 = require("../constants");
|
|
11
10
|
const lang_1 = require("../../lang");
|
|
@@ -43,36 +42,6 @@ const promisifyPut = (cosClient, bucket, region, key, body) => {
|
|
|
43
42
|
});
|
|
44
43
|
});
|
|
45
44
|
};
|
|
46
|
-
const promisifyPutIfAbsent = (cosClient, bucket, region, key, body) => {
|
|
47
|
-
return new Promise((resolve, reject) => {
|
|
48
|
-
cosClient.putObject({
|
|
49
|
-
Bucket: bucket,
|
|
50
|
-
Region: region,
|
|
51
|
-
Key: key,
|
|
52
|
-
Body: body,
|
|
53
|
-
Headers: { 'x-cos-forbid-overwrite': 'true' },
|
|
54
|
-
}, (err) => {
|
|
55
|
-
if (err) {
|
|
56
|
-
const code = err.code ?? '';
|
|
57
|
-
if (err.statusCode === 412 ||
|
|
58
|
-
code === 'PreconditionFailed' ||
|
|
59
|
-
code === 'KeyConflict' ||
|
|
60
|
-
err.statusCode === 409) {
|
|
61
|
-
resolve(false);
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (err.statusCode === 400 || err.statusCode === 501) {
|
|
65
|
-
reject(new types_1.ConditionalPutUnsupportedError(err));
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
reject(err);
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
resolve(true);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
45
|
const promisifyDelete = (cosClient, bucket, region, key) => {
|
|
77
46
|
return new Promise((resolve, reject) => {
|
|
78
47
|
cosClient.deleteObject({ Bucket: bucket, Region: region, Key: key }, (err) => {
|
|
@@ -114,21 +83,6 @@ const createCosStorageAdapter = (config) => {
|
|
|
114
83
|
write: async (key, data) => {
|
|
115
84
|
await promisifyPut(cosClient, config.bucket, config.region, key, JSON.stringify(data, null, 2));
|
|
116
85
|
},
|
|
117
|
-
/** COS only honors forbid-overwrite on buckets that never enabled versioning. */
|
|
118
|
-
putIfAbsent: async (key, data) => {
|
|
119
|
-
const versioning = await new Promise((resolve, reject) => {
|
|
120
|
-
cosClient.getBucketVersioning({ Bucket: config.bucket, Region: config.region }, (error, data) => {
|
|
121
|
-
if (error)
|
|
122
|
-
reject(error);
|
|
123
|
-
else
|
|
124
|
-
resolve(data);
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
if (versioning.VersioningConfiguration.Status) {
|
|
128
|
-
throw new types_1.ConditionalPutUnsupportedError('bucket versioning disables exclusive creation');
|
|
129
|
-
}
|
|
130
|
-
return promisifyPutIfAbsent(cosClient, config.bucket, config.region, key, JSON.stringify(data, null, 2));
|
|
131
|
-
},
|
|
132
86
|
delete: async (key) => {
|
|
133
87
|
await promisifyDelete(cosClient, config.bucket, config.region, key);
|
|
134
88
|
},
|
|
@@ -21,6 +21,7 @@ const lang_1 = require("../../lang");
|
|
|
21
21
|
const localStateBackend_1 = require("./localStateBackend");
|
|
22
22
|
const ossStateBackend_1 = require("./ossStateBackend");
|
|
23
23
|
const cosStateBackend_1 = require("./cosStateBackend");
|
|
24
|
+
const tosStateBackend_1 = require("./tosStateBackend");
|
|
24
25
|
const saasStateBackend_1 = require("./saasStateBackend");
|
|
25
26
|
const stateScope_1 = require("../stateScope");
|
|
26
27
|
const credentials_1 = require("../credentials");
|
|
@@ -28,10 +29,11 @@ __exportStar(require("./types"), exports);
|
|
|
28
29
|
__exportStar(require("./localStateBackend"), exports);
|
|
29
30
|
__exportStar(require("./ossStateBackend"), exports);
|
|
30
31
|
__exportStar(require("./cosStateBackend"), exports);
|
|
32
|
+
__exportStar(require("./tosStateBackend"), exports);
|
|
31
33
|
__exportStar(require("./remoteStateBackend"), exports);
|
|
32
34
|
__exportStar(require("./saasStateBackend"), exports);
|
|
33
35
|
__exportStar(require("./lockUtils"), exports);
|
|
34
|
-
const createStateBackend = (backendConfig, context) => {
|
|
36
|
+
const createStateBackend = async (backendConfig, context) => {
|
|
35
37
|
const scope = {
|
|
36
38
|
provider: context.provider,
|
|
37
39
|
app: context.app,
|
|
@@ -39,12 +41,18 @@ const createStateBackend = (backendConfig, context) => {
|
|
|
39
41
|
stage: context.stage,
|
|
40
42
|
region: context.region,
|
|
41
43
|
};
|
|
42
|
-
// SaaS (default) — requires API key
|
|
44
|
+
// SaaS (default) — requires API key; line/key/org resolution happens inside
|
|
45
|
+
// (ADR-008), so this awaits the async SaaS factory.
|
|
43
46
|
if (!backendConfig || backendConfig.type === types_1.StateBackendType.SAAS) {
|
|
44
|
-
return (0, saasStateBackend_1.createSaasStateBackend)({
|
|
47
|
+
return await (0, saasStateBackend_1.createSaasStateBackend)({
|
|
45
48
|
scope,
|
|
46
49
|
declaredOrg: context.declaredOrg,
|
|
47
|
-
}, {
|
|
50
|
+
}, {
|
|
51
|
+
apiKey: context.siApiKey,
|
|
52
|
+
mode: context.mode,
|
|
53
|
+
...(context.org ? { org: context.org } : {}),
|
|
54
|
+
...(context.line ? { line: context.line } : {}),
|
|
55
|
+
});
|
|
48
56
|
}
|
|
49
57
|
if (backendConfig.type === types_1.StateBackendType.LOCAL) {
|
|
50
58
|
return (0, localStateBackend_1.createLocalStateBackend)(scope, {
|
|
@@ -54,28 +62,28 @@ const createStateBackend = (backendConfig, context) => {
|
|
|
54
62
|
}
|
|
55
63
|
const bucketConfig = backendConfig;
|
|
56
64
|
const storage = (0, exports.resolveStateStorage)(bucketConfig, context);
|
|
57
|
-
|
|
58
|
-
return (0, cosStateBackend_1.createCosStateBackend)({
|
|
59
|
-
scope,
|
|
60
|
-
bucket: bucketConfig.bucket,
|
|
61
|
-
key: bucketConfig.key,
|
|
62
|
-
...storage,
|
|
63
|
-
markerAction: context.migrationMarker,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
return (0, ossStateBackend_1.createOssStateBackend)({
|
|
65
|
+
const bucketBackendConfig = {
|
|
67
66
|
scope,
|
|
68
67
|
bucket: bucketConfig.bucket,
|
|
69
68
|
key: bucketConfig.key,
|
|
70
69
|
...storage,
|
|
71
70
|
markerAction: context.migrationMarker,
|
|
72
|
-
}
|
|
71
|
+
};
|
|
72
|
+
if (storage.provider === providerEnum_1.ProviderEnum.TENCENT)
|
|
73
|
+
return (0, cosStateBackend_1.createCosStateBackend)(bucketBackendConfig);
|
|
74
|
+
if (storage.provider === providerEnum_1.ProviderEnum.VOLCENGINE)
|
|
75
|
+
return (0, tosStateBackend_1.createTosStateBackend)(bucketBackendConfig);
|
|
76
|
+
if (storage.provider === providerEnum_1.ProviderEnum.ALIYUN)
|
|
77
|
+
return (0, ossStateBackend_1.createOssStateBackend)(bucketBackendConfig);
|
|
78
|
+
throw new Error(lang_1.lang.__('STATE_STORAGE_PROVIDER_UNSUPPORTED', { provider: storage.provider }));
|
|
73
79
|
};
|
|
74
80
|
exports.createStateBackend = createStateBackend;
|
|
75
81
|
const resolveStateStorage = (bucketConfig, context) => {
|
|
76
82
|
const provider = bucketConfig.storageProvider ?? context.storage?.provider ?? context.provider;
|
|
77
83
|
const region = (0, stateScope_1.canonicalizeRegion)(bucketConfig.storageRegion ?? context.storage?.region ?? context.region);
|
|
78
|
-
if (provider !== providerEnum_1.ProviderEnum.ALIYUN &&
|
|
84
|
+
if (provider !== providerEnum_1.ProviderEnum.ALIYUN &&
|
|
85
|
+
provider !== providerEnum_1.ProviderEnum.TENCENT &&
|
|
86
|
+
provider !== providerEnum_1.ProviderEnum.VOLCENGINE) {
|
|
79
87
|
throw new Error(lang_1.lang.__('STATE_STORAGE_PROVIDER_UNSUPPORTED', { provider }));
|
|
80
88
|
}
|
|
81
89
|
const credentials = (0, credentials_1.getCredentials)(provider === context.provider ? context : undefined, provider);
|
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.createOssStateBackend = exports.createOssStorageAdapter = void 0;
|
|
7
7
|
const ali_oss_1 = __importDefault(require("ali-oss"));
|
|
8
|
-
const types_1 = require("./types");
|
|
9
8
|
const remoteStateBackend_1 = require("./remoteStateBackend");
|
|
10
9
|
const constants_1 = require("../constants");
|
|
11
10
|
const lang_1 = require("../../lang");
|
|
@@ -55,30 +54,6 @@ const createOssStorageAdapter = (config) => {
|
|
|
55
54
|
const content = JSON.stringify(data, null, 2);
|
|
56
55
|
await ossClient.put(key, Buffer.from(content, 'utf-8'));
|
|
57
56
|
},
|
|
58
|
-
putIfAbsent: async (key, data) => {
|
|
59
|
-
const content = JSON.stringify(data, null, 2);
|
|
60
|
-
const versioning = await ossClient.getBucketVersioning(config.bucket);
|
|
61
|
-
if (versioning.versionStatus && versioning.versionStatus !== 'Disabled') {
|
|
62
|
-
throw new types_1.ConditionalPutUnsupportedError('bucket versioning disables exclusive creation');
|
|
63
|
-
}
|
|
64
|
-
try {
|
|
65
|
-
await ossClient.put(key, Buffer.from(content, 'utf-8'), {
|
|
66
|
-
headers: { 'x-oss-forbid-overwrite': 'true' },
|
|
67
|
-
});
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
catch (err) {
|
|
71
|
-
if (err && typeof err === 'object' && 'code' in err) {
|
|
72
|
-
const code = err.code;
|
|
73
|
-
if (code === 'FileAlreadyExists' ||
|
|
74
|
-
code === 'EtagMismatch' ||
|
|
75
|
-
code === 'PreconditionFailed') {
|
|
76
|
-
return false;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
throw err;
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
57
|
delete: async (key) => {
|
|
83
58
|
try {
|
|
84
59
|
await ossClient.delete(key);
|