@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
|
@@ -5,6 +5,7 @@ const tencentClient_1 = require("../../common/tencentClient");
|
|
|
5
5
|
const tdsqlcTypes_1 = require("./tdsqlcTypes");
|
|
6
6
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
7
|
const hashUtils_1 = require("../../common/hashUtils");
|
|
8
|
+
const ownershipTag_1 = require("../ownershipTag");
|
|
8
9
|
const planDatabaseDeletion = (logicalId, definition) => ({
|
|
9
10
|
logicalId,
|
|
10
11
|
action: 'delete',
|
|
@@ -33,7 +34,17 @@ const generateDatabasePlan = async (context, state, databases) => {
|
|
|
33
34
|
const currentState = (0, stateManager_1.getResource)(state, logicalId);
|
|
34
35
|
const config = (0, tdsqlcTypes_1.databaseToTdsqlcConfig)(database);
|
|
35
36
|
const desiredDefinition = (0, tdsqlcTypes_1.extractTdsqlcDefinition)(config);
|
|
36
|
-
if (!currentState) {
|
|
37
|
+
if (!currentState || currentState.status === 'tainted') {
|
|
38
|
+
// No usable local state: probe the provider before planning create. If a
|
|
39
|
+
// same-named cluster already exists WITHOUT our ownership tag it may
|
|
40
|
+
// belong to another project — fail fast in the plan instead of letting
|
|
41
|
+
// the executor discover it mid-deploy.
|
|
42
|
+
const client = (0, tencentClient_1.createTencentClient)(context);
|
|
43
|
+
const remoteCluster = await client.tdsqlc.getClusterByName(database.name);
|
|
44
|
+
if (remoteCluster &&
|
|
45
|
+
!(0, ownershipTag_1.isOwnedByStack)(context, logicalId, (0, tdsqlcTypes_1.tdsqlcTagsToOwnershipTags)(remoteCluster.ResourceTags))) {
|
|
46
|
+
throw new Error(`Cluster ${database.name} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`);
|
|
47
|
+
}
|
|
37
48
|
return {
|
|
38
49
|
logicalId,
|
|
39
50
|
action: 'create',
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deleteDatabaseResource = exports.updateDatabaseResource = exports.readDatabaseResource = exports.createDatabaseResource = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
4
5
|
const tencentClient_1 = require("../../common/tencentClient");
|
|
5
6
|
const tdsqlcTypes_1 = require("./tdsqlcTypes");
|
|
6
7
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
8
|
const common_1 = require("../../common");
|
|
8
9
|
const logger_1 = require("../../common/logger");
|
|
9
10
|
const lang_1 = require("../../lang");
|
|
11
|
+
const ownershipTag_1 = require("../ownershipTag");
|
|
12
|
+
const alreadyExists_1 = require("../alreadyExists");
|
|
10
13
|
const buildTdsqlcInstanceFromProvider = (info, sid) => {
|
|
11
14
|
return {
|
|
12
15
|
sid,
|
|
@@ -77,36 +80,112 @@ const buildTdsqlcInstanceFromProvider = (info, sid) => {
|
|
|
77
80
|
tagKey: t.TagKey ?? null,
|
|
78
81
|
tagValue: t.TagValue ?? null,
|
|
79
82
|
})) ?? [],
|
|
83
|
+
uin: info.Uin ?? null,
|
|
84
|
+
appId: info.AppId ?? null,
|
|
85
|
+
tasks: info.Tasks?.map((t) => ({
|
|
86
|
+
taskId: t.TaskId ?? null,
|
|
87
|
+
taskType: t.TaskType ?? null,
|
|
88
|
+
taskStatus: t.TaskStatus ?? null,
|
|
89
|
+
objectId: t.ObjectId ?? null,
|
|
90
|
+
objectType: t.ObjectType ?? null,
|
|
91
|
+
})) ?? [],
|
|
92
|
+
netAddrs: info.NetAddrs?.map((n) => ({
|
|
93
|
+
vip: n.Vip ?? null,
|
|
94
|
+
vport: n.Vport ?? null,
|
|
95
|
+
wanDomain: n.WanDomain ?? null,
|
|
96
|
+
wanPort: n.WanPort ?? null,
|
|
97
|
+
netType: n.NetType ?? null,
|
|
98
|
+
uniqSubnetId: n.UniqSubnetId ?? null,
|
|
99
|
+
uniqVpcId: n.UniqVpcId ?? null,
|
|
100
|
+
})) ?? [],
|
|
101
|
+
hasSlaveZone: info.HasSlaveZone ?? null,
|
|
102
|
+
resourcePackages: info.ResourcePackages?.map((p) => ({
|
|
103
|
+
packageId: p.PackageId ?? null,
|
|
104
|
+
packageType: p.PackageType ?? null,
|
|
105
|
+
deductionPriority: p.DeductionPriority ?? null,
|
|
106
|
+
})) ?? [],
|
|
107
|
+
gdnId: info.GdnId ?? null,
|
|
108
|
+
gdnRole: info.GdnRole ?? null,
|
|
80
109
|
cynosVersion: info.CynosVersion ?? null,
|
|
110
|
+
cynosVersionTag: info.CynosVersionTag ?? null,
|
|
81
111
|
cynosVersionStatus: info.CynosVersionStatus ?? null,
|
|
82
112
|
isLatestVersion: info.IsLatestVersion ?? null,
|
|
83
113
|
};
|
|
84
114
|
};
|
|
85
115
|
const createDatabaseResource = async (context, database, state) => {
|
|
116
|
+
const logicalId = `databases.${database.key}`;
|
|
86
117
|
const config = (0, tdsqlcTypes_1.databaseToTdsqlcConfig)(database);
|
|
118
|
+
config.ResourceTags = [
|
|
119
|
+
{ TagKey: ownershipTag_1.OWNERSHIP_TAG_KEY, TagValue: (0, ownershipTag_1.buildOwnershipTagValue)(context, logicalId) },
|
|
120
|
+
];
|
|
87
121
|
const client = (0, tencentClient_1.createTencentClient)(context);
|
|
88
|
-
const clusterId = await client.tdsqlc.createCluster(config);
|
|
89
|
-
// Refresh state from provider to get all attributes
|
|
90
|
-
const clusterInfo = await client.tdsqlc.getCluster(clusterId);
|
|
91
|
-
if (!clusterInfo) {
|
|
92
|
-
throw new Error(`Failed to refresh state for cluster: ${clusterId}`);
|
|
93
|
-
}
|
|
94
122
|
const definition = (0, tdsqlcTypes_1.extractTdsqlcDefinition)(config);
|
|
95
|
-
const
|
|
96
|
-
const resourceState = {
|
|
123
|
+
const taintedResourceState = {
|
|
97
124
|
mode: 'managed',
|
|
98
125
|
region: context.region,
|
|
99
126
|
definition,
|
|
100
|
-
instances: [
|
|
127
|
+
instances: [],
|
|
101
128
|
lastUpdated: new Date().toISOString(),
|
|
102
|
-
|
|
103
|
-
clusterName: database.name,
|
|
104
|
-
clusterId,
|
|
105
|
-
resourceType: 'TDSQL_C_SERVERLESS',
|
|
106
|
-
},
|
|
129
|
+
status: 'tainted',
|
|
107
130
|
};
|
|
108
|
-
const
|
|
109
|
-
|
|
131
|
+
const stateAfterDependents = (0, stateManager_1.setResource)(state, logicalId, taintedResourceState);
|
|
132
|
+
try {
|
|
133
|
+
let clusterId;
|
|
134
|
+
let clusterInfo = null;
|
|
135
|
+
try {
|
|
136
|
+
clusterId = await client.tdsqlc.createCluster(config);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
if ((0, alreadyExists_1.isResourceAlreadyExistsError)(error, ['ResourceInUse'])) {
|
|
140
|
+
// Idempotent adoption: a cluster with this name already exists in the
|
|
141
|
+
// provider. Adopt it ONLY if it carries our ownership tag (proves a
|
|
142
|
+
// previous run of THIS stack created it — e.g. state was reset). An
|
|
143
|
+
// untagged same-named cluster may belong to another project, so it must
|
|
144
|
+
// fail loudly rather than silently taking it over (destroy would then
|
|
145
|
+
// remove a resource that was never ours).
|
|
146
|
+
const probe = await client.tdsqlc.getClusterByName(database.name);
|
|
147
|
+
if (probe &&
|
|
148
|
+
(0, ownershipTag_1.isOwnedByStack)(context, logicalId, (0, tdsqlcTypes_1.tdsqlcTagsToOwnershipTags)(probe.ResourceTags))) {
|
|
149
|
+
logger_1.logger.info(`Cluster ${database.name} exists and carries ownership tag (${ownershipTag_1.OWNERSHIP_TAG_KEY}), adopting idempotently`);
|
|
150
|
+
clusterId = probe.ClusterId;
|
|
151
|
+
clusterInfo = probe;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
throw new types_1.PartialResourceError(stateAfterDependents, new Error(`Cluster ${database.name} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to adopt — resolve manually.`));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// Adopt path already has the probe info; fresh creates refresh via getCluster.
|
|
162
|
+
if (!clusterInfo) {
|
|
163
|
+
clusterInfo = await client.tdsqlc.getCluster(clusterId);
|
|
164
|
+
if (!clusterInfo) {
|
|
165
|
+
throw new Error(`Failed to refresh state for cluster: ${clusterId}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
const sid = (0, common_1.buildSid)('tencent', 'cynosdb', context.stage, clusterId);
|
|
169
|
+
const resourceState = {
|
|
170
|
+
mode: 'managed',
|
|
171
|
+
region: context.region,
|
|
172
|
+
definition,
|
|
173
|
+
instances: [buildTdsqlcInstanceFromProvider(clusterInfo, sid)],
|
|
174
|
+
lastUpdated: new Date().toISOString(),
|
|
175
|
+
metadata: {
|
|
176
|
+
clusterName: database.name,
|
|
177
|
+
clusterId,
|
|
178
|
+
resourceType: 'TDSQL_C_SERVERLESS',
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
return (0, stateManager_1.setResource)(state, logicalId, resourceState);
|
|
182
|
+
}
|
|
183
|
+
catch (error) {
|
|
184
|
+
if (error instanceof types_1.PartialResourceError) {
|
|
185
|
+
throw error;
|
|
186
|
+
}
|
|
187
|
+
throw new types_1.PartialResourceError(stateAfterDependents, error instanceof Error ? error : new Error(String(error)));
|
|
188
|
+
}
|
|
110
189
|
};
|
|
111
190
|
exports.createDatabaseResource = createDatabaseResource;
|
|
112
191
|
const readDatabaseResource = async (context, clusterId) => {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractTdsqlcDefinition = exports.databaseToTdsqlcConfig = void 0;
|
|
3
|
+
exports.extractTdsqlcDefinition = exports.databaseToTdsqlcConfig = exports.tdsqlcTagsToOwnershipTags = void 0;
|
|
4
|
+
// TDSQL-C tags are {TagKey,TagValue}; the ownership-tag matcher expects
|
|
5
|
+
// {Key,Value}. Convert once at the probe site.
|
|
6
|
+
const tdsqlcTagsToOwnershipTags = (tags) => (tags ?? []).map((t) => ({ Key: t.TagKey, Value: t.TagValue }));
|
|
7
|
+
exports.tdsqlcTagsToOwnershipTags = tdsqlcTagsToOwnershipTags;
|
|
4
8
|
const databaseToTdsqlcConfig = (database) => {
|
|
5
9
|
// Map version from enum to Tencent Cloud version format
|
|
6
10
|
const versionMap = {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.executeApigwPlan = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
4
5
|
const apigwResource_1 = require("./apigwResource");
|
|
5
6
|
const common_1 = require("../../common");
|
|
7
|
+
const reportResourceEvent_1 = require("../../common/reportResourceEvent");
|
|
6
8
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
9
|
const lang_1 = require("../../lang");
|
|
8
10
|
const executeSingleItem = async (context, item, eventsMap, serviceName, currentState) => {
|
|
@@ -57,13 +59,26 @@ const executeApigwPlan = async (context, plan, events, serviceName, initialState
|
|
|
57
59
|
const successfulItems = [];
|
|
58
60
|
let currentState = initialState;
|
|
59
61
|
for (const item of plan.items) {
|
|
62
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
63
|
+
type: 'resource_pre',
|
|
64
|
+
logicalId: item.logicalId,
|
|
65
|
+
resourceType: item.resourceType,
|
|
66
|
+
action: item.action,
|
|
67
|
+
...(item.drifted ? { message: 'resource drifted' } : {}),
|
|
68
|
+
});
|
|
69
|
+
const __siStartedAt = Date.now();
|
|
60
70
|
try {
|
|
61
71
|
const newState = await executeSingleItem(context, item, eventsMap, serviceName, currentState);
|
|
62
72
|
if (newState !== null) {
|
|
63
73
|
currentState = newState;
|
|
64
74
|
successfulItems.push(item);
|
|
75
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
76
|
+
type: 'resource_complete',
|
|
77
|
+
logicalId: item.logicalId,
|
|
78
|
+
durationMs: Date.now() - __siStartedAt,
|
|
79
|
+
});
|
|
65
80
|
if (onStateChange) {
|
|
66
|
-
onStateChange(currentState);
|
|
81
|
+
await onStateChange(currentState);
|
|
67
82
|
common_1.logger.debug(lang_1.lang.__('STATE_PERSISTED_AFTER_OPERATION', {
|
|
68
83
|
action: item.action,
|
|
69
84
|
resourceId: item.logicalId,
|
|
@@ -72,6 +87,29 @@ const executeApigwPlan = async (context, plan, events, serviceName, initialState
|
|
|
72
87
|
}
|
|
73
88
|
}
|
|
74
89
|
catch (error) {
|
|
90
|
+
(0, reportResourceEvent_1.reportResourceEvent)(context, {
|
|
91
|
+
type: 'resource_failed',
|
|
92
|
+
logicalId: item.logicalId,
|
|
93
|
+
severity: 'error',
|
|
94
|
+
durationMs: Date.now() - __siStartedAt,
|
|
95
|
+
error: {
|
|
96
|
+
message: error instanceof Error ? error.message : String(error),
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
if (error instanceof types_1.PartialResourceError) {
|
|
100
|
+
const updatedState = error.updatedState;
|
|
101
|
+
if (onStateChange) {
|
|
102
|
+
await onStateChange(updatedState);
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
state: updatedState,
|
|
106
|
+
partialFailure: {
|
|
107
|
+
failedItem: item,
|
|
108
|
+
error: error.cause,
|
|
109
|
+
successfulItems,
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
75
113
|
return {
|
|
76
114
|
state: currentState,
|
|
77
115
|
partialFailure: {
|
|
@@ -5,6 +5,7 @@ const volcengineClient_1 = require("../../common/volcengineClient");
|
|
|
5
5
|
const apigwTypes_1 = require("./apigwTypes");
|
|
6
6
|
const stateManager_1 = require("../../common/stateManager");
|
|
7
7
|
const hashUtils_1 = require("../../common/hashUtils");
|
|
8
|
+
const ownershipTag_1 = require("../ownershipTag");
|
|
8
9
|
const planEventDeletion = (logicalId, definition) => ({
|
|
9
10
|
logicalId,
|
|
10
11
|
action: 'delete',
|
|
@@ -23,33 +24,17 @@ const generateApigwPlan = async (context, state, events, serviceName) => {
|
|
|
23
24
|
const eventItems = await Promise.all(events.map(async (event) => {
|
|
24
25
|
const logicalId = `events.${event.key}`;
|
|
25
26
|
const currentState = (0, stateManager_1.getResource)(state, logicalId);
|
|
26
|
-
const groupConfig = (0, apigwTypes_1.eventToApigwGroupConfig)(event, serviceName, context.stage);
|
|
27
|
-
const groupDefinition = (0, apigwTypes_1.extractApigwGroupDefinition)(groupConfig);
|
|
28
27
|
const client = (0, volcengineClient_1.createVolcengineClient)(context);
|
|
29
|
-
const desiredDefinition =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
const remoteGateway = await client.apigw.findGatewayByName(groupConfig.groupName);
|
|
41
|
-
if (remoteGateway) {
|
|
42
|
-
return {
|
|
43
|
-
logicalId,
|
|
44
|
-
action: 'update',
|
|
45
|
-
resourceType: 'VOLCENGINE_APIGW',
|
|
46
|
-
changes: { after: desiredDefinition },
|
|
47
|
-
drifted: true,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
catch {
|
|
52
|
-
// Ignore errors when checking remote
|
|
28
|
+
const desiredDefinition = (0, apigwTypes_1.buildEventResourceDefinition)(event);
|
|
29
|
+
if (!currentState || currentState.status === 'tainted') {
|
|
30
|
+
// No usable local state: probe the provider before planning create.
|
|
31
|
+
// If a same-named gateway already exists WITHOUT our ownership tag it
|
|
32
|
+
// may belong to another project — fail fast in the plan instead of
|
|
33
|
+
// letting the executor discover it mid-deploy. The serverless gateway
|
|
34
|
+
// is account-scoped, so only refuse when the NAMED one is foreign.
|
|
35
|
+
const remoteGateway = await client.apigw.findGatewayByName((0, apigwTypes_1.buildGatewayName)(serviceName, context.stage));
|
|
36
|
+
if (remoteGateway?.gatewayId && !(0, ownershipTag_1.isOwnedByStack)(context, logicalId, remoteGateway.tags)) {
|
|
37
|
+
throw new Error(`API Gateway ${(0, apigwTypes_1.buildGatewayName)(serviceName, context.stage)} already exists in provider but is not owned by this stack (missing ${ownershipTag_1.OWNERSHIP_TAG_KEY} tag). Refusing to create — resolve manually.`);
|
|
53
38
|
}
|
|
54
39
|
return {
|
|
55
40
|
logicalId,
|
|
@@ -58,40 +43,30 @@ const generateApigwPlan = async (context, state, events, serviceName) => {
|
|
|
58
43
|
changes: { after: desiredDefinition },
|
|
59
44
|
};
|
|
60
45
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (!remoteGateway) {
|
|
66
|
-
return {
|
|
67
|
-
logicalId,
|
|
68
|
-
action: 'create',
|
|
69
|
-
resourceType: 'VOLCENGINE_APIGW',
|
|
70
|
-
changes: { before: currentState.definition, after: desiredDefinition },
|
|
71
|
-
drifted: true,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
const currentDefinition = currentState.definition || {};
|
|
76
|
-
const definitionChanged = !(0, hashUtils_1.attributesEqual)(currentDefinition, desiredDefinition);
|
|
77
|
-
if (definitionChanged) {
|
|
46
|
+
const serviceInstance = currentState.instances.find((i) => i.type === 'VOLCENGINE_APIGW_SERVICE');
|
|
47
|
+
if (serviceInstance) {
|
|
48
|
+
const remoteService = await client.apigw.getService(serviceInstance.id).catch(() => null);
|
|
49
|
+
if (!remoteService) {
|
|
78
50
|
return {
|
|
79
51
|
logicalId,
|
|
80
|
-
action: '
|
|
52
|
+
action: 'create',
|
|
81
53
|
resourceType: 'VOLCENGINE_APIGW',
|
|
82
|
-
changes: { before:
|
|
54
|
+
changes: { before: currentState.definition, after: desiredDefinition },
|
|
55
|
+
drifted: true,
|
|
83
56
|
};
|
|
84
57
|
}
|
|
85
|
-
return { logicalId, action: 'noop', resourceType: 'VOLCENGINE_APIGW' };
|
|
86
58
|
}
|
|
87
|
-
|
|
59
|
+
const currentDefinition = currentState.definition || {};
|
|
60
|
+
const definitionChanged = !(0, hashUtils_1.attributesEqual)(currentDefinition, desiredDefinition);
|
|
61
|
+
if (definitionChanged) {
|
|
88
62
|
return {
|
|
89
63
|
logicalId,
|
|
90
|
-
action: '
|
|
64
|
+
action: 'update',
|
|
91
65
|
resourceType: 'VOLCENGINE_APIGW',
|
|
92
|
-
changes: { before:
|
|
66
|
+
changes: { before: currentDefinition, after: desiredDefinition },
|
|
93
67
|
};
|
|
94
68
|
}
|
|
69
|
+
return { logicalId, action: 'noop', resourceType: 'VOLCENGINE_APIGW' };
|
|
95
70
|
}));
|
|
96
71
|
const allStates = (0, stateManager_1.getAllResources)(state);
|
|
97
72
|
const deletionItems = Object.entries(allStates)
|
|
@@ -99,10 +74,7 @@ const generateApigwPlan = async (context, state, events, serviceName) => {
|
|
|
99
74
|
if (!logicalId.startsWith('events.')) {
|
|
100
75
|
return false;
|
|
101
76
|
}
|
|
102
|
-
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
return true;
|
|
77
|
+
return !desiredLogicalIds.has(logicalId);
|
|
106
78
|
})
|
|
107
79
|
.map(([logicalId, resourceState]) => planEventDeletion(logicalId, resourceState.definition));
|
|
108
80
|
return { items: [...eventItems, ...deletionItems] };
|