@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.
Files changed (160) hide show
  1. package/.gitattributes +1 -0
  2. package/README.md +108 -8
  3. package/README.zh-CN.md +52 -8
  4. package/dist/package.json +37 -35
  5. package/dist/src/commands/deploy.js +17 -7
  6. package/dist/src/commands/destroy.js +27 -4
  7. package/dist/src/commands/forceUnlock.js +61 -0
  8. package/dist/src/commands/index.js +86 -14
  9. package/dist/src/commands/local.js +10 -1
  10. package/dist/src/commands/plan.js +33 -0
  11. package/dist/src/commands/template.js +3 -1
  12. package/dist/src/commands/validate.js +2 -1
  13. package/dist/src/common/aliyunClient/apigwOperations.js +652 -0
  14. package/dist/src/common/aliyunClient/dnsOperations.js +90 -0
  15. package/dist/src/common/aliyunClient/ecsOperations.js +141 -0
  16. package/dist/src/common/aliyunClient/esOperations.js +219 -0
  17. package/dist/src/common/aliyunClient/fc3Operations.js +270 -0
  18. package/dist/src/common/aliyunClient/index.js +141 -0
  19. package/dist/src/common/aliyunClient/nasOperations.js +233 -0
  20. package/dist/src/common/aliyunClient/ossOperations.js +237 -0
  21. package/dist/src/common/aliyunClient/ramOperations.js +205 -0
  22. package/dist/src/common/aliyunClient/rdsOperations.js +206 -0
  23. package/dist/src/common/aliyunClient/slsOperations.js +218 -0
  24. package/dist/src/common/aliyunClient/tablestoreOperations.js +199 -0
  25. package/dist/src/common/aliyunClient/types.js +2 -0
  26. package/dist/src/common/constants.js +7 -1
  27. package/dist/src/common/context.js +32 -14
  28. package/dist/src/common/credentials.js +39 -0
  29. package/dist/src/common/dependencyGraph/graph.js +280 -0
  30. package/dist/src/common/dependencyGraph/index.js +18 -0
  31. package/dist/src/common/dependencyGraph/types.js +2 -0
  32. package/dist/src/common/fileUtils.js +16 -0
  33. package/dist/src/common/hashUtils.js +121 -0
  34. package/dist/src/common/iacHelper.js +25 -97
  35. package/dist/src/common/imsClient.js +4 -0
  36. package/dist/src/common/index.js +7 -2
  37. package/dist/src/common/lockManager.js +212 -0
  38. package/dist/src/common/logger.js +89 -6
  39. package/dist/src/common/providerEnum.js +2 -3
  40. package/dist/src/common/runtimeMapper.js +160 -0
  41. package/dist/src/common/scfClient.js +84 -0
  42. package/dist/src/common/stateManager.js +107 -0
  43. package/dist/src/common/tencentClient/cosOperations.js +287 -0
  44. package/dist/src/common/tencentClient/esOperations.js +156 -0
  45. package/dist/src/common/tencentClient/index.js +116 -0
  46. package/dist/src/common/tencentClient/scfOperations.js +141 -0
  47. package/dist/src/common/tencentClient/tdsqlcOperations.js +211 -0
  48. package/dist/src/common/tencentClient/types.js +17 -0
  49. package/dist/src/lang/en.js +254 -0
  50. package/dist/src/lang/index.js +28 -8
  51. package/dist/src/lang/zh-CN.js +229 -0
  52. package/dist/src/parser/bucketParser.js +25 -12
  53. package/dist/src/parser/databaseParser.js +14 -10
  54. package/dist/src/parser/functionParser.js +19 -6
  55. package/dist/src/parser/parseUtils.js +74 -0
  56. package/dist/src/parser/tableParser.js +19 -17
  57. package/dist/src/stack/aliyunStack/apigwExecutor.js +84 -0
  58. package/dist/src/stack/aliyunStack/apigwPlanner.js +118 -0
  59. package/dist/src/stack/aliyunStack/apigwResource.js +339 -0
  60. package/dist/src/stack/aliyunStack/apigwTypes.js +125 -0
  61. package/dist/src/stack/aliyunStack/databaseExecutor.js +112 -0
  62. package/dist/src/stack/aliyunStack/databasePlanner.js +128 -0
  63. package/dist/src/stack/aliyunStack/databaseResource.js +228 -0
  64. package/dist/src/stack/aliyunStack/deployer.js +133 -0
  65. package/dist/src/stack/aliyunStack/destroyer.js +114 -0
  66. package/dist/src/stack/aliyunStack/esServerlessTypes.js +141 -0
  67. package/dist/src/stack/aliyunStack/fc3Executor.js +91 -0
  68. package/dist/src/stack/aliyunStack/fc3Planner.js +77 -0
  69. package/dist/src/stack/aliyunStack/fc3Resource.js +511 -0
  70. package/dist/src/stack/aliyunStack/fc3Types.js +76 -0
  71. package/dist/src/stack/aliyunStack/index.js +40 -0
  72. package/dist/src/stack/aliyunStack/ossExecutor.js +91 -0
  73. package/dist/src/stack/aliyunStack/ossPlanner.js +76 -0
  74. package/dist/src/stack/aliyunStack/ossResource.js +196 -0
  75. package/dist/src/stack/aliyunStack/ossTypes.js +50 -0
  76. package/dist/src/stack/aliyunStack/planner.js +37 -0
  77. package/dist/src/stack/aliyunStack/rdsTypes.js +217 -0
  78. package/dist/src/stack/aliyunStack/tablestoreExecutor.js +92 -0
  79. package/dist/src/stack/aliyunStack/tablestorePlanner.js +94 -0
  80. package/dist/src/stack/aliyunStack/tablestoreResource.js +120 -0
  81. package/dist/src/stack/aliyunStack/tablestoreTypes.js +77 -0
  82. package/dist/src/stack/bucketTypes.js +17 -0
  83. package/dist/src/stack/deploy.js +24 -77
  84. package/dist/src/stack/localStack/bucket.js +11 -6
  85. package/dist/src/stack/localStack/event.js +10 -5
  86. package/dist/src/stack/localStack/function.js +13 -7
  87. package/dist/src/stack/localStack/functionRunner.js +1 -1
  88. package/dist/src/stack/localStack/localServer.js +7 -6
  89. package/dist/src/stack/scfStack/cosExecutor.js +91 -0
  90. package/dist/src/stack/scfStack/cosPlanner.js +76 -0
  91. package/dist/src/stack/scfStack/cosResource.js +126 -0
  92. package/dist/src/stack/scfStack/cosTypes.js +46 -0
  93. package/dist/src/stack/scfStack/deployer.js +91 -0
  94. package/dist/src/stack/scfStack/destroyer.js +88 -0
  95. package/dist/src/stack/scfStack/esServerlessExecutor.js +105 -0
  96. package/dist/src/stack/scfStack/esServerlessPlanner.js +86 -0
  97. package/dist/src/stack/scfStack/esServerlessResource.js +94 -0
  98. package/dist/src/stack/scfStack/esServerlessTypes.js +48 -0
  99. package/dist/src/stack/scfStack/index.js +35 -0
  100. package/dist/src/stack/scfStack/planner.js +91 -0
  101. package/dist/src/stack/scfStack/scfExecutor.js +91 -0
  102. package/dist/src/stack/scfStack/scfPlanner.js +78 -0
  103. package/dist/src/stack/scfStack/scfResource.js +216 -0
  104. package/dist/src/stack/scfStack/scfTypes.js +41 -0
  105. package/dist/src/stack/scfStack/tdsqlcExecutor.js +105 -0
  106. package/dist/src/stack/scfStack/tdsqlcPlanner.js +90 -0
  107. package/dist/src/stack/scfStack/tdsqlcResource.js +146 -0
  108. package/dist/src/stack/scfStack/tdsqlcTypes.js +59 -0
  109. package/dist/src/types/domains/lock.js +2 -0
  110. package/dist/src/types/domains/resolvable.js +2 -0
  111. package/dist/src/types/domains/state.js +19 -0
  112. package/dist/src/types/index.js +4 -0
  113. package/dist/src/validator/bucketSchema.js +4 -10
  114. package/dist/src/validator/databaseSchema.js +36 -36
  115. package/dist/src/validator/eventSchema.js +3 -2
  116. package/dist/src/validator/functionSchema.js +51 -46
  117. package/dist/src/validator/iacSchema.js +52 -3
  118. package/dist/src/validator/rootSchema.js +47 -1
  119. package/dist/src/validator/tableschema.js +9 -8
  120. package/dist/src/validator/templateRefSchema.js +23 -0
  121. package/dist/tsconfig.tsbuildinfo +1 -1
  122. package/package.json +37 -35
  123. package/samples/README_TENCENT_COS.md +486 -0
  124. package/samples/README_TENCENT_SCF.md +272 -0
  125. package/samples/aliyun-poc-api.yml +1 -1
  126. package/samples/aliyun-poc-bucket.yml +0 -1
  127. package/samples/aliyun-poc-domain.yml +0 -1
  128. package/samples/aliyun-poc-es.yml +14 -13
  129. package/samples/aliyun-poc-rds.yml +0 -2
  130. package/samples/aliyun-poc-table.yml +1 -3
  131. package/samples/tencent-poc-cos.yml +20 -0
  132. package/samples/tencent-poc-scf.yml +36 -0
  133. package/dist/src/commands/index.d.ts +0 -2
  134. package/dist/src/common/index.d.ts +0 -11
  135. package/dist/src/common/rosAssets.js +0 -178
  136. package/dist/src/common/rosClient.js +0 -198
  137. package/dist/src/index.d.ts +0 -1
  138. package/dist/src/lang/index.d.ts +0 -3
  139. package/dist/src/parser/index.d.ts +0 -3
  140. package/dist/src/stack/index.d.ts +0 -1
  141. package/dist/src/stack/localStack/index.d.ts +0 -5
  142. package/dist/src/stack/rfsStack/index.d.ts +0 -9
  143. package/dist/src/stack/rosStack/bootstrap.js +0 -187
  144. package/dist/src/stack/rosStack/bucket.js +0 -127
  145. package/dist/src/stack/rosStack/database.js +0 -313
  146. package/dist/src/stack/rosStack/event.js +0 -143
  147. package/dist/src/stack/rosStack/function.js +0 -259
  148. package/dist/src/stack/rosStack/index.d.ts +0 -7
  149. package/dist/src/stack/rosStack/index.js +0 -75
  150. package/dist/src/stack/rosStack/stage.js +0 -46
  151. package/dist/src/stack/rosStack/table.js +0 -95
  152. package/dist/src/stack/rosStack/tag.js +0 -11
  153. package/dist/src/stack/rosStack/vars.js +0 -49
  154. package/dist/src/types/index.d.ts +0 -55
  155. package/dist/src/types/localStack/index.d.ts +0 -81
  156. package/dist/src/validator/index.d.ts +0 -1
  157. package/layers/si-bootstrap-sdk/Dockerfile-aliyuncli +0 -12
  158. package/layers/si-bootstrap-sdk/README.md +0 -1
  159. package/layers/si-bootstrap-sdk/package-lock.json +0 -875
  160. package/layers/si-bootstrap-sdk/package.json +0 -33
