@geek-fun/serverlessinsight 0.9.6 → 0.9.8
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/AGENTS.md +1 -0
- package/CHANGELOG.md +68 -0
- package/README.md +52 -11
- package/README.zh-CN.md +44 -10
- package/dist/package.json +2 -1
- package/dist/src/commands/deploy.js +3 -1
- package/dist/src/commands/destroy.js +3 -1
- package/dist/src/commands/forceUnlock.js +2 -2
- package/dist/src/commands/index.js +28 -8
- package/dist/src/commands/local.js +3 -2
- package/dist/src/commands/login.js +120 -37
- package/dist/src/commands/logout.js +3 -5
- package/dist/src/commands/migrate.js +17 -10
- package/dist/src/commands/plan.js +5 -1
- package/dist/src/commands/show.js +3 -1
- package/dist/src/commands/whoami.js +24 -6
- package/dist/src/common/aliyunClient/cdnOperations.js +64 -29
- package/dist/src/common/aliyunClient/dnsOperations.js +10 -0
- package/dist/src/common/aliyunClient/fc3Operations.js +36 -7
- package/dist/src/common/apiClient.js +1 -0
- package/dist/src/common/bindingReconcile.js +182 -0
- package/dist/src/common/cdnCapabilities.js +80 -0
- package/dist/src/common/certUtils.js +44 -5
- package/dist/src/common/consoleLines.js +126 -0
- package/dist/src/common/constants.js +4 -2
- package/dist/src/common/credentialStore.js +136 -39
- package/dist/src/common/domainUtils.js +23 -4
- package/dist/src/common/functionDefinition.js +4 -1
- package/dist/src/common/functionDomainCapabilities.js +28 -0
- package/dist/src/common/functionDomainReconcile.js +197 -0
- package/dist/src/common/lineContext.js +164 -0
- package/dist/src/common/planCapabilities.js +14 -27
- package/dist/src/common/planCompare.js +8 -7
- package/dist/src/common/planFormatter.js +71 -37
- package/dist/src/common/stateBackend/cosStateBackend.js +0 -46
- package/dist/src/common/stateBackend/index.js +24 -16
- package/dist/src/common/stateBackend/ossStateBackend.js +0 -25
- package/dist/src/common/stateBackend/remoteStateBackend.js +5 -22
- package/dist/src/common/stateBackend/saasStateBackend.js +46 -53
- package/dist/src/common/stateBackend/tosStateBackend.js +100 -0
- package/dist/src/common/stateBackend/types.js +0 -9
- package/dist/src/common/tencentClient/cdnOperations.js +165 -0
- package/dist/src/common/tencentClient/cosOperations.js +18 -2
- package/dist/src/common/tencentClient/dnspodOperations.js +12 -0
- package/dist/src/common/tencentClient/index.js +16 -0
- package/dist/src/common/tencentClient/scfOperations.js +23 -1
- package/dist/src/common/tencentClient/sslOperations.js +147 -77
- package/dist/src/common/volcengineClient/cdnOperations.js +221 -0
- package/dist/src/common/volcengineClient/dnsOperations.js +132 -0
- package/dist/src/common/volcengineClient/index.js +28 -0
- package/dist/src/common/volcengineClient/tosOperations.js +131 -1
- package/dist/src/lang/en.js +89 -12
- package/dist/src/lang/zh-CN.js +90 -11
- package/dist/src/parser/bucketParser.js +22 -79
- package/dist/src/parser/functionParser.js +13 -9
- package/dist/src/stack/aliyunStack/apigwResource.js +2 -1
- package/dist/src/stack/aliyunStack/fc3Planner.js +32 -12
- package/dist/src/stack/aliyunStack/fc3Resource.js +169 -121
- package/dist/src/stack/aliyunStack/ossPlanner.js +12 -4
- package/dist/src/stack/aliyunStack/ossResource.js +484 -501
- package/dist/src/stack/aliyunStack/ossTypes.js +21 -67
- package/dist/src/stack/localStack/aliyunFc.js +59 -9
- package/dist/src/stack/localStack/bucket.js +75 -28
- package/dist/src/stack/localStack/event.js +33 -24
- package/dist/src/stack/localStack/httpAdapter.js +1 -13
- package/dist/src/stack/localStack/index.js +2 -2
- package/dist/src/stack/localStack/localServer.js +85 -7
- package/dist/src/stack/scfStack/cosPlanner.js +11 -3
- package/dist/src/stack/scfStack/cosResource.js +339 -161
- package/dist/src/stack/scfStack/cosTypes.js +25 -34
- package/dist/src/stack/scfStack/scfPlanner.js +26 -8
- package/dist/src/stack/scfStack/scfResource.js +191 -124
- package/dist/src/stack/volcengineStack/tosPlanner.js +13 -1
- package/dist/src/stack/volcengineStack/tosResource.js +398 -7
- package/dist/src/stack/volcengineStack/tosTypes.js +27 -0
- package/dist/src/stack/volcengineStack/vefaasTypes.js +1 -1
- package/dist/src/types/domains/state.js +6 -0
- package/dist/src/validator/bucketSchema.js +35 -113
- package/dist/src/validator/cdnSchema.js +30 -0
- package/dist/src/validator/eventSchema.js +2 -20
- package/dist/src/validator/functionSchema.js +55 -8
- package/dist/src/validator/rootSchema.js +3 -3
- package/dist/src/validator/semanticValidation.js +504 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/release-notes.md +82 -6
- package/samples/aliyun-poc-api-cdn.yml +1 -1
- package/samples/aliyun-poc-bucket-cdn.yml +28 -26
- package/samples/aliyun-poc-domain.yml +2 -1
- package/samples/volcengine-poc-tos-state.yml +36 -0
|
@@ -4,13 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.deleteBucketResource = exports.updateBucketResource = exports.readBucketResource = exports.createBucketResource = void 0;
|
|
7
|
-
const domainUtils_1 = require("../../common/domainUtils");
|
|
8
|
-
const planCompare_1 = require("../../common/planCompare");
|
|
9
7
|
const bucketPolicy_1 = require("../../common/bucketPolicy");
|
|
8
|
+
const planCompare_1 = require("../../common/planCompare");
|
|
10
9
|
const functionDefinition_1 = require("../../common/functionDefinition");
|
|
10
|
+
const bindingReconcile_1 = require("../../common/bindingReconcile");
|
|
11
|
+
const cdnCapabilities_1 = require("../../common/cdnCapabilities");
|
|
12
|
+
const certUtils_1 = require("../../common/certUtils");
|
|
11
13
|
const aliyunClient_1 = require("../../common/aliyunClient");
|
|
12
14
|
const common_1 = require("../../common");
|
|
13
|
-
const
|
|
15
|
+
const certUtils_2 = require("../../common/certUtils");
|
|
14
16
|
const types_1 = require("../../types");
|
|
15
17
|
const ossTypes_1 = require("./ossTypes");
|
|
16
18
|
const ownershipTag_1 = require("../ownershipTag");
|
|
@@ -18,7 +20,7 @@ const alreadyExists_1 = require("../alreadyExists");
|
|
|
18
20
|
const logger_1 = require("../../common/logger");
|
|
19
21
|
const lang_1 = require("../../lang");
|
|
20
22
|
const node_path_1 = __importDefault(require("node:path"));
|
|
21
|
-
const
|
|
23
|
+
const domainUtils_1 = require("../../common/domainUtils");
|
|
22
24
|
// getBucket returns tags as { key, value } (BucketTag); the ownership helper
|
|
23
25
|
// expects { Key, Value }. Convert before verification.
|
|
24
26
|
const toOwnershipTags = (tags) => tags?.map((tag) => ({ Key: tag.key, Value: tag.value }));
|
|
@@ -109,37 +111,22 @@ const buildOssInstanceFromProvider = (info, sid) => {
|
|
|
109
111
|
policy: info.policy ?? null,
|
|
110
112
|
};
|
|
111
113
|
};
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const certId = domain?.certificate_id || website?.domain_certificate_id;
|
|
116
|
-
const certBody = domain?.certificate_body || website?.domain_certificate_body;
|
|
117
|
-
const certKey = domain?.certificate_private_key || website?.domain_certificate_private_key;
|
|
118
|
-
if (certId) {
|
|
119
|
-
const detail = await client.cas.getCertificate(certId);
|
|
114
|
+
const resolveBindingCertificate = async (binding, client) => {
|
|
115
|
+
if (binding.certificate_id) {
|
|
116
|
+
const detail = await client.cas.getCertificate(binding.certificate_id);
|
|
120
117
|
if (!detail || !detail.cert || !detail.key) {
|
|
121
|
-
throw new Error(lang_1.lang.__('CERT_REFERENCE_NOT_FOUND', { reference:
|
|
118
|
+
throw new Error(lang_1.lang.__('CERT_REFERENCE_NOT_FOUND', { reference: binding.certificate_id }));
|
|
122
119
|
}
|
|
123
120
|
return { certificateBody: detail.cert, certificatePrivateKey: detail.key };
|
|
124
121
|
}
|
|
125
|
-
if (
|
|
126
|
-
const body = (0,
|
|
127
|
-
const key = (0,
|
|
128
|
-
(0,
|
|
122
|
+
if (binding.certificate_body && binding.certificate_private_key) {
|
|
123
|
+
const body = (0, certUtils_2.readPemContent)(binding.certificate_body);
|
|
124
|
+
const key = (0, certUtils_2.readPemContent)(binding.certificate_private_key);
|
|
125
|
+
(0, certUtils_2.warnInlinePem)(binding.certificate_private_key);
|
|
129
126
|
return { certificateBody: body, certificatePrivateKey: key };
|
|
130
127
|
}
|
|
131
128
|
return undefined;
|
|
132
129
|
};
|
|
133
|
-
const getIsCdnEnabled = (bucket) => {
|
|
134
|
-
if (!bucket.domain?.cdn)
|
|
135
|
-
return false;
|
|
136
|
-
if (typeof bucket.domain.cdn === 'boolean')
|
|
137
|
-
return bucket.domain.cdn;
|
|
138
|
-
return bucket.domain.cdn.enabled;
|
|
139
|
-
};
|
|
140
|
-
const getIsAccelerateEnabled = (bucket) => {
|
|
141
|
-
return bucket.domain?.accelerate === true;
|
|
142
|
-
};
|
|
143
130
|
const buildOssBucketPolicyJson = (iam) => (0, bucketPolicy_1.buildBucketPolicy)(iam, 'aliyun');
|
|
144
131
|
const buildOssPolicyInstance = (context, bucketName) => ({
|
|
145
132
|
sid: (0, common_1.buildSid)('aliyun', 'oss-policy', context.stage, bucketName),
|
|
@@ -163,9 +150,6 @@ const deleteBucketPolicy = async (client, bucketName) => {
|
|
|
163
150
|
await client.oss.deleteBucketPolicy(bucketName);
|
|
164
151
|
logger_1.logger.info(lang_1.lang.__('BUCKET_POLICY_DELETED', { bucketName }));
|
|
165
152
|
};
|
|
166
|
-
const getDomainName = (bucket) => {
|
|
167
|
-
return bucket.domain?.domain_name || bucket.website?.domain;
|
|
168
|
-
};
|
|
169
153
|
/* istanbul ignore next */
|
|
170
154
|
const createBucketResource = async (context, bucket, state) => {
|
|
171
155
|
const config = (0, ossTypes_1.bucketToOssBucketConfig)(bucket);
|
|
@@ -189,30 +173,29 @@ const createBucketResource = async (context, bucket, state) => {
|
|
|
189
173
|
resourceName: config.bucketName,
|
|
190
174
|
}));
|
|
191
175
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
176
|
+
if (existingBucketOnRetry && existingResourceState) {
|
|
177
|
+
return (0, exports.updateBucketResource)(context, bucket, state);
|
|
178
|
+
}
|
|
179
|
+
const instances = [];
|
|
180
|
+
const hasBindings = (bucket.domains?.length ?? 0) > 0;
|
|
195
181
|
const partialResourceState = {
|
|
196
182
|
mode: 'managed',
|
|
197
183
|
region: context.region,
|
|
198
184
|
definition: {
|
|
199
185
|
...(0, ossTypes_1.extractOssBucketDefinition)(config, websiteCodeHash),
|
|
200
|
-
...(
|
|
186
|
+
...(hasBindings ? { domainBound: null } : {}),
|
|
201
187
|
},
|
|
202
188
|
instances,
|
|
203
189
|
lastUpdated: new Date().toISOString(),
|
|
204
190
|
status: 'tainted',
|
|
205
191
|
};
|
|
206
192
|
const stateAfterDependents = (0, common_1.setResource)(state, logicalId, partialResourceState);
|
|
207
|
-
const domainName = getDomainName(bucket);
|
|
208
|
-
const isCdnEnabled = getIsCdnEnabled(bucket);
|
|
209
|
-
const isAccelerateEnabled = getIsAccelerateEnabled(bucket);
|
|
210
|
-
let cnameInfo;
|
|
211
193
|
const refuseAdoptionError = () => new Error(lang_1.lang.__('RESOURCE_EXISTS_NOT_OWNED_ADOPT', {
|
|
212
194
|
resourceType: 'Bucket',
|
|
213
195
|
resourceName: config.bucketName,
|
|
214
196
|
tagKey: ownershipTag_1.OWNERSHIP_TAG_KEY,
|
|
215
197
|
}));
|
|
198
|
+
let anyBindingBound;
|
|
216
199
|
try {
|
|
217
200
|
if (!existingBucketOnRetry) {
|
|
218
201
|
try {
|
|
@@ -266,231 +249,23 @@ const createBucketResource = async (context, bucket, state) => {
|
|
|
266
249
|
}
|
|
267
250
|
}
|
|
268
251
|
instances[0] = buildOssInstanceFromProvider(bucketInfo, sid);
|
|
269
|
-
//
|
|
270
|
-
if (
|
|
252
|
+
// Bucket-level transfer acceleration (issue #279)
|
|
253
|
+
if (bucket.accelerate === true) {
|
|
271
254
|
logger_1.logger.info(lang_1.lang.__('ENABLING_OSS_TRANSFER_ACCELERATION', { bucketName: config.bucketName }));
|
|
272
255
|
const accelEnabled = await client.oss.enableTransferAcceleration(config.bucketName);
|
|
273
256
|
if (!accelEnabled) {
|
|
274
257
|
throw new Error(lang_1.lang.__('FAILED_TO_ENABLE_ACCELERATION', { bucketName: config.bucketName }));
|
|
275
258
|
}
|
|
276
259
|
}
|
|
277
|
-
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}));
|
|
287
|
-
// Resolve CDN config from bucket.domain.cdn object form
|
|
288
|
-
const cdnObj = typeof bucket.domain?.cdn === 'object' ? bucket.domain?.cdn : undefined;
|
|
289
|
-
const resolvedCdnType = cdnObj?.cdn_type ?? 'web';
|
|
290
|
-
const resolvedScope = cdnObj?.scope ?? 'global';
|
|
291
|
-
if (isCdnEnabled) {
|
|
292
|
-
const originEndpoint = isAccelerateEnabled
|
|
293
|
-
? await client.oss.getAccelerateEndpoint(config.bucketName)
|
|
294
|
-
: await client.oss.getBucketCnameEndpoint(config.bucketName);
|
|
295
|
-
logger_1.logger.info(lang_1.lang.__('CREATING_CDN_DISTRIBUTION', {
|
|
296
|
-
domain: primaryDomain,
|
|
297
|
-
origin: originEndpoint,
|
|
298
|
-
}));
|
|
299
|
-
await client.cdn.addCdnDomain({
|
|
300
|
-
domainName: primaryDomain,
|
|
301
|
-
cdnType: resolvedCdnType,
|
|
302
|
-
sources: [{ type: 'oss', content: originEndpoint }],
|
|
303
|
-
scope: resolvedScope,
|
|
304
|
-
});
|
|
305
|
-
if (cdnObj) {
|
|
306
|
-
if (cdnObj.cache_ttl != null || cdnObj.ignore_query_string != null) {
|
|
307
|
-
await client.cdn.applyCacheConfig(primaryDomain, cdnObj.cache_ttl, cdnObj.ignore_query_string);
|
|
308
|
-
}
|
|
309
|
-
if (cdnObj.origin_protocol) {
|
|
310
|
-
await client.cdn.applyProtocolConfig(primaryDomain, cdnObj.origin_protocol);
|
|
311
|
-
}
|
|
312
|
-
if (cdnObj.compression != null) {
|
|
313
|
-
await client.cdn.applyCompression(primaryDomain, cdnObj.compression);
|
|
314
|
-
}
|
|
315
|
-
if (cdnObj.force_redirect_https != null) {
|
|
316
|
-
await client.cdn.applyHttpsRedirect(primaryDomain, cdnObj.force_redirect_https);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
const cdnDomainInfo = await client.cdn.describeCdnDomainDetail(primaryDomain);
|
|
320
|
-
const cdnCname = cdnDomainInfo?.cname;
|
|
321
|
-
if (certificate) {
|
|
322
|
-
logger_1.logger.info(lang_1.lang.__('CDN_DEPLOYING_CERTIFICATE', { domain: primaryDomain }));
|
|
323
|
-
await client.cdn.setDomainServerCertificate(primaryDomain, {
|
|
324
|
-
serverCertificate: certificate.certificateBody,
|
|
325
|
-
privateKey: certificate.certificatePrivateKey,
|
|
326
|
-
serverCertificateStatus: 'on',
|
|
327
|
-
});
|
|
328
|
-
}
|
|
329
|
-
if (cdnCname) {
|
|
330
|
-
const cdnInstance = {
|
|
331
|
-
sid: (0, common_1.buildSid)('aliyun', 'cdn', context.stage, primaryDomain),
|
|
332
|
-
id: primaryDomain,
|
|
333
|
-
type: types_1.ResourceTypeEnum.ALIYUN_CDN_DISTRIBUTION,
|
|
334
|
-
domainName: primaryDomain,
|
|
335
|
-
cname: cdnCname,
|
|
336
|
-
};
|
|
337
|
-
instances.push(cdnInstance);
|
|
338
|
-
// Create DNS CNAME pointing to CDN distribution target
|
|
339
|
-
const dnsRecordId = await client.dns.addDomainRecord({
|
|
340
|
-
domainName: mainDomain,
|
|
341
|
-
rr: hostRecord,
|
|
342
|
-
type: 'CNAME',
|
|
343
|
-
value: cdnCname,
|
|
344
|
-
ttl: 600,
|
|
345
|
-
});
|
|
346
|
-
const dnsInstance = {
|
|
347
|
-
sid: (0, common_1.buildSid)('aliyun', 'alidns', context.stage, dnsRecordId || primaryDomain),
|
|
348
|
-
id: dnsRecordId || primaryDomain,
|
|
349
|
-
type: types_1.ResourceTypeEnum.ALIYUN_CDN_DNS_CNAME,
|
|
350
|
-
domain: primaryDomain,
|
|
351
|
-
cname: cdnCname,
|
|
352
|
-
dnsRecordId: dnsRecordId || undefined,
|
|
353
|
-
};
|
|
354
|
-
instances.push(dnsInstance);
|
|
355
|
-
}
|
|
356
|
-
// Bind custom domain to OSS bucket for back-to-origin (internal, not DNS-facing)
|
|
357
|
-
cnameInfo = await client.oss.bindCustomDomain(config.bucketName, primaryDomain, certificate, true);
|
|
358
|
-
}
|
|
359
|
-
else if (isAccelerateEnabled) {
|
|
360
|
-
// Accelerate-only: create DNS pointing to accelerated endpoint
|
|
361
|
-
const accelerateEndpoint = await client.oss.getAccelerateEndpoint(config.bucketName);
|
|
362
|
-
const dnsRecordId = await client.dns.addDomainRecord({
|
|
363
|
-
domainName: mainDomain,
|
|
364
|
-
rr: hostRecord,
|
|
365
|
-
type: 'CNAME',
|
|
366
|
-
value: accelerateEndpoint,
|
|
367
|
-
ttl: 600,
|
|
368
|
-
});
|
|
369
|
-
const dnsInstance = {
|
|
370
|
-
sid: (0, common_1.buildSid)('aliyun', 'alidns', context.stage, dnsRecordId || primaryDomain),
|
|
371
|
-
id: dnsRecordId || primaryDomain,
|
|
372
|
-
type: types_1.ResourceTypeEnum.ALIYUN_CDN_DNS_CNAME,
|
|
373
|
-
domain: primaryDomain,
|
|
374
|
-
cname: accelerateEndpoint,
|
|
375
|
-
dnsRecordId: dnsRecordId || undefined,
|
|
376
|
-
};
|
|
377
|
-
instances.push(dnsInstance);
|
|
378
|
-
cnameInfo = {
|
|
379
|
-
domain: primaryDomain,
|
|
380
|
-
cname: accelerateEndpoint,
|
|
381
|
-
dnsRecordId: dnsRecordId || undefined,
|
|
382
|
-
bucketCnameBound: false,
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
else {
|
|
386
|
-
// Direct OSS domain binding (existing behavior)
|
|
387
|
-
if (certificate) {
|
|
388
|
-
logger_1.logger.info(lang_1.lang.__('OSS_BUCKET_CERT_BINDING', {
|
|
389
|
-
domain: primaryDomain,
|
|
390
|
-
bucketName: config.bucketName,
|
|
391
|
-
}));
|
|
392
|
-
}
|
|
393
|
-
cnameInfo = await client.oss.bindCustomDomain(config.bucketName, primaryDomain, certificate);
|
|
394
|
-
if (cnameInfo) {
|
|
395
|
-
const instanceId = cnameInfo.dnsRecordId ?? primaryDomain;
|
|
396
|
-
const dnsInstance = {
|
|
397
|
-
sid: (0, common_1.buildSid)('aliyun', 'alidns', context.stage, instanceId),
|
|
398
|
-
id: instanceId,
|
|
399
|
-
type: types_1.ResourceTypeEnum.ALIYUN_OSS_DNS_CNAME,
|
|
400
|
-
domain: primaryDomain,
|
|
401
|
-
cname: cnameInfo.cname,
|
|
402
|
-
...(cnameInfo.dnsRecordId ? { dnsRecordId: cnameInfo.dnsRecordId } : {}),
|
|
403
|
-
...(cnameInfo.txtRecordId ? { txtRecordId: cnameInfo.txtRecordId } : {}),
|
|
404
|
-
};
|
|
405
|
-
instances.push(dnsInstance);
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
const wwwDomain = wwwBindApex ? (0, domainUtils_2.deriveWwwDomain)(primaryDomain) : null;
|
|
409
|
-
if (wwwDomain) {
|
|
410
|
-
logger_1.logger.info(lang_1.lang.__('BINDING_CUSTOM_DOMAIN_TO_BUCKET', {
|
|
411
|
-
domain: wwwDomain,
|
|
412
|
-
bucketName: config.bucketName,
|
|
413
|
-
}));
|
|
414
|
-
if (isCdnEnabled) {
|
|
415
|
-
const originEndpoint = isAccelerateEnabled
|
|
416
|
-
? await client.oss.getAccelerateEndpoint(config.bucketName)
|
|
417
|
-
: await client.oss.getBucketCnameEndpoint(config.bucketName);
|
|
418
|
-
await client.cdn.addCdnDomain({
|
|
419
|
-
domainName: wwwDomain,
|
|
420
|
-
cdnType: resolvedCdnType,
|
|
421
|
-
sources: [{ type: 'oss', content: originEndpoint }],
|
|
422
|
-
scope: resolvedScope,
|
|
423
|
-
});
|
|
424
|
-
const wwwCdnInfo = await client.cdn.describeCdnDomainDetail(wwwDomain);
|
|
425
|
-
if (cdnObj) {
|
|
426
|
-
if (cdnObj.cache_ttl != null || cdnObj.ignore_query_string != null) {
|
|
427
|
-
await client.cdn.applyCacheConfig(wwwDomain, cdnObj.cache_ttl, cdnObj.ignore_query_string);
|
|
428
|
-
}
|
|
429
|
-
if (cdnObj.origin_protocol) {
|
|
430
|
-
await client.cdn.applyProtocolConfig(wwwDomain, cdnObj.origin_protocol);
|
|
431
|
-
}
|
|
432
|
-
if (cdnObj.compression != null) {
|
|
433
|
-
await client.cdn.applyCompression(wwwDomain, cdnObj.compression);
|
|
434
|
-
}
|
|
435
|
-
if (cdnObj.force_redirect_https != null) {
|
|
436
|
-
await client.cdn.applyHttpsRedirect(wwwDomain, cdnObj.force_redirect_https);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
if (certificate) {
|
|
440
|
-
await client.cdn.setDomainServerCertificate(wwwDomain, {
|
|
441
|
-
serverCertificate: certificate.certificateBody,
|
|
442
|
-
privateKey: certificate.certificatePrivateKey,
|
|
443
|
-
serverCertificateStatus: 'on',
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
|
-
if (wwwCdnInfo?.cname) {
|
|
447
|
-
const wwwMainDomain = (0, domainUtils_2.extractMainDomain)(wwwDomain);
|
|
448
|
-
const wwwHostRecord = (0, domainUtils_2.extractHostRecord)(wwwDomain, wwwMainDomain);
|
|
449
|
-
const wwwDnsRecordId = await client.dns.addDomainRecord({
|
|
450
|
-
domainName: wwwMainDomain,
|
|
451
|
-
rr: wwwHostRecord,
|
|
452
|
-
type: 'CNAME',
|
|
453
|
-
value: wwwCdnInfo.cname,
|
|
454
|
-
ttl: 600,
|
|
455
|
-
});
|
|
456
|
-
const wwwCdnInstance = {
|
|
457
|
-
sid: (0, common_1.buildSid)('aliyun', 'cdn', context.stage, wwwDomain),
|
|
458
|
-
id: wwwDomain,
|
|
459
|
-
type: types_1.ResourceTypeEnum.ALIYUN_CDN_DISTRIBUTION,
|
|
460
|
-
domainName: wwwDomain,
|
|
461
|
-
cname: wwwCdnInfo.cname,
|
|
462
|
-
};
|
|
463
|
-
instances.push(wwwCdnInstance);
|
|
464
|
-
const wwwDnsInstance = {
|
|
465
|
-
sid: (0, common_1.buildSid)('aliyun', 'alidns', context.stage, wwwDnsRecordId || wwwDomain),
|
|
466
|
-
id: wwwDnsRecordId || wwwDomain,
|
|
467
|
-
type: types_1.ResourceTypeEnum.ALIYUN_CDN_DNS_CNAME,
|
|
468
|
-
domain: wwwDomain,
|
|
469
|
-
cname: wwwCdnInfo.cname,
|
|
470
|
-
dnsRecordId: wwwDnsRecordId || undefined,
|
|
471
|
-
};
|
|
472
|
-
instances.push(wwwDnsInstance);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
else {
|
|
476
|
-
const wwwCnameInfo = await client.oss.bindCustomDomain(config.bucketName, wwwDomain, certificate);
|
|
477
|
-
if (wwwCnameInfo) {
|
|
478
|
-
const wwwInstanceId = wwwCnameInfo.dnsRecordId ?? wwwDomain;
|
|
479
|
-
const wwwDnsInstance = {
|
|
480
|
-
sid: (0, common_1.buildSid)('aliyun', 'alidns', context.stage, wwwInstanceId),
|
|
481
|
-
id: wwwInstanceId,
|
|
482
|
-
type: types_1.ResourceTypeEnum.ALIYUN_OSS_DNS_CNAME,
|
|
483
|
-
domain: wwwDomain,
|
|
484
|
-
cname: wwwCnameInfo.cname,
|
|
485
|
-
isWwwVariant: true,
|
|
486
|
-
...(wwwCnameInfo.dnsRecordId ? { dnsRecordId: wwwCnameInfo.dnsRecordId } : {}),
|
|
487
|
-
...(wwwCnameInfo.txtRecordId ? { txtRecordId: wwwCnameInfo.txtRecordId } : {}),
|
|
488
|
-
};
|
|
489
|
-
instances.push(wwwDnsInstance);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
// Refresh bucket info to capture auto-added CORS rule
|
|
260
|
+
for (const binding of bucket.domains ?? []) {
|
|
261
|
+
const bound = await createBindingResources(context, client, config.bucketName, binding, bucket.accelerate === true, instances);
|
|
262
|
+
if (bound != null)
|
|
263
|
+
anyBindingBound = anyBindingBound ?? true;
|
|
264
|
+
if (bound === false)
|
|
265
|
+
anyBindingBound = false;
|
|
266
|
+
}
|
|
267
|
+
// Refresh bucket info to capture auto-added CORS rules from the bindings
|
|
268
|
+
if (hasBindings) {
|
|
494
269
|
bucketInfo = await client.oss.getBucket(config.bucketName);
|
|
495
270
|
if (bucketInfo) {
|
|
496
271
|
instances[0] = buildOssInstanceFromProvider(bucketInfo, sid);
|
|
@@ -523,7 +298,7 @@ const createBucketResource = async (context, bucket, state) => {
|
|
|
523
298
|
region: context.region,
|
|
524
299
|
definition: {
|
|
525
300
|
...(0, ossTypes_1.extractOssBucketDefinition)(config, websiteCodeHash),
|
|
526
|
-
...(
|
|
301
|
+
...(hasBindings ? { domainBound: anyBindingBound == null ? null : anyBindingBound } : {}),
|
|
527
302
|
},
|
|
528
303
|
instances,
|
|
529
304
|
lastUpdated: new Date().toISOString(),
|
|
@@ -537,6 +312,320 @@ const readBucketResource = async (context, bucketName) => {
|
|
|
537
312
|
return await client.oss.getBucket(bucketName);
|
|
538
313
|
};
|
|
539
314
|
exports.readBucketResource = readBucketResource;
|
|
315
|
+
const asAliyunGroup = (group) => group;
|
|
316
|
+
const bindingInstanceHostname = (instance) => (0, domainUtils_1.normalizeHostname)(String(instance.domainName ?? instance.domain));
|
|
317
|
+
const ALIYUN_BINDING_ROLE_BY_TYPE = {
|
|
318
|
+
[types_1.ResourceTypeEnum.ALIYUN_OSS_DNS_CNAME]: 'dns',
|
|
319
|
+
[types_1.ResourceTypeEnum.ALIYUN_CDN_DISTRIBUTION]: 'cdn',
|
|
320
|
+
[types_1.ResourceTypeEnum.ALIYUN_CDN_DNS_CNAME]: 'cdnDns',
|
|
321
|
+
};
|
|
322
|
+
const LEGACY_BINDING_FIELDS = [
|
|
323
|
+
'domain',
|
|
324
|
+
'wwwBindApex',
|
|
325
|
+
'domainCertificateId',
|
|
326
|
+
'domainCertificateBody',
|
|
327
|
+
'domainCertificatePrivateKey',
|
|
328
|
+
'domainProtocol',
|
|
329
|
+
'cdnEnabled',
|
|
330
|
+
'cdnType',
|
|
331
|
+
'cdnScope',
|
|
332
|
+
'cdnCacheTtl',
|
|
333
|
+
'cdnIgnoreQueryString',
|
|
334
|
+
'cdnOriginProtocol',
|
|
335
|
+
'cdnCompression',
|
|
336
|
+
'cdnForceRedirectHttps',
|
|
337
|
+
'accelerateEnabled',
|
|
338
|
+
];
|
|
339
|
+
const storedAccelerationEnabled = (definition) => (definition.accelerate ?? definition.accelerateEnabled) === true;
|
|
340
|
+
/** Legacy single-domain definitions (pre-v1 state) migrate in place. */
|
|
341
|
+
const aliyunLegacyBinding = (definition) => {
|
|
342
|
+
const legacy = definition;
|
|
343
|
+
if (Array.isArray(legacy.domains) || typeof legacy.domain !== 'string' || !legacy.domain) {
|
|
344
|
+
return undefined;
|
|
345
|
+
}
|
|
346
|
+
const hostname = (0, domainUtils_1.normalizeHostname)(legacy.domain);
|
|
347
|
+
const cdnEnabled = legacy.cdnEnabled === true;
|
|
348
|
+
const accelerate = storedAccelerationEnabled(definition);
|
|
349
|
+
return {
|
|
350
|
+
hostname,
|
|
351
|
+
mode: cdnEnabled ? 'cdn' : accelerate ? 'accelerate-only' : 'direct',
|
|
352
|
+
...(cdnEnabled
|
|
353
|
+
? {
|
|
354
|
+
cdn: {
|
|
355
|
+
enabled: true,
|
|
356
|
+
cdn_type: legacy.cdnType ?? 'web',
|
|
357
|
+
scope: legacy.cdnScope ?? 'global',
|
|
358
|
+
...(legacy.cdnCacheTtl != null ? { cache_ttl: legacy.cdnCacheTtl } : {}),
|
|
359
|
+
...(legacy.cdnIgnoreQueryString != null
|
|
360
|
+
? { ignore_query_string: legacy.cdnIgnoreQueryString }
|
|
361
|
+
: {}),
|
|
362
|
+
...(legacy.cdnOriginProtocol != null
|
|
363
|
+
? { origin_protocol: legacy.cdnOriginProtocol }
|
|
364
|
+
: {}),
|
|
365
|
+
...(legacy.cdnCompression != null
|
|
366
|
+
? { compression: legacy.cdnCompression }
|
|
367
|
+
: {}),
|
|
368
|
+
...(legacy.cdnForceRedirectHttps != null
|
|
369
|
+
? { force_redirect_https: legacy.cdnForceRedirectHttps }
|
|
370
|
+
: {}),
|
|
371
|
+
},
|
|
372
|
+
}
|
|
373
|
+
: {}),
|
|
374
|
+
...(typeof legacy.domainCertificateId === 'string' && legacy.domainCertificateId
|
|
375
|
+
? { certId: legacy.domainCertificateId }
|
|
376
|
+
: {}),
|
|
377
|
+
};
|
|
378
|
+
};
|
|
379
|
+
const applyCdnOptions = async (client, hostname, cdnObj) => {
|
|
380
|
+
if (cdnObj?.cache_ttl != null || cdnObj?.ignore_query_string != null) {
|
|
381
|
+
await client.cdn.applyCacheConfig(hostname, cdnObj?.cache_ttl, cdnObj?.ignore_query_string);
|
|
382
|
+
}
|
|
383
|
+
if (cdnObj?.origin_protocol) {
|
|
384
|
+
await client.cdn.applyProtocolConfig(hostname, cdnObj.origin_protocol);
|
|
385
|
+
}
|
|
386
|
+
if (cdnObj?.compression != null) {
|
|
387
|
+
await client.cdn.applyCompression(hostname, cdnObj.compression);
|
|
388
|
+
}
|
|
389
|
+
if (cdnObj?.force_redirect_https != null) {
|
|
390
|
+
await client.cdn.applyHttpsRedirect(hostname, cdnObj.force_redirect_https);
|
|
391
|
+
}
|
|
392
|
+
};
|
|
393
|
+
const deployCdnCertificate = async (client, hostname, certificate) => {
|
|
394
|
+
logger_1.logger.info(lang_1.lang.__('CDN_DEPLOYING_CERTIFICATE', { domain: hostname }));
|
|
395
|
+
await client.cdn.setDomainServerCertificate(hostname, {
|
|
396
|
+
serverCertificate: certificate.certificateBody,
|
|
397
|
+
privateKey: certificate.certificatePrivateKey,
|
|
398
|
+
serverCertificateStatus: 'on',
|
|
399
|
+
});
|
|
400
|
+
};
|
|
401
|
+
const resolveCdnOriginEndpoint = async (client, bucketName, accelerate) => accelerate
|
|
402
|
+
? await client.oss.getAccelerateEndpoint(bucketName)
|
|
403
|
+
: await client.oss.getBucketCnameEndpoint(bucketName);
|
|
404
|
+
const recordOssBinding = (context, hostname, info, instances, previous, separateDns = false) => {
|
|
405
|
+
if (!info && !previous)
|
|
406
|
+
return;
|
|
407
|
+
const dnsRecordId = separateDns ? undefined : (info?.dnsRecordId ?? previous?.dnsRecordId);
|
|
408
|
+
const txtRecordId = info?.txtRecordId ?? previous?.txtRecordId;
|
|
409
|
+
const id = dnsRecordId ?? hostname;
|
|
410
|
+
instances.push({
|
|
411
|
+
sid: (0, common_1.buildSid)('aliyun', separateDns ? 'oss-cname' : 'alidns', context.stage, id),
|
|
412
|
+
id,
|
|
413
|
+
type: types_1.ResourceTypeEnum.ALIYUN_OSS_DNS_CNAME,
|
|
414
|
+
domain: hostname,
|
|
415
|
+
cname: info?.cname ?? previous.cname,
|
|
416
|
+
...(dnsRecordId ? { dnsRecordId } : {}),
|
|
417
|
+
...(txtRecordId ? { txtRecordId } : {}),
|
|
418
|
+
});
|
|
419
|
+
};
|
|
420
|
+
const ensureDeliveryDns = async (context, client, hostname, cname, instances, previous) => {
|
|
421
|
+
const config = {
|
|
422
|
+
domainName: (0, domainUtils_1.extractMainDomain)(hostname),
|
|
423
|
+
rr: (0, domainUtils_1.extractHostRecord)(hostname, (0, domainUtils_1.extractMainDomain)(hostname)),
|
|
424
|
+
type: 'CNAME',
|
|
425
|
+
value: cname,
|
|
426
|
+
ttl: 600,
|
|
427
|
+
};
|
|
428
|
+
let dnsRecordId = previous?.dnsRecordId;
|
|
429
|
+
const index = instances.length;
|
|
430
|
+
if (dnsRecordId) {
|
|
431
|
+
instances.push({
|
|
432
|
+
sid: previous.sid,
|
|
433
|
+
id: dnsRecordId,
|
|
434
|
+
type: types_1.ResourceTypeEnum.ALIYUN_CDN_DNS_CNAME,
|
|
435
|
+
domain: hostname,
|
|
436
|
+
cname: previous.cname,
|
|
437
|
+
dnsRecordId,
|
|
438
|
+
});
|
|
439
|
+
if (previous?.cname !== cname)
|
|
440
|
+
await client.dns.updateDomainRecord(dnsRecordId, config);
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
dnsRecordId = await client.dns.addDomainRecord(config);
|
|
444
|
+
}
|
|
445
|
+
const id = dnsRecordId || hostname;
|
|
446
|
+
instances[index] = {
|
|
447
|
+
sid: (0, common_1.buildSid)('aliyun', 'alidns', context.stage, id),
|
|
448
|
+
id,
|
|
449
|
+
type: types_1.ResourceTypeEnum.ALIYUN_CDN_DNS_CNAME,
|
|
450
|
+
domain: hostname,
|
|
451
|
+
cname,
|
|
452
|
+
...(dnsRecordId ? { dnsRecordId } : {}),
|
|
453
|
+
};
|
|
454
|
+
};
|
|
455
|
+
const createCdnBinding = async (context, client, bucketName, binding, accelerate, certificate, instances) => {
|
|
456
|
+
const hostname = binding.domain_name;
|
|
457
|
+
const cdnObj = (0, bindingReconcile_1.getBindingCdnOptions)(binding);
|
|
458
|
+
const originEndpoint = await resolveCdnOriginEndpoint(client, bucketName, accelerate);
|
|
459
|
+
logger_1.logger.info(lang_1.lang.__('CREATING_CDN_DISTRIBUTION', { domain: hostname, origin: originEndpoint }));
|
|
460
|
+
await client.cdn.addCdnDomain({
|
|
461
|
+
domainName: hostname,
|
|
462
|
+
cdnType: cdnObj?.cdn_type ?? 'web',
|
|
463
|
+
sources: [{ type: 'oss', content: originEndpoint }],
|
|
464
|
+
scope: (0, cdnCapabilities_1.mapCdnScope)('aliyun', cdnObj?.scope),
|
|
465
|
+
});
|
|
466
|
+
return updateCdnBinding(context, client, bucketName, binding, accelerate, certificate, { hostname, mode: 'cdn', cdn: { ...cdnObj, enabled: true } }, {
|
|
467
|
+
cdn: {
|
|
468
|
+
sid: (0, common_1.buildSid)('aliyun', 'cdn', context.stage, hostname),
|
|
469
|
+
id: hostname,
|
|
470
|
+
type: types_1.ResourceTypeEnum.ALIYUN_CDN_DISTRIBUTION,
|
|
471
|
+
domainName: hostname,
|
|
472
|
+
pending: true,
|
|
473
|
+
},
|
|
474
|
+
}, instances);
|
|
475
|
+
};
|
|
476
|
+
const updateCdnBinding = async (context, client, bucketName, binding, accelerate, certificate, stored, group, instances) => {
|
|
477
|
+
const hostname = binding.domain_name;
|
|
478
|
+
const cdnObj = (0, bindingReconcile_1.getBindingCdnOptions)(binding);
|
|
479
|
+
const aliyunGroup = asAliyunGroup(group);
|
|
480
|
+
const pending = aliyunGroup?.cdn?.pending === true;
|
|
481
|
+
const distributionIndex = instances.length;
|
|
482
|
+
instances.push({
|
|
483
|
+
...aliyunGroup?.cdn,
|
|
484
|
+
sid: aliyunGroup?.cdn?.sid ?? (0, common_1.buildSid)('aliyun', 'cdn', context.stage, hostname),
|
|
485
|
+
id: hostname,
|
|
486
|
+
type: types_1.ResourceTypeEnum.ALIYUN_CDN_DISTRIBUTION,
|
|
487
|
+
domainName: hostname,
|
|
488
|
+
pending: true,
|
|
489
|
+
});
|
|
490
|
+
if ((0, bindingReconcile_1.cdnDeliveryChanged)(stored.cdn, cdnObj)) {
|
|
491
|
+
await client.cdn.modifyCdnDomain({
|
|
492
|
+
domainName: hostname,
|
|
493
|
+
cdnType: cdnObj?.cdn_type ?? 'web',
|
|
494
|
+
scope: (0, cdnCapabilities_1.mapCdnScope)('aliyun', cdnObj?.scope),
|
|
495
|
+
sources: [
|
|
496
|
+
{ type: 'oss', content: await resolveCdnOriginEndpoint(client, bucketName, accelerate) },
|
|
497
|
+
],
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
if (pending) {
|
|
501
|
+
await applyCdnOptions(client, hostname, cdnObj);
|
|
502
|
+
}
|
|
503
|
+
else {
|
|
504
|
+
// Omitted options resolve to their documented defaults (issue #283/#294
|
|
505
|
+
// unified contract): cache_ttl/ignore_query_string → provider-default
|
|
506
|
+
// cache behavior, origin_protocol → provider default, the boolean knobs
|
|
507
|
+
// → off. The apply layer renders null as the default (aliyun: absence of
|
|
508
|
+
// the config item), so a dropped option converges the cloud instead of
|
|
509
|
+
// leaving the previous setting behind (same shape on tencent/volcengine).
|
|
510
|
+
if ((stored.cdn?.cache_ttl ?? null) !== (cdnObj?.cache_ttl ?? null) ||
|
|
511
|
+
(stored.cdn?.ignore_query_string ?? null) !== (cdnObj?.ignore_query_string ?? null)) {
|
|
512
|
+
await client.cdn.applyCacheConfig(hostname, cdnObj?.cache_ttl ?? null, cdnObj?.ignore_query_string ?? null);
|
|
513
|
+
}
|
|
514
|
+
if ((stored.cdn?.origin_protocol ?? null) !== (cdnObj?.origin_protocol ?? null)) {
|
|
515
|
+
await client.cdn.applyProtocolConfig(hostname, cdnObj?.origin_protocol ?? null);
|
|
516
|
+
}
|
|
517
|
+
if ((stored.cdn?.compression ?? null) !== (cdnObj?.compression ?? null)) {
|
|
518
|
+
await client.cdn.applyCompression(hostname, cdnObj?.compression ?? false);
|
|
519
|
+
}
|
|
520
|
+
if ((stored.cdn?.force_redirect_https ?? null) !== (cdnObj?.force_redirect_https ?? null)) {
|
|
521
|
+
await client.cdn.applyHttpsRedirect(hostname, cdnObj?.force_redirect_https ?? false);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if (certificate) {
|
|
525
|
+
const certificateHash = (0, certUtils_1.resolveBindingCertificateHash)({
|
|
526
|
+
certificate_id: binding.certificate_id,
|
|
527
|
+
certificate_body: binding.certificate_body,
|
|
528
|
+
certificate_private_key: binding.certificate_private_key,
|
|
529
|
+
});
|
|
530
|
+
if ((0, bindingReconcile_1.shouldDeployBindingCertificate)({
|
|
531
|
+
pending,
|
|
532
|
+
certificateId: binding.certificate_id,
|
|
533
|
+
certificateHash,
|
|
534
|
+
stored,
|
|
535
|
+
})) {
|
|
536
|
+
await deployCdnCertificate(client, hostname, certificate);
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
logger_1.logger.info(lang_1.lang.__('CDN_CERT_UNCHANGED_SKIPPED', { domain: hostname }));
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
if (aliyunGroup?.cdnDns) {
|
|
543
|
+
instances.push(aliyunGroup.cdnDns);
|
|
544
|
+
}
|
|
545
|
+
else {
|
|
546
|
+
const detail = await client.cdn.describeCdnDomainDetail(hostname);
|
|
547
|
+
if (!detail?.cname) {
|
|
548
|
+
throw new Error(lang_1.lang.__('FAILED_TO_REFRESH_STATE', { resourceType: 'CDN domain', name: hostname }));
|
|
549
|
+
}
|
|
550
|
+
await ensureDeliveryDns(context, client, hostname, detail.cname, instances);
|
|
551
|
+
instances[distributionIndex] = { ...instances[distributionIndex], cname: detail.cname };
|
|
552
|
+
}
|
|
553
|
+
const cnameInfo = await client.oss.bindCustomDomain(bucketName, hostname, certificate, true);
|
|
554
|
+
recordOssBinding(context, hostname, cnameInfo, instances, aliyunGroup?.dns, true);
|
|
555
|
+
const { pending: _pending, ...ready } = instances[distributionIndex];
|
|
556
|
+
instances[distributionIndex] = ready;
|
|
557
|
+
return cnameInfo?.bucketCnameBound;
|
|
558
|
+
};
|
|
559
|
+
const createAccelerateOnlyBinding = async (context, client, bucketName, binding, certificate, instances, group) => {
|
|
560
|
+
const hostname = binding.domain_name;
|
|
561
|
+
const cnameInfo = await client.oss.bindCustomDomain(bucketName, hostname, certificate, true);
|
|
562
|
+
const aliyunGroup = asAliyunGroup(group);
|
|
563
|
+
recordOssBinding(context, hostname, cnameInfo, instances, aliyunGroup?.dns, true);
|
|
564
|
+
const endpoint = await client.oss.getAccelerateEndpoint(bucketName);
|
|
565
|
+
await ensureDeliveryDns(context, client, hostname, endpoint, instances, aliyunGroup?.cdnDns ?? aliyunGroup?.dns);
|
|
566
|
+
return cnameInfo?.bucketCnameBound;
|
|
567
|
+
};
|
|
568
|
+
const createDirectBinding = async (context, client, bucketName, binding, certificate, instances, previous) => {
|
|
569
|
+
const hostname = binding.domain_name;
|
|
570
|
+
if (certificate) {
|
|
571
|
+
logger_1.logger.info(lang_1.lang.__('OSS_BUCKET_CERT_BINDING', {
|
|
572
|
+
domain: hostname,
|
|
573
|
+
bucketName,
|
|
574
|
+
}));
|
|
575
|
+
}
|
|
576
|
+
const cnameInfo = await client.oss.bindCustomDomain(bucketName, hostname, certificate);
|
|
577
|
+
recordOssBinding(context, hostname, cnameInfo, instances, previous);
|
|
578
|
+
return cnameInfo?.bucketCnameBound;
|
|
579
|
+
};
|
|
580
|
+
const teardownBinding = async (client, bucketName, stored, group) => {
|
|
581
|
+
if (!group)
|
|
582
|
+
return;
|
|
583
|
+
const aliyunGroup = asAliyunGroup(group);
|
|
584
|
+
if (stored.mode === 'cdn') {
|
|
585
|
+
const distributionName = aliyunGroup?.cdn?.domainName ?? stored.hostname;
|
|
586
|
+
try {
|
|
587
|
+
await client.cdn.deleteCdnDomain(distributionName);
|
|
588
|
+
}
|
|
589
|
+
catch (error) {
|
|
590
|
+
if (error?.code !== 'InvalidDomain.NotFound')
|
|
591
|
+
throw error;
|
|
592
|
+
}
|
|
593
|
+
logger_1.logger.info(lang_1.lang.__('CDN_DOMAIN_DELETED', { domain: distributionName }));
|
|
594
|
+
if (aliyunGroup?.cdnDns?.dnsRecordId) {
|
|
595
|
+
await client.dns.deleteDomainRecord(aliyunGroup.cdnDns.dnsRecordId);
|
|
596
|
+
}
|
|
597
|
+
await client.oss.unbindCustomDomain(bucketName, stored.hostname, undefined, aliyunGroup?.dns?.txtRecordId);
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
if (stored.mode === 'accelerate-only') {
|
|
601
|
+
if (aliyunGroup?.cdnDns?.dnsRecordId) {
|
|
602
|
+
await client.dns.deleteDomainRecord(aliyunGroup.cdnDns.dnsRecordId);
|
|
603
|
+
}
|
|
604
|
+
await client.oss.unbindCustomDomain(bucketName, stored.hostname, undefined, aliyunGroup?.dns?.txtRecordId);
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
// direct binding
|
|
608
|
+
const domain = aliyunGroup?.dns?.domain ?? stored.hostname;
|
|
609
|
+
await client.oss.unbindCustomDomain(bucketName, domain, aliyunGroup?.dns?.dnsRecordId, aliyunGroup?.dns?.txtRecordId);
|
|
610
|
+
};
|
|
611
|
+
const createBindingResources = async (context, client, bucketName, binding, accelerate, instances) => {
|
|
612
|
+
const certificate = await resolveBindingCertificate(binding, client);
|
|
613
|
+
const hostname = (0, domainUtils_1.normalizeHostname)(binding.domain_name);
|
|
614
|
+
logger_1.logger.info(lang_1.lang.__('BINDING_CUSTOM_DOMAIN_TO_BUCKET', {
|
|
615
|
+
domain: hostname,
|
|
616
|
+
bucketName,
|
|
617
|
+
}));
|
|
618
|
+
if ((0, bindingReconcile_1.isBindingCdnEnabled)(binding)) {
|
|
619
|
+
return createCdnBinding(context, client, bucketName, { ...binding, domain_name: hostname }, accelerate, certificate, instances);
|
|
620
|
+
}
|
|
621
|
+
if (accelerate) {
|
|
622
|
+
return createAccelerateOnlyBinding(context, client, bucketName, { ...binding, domain_name: hostname }, certificate, instances);
|
|
623
|
+
}
|
|
624
|
+
return createDirectBinding(context, client, bucketName, { ...binding, domain_name: hostname }, certificate, instances);
|
|
625
|
+
};
|
|
626
|
+
// A binding switching between CDN and non-CDN delivery on the same hostname is
|
|
627
|
+
// reconciled at binding level (issue #283): the previous delivery group is torn
|
|
628
|
+
// down and rebuilt in the new mode — the bucket and unrelated bindings stay.
|
|
540
629
|
/* istanbul ignore next */
|
|
541
630
|
const updateBucketResource = async (context, bucket, state) => {
|
|
542
631
|
const config = (0, ossTypes_1.bucketToOssBucketConfig)(bucket);
|
|
@@ -557,278 +646,172 @@ const updateBucketResource = async (context, bucket, state) => {
|
|
|
557
646
|
}
|
|
558
647
|
const sid = (0, common_1.buildSid)('aliyun', 'oss', context.stage, config.bucketName);
|
|
559
648
|
const logicalId = `buckets.${bucket.key}`;
|
|
649
|
+
const existingState = state.resources[logicalId];
|
|
560
650
|
const instances = [buildOssInstanceFromProvider(bucketInfo, sid)];
|
|
561
651
|
const websiteCodeHash = bucket.website?.code
|
|
562
652
|
? (0, common_1.computeDirectoryHash)(node_path_1.default.resolve(process.cwd(), bucket.website.code))
|
|
563
653
|
: undefined;
|
|
564
|
-
const
|
|
565
|
-
const
|
|
566
|
-
const
|
|
567
|
-
const
|
|
568
|
-
const
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
if (
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
if (!
|
|
588
|
-
|
|
589
|
-
if (existingCdnInstances) {
|
|
590
|
-
for (const cdnInstance of existingCdnInstances) {
|
|
591
|
-
try {
|
|
592
|
-
await client.cdn.deleteCdnDomain(cdnInstance.domainName);
|
|
593
|
-
}
|
|
594
|
-
catch {
|
|
595
|
-
/* best effort */
|
|
596
|
-
}
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
// Clean up old DNS bindings
|
|
600
|
-
if (existingDnsInstances) {
|
|
601
|
-
for (const instance of existingDnsInstances) {
|
|
602
|
-
const ossInstance = instance;
|
|
603
|
-
await client.oss.unbindCustomDomain(config.bucketName, ossInstance.domain, ossInstance.dnsRecordId, ossInstance.txtRecordId);
|
|
604
|
-
}
|
|
605
|
-
}
|
|
654
|
+
const desiredBindings = bucket.domains ?? [];
|
|
655
|
+
const desiredAccelerate = bucket.accelerate === true;
|
|
656
|
+
const groups = (0, bindingReconcile_1.groupBindingInstances)(existingState?.instances, ALIYUN_BINDING_ROLE_BY_TYPE);
|
|
657
|
+
const storedAccelerate = storedAccelerationEnabled(existingState?.definition ?? {});
|
|
658
|
+
const storedBindings = (0, bindingReconcile_1.buildStoredBindings)(existingState, groups, {
|
|
659
|
+
accelerateEnabled: storedAccelerate,
|
|
660
|
+
legacyBinding: aliyunLegacyBinding,
|
|
661
|
+
});
|
|
662
|
+
// Transfer acceleration cannot be disabled through update, and enabling it
|
|
663
|
+
// under existing CDN bindings would orphan their origins (the CDN origin
|
|
664
|
+
// endpoint was chosen at creation) — both fail loudly instead of drifting.
|
|
665
|
+
if ((storedAccelerate && !desiredAccelerate) ||
|
|
666
|
+
(!storedAccelerate &&
|
|
667
|
+
desiredAccelerate &&
|
|
668
|
+
[...storedBindings.values()].some((b) => b.mode === 'cdn'))) {
|
|
669
|
+
throw new Error(lang_1.lang.__('CDN_ACCELERATE_CONFIG_CHANGED', { bucketName: config.bucketName }));
|
|
670
|
+
}
|
|
671
|
+
const removedHosts = new Set();
|
|
672
|
+
let accelerationEnabled = storedAccelerate;
|
|
673
|
+
try {
|
|
674
|
+
if (desiredAccelerate && !storedAccelerate) {
|
|
675
|
+
logger_1.logger.info(lang_1.lang.__('ENABLING_OSS_TRANSFER_ACCELERATION', { bucketName: config.bucketName }));
|
|
676
|
+
const accelEnabled = await client.oss.enableTransferAcceleration(config.bucketName);
|
|
677
|
+
if (!accelEnabled) {
|
|
678
|
+
throw new Error(lang_1.lang.__('FAILED_TO_ENABLE_ACCELERATION', { bucketName: config.bucketName }));
|
|
606
679
|
}
|
|
607
680
|
}
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
681
|
+
accelerationEnabled = desiredAccelerate;
|
|
682
|
+
let anyBindingBound;
|
|
683
|
+
const trackBindingResult = (bound) => {
|
|
684
|
+
if (bound == null)
|
|
685
|
+
return;
|
|
686
|
+
anyBindingBound = anyBindingBound ?? true;
|
|
687
|
+
if (bound === false)
|
|
688
|
+
anyBindingBound = false;
|
|
689
|
+
};
|
|
690
|
+
for (const rawBinding of desiredBindings) {
|
|
691
|
+
const hostname = (0, domainUtils_1.normalizeHostname)(rawBinding.domain_name);
|
|
692
|
+
const binding = { ...rawBinding, domain_name: hostname };
|
|
693
|
+
let stored = storedBindings.get(hostname);
|
|
694
|
+
const cdnEnabled = (0, bindingReconcile_1.isBindingCdnEnabled)(binding);
|
|
695
|
+
// Binding-level delivery-mode switch (issue #283): tear the previous
|
|
696
|
+
// delivery group down and rebuild in the new mode below.
|
|
697
|
+
if (stored &&
|
|
698
|
+
stored.mode !== (0, bindingReconcile_1.desiredBindingMode)(cdnEnabled, desiredAccelerate) &&
|
|
699
|
+
!(stored.mode === 'direct' && desiredAccelerate && !cdnEnabled)) {
|
|
700
|
+
await teardownBinding(client, config.bucketName, stored, groups.get(hostname));
|
|
701
|
+
stored = undefined;
|
|
702
|
+
}
|
|
703
|
+
const certificate = await resolveBindingCertificate(binding, client);
|
|
704
|
+
logger_1.logger.info(lang_1.lang.__('BINDING_CUSTOM_DOMAIN_TO_BUCKET', {
|
|
705
|
+
domain: hostname,
|
|
616
706
|
bucketName: config.bucketName,
|
|
617
707
|
}));
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
const existingDef = existingState?.definition;
|
|
623
|
-
const cdnWasEnabled = existingDef?.cdnEnabled === true;
|
|
624
|
-
const accelWasEnabled = existingDef?.accelerateEnabled === true;
|
|
625
|
-
if (cdnWasEnabled || accelWasEnabled) {
|
|
626
|
-
throw new Error(lang_1.lang.__('CDN_ACCELERATE_CONFIG_CHANGED', {
|
|
627
|
-
bucketName: config.bucketName,
|
|
628
|
-
}));
|
|
708
|
+
if (cdnEnabled) {
|
|
709
|
+
trackBindingResult(stored?.mode === 'cdn' && groups.get(hostname)?.cdn
|
|
710
|
+
? await updateCdnBinding(context, client, config.bucketName, binding, desiredAccelerate, certificate, stored, groups.get(hostname), instances)
|
|
711
|
+
: await createCdnBinding(context, client, config.bucketName, binding, desiredAccelerate, certificate, instances));
|
|
629
712
|
}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
const existingDef = existingState?.definition;
|
|
633
|
-
const cdnWasEnabled = existingDef?.cdnEnabled === true;
|
|
634
|
-
const accelWasEnabled = existingDef?.accelerateEnabled === true;
|
|
635
|
-
const oldDomain = existingDef?.domain;
|
|
636
|
-
const oldCdnType = existingDef?.cdnType;
|
|
637
|
-
const oldCdnScope = existingDef?.cdnScope;
|
|
638
|
-
const oldCacheTtl = existingDef?.cdnCacheTtl;
|
|
639
|
-
const oldIgnoreQS = existingDef?.cdnIgnoreQueryString;
|
|
640
|
-
const oldOriginProto = existingDef?.cdnOriginProtocol;
|
|
641
|
-
const oldCompression = existingDef?.cdnCompression;
|
|
642
|
-
const oldHttpsRedirect = existingDef?.cdnForceRedirectHttps;
|
|
643
|
-
const enableChanged = cdnWasEnabled !== isCdnEnabled || accelWasEnabled !== isAccelerateEnabled;
|
|
644
|
-
const domainChanged = oldDomain !== primaryDomain;
|
|
645
|
-
if (enableChanged || domainChanged) {
|
|
646
|
-
throw new Error(lang_1.lang.__('CDN_ACCELERATE_CONFIG_CHANGED', {
|
|
647
|
-
bucketName: config.bucketName,
|
|
648
|
-
}));
|
|
713
|
+
else if (desiredAccelerate) {
|
|
714
|
+
trackBindingResult(await createAccelerateOnlyBinding(context, client, config.bucketName, binding, certificate, instances, groups.get(hostname)));
|
|
649
715
|
}
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
scope: 'global',
|
|
653
|
-
cache_ttl: oldCacheTtl,
|
|
654
|
-
ignore_query_string: oldIgnoreQS,
|
|
655
|
-
origin_protocol: oldOriginProto,
|
|
656
|
-
compression: oldCompression,
|
|
657
|
-
force_redirect_https: oldHttpsRedirect,
|
|
658
|
-
...(typeof bucket.domain?.cdn === 'object' ? bucket.domain.cdn : {}),
|
|
659
|
-
};
|
|
660
|
-
const resolvedCdnType = cdnConfig?.cdn_type ?? 'web';
|
|
661
|
-
const resolvedScope = cdnConfig?.scope ?? 'global';
|
|
662
|
-
if (isCdnEnabled) {
|
|
663
|
-
if (oldCdnType !== (cdnConfig?.cdn_type ?? 'web') ||
|
|
664
|
-
oldCdnScope !== (cdnConfig?.scope ?? 'global')) {
|
|
665
|
-
await client.cdn.modifyCdnDomain({
|
|
666
|
-
domainName: primaryDomain,
|
|
667
|
-
cdnType: resolvedCdnType,
|
|
668
|
-
scope: resolvedScope,
|
|
669
|
-
sources: [
|
|
670
|
-
{
|
|
671
|
-
type: 'oss',
|
|
672
|
-
content: isAccelerateEnabled
|
|
673
|
-
? await client.oss.getAccelerateEndpoint(config.bucketName)
|
|
674
|
-
: await client.oss.getBucketCnameEndpoint(config.bucketName),
|
|
675
|
-
},
|
|
676
|
-
],
|
|
677
|
-
});
|
|
678
|
-
}
|
|
679
|
-
if (oldCacheTtl !== cdnConfig?.cache_ttl ||
|
|
680
|
-
oldIgnoreQS !== cdnConfig?.ignore_query_string) {
|
|
681
|
-
await client.cdn.applyCacheConfig(primaryDomain, cdnConfig?.cache_ttl, cdnConfig?.ignore_query_string);
|
|
682
|
-
}
|
|
683
|
-
if (oldOriginProto !== cdnConfig?.origin_protocol) {
|
|
684
|
-
await client.cdn.applyProtocolConfig(primaryDomain, cdnConfig?.origin_protocol);
|
|
685
|
-
}
|
|
686
|
-
if (oldCompression !== cdnConfig?.compression) {
|
|
687
|
-
await client.cdn.applyCompression(primaryDomain, cdnConfig?.compression);
|
|
688
|
-
}
|
|
689
|
-
if (oldHttpsRedirect !== cdnConfig?.force_redirect_https) {
|
|
690
|
-
await client.cdn.applyHttpsRedirect(primaryDomain, cdnConfig?.force_redirect_https);
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
const existingCdnDnsInstances = existingState?.instances?.filter((i) => i.type === types_1.ResourceTypeEnum.ALIYUN_CDN_DISTRIBUTION ||
|
|
694
|
-
i.type === types_1.ResourceTypeEnum.ALIYUN_CDN_DNS_CNAME);
|
|
695
|
-
const wwwDomainName = (0, domainUtils_2.deriveWwwDomain)(primaryDomain);
|
|
696
|
-
const removedInstances = wwwAction === 'remove'
|
|
697
|
-
? (existingCdnDnsInstances ?? []).filter((instance) => instance.isWwwVariant === true ||
|
|
698
|
-
(wwwDomainName !== null &&
|
|
699
|
-
(instance.domain === wwwDomainName || instance.domainName === wwwDomainName)))
|
|
700
|
-
: [];
|
|
701
|
-
await Promise.all(removedInstances.map(async (instance) => {
|
|
702
|
-
if (instance.type === types_1.ResourceTypeEnum.ALIYUN_CDN_DISTRIBUTION) {
|
|
703
|
-
await client.cdn.deleteCdnDomain(instance.domainName);
|
|
704
|
-
}
|
|
705
|
-
else if (instance.dnsRecordId) {
|
|
706
|
-
await client.dns.deleteDomainRecord(instance.dnsRecordId);
|
|
707
|
-
}
|
|
708
|
-
}));
|
|
709
|
-
const removedIds = new Set(removedInstances.map((instance) => instance.sid));
|
|
710
|
-
const filteredInstances = (existingCdnDnsInstances ?? []).filter((instance) => !removedIds.has(instance.sid));
|
|
711
|
-
if (filteredInstances.length > 0) {
|
|
712
|
-
instances.push(...filteredInstances);
|
|
716
|
+
else {
|
|
717
|
+
trackBindingResult(await createDirectBinding(context, client, config.bucketName, binding, certificate, instances, asAliyunGroup(groups.get(hostname))?.dns));
|
|
713
718
|
}
|
|
714
719
|
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
domain: primaryDomain,
|
|
724
|
-
cname: cnameInfo.cname,
|
|
725
|
-
...(cnameInfo.dnsRecordId ? { dnsRecordId: cnameInfo.dnsRecordId } : {}),
|
|
726
|
-
...(cnameInfo.txtRecordId ? { txtRecordId: cnameInfo.txtRecordId } : {}),
|
|
727
|
-
};
|
|
728
|
-
instances.push(dnsInstance);
|
|
729
|
-
}
|
|
720
|
+
// Converge removed bindings: any stored binding no longer declared is torn down.
|
|
721
|
+
const desiredHosts = new Set(desiredBindings.map((b) => (0, domainUtils_1.normalizeHostname)(b.domain_name)));
|
|
722
|
+
for (const [hostname, stored] of storedBindings) {
|
|
723
|
+
if (desiredHosts.has(hostname))
|
|
724
|
+
continue;
|
|
725
|
+
logger_1.logger.info(lang_1.lang.__('BINDING_REMOVING_DOMAIN', { domain: hostname, bucketName: config.bucketName }));
|
|
726
|
+
await teardownBinding(client, config.bucketName, stored, groups.get(hostname));
|
|
727
|
+
removedHosts.add(hostname);
|
|
730
728
|
}
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
const wwwInstanceId = wwwCnameInfo.dnsRecordId ?? wwwDomain;
|
|
741
|
-
const wwwDnsInstance = {
|
|
742
|
-
sid: (0, common_1.buildSid)('aliyun', 'alidns', context.stage, wwwInstanceId),
|
|
743
|
-
id: wwwInstanceId,
|
|
744
|
-
type: types_1.ResourceTypeEnum.ALIYUN_OSS_DNS_CNAME,
|
|
745
|
-
domain: wwwDomain,
|
|
746
|
-
cname: wwwCnameInfo.cname,
|
|
747
|
-
isWwwVariant: true,
|
|
748
|
-
...(wwwCnameInfo.dnsRecordId ? { dnsRecordId: wwwCnameInfo.dnsRecordId } : {}),
|
|
749
|
-
...(wwwCnameInfo.txtRecordId ? { txtRecordId: wwwCnameInfo.txtRecordId } : {}),
|
|
750
|
-
};
|
|
751
|
-
instances.push(wwwDnsInstance);
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
else if (existingWwwDnsInstance && !domainChanged && wwwAction === 'remove') {
|
|
755
|
-
const wwwInstance = existingWwwDnsInstance;
|
|
756
|
-
await client.oss.unbindCustomDomain(config.bucketName, wwwInstance.domain, wwwInstance.dnsRecordId, wwwInstance.txtRecordId);
|
|
757
|
-
}
|
|
729
|
+
const hasBindings = desiredBindings.length > 0;
|
|
730
|
+
const policy = buildOssBucketPolicyJson(bucket.iam);
|
|
731
|
+
const policyOwned = (0, bucketPolicy_1.isOwnedBucketPolicy)(ossTypes_1.OSS_BUCKET_POLICY_INSTANCE_TYPE, existingState?.instances, existingState?.definition);
|
|
732
|
+
if (policy) {
|
|
733
|
+
await client.oss.putBucketPolicy(config.bucketName, policy);
|
|
734
|
+
instances.push(buildOssPolicyInstance(context, config.bucketName));
|
|
735
|
+
}
|
|
736
|
+
else if (policyOwned || bucket.iam?.resource?.statements !== undefined) {
|
|
737
|
+
await deleteBucketPolicy(client, config.bucketName);
|
|
758
738
|
}
|
|
759
739
|
const refreshedInfo = await client.oss.getBucket(config.bucketName);
|
|
760
740
|
if (refreshedInfo) {
|
|
761
741
|
instances[0] = buildOssInstanceFromProvider(refreshedInfo, sid);
|
|
762
742
|
}
|
|
743
|
+
const definitionIntent = {
|
|
744
|
+
...(0, ossTypes_1.extractOssBucketDefinition)(config, websiteCodeHash),
|
|
745
|
+
...(hasBindings ? { domainBound: anyBindingBound == null ? null : anyBindingBound } : {}),
|
|
746
|
+
};
|
|
747
|
+
const resourceState = {
|
|
748
|
+
mode: 'managed',
|
|
749
|
+
region: context.region,
|
|
750
|
+
definition: (0, functionDefinition_1.withLifecycleIntent)((0, planCompare_1.mergeManagedIntent)(existingState?.definition ?? {}, definitionIntent), definitionIntent, ['policy', 'domainBound', ...LEGACY_BINDING_FIELDS]),
|
|
751
|
+
instances,
|
|
752
|
+
lastUpdated: new Date().toISOString(),
|
|
753
|
+
};
|
|
754
|
+
return (0, common_1.setResource)(state, logicalId, resourceState);
|
|
763
755
|
}
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
756
|
+
catch (error) {
|
|
757
|
+
const previousDefinition = existingState?.definition ?? {};
|
|
758
|
+
const previousDomains = previousDefinition.domains;
|
|
759
|
+
const legacyRemoved = typeof previousDefinition.domain === 'string' &&
|
|
760
|
+
removedHosts.has((0, domainUtils_1.normalizeHostname)(previousDefinition.domain));
|
|
761
|
+
const recoveryDefinition = {
|
|
762
|
+
...previousDefinition,
|
|
763
|
+
bucketName: config.bucketName,
|
|
764
|
+
...(Array.isArray(previousDomains)
|
|
765
|
+
? {
|
|
766
|
+
domains: previousDomains.filter((entry) => typeof entry?.domain_name !== 'string' ||
|
|
767
|
+
!removedHosts.has((0, domainUtils_1.normalizeHostname)(entry.domain_name))),
|
|
768
|
+
}
|
|
769
|
+
: legacyRemoved
|
|
770
|
+
? { domains: [] }
|
|
771
|
+
: {}),
|
|
772
|
+
accelerate: accelerationEnabled,
|
|
773
|
+
domainBound: false,
|
|
774
|
+
};
|
|
775
|
+
const bindingTypes = new Set([
|
|
776
|
+
types_1.ResourceTypeEnum.ALIYUN_OSS_DNS_CNAME,
|
|
777
|
+
types_1.ResourceTypeEnum.ALIYUN_CDN_DISTRIBUTION,
|
|
778
|
+
types_1.ResourceTypeEnum.ALIYUN_CDN_DNS_CNAME,
|
|
779
|
+
]);
|
|
780
|
+
const retainedInstances = new Map([...(existingState?.instances ?? []), ...instances]
|
|
781
|
+
.filter((instance) => !bindingTypes.has(String(instance.type)) ||
|
|
782
|
+
!removedHosts.has(bindingInstanceHostname(instance)))
|
|
783
|
+
.map((instance) => [
|
|
784
|
+
bindingTypes.has(String(instance.type))
|
|
785
|
+
? `${instance.type}:${bindingInstanceHostname(instance)}`
|
|
786
|
+
: instance.sid,
|
|
787
|
+
instance,
|
|
788
|
+
]));
|
|
789
|
+
throw new types_1.PartialResourceError((0, common_1.setResource)(state, logicalId, {
|
|
790
|
+
...existingState,
|
|
791
|
+
mode: 'managed',
|
|
792
|
+
region: context.region,
|
|
793
|
+
definition: recoveryDefinition,
|
|
794
|
+
instances: [...retainedInstances.values()],
|
|
795
|
+
lastUpdated: new Date().toISOString(),
|
|
796
|
+
status: 'ready',
|
|
797
|
+
}), error instanceof Error ? error : new Error(String(error)));
|
|
784
798
|
}
|
|
785
|
-
const definitionIntent = {
|
|
786
|
-
...(0, ossTypes_1.extractOssBucketDefinition)(config, websiteCodeHash),
|
|
787
|
-
...(domName != null
|
|
788
|
-
? {
|
|
789
|
-
domainBound: cnameInfo?.bucketCnameBound ?? existingState?.definition.domainBound ?? null,
|
|
790
|
-
}
|
|
791
|
-
: {}),
|
|
792
|
-
};
|
|
793
|
-
const resourceState = {
|
|
794
|
-
mode: 'managed',
|
|
795
|
-
region: context.region,
|
|
796
|
-
definition: (0, functionDefinition_1.withLifecycleIntent)((0, planCompare_1.mergeManagedIntent)(existingState?.definition ?? {}, definitionIntent), definitionIntent, ['policy']),
|
|
797
|
-
instances,
|
|
798
|
-
lastUpdated: new Date().toISOString(),
|
|
799
|
-
};
|
|
800
|
-
return (0, common_1.setResource)(state, logicalId, resourceState);
|
|
801
799
|
};
|
|
802
800
|
exports.updateBucketResource = updateBucketResource;
|
|
803
801
|
/* istanbul ignore next */
|
|
804
802
|
const deleteBucketResource = async (context, bucketName, logicalId, state) => {
|
|
805
803
|
const client = (0, aliyunClient_1.createAliyunClient)(context);
|
|
806
804
|
const existingState = state.resources[logicalId];
|
|
807
|
-
const
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
// Clean up CDN DNS CNAME records
|
|
817
|
-
const cdnDnsInstances = existingState?.instances?.filter((i) => i.type === types_1.ResourceTypeEnum.ALIYUN_CDN_DNS_CNAME);
|
|
818
|
-
if (cdnDnsInstances && client.dns) {
|
|
819
|
-
for (const dnsInstance of cdnDnsInstances) {
|
|
820
|
-
if (dnsInstance.dnsRecordId) {
|
|
821
|
-
await client.dns.deleteDomainRecord(dnsInstance.dnsRecordId);
|
|
822
|
-
}
|
|
823
|
-
}
|
|
805
|
+
const groups = (0, bindingReconcile_1.groupBindingInstances)(existingState?.instances, ALIYUN_BINDING_ROLE_BY_TYPE);
|
|
806
|
+
const storedBindings = (0, bindingReconcile_1.buildStoredBindings)(existingState, groups, {
|
|
807
|
+
accelerateEnabled: storedAccelerationEnabled(existingState?.definition ?? {}),
|
|
808
|
+
legacyBinding: aliyunLegacyBinding,
|
|
809
|
+
});
|
|
810
|
+
for (const [hostname, stored] of storedBindings) {
|
|
811
|
+
await teardownBinding(client, bucketName, stored, groups.get(hostname));
|
|
824
812
|
}
|
|
825
813
|
// Clean up bucket policy before deleting bucket
|
|
826
814
|
await deleteBucketPolicy(client, bucketName);
|
|
827
|
-
if (dnsInstances) {
|
|
828
|
-
for (const dnsInstance of dnsInstances) {
|
|
829
|
-
await client.oss.unbindCustomDomain(bucketName, dnsInstance.domain, dnsInstance.dnsRecordId, dnsInstance.txtRecordId);
|
|
830
|
-
}
|
|
831
|
-
}
|
|
832
815
|
try {
|
|
833
816
|
await client.oss.deleteBucket(bucketName);
|
|
834
817
|
}
|