@geek-fun/serverlessinsight 0.8.1 → 0.8.3
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 +14 -0
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +14 -0
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +348 -0
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +14 -0
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +114 -0
- package/.serverlessinsight/state-insight-volc-destroy-app-insight-volc-destroy.json.backup +1 -0
- package/README.md +26 -18
- package/README.zh-CN.md +19 -6
- package/dist/package.json +3 -1
- package/dist/src/commands/deploy.js +87 -4
- package/dist/src/commands/destroy.js +61 -10
- package/dist/src/commands/forceUnlock.js +8 -0
- package/dist/src/commands/index.js +34 -2
- package/dist/src/commands/login.js +195 -0
- package/dist/src/commands/logout.js +17 -0
- package/dist/src/commands/show.js +15 -7
- package/dist/src/commands/whoami.js +20 -0
- package/dist/src/common/aliyunClient/apigwOperations.js +332 -32
- package/dist/src/common/aliyunClient/esOperations.js +43 -29
- package/dist/src/common/aliyunClient/fc3Operations.js +481 -207
- package/dist/src/common/aliyunClient/ossOperations.js +165 -13
- package/dist/src/common/aliyunClient/rdsOperations.js +143 -39
- package/dist/src/common/aliyunClient/slsOperations.js +56 -26
- package/dist/src/common/aliyunClient/tablestoreOperations.js +25 -22
- package/dist/src/common/apiClient.js +102 -0
- package/dist/src/common/constants.js +9 -4
- package/dist/src/common/credentialStore.js +94 -0
- package/dist/src/common/credentials.js +2 -0
- package/dist/src/common/eventQueue.js +208 -0
- package/dist/src/common/hashUtils.js +87 -11
- package/dist/src/common/imsClient.js +1 -0
- package/dist/src/common/index.js +3 -0
- package/dist/src/common/lockManager.js +61 -54
- package/dist/src/common/logger.js +2 -0
- package/dist/src/common/polling.js +54 -0
- package/dist/src/common/reportResourceEvent.js +8 -0
- package/dist/src/common/runtimeMapper.js +11 -12
- package/dist/src/common/stateBackend/index.js +10 -1
- package/dist/src/common/stateBackend/localStateBackend.js +4 -1
- package/dist/src/common/stateBackend/remoteStateBackend.js +6 -3
- package/dist/src/common/stateBackend/saasStateBackend.js +266 -0
- package/dist/src/common/stateManager.js +135 -13
- package/dist/src/common/tencentClient/cosOperations.js +180 -3
- package/dist/src/common/tencentClient/esOperations.js +110 -46
- package/dist/src/common/tencentClient/index.js +22 -1
- package/dist/src/common/tencentClient/scfOperations.js +255 -133
- package/dist/src/common/tencentClient/tdsqlcClusterMapper.js +81 -0
- package/dist/src/common/tencentClient/tdsqlcOperations.js +93 -99
- package/dist/src/common/triggerMapper.js +36 -0
- package/dist/src/common/volcengineClient/apigwOperations.js +539 -159
- package/dist/src/common/volcengineClient/iamOperations.js +58 -48
- package/dist/src/common/volcengineClient/index.js +46 -21
- package/dist/src/common/volcengineClient/stsOperations.js +32 -0
- package/dist/src/common/volcengineClient/tlsOperations.js +229 -178
- package/dist/src/common/volcengineClient/tosOperations.js +78 -19
- package/dist/src/common/volcengineClient/vefaasOperations.js +272 -54
- package/dist/src/lang/en.js +84 -0
- package/dist/src/lang/zh-CN.js +84 -0
- package/dist/src/parser/eventParser.js +2 -0
- package/dist/src/parser/functionParser.js +96 -65
- package/dist/src/parser/index.js +7 -4
- package/dist/src/stack/aliyunStack/apigwExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/apigwPlanner.js +14 -10
- package/dist/src/stack/aliyunStack/apigwResource.js +230 -125
- package/dist/src/stack/aliyunStack/apigwTypes.js +16 -3
- package/dist/src/stack/aliyunStack/databaseExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/databasePlanner.js +13 -1
- package/dist/src/stack/aliyunStack/databaseResource.js +135 -40
- package/dist/src/stack/aliyunStack/deployer.js +2 -2
- package/dist/src/stack/aliyunStack/destroyer.js +2 -2
- package/dist/src/stack/aliyunStack/fc3Executor.js +25 -2
- package/dist/src/stack/aliyunStack/fc3Planner.js +11 -1
- package/dist/src/stack/aliyunStack/fc3Resource.js +327 -64
- package/dist/src/stack/aliyunStack/ossExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/ossPlanner.js +15 -1
- package/dist/src/stack/aliyunStack/ossResource.js +267 -219
- package/dist/src/stack/aliyunStack/tablestoreExecutor.js +39 -1
- package/dist/src/stack/aliyunStack/tablestorePlanner.js +13 -1
- package/dist/src/stack/aliyunStack/tablestoreResource.js +54 -20
- package/dist/src/stack/alreadyExists.js +26 -0
- package/dist/src/stack/ownershipTag.js +40 -0
- package/dist/src/stack/rfsStack/index.js +3 -1
- package/dist/src/stack/scfStack/cosExecutor.js +39 -1
- package/dist/src/stack/scfStack/cosPlanner.js +11 -1
- package/dist/src/stack/scfStack/cosResource.js +167 -64
- package/dist/src/stack/scfStack/deployer.js +2 -2
- package/dist/src/stack/scfStack/destroyer.js +2 -2
- package/dist/src/stack/scfStack/esServerlessExecutor.js +39 -1
- package/dist/src/stack/scfStack/esServerlessPlanner.js +11 -1
- package/dist/src/stack/scfStack/esServerlessResource.js +88 -23
- package/dist/src/stack/scfStack/scfExecutor.js +39 -1
- package/dist/src/stack/scfStack/scfPlanner.js +12 -2
- package/dist/src/stack/scfStack/scfResource.js +484 -14
- package/dist/src/stack/scfStack/tdsqlcExecutor.js +39 -1
- package/dist/src/stack/scfStack/tdsqlcPlanner.js +12 -1
- package/dist/src/stack/scfStack/tdsqlcResource.js +95 -16
- package/dist/src/stack/scfStack/tdsqlcTypes.js +5 -1
- package/dist/src/stack/volcengineStack/apigwExecutor.js +39 -1
- package/dist/src/stack/volcengineStack/apigwPlanner.js +25 -53
- package/dist/src/stack/volcengineStack/apigwResource.js +418 -222
- package/dist/src/stack/volcengineStack/apigwTypes.js +76 -66
- package/dist/src/stack/volcengineStack/deployer.js +49 -14
- package/dist/src/stack/volcengineStack/destroyer.js +1 -1
- package/dist/src/stack/volcengineStack/index.js +1 -2
- package/dist/src/stack/volcengineStack/tosExecutor.js +25 -2
- package/dist/src/stack/volcengineStack/tosPlanner.js +11 -1
- package/dist/src/stack/volcengineStack/tosResource.js +82 -27
- package/dist/src/stack/volcengineStack/tosTypes.js +12 -0
- package/dist/src/stack/volcengineStack/vefaasExecutor.js +25 -2
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +71 -2
- package/dist/src/stack/volcengineStack/vefaasResource.js +148 -98
- package/dist/src/stack/volcengineStack/vefaasTypes.js +1 -3
- package/dist/src/types/domains/backend.js +1 -0
- package/dist/src/types/domains/state.js +29 -1
- package/dist/src/validator/eventSchema.js +10 -0
- package/dist/src/validator/functionSchema.js +37 -12
- package/dist/src/validator/iacSchema.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -1
|
@@ -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.getAllResources = exports.removeResource = exports.setResource = exports.getResource = exports.saveStateWithLock = exports.saveState = exports.loadState = exports.ensureStateDir = exports.getStatePath = void 0;
|
|
6
|
+
exports.getRoleArnFromState = exports.getAllResources = exports.removeResource = exports.setResource = exports.getResource = exports.saveStateWithLock = exports.saveState = exports.loadState = 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
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
9
10
|
const types_1 = require("../types");
|
|
10
11
|
const lockManager_1 = require("./lockManager");
|
|
12
|
+
const logger_1 = require("./logger");
|
|
11
13
|
const STATE_DIR = '.serverlessinsight';
|
|
12
14
|
/* istanbul ignore next */
|
|
13
15
|
const getStatePath = (app, service, baseDir = process.cwd()) => {
|
|
@@ -22,32 +24,125 @@ const ensureStateDir = (baseDir = process.cwd()) => {
|
|
|
22
24
|
}
|
|
23
25
|
};
|
|
24
26
|
exports.ensureStateDir = ensureStateDir;
|
|
27
|
+
const STATE_MIGRATIONS = [];
|
|
28
|
+
/**
|
|
29
|
+
* Register a migration from `fromVersion` to a newer format. Applied in
|
|
30
|
+
* registration order during `loadState`; empty today because CURRENT_STATE_VERSION
|
|
31
|
+
* ('3.0') is the only format this CLI writes so far.
|
|
32
|
+
*/
|
|
33
|
+
const registerStateMigration = (fromVersion, migrate) => {
|
|
34
|
+
STATE_MIGRATIONS.push({ fromVersion, migrate });
|
|
35
|
+
};
|
|
36
|
+
exports.registerStateMigration = registerStateMigration;
|
|
37
|
+
/** Drop all registered migrations (test/cleanup helper). */
|
|
38
|
+
const clearStateMigrations = () => {
|
|
39
|
+
STATE_MIGRATIONS.length = 0;
|
|
40
|
+
};
|
|
41
|
+
exports.clearStateMigrations = clearStateMigrations;
|
|
42
|
+
/**
|
|
43
|
+
* Parse a state version string ("3.0", "1.0.0") into a comparable number.
|
|
44
|
+
* Versions are treated as legacy-format (major.minor[.patch]); a missing
|
|
45
|
+
* minor/patch defaults to 0. Non-numeric segments are ignored.
|
|
46
|
+
*/
|
|
47
|
+
const parseStateVersion = (version) => {
|
|
48
|
+
const [major, minor] = version.split('.').map((part) => parseInt(part, 10));
|
|
49
|
+
return (isNaN(major) ? 0 : major) * 1000 + (isNaN(minor) ? 0 : minor);
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Apply registered migrations to bring `raw` up to CURRENT_STATE_VERSION, then
|
|
53
|
+
* guard against versions that cannot reach it. A state written by a NEWER CLI
|
|
54
|
+
* must not be silently read (downgraded) — that risks data loss — so it is
|
|
55
|
+
* rejected instead. Older/legacy versions without a registered migration load
|
|
56
|
+
* as-is (they predate the migration registry).
|
|
57
|
+
*/
|
|
58
|
+
const migrateState = (raw) => {
|
|
59
|
+
if (!raw.version) {
|
|
60
|
+
logger_1.logger.debug({ stateVersion: raw.version }, 'state file has no version field; treating as legacy');
|
|
61
|
+
return raw;
|
|
62
|
+
}
|
|
63
|
+
if (raw.version === types_1.CURRENT_STATE_VERSION) {
|
|
64
|
+
return raw;
|
|
65
|
+
}
|
|
66
|
+
let migrated = raw;
|
|
67
|
+
let hops = 0;
|
|
68
|
+
while (migrated.version !== types_1.CURRENT_STATE_VERSION && hops < STATE_MIGRATIONS.length) {
|
|
69
|
+
const entry = STATE_MIGRATIONS.find((m) => m.fromVersion === migrated.version);
|
|
70
|
+
if (!entry) {
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
migrated = entry.migrate(migrated);
|
|
74
|
+
hops++;
|
|
75
|
+
}
|
|
76
|
+
const migratedVersion = String(migrated.version ?? '');
|
|
77
|
+
if (migratedVersion && migratedVersion !== types_1.CURRENT_STATE_VERSION) {
|
|
78
|
+
// A registered migration ran but did not land on CURRENT — refuse rather
|
|
79
|
+
// than persist a half-migrated state.
|
|
80
|
+
if (hops > 0) {
|
|
81
|
+
throw new types_1.StateVersionError(migratedVersion, types_1.CURRENT_STATE_VERSION);
|
|
82
|
+
}
|
|
83
|
+
// No migration was applicable. Only reject versions NEWER than CURRENT
|
|
84
|
+
// (written by a newer CLI, or an unknown future format). Older legacy
|
|
85
|
+
// versions load as-is.
|
|
86
|
+
if (parseStateVersion(migratedVersion) > parseStateVersion(types_1.CURRENT_STATE_VERSION)) {
|
|
87
|
+
throw new types_1.StateVersionError(migratedVersion, types_1.CURRENT_STATE_VERSION);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return migrated;
|
|
91
|
+
};
|
|
92
|
+
exports.migrateState = migrateState;
|
|
25
93
|
/**
|
|
26
94
|
* Load state file, scoped to the given stage.
|
|
27
95
|
* The returned StateFile has `resources` populated from `stages[stage].resources`.
|
|
96
|
+
* A corrupt primary is recovered from `statePath + '.backup'`; if both are corrupt,
|
|
97
|
+
* StateCorruptError is thrown instead of silently returning empty state.
|
|
98
|
+
* Registered version migrations are applied on load; a state version that cannot
|
|
99
|
+
* be migrated to CURRENT_STATE_VERSION throws StateVersionError.
|
|
28
100
|
*/
|
|
29
|
-
/* istanbul ignore next */
|
|
30
101
|
const loadState = (provider, app, service, stage, baseDir = process.cwd()) => {
|
|
31
102
|
const statePath = (0, exports.getStatePath)(app, service, baseDir);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return
|
|
103
|
+
if (!node_fs_1.default.existsSync(statePath)) {
|
|
104
|
+
return { version: types_1.CURRENT_STATE_VERSION, provider, app, service, stages: {}, resources: {} };
|
|
105
|
+
}
|
|
106
|
+
const readBackup = () => {
|
|
107
|
+
const backupPath = `${statePath}.backup`;
|
|
108
|
+
if (!node_fs_1.default.existsSync(backupPath)) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
try {
|
|
112
|
+
const content = node_fs_1.default.readFileSync(backupPath, 'utf-8');
|
|
113
|
+
return JSON.parse(content);
|
|
39
114
|
}
|
|
115
|
+
catch {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
const hydrate = (raw) => {
|
|
120
|
+
const migrated = (0, exports.migrateState)(raw);
|
|
121
|
+
const stageResources = migrated.stages?.[stage]?.resources ?? {};
|
|
122
|
+
return { ...migrated, resources: stageResources };
|
|
123
|
+
};
|
|
124
|
+
try {
|
|
125
|
+
const content = node_fs_1.default.readFileSync(statePath, 'utf-8');
|
|
126
|
+
return hydrate(JSON.parse(content));
|
|
40
127
|
}
|
|
41
|
-
catch {
|
|
42
|
-
|
|
128
|
+
catch (error) {
|
|
129
|
+
if (error instanceof types_1.StateVersionError) {
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
const backup = readBackup();
|
|
133
|
+
if (backup) {
|
|
134
|
+
return hydrate(backup);
|
|
135
|
+
}
|
|
136
|
+
throw new types_1.StateCorruptError(statePath, error);
|
|
43
137
|
}
|
|
44
|
-
return { version: types_1.CURRENT_STATE_VERSION, provider, app, service, stages: {}, resources: {} };
|
|
45
138
|
};
|
|
46
139
|
exports.loadState = loadState;
|
|
47
140
|
/* istanbul ignore next */
|
|
48
141
|
const saveState = (state, app, service, stage, baseDir = process.cwd()) => {
|
|
49
142
|
(0, exports.ensureStateDir)(baseDir);
|
|
50
143
|
const statePath = (0, exports.getStatePath)(app, service, baseDir);
|
|
144
|
+
const tmpPath = `${statePath}.tmp`;
|
|
145
|
+
const backupPath = `${statePath}.backup`;
|
|
51
146
|
// Read the existing file to preserve other stages
|
|
52
147
|
let existing = {
|
|
53
148
|
version: types_1.CURRENT_STATE_VERSION,
|
|
@@ -70,6 +165,8 @@ const saveState = (state, app, service, stage, baseDir = process.cwd()) => {
|
|
|
70
165
|
const stateToSave = {
|
|
71
166
|
...existing,
|
|
72
167
|
version: types_1.CURRENT_STATE_VERSION,
|
|
168
|
+
lineage: existing.lineage || node_crypto_1.default.randomUUID(),
|
|
169
|
+
serial: (existing.serial ?? 0) + 1,
|
|
73
170
|
app,
|
|
74
171
|
service,
|
|
75
172
|
provider: state.provider,
|
|
@@ -79,7 +176,32 @@ const saveState = (state, app, service, stage, baseDir = process.cwd()) => {
|
|
|
79
176
|
},
|
|
80
177
|
resources: state.resources,
|
|
81
178
|
};
|
|
82
|
-
|
|
179
|
+
// Atomic write: back up the previous state, then write tmp + fsync + rename
|
|
180
|
+
try {
|
|
181
|
+
if (node_fs_1.default.existsSync(statePath)) {
|
|
182
|
+
node_fs_1.default.copyFileSync(statePath, backupPath);
|
|
183
|
+
}
|
|
184
|
+
const fd = node_fs_1.default.openSync(tmpPath, 'w');
|
|
185
|
+
try {
|
|
186
|
+
node_fs_1.default.writeFileSync(fd, JSON.stringify(stateToSave, null, 2), 'utf-8');
|
|
187
|
+
node_fs_1.default.fsyncSync(fd);
|
|
188
|
+
}
|
|
189
|
+
finally {
|
|
190
|
+
node_fs_1.default.closeSync(fd);
|
|
191
|
+
}
|
|
192
|
+
node_fs_1.default.renameSync(tmpPath, statePath);
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
try {
|
|
196
|
+
if (node_fs_1.default.existsSync(tmpPath)) {
|
|
197
|
+
node_fs_1.default.rmSync(tmpPath);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
// ignore cleanup failure
|
|
202
|
+
}
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
83
205
|
};
|
|
84
206
|
exports.saveState = saveState;
|
|
85
207
|
/**
|
|
@@ -272,11 +272,18 @@ const createCosOperations = (cosClient, region, dnsOps) => {
|
|
|
272
272
|
};
|
|
273
273
|
return {
|
|
274
274
|
createBucket: async (config) => {
|
|
275
|
+
// COS PutBucket accepts tags via the x-cos-tagging HTTP header, formatted
|
|
276
|
+
// as URL-encoded key=value pairs joined by '&'.
|
|
277
|
+
const headers = {};
|
|
278
|
+
if (config.Tags && config.Tags.length > 0) {
|
|
279
|
+
headers['x-cos-tagging'] = config.Tags.map((t) => `${encodeURIComponent(t.Key)}=${encodeURIComponent(t.Value)}`).join('&');
|
|
280
|
+
}
|
|
275
281
|
// Create bucket
|
|
276
282
|
await new Promise((resolve, reject) => {
|
|
277
283
|
cosClient.putBucket({
|
|
278
284
|
Bucket: config.Bucket,
|
|
279
285
|
Region: config.Region,
|
|
286
|
+
...(Object.keys(headers).length > 0 ? { Headers: headers } : {}),
|
|
280
287
|
}, (err) => {
|
|
281
288
|
if (err) {
|
|
282
289
|
reject(err);
|
|
@@ -324,8 +331,10 @@ const createCosOperations = (cosClient, region, dnsOps) => {
|
|
|
324
331
|
},
|
|
325
332
|
getBucket: async (bucketName, region) => {
|
|
326
333
|
try {
|
|
327
|
-
// Check if bucket exists
|
|
328
|
-
|
|
334
|
+
// Check if bucket exists. The HeadBucket response carries the bucket
|
|
335
|
+
// creation date in the x-cos-creation-date header — preserved so the
|
|
336
|
+
// state instance no longer reports creationDate: null.
|
|
337
|
+
const headBucketData = await new Promise((resolve, reject) => {
|
|
329
338
|
cosClient.headBucket({
|
|
330
339
|
Bucket: bucketName,
|
|
331
340
|
Region: region,
|
|
@@ -338,6 +347,7 @@ const createCosOperations = (cosClient, region, dnsOps) => {
|
|
|
338
347
|
}
|
|
339
348
|
});
|
|
340
349
|
});
|
|
350
|
+
const creationDate = headBucketData.headers?.['x-cos-creation-date'];
|
|
341
351
|
// Get ACL
|
|
342
352
|
let acl;
|
|
343
353
|
let accessControlPolicy;
|
|
@@ -481,18 +491,185 @@ const createCosOperations = (cosClient, region, dnsOps) => {
|
|
|
481
491
|
})),
|
|
482
492
|
};
|
|
483
493
|
}
|
|
494
|
+
catch (error) {
|
|
495
|
+
// A 404 or NoSuchTagSet means the bucket has no tagging config — not
|
|
496
|
+
// an error. Any other failure (auth, network) must surface loudly so
|
|
497
|
+
// it is not misread as "bucket not owned".
|
|
498
|
+
const err = error;
|
|
499
|
+
const isNoTags = err.statusCode === 404 ||
|
|
500
|
+
err.code === 'NoSuchTagSet' ||
|
|
501
|
+
String(err.message ?? '').includes('NoSuchTagSet');
|
|
502
|
+
if (!isNoTags) {
|
|
503
|
+
throw error;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
// Get lifecycle configuration
|
|
507
|
+
let lifecycleConfiguration;
|
|
508
|
+
try {
|
|
509
|
+
const lifecycleResult = await new Promise((resolve, reject) => {
|
|
510
|
+
cosClient.getBucketLifecycle({
|
|
511
|
+
Bucket: bucketName,
|
|
512
|
+
Region: region,
|
|
513
|
+
}, (err, data) => {
|
|
514
|
+
if (err) {
|
|
515
|
+
reject(err);
|
|
516
|
+
}
|
|
517
|
+
else {
|
|
518
|
+
resolve(data);
|
|
519
|
+
}
|
|
520
|
+
});
|
|
521
|
+
});
|
|
522
|
+
lifecycleConfiguration = {
|
|
523
|
+
rules: lifecycleResult.Rules?.map((r) => ({
|
|
524
|
+
id: r.ID,
|
|
525
|
+
status: r.Status,
|
|
526
|
+
prefix: typeof r.Filter?.Prefix === 'string' ? r.Filter.Prefix : undefined,
|
|
527
|
+
expiration: {
|
|
528
|
+
days: r.Expiration?.Days,
|
|
529
|
+
date: r.Expiration?.Date,
|
|
530
|
+
expiredObjectDeleteMarker: r.Expiration?.ExpiredObjectDeleteMarker,
|
|
531
|
+
},
|
|
532
|
+
transition: {
|
|
533
|
+
days: r.Transition?.Days,
|
|
534
|
+
date: r.Transition?.Date,
|
|
535
|
+
storageClass: r.Transition?.StorageClass,
|
|
536
|
+
},
|
|
537
|
+
})),
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
catch {
|
|
541
|
+
// Lifecycle might not be configured
|
|
542
|
+
}
|
|
543
|
+
// Get logging configuration
|
|
544
|
+
let loggingConfiguration;
|
|
545
|
+
try {
|
|
546
|
+
const loggingResult = await new Promise((resolve, reject) => {
|
|
547
|
+
cosClient.getBucketLogging({
|
|
548
|
+
Bucket: bucketName,
|
|
549
|
+
Region: region,
|
|
550
|
+
}, (err, data) => {
|
|
551
|
+
if (err) {
|
|
552
|
+
reject(err);
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
resolve(data);
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
});
|
|
559
|
+
loggingConfiguration = {
|
|
560
|
+
targetBucket: loggingResult.BucketLoggingStatus?.LoggingEnabled?.TargetBucket,
|
|
561
|
+
targetPrefix: loggingResult.BucketLoggingStatus?.LoggingEnabled?.TargetPrefix,
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
catch {
|
|
565
|
+
// Logging might not be configured
|
|
566
|
+
}
|
|
567
|
+
// Get replication configuration
|
|
568
|
+
let replicationConfiguration;
|
|
569
|
+
try {
|
|
570
|
+
const replicationResult = await new Promise((resolve, reject) => {
|
|
571
|
+
cosClient.getBucketReplication({
|
|
572
|
+
Bucket: bucketName,
|
|
573
|
+
Region: region,
|
|
574
|
+
}, (err, data) => {
|
|
575
|
+
if (err) {
|
|
576
|
+
reject(err);
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
resolve(data);
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
});
|
|
583
|
+
replicationConfiguration = {
|
|
584
|
+
role: replicationResult.ReplicationConfiguration?.Role,
|
|
585
|
+
rules: replicationResult.ReplicationConfiguration?.Rules?.map((r) => ({
|
|
586
|
+
id: r.ID,
|
|
587
|
+
status: r.Status,
|
|
588
|
+
prefix: r.Prefix,
|
|
589
|
+
destination: {
|
|
590
|
+
bucket: r.Destination?.Bucket,
|
|
591
|
+
storageClass: r.Destination?.StorageClass,
|
|
592
|
+
},
|
|
593
|
+
})),
|
|
594
|
+
};
|
|
595
|
+
}
|
|
484
596
|
catch {
|
|
485
|
-
//
|
|
597
|
+
// Replication might not be configured
|
|
598
|
+
}
|
|
599
|
+
// Get server-side encryption configuration
|
|
600
|
+
let sseConfiguration;
|
|
601
|
+
try {
|
|
602
|
+
const encryptionResult = await new Promise((resolve, reject) => {
|
|
603
|
+
cosClient.getBucketEncryption({
|
|
604
|
+
Bucket: bucketName,
|
|
605
|
+
Region: region,
|
|
606
|
+
}, (err, data) => {
|
|
607
|
+
if (err) {
|
|
608
|
+
reject(err);
|
|
609
|
+
}
|
|
610
|
+
else {
|
|
611
|
+
resolve(data);
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
});
|
|
615
|
+
const rule = encryptionResult.ServerSideEncryptionConfiguration?.Rule?.[0];
|
|
616
|
+
// SDK quirk: the type declares ApplySideEncryptionConfiguration, but the
|
|
617
|
+
// raw COS API returns ApplyServerSideEncryptionByDefault — read both.
|
|
618
|
+
const apply =
|
|
619
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
620
|
+
rule?.ApplyServerSideEncryptionByDefault ??
|
|
621
|
+
rule?.ApplySideEncryptionConfiguration;
|
|
622
|
+
sseConfiguration = {
|
|
623
|
+
sseAlgorithm: apply?.SSEAlgorithm,
|
|
624
|
+
sseKmsMasterKeyId: apply?.KMSMasterKeyID,
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
catch {
|
|
628
|
+
// Encryption might not be configured
|
|
629
|
+
}
|
|
630
|
+
// Get bucket policy (cloud-effective, may differ from the definition)
|
|
631
|
+
let policy = null;
|
|
632
|
+
try {
|
|
633
|
+
const policyResult = await new Promise((resolve, reject) => {
|
|
634
|
+
cosClient.getBucketPolicy({
|
|
635
|
+
Bucket: bucketName,
|
|
636
|
+
Region: region,
|
|
637
|
+
}, (err, data) => {
|
|
638
|
+
if (err)
|
|
639
|
+
reject(err);
|
|
640
|
+
else
|
|
641
|
+
resolve(data);
|
|
642
|
+
});
|
|
643
|
+
});
|
|
644
|
+
if (policyResult.Policy) {
|
|
645
|
+
policy =
|
|
646
|
+
typeof policyResult.Policy === 'string'
|
|
647
|
+
? JSON.parse(policyResult.Policy)
|
|
648
|
+
: policyResult.Policy;
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
catch (err) {
|
|
652
|
+
const e = err;
|
|
653
|
+
if (e.statusCode !== 404 && e.statusCode !== 403 && e.code !== 'NoSuchBucketPolicy') {
|
|
654
|
+
throw err;
|
|
655
|
+
}
|
|
486
656
|
}
|
|
487
657
|
return {
|
|
488
658
|
Name: bucketName,
|
|
489
659
|
Location: region,
|
|
660
|
+
CreationDate: creationDate,
|
|
490
661
|
ACL: acl,
|
|
491
662
|
WebsiteConfiguration: websiteConfig,
|
|
492
663
|
AccessControlPolicy: accessControlPolicy,
|
|
493
664
|
CorsConfiguration: corsConfiguration,
|
|
494
665
|
VersioningConfiguration: versioningConfig,
|
|
495
666
|
TaggingConfiguration: taggingConfig,
|
|
667
|
+
Tags: taggingConfig?.tags?.map((t) => ({ Key: t.key ?? '', Value: t.value ?? '' })),
|
|
668
|
+
LifecycleConfiguration: lifecycleConfiguration,
|
|
669
|
+
LoggingConfiguration: loggingConfiguration,
|
|
670
|
+
ReplicationConfiguration: replicationConfiguration,
|
|
671
|
+
SseConfiguration: sseConfiguration,
|
|
672
|
+
Policy: policy,
|
|
496
673
|
};
|
|
497
674
|
}
|
|
498
675
|
catch (error) {
|
|
@@ -4,46 +4,86 @@ exports.createTencentEsOperations = void 0;
|
|
|
4
4
|
const types_1 = require("./types");
|
|
5
5
|
const logger_1 = require("../logger");
|
|
6
6
|
const lang_1 = require("../../lang");
|
|
7
|
+
const polling_1 = require("../polling");
|
|
7
8
|
const waitForSpaceReady = async (getSpace, spaceId) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
try {
|
|
10
|
+
await (0, polling_1.pollUntil)({
|
|
11
|
+
description: `Tencent ES space ${spaceId} to be ready`,
|
|
12
|
+
fetch: async () => {
|
|
13
|
+
const space = await getSpace(spaceId);
|
|
14
|
+
if (!space) {
|
|
15
|
+
throw new Error(lang_1.lang.__('TENCENT_ES_SPACE_NOT_FOUND', { spaceId }));
|
|
16
|
+
}
|
|
17
|
+
if (space.Status === types_1.TencentEsSpaceStatus.DELETED ||
|
|
18
|
+
space.Status === types_1.TencentEsSpaceStatus.DELETING) {
|
|
19
|
+
throw new Error(lang_1.lang.__('TENCENT_ES_SPACE_ERROR_STATE', { status: String(space.Status) }));
|
|
20
|
+
}
|
|
21
|
+
return space;
|
|
22
|
+
},
|
|
23
|
+
isDone: (space) => space?.Status === types_1.TencentEsSpaceStatus.NORMAL,
|
|
24
|
+
intervalMs: 10000,
|
|
25
|
+
maxAttempts: 60,
|
|
26
|
+
onProgress: (space) => {
|
|
27
|
+
if (space) {
|
|
28
|
+
logger_1.logger.info(lang_1.lang.__('TENCENT_ES_SPACE_WAITING', { spaceId, status: String(space.Status) }));
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
logger_1.logger.info(lang_1.lang.__('TENCENT_ES_SPACE_READY', { spaceId }));
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
if (e instanceof polling_1.PollingTimeoutError) {
|
|
36
|
+
throw new Error(lang_1.lang.__('TENCENT_ES_SPACE_TIMEOUT_READY', { spaceId }), { cause: e });
|
|
22
37
|
}
|
|
23
|
-
|
|
24
|
-
await new Promise((resolve) => setTimeout(resolve, 10000));
|
|
25
|
-
attempts++;
|
|
38
|
+
throw e;
|
|
26
39
|
}
|
|
27
|
-
throw new Error(lang_1.lang.__('TENCENT_ES_SPACE_TIMEOUT_READY', { spaceId }));
|
|
28
40
|
};
|
|
41
|
+
// Maps a DescribeServerlessSpaces entry (SDK ServerlessSpace) to the internal
|
|
42
|
+
// space info. The ES SDK reports tags as TagList of { TagKey, TagValue } while
|
|
43
|
+
// the ownership check (isOwnedByStack) consumes { Key, Value } — normalized here
|
|
44
|
+
// at the boundary so callers never see the provider shape.
|
|
45
|
+
const toSpaceInfo = (space) => ({
|
|
46
|
+
SpaceId: space.SpaceId || '',
|
|
47
|
+
SpaceName: space.SpaceName || '',
|
|
48
|
+
Status: space.Status ?? types_1.TencentEsSpaceStatus.CREATING,
|
|
49
|
+
CreateTime: space.CreateTime,
|
|
50
|
+
IndexCount: space.IndexCount,
|
|
51
|
+
KibanaUrl: space.KibanaUrl,
|
|
52
|
+
KibanaPrivateUrl: space.KibanaPrivateUrl,
|
|
53
|
+
IndexAccessUrl: space.IndexAccessUrl,
|
|
54
|
+
KibanaPublicAcl: space.KibanaPublicAcl,
|
|
55
|
+
KibanaEmbedUrl: space.KibanaEmbedUrl,
|
|
56
|
+
DiDataList: space.DiDataList,
|
|
57
|
+
VpcInfo: space.VpcInfo,
|
|
58
|
+
Region: space.Region,
|
|
59
|
+
Zone: space.Zone,
|
|
60
|
+
EnableKibanaPublicAccess: space.EnableKibanaPublicAccess,
|
|
61
|
+
EnableKibanaPrivateAccess: space.EnableKibanaPrivateAccess,
|
|
62
|
+
AppId: space.AppId,
|
|
63
|
+
KibanaLanguage: space.KibanaLanguage,
|
|
64
|
+
ClusterType: space.ClusterType,
|
|
65
|
+
EnableMcpAccess: space.EnableMcpAccess,
|
|
66
|
+
McpAccess: space.McpAccess,
|
|
67
|
+
Tags: (space.TagList ?? []).map((t) => ({ Key: t.TagKey, Value: t.TagValue })),
|
|
68
|
+
});
|
|
29
69
|
const waitForSpaceDeleted = async (getSpace, spaceId) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
70
|
+
try {
|
|
71
|
+
await (0, polling_1.pollUntil)({
|
|
72
|
+
description: `Tencent ES space ${spaceId} to be deleted`,
|
|
73
|
+
fetch: () => getSpace(spaceId),
|
|
74
|
+
isDone: (space) => space === null || space?.Status === types_1.TencentEsSpaceStatus.DELETED,
|
|
75
|
+
intervalMs: 10000,
|
|
76
|
+
maxAttempts: 60,
|
|
77
|
+
onProgress: () => logger_1.logger.info(lang_1.lang.__('TENCENT_ES_SPACE_WAITING_DELETE', { spaceId })),
|
|
78
|
+
});
|
|
79
|
+
logger_1.logger.info(lang_1.lang.__('TENCENT_ES_SPACE_DELETED', { spaceId }));
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
if (e instanceof polling_1.PollingTimeoutError) {
|
|
83
|
+
throw new Error(lang_1.lang.__('TENCENT_ES_SPACE_TIMEOUT_DELETE', { spaceId }), { cause: e });
|
|
41
84
|
}
|
|
42
|
-
|
|
43
|
-
await new Promise((resolve) => setTimeout(resolve, 10000));
|
|
44
|
-
attempts++;
|
|
85
|
+
throw e;
|
|
45
86
|
}
|
|
46
|
-
throw new Error(lang_1.lang.__('TENCENT_ES_SPACE_TIMEOUT_DELETE', { spaceId }));
|
|
47
87
|
};
|
|
48
88
|
const createTencentEsOperations = (esClient, _context) => {
|
|
49
89
|
const operations = {
|
|
@@ -60,6 +100,9 @@ const createTencentEsOperations = (esClient, _context) => {
|
|
|
60
100
|
if (config.KibanaWhiteIpList && config.KibanaWhiteIpList.length > 0) {
|
|
61
101
|
params.KibanaWhiteIpList = config.KibanaWhiteIpList;
|
|
62
102
|
}
|
|
103
|
+
if (config.Tags && config.Tags.length > 0) {
|
|
104
|
+
params.TagList = config.Tags.map((t) => ({ TagKey: t.Key, TagValue: t.Value }));
|
|
105
|
+
}
|
|
63
106
|
try {
|
|
64
107
|
const response = await esClient.CreateServerlessSpaceV2(params);
|
|
65
108
|
logger_1.logger.info(lang_1.lang.__('TENCENT_ES_SPACE_CREATION_INITIATED'));
|
|
@@ -81,23 +124,44 @@ const createTencentEsOperations = (esClient, _context) => {
|
|
|
81
124
|
};
|
|
82
125
|
try {
|
|
83
126
|
const response = await esClient.DescribeServerlessSpaces(params);
|
|
84
|
-
|
|
127
|
+
const space = response.ServerlessSpaces?.[0];
|
|
128
|
+
return space ? toSpaceInfo(space) : null;
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
if (error &&
|
|
132
|
+
typeof error === 'object' &&
|
|
133
|
+
'code' in error &&
|
|
134
|
+
typeof error.code === 'string' &&
|
|
135
|
+
(error.code.startsWith('ResourceNotFound') ||
|
|
136
|
+
error.code === 'InvalidParameterValue' ||
|
|
137
|
+
error.code === 'ResourceNotFound.ServerlessSpaceNotFound')) {
|
|
85
138
|
return null;
|
|
86
139
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
getSpaceByName: async (spaceName) => {
|
|
144
|
+
const params = {
|
|
145
|
+
SpaceNames: [spaceName],
|
|
146
|
+
};
|
|
147
|
+
try {
|
|
148
|
+
const response = await esClient.DescribeServerlessSpaces(params);
|
|
149
|
+
const space = (response.ServerlessSpaces ?? []).find((s) => {
|
|
150
|
+
return s.SpaceName === spaceName;
|
|
151
|
+
});
|
|
152
|
+
return space ? toSpaceInfo(space) : null;
|
|
97
153
|
}
|
|
98
154
|
catch (error) {
|
|
99
|
-
|
|
100
|
-
|
|
155
|
+
if (error &&
|
|
156
|
+
typeof error === 'object' &&
|
|
157
|
+
'code' in error &&
|
|
158
|
+
typeof error.code === 'string' &&
|
|
159
|
+
(error.code.startsWith('ResourceNotFound') ||
|
|
160
|
+
error.code === 'InvalidParameterValue' ||
|
|
161
|
+
error.code === 'ResourceNotFound.ServerlessSpaceNotFound')) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
throw error;
|
|
101
165
|
}
|
|
102
166
|
},
|
|
103
167
|
updateSpace: async (spaceId, config) => {
|
|
@@ -45,6 +45,7 @@ const cynosdb = __importStar(require("tencentcloud-sdk-nodejs-cynosdb"));
|
|
|
45
45
|
const tencentCam = __importStar(require("tencentcloud-sdk-nodejs-cam"));
|
|
46
46
|
const tencentEs = __importStar(require("tencentcloud-sdk-nodejs-es"));
|
|
47
47
|
const tencentSsl = __importStar(require("tencentcloud-sdk-nodejs-ssl"));
|
|
48
|
+
const tencentTag = __importStar(require("tencentcloud-sdk-nodejs-tag"));
|
|
48
49
|
const cos_nodejs_sdk_v5_1 = __importDefault(require("cos-nodejs-sdk-v5"));
|
|
49
50
|
const scfOperations_1 = require("./scfOperations");
|
|
50
51
|
const cosOperations_1 = require("./cosOperations");
|
|
@@ -59,6 +60,7 @@ const CynosdbClient = cynosdb.cynosdb.v20190107.Client;
|
|
|
59
60
|
const CamClient = tencentCam.cam.v20190116.Client;
|
|
60
61
|
const EsClient = tencentEs.es.v20180416.Client;
|
|
61
62
|
const SslClient = tencentSsl.ssl.v20191205.Client;
|
|
63
|
+
const TagClient = tencentTag.tag.v20180813.Client;
|
|
62
64
|
// Initialize SDK clients (internal)
|
|
63
65
|
const initializeSdkClients = (context) => {
|
|
64
66
|
const scfClientConfig = {
|
|
@@ -130,6 +132,19 @@ const initializeSdkClients = (context) => {
|
|
|
130
132
|
},
|
|
131
133
|
};
|
|
132
134
|
const camClient = new CamClient(camClientConfig);
|
|
135
|
+
const tagClientConfig = {
|
|
136
|
+
credential: {
|
|
137
|
+
secretId: context.accessKeyId,
|
|
138
|
+
secretKey: context.accessKeySecret,
|
|
139
|
+
},
|
|
140
|
+
region: context.region,
|
|
141
|
+
profile: {
|
|
142
|
+
httpProfile: {
|
|
143
|
+
endpoint: 'tag.tencentcloudapi.com',
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
const tagClient = new TagClient(tagClientConfig);
|
|
133
148
|
return {
|
|
134
149
|
scf: scfClient,
|
|
135
150
|
cos: cosClient,
|
|
@@ -138,13 +153,19 @@ const initializeSdkClients = (context) => {
|
|
|
138
153
|
ssl: sslClient,
|
|
139
154
|
dns: (0, dnspodOperations_1.createDnsClient)(context),
|
|
140
155
|
cam: camClient,
|
|
156
|
+
tag: tagClient,
|
|
141
157
|
};
|
|
142
158
|
};
|
|
143
159
|
const createTencentClient = (context) => {
|
|
144
160
|
const sdkClients = initializeSdkClients(context);
|
|
145
161
|
const dnsOps = (0, dnspodOperations_1.createDnsOperations)(sdkClients.dns);
|
|
146
162
|
return {
|
|
147
|
-
scf: (0, scfOperations_1.createScfOperations)(sdkClients.scf
|
|
163
|
+
scf: (0, scfOperations_1.createScfOperations)(sdkClients.scf, {
|
|
164
|
+
tag: sdkClients.tag,
|
|
165
|
+
cam: sdkClients.cam,
|
|
166
|
+
region: context.region,
|
|
167
|
+
namespace: context.parameters?.find((p) => p.key === 'namespace')?.value ?? 'default',
|
|
168
|
+
}),
|
|
148
169
|
cos: (0, cosOperations_1.createCosOperations)(sdkClients.cos, context.region, dnsOps),
|
|
149
170
|
cam: (0, camOperations_1.createCamOperations)(sdkClients.cam),
|
|
150
171
|
tdsqlc: (0, tdsqlcOperations_1.createTdsqlcOperations)(sdkClients.cynosdb, context),
|