@geek-fun/serverlessinsight 0.5.8 → 0.6.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 (55) hide show
  1. package/AGENTS.md +372 -0
  2. package/README.md +2 -2
  3. package/README.zh-CN.md +11 -8
  4. package/dist/package.json +3 -1
  5. package/dist/src/commands/index.js +5 -4
  6. package/dist/src/common/aliyunClient/apigwOperations.js +96 -9
  7. package/dist/src/common/aliyunClient/casOperations.js +116 -0
  8. package/dist/src/common/aliyunClient/index.js +8 -0
  9. package/dist/src/common/aliyunClient/ossOperations.js +61 -4
  10. package/dist/src/common/aliyunClient/ramOperations.js +65 -20
  11. package/dist/src/common/certificateResolver.js +63 -0
  12. package/dist/src/common/iacHelper.js +9 -1
  13. package/dist/src/common/index.js +1 -0
  14. package/dist/src/common/tencentClient/index.js +18 -0
  15. package/dist/src/common/tencentClient/sslOperations.js +107 -0
  16. package/dist/src/lang/en.js +169 -0
  17. package/dist/src/lang/index.js +6 -0
  18. package/dist/src/lang/zh-CN.js +167 -0
  19. package/dist/src/parser/bucketParser.js +19 -1
  20. package/dist/src/parser/certificateParser.js +23 -0
  21. package/dist/src/parser/index.js +2 -0
  22. package/dist/src/stack/aliyunStack/apigwExecutor.js +15 -9
  23. package/dist/src/stack/aliyunStack/apigwPlanner.js +15 -2
  24. package/dist/src/stack/aliyunStack/apigwResource.js +44 -17
  25. package/dist/src/stack/aliyunStack/apigwTypes.js +36 -5
  26. package/dist/src/stack/aliyunStack/databaseExecutor.js +24 -9
  27. package/dist/src/stack/aliyunStack/databaseResource.js +5 -1
  28. package/dist/src/stack/aliyunStack/deployer.js +11 -2
  29. package/dist/src/stack/aliyunStack/destroyer.js +5 -1
  30. package/dist/src/stack/aliyunStack/fc3Executor.js +10 -9
  31. package/dist/src/stack/aliyunStack/fc3Resource.js +36 -27
  32. package/dist/src/stack/aliyunStack/ossExecutor.js +9 -9
  33. package/dist/src/stack/aliyunStack/ossResource.js +48 -5
  34. package/dist/src/stack/aliyunStack/tablestoreExecutor.js +21 -9
  35. package/dist/src/stack/localStack/event.js +1 -1
  36. package/dist/src/stack/scfStack/cosExecutor.js +9 -9
  37. package/dist/src/stack/scfStack/cosResource.js +45 -7
  38. package/dist/src/stack/scfStack/deployer.js +5 -1
  39. package/dist/src/stack/scfStack/destroyer.js +5 -1
  40. package/dist/src/stack/scfStack/esServerlessExecutor.js +21 -9
  41. package/dist/src/stack/scfStack/esServerlessResource.js +2 -1
  42. package/dist/src/stack/scfStack/scfExecutor.js +9 -9
  43. package/dist/src/stack/scfStack/scfResource.js +2 -1
  44. package/dist/src/stack/scfStack/tdsqlcExecutor.js +9 -9
  45. package/dist/src/stack/scfStack/tdsqlcResource.js +5 -1
  46. package/dist/src/types/domains/certificate.js +2 -0
  47. package/dist/src/types/index.js +1 -0
  48. package/dist/src/validator/bucketSchema.js +27 -1
  49. package/dist/src/validator/certificateSchema.js +31 -0
  50. package/dist/src/validator/eventSchema.js +12 -0
  51. package/dist/src/validator/iacSchema.js +2 -0
  52. package/dist/src/validator/rootSchema.js +3 -0
  53. package/dist/src/validator/templateRefSchema.js +3 -3
  54. package/dist/tsconfig.tsbuildinfo +1 -1
  55. package/package.json +3 -1
