@geek-fun/serverlessinsight 0.4.0 → 0.5.0
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/.gitattributes +1 -0
- package/README.md +108 -8
- package/README.zh-CN.md +52 -8
- package/dist/package.json +37 -35
- package/dist/src/commands/deploy.js +17 -7
- package/dist/src/commands/destroy.js +27 -4
- package/dist/src/commands/forceUnlock.js +61 -0
- package/dist/src/commands/index.js +86 -14
- package/dist/src/commands/local.js +10 -1
- package/dist/src/commands/plan.js +33 -0
- package/dist/src/commands/template.js +3 -1
- package/dist/src/commands/validate.js +2 -1
- package/dist/src/common/aliyunClient/apigwOperations.js +652 -0
- package/dist/src/common/aliyunClient/dnsOperations.js +90 -0
- package/dist/src/common/aliyunClient/ecsOperations.js +141 -0
- package/dist/src/common/aliyunClient/esOperations.js +219 -0
- package/dist/src/common/aliyunClient/fc3Operations.js +270 -0
- package/dist/src/common/aliyunClient/index.js +141 -0
- package/dist/src/common/aliyunClient/nasOperations.js +233 -0
- package/dist/src/common/aliyunClient/ossOperations.js +237 -0
- package/dist/src/common/aliyunClient/ramOperations.js +205 -0
- package/dist/src/common/aliyunClient/rdsOperations.js +206 -0
- package/dist/src/common/aliyunClient/slsOperations.js +218 -0
- package/dist/src/common/aliyunClient/tablestoreOperations.js +199 -0
- package/dist/src/common/aliyunClient/types.js +2 -0
- package/dist/src/common/constants.js +7 -1
- package/dist/src/common/context.js +32 -14
- package/dist/src/common/credentials.js +39 -0
- package/dist/src/common/dependencyGraph/graph.js +280 -0
- package/dist/src/common/dependencyGraph/index.js +18 -0
- package/dist/src/common/dependencyGraph/types.js +2 -0
- package/dist/src/common/fileUtils.js +16 -0
- package/dist/src/common/hashUtils.js +121 -0
- package/dist/src/common/iacHelper.js +25 -97
- package/dist/src/common/imsClient.js +4 -0
- package/dist/src/common/index.js +7 -2
- package/dist/src/common/lockManager.js +212 -0
- package/dist/src/common/logger.js +89 -6
- package/dist/src/common/providerEnum.js +2 -3
- package/dist/src/common/runtimeMapper.js +160 -0
- package/dist/src/common/scfClient.js +84 -0
- package/dist/src/common/stateManager.js +107 -0
- package/dist/src/common/tencentClient/cosOperations.js +287 -0
- package/dist/src/common/tencentClient/esOperations.js +156 -0
- package/dist/src/common/tencentClient/index.js +116 -0
- package/dist/src/common/tencentClient/scfOperations.js +141 -0
- package/dist/src/common/tencentClient/tdsqlcOperations.js +211 -0
- package/dist/src/common/tencentClient/types.js +17 -0
- package/dist/src/lang/en.js +254 -0
- package/dist/src/lang/index.js +28 -8
- package/dist/src/lang/zh-CN.js +229 -0
- package/dist/src/parser/bucketParser.js +25 -12
- package/dist/src/parser/databaseParser.js +14 -10
- package/dist/src/parser/functionParser.js +19 -6
- package/dist/src/parser/parseUtils.js +74 -0
- package/dist/src/parser/tableParser.js +19 -17
- package/dist/src/stack/aliyunStack/apigwExecutor.js +84 -0
- package/dist/src/stack/aliyunStack/apigwPlanner.js +118 -0
- package/dist/src/stack/aliyunStack/apigwResource.js +339 -0
- package/dist/src/stack/aliyunStack/apigwTypes.js +125 -0
- package/dist/src/stack/aliyunStack/databaseExecutor.js +112 -0
- package/dist/src/stack/aliyunStack/databasePlanner.js +128 -0
- package/dist/src/stack/aliyunStack/databaseResource.js +228 -0
- package/dist/src/stack/aliyunStack/deployer.js +133 -0
- package/dist/src/stack/aliyunStack/destroyer.js +114 -0
- package/dist/src/stack/aliyunStack/esServerlessTypes.js +141 -0
- package/dist/src/stack/aliyunStack/fc3Executor.js +91 -0
- package/dist/src/stack/aliyunStack/fc3Planner.js +77 -0
- package/dist/src/stack/aliyunStack/fc3Resource.js +511 -0
- package/dist/src/stack/aliyunStack/fc3Types.js +76 -0
- package/dist/src/stack/aliyunStack/index.js +40 -0
- package/dist/src/stack/aliyunStack/ossExecutor.js +91 -0
- package/dist/src/stack/aliyunStack/ossPlanner.js +76 -0
- package/dist/src/stack/aliyunStack/ossResource.js +196 -0
- package/dist/src/stack/aliyunStack/ossTypes.js +50 -0
- package/dist/src/stack/aliyunStack/planner.js +37 -0
- package/dist/src/stack/aliyunStack/rdsTypes.js +217 -0
- package/dist/src/stack/aliyunStack/tablestoreExecutor.js +92 -0
- package/dist/src/stack/aliyunStack/tablestorePlanner.js +94 -0
- package/dist/src/stack/aliyunStack/tablestoreResource.js +120 -0
- package/dist/src/stack/aliyunStack/tablestoreTypes.js +77 -0
- package/dist/src/stack/bucketTypes.js +17 -0
- package/dist/src/stack/deploy.js +24 -77
- package/dist/src/stack/localStack/bucket.js +11 -6
- package/dist/src/stack/localStack/event.js +10 -5
- package/dist/src/stack/localStack/function.js +13 -7
- package/dist/src/stack/localStack/functionRunner.js +1 -1
- package/dist/src/stack/localStack/localServer.js +7 -6
- package/dist/src/stack/scfStack/cosExecutor.js +91 -0
- package/dist/src/stack/scfStack/cosPlanner.js +76 -0
- package/dist/src/stack/scfStack/cosResource.js +126 -0
- package/dist/src/stack/scfStack/cosTypes.js +46 -0
- package/dist/src/stack/scfStack/deployer.js +91 -0
- package/dist/src/stack/scfStack/destroyer.js +88 -0
- package/dist/src/stack/scfStack/esServerlessExecutor.js +105 -0
- package/dist/src/stack/scfStack/esServerlessPlanner.js +86 -0
- package/dist/src/stack/scfStack/esServerlessResource.js +94 -0
- package/dist/src/stack/scfStack/esServerlessTypes.js +48 -0
- package/dist/src/stack/scfStack/index.js +35 -0
- package/dist/src/stack/scfStack/planner.js +91 -0
- package/dist/src/stack/scfStack/scfExecutor.js +91 -0
- package/dist/src/stack/scfStack/scfPlanner.js +78 -0
- package/dist/src/stack/scfStack/scfResource.js +216 -0
- package/dist/src/stack/scfStack/scfTypes.js +41 -0
- package/dist/src/stack/scfStack/tdsqlcExecutor.js +105 -0
- package/dist/src/stack/scfStack/tdsqlcPlanner.js +90 -0
- package/dist/src/stack/scfStack/tdsqlcResource.js +146 -0
- package/dist/src/stack/scfStack/tdsqlcTypes.js +59 -0
- package/dist/src/types/domains/lock.js +2 -0
- package/dist/src/types/domains/resolvable.js +2 -0
- package/dist/src/types/domains/state.js +19 -0
- package/dist/src/types/index.js +4 -0
- package/dist/src/validator/bucketSchema.js +4 -10
- package/dist/src/validator/databaseSchema.js +36 -36
- package/dist/src/validator/eventSchema.js +3 -2
- package/dist/src/validator/functionSchema.js +51 -46
- package/dist/src/validator/iacSchema.js +52 -3
- package/dist/src/validator/rootSchema.js +47 -1
- package/dist/src/validator/tableschema.js +9 -8
- package/dist/src/validator/templateRefSchema.js +23 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +37 -35
- package/samples/README_TENCENT_COS.md +486 -0
- package/samples/README_TENCENT_SCF.md +272 -0
- package/samples/aliyun-poc-api.yml +1 -1
- package/samples/aliyun-poc-bucket.yml +0 -1
- package/samples/aliyun-poc-domain.yml +0 -1
- package/samples/aliyun-poc-es.yml +14 -13
- package/samples/aliyun-poc-rds.yml +0 -2
- package/samples/aliyun-poc-table.yml +1 -3
- package/samples/tencent-poc-cos.yml +20 -0
- package/samples/tencent-poc-scf.yml +36 -0
- package/dist/src/commands/index.d.ts +0 -2
- package/dist/src/common/index.d.ts +0 -11
- package/dist/src/common/rosAssets.js +0 -178
- package/dist/src/common/rosClient.js +0 -198
- package/dist/src/index.d.ts +0 -1
- package/dist/src/lang/index.d.ts +0 -3
- package/dist/src/parser/index.d.ts +0 -3
- package/dist/src/stack/index.d.ts +0 -1
- package/dist/src/stack/localStack/index.d.ts +0 -5
- package/dist/src/stack/rfsStack/index.d.ts +0 -9
- package/dist/src/stack/rosStack/bootstrap.js +0 -187
- package/dist/src/stack/rosStack/bucket.js +0 -127
- package/dist/src/stack/rosStack/database.js +0 -313
- package/dist/src/stack/rosStack/event.js +0 -143
- package/dist/src/stack/rosStack/function.js +0 -259
- package/dist/src/stack/rosStack/index.d.ts +0 -7
- package/dist/src/stack/rosStack/index.js +0 -75
- package/dist/src/stack/rosStack/stage.js +0 -46
- package/dist/src/stack/rosStack/table.js +0 -95
- package/dist/src/stack/rosStack/tag.js +0 -11
- package/dist/src/stack/rosStack/vars.js +0 -49
- package/dist/src/types/index.d.ts +0 -55
- package/dist/src/types/localStack/index.d.ts +0 -81
- package/dist/src/validator/index.d.ts +0 -1
- package/layers/si-bootstrap-sdk/Dockerfile-aliyuncli +0 -12
- package/layers/si-bootstrap-sdk/README.md +0 -1
- package/layers/si-bootstrap-sdk/package-lock.json +0 -875
- package/layers/si-bootstrap-sdk/package.json +0 -33
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createSlsOperations = void 0;
|
|
37
|
+
const sls = __importStar(require("@alicloud/sls20201230"));
|
|
38
|
+
const waitForSlsProject = async (getProject, projectName) => {
|
|
39
|
+
let retries = 0;
|
|
40
|
+
while (retries < 30) {
|
|
41
|
+
try {
|
|
42
|
+
const project = await getProject(projectName);
|
|
43
|
+
if (project && project.status === 'Normal') {
|
|
44
|
+
return project;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
// Project not ready yet
|
|
49
|
+
}
|
|
50
|
+
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
51
|
+
retries++;
|
|
52
|
+
}
|
|
53
|
+
return { projectName };
|
|
54
|
+
};
|
|
55
|
+
const waitForSlsLogstore = async (getLogstore, projectName, logstoreName, ttl) => {
|
|
56
|
+
let retries = 0;
|
|
57
|
+
while (retries < 30) {
|
|
58
|
+
try {
|
|
59
|
+
const logstore = await getLogstore(projectName, logstoreName);
|
|
60
|
+
if (logstore) {
|
|
61
|
+
return logstore;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// Logstore not ready yet
|
|
66
|
+
}
|
|
67
|
+
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
68
|
+
retries++;
|
|
69
|
+
}
|
|
70
|
+
return { logstoreName, projectName, ttl };
|
|
71
|
+
};
|
|
72
|
+
const createSlsOperations = (slsClient) => {
|
|
73
|
+
const operations = {
|
|
74
|
+
createProject: async (projectName, description) => {
|
|
75
|
+
const request = new sls.CreateProjectRequest({
|
|
76
|
+
projectName,
|
|
77
|
+
description: description ?? `ServerlessInsight log project for ${projectName}`,
|
|
78
|
+
});
|
|
79
|
+
await slsClient.createProject(request);
|
|
80
|
+
// Wait for project to be ready
|
|
81
|
+
return await waitForSlsProject(operations.getProject, projectName);
|
|
82
|
+
},
|
|
83
|
+
getProject: async (projectName) => {
|
|
84
|
+
try {
|
|
85
|
+
const response = await slsClient.getProject(projectName);
|
|
86
|
+
if (!response || !response.body) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
projectName: response.body.name ?? projectName,
|
|
91
|
+
description: response.body.description,
|
|
92
|
+
status: response.body.status,
|
|
93
|
+
createTime: response.body.createTime,
|
|
94
|
+
lastModifyTime: response.body.lastModifyTime,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
if (error &&
|
|
99
|
+
typeof error === 'object' &&
|
|
100
|
+
'code' in error &&
|
|
101
|
+
error.code === 'ProjectNotExist') {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
deleteProject: async (projectName) => {
|
|
108
|
+
const request = new sls.DeleteProjectRequest({});
|
|
109
|
+
await slsClient.deleteProject(projectName, request);
|
|
110
|
+
},
|
|
111
|
+
createLogstore: async (projectName, logstoreName, ttl = 7) => {
|
|
112
|
+
const request = new sls.CreateLogStoreRequest({
|
|
113
|
+
logstoreName,
|
|
114
|
+
ttl,
|
|
115
|
+
shardCount: 2,
|
|
116
|
+
});
|
|
117
|
+
await slsClient.createLogStore(projectName, request);
|
|
118
|
+
// Wait for logstore to be ready
|
|
119
|
+
return await waitForSlsLogstore(operations.getLogstore, projectName, logstoreName, ttl);
|
|
120
|
+
},
|
|
121
|
+
getLogstore: async (projectName, logstoreName) => {
|
|
122
|
+
try {
|
|
123
|
+
const response = await slsClient.getLogStore(projectName, logstoreName);
|
|
124
|
+
if (!response || !response.body) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
logstoreName: response.body.logstoreName ?? logstoreName,
|
|
129
|
+
projectName,
|
|
130
|
+
ttl: response.body.ttl,
|
|
131
|
+
shardCount: response.body.shardCount,
|
|
132
|
+
createTime: response.body.createTime,
|
|
133
|
+
lastModifyTime: response.body.lastModifyTime,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
if (error &&
|
|
138
|
+
typeof error === 'object' &&
|
|
139
|
+
'code' in error &&
|
|
140
|
+
error.code === 'LogStoreNotExist') {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
deleteLogstore: async (projectName, logstoreName) => {
|
|
147
|
+
await slsClient.deleteLogStore(projectName, logstoreName);
|
|
148
|
+
},
|
|
149
|
+
createIndex: async (projectName, logstoreName) => {
|
|
150
|
+
const request = new sls.CreateIndexRequest({
|
|
151
|
+
body: new sls.Index({
|
|
152
|
+
line: new sls.IndexLine({
|
|
153
|
+
token: [
|
|
154
|
+
',',
|
|
155
|
+
' ',
|
|
156
|
+
"'",
|
|
157
|
+
'"',
|
|
158
|
+
';',
|
|
159
|
+
'=',
|
|
160
|
+
'(',
|
|
161
|
+
')',
|
|
162
|
+
'[',
|
|
163
|
+
']',
|
|
164
|
+
'{',
|
|
165
|
+
'}',
|
|
166
|
+
'?',
|
|
167
|
+
'@',
|
|
168
|
+
'&',
|
|
169
|
+
'<',
|
|
170
|
+
'>',
|
|
171
|
+
'/',
|
|
172
|
+
':',
|
|
173
|
+
'\n',
|
|
174
|
+
'\t',
|
|
175
|
+
'\r',
|
|
176
|
+
],
|
|
177
|
+
}),
|
|
178
|
+
}),
|
|
179
|
+
});
|
|
180
|
+
await slsClient.createIndex(projectName, logstoreName, request);
|
|
181
|
+
return { projectName, logstoreName };
|
|
182
|
+
},
|
|
183
|
+
getIndex: async (projectName, logstoreName) => {
|
|
184
|
+
try {
|
|
185
|
+
const response = await slsClient.getIndex(projectName, logstoreName);
|
|
186
|
+
if (!response || !response.body) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
projectName,
|
|
191
|
+
logstoreName,
|
|
192
|
+
indexMode: response.body.indexMode,
|
|
193
|
+
lastModifyTime: response.body.lastModifyTime,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
if (error &&
|
|
198
|
+
typeof error === 'object' &&
|
|
199
|
+
'code' in error &&
|
|
200
|
+
error.code === 'IndexConfigNotExist') {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
throw error;
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
deleteIndex: async (projectName, logstoreName) => {
|
|
207
|
+
await slsClient.deleteIndex(projectName, logstoreName);
|
|
208
|
+
},
|
|
209
|
+
waitForProject: async (projectName) => {
|
|
210
|
+
return waitForSlsProject(operations.getProject, projectName);
|
|
211
|
+
},
|
|
212
|
+
waitForLogstore: async (projectName, logstoreName, ttl = 7) => {
|
|
213
|
+
return waitForSlsLogstore(operations.getLogstore, projectName, logstoreName, ttl);
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
return operations;
|
|
217
|
+
};
|
|
218
|
+
exports.createSlsOperations = createSlsOperations;
|
|
@@ -0,0 +1,199 @@
|
|
|
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.createTablestoreOperations = exports.TableStoreInstanceStatus = void 0;
|
|
7
|
+
const tablestore_1 = __importDefault(require("tablestore"));
|
|
8
|
+
const logger_1 = require("../logger");
|
|
9
|
+
var TableStoreInstanceStatus;
|
|
10
|
+
(function (TableStoreInstanceStatus) {
|
|
11
|
+
TableStoreInstanceStatus["RUNNING"] = "RUNNING";
|
|
12
|
+
TableStoreInstanceStatus["CREATING"] = "CREATING";
|
|
13
|
+
TableStoreInstanceStatus["DELETED"] = "DELETED";
|
|
14
|
+
TableStoreInstanceStatus["DISABLED"] = "DISABLED";
|
|
15
|
+
})(TableStoreInstanceStatus || (exports.TableStoreInstanceStatus = TableStoreInstanceStatus = {}));
|
|
16
|
+
const waitForTableReady = async (describeTable, tableName) => {
|
|
17
|
+
const maxAttempts = 60;
|
|
18
|
+
let attempts = 0;
|
|
19
|
+
while (attempts < maxAttempts) {
|
|
20
|
+
try {
|
|
21
|
+
const table = await describeTable(tableName);
|
|
22
|
+
if (table) {
|
|
23
|
+
logger_1.logger.info(`Table ${tableName} is ready`);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
// Table might not exist yet during creation
|
|
29
|
+
if (attempts < maxAttempts - 1) {
|
|
30
|
+
logger_1.logger.info(`Waiting for table ${tableName} to be ready... (attempt ${attempts + 1}/${maxAttempts})`);
|
|
31
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
32
|
+
attempts++;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
38
|
+
attempts++;
|
|
39
|
+
}
|
|
40
|
+
throw new Error(`Timeout waiting for table ${tableName} to be ready`);
|
|
41
|
+
};
|
|
42
|
+
const createTablestoreOperations = (endpoint, instanceName, context) => {
|
|
43
|
+
const client = new tablestore_1.default.Client({
|
|
44
|
+
accessKeyId: context.accessKeyId,
|
|
45
|
+
secretAccessKey: context.accessKeySecret,
|
|
46
|
+
stsToken: context.securityToken,
|
|
47
|
+
endpoint,
|
|
48
|
+
instancename: instanceName,
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
createTable: async (config) => {
|
|
52
|
+
const params = {
|
|
53
|
+
tableMeta: {
|
|
54
|
+
tableName: config.tableName,
|
|
55
|
+
primaryKey: config.primaryKey.map((pk) => ({
|
|
56
|
+
name: pk.name,
|
|
57
|
+
type: pk.type,
|
|
58
|
+
})),
|
|
59
|
+
},
|
|
60
|
+
reservedThroughput: config.reservedThroughput || {
|
|
61
|
+
capacityUnit: {
|
|
62
|
+
read: 0,
|
|
63
|
+
write: 0,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
tableOptions: config.tableOptions || {
|
|
67
|
+
timeToLive: -1,
|
|
68
|
+
maxVersions: 1,
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
return new Promise((resolve, reject) => {
|
|
72
|
+
client.createTable(params, (err) => {
|
|
73
|
+
if (err) {
|
|
74
|
+
logger_1.logger.error(`Failed to create table ${config.tableName}: ${err.message}`);
|
|
75
|
+
reject(err);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
logger_1.logger.info(`Successfully created table ${config.tableName}`);
|
|
79
|
+
resolve();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
},
|
|
84
|
+
getTable: async (tableName) => {
|
|
85
|
+
const params = {
|
|
86
|
+
tableName,
|
|
87
|
+
};
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
client.describeTable(params, (err, data) => {
|
|
90
|
+
if (err) {
|
|
91
|
+
const errorMessage = err.message || String(err);
|
|
92
|
+
if (errorMessage.includes('OTSObjectNotExist') ||
|
|
93
|
+
errorMessage.includes('does not exist')) {
|
|
94
|
+
resolve(null);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
logger_1.logger.error(`Failed to describe table ${tableName}: ${errorMessage}`);
|
|
98
|
+
reject(err);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
const result = data;
|
|
103
|
+
if (!result.tableMeta) {
|
|
104
|
+
resolve(null);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
resolve({
|
|
108
|
+
tableName: result.tableMeta.tableName || tableName,
|
|
109
|
+
primaryKey: result.tableMeta.primaryKey,
|
|
110
|
+
reservedThroughputDetails: result.reservedThroughputDetails,
|
|
111
|
+
tableOptions: result.tableOptions,
|
|
112
|
+
streamDetails: result.streamDetails,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
updateTable: async (config) => {
|
|
120
|
+
const params = {
|
|
121
|
+
tableName: config.tableName,
|
|
122
|
+
reservedThroughput: config.reservedThroughput || {
|
|
123
|
+
capacityUnit: {
|
|
124
|
+
read: 0,
|
|
125
|
+
write: 0,
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
tableOptions: config.tableOptions,
|
|
129
|
+
};
|
|
130
|
+
return new Promise((resolve, reject) => {
|
|
131
|
+
client.updateTable(params, (err) => {
|
|
132
|
+
if (err) {
|
|
133
|
+
logger_1.logger.error(`Failed to update table ${config.tableName}: ${err.message}`);
|
|
134
|
+
reject(err);
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
logger_1.logger.info(`Successfully updated table ${config.tableName}`);
|
|
138
|
+
resolve();
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
},
|
|
143
|
+
deleteTable: async (tableName) => {
|
|
144
|
+
const params = {
|
|
145
|
+
tableName,
|
|
146
|
+
};
|
|
147
|
+
return new Promise((resolve, reject) => {
|
|
148
|
+
client.deleteTable(params, (err) => {
|
|
149
|
+
if (err) {
|
|
150
|
+
const errorMessage = err.message || String(err);
|
|
151
|
+
// If table doesn't exist, consider deletion successful
|
|
152
|
+
if (errorMessage.includes('OTSObjectNotExist') ||
|
|
153
|
+
errorMessage.includes('does not exist')) {
|
|
154
|
+
logger_1.logger.info(`Table ${tableName} already deleted or does not exist`);
|
|
155
|
+
resolve();
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
logger_1.logger.error(`Failed to delete table ${tableName}: ${errorMessage}`);
|
|
159
|
+
reject(err);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
logger_1.logger.info(`Successfully deleted table ${tableName}`);
|
|
164
|
+
resolve();
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
},
|
|
169
|
+
waitForTableReady: async (tableName) => {
|
|
170
|
+
return waitForTableReady(async (name) => {
|
|
171
|
+
try {
|
|
172
|
+
return await new Promise((resolve, reject) => {
|
|
173
|
+
client.describeTable({ tableName: name }, (err, data) => {
|
|
174
|
+
if (err) {
|
|
175
|
+
reject(err);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
const result = data;
|
|
179
|
+
if (!result.tableMeta) {
|
|
180
|
+
resolve(null);
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
resolve({
|
|
184
|
+
tableName: result.tableMeta.tableName || name,
|
|
185
|
+
primaryKey: result.tableMeta.primaryKey,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
}, tableName);
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
exports.createTablestoreOperations = createTablestoreOperations;
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SI_LOCALSTACK_SERVER_PORT = exports.SI_BOOTSTRAP_BUCKET_PREFIX = exports.SI_BOOTSTRAP_FC_PREFIX = exports.OSS_DEPLOYMENT_TIMEOUT = exports.CODE_ZIP_SIZE_LIMIT = void 0;
|
|
3
|
+
exports.STALE_LOCK_THRESHOLD = exports.DEFAULT_LOCK_RETRY_DELAY = exports.DEFAULT_LOCK_TIMEOUT = exports.LOCK_FILE_SUFFIX = exports.SI_LOCALSTACK_SERVER_PORT = exports.SI_BOOTSTRAP_BUCKET_PREFIX = exports.SI_BOOTSTRAP_FC_PREFIX = exports.ROS_STACK_OPERATION_TIMEOUT = exports.OSS_DEPLOYMENT_TIMEOUT = exports.CODE_ZIP_SIZE_LIMIT = void 0;
|
|
4
4
|
exports.CODE_ZIP_SIZE_LIMIT = 300 * 1000; // 300 KB ROS TemplateBody size limit 512 KB
|
|
5
5
|
exports.OSS_DEPLOYMENT_TIMEOUT = 3000; // in seconds
|
|
6
|
+
exports.ROS_STACK_OPERATION_TIMEOUT = 3600; // in seconds
|
|
6
7
|
exports.SI_BOOTSTRAP_FC_PREFIX = 'si-bootstrap-api';
|
|
7
8
|
exports.SI_BOOTSTRAP_BUCKET_PREFIX = 'si-bootstrap-artifacts';
|
|
8
9
|
exports.SI_LOCALSTACK_SERVER_PORT = 4567;
|
|
10
|
+
// Lock manager constants
|
|
11
|
+
exports.LOCK_FILE_SUFFIX = '.si-lock';
|
|
12
|
+
exports.DEFAULT_LOCK_TIMEOUT = 10 * 60 * 1000; // 10 minutes
|
|
13
|
+
exports.DEFAULT_LOCK_RETRY_DELAY = 2000; // 2 seconds
|
|
14
|
+
exports.STALE_LOCK_THRESHOLD = 60 * 60 * 1000; // 1 hour
|
|
@@ -3,13 +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.getContext = exports.setContext = exports.getIacLocation = void 0;
|
|
7
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
6
|
+
exports.clearContext = exports.setIac = exports.getContext = exports.setContext = exports.getIacLocation = void 0;
|
|
8
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
|
-
const
|
|
10
|
-
const
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const credentials_1 = require("./credentials");
|
|
11
10
|
const imsClient_1 = require("./imsClient");
|
|
12
|
-
const
|
|
11
|
+
const providerEnum_1 = require("./providerEnum");
|
|
12
|
+
let context;
|
|
13
13
|
const DEFAULT_IAC_FILES = [
|
|
14
14
|
'serverlessinsight.yml',
|
|
15
15
|
'serverlessInsight.yml',
|
|
@@ -58,14 +58,22 @@ const setContext = async (config, reaValToken = false) => {
|
|
|
58
58
|
process.env.ROS_REGION_ID ??
|
|
59
59
|
process.env.ALIYUN_REGION ??
|
|
60
60
|
'cn-hangzhou';
|
|
61
|
-
const
|
|
61
|
+
const provider = (config.provider ??
|
|
62
|
+
config.iacProvider?.name ??
|
|
63
|
+
providerEnum_1.ProviderEnum.ALIYUN);
|
|
64
|
+
const credentials = (0, credentials_1.getCredentials)({
|
|
65
|
+
accessKeyId: config.accessKeyId,
|
|
66
|
+
accessKeySecret: config.accessKeySecret,
|
|
67
|
+
securityToken: config.securityToken,
|
|
68
|
+
}, provider);
|
|
69
|
+
const newContext = {
|
|
62
70
|
stage: config.stage ?? 'default',
|
|
63
71
|
stackName: config.stackName ?? '',
|
|
64
|
-
provider
|
|
72
|
+
provider,
|
|
65
73
|
region,
|
|
66
|
-
accessKeyId:
|
|
67
|
-
accessKeySecret:
|
|
68
|
-
securityToken:
|
|
74
|
+
accessKeyId: credentials.accessKeyId,
|
|
75
|
+
accessKeySecret: credentials.accessKeySecret,
|
|
76
|
+
securityToken: credentials.securityToken,
|
|
69
77
|
iacLocation: (0, exports.getIacLocation)(config.location),
|
|
70
78
|
parameters: Object.entries(config.parameters ?? {}).map(([key, value]) => ({ key, value })),
|
|
71
79
|
stages: Object.entries(config.stages ?? {}).reduce((acc, [stage, parameters]) => ({
|
|
@@ -74,17 +82,27 @@ const setContext = async (config, reaValToken = false) => {
|
|
|
74
82
|
}), {}),
|
|
75
83
|
};
|
|
76
84
|
if (reaValToken) {
|
|
77
|
-
const iamInfo = await (0, imsClient_1.getIamInfo)(
|
|
78
|
-
|
|
85
|
+
const iamInfo = await (0, imsClient_1.getIamInfo)(newContext);
|
|
86
|
+
newContext.accountId = iamInfo?.accountId;
|
|
79
87
|
}
|
|
80
|
-
|
|
88
|
+
context = newContext;
|
|
81
89
|
};
|
|
82
90
|
exports.setContext = setContext;
|
|
83
91
|
const getContext = () => {
|
|
84
|
-
const context = asyncLocalStorage.getStore();
|
|
85
92
|
if (!context) {
|
|
86
93
|
throw new Error('No context found');
|
|
87
94
|
}
|
|
88
95
|
return context;
|
|
89
96
|
};
|
|
90
97
|
exports.getContext = getContext;
|
|
98
|
+
const setIac = (iac) => {
|
|
99
|
+
if (!context) {
|
|
100
|
+
throw new Error('Context must be set before setting IAC');
|
|
101
|
+
}
|
|
102
|
+
context.iac = iac;
|
|
103
|
+
};
|
|
104
|
+
exports.setIac = setIac;
|
|
105
|
+
const clearContext = () => {
|
|
106
|
+
context = undefined;
|
|
107
|
+
};
|
|
108
|
+
exports.clearContext = clearContext;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hasCredentials = exports.getCredentials = void 0;
|
|
4
|
+
const providerEnum_1 = require("./providerEnum");
|
|
5
|
+
const getCredentials = (config, provider) => {
|
|
6
|
+
if (config?.accessKeyId && config?.accessKeySecret) {
|
|
7
|
+
return {
|
|
8
|
+
accessKeyId: config.accessKeyId,
|
|
9
|
+
accessKeySecret: config.accessKeySecret,
|
|
10
|
+
securityToken: config.securityToken,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
switch (provider) {
|
|
14
|
+
case providerEnum_1.ProviderEnum.TENCENT:
|
|
15
|
+
return {
|
|
16
|
+
accessKeyId: config?.accessKeyId ?? process.env.TENCENTCLOUD_SECRET_ID,
|
|
17
|
+
accessKeySecret: config?.accessKeySecret ?? process.env.TENCENTCLOUD_SECRET_KEY,
|
|
18
|
+
securityToken: config?.securityToken ?? process.env.TENCENTCLOUD_SECURITY_TOKEN,
|
|
19
|
+
};
|
|
20
|
+
case providerEnum_1.ProviderEnum.HUAWEI:
|
|
21
|
+
return {
|
|
22
|
+
accessKeyId: config?.accessKeyId ?? process.env.HUAWEICLOUD_ACCESS_KEY,
|
|
23
|
+
accessKeySecret: config?.accessKeySecret ?? process.env.HUAWEICLOUD_SECRET_KEY,
|
|
24
|
+
securityToken: config?.securityToken,
|
|
25
|
+
};
|
|
26
|
+
case providerEnum_1.ProviderEnum.ALIYUN:
|
|
27
|
+
default:
|
|
28
|
+
return {
|
|
29
|
+
accessKeyId: config?.accessKeyId ?? process.env.ALIYUN_ACCESS_KEY_ID,
|
|
30
|
+
accessKeySecret: config?.accessKeySecret ?? process.env.ALIYUN_ACCESS_KEY_SECRET,
|
|
31
|
+
securityToken: config?.securityToken ?? process.env.ALIYUN_SECURITY_TOKEN,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.getCredentials = getCredentials;
|
|
36
|
+
const hasCredentials = (credentials) => {
|
|
37
|
+
return !!credentials.accessKeyId && !!credentials.accessKeySecret;
|
|
38
|
+
};
|
|
39
|
+
exports.hasCredentials = hasCredentials;
|