@@ -0,0 +1,270 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.createFc3Operations = void 0;
40
+ const fc = __importStar(require("@alicloud/fc20230330"));
41
+ const node_fs_1 = __importDefault(require("node:fs"));
42
+ const createFc3Operations = (fc3Client) => ({
43
+ createFunction: async (config, codePath) => {
44
+ const codeBuffer = node_fs_1.default.readFileSync(codePath);
45
+ const codeBase64 = codeBuffer.toString('base64');
46
+ const createFunctionInput = new fc.CreateFunctionInput({
47
+ functionName: config.functionName,
48
+ runtime: config.runtime,
49
+ handler: config.handler,
50
+ memorySize: config.memorySize,
51
+ timeout: config.timeout,
52
+ code: new fc.InputCodeLocation({
53
+ zipFile: codeBase64,
54
+ }),
55
+ ...(config.diskSize && { diskSize: config.diskSize }),
56
+ ...(config.environmentVariables && { environmentVariables: config.environmentVariables }),
57
+ ...(config.gpuConfig && {
58
+ gpuConfig: new fc.GPUConfig({
59
+ gpuMemorySize: config.gpuConfig.gpuMemorySize,
60
+ gpuType: config.gpuConfig.gpuType,
61
+ }),
62
+ }),
63
+ ...(config.vpcConfig && {
64
+ vpcConfig: new fc.VPCConfig({
65
+ vpcId: config.vpcConfig.vpcId,
66
+ vSwitchIds: config.vpcConfig.vSwitchIds,
67
+ securityGroupId: config.vpcConfig.securityGroupId,
68
+ }),
69
+ }),
70
+ ...(config.nasConfig && {
71
+ nasConfig: new fc.NASConfig({
72
+ userId: config.nasConfig.userId,
73
+ groupId: config.nasConfig.groupId,
74
+ mountPoints: config.nasConfig.mountPoints?.map((mp) => new fc.NASMountConfig({
75
+ serverAddr: mp.serverAddr,
76
+ mountDir: mp.mountDir,
77
+ enableTLS: mp.enableTls,
78
+ })),
79
+ }),
80
+ }),
81
+ ...(config.logConfig && {
82
+ logConfig: new fc.LogConfig({
83
+ project: config.logConfig.project,
84
+ logstore: config.logConfig.logstore,
85
+ enableRequestMetrics: config.logConfig.enableRequestMetrics,
86
+ enableInstanceMetrics: config.logConfig.enableInstanceMetrics,
87
+ logBeginRule: config.logConfig.logBeginRule,
88
+ }),
89
+ }),
90
+ ...(config.customContainerConfig && {
91
+ customContainerConfig: new fc.CustomContainerConfig({
92
+ image: config.customContainerConfig.image,
93
+ entrypoint: config.customContainerConfig.entrypoint,
94
+ command: config.customContainerConfig.command,
95
+ port: config.customContainerConfig.port,
96
+ accelerationType: config.customContainerConfig.accelerationType,
97
+ }),
98
+ }),
99
+ ...(config.description && { description: config.description }),
100
+ ...(config.internetAccess !== undefined && { internetAccess: config.internetAccess }),
101
+ ...(config.role && { role: config.role }),
102
+ });
103
+ const request = new fc.CreateFunctionRequest({
104
+ body: createFunctionInput,
105
+ });
106
+ await fc3Client.createFunction(request);
107
+ },
108
+ getFunction: async (functionName) => {
109
+ try {
110
+ const request = new fc.GetFunctionRequest({});
111
+ const response = await fc3Client.getFunction(functionName, request);
112
+ if (!response || !response.body) {
113
+ return null;
114
+ }
115
+ const body = response.body;
116
+ return {
117
+ functionName: body.functionName,
118
+ functionArn: body.functionArn,
119
+ functionId: body.functionId,
120
+ runtime: body.runtime,
121
+ handler: body.handler,
122
+ memorySize: body.memorySize,
123
+ timeout: body.timeout,
124
+ diskSize: body.diskSize,
125
+ cpu: body.cpu,
126
+ environmentVariables: body.environmentVariables,
127
+ vpcConfig: body.vpcConfig
128
+ ? {
129
+ vpcId: body.vpcConfig.vpcId,
130
+ vSwitchIds: body.vpcConfig.vSwitchIds,
131
+ securityGroupId: body.vpcConfig.securityGroupId,
132
+ }
133
+ : undefined,
134
+ gpuConfig: body.gpuConfig
135
+ ? {
136
+ gpuMemorySize: body.gpuConfig.gpuMemorySize,
137
+ gpuType: body.gpuConfig.gpuType,
138
+ }
139
+ : undefined,
140
+ nasConfig: body.nasConfig
141
+ ? {
142
+ userId: body.nasConfig.userId,
143
+ groupId: body.nasConfig.groupId,
144
+ mountPoints: body.nasConfig.mountPoints?.map((mp) => ({
145
+ serverAddr: mp.serverAddr,
146
+ mountDir: mp.mountDir,
147
+ enableTls: mp.enableTLS,
148
+ })),
149
+ }
150
+ : undefined,
151
+ logConfig: body.logConfig
152
+ ? {
153
+ project: body.logConfig.project,
154
+ logstore: body.logConfig.logstore,
155
+ enableRequestMetrics: body.logConfig.enableRequestMetrics,
156
+ enableInstanceMetrics: body.logConfig.enableInstanceMetrics,
157
+ logBeginRule: body.logConfig.logBeginRule,
158
+ }
159
+ : undefined,
160
+ customContainerConfig: body.customContainerConfig
161
+ ? {
162
+ image: body.customContainerConfig.image,
163
+ entrypoint: body.customContainerConfig.entrypoint,
164
+ command: body.customContainerConfig.command,
165
+ port: body.customContainerConfig.port,
166
+ accelerationType: body.customContainerConfig.accelerationType,
167
+ }
168
+ : undefined,
169
+ description: body.description,
170
+ internetAccess: body.internetAccess,
171
+ role: body.role,
172
+ codeChecksum: body.codeChecksum,
173
+ codeSize: body.codeSize,
174
+ createdTime: body.createdTime,
175
+ lastModifiedTime: body.lastModifiedTime,
176
+ state: body.state,
177
+ stateReason: body.stateReason,
178
+ stateReasonCode: body.stateReasonCode,
179
+ lastUpdateStatus: body.lastUpdateStatus,
180
+ lastUpdateStatusReason: body.lastUpdateStatusReason,
181
+ lastUpdateStatusReasonCode: body.lastUpdateStatusReasonCode,
182
+ };
183
+ }
184
+ catch (error) {
185
+ if (error &&
186
+ typeof error === 'object' &&
187
+ 'code' in error &&
188
+ error.code === 'FunctionNotFound') {
189
+ return null;
190
+ }
191
+ throw error;
192
+ }
193
+ },
194
+ updateFunctionConfiguration: async (config) => {
195
+ const updateFunctionInput = new fc.UpdateFunctionInput({
196
+ runtime: config.runtime,
197
+ handler: config.handler,
198
+ memorySize: config.memorySize,
199
+ timeout: config.timeout,
200
+ ...(config.diskSize && { diskSize: config.diskSize }),
201
+ ...(config.environmentVariables && { environmentVariables: config.environmentVariables }),
202
+ ...(config.gpuConfig && {
203
+ gpuConfig: new fc.GPUConfig({
204
+ gpuMemorySize: config.gpuConfig.gpuMemorySize,
205
+ gpuType: config.gpuConfig.gpuType,
206
+ }),
207
+ }),
208
+ ...(config.vpcConfig && {
209
+ vpcConfig: new fc.VPCConfig({
210
+ vpcId: config.vpcConfig.vpcId,
211
+ vSwitchIds: config.vpcConfig.vSwitchIds,
212
+ securityGroupId: config.vpcConfig.securityGroupId,
213
+ }),
214
+ }),
215
+ ...(config.nasConfig && {
216
+ nasConfig: new fc.NASConfig({
217
+ userId: config.nasConfig.userId,
218
+ groupId: config.nasConfig.groupId,
219
+ mountPoints: config.nasConfig.mountPoints?.map((mp) => new fc.NASMountConfig({
220
+ serverAddr: mp.serverAddr,
221
+ mountDir: mp.mountDir,
222
+ enableTLS: mp.enableTls,
223
+ })),
224
+ }),
225
+ }),
226
+ ...(config.logConfig && {
227
+ logConfig: new fc.LogConfig({
228
+ project: config.logConfig.project,
229
+ logstore: config.logConfig.logstore,
230
+ enableRequestMetrics: config.logConfig.enableRequestMetrics,
231
+ enableInstanceMetrics: config.logConfig.enableInstanceMetrics,
232
+ logBeginRule: config.logConfig.logBeginRule,
233
+ }),
234
+ }),
235
+ ...(config.customContainerConfig && {
236
+ customContainerConfig: new fc.CustomContainerConfig({
237
+ image: config.customContainerConfig.image,
238
+ entrypoint: config.customContainerConfig.entrypoint,
239
+ command: config.customContainerConfig.command,
240
+ port: config.customContainerConfig.port,
241
+ accelerationType: config.customContainerConfig.accelerationType,
242
+ }),
243
+ }),
244
+ ...(config.description && { description: config.description }),
245
+ ...(config.internetAccess !== undefined && { internetAccess: config.internetAccess }),
246
+ ...(config.role && { role: config.role }),
247
+ });
248
+ const request = new fc.UpdateFunctionRequest({
249
+ body: updateFunctionInput,
250
+ });
251
+ await fc3Client.updateFunction(config.functionName, request);
252
+ },
253
+ updateFunctionCode: async (functionName, codePath) => {
254
+ const codeBuffer = node_fs_1.default.readFileSync(codePath);
255
+ const codeBase64 = codeBuffer.toString('base64');
256
+ const updateFunctionInput = new fc.UpdateFunctionInput({
257
+ code: new fc.InputCodeLocation({
258
+ zipFile: codeBase64,
259
+ }),
260
+ });
261
+ const request = new fc.UpdateFunctionRequest({
262
+ body: updateFunctionInput,
263
+ });
264
+ await fc3Client.updateFunction(functionName, request);
265
+ },
266
+ deleteFunction: async (functionName) => {
267
+ await fc3Client.deleteFunction(functionName);
268
+ },
269
+ });
270
+ exports.createFc3Operations = createFc3Operations;
@@ -0,0 +1,141 @@
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
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.createAliyunClient = void 0;
43
+ const fc20230330_1 = __importDefault(require("@alicloud/fc20230330"));
44
+ const sls20201230_1 = __importDefault(require("@alicloud/sls20201230"));
45
+ const ram20150501_1 = __importDefault(require("@alicloud/ram20150501"));
46
+ const ecs20140526_1 = __importDefault(require("@alicloud/ecs20140526"));
47
+ const nas20170626_1 = __importDefault(require("@alicloud/nas20170626"));
48
+ const cloudapi20160714_1 = __importDefault(require("@alicloud/cloudapi20160714"));
49
+ const rds20140815_1 = __importDefault(require("@alicloud/rds20140815"));
50
+ const es_serverless20230627_1 = __importDefault(require("@alicloud/es-serverless20230627"));
51
+ const alidns20150109_1 = __importDefault(require("@alicloud/alidns20150109"));
52
+ const $OpenApi = __importStar(require("@alicloud/openapi-client"));
53
+ const ali_oss_1 = __importDefault(require("ali-oss"));
54
+ const fc3Operations_1 = require("./fc3Operations");
55
+ const slsOperations_1 = require("./slsOperations");
56
+ const ramOperations_1 = require("./ramOperations");
57
+ const ecsOperations_1 = require("./ecsOperations");
58
+ const nasOperations_1 = require("./nasOperations");
59
+ const apigwOperations_1 = require("./apigwOperations");
60
+ const ossOperations_1 = require("./ossOperations");
61
+ const rdsOperations_1 = require("./rdsOperations");
62
+ const esOperations_1 = require("./esOperations");
63
+ const tablestoreOperations_1 = require("./tablestoreOperations");
64
+ const dnsOperations_1 = require("./dnsOperations");
65
+ __exportStar(require("./types"), exports);
66
+ __exportStar(require("./apigwOperations"), exports);
67
+ __exportStar(require("./ossOperations"), exports);
68
+ __exportStar(require("./rdsOperations"), exports);
69
+ __exportStar(require("./esOperations"), exports);
70
+ __exportStar(require("./tablestoreOperations"), exports);
71
+ __exportStar(require("./dnsOperations"), exports);
72
+ const initializeSdkClients = (context) => {
73
+ const baseConfig = {
74
+ accessKeyId: context.accessKeyId,
75
+ accessKeySecret: context.accessKeySecret,
76
+ regionId: context.region,
77
+ securityToken: context.securityToken,
78
+ };
79
+ const fc3Config = new $OpenApi.Config(baseConfig);
80
+ fc3Config.endpoint = `${context.accountId}.${context.region}.fc.aliyuncs.com`;
81
+ const fc3Client = new fc20230330_1.default(fc3Config);
82
+ const slsConfig = new $OpenApi.Config(baseConfig);
83
+ slsConfig.endpoint = `${context.region}.log.aliyuncs.com`;
84
+ const slsClient = new sls20201230_1.default(slsConfig);
85
+ const ramConfig = new $OpenApi.Config(baseConfig);
86
+ ramConfig.endpoint = 'ram.aliyuncs.com';
87
+ const ramClient = new ram20150501_1.default(ramConfig);
88
+ const ecsConfig = new $OpenApi.Config(baseConfig);
89
+ ecsConfig.endpoint = `ecs.${context.region}.aliyuncs.com`;
90
+ const ecsClient = new ecs20140526_1.default(ecsConfig);
91
+ const nasConfig = new $OpenApi.Config(baseConfig);
92
+ nasConfig.endpoint = `nas.${context.region}.aliyuncs.com`;
93
+ const nasClient = new nas20170626_1.default(nasConfig);
94
+ const ossClient = new ali_oss_1.default({
95
+ accessKeyId: context.accessKeyId,
96
+ accessKeySecret: context.accessKeySecret,
97
+ region: `oss-${context.region}`,
98
+ stsToken: context.securityToken,
99
+ });
100
+ const apigwConfig = new $OpenApi.Config(baseConfig);
101
+ apigwConfig.endpoint = `apigateway.${context.region}.aliyuncs.com`;
102
+ const apigwClient = new cloudapi20160714_1.default(apigwConfig);
103
+ const rdsConfig = new $OpenApi.Config(baseConfig);
104
+ rdsConfig.endpoint = `rds.aliyuncs.com`;
105
+ const rdsClient = new rds20140815_1.default(rdsConfig);
106
+ const esConfig = new $OpenApi.Config(baseConfig);
107
+ esConfig.endpoint = `elasticsearch-serverless.${context.region}.aliyuncs.com`;
108
+ const esClient = new es_serverless20230627_1.default(esConfig);
109
+ const dnsConfig = new $OpenApi.Config(baseConfig);
110
+ dnsConfig.endpoint = `alidns.aliyuncs.com`;
111
+ const dnsClient = new alidns20150109_1.default(dnsConfig);
112
+ return {
113
+ fc3: fc3Client,
114
+ sls: slsClient,
115
+ ram: ramClient,
116
+ ecs: ecsClient,
117
+ nas: nasClient,
118
+ oss: ossClient,
119
+ apigw: apigwClient,
120
+ rds: rdsClient,
121
+ es: esClient,
122
+ dns: dnsClient,
123
+ };
124
+ };
125
+ const createAliyunClient = (context) => {
126
+ const sdkClients = initializeSdkClients(context);
127
+ return {
128
+ fc3: (0, fc3Operations_1.createFc3Operations)(sdkClients.fc3),
129
+ sls: (0, slsOperations_1.createSlsOperations)(sdkClients.sls),
130
+ ram: (0, ramOperations_1.createRamOperations)(sdkClients.ram),
131
+ ecs: (0, ecsOperations_1.createEcsOperations)(sdkClients.ecs, context),
132
+ nas: (0, nasOperations_1.createNasOperations)(sdkClients.nas),
133
+ oss: (0, ossOperations_1.createOssOperations)(sdkClients.oss, context.region),
134
+ apigw: (0, apigwOperations_1.createApigwOperations)(sdkClients.apigw, sdkClients.dns, context),
135
+ rds: (0, rdsOperations_1.createRdsOperations)(sdkClients.rds, context),
136
+ es: (0, esOperations_1.createEsOperations)(sdkClients.es, context),
137
+ dns: (0, dnsOperations_1.createDnsOperations)(sdkClients.dns),
138
+ tablestore: (instanceName) => (0, tablestoreOperations_1.createTablestoreOperations)(`https://${instanceName}.${context.region}.ots.aliyuncs.com`, instanceName, context),
139
+ };
140
+ };
141
+ exports.createAliyunClient = createAliyunClient;
@@ -0,0 +1,233 @@
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.createNasOperations = void 0;
37
+ const nas = __importStar(require("@alicloud/nas20170626"));
38
+ const types_1 = require("../../types");
39
+ const storageClassMap = {
40
+ [types_1.NasStorageClassEnum.STANDARD_CAPACITY]: { fileSystemType: 'standard', storageType: 'Capacity' },
41
+ [types_1.NasStorageClassEnum.STANDARD_PERFORMANCE]: {
42
+ fileSystemType: 'standard',
43
+ storageType: 'Performance',
44
+ },
45
+ [types_1.NasStorageClassEnum.EXTREME_STANDARD]: { fileSystemType: 'extreme', storageType: 'standard' },
46
+ [types_1.NasStorageClassEnum.EXTREME_ADVANCE]: { fileSystemType: 'extreme', storageType: 'advance' },
47
+ };
48
+ const createNasOperations = (nasClient) => {
49
+ const operations = {
50
+ createAccessGroup: async (accessGroupName, accessGroupType = 'Vpc') => {
51
+ const request = new nas.CreateAccessGroupRequest({
52
+ accessGroupName,
53
+ accessGroupType,
54
+ });
55
+ await nasClient.createAccessGroup(request);
56
+ return {
57
+ accessGroupName,
58
+ accessGroupType,
59
+ };
60
+ },
61
+ getAccessGroup: async (accessGroupName) => {
62
+ try {
63
+ const request = new nas.DescribeAccessGroupsRequest({
64
+ accessGroupName,
65
+ });
66
+ const response = await nasClient.describeAccessGroups(request);
67
+ if (!response ||
68
+ !response.body ||
69
+ !response.body.accessGroups ||
70
+ !response.body.accessGroups.accessGroup ||
71
+ response.body.accessGroups.accessGroup.length === 0) {
72
+ return null;
73
+ }
74
+ const ag = response.body.accessGroups.accessGroup[0];
75
+ return {
76
+ accessGroupName: ag.accessGroupName ?? accessGroupName,
77
+ accessGroupType: ag.accessGroupType,
78
+ ruleCount: ag.ruleCount,
79
+ };
80
+ }
81
+ catch {
82
+ return null;
83
+ }
84
+ },
85
+ deleteAccessGroup: async (accessGroupName) => {
86
+ const request = new nas.DeleteAccessGroupRequest({
87
+ accessGroupName,
88
+ });
89
+ await nasClient.deleteAccessGroup(request);
90
+ },
91
+ createAccessRule: async (accessGroupName, sourceCidrIp) => {
92
+ const request = new nas.CreateAccessRuleRequest({
93
+ accessGroupName,
94
+ sourceCidrIp,
95
+ RWAccessType: 'RDWR',
96
+ userAccessType: 'no_squash',
97
+ priority: 1,
98
+ });
99
+ await nasClient.createAccessRule(request);
100
+ },
101
+ createFileSystem: async (storageClass, functionName) => {
102
+ const { fileSystemType, storageType } = storageClassMap[storageClass];
103
+ const request = new nas.CreateFileSystemRequest({
104
+ fileSystemType,
105
+ storageType,
106
+ protocolType: 'NFS',
107
+ description: `ServerlessInsight NAS for ${functionName}`,
108
+ });
109
+ const response = await nasClient.createFileSystem(request);
110
+ const fileSystemId = response.body?.fileSystemId;
111
+ if (!fileSystemId) {
112
+ throw new Error('Failed to create NAS file system');
113
+ }
114
+ // Wait for file system to be ready
115
+ let retries = 0;
116
+ while (retries < 30) {
117
+ const fs = await operations.getFileSystem(fileSystemId);
118
+ if (fs && fs.status === 'Running') {
119
+ return fs;
120
+ }
121
+ await new Promise((resolve) => setTimeout(resolve, 5000));
122
+ retries++;
123
+ }
124
+ return {
125
+ fileSystemId,
126
+ fileSystemType,
127
+ storageType,
128
+ protocolType: 'NFS',
129
+ };
130
+ },
131
+ getFileSystem: async (fileSystemId) => {
132
+ try {
133
+ const request = new nas.DescribeFileSystemsRequest({
134
+ fileSystemId,
135
+ });
136
+ const response = await nasClient.describeFileSystems(request);
137
+ if (!response ||
138
+ !response.body ||
139
+ !response.body.fileSystems ||
140
+ !response.body.fileSystems.fileSystem ||
141
+ response.body.fileSystems.fileSystem.length === 0) {
142
+ return null;
143
+ }
144
+ const fs = response.body.fileSystems.fileSystem[0];
145
+ return {
146
+ fileSystemId: fs.fileSystemId ?? fileSystemId,
147
+ fileSystemType: fs.fileSystemType,
148
+ storageType: fs.storageType,
149
+ protocolType: fs.protocolType,
150
+ status: fs.status,
151
+ createTime: fs.createTime,
152
+ };
153
+ }
154
+ catch {
155
+ return null;
156
+ }
157
+ },
158
+ deleteFileSystem: async (fileSystemId) => {
159
+ const request = new nas.DeleteFileSystemRequest({
160
+ fileSystemId,
161
+ });
162
+ await nasClient.deleteFileSystem(request);
163
+ },
164
+ createMountTarget: async (fileSystemId, accessGroupName, vpcId, vSwitchId) => {
165
+ const request = new nas.CreateMountTargetRequest({
166
+ fileSystemId,
167
+ accessGroupName,
168
+ networkType: 'Vpc',
169
+ vpcId,
170
+ vSwitchId,
171
+ });
172
+ const response = await nasClient.createMountTarget(request);
173
+ const mountTargetDomain = response.body?.mountTargetDomain;
174
+ if (!mountTargetDomain) {
175
+ throw new Error('Failed to create NAS mount target');
176
+ }
177
+ // Wait for mount target to be ready
178
+ let retries = 0;
179
+ while (retries < 30) {
180
+ const mt = await operations.getMountTarget(fileSystemId, mountTargetDomain);
181
+ if (mt && mt.status === 'Active') {
182
+ return mt;
183
+ }
184
+ await new Promise((resolve) => setTimeout(resolve, 5000));
185
+ retries++;
186
+ }
187
+ return {
188
+ mountTargetDomain,
189
+ fileSystemId,
190
+ vpcId,
191
+ vSwitchId,
192
+ accessGroupName,
193
+ };
194
+ },
195
+ getMountTarget: async (fileSystemId, mountTargetDomain) => {
196
+ try {
197
+ const request = new nas.DescribeMountTargetsRequest({
198
+ fileSystemId,
199
+ mountTargetDomain,
200
+ });
201
+ const response = await nasClient.describeMountTargets(request);
202
+ if (!response ||
203
+ !response.body ||
204
+ !response.body.mountTargets ||
205
+ !response.body.mountTargets.mountTarget ||
206
+ response.body.mountTargets.mountTarget.length === 0) {
207
+ return null;
208
+ }
209
+ const mt = response.body.mountTargets.mountTarget[0];
210
+ return {
211
+ mountTargetDomain: mt.mountTargetDomain ?? mountTargetDomain,
212
+ fileSystemId,
213
+ vpcId: mt.vpcId,
214
+ vSwitchId: mt.vswId,
215
+ accessGroupName: mt.accessGroup,
216
+ status: mt.status,
217
+ };
218
+ }
219
+ catch {
220
+ return null;
221
+ }
222
+ },
223
+ deleteMountTarget: async (fileSystemId, mountTargetDomain) => {
224
+ const request = new nas.DeleteMountTargetRequest({
225
+ fileSystemId,
226
+ mountTargetDomain,
227
+ });
228
+ await nasClient.deleteMountTarget(request);
229
+ },
230
+ };
231
+ return operations;
232
+ };
233
+ exports.createNasOperations = createNasOperations;