@@ -0,0 +1,116 @@
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.createCasOperations = void 0;
37
+ const cas = __importStar(require("@alicloud/cas20200407"));
38
+ const lang_1 = require("../../lang");
39
+ const logger_1 = require("../logger");
40
+ const createCasOperations = (casClient) => {
41
+ return {
42
+ uploadCertificate: async (name, cert, key, chain) => {
43
+ logger_1.logger.info(lang_1.lang.__('CAS_UPLOADING_CERT', { name }));
44
+ const request = new cas.UploadUserCertificateRequest({
45
+ name,
46
+ cert: chain ? `${cert}\n${chain}` : cert,
47
+ key,
48
+ });
49
+ const response = await casClient.uploadUserCertificate(request);
50
+ const certId = response.body?.certId;
51
+ if (certId == null) {
52
+ throw new Error(lang_1.lang.__('CAS_UPLOAD_NO_CERT_ID', { name }));
53
+ }
54
+ logger_1.logger.info(lang_1.lang.__('CAS_CERT_UPLOADED', { name, certId: String(certId) }));
55
+ return {
56
+ certificateId: certId,
57
+ name,
58
+ };
59
+ },
60
+ getCertificate: async (certificateId) => {
61
+ const numericId = Number(certificateId);
62
+ if (Number.isNaN(numericId)) {
63
+ throw new Error(lang_1.lang.__('CERT_INVALID_CONFIGURATION', { name: certificateId }));
64
+ }
65
+ try {
66
+ const request = new cas.GetUserCertificateDetailRequest({
67
+ certId: numericId,
68
+ certFilter: false,
69
+ });
70
+ const response = await casClient.getUserCertificateDetail(request);
71
+ const body = response.body;
72
+ if (!body) {
73
+ return null;
74
+ }
75
+ return {
76
+ certificateId: body.id ?? numericId,
77
+ name: body.name ?? undefined,
78
+ cert: body.cert ?? undefined,
79
+ key: body.key ?? undefined,
80
+ endDate: body.endDate ?? undefined,
81
+ expired: body.expired ?? undefined,
82
+ };
83
+ }
84
+ catch (error) {
85
+ if (error &&
86
+ typeof error === 'object' &&
87
+ 'code' in error &&
88
+ (error.code === 'CertNotExist' || error.code === 'NotFound')) {
89
+ return null;
90
+ }
91
+ throw error;
92
+ }
93
+ },
94
+ deleteCertificate: async (certificateId) => {
95
+ logger_1.logger.info(lang_1.lang.__('CAS_DELETING_CERT', { certId: String(certificateId) }));
96
+ const request = new cas.DeleteUserCertificateRequest({
97
+ certId: certificateId,
98
+ });
99
+ try {
100
+ await casClient.deleteUserCertificate(request);
101
+ logger_1.logger.info(lang_1.lang.__('CAS_CERT_DELETED', { certId: String(certificateId) }));
102
+ }
103
+ catch (error) {
104
+ if (error &&
105
+ typeof error === 'object' &&
106
+ 'code' in error &&
107
+ (error.code === 'CertNotExist' || error.code === 'NotFound')) {
108
+ logger_1.logger.warn(lang_1.lang.__('CAS_CERT_NOT_FOUND', { certId: String(certificateId) }));
109
+ return;
110
+ }
111
+ throw error;
112
+ }
113
+ },
114
+ };
115
+ };
116
+ exports.createCasOperations = createCasOperations;
@@ -49,6 +49,7 @@ const cloudapi20160714_1 = __importDefault(require("@alicloud/cloudapi20160714")
49
49
  const rds20140815_1 = __importDefault(require("@alicloud/rds20140815"));
50
50
  const es_serverless20230627_1 = __importDefault(require("@alicloud/es-serverless20230627"));
51
51
  const alidns20150109_1 = __importDefault(require("@alicloud/alidns20150109"));
52
+ const cas20200407_1 = __importDefault(require("@alicloud/cas20200407"));
52
53
  const $OpenApi = __importStar(require("@alicloud/openapi-client"));
53
54
  const ali_oss_1 = __importDefault(require("ali-oss"));
54
55
  const constants_1 = require("../constants");
@@ -63,6 +64,7 @@ const rdsOperations_1 = require("./rdsOperations");
63
64
  const esOperations_1 = require("./esOperations");
64
65
  const tablestoreOperations_1 = require("./tablestoreOperations");
65
66
  const dnsOperations_1 = require("./dnsOperations");
67
+ const casOperations_1 = require("./casOperations");
66
68
  __exportStar(require("./types"), exports);
67
69
  __exportStar(require("./apigwOperations"), exports);
68
70
  __exportStar(require("./ossOperations"), exports);
@@ -70,6 +72,7 @@ __exportStar(require("./rdsOperations"), exports);
70
72
  __exportStar(require("./esOperations"), exports);
71
73
  __exportStar(require("./tablestoreOperations"), exports);
72
74
  __exportStar(require("./dnsOperations"), exports);
75
+ __exportStar(require("./casOperations"), exports);
73
76
  const initializeSdkClients = (context) => {
74
77
  const baseConfig = {
75
78
  accessKeyId: context.accessKeyId,
@@ -112,6 +115,9 @@ const initializeSdkClients = (context) => {
112
115
  const dnsConfig = new $OpenApi.Config(baseConfig);
113
116
  dnsConfig.endpoint = `alidns.aliyuncs.com`;
114
117
  const dnsClient = new alidns20150109_1.default(dnsConfig);
118
+ const casConfig = new $OpenApi.Config(baseConfig);
119
+ casConfig.endpoint = `cas.aliyuncs.com`;
120
+ const casClient = new cas20200407_1.default(casConfig);
115
121
  return {
116
122
  fc3: fc3Client,
117
123
  sls: slsClient,
@@ -123,6 +129,7 @@ const initializeSdkClients = (context) => {
123
129
  rds: rdsClient,
124
130
  es: esClient,
125
131
  dns: dnsClient,
132
+ cas: casClient,
126
133
  };
127
134
  };
128
135
  const createAliyunClient = (context) => {
@@ -138,6 +145,7 @@ const createAliyunClient = (context) => {
138
145
  apigw: (0, apigwOperations_1.createApigwOperations)(sdkClients.apigw, sdkClients.dns, context),
139
146
  rds: (0, rdsOperations_1.createRdsOperations)(sdkClients.rds, context),
140
147
  es: (0, esOperations_1.createEsOperations)(sdkClients.es, context),
148
+ cas: (0, casOperations_1.createCasOperations)(sdkClients.cas),
141
149
  dns: dnsOps,
142
150
  tablestore: (instanceName) => (0, tablestoreOperations_1.createTablestoreOperations)(`https://${instanceName}.${context.region}.ots.aliyuncs.com`, instanceName, context),
143
151
  };
@@ -6,9 +6,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.createOssOperations = void 0;
7
7
  const node_fs_1 = __importDefault(require("node:fs"));
8
8
  const node_path_1 = __importDefault(require("node:path"));
9
+ const bucketTypes_1 = require("../../stack/bucketTypes");
9
10
  const logger_1 = require("../logger");
10
11
  const lang_1 = require("../../lang");
11
12
  const domainUtils_1 = require("../domainUtils");
13
+ const ossRequest = (ossClient, params) => {
14
+ return ossClient.request(params);
15
+ };
16
+ const escapeXmlText = (text) => text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
12
17
  const createOssOperations = (ossClient, region, dnsOps) => {
13
18
  const useBucket = (bucketName) => {
14
19
  ossClient.useBucket(bucketName);
@@ -16,12 +21,23 @@ const createOssOperations = (ossClient, region, dnsOps) => {
16
21
  const getOssEndpoint = (bucketName) => {
17
22
  return `${bucketName}.oss-${region}.aliyuncs.com`;
18
23
  };
19
- const putBucketCname = async (bucketName, domain) => {
24
+ const buildCertificateXml = (cert) => {
25
+ if (!cert)
26
+ return '';
27
+ return `
28
+ <CertificateConfiguration>
29
+ <Certificate>${escapeXmlText(cert.certificateBody)}</Certificate>
30
+ <PrivateKey>${escapeXmlText(cert.certificatePrivateKey)}</PrivateKey>
31
+ <Force>true</Force>
32
+ </CertificateConfiguration>`;
33
+ };
34
+ const putBucketCname = async (bucketName, domain, certificate) => {
20
35
  useBucket(bucketName);
36
+ const certXml = buildCertificateXml(certificate);
21
37
  const xml = `<?xml version="1.0" encoding="UTF-8"?>
22
38
  <BucketCnameConfiguration>
23
39
  <Cname>
24
- <Domain>${domain}</Domain>
40
+ <Domain>${escapeXmlText(domain)}</Domain>${certXml}
25
41
  </Cname>
26
42
  </BucketCnameConfiguration>`;
27
43
  try {
@@ -50,6 +66,10 @@ const createOssOperations = (ossClient, region, dnsOps) => {
50
66
  logger_1.logger.warn(lang_1.lang.__('OSS_BUCKET_CNAME_NEED_VERIFY', { domain }));
51
67
  return false;
52
68
  }
69
+ if (certificate) {
70
+ // eslint-disable-next-line preserve-caught-error
71
+ throw new Error(lang_1.lang.__('OSS_BUCKET_CNAME_BIND_FAILED', { error: String(error) }));
72
+ }
53
73
  logger_1.logger.warn(lang_1.lang.__('OSS_BUCKET_CNAME_BIND_FAILED', { error: String(error) }));
54
74
  return false;
55
75
  }
@@ -148,11 +168,14 @@ const createOssOperations = (ossClient, region, dnsOps) => {
148
168
  logger_1.logger.warn(lang_1.lang.__('OSS_CORS_RULE_REMOVE_FAILED', { domain, error: String(error) }));
149
169
  }
150
170
  };
151
- const bindCustomDomain = async (bucketName, domain) => {
171
+ const bindCustomDomain = async (bucketName, domain, certificate) => {
152
172
  const mainDomain = (0, domainUtils_1.extractMainDomain)(domain);
153
173
  const hostRecord = (0, domainUtils_1.extractHostRecord)(domain, mainDomain);
154
174
  const ossEndpoint = getOssEndpoint(bucketName);
155
- const bucketCnameBound = await putBucketCname(bucketName, domain);
175
+ const bucketCnameBound = await putBucketCname(bucketName, domain, certificate);
176
+ if (certificate && bucketCnameBound) {
177
+ logger_1.logger.info(lang_1.lang.__('OSS_BUCKET_CERT_BOUND', { domain }));
178
+ }
156
179
  await addCorsRuleForDomain(bucketName, domain);
157
180
  if (!dnsOps) {
158
181
  logger_1.logger.warn(lang_1.lang.__('OSS_DNS_MANUAL_CONFIG_REQUIRED', { domain, cname: ossEndpoint }));
@@ -186,6 +209,34 @@ const createOssOperations = (ossClient, region, dnsOps) => {
186
209
  return { domain, cname: ossEndpoint, bucketCnameBound };
187
210
  }
188
211
  };
212
+ const isPublicAcl = (acl) => acl === bucketTypes_1.BucketACL.PUBLIC_READ || acl === bucketTypes_1.BucketACL.PUBLIC_READ_WRITE;
213
+ const disableBucketPublicAccessBlock = async (bucketName) => {
214
+ useBucket(bucketName);
215
+ const xml = `<?xml version="1.0" encoding="UTF-8"?>
216
+ <PublicAccessBlockConfiguration>
217
+ <BlockPublicAccess>false</BlockPublicAccess>
218
+ </PublicAccessBlockConfiguration>`;
219
+ try {
220
+ const params = {
221
+ method: 'PUT',
222
+ bucket: bucketName,
223
+ subres: { publicAccessBlock: '' },
224
+ headers: {
225
+ 'Content-Type': 'application/xml',
226
+ },
227
+ content: xml,
228
+ successStatuses: [200],
229
+ };
230
+ await ossRequest(ossClient, params);
231
+ logger_1.logger.info(lang_1.lang.__('OSS_BUCKET_PUBLIC_ACCESS_BLOCK_DISABLED', { bucketName }));
232
+ }
233
+ catch (error) {
234
+ logger_1.logger.warn(lang_1.lang.__('OSS_BUCKET_PUBLIC_ACCESS_BLOCK_DISABLE_FAILED', {
235
+ bucketName,
236
+ error: String(error),
237
+ }));
238
+ }
239
+ };
189
240
  const unbindCustomDomain = async (bucketName, domain, dnsRecordId) => {
190
241
  await removeCorsRuleForDomain(bucketName, domain);
191
242
  await deleteBucketCname(bucketName, domain);
@@ -212,6 +263,9 @@ const createOssOperations = (ossClient, region, dnsOps) => {
212
263
  }
213
264
  // Set ACL if specified
214
265
  if (config.acl) {
266
+ if (isPublicAcl(config.acl)) {
267
+ await disableBucketPublicAccessBlock(config.bucketName);
268
+ }
215
269
  useBucket(config.bucketName);
216
270
  await ossClient.putBucketACL(config.bucketName, config.acl);
217
271
  }
@@ -362,6 +416,9 @@ const createOssOperations = (ossClient, region, dnsOps) => {
362
416
  }
363
417
  },
364
418
  updateBucketAcl: async (bucketName, acl) => {
419
+ if (isPublicAcl(acl)) {
420
+ await disableBucketPublicAccessBlock(bucketName);
421
+ }
365
422
  useBucket(bucketName);
366
423
  await ossClient.putBucketACL(bucketName, acl);
367
424
  },
@@ -35,6 +35,8 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.createRamOperations = void 0;
37
37
  const ram = __importStar(require("@alicloud/ram20150501"));
38
+ const lang_1 = require("../../lang");
39
+ const logger_1 = require("../logger");
38
40
  const buildAssumeRolePolicy = (trustedServices) => JSON.stringify({
39
41
  Version: '1',
40
42
  Statement: [
@@ -50,6 +52,11 @@ const buildAssumeRolePolicy = (trustedServices) => JSON.stringify({
50
52
  const FC_EXECUTION_POLICY = JSON.stringify({
51
53
  Version: '1',
52
54
  Statement: [
55
+ {
56
+ Effect: 'Allow',
57
+ Action: ['fc:InvokeFunction'],
58
+ Resource: '*',
59
+ },
53
60
  {
54
61
  Effect: 'Allow',
55
62
  Action: [
@@ -127,7 +134,6 @@ const createRamOperations = (ramClient) => {
127
134
  };
128
135
  return {
129
136
  createRole: async (roleName, trustedServices, description) => {
130
- let roleInfo;
131
137
  const assumeRolePolicy = buildAssumeRolePolicy(trustedServices);
132
138
  try {
133
139
  const request = new ram.CreateRoleRequest({
@@ -136,40 +142,79 @@ const createRamOperations = (ramClient) => {
136
142
  description: description ?? `ServerlessInsight FC execution role for ${roleName}`,
137
143
  });
138
144
  const response = await ramClient.createRole(request);
139
- roleInfo = {
145
+ const roleInfo = {
140
146
  roleName,
141
147
  roleId: response.body?.role?.roleId,
142
148
  arn: response.body?.role?.arn,
143
149
  description: response.body?.role?.description,
144
150
  createDate: response.body?.role?.createDate,
145
151
  };
152
+ await attachRolePolicyForFc(roleName);
153
+ return roleInfo;
146
154
  }
147
155
  catch (error) {
148
156
  if (error &&
149
157
  typeof error === 'object' &&
150
158
  'code' in error &&
151
159
  error.code === 'EntityAlreadyExists.Role') {
152
- const getRequest = new ram.GetRoleRequest({ roleName });
153
- const getResponse = await ramClient.getRole(getRequest);
154
- roleInfo = {
155
- roleName,
156
- roleId: getResponse.body?.role?.roleId,
157
- arn: getResponse.body?.role?.arn,
158
- description: getResponse.body?.role?.description,
159
- createDate: getResponse.body?.role?.createDate,
160
- };
161
- const updateRequest = new ram.UpdateRoleRequest({
162
- roleName,
163
- newAssumeRolePolicyDocument: assumeRolePolicy,
164
- });
165
- await ramClient.updateRole(updateRequest);
160
+ logger_1.logger.warn(lang_1.lang.__('RAM_ROLE_ALREADY_EXISTS', { roleName }));
161
+ try {
162
+ const getRequest = new ram.GetRoleRequest({ roleName });
163
+ const getResponse = await ramClient.getRole(getRequest);
164
+ const updateRequest = new ram.UpdateRoleRequest({
165
+ roleName,
166
+ newAssumeRolePolicyDocument: assumeRolePolicy,
167
+ });
168
+ await ramClient.updateRole(updateRequest);
169
+ await attachRolePolicyForFc(roleName);
170
+ return {
171
+ roleName,
172
+ roleId: getResponse.body?.role?.roleId,
173
+ arn: getResponse.body?.role?.arn,
174
+ description: getResponse.body?.role?.description,
175
+ createDate: getResponse.body?.role?.createDate,
176
+ };
177
+ }
178
+ catch (recoveryError) {
179
+ // eslint-disable-next-line preserve-caught-error
180
+ throw new Error(lang_1.lang.__('RAM_ROLE_DRIFT_RECOVERY_FAILED', {
181
+ roleName,
182
+ error: recoveryError instanceof Error ? recoveryError.message : String(recoveryError),
183
+ }));
184
+ }
166
185
  }
167
- else {
168
- throw error;
186
+ throw error;
187
+ }
188
+ },
189
+ updateRoleTrustPolicy: async (roleName, trustedServices) => {
190
+ const assumeRolePolicy = buildAssumeRolePolicy(trustedServices);
191
+ try {
192
+ const getRequest = new ram.GetRoleRequest({ roleName });
193
+ const getResponse = await ramClient.getRole(getRequest);
194
+ const roleInfo = {
195
+ roleName,
196
+ roleId: getResponse.body?.role?.roleId,
197
+ arn: getResponse.body?.role?.arn,
198
+ description: getResponse.body?.role?.description,
199
+ createDate: getResponse.body?.role?.createDate,
200
+ };
201
+ const updateRequest = new ram.UpdateRoleRequest({
202
+ roleName,
203
+ newAssumeRolePolicyDocument: assumeRolePolicy,
204
+ });
205
+ await ramClient.updateRole(updateRequest);
206
+ return roleInfo;
207
+ }
208
+ catch (error) {
209
+ if (error &&
210
+ typeof error === 'object' &&
211
+ 'code' in error &&
212
+ error.code === 'EntityNotExist.Role') {
213
+ // eslint-disable-next-line preserve-caught-error
214
+ throw new Error(lang_1.lang.__('RAM_ROLE_NOT_FOUND_IN_CLOUD', { roleName }));
169
215
  }
216
+ throw error;
170
217
  }
171
- await attachRolePolicyForFc(roleName);
172
- return roleInfo;
173
218
  },
174
219
  getRole: async (roleName) => {
175
220
  try {
@@ -0,0 +1,63 @@
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.resolveCertificateDomain = exports.resolveReferenceCertificate = exports.resolveUploadCertificate = void 0;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const node_fs_1 = __importDefault(require("node:fs"));
9
+ const certificateParser_1 = require("../parser/certificateParser");
10
+ const logger_1 = require("./logger");
11
+ const lang_1 = require("../lang");
12
+ const readPemContent = (value) => {
13
+ if (!(0, certificateParser_1.isFilePath)(value)) {
14
+ return value;
15
+ }
16
+ const filePath = node_path_1.default.resolve(process.cwd(), value);
17
+ if (!node_fs_1.default.existsSync(filePath)) {
18
+ throw new Error(lang_1.lang.__('CERT_FILE_NOT_FOUND', { filePath }));
19
+ }
20
+ logger_1.logger.info(lang_1.lang.__('CERT_READING_FILE', { filePath }));
21
+ return node_fs_1.default.readFileSync(filePath, 'utf-8');
22
+ };
23
+ const resolveUploadCertificate = (cert) => {
24
+ if (!cert.certificate_body || !cert.private_key) {
25
+ throw new Error(lang_1.lang.__('CERT_INVALID_CONFIGURATION', { name: cert.key }));
26
+ }
27
+ logger_1.logger.info(lang_1.lang.__('CERT_RESOLVED_UPLOAD', { name: cert.key }));
28
+ logger_1.logger.info(lang_1.lang.__('CERT_READING_PEM_FILES', { name: cert.key }));
29
+ const body = readPemContent(cert.certificate_body);
30
+ const key = readPemContent(cert.private_key);
31
+ const chain = cert.chain ? readPemContent(cert.chain) : undefined;
32
+ return {
33
+ certificateName: cert.key,
34
+ certificateBody: chain ? `${body}\n${chain}` : body,
35
+ certificatePrivateKey: key,
36
+ };
37
+ };
38
+ exports.resolveUploadCertificate = resolveUploadCertificate;
39
+ const resolveReferenceCertificate = async (cert, getCertificateFromProvider) => {
40
+ if (!cert.certificate_id) {
41
+ throw new Error(lang_1.lang.__('CERT_INVALID_CONFIGURATION', { name: cert.key }));
42
+ }
43
+ const certId = cert.certificate_id;
44
+ logger_1.logger.info(lang_1.lang.__('CERT_RESOLVED_REFERENCE', { name: cert.key, certId }));
45
+ logger_1.logger.info(lang_1.lang.__('CAS_FETCHING_CERT', { certId }));
46
+ const certDetail = await getCertificateFromProvider(certId);
47
+ if (!certDetail || !certDetail.cert || !certDetail.key) {
48
+ throw new Error(lang_1.lang.__('CAS_CERT_NOT_FOUND', { certId }));
49
+ }
50
+ return {
51
+ certificateName: cert.key,
52
+ certificateBody: certDetail.cert,
53
+ certificatePrivateKey: certDetail.key,
54
+ };
55
+ };
56
+ exports.resolveReferenceCertificate = resolveReferenceCertificate;
57
+ const resolveCertificateDomain = async (cert, getCertificateFromProvider) => {
58
+ if (cert.certificate_id) {
59
+ return (0, exports.resolveReferenceCertificate)(cert, getCertificateFromProvider);
60
+ }
61
+ return (0, exports.resolveUploadCertificate)(cert);
62
+ };
63
+ exports.resolveCertificateDomain = resolveCertificateDomain;
@@ -3,7 +3,7 @@ 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.getIacDefinition = exports.calcValue = exports.readCodeSize = exports.resolveCode = void 0;
6
+ exports.getIacDefinition = exports.isCertificateDomain = exports.isFunctionDomain = exports.calcValue = exports.readCodeSize = exports.resolveCode = void 0;
7
7
  const node_path_1 = __importDefault(require("node:path"));
8
8
  const node_fs_1 = __importDefault(require("node:fs"));
9
9
  const lodash_1 = require("lodash");
@@ -83,11 +83,19 @@ const calcValue = (rawValue, ctx, iacVars) => {
83
83
  return inferType(value, isExactTemplateRef);
84
84
  };
85
85
  exports.calcValue = calcValue;
86
+ const isFunctionDomain = (def) => 'name' in def;
87
+ exports.isFunctionDomain = isFunctionDomain;
88
+ const isCertificateDomain = (def) => !('name' in def);
89
+ exports.isCertificateDomain = isCertificateDomain;
86
90
  const getIacDefinition = (iac, rawValue) => {
87
91
  const matchFn = rawValue.match(/^\$\{functions\.(\w+(\.\w+)?)}$/);
88
92
  if (matchFn?.length) {
89
93
  return iac.functions?.find((fc) => fc.key === matchFn[1]);
90
94
  }
95
+ const matchCert = rawValue.match(/^\$\{certificates\.(\w+)}$/);
96
+ if (matchCert?.length) {
97
+ return iac.certificates?.find((cert) => cert.key === matchCert[1]);
98
+ }
91
99
  return iac.functions?.find((fc) => fc.key === rawValue);
92
100
  };
93
101
  exports.getIacDefinition = getIacDefinition;
@@ -31,3 +31,4 @@ __exportStar(require("./runtimeMapper"), exports);
31
31
  __exportStar(require("./hashUtils"), exports);
32
32
  __exportStar(require("./dependencyGraph"), exports);
33
33
  __exportStar(require("./sidUtils"), exports);
34
+ __exportStar(require("./certificateResolver"), exports);
@@ -43,16 +43,19 @@ exports.createTencentClient = void 0;
43
43
  const tencentcloud = __importStar(require("tencentcloud-sdk-nodejs-scf"));
44
44
  const cynosdb = __importStar(require("tencentcloud-sdk-nodejs-cynosdb"));
45
45
  const tencentEs = __importStar(require("tencentcloud-sdk-nodejs-es"));
46
+ const tencentSsl = __importStar(require("tencentcloud-sdk-nodejs-ssl"));
46
47
  const cos_nodejs_sdk_v5_1 = __importDefault(require("cos-nodejs-sdk-v5"));
47
48
  const scfOperations_1 = require("./scfOperations");
48
49
  const cosOperations_1 = require("./cosOperations");
49
50
  const tdsqlcOperations_1 = require("./tdsqlcOperations");
50
51
  const esOperations_1 = require("./esOperations");
51
52
  const dnspodOperations_1 = require("./dnspodOperations");
53
+ const sslOperations_1 = require("./sslOperations");
52
54
  __exportStar(require("./types"), exports);
53
55
  const ScfClient = tencentcloud.scf.v20180416.Client;
54
56
  const CynosdbClient = cynosdb.cynosdb.v20190107.Client;
55
57
  const EsClient = tencentEs.es.v20180416.Client;
58
+ const SslClient = tencentSsl.ssl.v20191205.Client;
56
59
  // Initialize SDK clients (internal)
57
60
  const initializeSdkClients = (context) => {
58
61
  const scfClientConfig = {
@@ -98,11 +101,25 @@ const initializeSdkClients = (context) => {
98
101
  },
99
102
  };
100
103
  const esClient = new EsClient(esClientConfig);
104
+ const sslClientConfig = {
105
+ credential: {
106
+ secretId: context.accessKeyId,
107
+ secretKey: context.accessKeySecret,
108
+ },
109
+ region: context.region,
110
+ profile: {
111
+ httpProfile: {
112
+ endpoint: 'ssl.tencentcloudapi.com',
113
+ },
114
+ },
115
+ };
116
+ const sslClient = new SslClient(sslClientConfig);
101
117
  return {
102
118
  scf: scfClient,
103
119
  cos: cosClient,
104
120
  cynosdb: cynosdbClient,
105
121
  es: esClient,
122
+ ssl: sslClient,
106
123
  dns: (0, dnspodOperations_1.createDnsClient)(context),
107
124
  };
108
125
  };
@@ -114,6 +131,7 @@ const createTencentClient = (context) => {
114
131
  cos: (0, cosOperations_1.createCosOperations)(sdkClients.cos, context.region, dnsOps),
115
132
  tdsqlc: (0, tdsqlcOperations_1.createTdsqlcOperations)(sdkClients.cynosdb, context),
116
133
  es: (0, esOperations_1.createTencentEsOperations)(sdkClients.es, context),
134
+ ssl: (0, sslOperations_1.createSslOperations)(sdkClients.ssl),
117
135
  dns: dnsOps,
118
136
  };
119
137
  };