@geek-fun/serverlessinsight 0.5.10 → 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.
- package/dist/package.json +3 -1
- package/dist/src/common/aliyunClient/casOperations.js +116 -0
- package/dist/src/common/aliyunClient/index.js +8 -0
- package/dist/src/common/aliyunClient/ossOperations.js +61 -4
- package/dist/src/common/certificateResolver.js +63 -0
- package/dist/src/common/iacHelper.js +9 -1
- package/dist/src/common/index.js +1 -0
- package/dist/src/common/tencentClient/index.js +18 -0
- package/dist/src/common/tencentClient/sslOperations.js +107 -0
- package/dist/src/lang/en.js +42 -0
- package/dist/src/lang/zh-CN.js +41 -0
- package/dist/src/parser/bucketParser.js +19 -1
- package/dist/src/parser/certificateParser.js +23 -0
- package/dist/src/parser/index.js +2 -0
- package/dist/src/stack/aliyunStack/apigwResource.js +41 -14
- package/dist/src/stack/aliyunStack/apigwTypes.js +32 -2
- package/dist/src/stack/aliyunStack/ossResource.js +39 -2
- package/dist/src/stack/localStack/event.js +1 -1
- package/dist/src/stack/scfStack/cosResource.js +35 -4
- package/dist/src/types/domains/certificate.js +2 -0
- package/dist/src/types/index.js +1 -0
- package/dist/src/validator/bucketSchema.js +23 -1
- package/dist/src/validator/certificateSchema.js +31 -0
- package/dist/src/validator/eventSchema.js +12 -0
- package/dist/src/validator/iacSchema.js +2 -0
- package/dist/src/validator/rootSchema.js +3 -0
- package/dist/src/validator/templateRefSchema.js +3 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -1
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geek-fun/serverlessinsight",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Full life cycle cross providers serverless application management for your fast-growing business.",
|
|
5
5
|
"homepage": "https://serverlessinsight.geekfun.club",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@alicloud/alidns20150109": "^4.3.1",
|
|
53
|
+
"@alicloud/cas20200407": "^3.2.0",
|
|
53
54
|
"@alicloud/cloudapi20160714": "^4.7.9",
|
|
54
55
|
"@alicloud/ecs20140526": "^7.6.0",
|
|
55
56
|
"@alicloud/es-serverless20230627": "^2.3.0",
|
|
@@ -75,6 +76,7 @@
|
|
|
75
76
|
"tencentcloud-sdk-nodejs-dnspod": "^4.1.197",
|
|
76
77
|
"tencentcloud-sdk-nodejs-es": "^4.1.183",
|
|
77
78
|
"tencentcloud-sdk-nodejs-scf": "^4.1.168",
|
|
79
|
+
"tencentcloud-sdk-nodejs-ssl": "^4.1.191",
|
|
78
80
|
"yaml": "^2.8.2"
|
|
79
81
|
},
|
|
80
82
|
"devDependencies": {
|
|
@@ -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, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
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
|
|
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
|
},
|
|
@@ -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;
|
package/dist/src/common/index.js
CHANGED
|
@@ -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
|
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSslOperations = void 0;
|
|
4
|
+
const lang_1 = require("../../lang");
|
|
5
|
+
const logger_1 = require("../logger");
|
|
6
|
+
const createSslOperations = (sslClient) => ({
|
|
7
|
+
uploadCertificate: async (alias, cert, key, chain) => {
|
|
8
|
+
logger_1.logger.info(lang_1.lang.__('SSL_UPLOADING_CERT', { alias }));
|
|
9
|
+
const response = await sslClient.UploadCertificate({
|
|
10
|
+
CertificatePublicKey: chain ? `${cert}\n${chain}` : cert,
|
|
11
|
+
CertificatePrivateKey: key,
|
|
12
|
+
CertificateType: 'SVR',
|
|
13
|
+
Alias: alias,
|
|
14
|
+
Repeatable: false,
|
|
15
|
+
});
|
|
16
|
+
const certificateId = response.RepeatCertId ?? response.CertificateId;
|
|
17
|
+
if (!certificateId) {
|
|
18
|
+
throw new Error(lang_1.lang.__('SSL_UPLOAD_NO_CERT_ID', { alias }));
|
|
19
|
+
}
|
|
20
|
+
logger_1.logger.info(lang_1.lang.__('SSL_CERT_UPLOADED', { alias, certificateId }));
|
|
21
|
+
return { certificateId, alias };
|
|
22
|
+
},
|
|
23
|
+
getCertificate: async (certificateId) => {
|
|
24
|
+
try {
|
|
25
|
+
const response = await sslClient.DescribeCertificateDetail({ CertificateId: certificateId });
|
|
26
|
+
return {
|
|
27
|
+
certificateId: response.CertificateId ?? certificateId,
|
|
28
|
+
alias: response.Alias ?? undefined,
|
|
29
|
+
domain: response.Domain ?? undefined,
|
|
30
|
+
status: response.Status ?? undefined,
|
|
31
|
+
certBeginTime: response.CertBeginTime ?? undefined,
|
|
32
|
+
certEndTime: response.CertEndTime ?? undefined,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (error &&
|
|
37
|
+
typeof error === 'object' &&
|
|
38
|
+
'code' in error &&
|
|
39
|
+
(error.code === 'FailedOperation.CertificateNotFound' || error.code === 'ResourceNotFound')) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
deleteCertificate: async (certificateId) => {
|
|
46
|
+
logger_1.logger.info(lang_1.lang.__('SSL_DELETING_CERT', { certificateId }));
|
|
47
|
+
try {
|
|
48
|
+
const response = await sslClient.DeleteCertificate({ CertificateId: certificateId });
|
|
49
|
+
if (response.DeleteResult === false) {
|
|
50
|
+
throw new Error(lang_1.lang.__('SSL_DELETE_FAILED', { certificateId }));
|
|
51
|
+
}
|
|
52
|
+
logger_1.logger.info(lang_1.lang.__('SSL_CERT_DELETED', { certificateId }));
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
if (error &&
|
|
56
|
+
typeof error === 'object' &&
|
|
57
|
+
'code' in error &&
|
|
58
|
+
(error.code === 'FailedOperation.CertificateNotFound' || error.code === 'ResourceNotFound')) {
|
|
59
|
+
logger_1.logger.warn(lang_1.lang.__('SSL_CERT_NOT_FOUND', { certificateId }));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
deployCertificateInstance: async (certificateId, resourceType, instanceIdList) => {
|
|
66
|
+
logger_1.logger.info(lang_1.lang.__('SSL_DEPLOYING_CERT', {
|
|
67
|
+
certificateId,
|
|
68
|
+
resourceType,
|
|
69
|
+
instances: instanceIdList.join(', '),
|
|
70
|
+
}));
|
|
71
|
+
try {
|
|
72
|
+
const response = await sslClient.DeployCertificateInstance({
|
|
73
|
+
CertificateId: certificateId,
|
|
74
|
+
ResourceType: resourceType,
|
|
75
|
+
InstanceIdList: instanceIdList,
|
|
76
|
+
});
|
|
77
|
+
const deployStatus = response.DeployStatus ?? undefined;
|
|
78
|
+
if (deployStatus === 0) {
|
|
79
|
+
logger_1.logger.info(lang_1.lang.__('SSL_CERT_DEPLOY_EXISTING_TASK', {
|
|
80
|
+
certificateId,
|
|
81
|
+
resourceType,
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
logger_1.logger.info(lang_1.lang.__('SSL_CERT_DEPLOY_SUBMITTED', {
|
|
86
|
+
certificateId,
|
|
87
|
+
resourceType,
|
|
88
|
+
deployRecordId: String(response.DeployRecordId ?? ''),
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
return {
|
|
92
|
+
deployRecordId: response.DeployRecordId ?? undefined,
|
|
93
|
+
deployStatus,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
98
|
+
// eslint-disable-next-line preserve-caught-error
|
|
99
|
+
throw new Error(lang_1.lang.__('SSL_CERT_DEPLOY_FAILED', {
|
|
100
|
+
resourceType,
|
|
101
|
+
certificateId,
|
|
102
|
+
error: message,
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
exports.createSslOperations = createSslOperations;
|
package/dist/src/lang/en.js
CHANGED
|
@@ -276,11 +276,16 @@ exports.en = {
|
|
|
276
276
|
OSS_BUCKET_CNAME_BIND_FAILED: 'Failed to bind bucket CNAME: {{error}}',
|
|
277
277
|
OSS_BUCKET_CNAME_UNBIND_FAILED: 'Failed to unbind bucket CNAME: {{error}}',
|
|
278
278
|
OSS_BUCKET_CNAME_NEED_VERIFY: 'Domain ownership verification required. Please add TXT record in DNS console, then retry.',
|
|
279
|
+
OSS_BUCKET_CERT_BINDING: 'Binding SSL certificate to custom domain {{domain}} on bucket {{bucketName}}',
|
|
280
|
+
OSS_BUCKET_CERT_BOUND: 'SSL certificate bound to custom domain: {{domain}}',
|
|
279
281
|
OSS_CORS_RULE_ADDED: 'Added CORS rule for custom domain: {{domain}}',
|
|
280
282
|
OSS_CORS_RULE_EXISTS: 'CORS rule already exists for custom domain: {{domain}}',
|
|
281
283
|
OSS_CORS_RULE_ADD_FAILED: 'Failed to add CORS rule for {{domain}}: {{error}}',
|
|
282
284
|
OSS_CORS_RULE_REMOVED: 'Removed CORS rule for custom domain: {{domain}}',
|
|
283
285
|
OSS_CORS_RULE_REMOVE_FAILED: 'Failed to remove CORS rule for {{domain}}: {{error}}',
|
|
286
|
+
OSS_BUCKET_PUBLIC_ACCESS_BLOCK_DISABLED: 'Disabled Block Public Access for bucket: {{bucketName}}',
|
|
287
|
+
OSS_BUCKET_PUBLIC_ACCESS_BLOCK_DISABLE_FAILED: 'Failed to disable Block Public Access for bucket {{bucketName}}: {{error}}. ' +
|
|
288
|
+
'You may need to manually disable Block Public Access in the Alibaba Cloud OSS Console.',
|
|
284
289
|
// Tencent COS DNS messages
|
|
285
290
|
COS_DNS_CNAME_CREATED: 'Created DNS CNAME record: {{domain}} -> {{cname}}',
|
|
286
291
|
COS_DNS_CNAME_EXISTS: 'DNS CNAME record already exists: {{domain}} -> {{cname}}',
|
|
@@ -426,4 +431,41 @@ exports.en = {
|
|
|
426
431
|
RAM_ROLE_DRIFT_RECOVERY_FAILED: 'Failed to recover from RAM role state drift for "{{roleName}}": {{error}}. ' +
|
|
427
432
|
'The role existed in the cloud but recovery operations failed. ' +
|
|
428
433
|
'To fix: manually verify the role in the cloud console, remove it from state, and redeploy.',
|
|
434
|
+
// Certificate messages
|
|
435
|
+
CERT_INVALID_CONFIGURATION: 'Certificate "{{name}}" must have either (certificate_body + private_key) or certificate_id, but not both',
|
|
436
|
+
CERT_FILE_NOT_FOUND: 'Certificate file not found: {{filePath}}',
|
|
437
|
+
CERT_READING_FILE: 'Reading certificate file: {{filePath}}',
|
|
438
|
+
CERT_PARSING_CERTIFICATES: 'Parsing certificates configuration',
|
|
439
|
+
CERT_RESOLVING_REFERENCE: 'Resolving certificate reference "{{reference}}" for domain "{{domain}}"',
|
|
440
|
+
CERT_REFERENCE_NOT_FOUND: 'Certificate reference "{{reference}}" could not be resolved. Ensure it is defined in the certificates block.',
|
|
441
|
+
CERT_RESOLVED_UPLOAD: 'Certificate "{{name}}" resolved as upload mode (PEM files provided)',
|
|
442
|
+
CERT_RESOLVED_REFERENCE: 'Certificate "{{name}}" resolved as reference mode (certificate_id: {{certId}})',
|
|
443
|
+
CERT_READING_PEM_FILES: 'Reading PEM files for certificate "{{name}}"',
|
|
444
|
+
// CAS (Certificate Authority Service) messages
|
|
445
|
+
CAS_UPLOADING_CERT: 'Uploading certificate "{{name}}" to CAS',
|
|
446
|
+
CAS_CERT_UPLOADED: 'Certificate "{{name}}" uploaded to CAS (certId: {{certId}})',
|
|
447
|
+
CAS_UPLOAD_NO_CERT_ID: 'CAS upload succeeded but no certificate ID returned for "{{name}}"',
|
|
448
|
+
CAS_FETCHING_CERT: 'Fetching certificate details from CAS (certId: {{certId}})',
|
|
449
|
+
CAS_CERT_NOT_FOUND: 'Certificate not found in CAS (certId: {{certId}})',
|
|
450
|
+
CAS_CERT_FETCH_FAILED: 'Failed to fetch certificate from CAS (certId: {{certId}}): {{error}}',
|
|
451
|
+
CAS_DELETING_CERT: 'Deleting certificate from CAS (certId: {{certId}})',
|
|
452
|
+
CAS_CERT_DELETED: 'Certificate deleted from CAS (certId: {{certId}})',
|
|
453
|
+
// Tencent SSL certificate messages
|
|
454
|
+
SSL_UPLOADING_CERT: 'Uploading certificate to Tencent SSL (alias: {{alias}})',
|
|
455
|
+
SSL_CERT_UPLOADED: 'Certificate uploaded to Tencent SSL (alias: {{alias}}, certificateId: {{certificateId}})',
|
|
456
|
+
SSL_UPLOAD_NO_CERT_ID: 'SSL upload succeeded but no certificate ID returned for "{{alias}}"',
|
|
457
|
+
SSL_DELETING_CERT: 'Deleting certificate from Tencent SSL (certificateId: {{certificateId}})',
|
|
458
|
+
SSL_CERT_DELETED: 'Certificate deleted from Tencent SSL (certificateId: {{certificateId}})',
|
|
459
|
+
SSL_CERT_NOT_FOUND: 'Certificate not found in Tencent SSL (certificateId: {{certificateId}})',
|
|
460
|
+
SSL_DELETE_FAILED: 'Failed to delete certificate from Tencent SSL (certificateId: {{certificateId}})',
|
|
461
|
+
SSL_DEPLOYING_CERT: 'Deploying certificate to {{resourceType}} (certificateId: {{certificateId}}, instances: {{instances}})',
|
|
462
|
+
SSL_CERT_DEPLOY_SUBMITTED: 'Certificate deploy task submitted to {{resourceType}} (certificateId: {{certificateId}}, deployRecordId: {{deployRecordId}})',
|
|
463
|
+
SSL_CERT_DEPLOY_EXISTING_TASK: 'Certificate deploy task already in progress for {{resourceType}} (certificateId: {{certificateId}})',
|
|
464
|
+
SSL_CERT_DEPLOYED: 'Certificate deployed to {{resourceType}} (certificateId: {{certificateId}}, deployRecordId: {{deployRecordId}})',
|
|
465
|
+
SSL_CERT_DEPLOY_FAILED: 'Failed to deploy certificate to {{resourceType}} (certificateId: {{certificateId}}): {{error}}',
|
|
466
|
+
COS_BUCKET_CERT_DEPLOYING: 'Deploying SSL certificate to COS bucket domain: {{domain}} (bucket: {{bucketName}})',
|
|
467
|
+
COS_BUCKET_CERT_DEPLOYED: 'SSL certificate deployed to COS bucket domain: {{domain}}',
|
|
468
|
+
TENCENT_CERT_REFERENCE_NOT_SUPPORTED: 'Certificate "{{name}}" uses certificate_id reference mode which is not yet supported for Tencent Cloud. Use certificate_body and private_key instead.',
|
|
469
|
+
// Protocol messages
|
|
470
|
+
PROTOCOL_INFERRED_REDIRECT: 'Protocol "{{protocol}}" inferred HTTP-to-HTTPS redirect: {{redirect}}',
|
|
429
471
|
};
|