@geek-fun/serverlessinsight 0.9.4 → 0.9.6
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 +44 -0
- package/README.md +26 -6
- package/README.zh-CN.md +26 -6
- package/codecov +0 -0
- package/codecov.SHA256SUM +1 -1
- package/codecov.SHA256SUM.sig +13 -13
- package/dist/package.json +1 -1
- 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 +14 -4
- package/dist/src/commands/migrate.js +105 -132
- package/dist/src/commands/plan.js +2 -2
- 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/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/iacHelper.js +2 -2
- 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 +43 -2
- package/dist/src/lang/zh-CN.js +43 -2
- package/dist/src/parser/index.js +33 -8
- package/dist/src/parser/templateValues.js +31 -0
- 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/index.js +3 -1
- package/dist/src/validator/rootSchema.js +8 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/release-notes.md +8 -36
- package/samples/README_TENCENT_COS.md +65 -23
- package/samples/README_TENCENT_SCF.md +44 -26
- 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
|
@@ -3,11 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getRoleArnFromState = exports.removeSharedResource = exports.setSharedResource = exports.getSharedResource = exports.getAllSharedResources = exports.getAllResources = exports.removeResource = exports.setResource = exports.getResource = exports.saveStateWithLock = exports.patchPersistedState = exports.writeStateFileAtomically = exports.saveState = exports.loadState = exports.toPersistedState = exports.migrateState = exports.clearStateMigrations = exports.registerStateMigration = exports.ensureStateDir = exports.getStatePath = void 0;
|
|
6
|
+
exports.getRoleArnFromState = exports.removeSharedResource = exports.setSharedResource = exports.getSharedResource = exports.getAllSharedResources = exports.getAllResources = exports.removeResource = exports.setResource = exports.getResource = exports.validateScopedDocument = exports.emptyScopedState = exports.saveStateWithLock = exports.patchPersistedState = exports.writeStateFileAtomically = exports.saveState = exports.loadState = exports.toPersistedState = exports.migrateState = exports.clearStateMigrations = exports.registerStateMigration = exports.ensureStateDir = exports.getStatePath = void 0;
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
8
|
const node_path_1 = __importDefault(require("node:path"));
|
|
9
9
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
10
10
|
const types_1 = require("../types");
|
|
11
|
+
const stateScope_1 = require("./stateScope");
|
|
12
|
+
const aggregateState_1 = require("./aggregateState");
|
|
11
13
|
const lockManager_1 = require("./lockManager");
|
|
12
14
|
const logger_1 = require("./logger");
|
|
13
15
|
const STATE_DIR = '.serverlessinsight';
|
|
@@ -164,6 +166,9 @@ const saveState = (state, app, service, stage, baseDir = process.cwd()) => {
|
|
|
164
166
|
catch {
|
|
165
167
|
// use default
|
|
166
168
|
}
|
|
169
|
+
if (parseStateVersion(existing.version) > parseStateVersion(types_1.CURRENT_STATE_VERSION)) {
|
|
170
|
+
throw new types_1.StateVersionError(existing.version, types_1.CURRENT_STATE_VERSION);
|
|
171
|
+
}
|
|
167
172
|
// Write updated stage resources, preserve all other stages
|
|
168
173
|
const stateToSave = {
|
|
169
174
|
...existing,
|
|
@@ -189,11 +194,11 @@ exports.saveState = saveState;
|
|
|
189
194
|
* Back up the previous state file, then write tmp + fsync + rename. Shared by
|
|
190
195
|
* saveState and patchPersistedState.
|
|
191
196
|
*/
|
|
192
|
-
const writeStateFileAtomically = (statePath, content) => {
|
|
197
|
+
const writeStateFileAtomically = (statePath, content, options = {}) => {
|
|
193
198
|
const tmpPath = `${statePath}.tmp`;
|
|
194
199
|
const backupPath = `${statePath}.backup`;
|
|
195
200
|
try {
|
|
196
|
-
if (node_fs_1.default.existsSync(statePath)) {
|
|
201
|
+
if (options.backup !== false && node_fs_1.default.existsSync(statePath)) {
|
|
197
202
|
node_fs_1.default.copyFileSync(statePath, backupPath);
|
|
198
203
|
}
|
|
199
204
|
const fd = node_fs_1.default.openSync(tmpPath, 'w');
|
|
@@ -245,15 +250,10 @@ const patchPersistedState = (app, service, patch, baseDir = process.cwd()) => {
|
|
|
245
250
|
catch {
|
|
246
251
|
// use default
|
|
247
252
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if (value === undefined) {
|
|
251
|
-
delete patched[key];
|
|
252
|
-
}
|
|
253
|
-
else {
|
|
254
|
-
patched[key] = value;
|
|
255
|
-
}
|
|
253
|
+
if (parseStateVersion(existing.version) > parseStateVersion(types_1.CURRENT_STATE_VERSION)) {
|
|
254
|
+
throw new types_1.StateVersionError(existing.version, types_1.CURRENT_STATE_VERSION);
|
|
256
255
|
}
|
|
256
|
+
const patched = Object.fromEntries(Object.entries({ ...existing, ...patch }).filter(([, value]) => value !== undefined));
|
|
257
257
|
const stateToSave = {
|
|
258
258
|
...patched,
|
|
259
259
|
version: types_1.CURRENT_STATE_VERSION,
|
|
@@ -274,6 +274,33 @@ const saveStateWithLock = async (state, app, service, stage, operation, baseDir
|
|
|
274
274
|
}, options);
|
|
275
275
|
};
|
|
276
276
|
exports.saveStateWithLock = saveStateWithLock;
|
|
277
|
+
const emptyScopedState = (scope) => {
|
|
278
|
+
return (0, aggregateState_1.emptyDeploymentState)(scope);
|
|
279
|
+
};
|
|
280
|
+
exports.emptyScopedState = emptyScopedState;
|
|
281
|
+
const validateScopedDocument = (raw, scope) => {
|
|
282
|
+
const normalized = (0, stateScope_1.normalizeScope)(scope);
|
|
283
|
+
if (raw.version && raw.version !== types_1.CURRENT_STATE_VERSION) {
|
|
284
|
+
throw new types_1.StateVersionError(raw.version, types_1.CURRENT_STATE_VERSION);
|
|
285
|
+
}
|
|
286
|
+
const stored = {
|
|
287
|
+
provider: raw.provider,
|
|
288
|
+
app: raw.app,
|
|
289
|
+
service: raw.service,
|
|
290
|
+
stage: raw.scope?.stage,
|
|
291
|
+
region: raw.scope?.region,
|
|
292
|
+
};
|
|
293
|
+
const matches = stored.provider === normalized.provider &&
|
|
294
|
+
stored.app === normalized.app &&
|
|
295
|
+
stored.service === normalized.service &&
|
|
296
|
+
!!raw.scope &&
|
|
297
|
+
raw.scope.stage === normalized.stage &&
|
|
298
|
+
raw.scope.region.toLowerCase() === normalized.region;
|
|
299
|
+
if (!matches) {
|
|
300
|
+
throw new types_1.StateScopeMismatchError(normalized, stored);
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
exports.validateScopedDocument = validateScopedDocument;
|
|
277
304
|
/* istanbul ignore next */
|
|
278
305
|
const getResource = (state, resourceId) => {
|
|
279
306
|
return state.resources[resourceId];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stateScopeMatches = exports.normalizeScope = exports.canonicalizeRegion = exports.validateScopeKeyPart = void 0;
|
|
4
|
+
const lang_1 = require("../lang");
|
|
5
|
+
const validateScopeKeyPart = (part, label) => {
|
|
6
|
+
if (!part || part.trim().length === 0) {
|
|
7
|
+
throw new Error(lang_1.lang.__('SCOPE_KEY_PART_REQUIRED', { label }));
|
|
8
|
+
}
|
|
9
|
+
if (part.includes('/') ||
|
|
10
|
+
part.includes('\\') ||
|
|
11
|
+
part.includes('..') ||
|
|
12
|
+
part.trim() !== part ||
|
|
13
|
+
part === '.' ||
|
|
14
|
+
part === '..') {
|
|
15
|
+
throw new Error(lang_1.lang.__('SCOPE_KEY_PART_INVALID', { label, part }));
|
|
16
|
+
}
|
|
17
|
+
return part;
|
|
18
|
+
};
|
|
19
|
+
exports.validateScopeKeyPart = validateScopeKeyPart;
|
|
20
|
+
const canonicalizeRegion = (region) => {
|
|
21
|
+
const canonical = (region ?? '').trim().toLowerCase();
|
|
22
|
+
return (0, exports.validateScopeKeyPart)(canonical, 'region');
|
|
23
|
+
};
|
|
24
|
+
exports.canonicalizeRegion = canonicalizeRegion;
|
|
25
|
+
const normalizeScope = (scope) => ({
|
|
26
|
+
provider: (0, exports.validateScopeKeyPart)(scope.provider, 'provider'),
|
|
27
|
+
app: (0, exports.validateScopeKeyPart)(scope.app, 'app'),
|
|
28
|
+
service: (0, exports.validateScopeKeyPart)(scope.service, 'service'),
|
|
29
|
+
stage: (0, exports.validateScopeKeyPart)(scope.stage, 'stage'),
|
|
30
|
+
region: (0, exports.canonicalizeRegion)(scope.region),
|
|
31
|
+
});
|
|
32
|
+
exports.normalizeScope = normalizeScope;
|
|
33
|
+
const stateScopeMatches = (scope, stage, region) => scope.stage === stage && (0, exports.canonicalizeRegion)(scope.region) === (0, exports.canonicalizeRegion)(region);
|
|
34
|
+
exports.stateScopeMatches = stateScopeMatches;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createLocalStateIO = void 0;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const stateManager_1 = require("./stateManager");
|
|
10
|
+
const createLocalStateIO = (options = {}) => ({
|
|
11
|
+
read: async (key) => {
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(node_fs_1.default.readFileSync(key, 'utf-8'));
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (error.code === 'ENOENT')
|
|
17
|
+
return null;
|
|
18
|
+
throw error;
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
write: async (key, data) => {
|
|
22
|
+
node_fs_1.default.mkdirSync(node_path_1.default.dirname(key), { recursive: true });
|
|
23
|
+
if (options.backupWrites === false) {
|
|
24
|
+
(0, stateManager_1.writeStateFileAtomically)(key, JSON.stringify(data, null, 2), { backup: false });
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
(0, stateManager_1.writeStateFileAtomically)(key, JSON.stringify(data, null, 2));
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
exports.createLocalStateIO = createLocalStateIO;
|
package/dist/src/lang/en.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.en = void 0;
|
|
4
4
|
exports.en = {
|
|
5
|
+
STATE_STORAGE_PROVIDER_UNSUPPORTED: 'State storage does not support provider {{provider}}. Configure storageProvider as aliyun or tencent.',
|
|
5
6
|
PLAN_SENSITIVE_VALUE: '(sensitive)',
|
|
6
7
|
PLAN_NAS_NETWORK_REQUIRED: 'NAS storage on {{logicalId}} needs a declared VPC network or recorded mount targets. Planning stopped before creating any resources.',
|
|
7
8
|
APIGW_DOMAIN_READ_INVALID: 'Invalid domain response for: {{domainId}}',
|
|
@@ -864,7 +865,6 @@ exports.en = {
|
|
|
864
865
|
MIGRATE_UPLOADED: ' ✓ stage {{stage}} → version {{version}}{{deduped}} (app {{appId}}, service {{serviceId}})',
|
|
865
866
|
MIGRATE_UPLOADED_DEDUPLICATED: ' (unchanged, deduplicated)',
|
|
866
867
|
MIGRATE_VERIFY_FAILED: 'Read-back verification FAILED for stage {{stage}} — the migration marker was NOT written. Compare the Console state version with your legacy state, then re-run `si migrate`.',
|
|
867
|
-
MIGRATE_CONFLICT: 'The target stage already has Console state. Re-run with --force to adopt it as a new imported version (history is kept).',
|
|
868
868
|
MIGRATE_MARKER_WRITTEN: 'Migration marker written: the legacy state is now read-only (managedBy=saas).',
|
|
869
869
|
MIGRATE_MARKER_SKIPPED: 'WARNING: --no-marker was set. The legacy backend stays writable until cutover — complete the YAML cutover immediately.',
|
|
870
870
|
MIGRATE_ROLLBACK_NO_MARKER: 'No migration marker found on the legacy state — nothing to roll back.',
|
|
@@ -873,7 +873,48 @@ exports.en = {
|
|
|
873
873
|
MIGRATE_CUTOVER_STEPS: 'Cutover checklist:\n 1. Remove the backend.state_manager block from serverlessinsight.yml, add a top-level org declaration (org: <slug> — see your org settings in Console), and merge\n 2. Run `si diff` — it MUST report no changes and exit 0 (that is the proof of a lossless migration)\n 3. Resume deploys; the Console now owns the deployment timeline',
|
|
874
874
|
MIGRATION_MARKER_REFUSED: 'This state has been migrated to the ServerlessInsight Console (managedBy=saas) and the legacy backend is closed for changes.\n • To continue with the Console: remove the backend.state_manager block from your YAML, declare a top-level org: <slug>, then deploy again.\n • To deliberately use the legacy backend: run `si migrate --rollback` to clear the marker.',
|
|
875
875
|
MIGRATION_MARKER_WARN: 'This state has been migrated to the Console (managedBy=saas) — the copy shown here is read-only and may be stale. Do not deploy from this backend.',
|
|
876
|
-
|
|
876
|
+
SCOPE_KEY_PART_REQUIRED: "'{{label}}' is required and must not be empty",
|
|
877
|
+
SCOPE_KEY_PART_INVALID: "'{{label}}' value '{{part}}' is not path-safe: it must not be empty, contain '/', '\\', '..' or leading/trailing whitespace",
|
|
878
|
+
EFFECTIVE_CONFIG_UNKNOWN_PROVIDER: "Unknown provider '{{provider}}'. Supported providers: aliyun, tencent, volcengine, huawei, aws",
|
|
879
|
+
EFFECTIVE_CONFIG_RESOURCE_UNSUPPORTED: "Provider '{{provider}}' cannot deploy '{{resource}}' from this template. Adjust the template before overriding the provider.",
|
|
880
|
+
EFFECTIVE_CONFIG_REGION_REQUIRED: 'A region is required: pass -r/--region, set provider.region in the YAML, or set the SI_REGION environment variable',
|
|
881
|
+
STATE_AGGREGATE_INVALID: 'The aggregate state document is malformed. Restore a verified backup before continuing.',
|
|
882
|
+
STATE_STORE_UPGRADE_REQUIRED: 'State at {{location}} requires an in-place format upgrade. Deploy, destroy and SaaS handoff prepare it automatically before planning or importing.',
|
|
883
|
+
STATE_PARTITION_PATCH_INVALID: 'Only deployment ownership and migration metadata can be patched.',
|
|
884
|
+
STATE_PLAN_BASE_CHANGED: 'The selected deployment state changed after planning. Generate and approve a new plan before continuing.',
|
|
885
|
+
STATE_SCOPED_VERSION_UNSUPPORTED: 'Unsupported state version {{version}}',
|
|
886
|
+
STATE_SCOPED_IDENTITY_MISMATCH: 'State identity does not match the requested deployment scope',
|
|
887
|
+
STATE_SCOPED_IDENTITY_DETAILS_MISMATCH: 'State identity ({{stored}}) does not match the bound deployment scope ({{requested}})',
|
|
888
|
+
STATE_WRITE_NOT_READY: 'Regional state writes are not ready for this deployment scope',
|
|
889
|
+
STATE_BUCKET_NOT_FOUND: 'The state storage bucket does not exist ({{code}}). Create the bucket or fix the backend.state_manager configuration — the missing bucket is not treated as empty state',
|
|
890
|
+
STATE_BUCKET_ACCESS_DENIED: 'Access to the state storage bucket was denied ({{code}}). Check the storage credentials — an authorization failure is never treated as empty state',
|
|
891
|
+
STATE_STORAGE_CREDENTIALS_MISSING: "State storage needs credentials for {{provider}}. Configure that cloud's credential environment variables. Workload credentials from another provider are never reused.",
|
|
892
|
+
LOCK_CONDITIONAL_CREATE_UNSUPPORTED: 'This state storage does not support exclusive (conditional) create — concurrent first lock acquisition falls back to a verified write and is not guaranteed atomic. Avoid running mutating commands for the same scope in parallel',
|
|
893
|
+
SAAS_REGIONAL_SCOPE_UNSUPPORTED: 'The Console at {{consoleUrl}} does not advertise compatible regional deployment states (scope protocol 2 and state format 4.0). Upgrading the CLI alone cannot isolate regions safely — update the Console, or keep using the previous CLI release for unscoped deployments',
|
|
894
|
+
SAAS_STATE_SCOPE_MISMATCH: 'The Console returned state for stage {{storedStage}} / region {{storedRegion}}, but this command targets stage {{stage}} / region {{region}}. Refusing to mix regional scopes',
|
|
895
|
+
SAAS_READ_ONLY_WRITE_REFUSED: 'This SaaS backend instance was created read-only (diff/show); state writes are refused',
|
|
896
|
+
SAAS_WRITE_BLOCKED_UNSCOPED_STATE: "The current state of stage {{stage}} on the Console has no regional scope recorded (it predates regional isolation). Run the Console-side migration for this service before deploying to region {{region}} — writing here would overwrite another region's state",
|
|
897
|
+
REGIONAL_MIGRATION_UNSUPPORTED_SOURCE: 'Expected a legacy V3.0 state aggregate but found version "{{version}}". No V3 upgrade is needed',
|
|
898
|
+
REGIONAL_MIGRATION_SOURCE_MANAGED_BY_SAAS: 'This legacy state has been migrated to (and is owned by) the ServerlessInsight Console (managedBy=saas). An in-place upgrade would create an unmarked local copy and reopen double-write hazards — refused. Continue on the Console backend, or run `si migrate --rollback` first only if you deliberately want to hand ownership back',
|
|
899
|
+
REGIONAL_MIGRATION_INCOMPLETE_STAGE_COVERAGE: 'The automatic upgrade must preserve every resource in every stage. Source coverage is incomplete; review the source and recovery records before retrying.',
|
|
900
|
+
STATE_ATOMIC_CREATE_REQUIRED: 'This state store cannot atomically reserve ownership or acquire a lock. Mutations are refused.',
|
|
901
|
+
REGIONAL_MIGRATION_PENDING: 'State upgrade {{opId}} is incomplete. Re-run the deploy, destroy or migrate operation to resume with the reviewed region binding.',
|
|
902
|
+
SAAS_STATE_BASE_UNKNOWN: 'Load the regional state before saving or starting a deployment.',
|
|
903
|
+
REGIONAL_LOCK_STALE: 'State is currently locked (stale lock detected).\n{{info}}\nIf you are certain no other operation is running, use:\n si force-unlock {{id}}',
|
|
904
|
+
REGIONAL_LOCK_TIMEOUT: 'Failed to acquire lock after {{seconds}} seconds.\n{{info}}',
|
|
905
|
+
REGIONAL_LOCK_FAILED: 'Failed to acquire lock.\n{{path}}',
|
|
906
|
+
MIGRATE_SOURCE_FORMAT_INVALID: 'The source backend did not provide a valid single-deployment V4 view after automatic preparation. Nothing was imported.',
|
|
907
|
+
MIGRATE_TARGET_REGIONAL_REQUIRED: 'The target service still uses legacy state. Complete its Console-side binding and activation before importing a regional state.',
|
|
908
|
+
MIGRATE_SOURCE_MULTIPLE_SCOPES: 'This regional document contains resources from other stages. Resolve the source ownership before importing; one regional document may own only its selected stage.',
|
|
909
|
+
SAAS_STATE_ACK_INVALID: 'The state server did not confirm a valid regional snapshot and content hash. Refusing to guess the next state revision; upgrade the server to scope protocol 2.',
|
|
910
|
+
REGIONAL_MIGRATION_PROVIDER_MISMATCH: 'The source records provider "{{source}}", while the command selects "{{effective}}". The upgrade preserves the source provider; workload overrides never rewrite historical ownership.',
|
|
911
|
+
REGIONAL_MIGRATION_UNKNOWN_REGION_REQUIRED: 'Some resources carry no region evidence (pre-regional state). Re-run with --bind-unknown-region <region> to bind them explicitly to a region — the CLI never guesses historical regions from YAML or filenames',
|
|
912
|
+
REGIONAL_MIGRATION_SOURCE_CHANGED: 'The source state changed during its format upgrade. Refusing to overwrite it; review the source and retained recovery records before retrying.',
|
|
913
|
+
REGIONAL_MIGRATION_APPLIED: 'State upgraded in place (operation {{opId}}). Stage/provider/region partitions now share the original file or Bucket key. Continuing the requested operation.',
|
|
914
|
+
REGIONAL_MIGRATION_PARTIAL_FAILURE: 'State upgrade interrupted (operation {{opId}}): {{error}}. Keep the source backup and journal; re-run the same operation to resume.',
|
|
915
|
+
REGIONAL_MIGRATION_BACKUP_MISSING: 'Original backup for state upgrade {{opId}} is missing; cannot safely resume. Restore that backup before retrying.',
|
|
916
|
+
REGIONAL_MIGRATION_UNKNOWN_ITEM: ' • [{{stage}}] {{logicalId}} ({{kind}})',
|
|
917
|
+
OPT_BIND_UNKNOWN_REGION: 'explicitly bind resources without region evidence to this region',
|
|
877
918
|
HTTP_TRIGGER_AUTH_TYPE_REQUIRED: "HTTP trigger '{{functionName}}' requires 'auth_type' (public or iam)",
|
|
878
919
|
CREATING_HTTP_TRIGGER: "Creating HTTP trigger '{{triggerName}}' for function '{{functionName}}'...",
|
|
879
920
|
HTTP_TRIGGER_CREATED: "HTTP trigger '{{triggerName}}' created for function '{{functionName}}'",
|
package/dist/src/lang/zh-CN.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.zhCN = void 0;
|
|
4
4
|
exports.zhCN = {
|
|
5
|
+
STATE_STORAGE_PROVIDER_UNSUPPORTED: 'State 存储不支持云厂商 {{provider}}。请将 storageProvider 配置为 aliyun 或 tencent。',
|
|
5
6
|
PLAN_SENSITIVE_VALUE: '(敏感值)',
|
|
6
7
|
PLAN_NAS_NETWORK_REQUIRED: '{{logicalId}} 的 NAS 存储需要声明 VPC 网络或已有挂载目标记录。计划已停止,尚未创建任何资源。',
|
|
7
8
|
APIGW_DOMAIN_READ_INVALID: '域名 {{domainId}} 的查询响应无效',
|
|
@@ -856,7 +857,6 @@ exports.zhCN = {
|
|
|
856
857
|
MIGRATE_UPLOADED: ' ✓ stage {{stage}} → 版本 {{version}}{{deduped}}(app {{appId}},service {{serviceId}})',
|
|
857
858
|
MIGRATE_UPLOADED_DEDUPLICATED: '(内容未变,已去重)',
|
|
858
859
|
MIGRATE_VERIFY_FAILED: 'stage {{stage}} 回读校验失败——未写迁移标记。请对比 Console 状态版本与旧状态后重新执行 `si migrate`。',
|
|
859
|
-
MIGRATE_CONFLICT: '目标 stage 在 Console 已有状态。如确认覆盖采纳,请加 --force(将作为新版本导入,历史保留)。',
|
|
860
860
|
MIGRATE_MARKER_WRITTEN: '已写迁移标记:旧状态转为只读(managedBy=saas)。',
|
|
861
861
|
MIGRATE_MARKER_SKIPPED: '警告:使用了 --no-marker。cutover 完成前旧后端仍可写入——请立即完成 YAML 切换。',
|
|
862
862
|
MIGRATE_ROLLBACK_NO_MARKER: '旧状态没有迁移标记——无需回滚。',
|
|
@@ -865,7 +865,48 @@ exports.zhCN = {
|
|
|
865
865
|
MIGRATE_CUTOVER_STEPS: 'cutover 清单:\n 1. 从 serverlessinsight.yml 删除 backend.state_manager 段,并在顶层添加 org 声明(org: <slug>,slug 见 Console 组织设置)后合并\n 2. 运行 `si diff`——必须显示无变更并退出 0(这是迁移无损的证明)\n 3. 恢复部署;此后部署时间线由 Console 接管',
|
|
866
866
|
MIGRATION_MARKER_REFUSED: '该状态已迁移至 ServerlessInsight Console(managedBy=saas),旧后端已关闭变更。\n • 继续使用 Console:从 YAML 中删除 backend.state_manager 段并在顶层声明 org: <slug> 后重新部署。\n • 确需经旧后端操作:运行 `si migrate --rollback` 清除标记。',
|
|
867
867
|
MIGRATION_MARKER_WARN: '该状态已迁移至 Console(managedBy=saas)——此处展示的是只读副本,可能已过期。请勿从该后端部署。',
|
|
868
|
-
|
|
868
|
+
SCOPE_KEY_PART_REQUIRED: "'{{label}}' 必填且不能为空",
|
|
869
|
+
SCOPE_KEY_PART_INVALID: "'{{label}}' 的值 '{{part}}' 不是路径安全的:不能为空,不能包含 '/'、'\\'、'..' 或首尾空白",
|
|
870
|
+
EFFECTIVE_CONFIG_UNKNOWN_PROVIDER: "未知 provider '{{provider}}'。支持的 provider:aliyun、tencent、volcengine、huawei、aws",
|
|
871
|
+
EFFECTIVE_CONFIG_RESOURCE_UNSUPPORTED: "Provider '{{provider}}' 无法部署当前模板中的 '{{resource}}'。请先调整模板,再覆盖 provider。",
|
|
872
|
+
EFFECTIVE_CONFIG_REGION_REQUIRED: '需要指定 region:通过 -r/--region 传入、在 YAML 的 provider.region 中设置,或设置 SI_REGION 环境变量',
|
|
873
|
+
STATE_AGGREGATE_INVALID: '聚合状态文档格式损坏,请先恢复已验证的备份后再继续。',
|
|
874
|
+
STATE_STORE_UPGRADE_REQUIRED: '状态 {{location}} 需要原位置格式升级。deploy、destroy 和 SaaS 交接会在规划或导入前自动完成升级。',
|
|
875
|
+
STATE_PARTITION_PATCH_INVALID: '仅可修改部署归属和迁移元数据。',
|
|
876
|
+
STATE_PLAN_BASE_CHANGED: '目标部署状态在规划后发生变化,请重新生成并批准计划后再继续。',
|
|
877
|
+
STATE_SCOPED_VERSION_UNSUPPORTED: '不支持的状态版本 {{version}}',
|
|
878
|
+
STATE_SCOPED_IDENTITY_MISMATCH: '状态身份与请求的部署作用域不匹配',
|
|
879
|
+
STATE_SCOPED_IDENTITY_DETAILS_MISMATCH: '状态身份({{stored}})与绑定的部署作用域({{requested}})不匹配',
|
|
880
|
+
STATE_WRITE_NOT_READY: '当前部署范围的状态写入尚未就绪',
|
|
881
|
+
STATE_BUCKET_NOT_FOUND: '状态存储 bucket 不存在({{code}})。请创建 bucket 或修正 backend.state_manager 配置——bucket 缺失不会被当作空状态',
|
|
882
|
+
STATE_BUCKET_ACCESS_DENIED: '状态存储 bucket 访问被拒绝({{code}})。请检查存储凭据——鉴权失败永远不会被当作空状态',
|
|
883
|
+
STATE_STORAGE_CREDENTIALS_MISSING: 'State 存储需要 {{provider}} 的凭证。请配置该云厂商的凭证环境变量,不会复用其他云厂商的业务部署凭证。',
|
|
884
|
+
LOCK_CONDITIONAL_CREATE_UNSUPPORTED: '当前状态存储不支持排他(条件)创建——并发首次加锁将回退为"写入后校验",不保证原子性。请避免对同一 scope 并行执行变更命令',
|
|
885
|
+
SAAS_REGIONAL_SCOPE_UNSUPPORTED: 'Console({{consoleUrl}})尚不支持区域部署状态(缺少 scope protocol 能力)。仅升级 CLI 无法安全隔离区域——请升级 Console,或在未隔离部署场景下继续使用旧版 CLI',
|
|
886
|
+
SAAS_STATE_SCOPE_MISMATCH: 'Console 返回的是 stage {{storedStage}} / region {{storedRegion}} 的状态,但本次命令目标是 stage {{stage}} / region {{region}}。拒绝混用区域 scope',
|
|
887
|
+
SAAS_READ_ONLY_WRITE_REFUSED: '该 SaaS 后端实例以只读模式创建(diff/show),拒绝状态写入',
|
|
888
|
+
SAAS_WRITE_BLOCKED_UNSCOPED_STATE: 'Console 上 stage {{stage}} 的当前状态没有记录区域 scope(早于区域隔离)。请先在 Console 侧完成该服务的迁移,再向 region {{region}} 部署——直接写入会覆盖其他区域的状态',
|
|
889
|
+
REGIONAL_MIGRATION_UNSUPPORTED_SOURCE: '期望旧版 V3.0 状态聚合,但发现版本 "{{version}}"。没有可升级的内容',
|
|
890
|
+
REGIONAL_MIGRATION_SOURCE_MANAGED_BY_SAAS: '该旧版状态已迁移至(并归)ServerlessInsight Console 所有(managedBy=saas)。状态升级会生成无标记的本地副本,重新引入双写风险——已拒绝。请继续使用 Console 后端;或仅在你明确要交还所有权时先运行 `si migrate --rollback`',
|
|
891
|
+
REGIONAL_MIGRATION_INCOMPLETE_STAGE_COVERAGE: '自动升级必须保留所有 stage 中的每个资源。当前源数据覆盖不完整,请核对源状态和恢复记录后再重试。',
|
|
892
|
+
STATE_ATOMIC_CREATE_REQUIRED: '此状态存储无法原子登记所有权或获取锁,已拒绝变更。',
|
|
893
|
+
REGIONAL_MIGRATION_PENDING: 'State 升级 {{opId}} 尚未完成。请使用已审查的区域绑定重新执行 deploy、destroy 或 migrate 以继续。',
|
|
894
|
+
SAAS_STATE_BASE_UNKNOWN: '请先读取区域状态,再保存或开始部署。',
|
|
895
|
+
REGIONAL_LOCK_STALE: '状态已锁定(检测到可能过期的锁)。\n{{info}}\n确认没有其他操作正在运行后,可执行:\n si force-unlock {{id}}',
|
|
896
|
+
REGIONAL_LOCK_TIMEOUT: '等待 {{seconds}} 秒后仍无法获取锁。\n{{info}}',
|
|
897
|
+
REGIONAL_LOCK_FAILED: '无法获取锁。\n{{path}}',
|
|
898
|
+
MIGRATE_SOURCE_FORMAT_INVALID: '源后端在自动准备后未提供有效的单部署 V4 视图,尚未导入任何状态。',
|
|
899
|
+
MIGRATE_TARGET_REGIONAL_REQUIRED: '目标服务仍使用旧版状态。请先完成控制台侧的区域绑定和激活,再导入区域状态。',
|
|
900
|
+
MIGRATE_SOURCE_MULTIPLE_SCOPES: '此区域状态文档还包含其他 stage 的资源。请先核实源状态的归属,再导入;一个区域文档只能管理选定 stage 的资源。',
|
|
901
|
+
SAAS_STATE_ACK_INVALID: '状态服务未确认有效的区域快照和内容哈希。已拒绝推测下一版本,请升级服务端以支持作用域协议 2。',
|
|
902
|
+
REGIONAL_MIGRATION_PROVIDER_MISMATCH: '源状态记录的 provider 为 "{{source}}",命令选择的是 "{{effective}}"。升级保留源 provider,业务部署参数不会重写历史资源归属。',
|
|
903
|
+
REGIONAL_MIGRATION_UNKNOWN_REGION_REQUIRED: '部分资源没有区域证据(早于区域隔离的状态)。请使用 --bind-unknown-region <region> 重新运行以显式绑定区域——CLI 绝不会从 YAML 或文件名猜测历史区域',
|
|
904
|
+
REGIONAL_MIGRATION_SOURCE_CHANGED: '格式升级期间源状态发生了变化。为避免覆盖已有状态,请先核对源状态和保留的恢复记录,再重试原操作。',
|
|
905
|
+
REGIONAL_MIGRATION_APPLIED: 'State 已在原位置升级(操作 {{opId}})。各 stage/provider/region 分区共用原文件或 Bucket key。继续处理当前操作。',
|
|
906
|
+
REGIONAL_MIGRATION_PARTIAL_FAILURE: 'State 升级中断(操作 {{opId}}):{{error}}。请保留源备份和迁移记录,重新运行同一操作以继续。',
|
|
907
|
+
REGIONAL_MIGRATION_BACKUP_MISSING: 'State 升级 {{opId}} 的原始备份缺失,无法安全恢复。请先恢复该备份,再重试原操作。',
|
|
908
|
+
REGIONAL_MIGRATION_UNKNOWN_ITEM: ' • [{{stage}}] {{logicalId}}({{kind}})',
|
|
909
|
+
OPT_BIND_UNKNOWN_REGION: '将没有区域证据的资源显式绑定到该区域',
|
|
869
910
|
HTTP_TRIGGER_AUTH_TYPE_REQUIRED: "HTTP 触发器 '{{functionName}}' 需要设置 'auth_type'(public 或 iam)",
|
|
870
911
|
CREATING_HTTP_TRIGGER: "正在为函数 '{{functionName}}' 创建 HTTP 触发器 '{{triggerName}}'...",
|
|
871
912
|
HTTP_TRIGGER_CREATED: "HTTP 触发器 '{{triggerName}}' 已为函数 '{{functionName}}' 创建成功",
|
package/dist/src/parser/index.js
CHANGED
|
@@ -11,6 +11,7 @@ const yaml_1 = require("yaml");
|
|
|
11
11
|
const validator_1 = require("../validator");
|
|
12
12
|
const bucketParser_1 = require("./bucketParser");
|
|
13
13
|
const tableParser_1 = require("./tableParser");
|
|
14
|
+
const templateValues_1 = require("./templateValues");
|
|
14
15
|
const common_1 = require("../common");
|
|
15
16
|
const lang_1 = require("../lang");
|
|
16
17
|
const validateExistence = (path) => {
|
|
@@ -33,6 +34,8 @@ const parseBackend = (raw) => {
|
|
|
33
34
|
type: types_1.StateBackendType.BUCKET_STORE,
|
|
34
35
|
bucket: stateManager.bucket,
|
|
35
36
|
key: stateManager.key,
|
|
37
|
+
...(stateManager.storageRegion ? { storageRegion: stateManager.storageRegion } : {}),
|
|
38
|
+
...(stateManager.storageProvider ? { storageProvider: stateManager.storageProvider } : {}),
|
|
36
39
|
};
|
|
37
40
|
}
|
|
38
41
|
if (type === types_1.StateBackendType.SAAS) {
|
|
@@ -65,18 +68,38 @@ const parseYaml = (iacLocation) => {
|
|
|
65
68
|
return transformYaml(iacJson);
|
|
66
69
|
};
|
|
67
70
|
exports.parseYaml = parseYaml;
|
|
68
|
-
const evaluateObject = (obj, ctx, iacVars) => {
|
|
71
|
+
const evaluateObject = (obj, ctx, iacVars, path = []) => {
|
|
69
72
|
if (typeof obj === 'string') {
|
|
70
|
-
return (0, common_1.calcValue)(obj, ctx, iacVars);
|
|
73
|
+
return (0, common_1.calcValue)(obj, ctx, iacVars, !(0, templateValues_1.isStringTemplateField)(path));
|
|
71
74
|
}
|
|
72
75
|
if (Array.isArray(obj)) {
|
|
73
|
-
return obj.map((item) => evaluateObject(item, ctx, iacVars));
|
|
76
|
+
return obj.map((item, index) => evaluateObject(item, ctx, iacVars, [...path, index]));
|
|
74
77
|
}
|
|
75
78
|
if (typeof obj === 'object' && obj !== null) {
|
|
76
|
-
return Object.fromEntries(Object.entries(obj).map(([key, val]) => [
|
|
79
|
+
return Object.fromEntries(Object.entries(obj).map(([key, val]) => [
|
|
80
|
+
key,
|
|
81
|
+
evaluateObject(val, ctx, iacVars, [...path, key]),
|
|
82
|
+
]));
|
|
77
83
|
}
|
|
78
84
|
return obj;
|
|
79
85
|
};
|
|
86
|
+
const assertProviderOverrideResources = (iac) => {
|
|
87
|
+
const provider = iac.provider.name;
|
|
88
|
+
const unsupportedSections = provider === 'tencent'
|
|
89
|
+
? ['events', 'tables']
|
|
90
|
+
: provider === 'volcengine'
|
|
91
|
+
? ['databases', 'tables']
|
|
92
|
+
: [];
|
|
93
|
+
const unsupportedSection = unsupportedSections.find((section) => Object.keys(iac[section] ?? {}).length > 0);
|
|
94
|
+
const unsupportedDatabase = Object.entries(iac.databases ?? {}).find(([, database]) => provider === 'aliyun'
|
|
95
|
+
? database.type === 'TDSQL_C_SERVERLESS'
|
|
96
|
+
: provider === 'tencent'
|
|
97
|
+
? !['TDSQL_C_SERVERLESS', 'ELASTICSEARCH_SERVERLESS'].includes(database.type)
|
|
98
|
+
: false);
|
|
99
|
+
const resource = unsupportedSection ?? (unsupportedDatabase ? `databases.${unsupportedDatabase[0]}` : undefined);
|
|
100
|
+
if (resource)
|
|
101
|
+
throw new Error(lang_1.lang.__('EFFECTIVE_CONFIG_RESOURCE_UNSUPPORTED', { provider, resource }));
|
|
102
|
+
};
|
|
80
103
|
const revalYaml = (iacLocation, ctx) => {
|
|
81
104
|
validateExistence(iacLocation);
|
|
82
105
|
const yamlContent = (0, node_fs_1.readFileSync)(iacLocation, 'utf8');
|
|
@@ -86,12 +109,14 @@ const revalYaml = (iacLocation, ctx) => {
|
|
|
86
109
|
app: iacJson.app,
|
|
87
110
|
service: iacJson.service,
|
|
88
111
|
version: iacJson.version,
|
|
89
|
-
provider: { ...iacJson.provider, name:
|
|
112
|
+
provider: { ...iacJson.provider, name: ctx.provider, region: ctx.region },
|
|
90
113
|
};
|
|
91
|
-
// staticFields are spread in before evaluation (identity fields are not template strings,
|
|
92
|
-
// so this is a no-op) and again after to ensure evaluateObject never mangles them.
|
|
93
114
|
const evaluatedIacJson = evaluateObject({ ...iacJson, ...staticFields }, ctx, iacJson.vars);
|
|
94
|
-
const
|
|
115
|
+
const resolved = { ...evaluatedIacJson, ...staticFields };
|
|
116
|
+
(0, validator_1.validateYaml)(resolved);
|
|
117
|
+
if (iacJson.provider.name !== ctx.provider)
|
|
118
|
+
assertProviderOverrideResources(resolved);
|
|
119
|
+
const iac = transformYaml(resolved, ctx.stage);
|
|
95
120
|
if (iac.functions) {
|
|
96
121
|
iac.functions = iac.functions.map((fn) => ({
|
|
97
122
|
...fn,
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isStringTemplateField = void 0;
|
|
4
|
+
const validator_1 = require("../validator");
|
|
5
|
+
let document;
|
|
6
|
+
const getDocument = () => (document ??= (0, validator_1.exportIacJsonSchema)());
|
|
7
|
+
const expandSchema = (schema) => {
|
|
8
|
+
const reference = schema.$ref && getDocument().definitions?.[schema.$ref.split('/').pop()];
|
|
9
|
+
if (reference)
|
|
10
|
+
return expandSchema(reference);
|
|
11
|
+
return [
|
|
12
|
+
schema,
|
|
13
|
+
...[...(schema.oneOf ?? []), ...(schema.anyOf ?? []), ...(schema.allOf ?? [])].flatMap(expandSchema),
|
|
14
|
+
];
|
|
15
|
+
};
|
|
16
|
+
const childSchemas = (schema, key) => {
|
|
17
|
+
if (typeof key === 'number')
|
|
18
|
+
return schema.items ? [schema.items] : [];
|
|
19
|
+
const property = schema.properties?.[key];
|
|
20
|
+
const patterns = Object.entries(schema.patternProperties ?? {})
|
|
21
|
+
.filter(([pattern]) => new RegExp(pattern).test(key))
|
|
22
|
+
.map(([, value]) => value);
|
|
23
|
+
if (property || patterns.length)
|
|
24
|
+
return [...(property ? [property] : []), ...patterns];
|
|
25
|
+
return typeof schema.additionalProperties === 'object' ? [schema.additionalProperties] : [];
|
|
26
|
+
};
|
|
27
|
+
const isStringTemplateField = (path) => path
|
|
28
|
+
.reduce((schemas, key) => schemas.flatMap(expandSchema).flatMap((schema) => childSchemas(schema, key)), [getDocument()])
|
|
29
|
+
.flatMap(expandSchema)
|
|
30
|
+
.some((schema) => schema.type === 'string' && schema.pattern !== validator_1.templateRefSchema.pattern);
|
|
31
|
+
exports.isStringTemplateField = isStringTemplateField;
|
|
@@ -14,8 +14,8 @@ const tablestorePlanner_1 = require("./tablestorePlanner");
|
|
|
14
14
|
const tablestoreExecutor_1 = require("./tablestoreExecutor");
|
|
15
15
|
const apigwPlanner_1 = require("./apigwPlanner");
|
|
16
16
|
const apigwExecutor_1 = require("./apigwExecutor");
|
|
17
|
-
const createSaveStateFn = (backend
|
|
18
|
-
await backend.saveState(state
|
|
17
|
+
const createSaveStateFn = (backend) => async (state) => {
|
|
18
|
+
await backend.saveState(state);
|
|
19
19
|
};
|
|
20
20
|
const handlePartialFailure = (failure) => {
|
|
21
21
|
const error = failure.error;
|
|
@@ -84,8 +84,8 @@ const deployAliyunStack = async (iac, backend, approvedPlan) => {
|
|
|
84
84
|
// Cache IAC for access throughout the deployment
|
|
85
85
|
(0, common_1.setIac)(iac);
|
|
86
86
|
common_1.logger.info(lang_1.lang.__('DEPLOYING_STACK_PUBLISHING_ASSETS'));
|
|
87
|
-
let state = await backend.loadState(
|
|
88
|
-
const onStateChange = createSaveStateFn(backend
|
|
87
|
+
let state = await backend.loadState();
|
|
88
|
+
const onStateChange = createSaveStateFn(backend);
|
|
89
89
|
common_1.logger.info(lang_1.lang.__('GENERATING_PLAN'));
|
|
90
90
|
const functionPlan = approvedPlan
|
|
91
91
|
? partitionPlan(approvedPlan, ['ALIYUN_FC3'])
|
|
@@ -184,7 +184,7 @@ const deployAliyunStack = async (iac, backend, approvedPlan) => {
|
|
|
184
184
|
],
|
|
185
185
|
});
|
|
186
186
|
}
|
|
187
|
-
await backend.saveState(state
|
|
187
|
+
await backend.saveState(state);
|
|
188
188
|
common_1.logger.info(lang_1.lang.__('STACK_DEPLOYED'));
|
|
189
189
|
};
|
|
190
190
|
exports.deployAliyunStack = deployAliyunStack;
|
|
@@ -16,8 +16,8 @@ const tablestoreExecutor_1 = require("./tablestoreExecutor");
|
|
|
16
16
|
const apigwPlanner_1 = require("./apigwPlanner");
|
|
17
17
|
const apigwExecutor_1 = require("./apigwExecutor");
|
|
18
18
|
const sharedLogProject_1 = require("./sharedLogProject");
|
|
19
|
-
const createSaveStateFn = (backend
|
|
20
|
-
await backend.saveState(state
|
|
19
|
+
const createSaveStateFn = (backend) => async (state) => {
|
|
20
|
+
await backend.saveState(state);
|
|
21
21
|
};
|
|
22
22
|
const handlePartialFailure = (failure) => {
|
|
23
23
|
const error = failure.error;
|
|
@@ -36,8 +36,8 @@ const collectSuccessfulItems = (results) => results.flatMap((result) => result.p
|
|
|
36
36
|
const destroyAliyunStack = async (backend) => {
|
|
37
37
|
const context = (0, common_1.getContext)();
|
|
38
38
|
const providerName = common_1.ProviderEnum.ALIYUN;
|
|
39
|
-
let state = await backend.loadState(
|
|
40
|
-
const onStateChange = createSaveStateFn(backend
|
|
39
|
+
let state = await backend.loadState();
|
|
40
|
+
const onStateChange = createSaveStateFn(backend);
|
|
41
41
|
// Set minimal IAC for destruction (function resolution not needed)
|
|
42
42
|
(0, common_1.setIac)({
|
|
43
43
|
version: '1.0',
|
|
@@ -142,6 +142,6 @@ const destroyAliyunStack = async (backend) => {
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
}
|
|
145
|
-
await backend.saveState(state
|
|
145
|
+
await backend.saveState(state);
|
|
146
146
|
};
|
|
147
147
|
exports.destroyAliyunStack = destroyAliyunStack;
|
|
@@ -110,7 +110,7 @@ const resolveManagedRoleProbe = (context, fn, currentState) => {
|
|
|
110
110
|
if (iamRole && typeof iamRole === 'object') {
|
|
111
111
|
const serviceName = `${context.app}-${context.service}`;
|
|
112
112
|
return {
|
|
113
|
-
roleName: iamRole.name ?? (0, common_1.buildFunctionRoleName)(serviceName, context.stage, fn.key),
|
|
113
|
+
roleName: iamRole.name ?? (0, common_1.buildFunctionRoleName)(serviceName, context.stage, context.region, fn.key),
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
116
|
return undefined;
|
|
@@ -470,7 +470,7 @@ const createDependentResources = async (context, fn, serviceName, existingInstan
|
|
|
470
470
|
const iamConfig = fn.iam?.role;
|
|
471
471
|
const managedPolicies = iamConfig && typeof iamConfig !== 'string' ? iamConfig.managed_policies : undefined;
|
|
472
472
|
const customRoleName = iamConfig && typeof iamConfig !== 'string' ? iamConfig.name : undefined;
|
|
473
|
-
const defaultRoleName = buildDefaultRoleName(serviceName, context.stage, fn.key);
|
|
473
|
+
const defaultRoleName = buildDefaultRoleName(serviceName, context.stage, context.region, fn.key);
|
|
474
474
|
const isExternalRole = typeof iamConfig === 'string';
|
|
475
475
|
if (isExternalRole && !skipRole) {
|
|
476
476
|
// External role - use ARN directly, skip creation and management
|
|
@@ -1037,7 +1037,7 @@ const updateResource = async (context, providedFn, state, options) => {
|
|
|
1037
1037
|
else if (!ramRoleInstance || isRecordedRoleExternal || !cloudRoleExists) {
|
|
1038
1038
|
const roleName = (isRecordedRoleExternal ? undefined : ramRoleInstance?.id) ??
|
|
1039
1039
|
customRoleName ??
|
|
1040
|
-
buildDefaultRoleName(serviceName, context.stage, fn.key);
|
|
1040
|
+
buildDefaultRoleName(serviceName, context.stage, context.region, fn.key);
|
|
1041
1041
|
const roleGrant = (0, exports.resolveRoleGrant)(context, state, fn, logConfig, roleName);
|
|
1042
1042
|
logger_1.logger.info(lang_1.lang.__('CREATING_RAM_ROLE', { roleName }));
|
|
1043
1043
|
const ramRole = await client.ram.createRole(roleName, roleGrant.trustedServices, undefined, roleGrant.customStatements, desiredManagedPolicies, roleGrant.executionStatements);
|
|
@@ -10,7 +10,7 @@ const tablestorePlanner_1 = require("./tablestorePlanner");
|
|
|
10
10
|
const apigwPlanner_1 = require("./apigwPlanner");
|
|
11
11
|
const generateAliyunPlan = async (iac, backend) => {
|
|
12
12
|
const context = (0, common_1.getContext)();
|
|
13
|
-
const state = await backend.loadState(
|
|
13
|
+
const state = await backend.loadState();
|
|
14
14
|
const functionPlan = await (0, fc3Planner_1.generateFunctionPlan)(context, state, iac.functions);
|
|
15
15
|
const bucketPlan = await (0, ossPlanner_1.generateBucketPlan)(context, state, iac.buckets);
|
|
16
16
|
const databasePlan = await (0, databasePlanner_1.generateDatabasePlan)(context, state, iac.databases);
|
|
@@ -65,7 +65,7 @@ const ensureSharedSlsProject = async (context, client, state) => {
|
|
|
65
65
|
tags: [
|
|
66
66
|
{
|
|
67
67
|
key: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
68
|
-
value: (0, ownershipTag_1.buildSharedOwnershipTagValue)(context.app, exports.SHARED_LOG_PROJECT_KEY),
|
|
68
|
+
value: (0, ownershipTag_1.buildSharedOwnershipTagValue)(context.app, exports.SHARED_LOG_PROJECT_KEY, context.region),
|
|
69
69
|
},
|
|
70
70
|
],
|
|
71
71
|
});
|
|
@@ -99,7 +99,7 @@ exports.adoptSharedSlsProjectState = adoptSharedSlsProjectState;
|
|
|
99
99
|
*/
|
|
100
100
|
const isSharedProjectOwnedByApp = async (context, client, projectName) => {
|
|
101
101
|
const tags = await client.sls.getProjectTags(projectName);
|
|
102
|
-
return (0, ownershipTag_1.isOwnedByApp)(context.app, exports.SHARED_LOG_PROJECT_KEY, tags.map((t) => ({ Key: t.key, Value: t.value })));
|
|
102
|
+
return (0, ownershipTag_1.isOwnedByApp)(context.app, exports.SHARED_LOG_PROJECT_KEY, tags.map((t) => ({ Key: t.key, Value: t.value })), context.region);
|
|
103
103
|
};
|
|
104
104
|
exports.isSharedProjectOwnedByApp = isSharedProjectOwnedByApp;
|
|
105
105
|
const releaseSharedSlsProjectIfUnused = async (context, client, shared) => {
|
|
@@ -1,21 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isOwnedByApp = exports.buildSharedOwnershipTagValue = exports.SHARED_SCOPE = exports.isOwnedByStack = exports.parseOwnershipTagValue = exports.buildOwnershipTagValue = exports.OWNERSHIP_TAG_KEY = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Ownership tag stamped on provider resources at create time so a deploy can
|
|
6
|
-
* idempotently adopt a resource that exists in the cloud but is missing from
|
|
7
|
-
* local state (e.g. state was reset or a previous run failed mid-way).
|
|
8
|
-
*
|
|
9
|
-
* The value encodes BOTH the owning stack and the logical id:
|
|
10
|
-
* `${app}-${service}:${logicalId}` e.g. "fn-url-probe:functions.probe"
|
|
11
|
-
*
|
|
12
|
-
* A single tag is enough because the cloud resource name is already globally
|
|
13
|
-
* unique per provider; the tag only needs to prove ownership so an unrelated
|
|
14
|
-
* same-named resource is never adopted (that would corrupt state and let a
|
|
15
|
-
* later destroy remove a resource that was never ours).
|
|
16
|
-
*/
|
|
3
|
+
exports.isOwnedByApp = exports.buildSharedOwnershipTagValue = exports.SHARED_SCOPE = exports.isOwnedByStack = exports.isLegacyOwnershipTag = exports.parseOwnershipTagValue = exports.buildOwnershipTagValue = exports.OWNERSHIP_TAG_KEY = void 0;
|
|
17
4
|
exports.OWNERSHIP_TAG_KEY = 'si-owned-by';
|
|
18
|
-
const buildOwnershipTagValue = (context, logicalId) => `${context.app}-${context.service}:${logicalId}`;
|
|
5
|
+
const buildOwnershipTagValue = (context, logicalId) => `${context.app}-${context.service}:${logicalId}@${context.region}`;
|
|
19
6
|
exports.buildOwnershipTagValue = buildOwnershipTagValue;
|
|
20
7
|
const parseOwnershipTagValue = (value) => {
|
|
21
8
|
if (!value)
|
|
@@ -23,9 +10,23 @@ const parseOwnershipTagValue = (value) => {
|
|
|
23
10
|
const idx = value.indexOf(':');
|
|
24
11
|
if (idx <= 0)
|
|
25
12
|
return null;
|
|
26
|
-
|
|
13
|
+
const stack = value.slice(0, idx);
|
|
14
|
+
const rest = value.slice(idx + 1);
|
|
15
|
+
const atIdx = rest.lastIndexOf('@');
|
|
16
|
+
if (atIdx > 0) {
|
|
17
|
+
const region = rest.slice(atIdx + 1);
|
|
18
|
+
if (region) {
|
|
19
|
+
return { stack, logicalId: rest.slice(0, atIdx), region };
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return { stack, logicalId: rest };
|
|
27
23
|
};
|
|
28
24
|
exports.parseOwnershipTagValue = parseOwnershipTagValue;
|
|
25
|
+
const isLegacyOwnershipTag = (value) => {
|
|
26
|
+
const parsed = (0, exports.parseOwnershipTagValue)(value);
|
|
27
|
+
return !!parsed && !parsed.region;
|
|
28
|
+
};
|
|
29
|
+
exports.isLegacyOwnershipTag = isLegacyOwnershipTag;
|
|
29
30
|
const isOwnedByStack = (context, logicalId, tags) => {
|
|
30
31
|
if (!tags)
|
|
31
32
|
return false;
|
|
@@ -35,24 +36,31 @@ const isOwnedByStack = (context, logicalId, tags) => {
|
|
|
35
36
|
const parsed = (0, exports.parseOwnershipTagValue)(tag.Value);
|
|
36
37
|
if (!parsed)
|
|
37
38
|
return false;
|
|
38
|
-
|
|
39
|
+
if (parsed.stack !== `${context.app}-${context.service}` || parsed.logicalId !== logicalId) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
return parsed.region === undefined || parsed.region === context.region;
|
|
39
43
|
};
|
|
40
44
|
exports.isOwnedByStack = isOwnedByStack;
|
|
41
|
-
/**
|
|
42
|
-
* App-scoped ownership for resources shared across services of one app
|
|
43
|
-
* (issue #214 unified log container). Exact full-value match by design:
|
|
44
|
-
* per-service stacks have no claim on shared resources, so only the
|
|
45
|
-
* owning app may adopt them.
|
|
46
|
-
*/
|
|
47
45
|
exports.SHARED_SCOPE = 'shared';
|
|
48
|
-
const buildSharedOwnershipTagValue = (app, logicalId) => `${app}:${exports.SHARED_SCOPE}:${logicalId}`;
|
|
46
|
+
const buildSharedOwnershipTagValue = (app, logicalId, region) => region ? `${app}:${exports.SHARED_SCOPE}:${logicalId}@${region}` : `${app}:${exports.SHARED_SCOPE}:${logicalId}`;
|
|
49
47
|
exports.buildSharedOwnershipTagValue = buildSharedOwnershipTagValue;
|
|
50
|
-
const isOwnedByApp = (app, logicalId, tags) => {
|
|
48
|
+
const isOwnedByApp = (app, logicalId, tags, region) => {
|
|
51
49
|
if (!tags)
|
|
52
50
|
return false;
|
|
53
51
|
const tag = tags.find((t) => t.Key === exports.OWNERSHIP_TAG_KEY);
|
|
54
52
|
if (!tag?.Value)
|
|
55
53
|
return false;
|
|
56
|
-
|
|
54
|
+
if (!tag.Value.startsWith(`${app}:${exports.SHARED_SCOPE}:`)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
const suffix = tag.Value.slice(`${app}:${exports.SHARED_SCOPE}:`.length);
|
|
58
|
+
const atIdx = suffix.lastIndexOf('@');
|
|
59
|
+
const taggedLogicalId = atIdx > 0 ? suffix.slice(0, atIdx) : suffix;
|
|
60
|
+
const taggedRegion = atIdx > 0 ? suffix.slice(atIdx + 1) : undefined;
|
|
61
|
+
if (taggedLogicalId !== logicalId) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
return taggedRegion === undefined || (region !== undefined && taggedRegion === region);
|
|
57
65
|
};
|
|
58
66
|
exports.isOwnedByApp = isOwnedByApp;
|