@geek-fun/serverlessinsight 0.8.2 → 0.8.4
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 +15 -0
- package/.serverlessinsight/state-iam-test-app-iam-test-service.json.backup +33 -0
- package/.serverlessinsight/state-insight-poc-deploy-app-insight-poc-deploy.json.backup +359 -0
- package/.serverlessinsight/state-insight-poc-destroy-app-insight-poc-destroy.json.backup +15 -0
- package/.serverlessinsight/state-insight-volc-app-insight-volc.json.backup +154 -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 +5 -2
- 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 +363 -30
- 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 +90 -28
- package/dist/src/common/aliyunClient/tablestoreOperations.js +25 -22
- package/dist/src/common/apiClient.js +102 -0
- package/dist/src/common/constants.js +13 -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 +10 -4
- package/dist/src/common/stateBackend/saasStateBackend.js +266 -0
- package/dist/src/common/stateManager.js +186 -14
- package/dist/src/common/tencentClient/clsOperations.js +137 -0
- 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 +43 -2
- package/dist/src/common/tencentClient/scfOperations.js +266 -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 +91 -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 +305 -171
- package/dist/src/common/volcengineClient/tosOperations.js +78 -19
- package/dist/src/common/volcengineClient/vefaasOperations.js +272 -54
- package/dist/src/lang/en.js +107 -1
- package/dist/src/lang/zh-CN.js +107 -1
- 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 +16 -10
- package/dist/src/stack/aliyunStack/apigwResource.js +334 -125
- package/dist/src/stack/aliyunStack/apigwTypes.js +35 -4
- 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 +27 -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 +416 -94
- 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/sharedLogProject.js +137 -0
- 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 +58 -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 +15 -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 +21 -3
- package/dist/src/stack/scfStack/scfResource.js +686 -24
- package/dist/src/stack/scfStack/scfTypes.js +6 -0
- package/dist/src/stack/scfStack/sharedLogset.js +126 -0
- 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 +434 -222
- package/dist/src/stack/volcengineStack/apigwTypes.js +85 -66
- package/dist/src/stack/volcengineStack/deployer.js +49 -14
- package/dist/src/stack/volcengineStack/destroyer.js +13 -1
- package/dist/src/stack/volcengineStack/index.js +1 -2
- package/dist/src/stack/volcengineStack/sharedLogProject.js +190 -0
- 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 +78 -2
- package/dist/src/stack/volcengineStack/vefaasResource.js +194 -144
- 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 +32 -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 +5 -2
|
@@ -3,254 +3,388 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createTlsOperations = void 0;
|
|
4
4
|
const logger_1 = require("../logger");
|
|
5
5
|
const lang_1 = require("../../lang");
|
|
6
|
+
const polling_1 = require("../polling");
|
|
6
7
|
const WAIT_INTERVAL_MS = 5000;
|
|
7
8
|
const MAX_WAIT_ATTEMPTS = 30;
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const waitForProjectReady = async (getProject, projectName) => {
|
|
10
|
+
try {
|
|
11
|
+
await (0, polling_1.pollUntil)({
|
|
12
|
+
description: `TLS project ${projectName} to be ready`,
|
|
13
|
+
fetch: async () => {
|
|
14
|
+
const project = await getProject(projectName);
|
|
15
|
+
if (!project) {
|
|
16
|
+
throw new Error(lang_1.lang.__('TLS_PROJECT_NOT_FOUND', { projectName }));
|
|
17
|
+
}
|
|
18
|
+
if (project.status === 'Failed' || project.status === 'Error') {
|
|
19
|
+
throw new Error(lang_1.lang.__('TLS_PROJECT_FAILED', { projectName }));
|
|
20
|
+
}
|
|
21
|
+
return project;
|
|
22
|
+
},
|
|
23
|
+
isDone: (project) => project?.status === 'Active',
|
|
24
|
+
intervalMs: WAIT_INTERVAL_MS,
|
|
25
|
+
maxAttempts: MAX_WAIT_ATTEMPTS,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
if (e instanceof polling_1.PollingTimeoutError) {
|
|
30
|
+
throw new Error(lang_1.lang.__('TLS_PROJECT_TIMEOUT', { projectName }), { cause: e });
|
|
31
|
+
}
|
|
32
|
+
throw e;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const waitForTopicReady = async (getTopic, projectName, topicName) => {
|
|
36
|
+
try {
|
|
37
|
+
await (0, polling_1.pollUntil)({
|
|
38
|
+
description: `TLS topic ${topicName} to be ready`,
|
|
39
|
+
fetch: async () => {
|
|
40
|
+
const topic = await getTopic(projectName, topicName);
|
|
41
|
+
if (!topic) {
|
|
42
|
+
throw new Error(lang_1.lang.__('TLS_TOPIC_NOT_FOUND', { topicName }));
|
|
43
|
+
}
|
|
44
|
+
return topic;
|
|
45
|
+
},
|
|
46
|
+
isDone: (topic) => !!topic?.topicId,
|
|
47
|
+
intervalMs: WAIT_INTERVAL_MS,
|
|
48
|
+
maxAttempts: MAX_WAIT_ATTEMPTS,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
catch (e) {
|
|
52
|
+
if (e instanceof polling_1.PollingTimeoutError) {
|
|
53
|
+
throw new Error(lang_1.lang.__('TLS_TOPIC_TIMEOUT', { topicName }), { cause: e });
|
|
54
|
+
}
|
|
55
|
+
throw e;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const extractErrorCode = (error) => {
|
|
59
|
+
if (error && typeof error === 'object') {
|
|
60
|
+
const candidate = error;
|
|
61
|
+
if (candidate.code)
|
|
62
|
+
return candidate.code;
|
|
63
|
+
const nestedCode = candidate.response?.data?.Error?.Code;
|
|
64
|
+
if (nestedCode)
|
|
65
|
+
return nestedCode;
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
};
|
|
69
|
+
const isAlreadyExistsError = (error) => {
|
|
70
|
+
const code = extractErrorCode(error);
|
|
71
|
+
return (code === 'ProjectAlreadyExists' ||
|
|
72
|
+
code === 'TopicAlreadyExists' ||
|
|
73
|
+
code === 'IndexAlreadyExists' ||
|
|
74
|
+
code === 'ResourceAlreadyExists' ||
|
|
75
|
+
code === 'AlreadyExists' ||
|
|
76
|
+
code === 'Conflict' ||
|
|
77
|
+
code === 'Duplicated');
|
|
78
|
+
};
|
|
79
|
+
const isNotFoundError = (error) => {
|
|
80
|
+
const code = extractErrorCode(error);
|
|
81
|
+
return (code === 'ProjectNotFound' ||
|
|
82
|
+
code === 'TopicNotFound' ||
|
|
83
|
+
code === 'IndexNotFound' ||
|
|
84
|
+
code === 'ResourceNotFound' ||
|
|
85
|
+
code === 'NotFound');
|
|
86
|
+
};
|
|
87
|
+
const listTagsForResource = async (tlsClient, resourceType, resourceId) => {
|
|
88
|
+
try {
|
|
89
|
+
const response = await tlsClient.ListTagsForResources({
|
|
90
|
+
ResourceType: resourceType,
|
|
91
|
+
ResourcesIds: [resourceId],
|
|
92
|
+
MaxResults: 50,
|
|
93
|
+
});
|
|
94
|
+
return (response.ResourceTags ?? []).map((rt) => ({ Key: rt.TagKey, Value: rt.TagValue }));
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
if (isNotFoundError(error)) {
|
|
98
|
+
return [];
|
|
99
|
+
}
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
11
103
|
const createTlsOperations = (tlsClient) => {
|
|
12
|
-
|
|
104
|
+
const operations = {
|
|
13
105
|
createProject: async (config) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Version: '2024-01-01',
|
|
17
|
-
method: 'POST',
|
|
18
|
-
headers: { 'content-type': 'application/json' },
|
|
19
|
-
data: {
|
|
106
|
+
try {
|
|
107
|
+
const response = await tlsClient.CreateProject({
|
|
20
108
|
ProjectName: config.projectName,
|
|
21
109
|
Description: config.description,
|
|
22
|
-
Region: config.region,
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
110
|
+
Region: config.region ?? '',
|
|
111
|
+
});
|
|
112
|
+
logger_1.logger.info(lang_1.lang.__('TLS_PROJECT_CREATED', { projectName: config.projectName }));
|
|
113
|
+
return {
|
|
114
|
+
projectId: response.ProjectId,
|
|
115
|
+
projectName: config.projectName,
|
|
116
|
+
description: config.description,
|
|
117
|
+
region: config.region,
|
|
118
|
+
status: 'Active',
|
|
119
|
+
created: true,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
if (isAlreadyExistsError(error)) {
|
|
124
|
+
logger_1.logger.warn(lang_1.lang.__('TLS_PROJECT_ALREADY_EXISTS', { projectName: config.projectName }));
|
|
125
|
+
const existing = await operations.getProject(config.projectName);
|
|
126
|
+
if (existing) {
|
|
127
|
+
return { ...existing, created: false };
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
projectName: config.projectName,
|
|
131
|
+
description: config.description,
|
|
132
|
+
region: config.region,
|
|
133
|
+
status: 'Active',
|
|
134
|
+
created: false,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
throw error;
|
|
138
|
+
}
|
|
35
139
|
},
|
|
36
140
|
getProject: async (projectName) => {
|
|
37
141
|
try {
|
|
38
|
-
const response = await tlsClient.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
data: { ProjectName: projectName },
|
|
44
|
-
});
|
|
45
|
-
const data = (response.Result || {});
|
|
142
|
+
const response = await tlsClient.DescribeProjects({ ProjectName: projectName });
|
|
143
|
+
const project = response.Projects?.find((p) => p.ProjectName === projectName);
|
|
144
|
+
if (!project) {
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
46
147
|
return {
|
|
47
|
-
projectId:
|
|
48
|
-
projectName:
|
|
49
|
-
description:
|
|
50
|
-
region:
|
|
51
|
-
createTime:
|
|
52
|
-
status:
|
|
148
|
+
projectId: project.ProjectId,
|
|
149
|
+
projectName: project.ProjectName,
|
|
150
|
+
description: project.Description,
|
|
151
|
+
region: undefined,
|
|
152
|
+
createTime: project.CreateTime,
|
|
153
|
+
status: 'Active',
|
|
53
154
|
};
|
|
54
155
|
}
|
|
55
156
|
catch (error) {
|
|
56
|
-
if (error
|
|
57
|
-
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
157
|
+
if (isNotFoundError(error)) {
|
|
158
|
+
return null;
|
|
60
159
|
}
|
|
61
160
|
throw error;
|
|
62
161
|
}
|
|
63
162
|
},
|
|
163
|
+
getProjectTags: async (projectName) => {
|
|
164
|
+
const project = await operations.getProject(projectName);
|
|
165
|
+
if (!project?.projectId) {
|
|
166
|
+
return [];
|
|
167
|
+
}
|
|
168
|
+
return listTagsForResource(tlsClient, 'project', project.projectId);
|
|
169
|
+
},
|
|
64
170
|
deleteProject: async (projectName) => {
|
|
65
171
|
try {
|
|
66
|
-
await
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
});
|
|
172
|
+
const existing = await operations.getProject(projectName);
|
|
173
|
+
if (!existing?.projectId) {
|
|
174
|
+
logger_1.logger.warn(lang_1.lang.__('TLS_PROJECT_NOT_FOUND', { projectName }));
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
await tlsClient.DeleteProject({ ProjectId: existing.projectId });
|
|
73
178
|
logger_1.logger.info(lang_1.lang.__('TLS_PROJECT_DELETED', { projectName }));
|
|
74
179
|
}
|
|
75
180
|
catch (error) {
|
|
76
|
-
if (error
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
181
|
+
if (isNotFoundError(error)) {
|
|
182
|
+
logger_1.logger.warn(lang_1.lang.__('TLS_PROJECT_NOT_FOUND', { projectName }));
|
|
183
|
+
return;
|
|
81
184
|
}
|
|
82
185
|
throw error;
|
|
83
186
|
}
|
|
84
187
|
},
|
|
85
188
|
createTopic: async (config) => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
189
|
+
try {
|
|
190
|
+
const project = await operations.getProject(config.projectName);
|
|
191
|
+
if (!project?.projectId) {
|
|
192
|
+
throw new Error(lang_1.lang.__('TLS_PROJECT_NOT_FOUND', { projectName: config.projectName }));
|
|
193
|
+
}
|
|
194
|
+
const response = await tlsClient.CreateTopic({
|
|
195
|
+
ProjectId: project.projectId,
|
|
93
196
|
TopicName: config.topicName,
|
|
94
197
|
Description: config.description,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
198
|
+
Ttl: config.ttl ?? 30,
|
|
199
|
+
ShardCount: 1,
|
|
200
|
+
});
|
|
201
|
+
logger_1.logger.info(lang_1.lang.__('TLS_TOPIC_CREATED', { topicName: config.topicName }));
|
|
202
|
+
return {
|
|
203
|
+
topicId: response.TopicId,
|
|
204
|
+
topicName: config.topicName,
|
|
205
|
+
projectName: config.projectName,
|
|
206
|
+
description: config.description,
|
|
207
|
+
ttl: config.ttl ?? 30,
|
|
208
|
+
status: 'Active',
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
if (isAlreadyExistsError(error)) {
|
|
213
|
+
logger_1.logger.warn(lang_1.lang.__('TLS_TOPIC_ALREADY_EXISTS', { topicName: config.topicName }));
|
|
214
|
+
const existing = await operations.getTopic(config.projectName, config.topicName);
|
|
215
|
+
if (existing) {
|
|
216
|
+
return existing;
|
|
217
|
+
}
|
|
218
|
+
return {
|
|
219
|
+
topicName: config.topicName,
|
|
220
|
+
projectName: config.projectName,
|
|
221
|
+
description: config.description,
|
|
222
|
+
ttl: config.ttl ?? 30,
|
|
223
|
+
status: 'Active',
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
throw error;
|
|
227
|
+
}
|
|
109
228
|
},
|
|
110
229
|
getTopic: async (projectName, topicName) => {
|
|
111
230
|
try {
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
TopicName: topicName,
|
|
120
|
-
},
|
|
231
|
+
const project = await operations.getProject(projectName);
|
|
232
|
+
if (!project?.projectId) {
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
const response = await tlsClient.DescribeTopics({
|
|
236
|
+
ProjectId: project.projectId,
|
|
237
|
+
TopicName: topicName,
|
|
121
238
|
});
|
|
122
|
-
const
|
|
239
|
+
const topic = response.Topics?.find((t) => t.TopicName === topicName);
|
|
240
|
+
if (!topic) {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
const tags = await listTagsForResource(tlsClient, 'topic', topic.TopicId);
|
|
123
244
|
return {
|
|
124
|
-
topicId:
|
|
125
|
-
topicName:
|
|
126
|
-
projectName
|
|
127
|
-
description:
|
|
128
|
-
ttl:
|
|
129
|
-
createTime:
|
|
130
|
-
status:
|
|
245
|
+
topicId: topic.TopicId,
|
|
246
|
+
topicName: topic.TopicName,
|
|
247
|
+
projectName,
|
|
248
|
+
description: topic.Description,
|
|
249
|
+
ttl: topic.Ttl,
|
|
250
|
+
createTime: topic.CreateTime,
|
|
251
|
+
status: 'Active',
|
|
252
|
+
tags,
|
|
131
253
|
};
|
|
132
254
|
}
|
|
133
255
|
catch (error) {
|
|
134
|
-
if (error
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
256
|
+
if (isNotFoundError(error)) {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
throw error;
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
listTopics: async (projectName) => {
|
|
263
|
+
try {
|
|
264
|
+
const project = await operations.getProject(projectName);
|
|
265
|
+
if (!project?.projectId) {
|
|
266
|
+
return [];
|
|
267
|
+
}
|
|
268
|
+
const response = await tlsClient.DescribeTopics({ ProjectId: project.projectId });
|
|
269
|
+
return (response.Topics ?? []).map((topic) => ({
|
|
270
|
+
topicId: topic.TopicId,
|
|
271
|
+
topicName: topic.TopicName,
|
|
272
|
+
projectName,
|
|
273
|
+
description: topic.Description,
|
|
274
|
+
ttl: topic.Ttl,
|
|
275
|
+
createTime: topic.CreateTime,
|
|
276
|
+
status: 'Active',
|
|
277
|
+
}));
|
|
278
|
+
}
|
|
279
|
+
catch (error) {
|
|
280
|
+
if (isNotFoundError(error)) {
|
|
281
|
+
return [];
|
|
138
282
|
}
|
|
139
283
|
throw error;
|
|
140
284
|
}
|
|
141
285
|
},
|
|
142
286
|
deleteTopic: async (projectName, topicName) => {
|
|
143
287
|
try {
|
|
144
|
-
await
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
ProjectName: projectName,
|
|
151
|
-
TopicName: topicName,
|
|
152
|
-
},
|
|
153
|
-
});
|
|
288
|
+
const existing = await operations.getTopic(projectName, topicName);
|
|
289
|
+
if (!existing?.topicId) {
|
|
290
|
+
logger_1.logger.warn(lang_1.lang.__('TLS_TOPIC_NOT_FOUND', { topicName }));
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
await tlsClient.DeleteTopic({ TopicId: existing.topicId });
|
|
154
294
|
logger_1.logger.info(lang_1.lang.__('TLS_TOPIC_DELETED', { topicName }));
|
|
155
295
|
}
|
|
156
296
|
catch (error) {
|
|
157
|
-
if (error
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
297
|
+
if (isNotFoundError(error)) {
|
|
298
|
+
logger_1.logger.warn(lang_1.lang.__('TLS_TOPIC_NOT_FOUND', { topicName }));
|
|
299
|
+
return;
|
|
162
300
|
}
|
|
163
301
|
throw error;
|
|
164
302
|
}
|
|
165
303
|
},
|
|
166
304
|
createIndex: async (config) => {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
FullTextIndex: config.fullTextIndex
|
|
305
|
+
try {
|
|
306
|
+
const topic = await operations.getTopic(config.projectName, config.topicName);
|
|
307
|
+
if (!topic?.topicId) {
|
|
308
|
+
throw new Error(lang_1.lang.__('TLS_TOPIC_NOT_FOUND', { topicName: config.topicName }));
|
|
309
|
+
}
|
|
310
|
+
await tlsClient.CreateIndex({
|
|
311
|
+
TopicId: topic.topicId,
|
|
312
|
+
FullText: config.fullTextIndex
|
|
176
313
|
? {
|
|
177
314
|
Delimiter: config.fullTextIndex.delimiter ?? ' ,.?;!\n\t',
|
|
178
315
|
CaseSensitive: config.fullTextIndex.caseSensitive ?? false,
|
|
179
316
|
}
|
|
180
317
|
: undefined,
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
318
|
+
KeyValue: config.keyValueIndex?.map((kv) => ({
|
|
319
|
+
Key: kv.key,
|
|
320
|
+
Value: { ValueType: kv.type, SqlFlag: true },
|
|
321
|
+
})),
|
|
322
|
+
});
|
|
323
|
+
logger_1.logger.info(lang_1.lang.__('TLS_INDEX_CREATED', { topicName: config.topicName }));
|
|
324
|
+
}
|
|
325
|
+
catch (error) {
|
|
326
|
+
if (isAlreadyExistsError(error)) {
|
|
327
|
+
logger_1.logger.warn(lang_1.lang.__('TLS_INDEX_ALREADY_EXISTS', { topicName: config.topicName }));
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
throw error;
|
|
331
|
+
}
|
|
185
332
|
},
|
|
186
333
|
deleteIndex: async (projectName, topicName) => {
|
|
187
334
|
try {
|
|
188
|
-
await
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
data: {
|
|
194
|
-
ProjectName: projectName,
|
|
195
|
-
TopicName: topicName,
|
|
196
|
-
},
|
|
197
|
-
});
|
|
335
|
+
const topic = await operations.getTopic(projectName, topicName);
|
|
336
|
+
if (!topic?.topicId) {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
await tlsClient.DeleteIndex({ TopicId: topic.topicId });
|
|
198
340
|
logger_1.logger.info(lang_1.lang.__('TLS_INDEX_DELETED', { topicName }));
|
|
199
341
|
}
|
|
200
342
|
catch (error) {
|
|
201
|
-
if (error
|
|
202
|
-
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
343
|
+
if (isNotFoundError(error)) {
|
|
344
|
+
return;
|
|
205
345
|
}
|
|
206
346
|
throw error;
|
|
207
347
|
}
|
|
208
348
|
},
|
|
209
349
|
waitForProject: async (projectName) => {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
350
|
+
await waitForProjectReady(operations.getProject, projectName);
|
|
351
|
+
},
|
|
352
|
+
waitForTopic: async (projectName, topicName) => {
|
|
353
|
+
await waitForTopicReady(operations.getTopic, projectName, topicName);
|
|
354
|
+
},
|
|
355
|
+
addTags: async (config) => {
|
|
356
|
+
try {
|
|
357
|
+
await tlsClient.AddTagsToResource({
|
|
358
|
+
ResourceType: config.resourceType,
|
|
359
|
+
ResourcesList: config.resourcesList,
|
|
360
|
+
Tags: config.tags.map((tag) => ({ Key: tag.key, Value: tag.value })),
|
|
217
361
|
});
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
if (
|
|
362
|
+
}
|
|
363
|
+
catch (error) {
|
|
364
|
+
if (isNotFoundError(error)) {
|
|
365
|
+
logger_1.logger.warn(lang_1.lang.__('TLS_TAG_TARGET_NOT_FOUND', { resourceType: config.resourceType }));
|
|
221
366
|
return;
|
|
222
367
|
}
|
|
223
|
-
|
|
224
|
-
throw new Error(lang_1.lang.__('TLS_PROJECT_FAILED', { projectName }));
|
|
225
|
-
}
|
|
226
|
-
await delay(WAIT_INTERVAL_MS);
|
|
368
|
+
throw error;
|
|
227
369
|
}
|
|
228
|
-
throw new Error(lang_1.lang.__('TLS_PROJECT_TIMEOUT', { projectName }));
|
|
229
370
|
},
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
headers: { 'content-type': 'application/json' },
|
|
237
|
-
data: {
|
|
238
|
-
ProjectName: projectName,
|
|
239
|
-
TopicName: topicName,
|
|
240
|
-
},
|
|
371
|
+
removeTags: async (config) => {
|
|
372
|
+
try {
|
|
373
|
+
await tlsClient.RemoveTagsFromResource({
|
|
374
|
+
ResourceType: config.resourceType,
|
|
375
|
+
ResourcesList: config.resourcesList,
|
|
376
|
+
TagKeyList: config.tagKeys,
|
|
241
377
|
});
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
if (
|
|
378
|
+
}
|
|
379
|
+
catch (error) {
|
|
380
|
+
if (isNotFoundError(error)) {
|
|
381
|
+
logger_1.logger.warn(lang_1.lang.__('TLS_TAG_TARGET_NOT_FOUND', { resourceType: config.resourceType }));
|
|
245
382
|
return;
|
|
246
383
|
}
|
|
247
|
-
|
|
248
|
-
throw new Error(lang_1.lang.__('TLS_TOPIC_FAILED', { topicName }));
|
|
249
|
-
}
|
|
250
|
-
await delay(WAIT_INTERVAL_MS);
|
|
384
|
+
throw error;
|
|
251
385
|
}
|
|
252
|
-
throw new Error(lang_1.lang.__('TLS_TOPIC_TIMEOUT', { topicName }));
|
|
253
386
|
},
|
|
254
387
|
};
|
|
388
|
+
return operations;
|
|
255
389
|
};
|
|
256
390
|
exports.createTlsOperations = createTlsOperations;
|