@geek-fun/serverlessinsight 0.9.3 → 0.9.5
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 +5 -2
- package/CHANGELOG.md +56 -0
- package/README.md +266 -179
- package/README.zh-CN.md +264 -147
- package/codecov +0 -0
- package/codecov.SHA256SUM +1 -1
- package/codecov.SHA256SUM.sig +13 -13
- package/dist/package.json +22 -19
- package/dist/src/commands/deploy.js +7 -2
- package/dist/src/commands/destroy.js +6 -3
- package/dist/src/commands/forceUnlock.js +16 -21
- package/dist/src/commands/index.js +26 -63
- package/dist/src/commands/migrate.js +105 -132
- package/dist/src/commands/plan.js +27 -3
- package/dist/src/commands/show.js +17 -6
- package/dist/src/common/aggregateState.js +185 -0
- package/dist/src/common/aggregateStore.js +247 -0
- package/dist/src/common/aliyunClient/apigwOperations.js +32 -9
- package/dist/src/common/apiClient.js +35 -12
- package/dist/src/common/constants.js +2 -1
- package/dist/src/common/context.js +22 -15
- package/dist/src/common/effectiveConfig.js +48 -0
- package/dist/src/common/index.js +5 -0
- package/dist/src/common/jsonOutput.js +2 -13
- package/dist/src/common/migrationMarker.js +0 -7
- package/dist/src/common/nameBuilder.js +2 -3
- package/dist/src/common/regionalMigration.js +261 -0
- package/dist/src/common/saasProtocol.js +41 -0
- package/dist/src/common/stateBackend/cosStateBackend.js +88 -8
- package/dist/src/common/stateBackend/index.js +42 -18
- package/dist/src/common/stateBackend/localStateBackend.js +61 -26
- package/dist/src/common/stateBackend/ossStateBackend.js +62 -9
- package/dist/src/common/stateBackend/remoteStateBackend.js +94 -94
- package/dist/src/common/stateBackend/saasStateBackend.js +327 -92
- package/dist/src/common/stateBackend/types.js +9 -0
- package/dist/src/common/stateManager.js +38 -11
- package/dist/src/common/stateScope.js +34 -0
- package/dist/src/common/stateStorageIO.js +31 -0
- package/dist/src/lang/en.js +48 -6
- package/dist/src/lang/index.js +28 -14
- package/dist/src/lang/zh-CN.js +48 -6
- package/dist/src/parser/index.js +25 -4
- 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 +115 -55
- package/dist/src/stack/aliyunStack/apigwResource.js +169 -124
- package/dist/src/stack/aliyunStack/deployer.js +5 -5
- package/dist/src/stack/aliyunStack/destroyer.js +5 -5
- package/dist/src/stack/aliyunStack/fc3Planner.js +1 -1
- package/dist/src/stack/aliyunStack/fc3Resource.js +2 -2
- package/dist/src/stack/aliyunStack/planner.js +1 -1
- package/dist/src/stack/aliyunStack/sharedLogProject.js +2 -2
- package/dist/src/stack/ownershipTag.js +34 -26
- package/dist/src/stack/scfStack/deployer.js +5 -5
- package/dist/src/stack/scfStack/destroyer.js +5 -6
- package/dist/src/stack/scfStack/planner.js +1 -1
- package/dist/src/stack/scfStack/scfResource.js +1 -1
- package/dist/src/stack/scfStack/sharedLogset.js +5 -2
- package/dist/src/stack/volcengineStack/deployer.js +3 -3
- package/dist/src/stack/volcengineStack/destroyer.js +2 -3
- package/dist/src/stack/volcengineStack/planner.js +1 -1
- package/dist/src/stack/volcengineStack/sharedLogProject.js +4 -4
- package/dist/src/stack/volcengineStack/vefaasResource.js +1 -1
- package/dist/src/types/domains/state.js +28 -2
- package/dist/src/validator/rootSchema.js +8 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +22 -19
- package/release-notes.md +27 -56
- package/samples/README_TENCENT_COS.md +68 -26
- package/samples/README_TENCENT_SCF.md +47 -29
- package/.serverlessinsight/state-cdn-flow-app-cdn-flow-service.json.backup +0 -14
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +0 -32
- package/.serverlessinsight/state-insight-poc-app-insight-poc-tencent.json.backup +0 -90
- package/.serverlessinsight/state-insight-poc-app-log-insight-poc-tencent-log.json.backup +0 -118
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +0 -215
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +0 -14
- package/.serverlessinsight/state-insight-poc-timer-app-insight-poc-timer.json.backup +0 -132
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +0 -55
- package/.serverlessinsight/state-insight-volc-destroy-app-insight-volc-destroy.json.backup +0 -1
- package/.serverlessinsight/state-insight-volc-nested-app-insight-volc-nested.json.backup +0 -93
- package/.serverlessinsight/state-nested-drift-app-nested-drift-service.json.backup +0 -163
- package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +0 -148
|
@@ -86,6 +86,11 @@ const deploy = async (options) => {
|
|
|
86
86
|
siApiKey: options.siApiKey,
|
|
87
87
|
migrationMarker: 'refuse',
|
|
88
88
|
});
|
|
89
|
+
await backend.upgradeLegacyState?.({ bindUnknownRegion: options.bindUnknownRegion });
|
|
90
|
+
const readiness = await backend.probeWriteReadiness();
|
|
91
|
+
if (!readiness.ready) {
|
|
92
|
+
throw new Error(readiness.reason ?? lang_1.lang.__('STATE_WRITE_NOT_READY'));
|
|
93
|
+
}
|
|
89
94
|
// ADR-005: wire the backend's event reporter into the global context so
|
|
90
95
|
// executors can emit per-resource deployment events via context.reportEvent.
|
|
91
96
|
if (backend.reportEvent) {
|
|
@@ -165,7 +170,7 @@ const deploy = async (options) => {
|
|
|
165
170
|
// error; withLock's fail branch forwards them.
|
|
166
171
|
const failure = err;
|
|
167
172
|
try {
|
|
168
|
-
const partialState = await backend.loadState(
|
|
173
|
+
const partialState = await backend.loadState();
|
|
169
174
|
failure.stateJson = partialState ? (0, common_1.toPersistedState)(partialState) : {};
|
|
170
175
|
}
|
|
171
176
|
catch {
|
|
@@ -176,7 +181,7 @@ const deploy = async (options) => {
|
|
|
176
181
|
}
|
|
177
182
|
// Read back the final state so the deployment record can link it
|
|
178
183
|
// (console shows Changes + State JSON from the plan and state).
|
|
179
|
-
const finalState = await backend.loadState(
|
|
184
|
+
const finalState = await backend.loadState();
|
|
180
185
|
const stateJson = finalState ? (0, common_1.toPersistedState)(finalState) : {};
|
|
181
186
|
return {
|
|
182
187
|
plan: { items: planResult.items },
|
|
@@ -33,9 +33,12 @@ const destroyStack = async (options) => {
|
|
|
33
33
|
declaredOrg: iac.org,
|
|
34
34
|
migrationMarker: 'refuse',
|
|
35
35
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
await backend.
|
|
36
|
+
await backend.upgradeLegacyState?.({ bindUnknownRegion: options.bindUnknownRegion });
|
|
37
|
+
await backend.loadState();
|
|
38
|
+
const readiness = await backend.probeWriteReadiness();
|
|
39
|
+
if (!readiness.ready) {
|
|
40
|
+
throw new Error(readiness.reason ?? lang_1.lang.__('STATE_WRITE_NOT_READY'));
|
|
41
|
+
}
|
|
39
42
|
// ADR-005: wire the backend's event reporter into the global context so
|
|
40
43
|
// executors can emit per-resource deployment events via context.reportEvent.
|
|
41
44
|
if (backend.reportEvent) {
|
|
@@ -52,13 +52,23 @@ const forceUnlockCommand = async (lockId, options = {}) => {
|
|
|
52
52
|
else {
|
|
53
53
|
const stateDir = node_path_1.default.join(process.cwd(), '.serverlessinsight');
|
|
54
54
|
let foundStatePath;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const lockContent = node_fs_1.default.readFileSync(node_path_1.default.join(stateDir, lockFiles[0]), 'utf-8');
|
|
59
|
-
const lockMeta = JSON.parse(lockContent);
|
|
60
|
-
foundStatePath = lockMeta.path;
|
|
55
|
+
const findLockFiles = (dir) => {
|
|
56
|
+
if (!node_fs_1.default.existsSync(dir)) {
|
|
57
|
+
return [];
|
|
61
58
|
}
|
|
59
|
+
return node_fs_1.default.readdirSync(dir, { withFileTypes: true }).flatMap((entry) => {
|
|
60
|
+
const full = node_path_1.default.join(dir, entry.name);
|
|
61
|
+
if (entry.isDirectory()) {
|
|
62
|
+
return findLockFiles(full);
|
|
63
|
+
}
|
|
64
|
+
return entry.name.endsWith(constants_1.LOCK_FILE_SUFFIX) ? [full] : [];
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
const lockFiles = findLockFiles(stateDir);
|
|
68
|
+
if (lockFiles.length > 0) {
|
|
69
|
+
const lockContent = node_fs_1.default.readFileSync(lockFiles[0], 'utf-8');
|
|
70
|
+
const lockMeta = JSON.parse(lockContent);
|
|
71
|
+
foundStatePath = lockMeta.path;
|
|
62
72
|
}
|
|
63
73
|
if (!foundStatePath) {
|
|
64
74
|
common_1.logger.error(lang_1.lang.__('NO_LOCK_FOUND'));
|
|
@@ -68,21 +78,6 @@ const forceUnlockCommand = async (lockId, options = {}) => {
|
|
|
68
78
|
backend = {
|
|
69
79
|
readLock: async () => (0, lockManager_1.readLockFileForCommand)(statePath),
|
|
70
80
|
forceUnlock: async (id) => (0, lockManager_1.forceUnlock)(statePath, id),
|
|
71
|
-
loadState: async () => {
|
|
72
|
-
throw new Error(lang_1.lang.__('FORCE_UNLOCK_NO_LOCATION_MODE'));
|
|
73
|
-
},
|
|
74
|
-
saveState: async () => {
|
|
75
|
-
throw new Error(lang_1.lang.__('FORCE_UNLOCK_NO_LOCATION_MODE'));
|
|
76
|
-
},
|
|
77
|
-
acquireLock: async () => {
|
|
78
|
-
throw new Error(lang_1.lang.__('FORCE_UNLOCK_NO_LOCATION_MODE'));
|
|
79
|
-
},
|
|
80
|
-
releaseLock: async () => {
|
|
81
|
-
throw new Error(lang_1.lang.__('FORCE_UNLOCK_NO_LOCATION_MODE'));
|
|
82
|
-
},
|
|
83
|
-
withLock: async () => {
|
|
84
|
-
throw new Error(lang_1.lang.__('FORCE_UNLOCK_NO_LOCATION_MODE'));
|
|
85
|
-
},
|
|
86
81
|
};
|
|
87
82
|
}
|
|
88
83
|
// Check if lock exists
|
|
@@ -120,14 +120,18 @@ program
|
|
|
120
120
|
.description(lang_1.lang.__('CMD_SHOW_DESC'))
|
|
121
121
|
.option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
|
|
122
122
|
.option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
|
|
123
|
+
.option('-r, --region <region>', lang_1.lang.__('OPT_REGION'))
|
|
124
|
+
.option('-v, --provider <provider>', lang_1.lang.__('OPT_PROVIDER'))
|
|
123
125
|
.option('--json', lang_1.lang.__('OPT_JSON'))
|
|
124
|
-
.action(actionWrapper('show', async ({ file, stage, json }) => {
|
|
126
|
+
.action(actionWrapper('show', async ({ file, stage, region, provider, json }) => {
|
|
125
127
|
(0, jsonOutput_1.setJsonMode)(!!json);
|
|
126
128
|
const iacLocation = (0, common_1.getIacLocation)(file);
|
|
127
129
|
const rawIac = (0, parser_1.parseYaml)(iacLocation);
|
|
128
130
|
await (0, common_1.setContext)({
|
|
129
131
|
location: file,
|
|
130
132
|
stage,
|
|
133
|
+
region,
|
|
134
|
+
provider,
|
|
131
135
|
app: rawIac.app,
|
|
132
136
|
service: rawIac.service,
|
|
133
137
|
iacProvider: rawIac.provider,
|
|
@@ -153,46 +157,9 @@ program
|
|
|
153
157
|
process.exitCode = 1;
|
|
154
158
|
}
|
|
155
159
|
}));
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
.option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
|
|
160
|
-
.option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
|
|
161
|
-
.option('-r, --region <region>', lang_1.lang.__('OPT_REGION'))
|
|
162
|
-
.option('-v, --provider <provider>', lang_1.lang.__('OPT_PROVIDER'))
|
|
163
|
-
.option('-k, --accessKeyId <accessKeyId>', lang_1.lang.__('OPT_ACCESS_KEY_ID'))
|
|
164
|
-
.option('-x, --accessKeySecret <accessKeySecret>', lang_1.lang.__('OPT_ACCESS_KEY_SECRET'))
|
|
165
|
-
.option('-n, --securityToken <securityToken>', lang_1.lang.__('OPT_SECURITY_TOKEN'))
|
|
166
|
-
.option('--no-refresh', lang_1.lang.__('OPT_NO_REFRESH'))
|
|
167
|
-
.option('--json', lang_1.lang.__('OPT_JSON'))
|
|
168
|
-
.option('--no-color', lang_1.lang.__('OPT_NO_COLOR'))
|
|
169
|
-
.option('-p, --parameter <key=value>', lang_1.lang.__('OPT_PARAMETER'), (value, previous) => {
|
|
170
|
-
const [key, val] = value.split('=');
|
|
171
|
-
return { ...previous, [key]: val };
|
|
172
|
-
}, {})
|
|
173
|
-
.action(actionWrapper('plan', async ({ stage, parameter, file, region, provider, accessKeyId, accessKeySecret, securityToken, refresh, json, color, }) => {
|
|
174
|
-
(0, jsonOutput_1.setJsonMode)(!!json);
|
|
175
|
-
const result = await (0, plan_1.plan)({
|
|
176
|
-
stage,
|
|
177
|
-
parameters: parameter,
|
|
178
|
-
location: file,
|
|
179
|
-
region,
|
|
180
|
-
provider,
|
|
181
|
-
accessKeyId,
|
|
182
|
-
accessKeySecret,
|
|
183
|
-
securityToken,
|
|
184
|
-
refresh,
|
|
185
|
-
json: !!json,
|
|
186
|
-
noColor: color === false,
|
|
187
|
-
});
|
|
188
|
-
// Issue #250 exit-code convention (terraform-compatible):
|
|
189
|
-
// 0 = no changes, 2 = changes present, 1 = execution error (handler).
|
|
190
|
-
if (result.hasChanges) {
|
|
191
|
-
process.exitCode = 2;
|
|
192
|
-
}
|
|
193
|
-
}));
|
|
194
|
-
// Issue #246: `diff` is the primary verb users say — it runs the same plan
|
|
195
|
-
// flow; `plan` stays for compatibility.
|
|
160
|
+
// Issue #246/#271: `diff` is the sole verb for previewing deployment changes;
|
|
161
|
+
// the legacy `plan` verb is removed. Options and the action handler are
|
|
162
|
+
// defined exactly once.
|
|
196
163
|
program
|
|
197
164
|
.command('diff')
|
|
198
165
|
.description(lang_1.lang.__('CMD_DIFF_DESC'))
|
|
@@ -210,31 +177,14 @@ program
|
|
|
210
177
|
const [key, val] = value.split('=');
|
|
211
178
|
return { ...previous, [key]: val };
|
|
212
179
|
}, {})
|
|
213
|
-
.action(actionWrapper('diff',
|
|
214
|
-
(0, jsonOutput_1.setJsonMode)(!!json);
|
|
215
|
-
const result = await (0, plan_1.plan)({
|
|
216
|
-
stage,
|
|
217
|
-
parameters: parameter,
|
|
218
|
-
location: file,
|
|
219
|
-
region,
|
|
220
|
-
provider,
|
|
221
|
-
accessKeyId,
|
|
222
|
-
accessKeySecret,
|
|
223
|
-
securityToken,
|
|
224
|
-
refresh,
|
|
225
|
-
json: !!json,
|
|
226
|
-
noColor: color === false,
|
|
227
|
-
});
|
|
228
|
-
if (result.hasChanges) {
|
|
229
|
-
process.exitCode = 2;
|
|
230
|
-
}
|
|
231
|
-
}));
|
|
180
|
+
.action(actionWrapper('diff', plan_1.runDiffCommand));
|
|
232
181
|
program
|
|
233
182
|
.command('deploy')
|
|
234
183
|
.description(lang_1.lang.__('CMD_DEPLOY_DESC'))
|
|
235
184
|
.option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
|
|
236
185
|
.option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
|
|
237
186
|
.option('-r, --region <region>', lang_1.lang.__('OPT_REGION'))
|
|
187
|
+
.option('--bind-unknown-region <region>', lang_1.lang.__('OPT_BIND_UNKNOWN_REGION'))
|
|
238
188
|
.option('-v, --provider <provider>', lang_1.lang.__('OPT_PROVIDER'))
|
|
239
189
|
.option('-k, --accessKeyId <accessKeyId>', lang_1.lang.__('OPT_ACCESS_KEY_ID'))
|
|
240
190
|
.option('-x, --accessKeySecret <accessKeySecret>', lang_1.lang.__('OPT_ACCESS_KEY_SECRET'))
|
|
@@ -247,12 +197,13 @@ program
|
|
|
247
197
|
previous[key] = val;
|
|
248
198
|
return previous;
|
|
249
199
|
}, {})
|
|
250
|
-
.action(actionWrapper('deploy', async ({ stage, parameter, file, region, provider, accessKeyId, accessKeySecret, securityToken, siApiKey, autoApprove, refresh, }) => {
|
|
200
|
+
.action(actionWrapper('deploy', async ({ stage, parameter, file, region, bindUnknownRegion, provider, accessKeyId, accessKeySecret, securityToken, siApiKey, autoApprove, refresh, }) => {
|
|
251
201
|
await (0, deploy_1.deploy)({
|
|
252
202
|
stage,
|
|
253
203
|
parameters: parameter,
|
|
254
204
|
location: file,
|
|
255
205
|
region,
|
|
206
|
+
bindUnknownRegion,
|
|
256
207
|
provider,
|
|
257
208
|
accessKeyId,
|
|
258
209
|
accessKeySecret,
|
|
@@ -278,7 +229,8 @@ program
|
|
|
278
229
|
.option('--no-marker', lang_1.lang.__('OPT_NO_MARKER'))
|
|
279
230
|
.option('--dry-run', lang_1.lang.__('OPT_DRY_RUN'))
|
|
280
231
|
.option('--rollback', lang_1.lang.__('OPT_ROLLBACK'))
|
|
281
|
-
.
|
|
232
|
+
.option('--bind-unknown-region <region>', lang_1.lang.__('OPT_BIND_UNKNOWN_REGION'))
|
|
233
|
+
.action(actionWrapper('migrate', async ({ stage, file, region, provider, accessKeyId, accessKeySecret, securityToken, siApiKey, autoApprove, force, marker, dryRun, rollback, bindUnknownRegion, }) => {
|
|
282
234
|
await (0, migrate_1.migrate)({
|
|
283
235
|
stage,
|
|
284
236
|
location: file,
|
|
@@ -295,6 +247,7 @@ program
|
|
|
295
247
|
noMarker: marker === false,
|
|
296
248
|
dryRun,
|
|
297
249
|
rollback,
|
|
250
|
+
bindUnknownRegion,
|
|
298
251
|
});
|
|
299
252
|
}));
|
|
300
253
|
program
|
|
@@ -302,16 +255,18 @@ program
|
|
|
302
255
|
.option('-f, --file <path>', lang_1.lang.__('OPT_FILE'))
|
|
303
256
|
.option('-s, --stage <stage>', lang_1.lang.__('OPT_STAGE'))
|
|
304
257
|
.option('-r, --region <region>', lang_1.lang.__('OPT_REGION'))
|
|
258
|
+
.option('--bind-unknown-region <region>', lang_1.lang.__('OPT_BIND_UNKNOWN_REGION'))
|
|
305
259
|
.option('-v, --provider <provider>', lang_1.lang.__('OPT_PROVIDER'))
|
|
306
260
|
.option('-k, --accessKeyId <accessKeyId>', lang_1.lang.__('OPT_ACCESS_KEY_ID'))
|
|
307
261
|
.option('-x, --accessKeySecret <accessKeySecret>', lang_1.lang.__('OPT_ACCESS_KEY_SECRET'))
|
|
308
262
|
.option('-n, --securityToken <securityToken>', lang_1.lang.__('OPT_SECURITY_TOKEN'))
|
|
309
263
|
.description(lang_1.lang.__('CMD_DESTROY_DESC'))
|
|
310
|
-
.action(actionWrapper('destroy', async ({ file, stage, region, provider, accessKeyId, accessKeySecret, securityToken }) => {
|
|
264
|
+
.action(actionWrapper('destroy', async ({ file, stage, region, bindUnknownRegion, provider, accessKeyId, accessKeySecret, securityToken, }) => {
|
|
311
265
|
await (0, destroy_1.destroyStack)({
|
|
312
266
|
location: file,
|
|
313
267
|
stage,
|
|
314
268
|
region,
|
|
269
|
+
bindUnknownRegion,
|
|
315
270
|
provider,
|
|
316
271
|
accessKeyId,
|
|
317
272
|
accessKeySecret,
|
|
@@ -358,4 +313,12 @@ program
|
|
|
358
313
|
securityToken,
|
|
359
314
|
});
|
|
360
315
|
}));
|
|
316
|
+
// Issue #271: `si plan` was removed in favor of `si diff` — the legacy verb is
|
|
317
|
+
// rejected with a localized migration hint before anything runs (no cloud or
|
|
318
|
+
// state mutations). The check runs before commander parses argv so the hint
|
|
319
|
+
// also wins over generic unknown-command handling, while every other unknown
|
|
320
|
+
// verb keeps commander's default error, including did-you-mean suggestions.
|
|
321
|
+
if (process.argv[2] === 'plan') {
|
|
322
|
+
program.error(`error: ${lang_1.lang.__('CMD_PLAN_REMOVED')}`);
|
|
323
|
+
}
|
|
361
324
|
program.parse();
|
|
@@ -32,13 +32,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
32
32
|
return result;
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
36
|
exports.migrate = void 0;
|
|
40
37
|
const readline = __importStar(require("node:readline"));
|
|
41
|
-
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
42
38
|
const common_1 = require("../common");
|
|
43
39
|
const stateBackend_1 = require("../common/stateBackend");
|
|
44
40
|
const credentialStore_1 = require("../common/credentialStore");
|
|
@@ -102,7 +98,7 @@ const migrate = async (options) => {
|
|
|
102
98
|
// Purely local to the source backend, so it needs NO Console credentials.
|
|
103
99
|
if (options.rollback) {
|
|
104
100
|
await sourceBackend.withLock('migrate-rollback', async () => {
|
|
105
|
-
const state = await sourceBackend.loadState(
|
|
101
|
+
const state = await sourceBackend.loadState();
|
|
106
102
|
if (!(0, migrationMarker_1.isMigratedToSaas)(state)) {
|
|
107
103
|
common_1.logger.info(lang_1.lang.__('MIGRATE_ROLLBACK_NO_MARKER'));
|
|
108
104
|
return;
|
|
@@ -118,165 +114,142 @@ const migrate = async (options) => {
|
|
|
118
114
|
}
|
|
119
115
|
const creds = (0, credentialStore_1.loadCredentials)();
|
|
120
116
|
const apiKey = options.siApiKey ?? creds?.apiKey;
|
|
121
|
-
if (!apiKey)
|
|
117
|
+
if (!apiKey)
|
|
122
118
|
throw new Error(lang_1.lang.__('MIGRATE_NEED_CREDENTIALS'));
|
|
123
|
-
}
|
|
124
119
|
const baseUrl = (0, credentialStore_1.getConsoleUrl)();
|
|
125
120
|
const identity = await (0, apiClient_1.validateApiKey)(apiKey, baseUrl);
|
|
126
121
|
const orgId = identity.orgId;
|
|
127
|
-
|
|
122
|
+
if (iac.org && identity.orgSlug && iac.org !== identity.orgSlug) {
|
|
123
|
+
throw new Error(lang_1.lang.__('SAAS_ORG_MISMATCH', { declared: iac.org, actual: identity.orgSlug }));
|
|
124
|
+
}
|
|
128
125
|
const client = (0, apiClient_1.createApiClient)({ apiKey, baseUrl, orgId });
|
|
126
|
+
if (!(0, common_1.supportsRegionalSaas)(await client.get('/api/v1/capabilities'))) {
|
|
127
|
+
throw new Error(lang_1.lang.__('SAAS_REGIONAL_SCOPE_UNSUPPORTED', { consoleUrl: baseUrl }));
|
|
128
|
+
}
|
|
129
|
+
const scope = (0, common_1.normalizeScope)({
|
|
130
|
+
provider: context.provider,
|
|
131
|
+
app: iac.app,
|
|
132
|
+
service: iac.service,
|
|
133
|
+
stage: context.stage,
|
|
134
|
+
region: context.region,
|
|
135
|
+
});
|
|
136
|
+
common_1.logger.info(lang_1.lang.__('MIGRATE_PREFLIGHT_OK', { orgName: identity.orgName, orgId }));
|
|
129
137
|
await sourceBackend.withLock('migrate', async () => {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
138
|
+
await sourceBackend.upgradeLegacyState?.({
|
|
139
|
+
bindUnknownRegion: options.bindUnknownRegion,
|
|
140
|
+
dryRun: options.dryRun,
|
|
141
|
+
});
|
|
142
|
+
const state = await sourceBackend.loadState();
|
|
133
143
|
if ((0, migrationMarker_1.isMigratedToSaas)(state)) {
|
|
134
144
|
common_1.logger.warn(lang_1.lang.__('MIGRATE_ALREADY_MARKED'));
|
|
145
|
+
return;
|
|
135
146
|
}
|
|
136
|
-
if (state.
|
|
137
|
-
throw new Error(lang_1.lang.__('
|
|
138
|
-
stateProvider: state.provider,
|
|
139
|
-
ymlProvider: iac.provider.name,
|
|
140
|
-
}));
|
|
147
|
+
if (!state.scope || state.version !== '4.0') {
|
|
148
|
+
throw new Error(lang_1.lang.__('MIGRATE_SOURCE_FORMAT_INVALID'));
|
|
141
149
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
150
|
+
(0, common_1.validateScopedDocument)((0, common_1.toPersistedState)(state), scope);
|
|
151
|
+
if (!options.noMarker && !sourceBackend.patchPersisted)
|
|
152
|
+
throw new Error(lang_1.lang.__('MIGRATE_NO_BACKEND_SOURCE'));
|
|
153
|
+
if (Object.entries(state.stages).some(([stage, entry]) => stage !== scope.stage &&
|
|
154
|
+
(Object.keys(entry.resources ?? {}).length > 0 ||
|
|
155
|
+
Object.keys(entry.shared ?? {}).length > 0))) {
|
|
156
|
+
throw new Error(lang_1.lang.__('MIGRATE_SOURCE_MULTIPLE_SCOPES'));
|
|
146
157
|
}
|
|
147
|
-
const
|
|
148
|
-
if (
|
|
158
|
+
const selected = state.stages[scope.stage];
|
|
159
|
+
if (!Object.keys(selected?.resources ?? {}).length &&
|
|
160
|
+
!Object.keys(selected?.shared ?? {}).length) {
|
|
149
161
|
throw new Error(lang_1.lang.__('MIGRATE_NOTHING_TO_MIGRATE'));
|
|
150
162
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (targets.app.exists) {
|
|
158
|
-
common_1.logger.info(lang_1.lang.__('MIGRATE_TARGET_APP_EXISTS', {
|
|
159
|
-
app: targets.app.name,
|
|
160
|
-
appId: targets.app.id ?? '',
|
|
161
|
-
}));
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
common_1.logger.info(lang_1.lang.__('MIGRATE_TARGET_APP_CREATE', { app: targets.app.name }));
|
|
163
|
+
const resourceCount = Object.keys(selected.resources).length;
|
|
164
|
+
const targets = await client.get(`/api/v1/state/migrate/targets?app_name=${encodeURIComponent(scope.app)}&service_name=${encodeURIComponent(scope.service)}&stages=${encodeURIComponent(scope.stage)}®ion=${encodeURIComponent(scope.region)}&provider=${encodeURIComponent(scope.provider)}`);
|
|
165
|
+
if (targets.service.exists &&
|
|
166
|
+
(targets.service.regionalScopeEnabled !== true ||
|
|
167
|
+
targets.service.scopeProtocol !== common_1.SCOPE_PROTOCOL_VERSION)) {
|
|
168
|
+
throw new Error(lang_1.lang.__('MIGRATE_TARGET_REGIONAL_REQUIRED'));
|
|
165
169
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
service:
|
|
170
|
+
const report = targets.stages.find((entry) => entry.name === scope.stage);
|
|
171
|
+
if (report?.hasState && !report.contentHash)
|
|
172
|
+
throw new Error(lang_1.lang.__('SAAS_STATE_ACK_INVALID'));
|
|
173
|
+
common_1.logger.info(lang_1.lang.__('MIGRATE_TARGETS_HEADER', { orgName: identity.orgName }));
|
|
174
|
+
common_1.logger.info(targets.app.exists
|
|
175
|
+
? lang_1.lang.__('MIGRATE_TARGET_APP_EXISTS', { app: scope.app, appId: targets.app.id ?? '' })
|
|
176
|
+
: lang_1.lang.__('MIGRATE_TARGET_APP_CREATE', { app: scope.app }));
|
|
177
|
+
common_1.logger.info(targets.service.exists
|
|
178
|
+
? lang_1.lang.__('MIGRATE_TARGET_SERVICE_EXISTS', {
|
|
179
|
+
service: scope.service,
|
|
176
180
|
serviceId: targets.service.id ?? '',
|
|
177
|
-
provider:
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
service: targets.service.name,
|
|
183
|
-
provider: iac.provider.name,
|
|
181
|
+
provider: scope.provider,
|
|
182
|
+
})
|
|
183
|
+
: lang_1.lang.__('MIGRATE_TARGET_SERVICE_CREATE', {
|
|
184
|
+
service: scope.service,
|
|
185
|
+
provider: scope.provider,
|
|
184
186
|
}));
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}));
|
|
195
|
-
}
|
|
196
|
-
else if (report?.registered) {
|
|
197
|
-
common_1.logger.info(lang_1.lang.__('MIGRATE_TARGET_STAGE_EMPTY', { stage: stageKey, count }));
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
common_1.logger.info(lang_1.lang.__('MIGRATE_TARGET_STAGE_NEW', { stage: stageKey, count }));
|
|
201
|
-
}
|
|
202
|
-
}
|
|
187
|
+
common_1.logger.info(lang_1.lang.__(report?.hasState
|
|
188
|
+
? 'MIGRATE_TARGET_STAGE_EXISTS'
|
|
189
|
+
: report?.registered
|
|
190
|
+
? 'MIGRATE_TARGET_STAGE_EMPTY'
|
|
191
|
+
: 'MIGRATE_TARGET_STAGE_NEW', {
|
|
192
|
+
stage: `${scope.stage} / ${scope.region}`,
|
|
193
|
+
count: String(resourceCount),
|
|
194
|
+
version: String(report?.latestVersion ?? 1),
|
|
195
|
+
}));
|
|
203
196
|
common_1.logger.info(lang_1.lang.__('MIGRATE_TARGETS_HINT'));
|
|
204
197
|
if (options.dryRun) {
|
|
205
198
|
common_1.logger.info(lang_1.lang.__('MIGRATE_DRY_RUN_NOTICE'));
|
|
206
199
|
return;
|
|
207
200
|
}
|
|
208
|
-
// ⑤ confirm — the writer-upgrade question is the §4.5 runbook gate
|
|
209
201
|
if (!options.autoApprove) {
|
|
210
|
-
if (!(await askConfirmation(lang_1.lang.__('MIGRATE_WRITER_CONFIRMATION'))))
|
|
202
|
+
if (!(await askConfirmation(lang_1.lang.__('MIGRATE_WRITER_CONFIRMATION'))))
|
|
211
203
|
return;
|
|
212
|
-
|
|
213
|
-
if (!(await askConfirmation(lang_1.lang.__('MIGRATE_CONFIRMATION')))) {
|
|
204
|
+
if (!(await askConfirmation(lang_1.lang.__('MIGRATE_CONFIRMATION'))))
|
|
214
205
|
return;
|
|
215
|
-
}
|
|
216
206
|
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
// ⑦ read-back verification — the stored version must be ours. The server
|
|
248
|
-
// echoes the hash it stored, so no JSON re-serialization is involved
|
|
249
|
-
// (Postgres jsonb would reorder keys and break a naive string compare).
|
|
250
|
-
const remote = await client.get(`/api/v1/apps/${uploadResult.appId}/services/${uploadResult.serviceId}/state/current?stage=${encodeURIComponent(stageKey)}`);
|
|
251
|
-
const verified = remote.contentHash === contentHash &&
|
|
252
|
-
remote.versionNumber === uploadResult.versionNumber &&
|
|
253
|
-
(uploadResult.deduped || remote.resourceCount === resourceCount);
|
|
254
|
-
if (!verified) {
|
|
255
|
-
throw new Error(lang_1.lang.__('MIGRATE_VERIFY_FAILED', { stage: stageKey }));
|
|
256
|
-
}
|
|
257
|
-
results.push({ stage: stageKey, ...uploadResult });
|
|
258
|
-
common_1.logger.info(lang_1.lang.__('MIGRATE_UPLOADED', {
|
|
259
|
-
stage: stageKey,
|
|
260
|
-
version: String(uploadResult.versionNumber),
|
|
261
|
-
deduped: uploadResult.deduped ? lang_1.lang.__('MIGRATE_UPLOADED_DEDUPLICATED') : '',
|
|
262
|
-
appId: uploadResult.appId,
|
|
263
|
-
serviceId: uploadResult.serviceId,
|
|
264
|
-
}));
|
|
207
|
+
const persisted = { ...(0, common_1.toPersistedState)(state), stages: { [scope.stage]: selected }, orgId };
|
|
208
|
+
const contentHash = (0, common_1.hashSaasState)(persisted);
|
|
209
|
+
common_1.logger.info(lang_1.lang.__('MIGRATE_UPLOADING', { stage: scope.stage }));
|
|
210
|
+
const uploaded = await client.post('/api/v1/state/migrate', {
|
|
211
|
+
appName: scope.app,
|
|
212
|
+
serviceName: scope.service,
|
|
213
|
+
provider: scope.provider,
|
|
214
|
+
stage: scope.stage,
|
|
215
|
+
region: scope.region,
|
|
216
|
+
scopeProtocol: common_1.SCOPE_PROTOCOL_VERSION,
|
|
217
|
+
baseContentHash: report?.contentHash ?? '',
|
|
218
|
+
stateJson: persisted,
|
|
219
|
+
contentHash,
|
|
220
|
+
resourceCount,
|
|
221
|
+
origin: backendType === types_1.StateBackendType.LOCAL ? 'local' : 'bucket',
|
|
222
|
+
conflict: options.force ? 'overwrite' : 'reject',
|
|
223
|
+
});
|
|
224
|
+
const remote = await client.get(`/api/v1/apps/${uploaded.appId}/services/${uploaded.serviceId}/state/current?stage=${encodeURIComponent(scope.stage)}®ion=${encodeURIComponent(scope.region)}&provider=${encodeURIComponent(scope.provider)}`);
|
|
225
|
+
if (!(0, common_1.isRegionalSaasSnapshot)(remote, scope) ||
|
|
226
|
+
remote.serviceId !== uploaded.serviceId ||
|
|
227
|
+
remote.id !== uploaded.stateId ||
|
|
228
|
+
remote.stageId !== uploaded.stageId ||
|
|
229
|
+
uploaded.scopeProtocol !== common_1.SCOPE_PROTOCOL_VERSION ||
|
|
230
|
+
uploaded.provider !== scope.provider ||
|
|
231
|
+
uploaded.region !== scope.region ||
|
|
232
|
+
remote.contentHash !== contentHash ||
|
|
233
|
+
remote.versionNumber !== uploaded.versionNumber ||
|
|
234
|
+
(!uploaded.deduped && remote.resourceCount !== resourceCount)) {
|
|
235
|
+
throw new Error(lang_1.lang.__('MIGRATE_VERIFY_FAILED', { stage: scope.stage }));
|
|
265
236
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
237
|
+
(0, common_1.validateScopedDocument)(remote.stateJson, scope);
|
|
238
|
+
common_1.logger.info(lang_1.lang.__('MIGRATE_UPLOADED', {
|
|
239
|
+
stage: scope.stage,
|
|
240
|
+
version: String(uploaded.versionNumber),
|
|
241
|
+
deduped: uploaded.deduped ? lang_1.lang.__('MIGRATE_UPLOADED_DEDUPLICATED') : '',
|
|
242
|
+
appId: uploaded.appId,
|
|
243
|
+
serviceId: uploaded.serviceId,
|
|
244
|
+
}));
|
|
269
245
|
if (options.noMarker) {
|
|
270
246
|
common_1.logger.warn(lang_1.lang.__('MIGRATE_MARKER_SKIPPED'));
|
|
271
247
|
}
|
|
272
248
|
else {
|
|
273
|
-
if (!sourceBackend.patchPersisted) {
|
|
274
|
-
throw new Error(lang_1.lang.__('MIGRATE_NO_BACKEND_SOURCE'));
|
|
275
|
-
}
|
|
276
249
|
await sourceBackend.patchPersisted({
|
|
277
250
|
orgId,
|
|
278
|
-
appId:
|
|
279
|
-
serviceId:
|
|
251
|
+
appId: uploaded.appId,
|
|
252
|
+
serviceId: uploaded.serviceId,
|
|
280
253
|
managedBy: 'saas',
|
|
281
254
|
});
|
|
282
255
|
common_1.logger.info(lang_1.lang.__('MIGRATE_MARKER_WRITTEN'));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.plan = void 0;
|
|
3
|
+
exports.runDiffCommand = exports.plan = void 0;
|
|
4
4
|
const common_1 = require("../common");
|
|
5
5
|
const stateBackend_1 = require("../common/stateBackend");
|
|
6
6
|
const jsonOutput_1 = require("../common/jsonOutput");
|
|
@@ -34,12 +34,11 @@ const plan = async (options) => {
|
|
|
34
34
|
};
|
|
35
35
|
const providerDisplayName = providerDisplayNames[iac.provider.name] ?? iac.provider.name;
|
|
36
36
|
common_1.logger.info(lang_1.lang.__('GENERATING_PLAN_FOR_PROVIDER', { provider: providerDisplayName }));
|
|
37
|
-
// Read-only command: a migrated state only warns here (window-period
|
|
38
|
-
// reconciliation still needs plan against the legacy copy).
|
|
39
37
|
const backend = (0, stateBackend_1.createStateBackend)(iac.backend, {
|
|
40
38
|
...context,
|
|
41
39
|
declaredOrg: iac.org,
|
|
42
40
|
migrationMarker: 'warn',
|
|
41
|
+
mode: 'read-only',
|
|
43
42
|
});
|
|
44
43
|
let planResult;
|
|
45
44
|
if (iac.provider.name === common_1.ProviderEnum.TENCENT) {
|
|
@@ -61,6 +60,7 @@ const plan = async (options) => {
|
|
|
61
60
|
app: iac.app,
|
|
62
61
|
service: iac.service,
|
|
63
62
|
stage: context.stage,
|
|
63
|
+
region: context.region,
|
|
64
64
|
}));
|
|
65
65
|
}
|
|
66
66
|
else {
|
|
@@ -76,3 +76,27 @@ const plan = async (options) => {
|
|
|
76
76
|
return { hasChanges: changeCount > 0 };
|
|
77
77
|
};
|
|
78
78
|
exports.plan = plan;
|
|
79
|
+
// Single action implementation behind `si diff`, the sole command for
|
|
80
|
+
// previewing deployment changes (issue #271).
|
|
81
|
+
const runDiffCommand = async (options) => {
|
|
82
|
+
(0, jsonOutput_1.setJsonMode)(!!options.json);
|
|
83
|
+
const result = await (0, exports.plan)({
|
|
84
|
+
stage: options.stage,
|
|
85
|
+
parameters: options.parameter,
|
|
86
|
+
location: options.file,
|
|
87
|
+
region: options.region,
|
|
88
|
+
provider: options.provider,
|
|
89
|
+
accessKeyId: options.accessKeyId,
|
|
90
|
+
accessKeySecret: options.accessKeySecret,
|
|
91
|
+
securityToken: options.securityToken,
|
|
92
|
+
refresh: options.refresh,
|
|
93
|
+
json: !!options.json,
|
|
94
|
+
noColor: options.color === false,
|
|
95
|
+
});
|
|
96
|
+
// Issue #250 exit-code convention (terraform-compatible):
|
|
97
|
+
// 0 = no changes, 2 = changes present, 1 = execution error (handler).
|
|
98
|
+
if (result.hasChanges) {
|
|
99
|
+
process.exitCode = 2;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
exports.runDiffCommand = runDiffCommand;
|