@geek-fun/serverlessinsight 0.9.0 → 0.9.2
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 +2 -2
- package/.serverlessinsight/state-insight-poc-app-log-insight-poc-tencent-log.json.backup +3 -3
- 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 +109 -0
- 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 +2 -2
- package/.serverlessinsight/state-role-reconcile-test-app-role-reconcile-test-service.json.backup +3 -3
- package/CHANGELOG.md +17 -0
- package/README.md +78 -2
- package/README.zh-CN.md +69 -2
- package/codecov +0 -0
- package/codecov.SHA256SUM +1 -0
- package/codecov.SHA256SUM.sig +16 -0
- package/dist/package.json +2 -2
- package/dist/src/commands/deploy.js +9 -3
- package/dist/src/commands/destroy.js +8 -2
- package/dist/src/commands/forceUnlock.js +5 -5
- package/dist/src/commands/index.js +173 -85
- package/dist/src/commands/login.js +12 -1
- package/dist/src/commands/migrate.js +287 -0
- package/dist/src/commands/plan.js +28 -2
- package/dist/src/commands/schema.js +24 -0
- package/dist/src/commands/show.js +99 -33
- package/dist/src/commands/validate.js +34 -2
- package/dist/src/common/aliyunClient/apigwOperations.js +4 -4
- package/dist/src/common/aliyunClient/ecsOperations.js +22 -13
- package/dist/src/common/aliyunClient/fc3Operations.js +39 -4
- package/dist/src/common/aliyunClient/nasOperations.js +4 -3
- package/dist/src/common/aliyunClient/ossOperations.js +52 -8
- package/dist/src/common/aliyunClient/slsOperations.js +3 -2
- package/dist/src/common/aliyunClient/tablestoreOperations.js +22 -11
- package/dist/src/common/apiClient.js +22 -5
- package/dist/src/common/constants.js +7 -1
- package/dist/src/common/context.js +5 -4
- package/dist/src/common/jsonOutput.js +77 -0
- package/dist/src/common/lockManager.js +1 -1
- package/dist/src/common/logger.js +6 -3
- package/dist/src/common/migrationMarker.js +34 -0
- package/dist/src/common/noColor.js +9 -0
- package/dist/src/common/planFormatter.js +12 -6
- package/dist/src/common/runtimeMapper.js +7 -3
- package/dist/src/common/siCron.js +415 -0
- package/dist/src/common/stateBackend/cosStateBackend.js +1 -1
- package/dist/src/common/stateBackend/index.js +5 -2
- package/dist/src/common/stateBackend/localStateBackend.js +8 -2
- package/dist/src/common/stateBackend/ossStateBackend.js +1 -1
- package/dist/src/common/stateBackend/remoteStateBackend.js +19 -2
- package/dist/src/common/stateBackend/saasStateBackend.js +88 -9
- package/dist/src/common/stateManager.js +56 -5
- package/dist/src/common/tencentClient/cosOperations.js +1 -1
- package/dist/src/common/tencentClient/scfOperations.js +4 -1
- package/dist/src/common/volcengineClient/apigwOperations.js +2 -2
- package/dist/src/common/volcengineClient/index.js +6 -2
- package/dist/src/common/volcengineClient/vefaasOperations.js +48 -3
- package/dist/src/lang/en.js +254 -1
- package/dist/src/lang/index.js +36 -1
- package/dist/src/lang/zh-CN.js +253 -1
- package/dist/src/parser/functionParser.js +47 -1
- package/dist/src/parser/index.js +1 -1
- package/dist/src/stack/aliyunStack/apigwExecutor.js +2 -2
- package/dist/src/stack/aliyunStack/apigwResource.js +22 -10
- package/dist/src/stack/aliyunStack/databaseExecutor.js +5 -5
- package/dist/src/stack/aliyunStack/databasePlanner.js +2 -2
- package/dist/src/stack/aliyunStack/databaseResource.js +18 -10
- package/dist/src/stack/aliyunStack/esServerlessTypes.js +2 -1
- package/dist/src/stack/aliyunStack/fc3Executor.js +2 -2
- package/dist/src/stack/aliyunStack/fc3Planner.js +26 -0
- package/dist/src/stack/aliyunStack/fc3Resource.js +190 -13
- package/dist/src/stack/aliyunStack/ossExecutor.js +2 -2
- package/dist/src/stack/aliyunStack/ossResource.js +5 -1
- package/dist/src/stack/aliyunStack/rdsTypes.js +5 -1
- package/dist/src/stack/aliyunStack/tablestoreExecutor.js +2 -2
- package/dist/src/stack/aliyunStack/tablestoreResource.js +3 -3
- package/dist/src/stack/aliyunStack/tablestoreTypes.js +3 -2
- package/dist/src/stack/deploy.js +2 -3
- package/dist/src/stack/localStack/event.js +2 -13
- package/dist/src/stack/localStack/function.js +2 -13
- package/dist/src/stack/localStack/functionRunner.js +5 -4
- package/dist/src/stack/localStack/index.js +8 -1
- package/dist/src/stack/localStack/timer.js +162 -0
- package/dist/src/stack/localStack/utils.js +19 -1
- package/dist/src/stack/scfStack/cosExecutor.js +2 -2
- package/dist/src/stack/scfStack/cosResource.js +2 -2
- package/dist/src/stack/scfStack/esServerlessExecutor.js +5 -5
- package/dist/src/stack/scfStack/esServerlessResource.js +7 -3
- package/dist/src/stack/scfStack/esServerlessTypes.js +2 -1
- package/dist/src/stack/scfStack/scfExecutor.js +2 -2
- package/dist/src/stack/scfStack/scfPlanner.js +52 -18
- package/dist/src/stack/scfStack/scfResource.js +202 -12
- package/dist/src/stack/scfStack/tdsqlcExecutor.js +5 -5
- package/dist/src/stack/scfStack/tdsqlcResource.js +7 -3
- package/dist/src/stack/volcengineStack/apigwExecutor.js +2 -2
- package/dist/src/stack/volcengineStack/apigwResource.js +7 -4
- package/dist/src/stack/volcengineStack/tosExecutor.js +2 -2
- package/dist/src/stack/volcengineStack/tosResource.js +1 -1
- package/dist/src/stack/volcengineStack/vefaasExecutor.js +2 -2
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +49 -0
- package/dist/src/stack/volcengineStack/vefaasResource.js +221 -4
- package/dist/src/validator/functionSchema.js +25 -2
- package/dist/src/validator/iacSchema.js +2 -1
- package/dist/src/validator/index.js +4 -1
- package/dist/src/validator/rootSchema.js +77 -19
- package/dist/src/validator/schemaExport.js +60 -0
- package/dist/src/validator/semanticValidation.js +79 -0
- package/dist/src/validator/templateRefSchema.js +9 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/samples/aliyun-poc-timer.yml +39 -0
|
@@ -0,0 +1,287 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.migrate = void 0;
|
|
40
|
+
const readline = __importStar(require("node:readline"));
|
|
41
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
42
|
+
const common_1 = require("../common");
|
|
43
|
+
const stateBackend_1 = require("../common/stateBackend");
|
|
44
|
+
const credentialStore_1 = require("../common/credentialStore");
|
|
45
|
+
const apiClient_1 = require("../common/apiClient");
|
|
46
|
+
const migrationMarker_1 = require("../common/migrationMarker");
|
|
47
|
+
const types_1 = require("../types");
|
|
48
|
+
const parser_1 = require("../parser");
|
|
49
|
+
const lang_1 = require("../lang");
|
|
50
|
+
const askConfirmation = async (message) => {
|
|
51
|
+
if (!process.stdin.isTTY) {
|
|
52
|
+
throw new Error(lang_1.lang.__('CONFIRMATION_STDIN_NOT_TTY'));
|
|
53
|
+
}
|
|
54
|
+
const rl = readline.createInterface({
|
|
55
|
+
input: process.stdin,
|
|
56
|
+
output: process.stdout,
|
|
57
|
+
});
|
|
58
|
+
return new Promise((resolve) => {
|
|
59
|
+
rl.question(message, (answer) => {
|
|
60
|
+
rl.close();
|
|
61
|
+
resolve(answer.toLowerCase() === 'yes' || answer.toLowerCase() === 'y');
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* `si migrate` — one-time migration of a legacy (local/bucket) state to the
|
|
67
|
+
* Console. docs/state-migration-saas.md §4.2:
|
|
68
|
+
* preflight → source lock → pull/validate → plan → confirm → upload
|
|
69
|
+
* → read-back verify → backfill console UUIDs + write marker → unlock.
|
|
70
|
+
* The marker (managedBy=saas) is a new persisted version of the source state
|
|
71
|
+
* that closes the legacy backend for mutations (decision D-4). Every step is
|
|
72
|
+
* re-runnable: uploads dedupe by contentHash and the marker is only written
|
|
73
|
+
* after verification passes.
|
|
74
|
+
*/
|
|
75
|
+
const migrate = async (options) => {
|
|
76
|
+
common_1.logger.info(lang_1.lang.__('VALIDATING_YAML'));
|
|
77
|
+
const iacLocation = (0, common_1.getIacLocation)(options.location);
|
|
78
|
+
const rawIac = (0, parser_1.parseYaml)(iacLocation);
|
|
79
|
+
common_1.logger.info(lang_1.lang.__('YAML_VALID'));
|
|
80
|
+
await (0, common_1.setContext)({
|
|
81
|
+
...options,
|
|
82
|
+
app: rawIac.app,
|
|
83
|
+
service: rawIac.service,
|
|
84
|
+
iacProvider: rawIac.provider,
|
|
85
|
+
stages: rawIac.stages,
|
|
86
|
+
},
|
|
87
|
+
// No live cloud probing: migrate only touches the state stores. This also
|
|
88
|
+
// lets --rollback and local-backend runs work without cloud credentials.
|
|
89
|
+
false);
|
|
90
|
+
const context = (0, common_1.getContext)();
|
|
91
|
+
const iac = (0, parser_1.revalYaml)(iacLocation, context);
|
|
92
|
+
(0, common_1.setIac)(iac);
|
|
93
|
+
// ① preflight — the source must be a legacy backend with actual state
|
|
94
|
+
const backendType = iac.backend?.type ?? types_1.StateBackendType.SAAS;
|
|
95
|
+
if (backendType !== types_1.StateBackendType.LOCAL && backendType !== types_1.StateBackendType.BUCKET_STORE) {
|
|
96
|
+
throw new Error(lang_1.lang.__('MIGRATE_NO_BACKEND_SOURCE'));
|
|
97
|
+
}
|
|
98
|
+
// Marker checks stay OFF on the source backend: si migrate must be able to
|
|
99
|
+
// read a marked state (idempotent re-runs, --rollback).
|
|
100
|
+
const sourceBackend = (0, stateBackend_1.createStateBackend)(iac.backend, { ...context, siApiKey: options.siApiKey });
|
|
101
|
+
// --rollback: the explicit undo — clear the marker, legacy path reopens.
|
|
102
|
+
// Purely local to the source backend, so it needs NO Console credentials.
|
|
103
|
+
if (options.rollback) {
|
|
104
|
+
await sourceBackend.withLock('migrate-rollback', async () => {
|
|
105
|
+
const state = await sourceBackend.loadState(iac.provider.name, iac.app, iac.service, options.stage ?? 'default');
|
|
106
|
+
if (!(0, migrationMarker_1.isMigratedToSaas)(state)) {
|
|
107
|
+
common_1.logger.info(lang_1.lang.__('MIGRATE_ROLLBACK_NO_MARKER'));
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (!sourceBackend.patchPersisted) {
|
|
111
|
+
throw new Error(lang_1.lang.__('MIGRATE_NO_BACKEND_SOURCE'));
|
|
112
|
+
}
|
|
113
|
+
await sourceBackend.patchPersisted({ managedBy: undefined });
|
|
114
|
+
common_1.logger.info(lang_1.lang.__('MIGRATE_ROLLBACK_DONE'));
|
|
115
|
+
common_1.logger.info(lang_1.lang.__('MIGRATE_ROLLBACK_DONE_HINT'));
|
|
116
|
+
});
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const creds = (0, credentialStore_1.loadCredentials)();
|
|
120
|
+
const apiKey = options.siApiKey ?? creds?.apiKey;
|
|
121
|
+
if (!apiKey) {
|
|
122
|
+
throw new Error(lang_1.lang.__('MIGRATE_NEED_CREDENTIALS'));
|
|
123
|
+
}
|
|
124
|
+
const baseUrl = (0, credentialStore_1.getConsoleUrl)();
|
|
125
|
+
const identity = await (0, apiClient_1.validateApiKey)(apiKey, baseUrl);
|
|
126
|
+
const orgId = identity.orgId;
|
|
127
|
+
common_1.logger.info(lang_1.lang.__('MIGRATE_PREFLIGHT_OK', { orgName: identity.orgName, orgId }));
|
|
128
|
+
const client = (0, apiClient_1.createApiClient)({ apiKey, baseUrl, orgId });
|
|
129
|
+
await sourceBackend.withLock('migrate', async () => {
|
|
130
|
+
// ③ pull + normalize (loadState applies registered state migrations)
|
|
131
|
+
const hydrateStage = options.stage ?? Object.keys(iac.stages ?? {})[0] ?? 'default';
|
|
132
|
+
const state = await sourceBackend.loadState(iac.provider.name, iac.app, iac.service, hydrateStage);
|
|
133
|
+
if ((0, migrationMarker_1.isMigratedToSaas)(state)) {
|
|
134
|
+
common_1.logger.warn(lang_1.lang.__('MIGRATE_ALREADY_MARKED'));
|
|
135
|
+
}
|
|
136
|
+
if (state.provider && state.provider !== iac.provider.name) {
|
|
137
|
+
throw new Error(lang_1.lang.__('MIGRATE_PROVIDER_MISMATCH', {
|
|
138
|
+
stateProvider: state.provider,
|
|
139
|
+
ymlProvider: iac.provider.name,
|
|
140
|
+
}));
|
|
141
|
+
}
|
|
142
|
+
// ④ mapping plan — only stages holding deployed resources migrate
|
|
143
|
+
const allStageKeys = Object.keys(state.stages ?? {});
|
|
144
|
+
if (options.stage && !allStageKeys.includes(options.stage)) {
|
|
145
|
+
throw new Error(lang_1.lang.__('MIGRATE_STAGE_NOT_FOUND', { stage: options.stage }));
|
|
146
|
+
}
|
|
147
|
+
const stageKeys = (options.stage ? [options.stage] : allStageKeys).filter((stageKey) => Object.keys(state.stages?.[stageKey]?.resources ?? {}).length > 0);
|
|
148
|
+
if (stageKeys.length === 0) {
|
|
149
|
+
throw new Error(lang_1.lang.__('MIGRATE_NOTHING_TO_MIGRATE'));
|
|
150
|
+
}
|
|
151
|
+
// ④ mapping plan — resolve which Console targets already exist (mapped by
|
|
152
|
+
// name) and which would be auto-created, so the dry-run/confirm screen
|
|
153
|
+
// keeps the user in control of the destination (pre-create in Console to
|
|
154
|
+
// adopt existing apps/services/membership settings).
|
|
155
|
+
const targets = await client.get(`/api/v1/state/migrate/targets?app_name=${encodeURIComponent(iac.app)}&service_name=${encodeURIComponent(iac.service)}&stages=${encodeURIComponent(stageKeys.join(','))}`);
|
|
156
|
+
common_1.logger.info(lang_1.lang.__('MIGRATE_TARGETS_HEADER', { orgName: identity.orgName }));
|
|
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 }));
|
|
165
|
+
}
|
|
166
|
+
if (targets.service.exists) {
|
|
167
|
+
if (targets.service.provider && targets.service.provider !== iac.provider.name) {
|
|
168
|
+
throw new Error(lang_1.lang.__('MIGRATE_PROVIDER_MISMATCH_TARGET', {
|
|
169
|
+
service: iac.service,
|
|
170
|
+
existingProvider: targets.service.provider,
|
|
171
|
+
ymlProvider: iac.provider.name,
|
|
172
|
+
}));
|
|
173
|
+
}
|
|
174
|
+
common_1.logger.info(lang_1.lang.__('MIGRATE_TARGET_SERVICE_EXISTS', {
|
|
175
|
+
service: targets.service.name,
|
|
176
|
+
serviceId: targets.service.id ?? '',
|
|
177
|
+
provider: targets.service.provider ?? '',
|
|
178
|
+
}));
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
common_1.logger.info(lang_1.lang.__('MIGRATE_TARGET_SERVICE_CREATE', {
|
|
182
|
+
service: targets.service.name,
|
|
183
|
+
provider: iac.provider.name,
|
|
184
|
+
}));
|
|
185
|
+
}
|
|
186
|
+
for (const stageKey of stageKeys) {
|
|
187
|
+
const count = String(Object.keys(state.stages?.[stageKey]?.resources ?? {}).length);
|
|
188
|
+
const report = targets.stages.find((s) => s.name === stageKey);
|
|
189
|
+
if (report?.hasState) {
|
|
190
|
+
common_1.logger.info(lang_1.lang.__('MIGRATE_TARGET_STAGE_EXISTS', {
|
|
191
|
+
stage: stageKey,
|
|
192
|
+
count,
|
|
193
|
+
version: String(report.latestVersion ?? 1),
|
|
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
|
+
}
|
|
203
|
+
common_1.logger.info(lang_1.lang.__('MIGRATE_TARGETS_HINT'));
|
|
204
|
+
if (options.dryRun) {
|
|
205
|
+
common_1.logger.info(lang_1.lang.__('MIGRATE_DRY_RUN_NOTICE'));
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
// ⑤ confirm — the writer-upgrade question is the §4.5 runbook gate
|
|
209
|
+
if (!options.autoApprove) {
|
|
210
|
+
if (!(await askConfirmation(lang_1.lang.__('MIGRATE_WRITER_CONFIRMATION')))) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (!(await askConfirmation(lang_1.lang.__('MIGRATE_CONFIRMATION')))) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
// ⑥ upload — same full-persisted-state contract as the SaaS backend save.
|
|
218
|
+
// The imported version carries the owning org id immediately (D-6 identity
|
|
219
|
+
// anchor), so the first post-cutover loadState can verify it without
|
|
220
|
+
// waiting for a fresh deploy save.
|
|
221
|
+
const persisted = { ...(0, common_1.toPersistedState)(state), orgId };
|
|
222
|
+
const contentHash = node_crypto_1.default.createHash('sha256').update(JSON.stringify(persisted)).digest('hex');
|
|
223
|
+
const results = [];
|
|
224
|
+
for (const stageKey of stageKeys) {
|
|
225
|
+
common_1.logger.info(lang_1.lang.__('MIGRATE_UPLOADING', { stage: stageKey }));
|
|
226
|
+
const resourceCount = Object.keys(state.stages?.[stageKey]?.resources ?? {}).length;
|
|
227
|
+
let uploadResult;
|
|
228
|
+
try {
|
|
229
|
+
uploadResult = await client.post('/api/v1/state/migrate', {
|
|
230
|
+
appName: iac.app,
|
|
231
|
+
serviceName: iac.service,
|
|
232
|
+
provider: iac.provider.name,
|
|
233
|
+
stage: stageKey,
|
|
234
|
+
stateJson: persisted,
|
|
235
|
+
contentHash,
|
|
236
|
+
resourceCount,
|
|
237
|
+
origin: backendType === types_1.StateBackendType.LOCAL ? 'local' : 'bucket',
|
|
238
|
+
conflict: options.force ? 'overwrite' : 'reject',
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
if (error instanceof apiClient_1.ApiError && error.status === 409) {
|
|
243
|
+
throw new Error(lang_1.lang.__('MIGRATE_CONFLICT'), { cause: error });
|
|
244
|
+
}
|
|
245
|
+
throw error;
|
|
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
|
+
}));
|
|
265
|
+
}
|
|
266
|
+
// ⑧⑨ backfill console UUIDs + write the migration marker as one new
|
|
267
|
+
// persisted version. Only reached when every stage verified.
|
|
268
|
+
const first = results[0];
|
|
269
|
+
if (options.noMarker) {
|
|
270
|
+
common_1.logger.warn(lang_1.lang.__('MIGRATE_MARKER_SKIPPED'));
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
if (!sourceBackend.patchPersisted) {
|
|
274
|
+
throw new Error(lang_1.lang.__('MIGRATE_NO_BACKEND_SOURCE'));
|
|
275
|
+
}
|
|
276
|
+
await sourceBackend.patchPersisted({
|
|
277
|
+
orgId,
|
|
278
|
+
appId: first.appId,
|
|
279
|
+
serviceId: first.serviceId,
|
|
280
|
+
managedBy: 'saas',
|
|
281
|
+
});
|
|
282
|
+
common_1.logger.info(lang_1.lang.__('MIGRATE_MARKER_WRITTEN'));
|
|
283
|
+
}
|
|
284
|
+
common_1.logger.info(lang_1.lang.__('MIGRATE_CUTOVER_STEPS'));
|
|
285
|
+
});
|
|
286
|
+
};
|
|
287
|
+
exports.migrate = migrate;
|
|
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.plan = void 0;
|
|
4
4
|
const common_1 = require("../common");
|
|
5
5
|
const stateBackend_1 = require("../common/stateBackend");
|
|
6
|
+
const jsonOutput_1 = require("../common/jsonOutput");
|
|
7
|
+
const noColor_1 = require("../common/noColor");
|
|
6
8
|
const parser_1 = require("../parser");
|
|
7
9
|
const scfStack_1 = require("../stack/scfStack");
|
|
8
10
|
const aliyunStack_1 = require("../stack/aliyunStack");
|
|
@@ -28,7 +30,13 @@ const plan = async (options) => {
|
|
|
28
30
|
? lang_1.lang.__('PROVIDER_ALIYUN')
|
|
29
31
|
: lang_1.lang.__('PROVIDER_TENCENT');
|
|
30
32
|
common_1.logger.info(lang_1.lang.__('GENERATING_PLAN_FOR_PROVIDER', { provider: providerDisplayName }));
|
|
31
|
-
|
|
33
|
+
// Read-only command: a migrated state only warns here (window-period
|
|
34
|
+
// reconciliation still needs plan against the legacy copy).
|
|
35
|
+
const backend = (0, stateBackend_1.createStateBackend)(iac.backend, {
|
|
36
|
+
...context,
|
|
37
|
+
declaredOrg: iac.org,
|
|
38
|
+
migrationMarker: 'warn',
|
|
39
|
+
});
|
|
32
40
|
let planResult;
|
|
33
41
|
if (iac.provider.name === common_1.ProviderEnum.TENCENT) {
|
|
34
42
|
planResult = await (0, scfStack_1.generateTencentPlan)(iac, backend);
|
|
@@ -40,6 +48,24 @@ const plan = async (options) => {
|
|
|
40
48
|
common_1.logger.error(lang_1.lang.__('PLAN_COMMAND_NOT_SUPPORTED'));
|
|
41
49
|
throw new Error(lang_1.lang.__('PLAN_COMMAND_NOT_SUPPORTED'));
|
|
42
50
|
}
|
|
43
|
-
(
|
|
51
|
+
if (options.json) {
|
|
52
|
+
(0, jsonOutput_1.writeJson)((0, jsonOutput_1.buildPlanJson)(planResult, {
|
|
53
|
+
provider: iac.provider.name,
|
|
54
|
+
app: iac.app,
|
|
55
|
+
service: iac.service,
|
|
56
|
+
stage: context.stage,
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
const displayConfig = {
|
|
61
|
+
colorize: !(options.noColor ?? false) && !(0, noColor_1.isNoColorEnabled)(),
|
|
62
|
+
indentSize: 4,
|
|
63
|
+
keyAlignWidth: 12,
|
|
64
|
+
};
|
|
65
|
+
(0, scfStack_1.displayPlan)(planResult, displayConfig);
|
|
66
|
+
}
|
|
67
|
+
const summary = (0, jsonOutput_1.buildPlanSummary)(planResult.items ?? []);
|
|
68
|
+
const changeCount = summary.create + summary.update + summary.destroy + summary.recreate;
|
|
69
|
+
return { hasChanges: changeCount > 0 };
|
|
44
70
|
};
|
|
45
71
|
exports.plan = plan;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.schema = void 0;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const validator_1 = require("../validator");
|
|
6
|
+
const logger_1 = require("../common/logger");
|
|
7
|
+
const lang_1 = require("../lang");
|
|
8
|
+
/**
|
|
9
|
+
* Issue #250: export the JSON Schema the validator compiles against as a
|
|
10
|
+
* self-contained, standard draft-07 document — the anchor agents use for
|
|
11
|
+
* structured YAML generation, editors use for completion, and `si validate`
|
|
12
|
+
* loops use for pre-flight checks.
|
|
13
|
+
*/
|
|
14
|
+
const schema = async (options) => {
|
|
15
|
+
const exported = (0, validator_1.exportIacJsonSchema)();
|
|
16
|
+
const payload = `${JSON.stringify(exported, null, 2)}\n`;
|
|
17
|
+
if (options.output) {
|
|
18
|
+
(0, node_fs_1.writeFileSync)(options.output, payload, 'utf8');
|
|
19
|
+
logger_1.logger.info(lang_1.lang.__('SCHEMA_WRITTEN_TO', { path: options.output }));
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
process.stdout.write(payload);
|
|
23
|
+
};
|
|
24
|
+
exports.schema = schema;
|
|
@@ -1,12 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.show = void 0;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
4
9
|
const types_1 = require("../types");
|
|
5
10
|
const backend_1 = require("../types/domains/backend");
|
|
6
11
|
const common_1 = require("../common");
|
|
7
12
|
const lockManager_1 = require("../common/lockManager");
|
|
8
13
|
const stateBackend_1 = require("../common/stateBackend");
|
|
14
|
+
const migrationMarker_1 = require("../common/migrationMarker");
|
|
15
|
+
const jsonOutput_1 = require("../common/jsonOutput");
|
|
9
16
|
const logger_1 = require("../common/logger");
|
|
17
|
+
const lang_1 = require("../lang");
|
|
18
|
+
/**
|
|
19
|
+
* The CLI passes the yaml file path as `location`; the state directory lives
|
|
20
|
+
* next to that file, not underneath it. A directory (or cwd) stays as-is.
|
|
21
|
+
*/
|
|
22
|
+
const resolveBaseDir = (location) => {
|
|
23
|
+
if (!location) {
|
|
24
|
+
return process.cwd();
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
if (node_fs_1.default.statSync(location).isFile()) {
|
|
28
|
+
return node_path_1.default.dirname(location);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch {
|
|
32
|
+
// not an existing file — treat as a directory
|
|
33
|
+
}
|
|
34
|
+
return location;
|
|
35
|
+
};
|
|
10
36
|
const formatTimeAgo = (dateStr) => {
|
|
11
37
|
const date = new Date(dateStr);
|
|
12
38
|
const now = new Date();
|
|
@@ -15,12 +41,12 @@ const formatTimeAgo = (dateStr) => {
|
|
|
15
41
|
const diffHours = Math.floor(diffMs / 3600000);
|
|
16
42
|
const diffDays = Math.floor(diffMs / 86400000);
|
|
17
43
|
if (diffDays > 0)
|
|
18
|
-
return
|
|
44
|
+
return lang_1.lang.__('SHOW_TIME_DAYS_AGO', { count: String(diffDays) });
|
|
19
45
|
if (diffHours > 0)
|
|
20
|
-
return
|
|
46
|
+
return lang_1.lang.__('SHOW_TIME_HOURS_AGO', { count: String(diffHours) });
|
|
21
47
|
if (diffMins > 0)
|
|
22
|
-
return
|
|
23
|
-
return '
|
|
48
|
+
return lang_1.lang.__('SHOW_TIME_MINUTES_AGO', { count: String(diffMins) });
|
|
49
|
+
return lang_1.lang.__('SHOW_TIME_JUST_NOW');
|
|
24
50
|
};
|
|
25
51
|
const formatFunctionOutput = (logicalId, resource) => {
|
|
26
52
|
const lines = [];
|
|
@@ -169,14 +195,16 @@ const getBackendLocationString = (backendConfig) => {
|
|
|
169
195
|
const config = backendConfig;
|
|
170
196
|
return `bucket://${config.bucket}/${config.key}`;
|
|
171
197
|
};
|
|
198
|
+
const SAAS_STATE_LOCATION = 'saas';
|
|
172
199
|
const show = async (options) => {
|
|
173
200
|
const context = (0, common_1.getContext)();
|
|
174
201
|
const stage = options.stage ?? context.stage;
|
|
175
|
-
const baseDir = options.location
|
|
176
|
-
logger_1.logger.info(
|
|
202
|
+
const baseDir = resolveBaseDir(options.location);
|
|
203
|
+
logger_1.logger.info(lang_1.lang.__('SHOW_LOADING_STATE', { app: context.app, service: context.service, stage }));
|
|
177
204
|
let state;
|
|
178
205
|
let lockInfo;
|
|
179
206
|
let stateLocation;
|
|
207
|
+
let stateLocationDisplay;
|
|
180
208
|
let usingRemoteBackend = false;
|
|
181
209
|
const backendType = options.iac?.backend?.type;
|
|
182
210
|
const shouldUseRemoteBackend = backendType === backend_1.StateBackendType.BUCKET_STORE ||
|
|
@@ -184,48 +212,86 @@ const show = async (options) => {
|
|
|
184
212
|
!backendType;
|
|
185
213
|
if (shouldUseRemoteBackend) {
|
|
186
214
|
try {
|
|
187
|
-
|
|
215
|
+
// Read-only command: a migrated state only warns here.
|
|
216
|
+
const backend = (0, stateBackend_1.createStateBackend)(options.iac.backend, {
|
|
217
|
+
...context,
|
|
218
|
+
declaredOrg: options.iac.org,
|
|
219
|
+
migrationMarker: 'warn',
|
|
220
|
+
});
|
|
188
221
|
state = await backend.loadState(context.provider, context.app, context.service, stage);
|
|
189
222
|
lockInfo = await backend.readLock();
|
|
190
223
|
usingRemoteBackend = true;
|
|
191
224
|
stateLocation =
|
|
192
225
|
backendType === backend_1.StateBackendType.SAAS || !backendType
|
|
193
|
-
?
|
|
226
|
+
? SAAS_STATE_LOCATION
|
|
194
227
|
: getBackendLocationString(options.iac.backend);
|
|
195
228
|
}
|
|
196
229
|
catch (error) {
|
|
197
230
|
if (backendType === backend_1.StateBackendType.SAAS || !backendType) {
|
|
198
|
-
logger_1.logger.warn(
|
|
231
|
+
logger_1.logger.warn(lang_1.lang.__('SHOW_SAAS_BACKEND_FALLBACK', { error: String(error) }));
|
|
199
232
|
}
|
|
200
233
|
else {
|
|
201
|
-
logger_1.logger.warn(
|
|
234
|
+
logger_1.logger.warn(lang_1.lang.__('SHOW_REMOTE_BACKEND_FALLBACK', { error: String(error) }));
|
|
202
235
|
}
|
|
203
236
|
state = loadLocalState(context.provider, context.app, context.service, stage, baseDir);
|
|
237
|
+
// A local copy of a MIGRATED state is stale by definition — showing it
|
|
238
|
+
// after a remote failure would mislead the user (decision D-3/D-4).
|
|
239
|
+
if ((0, migrationMarker_1.isMigratedToSaas)(state)) {
|
|
240
|
+
throw new Error(lang_1.lang.__('MIGRATION_MARKER_REFUSED'), { cause: error });
|
|
241
|
+
}
|
|
204
242
|
lockInfo = readLocalLock(context.app, context.service, baseDir);
|
|
205
243
|
stateLocation = (0, common_1.getStatePath)(context.app, context.service, baseDir);
|
|
206
244
|
}
|
|
245
|
+
stateLocationDisplay =
|
|
246
|
+
stateLocation === SAAS_STATE_LOCATION ? lang_1.lang.__('SHOW_BACKEND_SAAS') : stateLocation;
|
|
207
247
|
}
|
|
208
248
|
else {
|
|
209
249
|
state = loadLocalState(context.provider, context.app, context.service, stage, baseDir);
|
|
210
250
|
lockInfo = readLocalLock(context.app, context.service, baseDir);
|
|
211
251
|
stateLocation = (0, common_1.getStatePath)(context.app, context.service, baseDir);
|
|
252
|
+
stateLocationDisplay = stateLocation;
|
|
212
253
|
}
|
|
213
254
|
const resources = state.resources;
|
|
214
255
|
const resourceCount = Object.keys(resources).length;
|
|
256
|
+
if (options.json) {
|
|
257
|
+
const backendKind = !usingRemoteBackend
|
|
258
|
+
? 'local'
|
|
259
|
+
: backendType === backend_1.StateBackendType.BUCKET_STORE
|
|
260
|
+
? 'bucket_store'
|
|
261
|
+
: 'saas';
|
|
262
|
+
const payload = {
|
|
263
|
+
showVersion: jsonOutput_1.SHOW_JSON_VERSION,
|
|
264
|
+
provider: state.provider,
|
|
265
|
+
app: state.app,
|
|
266
|
+
service: state.service,
|
|
267
|
+
stage,
|
|
268
|
+
...(state.serial !== undefined ? { serial: state.serial } : {}),
|
|
269
|
+
...(state.lineage !== undefined ? { lineage: state.lineage } : {}),
|
|
270
|
+
...(state.managedBy !== undefined ? { managedBy: state.managedBy } : {}),
|
|
271
|
+
stateLocation,
|
|
272
|
+
backend: backendKind,
|
|
273
|
+
locked: !!lockInfo,
|
|
274
|
+
lock: lockInfo ? { ...lockInfo } : null,
|
|
275
|
+
resources: resources,
|
|
276
|
+
resourceCount,
|
|
277
|
+
};
|
|
278
|
+
(0, jsonOutput_1.writeJson)(payload);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
215
281
|
if (resourceCount === 0) {
|
|
216
|
-
logger_1.logger.info(
|
|
282
|
+
logger_1.logger.info(lang_1.lang.__('SHOW_NO_RESOURCES'));
|
|
217
283
|
logger_1.logger.info('');
|
|
218
|
-
logger_1.logger.info(
|
|
284
|
+
logger_1.logger.info(lang_1.lang.__('SHOW_STATE_LOCATION', { stateLocation: stateLocationDisplay }));
|
|
219
285
|
if (usingRemoteBackend) {
|
|
220
|
-
logger_1.logger.info('
|
|
286
|
+
logger_1.logger.info(lang_1.lang.__('SHOW_BACKEND_REMOTE'));
|
|
221
287
|
}
|
|
222
288
|
logger_1.logger.info('');
|
|
223
|
-
logger_1.logger.info('
|
|
289
|
+
logger_1.logger.info(lang_1.lang.__('SHOW_DEPLOY_HINT'));
|
|
224
290
|
return;
|
|
225
291
|
}
|
|
226
292
|
logger_1.logger.info('');
|
|
227
293
|
logger_1.logger.info('═'.repeat(60));
|
|
228
|
-
logger_1.logger.info('
|
|
294
|
+
logger_1.logger.info(lang_1.lang.__('SHOW_HEADER_DEPLOYED'));
|
|
229
295
|
logger_1.logger.info('═'.repeat(60));
|
|
230
296
|
const groupedResources = {};
|
|
231
297
|
for (const [logicalId, resource] of Object.entries(resources)) {
|
|
@@ -252,19 +318,19 @@ const show = async (options) => {
|
|
|
252
318
|
}
|
|
253
319
|
const categoryOrder = ['functions', 'apiGateway', 'storage', 'databases', 'dns', 'other'];
|
|
254
320
|
const categoryLabels = {
|
|
255
|
-
functions: '
|
|
256
|
-
apiGateway: '
|
|
257
|
-
storage: '
|
|
258
|
-
databases: '
|
|
259
|
-
dns: '
|
|
260
|
-
other: '
|
|
321
|
+
functions: lang_1.lang.__('SHOW_CAT_FUNCTIONS'),
|
|
322
|
+
apiGateway: lang_1.lang.__('SHOW_CAT_API_GATEWAY'),
|
|
323
|
+
storage: lang_1.lang.__('SHOW_CAT_STORAGE'),
|
|
324
|
+
databases: lang_1.lang.__('SHOW_CAT_DATABASES'),
|
|
325
|
+
dns: lang_1.lang.__('SHOW_CAT_DNS'),
|
|
326
|
+
other: lang_1.lang.__('SHOW_CAT_OTHER'),
|
|
261
327
|
};
|
|
262
328
|
for (const category of categoryOrder) {
|
|
263
329
|
const resourcesInCategory = groupedResources[category];
|
|
264
330
|
if (!resourcesInCategory || resourcesInCategory.length === 0)
|
|
265
331
|
continue;
|
|
266
332
|
logger_1.logger.info('');
|
|
267
|
-
logger_1.logger.info(
|
|
333
|
+
logger_1.logger.info(lang_1.lang.__('SHOW_CATEGORY_HEADER', { label: categoryLabels[category] }));
|
|
268
334
|
logger_1.logger.info('─'.repeat(40));
|
|
269
335
|
for (const [logicalId, resource] of resourcesInCategory) {
|
|
270
336
|
const lines = formatResourceOutput(logicalId, resource);
|
|
@@ -275,14 +341,14 @@ const show = async (options) => {
|
|
|
275
341
|
}
|
|
276
342
|
logger_1.logger.info('');
|
|
277
343
|
logger_1.logger.info('═'.repeat(60));
|
|
278
|
-
logger_1.logger.info('
|
|
344
|
+
logger_1.logger.info(lang_1.lang.__('SHOW_HEADER_SUMMARY'));
|
|
279
345
|
logger_1.logger.info('═'.repeat(60));
|
|
280
346
|
logger_1.logger.info('');
|
|
281
|
-
logger_1.logger.info(
|
|
282
|
-
logger_1.logger.info(
|
|
283
|
-
logger_1.logger.info(
|
|
284
|
-
logger_1.logger.info(
|
|
285
|
-
logger_1.logger.info(
|
|
347
|
+
logger_1.logger.info(lang_1.lang.__('SHOW_SUMMARY_PROVIDER', { value: state.provider }));
|
|
348
|
+
logger_1.logger.info(lang_1.lang.__('SHOW_SUMMARY_APP', { value: state.app }));
|
|
349
|
+
logger_1.logger.info(lang_1.lang.__('SHOW_SUMMARY_SERVICE', { value: state.service }));
|
|
350
|
+
logger_1.logger.info(lang_1.lang.__('SHOW_SUMMARY_STAGE', { value: stage }));
|
|
351
|
+
logger_1.logger.info(lang_1.lang.__('SHOW_SUMMARY_RESOURCES', { value: String(resourceCount) }));
|
|
286
352
|
if (Object.keys(resources).length > 0) {
|
|
287
353
|
const lastUpdated = Object.values(resources).reduce((latest, r) => {
|
|
288
354
|
if (!r.lastUpdated)
|
|
@@ -292,19 +358,19 @@ const show = async (options) => {
|
|
|
292
358
|
return r.lastUpdated > latest ? r.lastUpdated : latest;
|
|
293
359
|
}, undefined);
|
|
294
360
|
if (lastUpdated) {
|
|
295
|
-
logger_1.logger.info(
|
|
361
|
+
logger_1.logger.info(lang_1.lang.__('SHOW_SUMMARY_LAST_UPDATED', { value: formatTimeAgo(lastUpdated) }));
|
|
296
362
|
}
|
|
297
363
|
}
|
|
298
364
|
logger_1.logger.info('');
|
|
299
|
-
logger_1.logger.info(
|
|
365
|
+
logger_1.logger.info(lang_1.lang.__('SHOW_STATE_LOCATION', { stateLocation: stateLocationDisplay }));
|
|
300
366
|
if (usingRemoteBackend) {
|
|
301
|
-
logger_1.logger.info('
|
|
367
|
+
logger_1.logger.info(lang_1.lang.__('SHOW_BACKEND_REMOTE'));
|
|
302
368
|
}
|
|
303
369
|
if (lockInfo) {
|
|
304
|
-
logger_1.logger.info(
|
|
370
|
+
logger_1.logger.info(lang_1.lang.__('SHOW_LOCKED_BY', { user: lockInfo.user || 'unknown' }));
|
|
305
371
|
}
|
|
306
372
|
else {
|
|
307
|
-
logger_1.logger.info('
|
|
373
|
+
logger_1.logger.info(lang_1.lang.__('SHOW_UNLOCKED'));
|
|
308
374
|
}
|
|
309
375
|
};
|
|
310
376
|
exports.show = show;
|
|
@@ -3,13 +3,45 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.validate = void 0;
|
|
4
4
|
const common_1 = require("../common");
|
|
5
5
|
const parser_1 = require("../parser");
|
|
6
|
+
const validator_1 = require("../validator");
|
|
7
|
+
const jsonOutput_1 = require("../common/jsonOutput");
|
|
6
8
|
const lang_1 = require("../lang");
|
|
7
9
|
const validate = async (options) => {
|
|
8
10
|
const iacLocation = (0, common_1.getIacLocation)(options.location);
|
|
11
|
+
if (options.json) {
|
|
12
|
+
try {
|
|
13
|
+
await runValidation(iacLocation, options);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (error instanceof validator_1.IacSchemaErrors) {
|
|
17
|
+
(0, jsonOutput_1.writeJson)({
|
|
18
|
+
validateVersion: jsonOutput_1.VALIDATE_JSON_VERSION,
|
|
19
|
+
valid: false,
|
|
20
|
+
errors: error.errors.map((schemaError) => ({
|
|
21
|
+
path: schemaError.instancePath,
|
|
22
|
+
keyword: schemaError.type,
|
|
23
|
+
message: schemaError.message,
|
|
24
|
+
...(schemaError.allowedValues && schemaError.allowedValues.length > 0
|
|
25
|
+
? { allowedValues: schemaError.allowedValues }
|
|
26
|
+
: {}),
|
|
27
|
+
})),
|
|
28
|
+
});
|
|
29
|
+
return { valid: false };
|
|
30
|
+
}
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
common_1.logger.info(lang_1.lang.__('YAML_VALID'));
|
|
34
|
+
(0, jsonOutput_1.writeJson)({ validateVersion: jsonOutput_1.VALIDATE_JSON_VERSION, valid: true, errors: [] });
|
|
35
|
+
return { valid: true };
|
|
36
|
+
}
|
|
37
|
+
await runValidation(iacLocation, options);
|
|
38
|
+
common_1.logger.info(lang_1.lang.__('YAML_VALID'));
|
|
39
|
+
return { valid: true };
|
|
40
|
+
};
|
|
41
|
+
exports.validate = validate;
|
|
42
|
+
const runValidation = async (iacLocation, options) => {
|
|
9
43
|
const rawIac = (0, parser_1.parseYaml)(iacLocation);
|
|
10
44
|
await (0, common_1.setContext)({ app: rawIac.app, service: rawIac.service, ...options });
|
|
11
45
|
const context = (0, common_1.getContext)();
|
|
12
46
|
(0, parser_1.parseYaml)(context.iacLocation);
|
|
13
|
-
common_1.logger.info(lang_1.lang.__('YAML_VALID'));
|
|
14
47
|
};
|
|
15
|
-
exports.validate = validate;
|