@geek-fun/serverlessinsight 0.5.10 → 0.6.1
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/README.md +94 -1
- package/README.zh-CN.md +94 -1
- package/dist/package.json +3 -1
- package/dist/src/common/aliyunClient/apigwOperations.js +5 -5
- 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 +290 -18
- package/dist/src/common/certificateResolver.js +63 -0
- package/dist/src/common/constants.js +10 -4
- package/dist/src/common/iacHelper.js +9 -1
- package/dist/src/common/index.js +2 -0
- package/dist/src/common/planFormatter.js +269 -0
- package/dist/src/common/retryUtils.js +5 -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 +86 -1
- package/dist/src/lang/zh-CN.js +84 -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 +44 -5
- package/dist/src/stack/localStack/event.js +1 -1
- package/dist/src/stack/scfStack/cosResource.js +35 -4
- package/dist/src/stack/scfStack/planner.js +1 -57
- 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
|
@@ -3,6 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseBucket = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
const parseUtils_1 = require("./parseUtils");
|
|
6
|
+
const isStructuredDomain = (domain) => typeof domain === 'object' && domain !== null && 'domain_name' in domain;
|
|
7
|
+
const parseWebsiteDomain = (domain) => {
|
|
8
|
+
if (domain == null) {
|
|
9
|
+
return { domain: undefined, domain_certificate: undefined, domain_protocol: undefined };
|
|
10
|
+
}
|
|
11
|
+
if (!isStructuredDomain(domain)) {
|
|
12
|
+
return { domain: String(domain), domain_certificate: undefined, domain_protocol: undefined };
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
domain: String(domain.domain_name),
|
|
16
|
+
domain_certificate: domain.certificate != null ? String(domain.certificate) : undefined,
|
|
17
|
+
domain_protocol: domain.protocol != null
|
|
18
|
+
? Array.isArray(domain.protocol)
|
|
19
|
+
? domain.protocol.map(String)
|
|
20
|
+
: String(domain.protocol)
|
|
21
|
+
: undefined,
|
|
22
|
+
};
|
|
23
|
+
};
|
|
6
24
|
const parseBucket = (buckets) => {
|
|
7
25
|
if (!buckets) {
|
|
8
26
|
return undefined;
|
|
@@ -37,7 +55,7 @@ const parseBucket = (buckets) => {
|
|
|
37
55
|
website: bucket.website
|
|
38
56
|
? {
|
|
39
57
|
code: String(bucket.website.code),
|
|
40
|
-
|
|
58
|
+
...parseWebsiteDomain(bucket.website.domain),
|
|
41
59
|
index: (0, parseUtils_1.parseStringWithDefault)(bucket.website.index, 'index.html'),
|
|
42
60
|
error_page: (0, parseUtils_1.parseStringWithDefault)(bucket.website.error_page, '404.html'),
|
|
43
61
|
error_code: (0, parseUtils_1.parseNumberWithDefault)(bucket.website.error_code, 404),
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isFilePath = exports.parseCertificate = void 0;
|
|
4
|
+
const isFilePath = (value) => {
|
|
5
|
+
if (value.startsWith('./') || value.startsWith('../')) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
return /\.(pem|crt|key)$/.test(value);
|
|
9
|
+
};
|
|
10
|
+
exports.isFilePath = isFilePath;
|
|
11
|
+
const parseCertificate = (certificates) => {
|
|
12
|
+
if (!certificates) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
return Object.entries(certificates).map(([key, cert]) => ({
|
|
16
|
+
key,
|
|
17
|
+
certificate_body: cert.certificate_body != null ? String(cert.certificate_body) : undefined,
|
|
18
|
+
private_key: cert.private_key != null ? String(cert.private_key) : undefined,
|
|
19
|
+
chain: cert.chain != null ? String(cert.chain) : undefined,
|
|
20
|
+
certificate_id: cert.certificate_id != null ? String(cert.certificate_id) : undefined,
|
|
21
|
+
}));
|
|
22
|
+
};
|
|
23
|
+
exports.parseCertificate = parseCertificate;
|
package/dist/src/parser/index.js
CHANGED
|
@@ -11,6 +11,7 @@ const yaml_1 = require("yaml");
|
|
|
11
11
|
const validator_1 = require("../validator");
|
|
12
12
|
const bucketParser_1 = require("./bucketParser");
|
|
13
13
|
const tableParser_1 = require("./tableParser");
|
|
14
|
+
const certificateParser_1 = require("./certificateParser");
|
|
14
15
|
const common_1 = require("../common");
|
|
15
16
|
const validateExistence = (path) => {
|
|
16
17
|
if (!(0, node_fs_1.existsSync)(path)) {
|
|
@@ -51,6 +52,7 @@ const transformYaml = (iacJson, stage) => {
|
|
|
51
52
|
tables: (0, tableParser_1.parseTable)(iacJson.tables),
|
|
52
53
|
tags: (0, tagParser_1.parseTag)(iacJson.tags, iacJson.app, iacJson.service, stage),
|
|
53
54
|
buckets: (0, bucketParser_1.parseBucket)(iacJson.buckets),
|
|
55
|
+
certificates: iacJson.certificates ? (0, certificateParser_1.parseCertificate)(iacJson.certificates) : undefined,
|
|
54
56
|
};
|
|
55
57
|
};
|
|
56
58
|
const parseYaml = (iacLocation) => {
|
|
@@ -56,6 +56,43 @@ const buildApigwDeploymentInstance = (groupId, apiId, stageName, stage) => {
|
|
|
56
56
|
stageName,
|
|
57
57
|
};
|
|
58
58
|
};
|
|
59
|
+
const resolveDomainCertificate = async (domain, context, client) => {
|
|
60
|
+
if (domain.certificate) {
|
|
61
|
+
if (!context.iac) {
|
|
62
|
+
throw new Error(lang_1.lang.__('CERT_REFERENCE_NOT_FOUND', { reference: String(domain.certificate) }));
|
|
63
|
+
}
|
|
64
|
+
const certDef = (0, common_1.getIacDefinition)(context.iac, domain.certificate);
|
|
65
|
+
if (!certDef || !(0, common_1.isCertificateDomain)(certDef)) {
|
|
66
|
+
throw new Error(lang_1.lang.__('CERT_REFERENCE_NOT_FOUND', { reference: String(domain.certificate) }));
|
|
67
|
+
}
|
|
68
|
+
const resolved = await (0, common_1.resolveCertificateDomain)(certDef, async (certId) => {
|
|
69
|
+
const detail = await client.cas.getCertificate(certId);
|
|
70
|
+
if (!detail)
|
|
71
|
+
return null;
|
|
72
|
+
return { cert: detail.cert, key: detail.key };
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
certificateName: resolved.certificateName,
|
|
76
|
+
certificateBody: resolved.certificateBody,
|
|
77
|
+
certificatePrivateKey: resolved.certificatePrivateKey,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
certificateName: domain.certificate_name,
|
|
82
|
+
certificateBody: domain.certificate_body,
|
|
83
|
+
certificatePrivateKey: domain.certificate_private_key,
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
const buildDomainBindingConfig = async (domain, groupId, context, client) => {
|
|
87
|
+
const certConfig = await resolveDomainCertificate(domain, context, client);
|
|
88
|
+
const protocolConfig = (0, apigwTypes_1.inferProtocolConfig)(domain.protocol);
|
|
89
|
+
return {
|
|
90
|
+
groupId,
|
|
91
|
+
domainName: domain.domain_name,
|
|
92
|
+
isHttpRedirectToHttps: protocolConfig.isHttpRedirectToHttps,
|
|
93
|
+
...certConfig,
|
|
94
|
+
};
|
|
95
|
+
};
|
|
59
96
|
const createApigwResource = async (context, event, serviceName, roleArn, state) => {
|
|
60
97
|
const logicalId = `events.${event.key}`;
|
|
61
98
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
@@ -147,13 +184,8 @@ const createApigwResource = async (context, event, serviceName, roleArn, state)
|
|
|
147
184
|
}
|
|
148
185
|
if (event.domain) {
|
|
149
186
|
try {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
domainName: event.domain.domain_name,
|
|
153
|
-
certificateName: event.domain.certificate_name,
|
|
154
|
-
certificateBody: event.domain.certificate_body,
|
|
155
|
-
certificatePrivateKey: event.domain.certificate_private_key,
|
|
156
|
-
}, state, logicalId);
|
|
187
|
+
const domainConfig = await buildDomainBindingConfig(event.domain, groupId, context, client);
|
|
188
|
+
state = await client.apigw.bindCustomDomain(domainConfig, state, logicalId);
|
|
157
189
|
}
|
|
158
190
|
catch (error) {
|
|
159
191
|
logger_1.logger.error(lang_1.lang.__('APIGW_DOMAIN_BINDING_FAILED', { error: String(error) }));
|
|
@@ -267,13 +299,8 @@ const updateApigwResource = async (context, event, serviceName, roleArn, state)
|
|
|
267
299
|
}
|
|
268
300
|
}
|
|
269
301
|
if (event.domain) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
domainName: event.domain.domain_name,
|
|
273
|
-
certificateName: event.domain.certificate_name,
|
|
274
|
-
certificateBody: event.domain.certificate_body,
|
|
275
|
-
certificatePrivateKey: event.domain.certificate_private_key,
|
|
276
|
-
}, state, logicalId);
|
|
302
|
+
const domainConfig = await buildDomainBindingConfig(event.domain, groupId, context, client);
|
|
303
|
+
state = await client.apigw.bindCustomDomain(domainConfig, state, logicalId);
|
|
277
304
|
}
|
|
278
305
|
const groupDefinition = (0, apigwTypes_1.extractApigwGroupDefinition)(groupConfig);
|
|
279
306
|
const resourceState = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.extractApigwDeploymentDefinition = exports.extractApigwApiDefinition = exports.extractApigwGroupDefinition = exports.triggerToApigwApiConfig = exports.generateApiKey = exports.eventToApigwGroupConfig = void 0;
|
|
3
|
+
exports.inferProtocolConfig = exports.extractApigwDeploymentDefinition = exports.extractApigwApiDefinition = exports.extractApigwGroupDefinition = exports.triggerToApigwApiConfig = exports.generateApiKey = exports.eventToApigwGroupConfig = void 0;
|
|
4
4
|
const common_1 = require("../../common");
|
|
5
5
|
const lang_1 = require("../../lang");
|
|
6
6
|
/**
|
|
@@ -40,7 +40,7 @@ const resolveFunctionReference = (backendRef) => {
|
|
|
40
40
|
}
|
|
41
41
|
// Use getIacDefinition to resolve function references
|
|
42
42
|
const functionDef = (0, common_1.getIacDefinition)(context.iac, backendRef);
|
|
43
|
-
if (!functionDef) {
|
|
43
|
+
if (!functionDef || !(0, common_1.isFunctionDomain)(functionDef)) {
|
|
44
44
|
// Not a function reference or function not found, return as is
|
|
45
45
|
common_1.logger.warn(lang_1.lang.__('FUNCTION_REF_NOT_RESOLVED', { backendRef }));
|
|
46
46
|
return backendRef;
|
|
@@ -124,3 +124,33 @@ const extractApigwDeploymentDefinition = (config) => {
|
|
|
124
124
|
};
|
|
125
125
|
};
|
|
126
126
|
exports.extractApigwDeploymentDefinition = extractApigwDeploymentDefinition;
|
|
127
|
+
/**
|
|
128
|
+
* Infer protocol and HTTP→HTTPS redirect from event domain protocol value.
|
|
129
|
+
*
|
|
130
|
+
* | Value | requestProtocol | isHttpRedirectToHttps |
|
|
131
|
+
* |---------------------|-----------------|-----------------------|
|
|
132
|
+
* | "HTTP" | "HTTP" | undefined |
|
|
133
|
+
* | "HTTPS" | "HTTPS" | true |
|
|
134
|
+
* | ["HTTP", "HTTPS"] | "HTTP,HTTPS" | false |
|
|
135
|
+
* | undefined (default) | "HTTP" | undefined |
|
|
136
|
+
*/
|
|
137
|
+
const inferProtocolConfig = (protocol) => {
|
|
138
|
+
if (!protocol) {
|
|
139
|
+
return { requestProtocol: 'HTTP' };
|
|
140
|
+
}
|
|
141
|
+
if (Array.isArray(protocol)) {
|
|
142
|
+
return {
|
|
143
|
+
requestProtocol: protocol.join(','),
|
|
144
|
+
isHttpRedirectToHttps: false,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
if (protocol === 'HTTPS') {
|
|
148
|
+
common_1.logger.info(lang_1.lang.__('PROTOCOL_INFERRED_REDIRECT', { protocol: 'HTTPS', redirect: 'true' }));
|
|
149
|
+
return {
|
|
150
|
+
requestProtocol: 'HTTPS',
|
|
151
|
+
isHttpRedirectToHttps: true,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return { requestProtocol: protocol };
|
|
155
|
+
};
|
|
156
|
+
exports.inferProtocolConfig = inferProtocolConfig;
|
|
@@ -97,6 +97,25 @@ const buildOssInstanceFromProvider = (info, sid) => {
|
|
|
97
97
|
})),
|
|
98
98
|
};
|
|
99
99
|
};
|
|
100
|
+
const resolveBucketDomainCertificate = async (domainCertificate, context, client) => {
|
|
101
|
+
if (!context.iac) {
|
|
102
|
+
throw new Error(lang_1.lang.__('CERT_REFERENCE_NOT_FOUND', { reference: domainCertificate }));
|
|
103
|
+
}
|
|
104
|
+
const certDef = (0, common_1.getIacDefinition)(context.iac, domainCertificate);
|
|
105
|
+
if (!certDef || !(0, common_1.isCertificateDomain)(certDef)) {
|
|
106
|
+
throw new Error(lang_1.lang.__('CERT_REFERENCE_NOT_FOUND', { reference: domainCertificate }));
|
|
107
|
+
}
|
|
108
|
+
const resolved = await (0, common_1.resolveCertificateDomain)(certDef, async (certId) => {
|
|
109
|
+
const detail = await client.cas.getCertificate(certId);
|
|
110
|
+
if (!detail)
|
|
111
|
+
return null;
|
|
112
|
+
return { cert: detail.cert, key: detail.key };
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
certificateBody: resolved.certificateBody,
|
|
116
|
+
certificatePrivateKey: resolved.certificatePrivateKey,
|
|
117
|
+
};
|
|
118
|
+
};
|
|
100
119
|
const createBucketResource = async (context, bucket, state) => {
|
|
101
120
|
const config = (0, ossTypes_1.bucketToOssBucketConfig)(bucket);
|
|
102
121
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
@@ -125,11 +144,20 @@ const createBucketResource = async (context, bucket, state) => {
|
|
|
125
144
|
state = (0, common_1.setResource)(state, logicalId, partialResourceState);
|
|
126
145
|
let cnameInfo;
|
|
127
146
|
if (bucket.website?.domain) {
|
|
147
|
+
const certificate = bucket.website.domain_certificate
|
|
148
|
+
? await resolveBucketDomainCertificate(bucket.website.domain_certificate, context, client)
|
|
149
|
+
: undefined;
|
|
128
150
|
logger_1.logger.info(lang_1.lang.__('BINDING_CUSTOM_DOMAIN_TO_BUCKET', {
|
|
129
151
|
domain: bucket.website.domain,
|
|
130
152
|
bucketName: config.bucketName,
|
|
131
153
|
}));
|
|
132
|
-
|
|
154
|
+
if (certificate) {
|
|
155
|
+
logger_1.logger.info(lang_1.lang.__('OSS_BUCKET_CERT_BINDING', {
|
|
156
|
+
domain: bucket.website.domain,
|
|
157
|
+
bucketName: config.bucketName,
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
160
|
+
cnameInfo = await client.oss.bindCustomDomain(config.bucketName, bucket.website.domain, certificate);
|
|
133
161
|
if (cnameInfo) {
|
|
134
162
|
const instanceId = cnameInfo.dnsRecordId ?? bucket.website.domain;
|
|
135
163
|
const dnsInstance = {
|
|
@@ -139,6 +167,7 @@ const createBucketResource = async (context, bucket, state) => {
|
|
|
139
167
|
domain: bucket.website.domain,
|
|
140
168
|
cname: cnameInfo.cname,
|
|
141
169
|
...(cnameInfo.dnsRecordId ? { dnsRecordId: cnameInfo.dnsRecordId } : {}),
|
|
170
|
+
...(cnameInfo.txtRecordId ? { txtRecordId: cnameInfo.txtRecordId } : {}),
|
|
142
171
|
};
|
|
143
172
|
instances.push(dnsInstance);
|
|
144
173
|
// Refresh bucket info to capture auto-added CORS rule
|
|
@@ -205,13 +234,22 @@ const updateBucketResource = async (context, bucket, state) => {
|
|
|
205
234
|
if (bucket.website?.domain) {
|
|
206
235
|
const domainChanged = existingDnsInstance?.domain !== bucket.website.domain;
|
|
207
236
|
if (domainChanged && existingDnsInstance) {
|
|
208
|
-
await client.oss.unbindCustomDomain(config.bucketName, existingDnsInstance.domain, existingDnsInstance.dnsRecordId);
|
|
237
|
+
await client.oss.unbindCustomDomain(config.bucketName, existingDnsInstance.domain, existingDnsInstance.dnsRecordId, existingDnsInstance.txtRecordId);
|
|
209
238
|
}
|
|
239
|
+
const certificate = bucket.website.domain_certificate
|
|
240
|
+
? await resolveBucketDomainCertificate(bucket.website.domain_certificate, context, client)
|
|
241
|
+
: undefined;
|
|
210
242
|
logger_1.logger.info(lang_1.lang.__('BINDING_CUSTOM_DOMAIN_TO_BUCKET', {
|
|
211
243
|
domain: bucket.website.domain,
|
|
212
244
|
bucketName: config.bucketName,
|
|
213
245
|
}));
|
|
214
|
-
|
|
246
|
+
if (certificate) {
|
|
247
|
+
logger_1.logger.info(lang_1.lang.__('OSS_BUCKET_CERT_BINDING', {
|
|
248
|
+
domain: bucket.website.domain,
|
|
249
|
+
bucketName: config.bucketName,
|
|
250
|
+
}));
|
|
251
|
+
}
|
|
252
|
+
const cnameInfo = await client.oss.bindCustomDomain(config.bucketName, bucket.website.domain, certificate);
|
|
215
253
|
if (cnameInfo) {
|
|
216
254
|
const instanceId = cnameInfo.dnsRecordId ?? bucket.website.domain;
|
|
217
255
|
const dnsInstance = {
|
|
@@ -221,6 +259,7 @@ const updateBucketResource = async (context, bucket, state) => {
|
|
|
221
259
|
domain: bucket.website.domain,
|
|
222
260
|
cname: cnameInfo.cname,
|
|
223
261
|
...(cnameInfo.dnsRecordId ? { dnsRecordId: cnameInfo.dnsRecordId } : {}),
|
|
262
|
+
...(cnameInfo.txtRecordId ? { txtRecordId: cnameInfo.txtRecordId } : {}),
|
|
224
263
|
};
|
|
225
264
|
instances.push(dnsInstance);
|
|
226
265
|
// Refresh bucket info to capture auto-added CORS rule
|
|
@@ -231,7 +270,7 @@ const updateBucketResource = async (context, bucket, state) => {
|
|
|
231
270
|
}
|
|
232
271
|
}
|
|
233
272
|
else if (existingDnsInstance) {
|
|
234
|
-
await client.oss.unbindCustomDomain(config.bucketName, existingDnsInstance.domain, existingDnsInstance.dnsRecordId);
|
|
273
|
+
await client.oss.unbindCustomDomain(config.bucketName, existingDnsInstance.domain, existingDnsInstance.dnsRecordId, existingDnsInstance.txtRecordId);
|
|
235
274
|
}
|
|
236
275
|
const resourceState = {
|
|
237
276
|
mode: 'managed',
|
|
@@ -248,7 +287,7 @@ const deleteBucketResource = async (context, bucketName, logicalId, state) => {
|
|
|
248
287
|
const existingState = state.resources[logicalId];
|
|
249
288
|
const dnsInstance = existingState?.instances?.find((i) => i.type === types_1.ResourceTypeEnum.ALIYUN_OSS_DNS_CNAME);
|
|
250
289
|
if (dnsInstance) {
|
|
251
|
-
await client.oss.unbindCustomDomain(bucketName, dnsInstance.domain, dnsInstance.dnsRecordId);
|
|
290
|
+
await client.oss.unbindCustomDomain(bucketName, dnsInstance.domain, dnsInstance.dnsRecordId, dnsInstance.txtRecordId);
|
|
252
291
|
}
|
|
253
292
|
try {
|
|
254
293
|
await client.oss.deleteBucket(bucketName);
|
|
@@ -63,7 +63,7 @@ const servEvent = async (req, parsed, iac) => {
|
|
|
63
63
|
}
|
|
64
64
|
if (matchedTrigger.backend) {
|
|
65
65
|
const backendDef = (0, common_1.getIacDefinition)(iac, matchedTrigger.backend);
|
|
66
|
-
if (!backendDef) {
|
|
66
|
+
if (!backendDef || !(0, common_1.isFunctionDomain)(backendDef)) {
|
|
67
67
|
const endTime = new Date();
|
|
68
68
|
if (isAliyun) {
|
|
69
69
|
(0, aliyunFc_1.logApiGatewayRequest)(requestId, parsed.url, 500, startTime, endTime, sourceIp);
|
|
@@ -4,10 +4,29 @@ exports.deleteBucketResource = exports.updateBucketResource = exports.readBucket
|
|
|
4
4
|
const types_1 = require("../../types");
|
|
5
5
|
const tencentClient_1 = require("../../common/tencentClient");
|
|
6
6
|
const cosTypes_1 = require("./cosTypes");
|
|
7
|
-
const stateManager_1 = require("../../common/stateManager");
|
|
8
7
|
const common_1 = require("../../common");
|
|
8
|
+
const certificateResolver_1 = require("../../common/certificateResolver");
|
|
9
9
|
const logger_1 = require("../../common/logger");
|
|
10
10
|
const lang_1 = require("../../lang");
|
|
11
|
+
const resolveBucketDomainCertificate = (domainCertificate, context) => {
|
|
12
|
+
if (!context.iac) {
|
|
13
|
+
throw new Error(lang_1.lang.__('CERT_REFERENCE_NOT_FOUND', { reference: domainCertificate }));
|
|
14
|
+
}
|
|
15
|
+
const certDef = (0, common_1.getIacDefinition)(context.iac, domainCertificate);
|
|
16
|
+
if (!certDef || !(0, common_1.isCertificateDomain)(certDef)) {
|
|
17
|
+
throw new Error(lang_1.lang.__('CERT_REFERENCE_NOT_FOUND', { reference: domainCertificate }));
|
|
18
|
+
}
|
|
19
|
+
if (certDef.certificate_id) {
|
|
20
|
+
throw new Error(lang_1.lang.__('TENCENT_CERT_REFERENCE_NOT_SUPPORTED', { name: certDef.key }));
|
|
21
|
+
}
|
|
22
|
+
return (0, certificateResolver_1.resolveUploadCertificate)(certDef);
|
|
23
|
+
};
|
|
24
|
+
const deployCertificateToCosDomain = async (client, resolved, bucketName, domain, region) => {
|
|
25
|
+
logger_1.logger.info(lang_1.lang.__('COS_BUCKET_CERT_DEPLOYING', { domain, bucketName }));
|
|
26
|
+
const certInfo = await client.ssl.uploadCertificate(resolved.certificateName, resolved.certificateBody, resolved.certificatePrivateKey);
|
|
27
|
+
const instanceId = `${region}|${bucketName}|${domain}`;
|
|
28
|
+
await client.ssl.deployCertificateInstance(certInfo.certificateId, 'cos', [instanceId]);
|
|
29
|
+
};
|
|
11
30
|
const buildCosInstanceFromProvider = (info, sid) => {
|
|
12
31
|
return {
|
|
13
32
|
sid,
|
|
@@ -82,6 +101,9 @@ const createBucketResource = async (context, bucket, state) => {
|
|
|
82
101
|
];
|
|
83
102
|
let cnameInfo;
|
|
84
103
|
if (bucket.website?.domain) {
|
|
104
|
+
const resolved = bucket.website.domain_certificate
|
|
105
|
+
? resolveBucketDomainCertificate(bucket.website.domain_certificate, context)
|
|
106
|
+
: undefined;
|
|
85
107
|
logger_1.logger.info(lang_1.lang.__('BINDING_CUSTOM_DOMAIN_TO_BUCKET', {
|
|
86
108
|
domain: bucket.website.domain,
|
|
87
109
|
bucketName: bucket.name,
|
|
@@ -103,6 +125,9 @@ const createBucketResource = async (context, bucket, state) => {
|
|
|
103
125
|
if (refreshedInfo) {
|
|
104
126
|
instances[0] = buildCosInstanceFromProvider(refreshedInfo, sid);
|
|
105
127
|
}
|
|
128
|
+
if (resolved && cnameInfo.bucketDomainBound) {
|
|
129
|
+
await deployCertificateToCosDomain(client, resolved, bucket.name, bucket.website.domain, context.region);
|
|
130
|
+
}
|
|
106
131
|
}
|
|
107
132
|
}
|
|
108
133
|
const resourceState = {
|
|
@@ -112,7 +137,7 @@ const createBucketResource = async (context, bucket, state) => {
|
|
|
112
137
|
instances,
|
|
113
138
|
lastUpdated: new Date().toISOString(),
|
|
114
139
|
};
|
|
115
|
-
return (0,
|
|
140
|
+
return (0, common_1.setResource)(state, logicalId, resourceState);
|
|
116
141
|
};
|
|
117
142
|
exports.createBucketResource = createBucketResource;
|
|
118
143
|
const readBucketResource = async (context, bucketName, region) => {
|
|
@@ -146,6 +171,9 @@ const updateBucketResource = async (context, bucket, state) => {
|
|
|
146
171
|
if (domainChanged && existingDnsInstance) {
|
|
147
172
|
await client.cos.unbindCustomDomain(bucket.name, existingDnsInstance.domain, existingDnsInstance.dnsRecordId);
|
|
148
173
|
}
|
|
174
|
+
const resolved = bucket.website.domain_certificate
|
|
175
|
+
? resolveBucketDomainCertificate(bucket.website.domain_certificate, context)
|
|
176
|
+
: undefined;
|
|
149
177
|
logger_1.logger.info(lang_1.lang.__('BINDING_CUSTOM_DOMAIN_TO_BUCKET', {
|
|
150
178
|
domain: bucket.website.domain,
|
|
151
179
|
bucketName: bucket.name,
|
|
@@ -167,6 +195,9 @@ const updateBucketResource = async (context, bucket, state) => {
|
|
|
167
195
|
if (refreshedInfo) {
|
|
168
196
|
instances[0] = buildCosInstanceFromProvider(refreshedInfo, sid);
|
|
169
197
|
}
|
|
198
|
+
if (resolved && cnameInfo.bucketDomainBound) {
|
|
199
|
+
await deployCertificateToCosDomain(client, resolved, bucket.name, bucket.website.domain, context.region);
|
|
200
|
+
}
|
|
170
201
|
}
|
|
171
202
|
}
|
|
172
203
|
else if (existingDnsInstance) {
|
|
@@ -179,7 +210,7 @@ const updateBucketResource = async (context, bucket, state) => {
|
|
|
179
210
|
instances,
|
|
180
211
|
lastUpdated: new Date().toISOString(),
|
|
181
212
|
};
|
|
182
|
-
return (0,
|
|
213
|
+
return (0, common_1.setResource)(state, logicalId, resourceState);
|
|
183
214
|
};
|
|
184
215
|
exports.updateBucketResource = updateBucketResource;
|
|
185
216
|
const deleteBucketResource = async (context, bucketName, region, logicalId, state) => {
|
|
@@ -202,6 +233,6 @@ const deleteBucketResource = async (context, bucketName, region, logicalId, stat
|
|
|
202
233
|
throw err;
|
|
203
234
|
}
|
|
204
235
|
}
|
|
205
|
-
return (0,
|
|
236
|
+
return (0, common_1.removeResource)(state, logicalId);
|
|
206
237
|
};
|
|
207
238
|
exports.deleteBucketResource = deleteBucketResource;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.displayPlan = exports.generateTencentPlan = void 0;
|
|
4
4
|
const common_1 = require("../../common");
|
|
5
|
+
Object.defineProperty(exports, "displayPlan", { enumerable: true, get: function () { return common_1.displayPlan; } });
|
|
5
6
|
const lang_1 = require("../../lang");
|
|
6
7
|
const scfPlanner_1 = require("./scfPlanner");
|
|
7
8
|
const cosPlanner_1 = require("./cosPlanner");
|
|
@@ -32,60 +33,3 @@ const generateTencentPlan = async (iac, backend) => {
|
|
|
32
33
|
};
|
|
33
34
|
};
|
|
34
35
|
exports.generateTencentPlan = generateTencentPlan;
|
|
35
|
-
const displayPlan = (planResult) => {
|
|
36
|
-
const separator = '========================================';
|
|
37
|
-
if (planResult.items.length === 0) {
|
|
38
|
-
common_1.logger.info(`${separator}\n${lang_1.lang.__('DEPLOYMENT_PLAN')}\n${separator}\n${lang_1.lang.__('NO_CHANGES_INFRASTRUCTURE_UP_TO_DATE')}`);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const createActions = planResult.items.filter((item) => item.action === 'create');
|
|
42
|
-
const updateActions = planResult.items.filter((item) => item.action === 'update');
|
|
43
|
-
const deleteActions = planResult.items.filter((item) => item.action === 'delete');
|
|
44
|
-
const noopActions = planResult.items.filter((item) => item.action === 'noop');
|
|
45
|
-
const sections = [];
|
|
46
|
-
if (createActions.length > 0) {
|
|
47
|
-
const createLines = [`[${lang_1.lang.__('CREATE')}]:`];
|
|
48
|
-
for (const item of createActions) {
|
|
49
|
-
createLines.push(` + ${item.logicalId} (${item.resourceType})`);
|
|
50
|
-
if (item.changes?.after) {
|
|
51
|
-
const jsonStr = JSON.stringify(item.changes.after, null, 2);
|
|
52
|
-
createLines.push(` ${jsonStr.split('\n').join('\n ')}`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
sections.push(createLines.join('\n'));
|
|
56
|
-
}
|
|
57
|
-
if (updateActions.length > 0) {
|
|
58
|
-
const updateLines = [`[${lang_1.lang.__('UPDATE')}]:`];
|
|
59
|
-
for (const item of updateActions) {
|
|
60
|
-
updateLines.push(` ~ ${item.logicalId} (${item.resourceType})`);
|
|
61
|
-
if (item.drifted) {
|
|
62
|
-
updateLines.push(` [${lang_1.lang.__('DRIFTED')}] ${lang_1.lang.__('REMOTE_CONFIG_DIFFERS')}`);
|
|
63
|
-
}
|
|
64
|
-
if (item.changes) {
|
|
65
|
-
const jsonStr = JSON.stringify(item.changes, null, 2);
|
|
66
|
-
updateLines.push(` ${lang_1.lang.__('CHANGES')}: ${jsonStr.split('\n').join('\n ')}`);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
sections.push(updateLines.join('\n'));
|
|
70
|
-
}
|
|
71
|
-
if (deleteActions.length > 0) {
|
|
72
|
-
const deleteLines = [`[${lang_1.lang.__('DELETE')}]:`];
|
|
73
|
-
for (const item of deleteActions) {
|
|
74
|
-
deleteLines.push(` - ${item.logicalId} (${item.resourceType})`);
|
|
75
|
-
if (item.changes?.before) {
|
|
76
|
-
const jsonStr = JSON.stringify(item.changes.before, null, 2);
|
|
77
|
-
deleteLines.push(` ${jsonStr.split('\n').join('\n ')}`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
sections.push(deleteLines.join('\n'));
|
|
81
|
-
}
|
|
82
|
-
if (noopActions.length > 0) {
|
|
83
|
-
const noopLines = [`[${lang_1.lang.__('NO_CHANGE')}]:`];
|
|
84
|
-
for (const item of noopActions) {
|
|
85
|
-
noopLines.push(` = ${item.logicalId} (${item.resourceType})`);
|
|
86
|
-
}
|
|
87
|
-
sections.push(noopLines.join('\n'));
|
|
88
|
-
}
|
|
89
|
-
common_1.logger.info(`\n${separator}\n${lang_1.lang.__('DEPLOYMENT_PLAN')}\n${separator}\n${sections.join('\n\n')}\n\n${separator}\n${lang_1.lang.__('PLAN')}: ${createActions.length} ${lang_1.lang.__('TO_CREATE')}, ${updateActions.length} ${lang_1.lang.__('TO_UPDATE')}, ${deleteActions.length} ${lang_1.lang.__('TO_DELETE')}, ${noopActions.length} ${lang_1.lang.__('UNCHANGED')}\n${separator}`);
|
|
90
|
-
};
|
|
91
|
-
exports.displayPlan = displayPlan;
|
package/dist/src/types/index.js
CHANGED
|
@@ -26,4 +26,5 @@ __exportStar(require("./domains/table"), exports);
|
|
|
26
26
|
__exportStar(require("./domains/state"), exports);
|
|
27
27
|
__exportStar(require("./domains/lock"), exports);
|
|
28
28
|
__exportStar(require("./domains/backend"), exports);
|
|
29
|
+
__exportStar(require("./domains/certificate"), exports);
|
|
29
30
|
__exportStar(require("./assets"), exports);
|
|
@@ -53,7 +53,29 @@ exports.bucketSchema = {
|
|
|
53
53
|
type: 'string',
|
|
54
54
|
},
|
|
55
55
|
domain: {
|
|
56
|
-
|
|
56
|
+
oneOf: [
|
|
57
|
+
{ type: 'string' },
|
|
58
|
+
{
|
|
59
|
+
type: 'object',
|
|
60
|
+
properties: {
|
|
61
|
+
domain_name: { type: 'string' },
|
|
62
|
+
certificate: { type: 'string' },
|
|
63
|
+
protocol: {
|
|
64
|
+
oneOf: [
|
|
65
|
+
{ type: 'string', enum: ['HTTP', 'HTTPS'] },
|
|
66
|
+
{
|
|
67
|
+
type: 'array',
|
|
68
|
+
items: { type: 'string', enum: ['HTTP', 'HTTPS'] },
|
|
69
|
+
minItems: 1,
|
|
70
|
+
uniqueItems: true,
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
required: ['domain_name'],
|
|
76
|
+
additionalProperties: false,
|
|
77
|
+
},
|
|
78
|
+
],
|
|
57
79
|
},
|
|
58
80
|
index: {
|
|
59
81
|
type: 'string',
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.certificateSchema = void 0;
|
|
4
|
+
exports.certificateSchema = {
|
|
5
|
+
$id: 'https://serverlessinsight.geekfun.club/schemas/certificateschema.json',
|
|
6
|
+
type: 'object',
|
|
7
|
+
patternProperties: {
|
|
8
|
+
'.*': {
|
|
9
|
+
type: 'object',
|
|
10
|
+
properties: {
|
|
11
|
+
certificate_body: { type: 'string' },
|
|
12
|
+
private_key: { type: 'string' },
|
|
13
|
+
chain: { type: 'string' },
|
|
14
|
+
certificate_id: { type: 'string' },
|
|
15
|
+
},
|
|
16
|
+
oneOf: [
|
|
17
|
+
{
|
|
18
|
+
required: ['certificate_body', 'private_key'],
|
|
19
|
+
not: { required: ['certificate_id'] },
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
required: ['certificate_id'],
|
|
23
|
+
not: {
|
|
24
|
+
anyOf: [{ required: ['certificate_body'] }, { required: ['private_key'] }],
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
additionalProperties: false,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
@@ -29,6 +29,18 @@ exports.eventSchema = {
|
|
|
29
29
|
certificate_name: { type: 'string' },
|
|
30
30
|
certificate_body: { type: 'string' },
|
|
31
31
|
certificate_private_key: { type: 'string' },
|
|
32
|
+
certificate: { type: 'string' },
|
|
33
|
+
protocol: {
|
|
34
|
+
oneOf: [
|
|
35
|
+
{ type: 'string', enum: ['HTTP', 'HTTPS'] },
|
|
36
|
+
{
|
|
37
|
+
type: 'array',
|
|
38
|
+
items: { type: 'string', enum: ['HTTP', 'HTTPS'] },
|
|
39
|
+
minItems: 1,
|
|
40
|
+
uniqueItems: true,
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
32
44
|
},
|
|
33
45
|
},
|
|
34
46
|
},
|
|
@@ -12,6 +12,7 @@ const eventSchema_1 = require("./eventSchema");
|
|
|
12
12
|
const functionSchema_1 = require("./functionSchema");
|
|
13
13
|
const bucketSchema_1 = require("./bucketSchema");
|
|
14
14
|
const tableschema_1 = require("./tableschema");
|
|
15
|
+
const certificateSchema_1 = require("./certificateSchema");
|
|
15
16
|
const lang_1 = require("../lang");
|
|
16
17
|
class IacSchemaErrors extends Error {
|
|
17
18
|
constructor(errors) {
|
|
@@ -50,6 +51,7 @@ const validate = ajv
|
|
|
50
51
|
.addSchema(databaseSchema_1.databaseSchema)
|
|
51
52
|
.addSchema(tableschema_1.tableSchema)
|
|
52
53
|
.addSchema(bucketSchema_1.bucketSchema)
|
|
54
|
+
.addSchema(certificateSchema_1.certificateSchema)
|
|
53
55
|
.compile(rootSchema_1.rootSchema);
|
|
54
56
|
const validateRuntimeCompatibility = (iacJson) => {
|
|
55
57
|
if (!iacJson.functions) {
|
|
@@ -99,6 +99,9 @@ exports.rootSchema = {
|
|
|
99
99
|
tables: {
|
|
100
100
|
$ref: 'https://serverlessinsight.geekfun.club/schemas/tableschema.json',
|
|
101
101
|
},
|
|
102
|
+
certificates: {
|
|
103
|
+
$ref: 'https://serverlessinsight.geekfun.club/schemas/certificateschema.json',
|
|
104
|
+
},
|
|
102
105
|
backend: {
|
|
103
106
|
type: 'object',
|
|
104
107
|
properties: {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolvableEnum = exports.resolvableBoolean = exports.resolvableInteger = exports.resolvableNumber = void 0;
|
|
4
|
-
// Template reference pattern that matches ${vars.xxx}, ${stages.xxx}, ${ctx.xxx}, ${functions.xxx}
|
|
5
|
-
// Note: ${functions.xxx} references are kept as strings and resolved by the deployment engine
|
|
4
|
+
// Template reference pattern that matches ${vars.xxx}, ${stages.xxx}, ${ctx.xxx}, ${functions.xxx}, ${certificates.xxx}
|
|
5
|
+
// Note: ${functions.xxx} and ${certificates.xxx} references are kept as strings and resolved by the deployment engine
|
|
6
6
|
// Only ${vars.xxx}, ${stages.xxx}, and ${ctx.xxx} are resolved at parse time
|
|
7
|
-
const templateRefPattern = '^\\$\\{(vars|stages|ctx|functions)\\.[\\w.]+\\}$';
|
|
7
|
+
const templateRefPattern = '^\\$\\{(vars|stages|ctx|functions|certificates)\\.[\\w.]+\\}$';
|
|
8
8
|
// Schema definition for a template reference string
|
|
9
9
|
const templateRefSchema = {
|
|
10
10
|
type: 'string',
|