@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
|
@@ -6,9 +6,36 @@ 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 retryUtils_1 = require("../retryUtils");
|
|
14
|
+
const constants_1 = require("../constants");
|
|
15
|
+
const ossRequest = (ossClient, params) => {
|
|
16
|
+
return ossClient.request(params);
|
|
17
|
+
};
|
|
18
|
+
const escapeXmlText = (text) => text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
|
19
|
+
const toCamelCase = (str) => str.charAt(0).toLowerCase() + str.slice(1);
|
|
20
|
+
const parseXmlResponse = (xml, tagName) => {
|
|
21
|
+
try {
|
|
22
|
+
const containerRegex = new RegExp(`<${tagName}>([\\s\\S]*?)<\\/${tagName}>`);
|
|
23
|
+
const containerMatch = containerRegex.exec(xml);
|
|
24
|
+
if (!containerMatch)
|
|
25
|
+
return null;
|
|
26
|
+
const innerXml = containerMatch[1];
|
|
27
|
+
const result = {};
|
|
28
|
+
const childRegex = /<(\w+)>([^<]*)<\/\1>/g;
|
|
29
|
+
let match;
|
|
30
|
+
while ((match = childRegex.exec(innerXml)) !== null) {
|
|
31
|
+
result[toCamelCase(match[1])] = match[2].trim();
|
|
32
|
+
}
|
|
33
|
+
return Object.keys(result).length > 0 ? result : null;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
12
39
|
const createOssOperations = (ossClient, region, dnsOps) => {
|
|
13
40
|
const useBucket = (bucketName) => {
|
|
14
41
|
ossClient.useBucket(bucketName);
|
|
@@ -16,12 +43,54 @@ const createOssOperations = (ossClient, region, dnsOps) => {
|
|
|
16
43
|
const getOssEndpoint = (bucketName) => {
|
|
17
44
|
return `${bucketName}.oss-${region}.aliyuncs.com`;
|
|
18
45
|
};
|
|
19
|
-
const
|
|
46
|
+
const buildCertificateXml = (cert) => {
|
|
47
|
+
if (!cert)
|
|
48
|
+
return '';
|
|
49
|
+
return `
|
|
50
|
+
<CertificateConfiguration>
|
|
51
|
+
<Certificate>${escapeXmlText(cert.certificateBody)}</Certificate>
|
|
52
|
+
<PrivateKey>${escapeXmlText(cert.certificatePrivateKey)}</PrivateKey>
|
|
53
|
+
<Force>true</Force>
|
|
54
|
+
</CertificateConfiguration>`;
|
|
55
|
+
};
|
|
56
|
+
const createCnameToken = async (bucketName, domain) => {
|
|
20
57
|
useBucket(bucketName);
|
|
21
58
|
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
22
59
|
<BucketCnameConfiguration>
|
|
23
60
|
<Cname>
|
|
24
|
-
<Domain>${domain}</Domain>
|
|
61
|
+
<Domain>${escapeXmlText(domain)}</Domain>
|
|
62
|
+
</Cname>
|
|
63
|
+
</BucketCnameConfiguration>`;
|
|
64
|
+
const params = {
|
|
65
|
+
method: 'POST',
|
|
66
|
+
bucket: bucketName,
|
|
67
|
+
subres: { cname: '', comp: 'token' },
|
|
68
|
+
headers: {
|
|
69
|
+
'Content-Type': 'application/xml',
|
|
70
|
+
},
|
|
71
|
+
content: xml,
|
|
72
|
+
successStatuses: [200],
|
|
73
|
+
};
|
|
74
|
+
const response = await ossRequest(ossClient, params);
|
|
75
|
+
const responseXml = response.data || '';
|
|
76
|
+
const parsed = parseXmlResponse(responseXml, 'CnameToken');
|
|
77
|
+
if (!parsed || !parsed.token) {
|
|
78
|
+
throw new Error(lang_1.lang.__('OSS_CNAME_TOKEN_CREATE_FAILED', { domain }));
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
bucket: bucketName,
|
|
82
|
+
cname: domain,
|
|
83
|
+
token: parsed.token,
|
|
84
|
+
expireTime: parsed.expireTime || '',
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
const putBucketCname = async (bucketName, domain, certificate) => {
|
|
88
|
+
useBucket(bucketName);
|
|
89
|
+
const certXml = buildCertificateXml(certificate);
|
|
90
|
+
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
91
|
+
<BucketCnameConfiguration>
|
|
92
|
+
<Cname>
|
|
93
|
+
<Domain>${escapeXmlText(domain)}</Domain>${certXml}
|
|
25
94
|
</Cname>
|
|
26
95
|
</BucketCnameConfiguration>`;
|
|
27
96
|
try {
|
|
@@ -38,20 +107,24 @@ const createOssOperations = (ossClient, region, dnsOps) => {
|
|
|
38
107
|
};
|
|
39
108
|
await ossClient.request(params);
|
|
40
109
|
logger_1.logger.info(lang_1.lang.__('OSS_BUCKET_CNAME_BOUND', { domain }));
|
|
41
|
-
return true;
|
|
110
|
+
return { success: true, needVerification: false };
|
|
42
111
|
}
|
|
43
112
|
catch (error) {
|
|
44
113
|
const err = error;
|
|
45
114
|
if (err.code === 'CnameAlreadyExists' || err.status === 409) {
|
|
46
115
|
logger_1.logger.info(lang_1.lang.__('OSS_BUCKET_CNAME_EXISTS', { domain }));
|
|
47
|
-
return true;
|
|
116
|
+
return { success: true, needVerification: false };
|
|
48
117
|
}
|
|
49
118
|
if (err.code === 'NeedVerifyDomainOwnership') {
|
|
50
119
|
logger_1.logger.warn(lang_1.lang.__('OSS_BUCKET_CNAME_NEED_VERIFY', { domain }));
|
|
51
|
-
return false;
|
|
120
|
+
return { success: false, needVerification: true };
|
|
121
|
+
}
|
|
122
|
+
if (certificate) {
|
|
123
|
+
// eslint-disable-next-line preserve-caught-error
|
|
124
|
+
throw new Error(lang_1.lang.__('OSS_BUCKET_CNAME_BIND_FAILED', { error: String(error) }));
|
|
52
125
|
}
|
|
53
126
|
logger_1.logger.warn(lang_1.lang.__('OSS_BUCKET_CNAME_BIND_FAILED', { error: String(error) }));
|
|
54
|
-
return false;
|
|
127
|
+
return { success: false, needVerification: false };
|
|
55
128
|
}
|
|
56
129
|
};
|
|
57
130
|
const deleteBucketCname = async (bucketName, domain) => {
|
|
@@ -148,16 +221,170 @@ const createOssOperations = (ossClient, region, dnsOps) => {
|
|
|
148
221
|
logger_1.logger.warn(lang_1.lang.__('OSS_CORS_RULE_REMOVE_FAILED', { domain, error: String(error) }));
|
|
149
222
|
}
|
|
150
223
|
};
|
|
151
|
-
const bindCustomDomain = async (bucketName, domain) => {
|
|
224
|
+
const bindCustomDomain = async (bucketName, domain, certificate) => {
|
|
152
225
|
const mainDomain = (0, domainUtils_1.extractMainDomain)(domain);
|
|
153
226
|
const hostRecord = (0, domainUtils_1.extractHostRecord)(domain, mainDomain);
|
|
154
227
|
const ossEndpoint = getOssEndpoint(bucketName);
|
|
155
|
-
|
|
228
|
+
let cnameResult = await putBucketCname(bucketName, domain, certificate);
|
|
229
|
+
let txtRecordId;
|
|
230
|
+
if (cnameResult.needVerification) {
|
|
231
|
+
const verificationResult = await handleDomainOwnershipVerification(bucketName, domain, certificate);
|
|
232
|
+
cnameResult = verificationResult;
|
|
233
|
+
txtRecordId = verificationResult.txtRecordId;
|
|
234
|
+
}
|
|
235
|
+
const bucketCnameBound = cnameResult.success;
|
|
236
|
+
if (certificate && bucketCnameBound) {
|
|
237
|
+
logger_1.logger.info(lang_1.lang.__('OSS_BUCKET_CERT_BOUND', { domain }));
|
|
238
|
+
}
|
|
156
239
|
await addCorsRuleForDomain(bucketName, domain);
|
|
157
240
|
if (!dnsOps) {
|
|
158
241
|
logger_1.logger.warn(lang_1.lang.__('OSS_DNS_MANUAL_CONFIG_REQUIRED', { domain, cname: ossEndpoint }));
|
|
159
|
-
return { domain, cname: ossEndpoint, bucketCnameBound };
|
|
242
|
+
return { domain, cname: ossEndpoint, bucketCnameBound, txtRecordId };
|
|
160
243
|
}
|
|
244
|
+
const result = await createOrFindDnsCnameRecord(domain, mainDomain, hostRecord, ossEndpoint, bucketCnameBound);
|
|
245
|
+
return { ...result, txtRecordId };
|
|
246
|
+
};
|
|
247
|
+
const logOssVerificationInstructions = (domain, fullTxtRecord, token) => {
|
|
248
|
+
const mainDomain = (0, domainUtils_1.extractMainDomain)(domain);
|
|
249
|
+
const separator = '='.repeat(80);
|
|
250
|
+
logger_1.logger.error(`\n${separator}\n${lang_1.lang.__('OSS_VERIFICATION_HEADER')}\n${separator}\n${lang_1.lang.__('OSS_VERIFICATION_DOMAIN', { domain })}\n\n${lang_1.lang.__('OSS_VERIFICATION_INSTRUCTIONS')}\n\n${lang_1.lang.__('OSS_VERIFICATION_RECORD_NAME', { name: `${fullTxtRecord}.${mainDomain}` })}\n${lang_1.lang.__('OSS_VERIFICATION_RECORD_TYPE')}\n${lang_1.lang.__('OSS_VERIFICATION_RECORD_VALUE', { value: token })}`);
|
|
251
|
+
logger_1.logger.error(`\n${separator}\n${lang_1.lang.__('OSS_VERIFICATION_NEXT_STEPS')}\n${lang_1.lang.__('OSS_VERIFICATION_STEP1')}\n${lang_1.lang.__('OSS_VERIFICATION_STEP2')}\n${separator}\n`);
|
|
252
|
+
};
|
|
253
|
+
const handleDomainOwnershipVerification = async (bucketName, domain, certificate) => {
|
|
254
|
+
logger_1.logger.info(lang_1.lang.__('OSS_CNAME_CREATING_VERIFICATION_TOKEN', { domain }));
|
|
255
|
+
const tokenInfo = await createCnameToken(bucketName, domain);
|
|
256
|
+
const txtRecordName = '_dnsauth';
|
|
257
|
+
const hostRecord = (0, domainUtils_1.extractHostRecord)(domain, (0, domainUtils_1.extractMainDomain)(domain));
|
|
258
|
+
const fullTxtRecord = hostRecord ? `${txtRecordName}.${hostRecord}` : txtRecordName;
|
|
259
|
+
logger_1.logger.info(lang_1.lang.__('OSS_CNAME_VERIFICATION_TOKEN_CREATED', {
|
|
260
|
+
domain,
|
|
261
|
+
txtRecord: fullTxtRecord,
|
|
262
|
+
token: tokenInfo.token,
|
|
263
|
+
}));
|
|
264
|
+
const txtResult = await addVerificationTxtRecord((0, domainUtils_1.extractMainDomain)(domain), fullTxtRecord, tokenInfo.token);
|
|
265
|
+
if (txtResult.success) {
|
|
266
|
+
await pollTxtDnsPropagation((0, domainUtils_1.extractMainDomain)(domain), fullTxtRecord, tokenInfo.token);
|
|
267
|
+
const retryResult = await retryCnameBindingAfterVerification(bucketName, domain, certificate);
|
|
268
|
+
return { ...retryResult, txtRecordId: txtResult.recordId };
|
|
269
|
+
}
|
|
270
|
+
logOssVerificationInstructions(domain, fullTxtRecord, tokenInfo.token);
|
|
271
|
+
throw new Error(lang_1.lang.__('OSS_CNAME_MANUAL_VERIFICATION_REQUIRED', {
|
|
272
|
+
domain,
|
|
273
|
+
txtRecord: `${fullTxtRecord}.${(0, domainUtils_1.extractMainDomain)(domain)}`,
|
|
274
|
+
token: tokenInfo.token,
|
|
275
|
+
}));
|
|
276
|
+
};
|
|
277
|
+
const addVerificationTxtRecord = async (mainDomain, fullTxtRecord, token) => {
|
|
278
|
+
if (!dnsOps)
|
|
279
|
+
return { success: false };
|
|
280
|
+
try {
|
|
281
|
+
const existingRecords = await dnsOps.describeDomainRecords(mainDomain, fullTxtRecord);
|
|
282
|
+
const existingRecord = existingRecords.find((record) => record.rr === fullTxtRecord && record.type === 'TXT' && record.value === token);
|
|
283
|
+
if (existingRecord) {
|
|
284
|
+
logger_1.logger.info(lang_1.lang.__('OSS_CNAME_TXT_RECORD_ALREADY_EXISTS', {
|
|
285
|
+
txtRecord: `${fullTxtRecord}.${mainDomain}`,
|
|
286
|
+
}));
|
|
287
|
+
return { success: true, recordId: existingRecord.recordId };
|
|
288
|
+
}
|
|
289
|
+
const recordId = await dnsOps.addDomainRecord({
|
|
290
|
+
domainName: mainDomain,
|
|
291
|
+
rr: fullTxtRecord,
|
|
292
|
+
type: 'TXT',
|
|
293
|
+
value: token,
|
|
294
|
+
ttl: 600,
|
|
295
|
+
});
|
|
296
|
+
logger_1.logger.info(lang_1.lang.__('OSS_CNAME_TXT_RECORD_CREATED', {
|
|
297
|
+
txtRecord: `${fullTxtRecord}.${mainDomain}`,
|
|
298
|
+
}));
|
|
299
|
+
return { success: true, recordId };
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
logger_1.logger.warn(lang_1.lang.__('OSS_CNAME_TXT_RECORD_CREATE_FAILED', {
|
|
303
|
+
txtRecord: `${fullTxtRecord}.${mainDomain}`,
|
|
304
|
+
error: String(error),
|
|
305
|
+
}));
|
|
306
|
+
return { success: false };
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
const pollTxtDnsPropagation = async (mainDomain, fullTxtRecord, token) => {
|
|
310
|
+
if (!dnsOps)
|
|
311
|
+
return false;
|
|
312
|
+
const checkPropagation = async () => {
|
|
313
|
+
try {
|
|
314
|
+
const currentRecords = await dnsOps.describeDomainRecords(mainDomain, fullTxtRecord);
|
|
315
|
+
return currentRecords.some((record) => record.rr === fullTxtRecord &&
|
|
316
|
+
record.type === 'TXT' &&
|
|
317
|
+
record.value === token &&
|
|
318
|
+
record.status === 'ENABLE');
|
|
319
|
+
}
|
|
320
|
+
catch (checkError) {
|
|
321
|
+
logger_1.logger.warn(lang_1.lang.__('OSS_CNAME_DNS_CHECK_FAILED', { error: String(checkError) }));
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
logger_1.logger.info(lang_1.lang.__('OSS_CNAME_DNS_PROPAGATION_WAITING', { domain: mainDomain }));
|
|
326
|
+
for (let attempt = 1; attempt <= constants_1.DNS_PROPAGATION_MAX_ATTEMPTS; attempt++) {
|
|
327
|
+
logger_1.logger.info(lang_1.lang.__('OSS_CNAME_DNS_PROPAGATION_CHECK', {
|
|
328
|
+
attempt: String(attempt),
|
|
329
|
+
max: String(constants_1.DNS_PROPAGATION_MAX_ATTEMPTS),
|
|
330
|
+
}));
|
|
331
|
+
await (0, retryUtils_1.sleep)(constants_1.DNS_PROPAGATION_DELAY_MS);
|
|
332
|
+
const propagated = await checkPropagation();
|
|
333
|
+
if (propagated) {
|
|
334
|
+
logger_1.logger.info(lang_1.lang.__('OSS_CNAME_DNS_PROPAGATION_VERIFIED', {
|
|
335
|
+
domain: mainDomain,
|
|
336
|
+
minutes: String(attempt),
|
|
337
|
+
}));
|
|
338
|
+
return true;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
logger_1.logger.warn(lang_1.lang.__('OSS_CNAME_DNS_PROPAGATION_TIMEOUT', {
|
|
342
|
+
max: String(constants_1.DNS_PROPAGATION_MAX_ATTEMPTS),
|
|
343
|
+
}));
|
|
344
|
+
return false;
|
|
345
|
+
};
|
|
346
|
+
const retryCnameBindingAfterVerification = async (bucketName, domain, certificate) => {
|
|
347
|
+
logger_1.logger.info(lang_1.lang.__('OSS_CNAME_WAITING_FOR_VERIFICATION', { domain }));
|
|
348
|
+
for (let attempt = 1; attempt <= constants_1.DOMAIN_BIND_MAX_RETRIES; attempt++) {
|
|
349
|
+
if (attempt > 1) {
|
|
350
|
+
logger_1.logger.info(lang_1.lang.__('RETRY_ATTEMPT', {
|
|
351
|
+
operation: 'domain binding',
|
|
352
|
+
attempt: String(attempt),
|
|
353
|
+
max: String(constants_1.DOMAIN_BIND_MAX_RETRIES),
|
|
354
|
+
}));
|
|
355
|
+
}
|
|
356
|
+
await (0, retryUtils_1.sleep)(constants_1.DOMAIN_BIND_RETRY_DELAY_MS);
|
|
357
|
+
try {
|
|
358
|
+
const cnameResult = await putBucketCname(bucketName, domain, certificate);
|
|
359
|
+
if (cnameResult.success) {
|
|
360
|
+
return cnameResult;
|
|
361
|
+
}
|
|
362
|
+
if (!cnameResult.needVerification) {
|
|
363
|
+
return cnameResult;
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
catch (error) {
|
|
367
|
+
if (attempt === constants_1.DOMAIN_BIND_MAX_RETRIES) {
|
|
368
|
+
throw error;
|
|
369
|
+
}
|
|
370
|
+
logger_1.logger.warn(lang_1.lang.__('RETRY_ATTEMPT_FAILED', {
|
|
371
|
+
operation: 'domain binding',
|
|
372
|
+
attempt: String(attempt),
|
|
373
|
+
max: String(constants_1.DOMAIN_BIND_MAX_RETRIES),
|
|
374
|
+
error: String(error),
|
|
375
|
+
}));
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
const hostRecord = (0, domainUtils_1.extractHostRecord)(domain, (0, domainUtils_1.extractMainDomain)(domain));
|
|
379
|
+
const txtRecordName = '_dnsauth';
|
|
380
|
+
const fullTxtRecord = hostRecord ? `${txtRecordName}.${hostRecord}` : txtRecordName;
|
|
381
|
+
logger_1.logger.warn(lang_1.lang.__('OSS_CNAME_VERIFICATION_RETRY_FAILED', {
|
|
382
|
+
domain,
|
|
383
|
+
txtRecord: `${fullTxtRecord}.${(0, domainUtils_1.extractMainDomain)(domain)}`,
|
|
384
|
+
}));
|
|
385
|
+
return { success: false, needVerification: true };
|
|
386
|
+
};
|
|
387
|
+
const createOrFindDnsCnameRecord = async (domain, mainDomain, hostRecord, ossEndpoint, bucketCnameBound) => {
|
|
161
388
|
try {
|
|
162
389
|
const existingRecords = await dnsOps.describeDomainRecords(mainDomain, hostRecord);
|
|
163
390
|
const existingRecord = existingRecords.find((record) => record.rr === hostRecord && record.type === 'CNAME' && record.value === ossEndpoint);
|
|
@@ -186,18 +413,56 @@ const createOssOperations = (ossClient, region, dnsOps) => {
|
|
|
186
413
|
return { domain, cname: ossEndpoint, bucketCnameBound };
|
|
187
414
|
}
|
|
188
415
|
};
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
416
|
+
const isPublicAcl = (acl) => acl === bucketTypes_1.BucketACL.PUBLIC_READ || acl === bucketTypes_1.BucketACL.PUBLIC_READ_WRITE;
|
|
417
|
+
const disableBucketPublicAccessBlock = async (bucketName) => {
|
|
418
|
+
useBucket(bucketName);
|
|
419
|
+
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
420
|
+
<PublicAccessBlockConfiguration>
|
|
421
|
+
<BlockPublicAccess>false</BlockPublicAccess>
|
|
422
|
+
</PublicAccessBlockConfiguration>`;
|
|
195
423
|
try {
|
|
196
|
-
|
|
197
|
-
|
|
424
|
+
const params = {
|
|
425
|
+
method: 'PUT',
|
|
426
|
+
bucket: bucketName,
|
|
427
|
+
subres: { publicAccessBlock: '' },
|
|
428
|
+
headers: {
|
|
429
|
+
'Content-Type': 'application/xml',
|
|
430
|
+
},
|
|
431
|
+
content: xml,
|
|
432
|
+
successStatuses: [200],
|
|
433
|
+
};
|
|
434
|
+
await ossRequest(ossClient, params);
|
|
435
|
+
logger_1.logger.info(lang_1.lang.__('OSS_BUCKET_PUBLIC_ACCESS_BLOCK_DISABLED', { bucketName }));
|
|
198
436
|
}
|
|
199
437
|
catch (error) {
|
|
200
|
-
logger_1.logger.warn(lang_1.lang.__('
|
|
438
|
+
logger_1.logger.warn(lang_1.lang.__('OSS_BUCKET_PUBLIC_ACCESS_BLOCK_DISABLE_FAILED', {
|
|
439
|
+
bucketName,
|
|
440
|
+
error: String(error),
|
|
441
|
+
}));
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
const unbindCustomDomain = async (bucketName, domain, dnsRecordId, txtRecordId) => {
|
|
445
|
+
await removeCorsRuleForDomain(bucketName, domain);
|
|
446
|
+
await deleteBucketCname(bucketName, domain);
|
|
447
|
+
if (dnsOps) {
|
|
448
|
+
if (dnsRecordId && dnsRecordId !== 'existing') {
|
|
449
|
+
try {
|
|
450
|
+
await dnsOps.deleteDomainRecord(dnsRecordId);
|
|
451
|
+
logger_1.logger.info(lang_1.lang.__('OSS_DNS_CNAME_DELETED', { domain }));
|
|
452
|
+
}
|
|
453
|
+
catch (error) {
|
|
454
|
+
logger_1.logger.warn(lang_1.lang.__('OSS_DNS_CNAME_DELETE_FAILED', { domain, error: String(error) }));
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (txtRecordId) {
|
|
458
|
+
try {
|
|
459
|
+
await dnsOps.deleteDomainRecord(txtRecordId);
|
|
460
|
+
logger_1.logger.info(lang_1.lang.__('OSS_DNS_TXT_RECORD_DELETED', { domain }));
|
|
461
|
+
}
|
|
462
|
+
catch (error) {
|
|
463
|
+
logger_1.logger.warn(lang_1.lang.__('OSS_DNS_TXT_RECORD_DELETE_FAILED', { domain, error: String(error) }));
|
|
464
|
+
}
|
|
465
|
+
}
|
|
201
466
|
}
|
|
202
467
|
};
|
|
203
468
|
return {
|
|
@@ -212,6 +477,9 @@ const createOssOperations = (ossClient, region, dnsOps) => {
|
|
|
212
477
|
}
|
|
213
478
|
// Set ACL if specified
|
|
214
479
|
if (config.acl) {
|
|
480
|
+
if (isPublicAcl(config.acl)) {
|
|
481
|
+
await disableBucketPublicAccessBlock(config.bucketName);
|
|
482
|
+
}
|
|
215
483
|
useBucket(config.bucketName);
|
|
216
484
|
await ossClient.putBucketACL(config.bucketName, config.acl);
|
|
217
485
|
}
|
|
@@ -362,6 +630,9 @@ const createOssOperations = (ossClient, region, dnsOps) => {
|
|
|
362
630
|
}
|
|
363
631
|
},
|
|
364
632
|
updateBucketAcl: async (bucketName, acl) => {
|
|
633
|
+
if (isPublicAcl(acl)) {
|
|
634
|
+
await disableBucketPublicAccessBlock(bucketName);
|
|
635
|
+
}
|
|
365
636
|
useBucket(bucketName);
|
|
366
637
|
await ossClient.putBucketACL(bucketName, acl);
|
|
367
638
|
},
|
|
@@ -429,6 +700,7 @@ const createOssOperations = (ossClient, region, dnsOps) => {
|
|
|
429
700
|
bindCustomDomain,
|
|
430
701
|
unbindCustomDomain,
|
|
431
702
|
getOssEndpoint,
|
|
703
|
+
createCnameToken,
|
|
432
704
|
};
|
|
433
705
|
};
|
|
434
706
|
exports.createOssOperations = createOssOperations;
|
|
@@ -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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RAM_ROLE_PROPAGATION_DELAY_MS = exports.APIGW_DNS_PUBLIC_RESOLUTION_DELAY_MS = exports.APIGW_DNS_PUBLIC_RESOLUTION_MAX_ATTEMPTS = exports.APIGW_DOMAIN_BIND_RETRY_DELAY_MS = exports.APIGW_DOMAIN_BIND_MAX_RETRIES = exports.STALE_LOCK_THRESHOLD = exports.DEFAULT_LOCK_RETRY_DELAY = exports.DEFAULT_LOCK_TIMEOUT = exports.LOCK_FILE_SUFFIX = exports.OSS_STATE_REQUEST_TIMEOUT_MS = exports.OSS_STATE_CONNECT_TIMEOUT_MS = exports.FC3_CODE_INLINE_SIZE_LIMIT = exports.ALIYUN_FC3_READ_TIMEOUT_MS = exports.ALIYUN_FC3_CONNECT_TIMEOUT_MS = exports.SI_LOCALSTACK_SERVER_PORT = exports.SI_BOOTSTRAP_BUCKET_PREFIX = exports.SI_BOOTSTRAP_FC_PREFIX = exports.OSS_DEPLOYMENT_TIMEOUT = exports.CODE_ZIP_SIZE_LIMIT = void 0;
|
|
3
|
+
exports.RAM_ROLE_PROPAGATION_DELAY_MS = exports.APIGW_DNS_PUBLIC_RESOLUTION_DELAY_MS = exports.APIGW_DNS_PUBLIC_RESOLUTION_MAX_ATTEMPTS = exports.APIGW_DOMAIN_BIND_RETRY_DELAY_MS = exports.APIGW_DOMAIN_BIND_MAX_RETRIES = exports.DNS_PROPAGATION_DELAY_MS = exports.DNS_PROPAGATION_MAX_ATTEMPTS = exports.DOMAIN_BIND_RETRY_DELAY_MS = exports.DOMAIN_BIND_MAX_RETRIES = exports.STALE_LOCK_THRESHOLD = exports.DEFAULT_LOCK_RETRY_DELAY = exports.DEFAULT_LOCK_TIMEOUT = exports.LOCK_FILE_SUFFIX = exports.OSS_STATE_REQUEST_TIMEOUT_MS = exports.OSS_STATE_CONNECT_TIMEOUT_MS = exports.FC3_CODE_INLINE_SIZE_LIMIT = exports.ALIYUN_FC3_READ_TIMEOUT_MS = exports.ALIYUN_FC3_CONNECT_TIMEOUT_MS = exports.SI_LOCALSTACK_SERVER_PORT = exports.SI_BOOTSTRAP_BUCKET_PREFIX = exports.SI_BOOTSTRAP_FC_PREFIX = exports.OSS_DEPLOYMENT_TIMEOUT = exports.CODE_ZIP_SIZE_LIMIT = void 0;
|
|
4
4
|
exports.CODE_ZIP_SIZE_LIMIT = 300 * 1000; // 300 KB - code package size limit for inline deployment
|
|
5
5
|
exports.OSS_DEPLOYMENT_TIMEOUT = 3000; // in seconds
|
|
6
6
|
exports.SI_BOOTSTRAP_FC_PREFIX = 'si-bootstrap-api';
|
|
@@ -17,9 +17,15 @@ exports.LOCK_FILE_SUFFIX = '.si-lock';
|
|
|
17
17
|
exports.DEFAULT_LOCK_TIMEOUT = 10 * 60 * 1000; // 10 minutes
|
|
18
18
|
exports.DEFAULT_LOCK_RETRY_DELAY = 2000; // 2 seconds
|
|
19
19
|
exports.STALE_LOCK_THRESHOLD = 60 * 60 * 1000; // 1 hour
|
|
20
|
-
// API Gateway
|
|
21
|
-
exports.
|
|
22
|
-
exports.
|
|
20
|
+
// Shared domain binding retry configuration (used by API Gateway, OSS, and future resources)
|
|
21
|
+
exports.DOMAIN_BIND_MAX_RETRIES = 5;
|
|
22
|
+
exports.DOMAIN_BIND_RETRY_DELAY_MS = 30000; // 30 seconds
|
|
23
|
+
// Shared DNS propagation polling configuration (used by API Gateway, OSS, and future resources)
|
|
24
|
+
exports.DNS_PROPAGATION_MAX_ATTEMPTS = 10;
|
|
25
|
+
exports.DNS_PROPAGATION_DELAY_MS = 60000; // 1 minute
|
|
26
|
+
// API Gateway domain binding (aliases for shared constants)
|
|
27
|
+
exports.APIGW_DOMAIN_BIND_MAX_RETRIES = exports.DOMAIN_BIND_MAX_RETRIES;
|
|
28
|
+
exports.APIGW_DOMAIN_BIND_RETRY_DELAY_MS = exports.DOMAIN_BIND_RETRY_DELAY_MS;
|
|
23
29
|
exports.APIGW_DNS_PUBLIC_RESOLUTION_MAX_ATTEMPTS = 10;
|
|
24
30
|
exports.APIGW_DNS_PUBLIC_RESOLUTION_DELAY_MS = 30000; // 30 seconds
|
|
25
31
|
// RAM role propagation
|
|
@@ -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
|
@@ -31,3 +31,5 @@ __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);
|
|
35
|
+
__exportStar(require("./planFormatter"), exports);
|