@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
|
@@ -3,78 +3,149 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createSslOperations = void 0;
|
|
4
4
|
const lang_1 = require("../../lang");
|
|
5
5
|
const logger_1 = require("../logger");
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
certEndTime: response.CertEndTime ?? undefined,
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
catch (error) {
|
|
36
|
-
if (error &&
|
|
37
|
-
typeof error === 'object' &&
|
|
38
|
-
'code' in error &&
|
|
39
|
-
(error.code === 'FailedOperation.CertificateNotFound' || error.code === 'ResourceNotFound')) {
|
|
40
|
-
return null;
|
|
6
|
+
const SSL_DEPLOY_POLL_INTERVAL_MS = 2000;
|
|
7
|
+
const SSL_DEPLOY_POLL_TIMEOUT_MS = 120000;
|
|
8
|
+
const delay = async (ms) => {
|
|
9
|
+
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
10
|
+
};
|
|
11
|
+
const createSslOperations = (sslClient, options) => {
|
|
12
|
+
const pollIntervalMs = options?.pollIntervalMs ?? SSL_DEPLOY_POLL_INTERVAL_MS;
|
|
13
|
+
const pollTimeoutMs = options?.pollTimeoutMs ?? SSL_DEPLOY_POLL_TIMEOUT_MS;
|
|
14
|
+
// DeployCertificateInstance only creates the deployment task; completion is
|
|
15
|
+
// tracked through DescribeHostDeployRecordDetail using the aggregate counters
|
|
16
|
+
// (success/failed/running/pending totals) so no per-resource status enum has
|
|
17
|
+
// to be interpreted here. Transient describe failures keep polling until the
|
|
18
|
+
// deadline instead of failing the deploy outright.
|
|
19
|
+
const pollDeployRecord = async (deployRecordId, resourceType) => {
|
|
20
|
+
const deadline = Date.now() + pollTimeoutMs;
|
|
21
|
+
let first = true;
|
|
22
|
+
while (Date.now() < deadline) {
|
|
23
|
+
if (!first)
|
|
24
|
+
await delay(pollIntervalMs);
|
|
25
|
+
first = false;
|
|
26
|
+
let detail;
|
|
27
|
+
try {
|
|
28
|
+
detail = await sslClient.DescribeHostDeployRecordDetail({
|
|
29
|
+
DeployRecordId: deployRecordId,
|
|
30
|
+
Limit: 200,
|
|
31
|
+
});
|
|
41
32
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
deleteCertificate: async (certificateId) => {
|
|
46
|
-
logger_1.logger.info(lang_1.lang.__('SSL_DELETING_CERT', { certificateId }));
|
|
47
|
-
try {
|
|
48
|
-
const response = await sslClient.DeleteCertificate({ CertificateId: certificateId });
|
|
49
|
-
if (response.DeleteResult === false) {
|
|
50
|
-
throw new Error(lang_1.lang.__('SSL_DELETE_FAILED', { certificateId }));
|
|
33
|
+
catch (error) {
|
|
34
|
+
logger_1.logger.debug(lang_1.lang.__('SSL_DEPLOY_POLL_ERROR', { error: String(error) }));
|
|
35
|
+
continue;
|
|
51
36
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
37
|
+
const totalCount = detail?.TotalCount ?? 0;
|
|
38
|
+
const failedCount = detail?.FailedTotalCount ?? 0;
|
|
39
|
+
const successCount = detail?.SuccessTotalCount ?? 0;
|
|
40
|
+
if (failedCount > 0) {
|
|
41
|
+
const errorMessages = (detail?.DeployRecordDetailList ?? [])
|
|
42
|
+
.map((record) => record.ErrorMsg)
|
|
43
|
+
.filter((message) => typeof message === 'string' && message !== '');
|
|
44
|
+
throw new Error(lang_1.lang.__('SSL_CERT_DEPLOY_FAILED_RESULT', {
|
|
45
|
+
deployRecordId,
|
|
46
|
+
resourceType,
|
|
47
|
+
error: errorMessages.join('; ') || 'unknown error',
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
if (totalCount > 0 && successCount >= totalCount) {
|
|
51
|
+
logger_1.logger.info(lang_1.lang.__('SSL_CERT_DEPLOY_COMPLETED', { deployRecordId, resourceType }));
|
|
60
52
|
return;
|
|
61
53
|
}
|
|
62
|
-
throw error;
|
|
63
54
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
logger_1.logger.info(lang_1.lang.__('SSL_DEPLOYING_CERT', {
|
|
67
|
-
certificateId,
|
|
55
|
+
throw new Error(lang_1.lang.__('SSL_CERT_DEPLOY_POLL_TIMEOUT', {
|
|
56
|
+
deployRecordId,
|
|
68
57
|
resourceType,
|
|
69
|
-
|
|
58
|
+
timeoutSeconds: String(Math.round(pollTimeoutMs / 1000)),
|
|
70
59
|
}));
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
uploadCertificate: async (alias, cert, key, chain) => {
|
|
63
|
+
logger_1.logger.info(lang_1.lang.__('SSL_UPLOADING_CERT', { alias }));
|
|
64
|
+
const response = await sslClient.UploadCertificate({
|
|
65
|
+
CertificatePublicKey: chain ? `${cert}\n${chain}` : cert,
|
|
66
|
+
CertificatePrivateKey: key,
|
|
67
|
+
CertificateType: 'SVR',
|
|
68
|
+
Alias: alias,
|
|
69
|
+
Repeatable: false,
|
|
76
70
|
});
|
|
71
|
+
const certificateId = response.RepeatCertId ?? response.CertificateId;
|
|
72
|
+
if (!certificateId) {
|
|
73
|
+
throw new Error(lang_1.lang.__('SSL_UPLOAD_NO_CERT_ID', { alias }));
|
|
74
|
+
}
|
|
75
|
+
logger_1.logger.info(lang_1.lang.__('SSL_CERT_UPLOADED', { alias, certificateId }));
|
|
76
|
+
return { certificateId, alias };
|
|
77
|
+
},
|
|
78
|
+
getCertificate: async (certificateId) => {
|
|
79
|
+
try {
|
|
80
|
+
const response = await sslClient.DescribeCertificateDetail({
|
|
81
|
+
CertificateId: certificateId,
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
certificateId: response.CertificateId ?? certificateId,
|
|
85
|
+
alias: response.Alias ?? undefined,
|
|
86
|
+
domain: response.Domain ?? undefined,
|
|
87
|
+
status: response.Status ?? undefined,
|
|
88
|
+
certBeginTime: response.CertBeginTime ?? undefined,
|
|
89
|
+
certEndTime: response.CertEndTime ?? undefined,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
if (error &&
|
|
94
|
+
typeof error === 'object' &&
|
|
95
|
+
'code' in error &&
|
|
96
|
+
(error.code === 'FailedOperation.CertificateNotFound' ||
|
|
97
|
+
error.code === 'ResourceNotFound')) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
deleteCertificate: async (certificateId) => {
|
|
104
|
+
logger_1.logger.info(lang_1.lang.__('SSL_DELETING_CERT', { certificateId }));
|
|
105
|
+
try {
|
|
106
|
+
const response = await sslClient.DeleteCertificate({ CertificateId: certificateId });
|
|
107
|
+
if (response.DeleteResult === false) {
|
|
108
|
+
throw new Error(lang_1.lang.__('SSL_DELETE_FAILED', { certificateId }));
|
|
109
|
+
}
|
|
110
|
+
logger_1.logger.info(lang_1.lang.__('SSL_CERT_DELETED', { certificateId }));
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (error &&
|
|
114
|
+
typeof error === 'object' &&
|
|
115
|
+
'code' in error &&
|
|
116
|
+
(error.code === 'FailedOperation.CertificateNotFound' ||
|
|
117
|
+
error.code === 'ResourceNotFound')) {
|
|
118
|
+
logger_1.logger.warn(lang_1.lang.__('SSL_CERT_NOT_FOUND', { certificateId }));
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
throw error;
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
deployCertificateInstance: async (certificateId, resourceType, instanceIdList) => {
|
|
125
|
+
logger_1.logger.info(lang_1.lang.__('SSL_DEPLOYING_CERT', {
|
|
126
|
+
certificateId,
|
|
127
|
+
resourceType,
|
|
128
|
+
instances: instanceIdList.join(', '),
|
|
129
|
+
}));
|
|
130
|
+
let response;
|
|
131
|
+
try {
|
|
132
|
+
response = await sslClient.DeployCertificateInstance({
|
|
133
|
+
CertificateId: certificateId,
|
|
134
|
+
ResourceType: resourceType,
|
|
135
|
+
InstanceIdList: instanceIdList,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
140
|
+
// eslint-disable-next-line preserve-caught-error
|
|
141
|
+
throw new Error(lang_1.lang.__('SSL_CERT_DEPLOY_FAILED', {
|
|
142
|
+
resourceType,
|
|
143
|
+
certificateId,
|
|
144
|
+
error: message,
|
|
145
|
+
}));
|
|
146
|
+
}
|
|
77
147
|
const deployStatus = response.DeployStatus ?? undefined;
|
|
148
|
+
const deployRecordId = response.DeployRecordId ?? undefined;
|
|
78
149
|
if (deployStatus === 0) {
|
|
79
150
|
logger_1.logger.info(lang_1.lang.__('SSL_CERT_DEPLOY_EXISTING_TASK', {
|
|
80
151
|
certificateId,
|
|
@@ -85,23 +156,22 @@ const createSslOperations = (sslClient) => ({
|
|
|
85
156
|
logger_1.logger.info(lang_1.lang.__('SSL_CERT_DEPLOY_SUBMITTED', {
|
|
86
157
|
certificateId,
|
|
87
158
|
resourceType,
|
|
88
|
-
deployRecordId: String(
|
|
159
|
+
deployRecordId: String(deployRecordId ?? ''),
|
|
89
160
|
}));
|
|
90
161
|
}
|
|
162
|
+
// The task runs asynchronously — wait for it so callers only record state
|
|
163
|
+
// once the certificate is actually live on the instances.
|
|
164
|
+
if (deployRecordId != null) {
|
|
165
|
+
await pollDeployRecord(String(deployRecordId), resourceType);
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
logger_1.logger.warn(lang_1.lang.__('SSL_DEPLOY_RECORD_ID_MISSING', { resourceType }));
|
|
169
|
+
}
|
|
91
170
|
return {
|
|
92
|
-
deployRecordId
|
|
171
|
+
deployRecordId,
|
|
93
172
|
deployStatus,
|
|
94
173
|
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// eslint-disable-next-line preserve-caught-error
|
|
99
|
-
throw new Error(lang_1.lang.__('SSL_CERT_DEPLOY_FAILED', {
|
|
100
|
-
resourceType,
|
|
101
|
-
certificateId,
|
|
102
|
-
error: message,
|
|
103
|
-
}));
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
});
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
};
|
|
107
177
|
exports.createSslOperations = createSslOperations;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCdnOperations = void 0;
|
|
4
|
+
const logger_1 = require("../logger");
|
|
5
|
+
const lang_1 = require("../../lang");
|
|
6
|
+
// Match-all rule condition shared by Cache/Compression modules — the canonical
|
|
7
|
+
// "root directory" filter from the volcengine CDN configuration docs
|
|
8
|
+
// (https://docs.volcengine.com/docs/information-delivery-network/cache-configuration-1).
|
|
9
|
+
const MATCH_ALL_CONDITION = {
|
|
10
|
+
ConditionRule: [{ Type: 'url', Object: 'directory', Operator: 'match', Value: '/' }],
|
|
11
|
+
};
|
|
12
|
+
// Origin lines use two distinct fields (UpdateCdnConfig error codes):
|
|
13
|
+
// `OriginType` is the primary/backup slot, `InstanceType` is the origin kind
|
|
14
|
+
// (TOS/OSS/COS/Domain/IP). For a TOS origin the pull address is the bucket's
|
|
15
|
+
// virtual-host endpoint.
|
|
16
|
+
const toOriginLines = (origin) => origin.originLines.map((line) => ({
|
|
17
|
+
OriginType: line.originType,
|
|
18
|
+
...(line.instanceType ? { InstanceType: line.instanceType } : {}),
|
|
19
|
+
...(line.bucketName ? { BucketName: line.bucketName } : {}),
|
|
20
|
+
...(line.region ? { Region: line.region } : {}),
|
|
21
|
+
...(line.address ? { Address: line.address } : {}),
|
|
22
|
+
...(line.originHost ? { OriginHost: line.originHost } : {}),
|
|
23
|
+
...(line.privateBucketAccess != null ? { PrivateBucketAccess: line.privateBucketAccess } : {}),
|
|
24
|
+
...(line.httpPort ? { HttpPort: line.httpPort } : {}),
|
|
25
|
+
...(line.httpsPort ? { HttpsPort: line.httpsPort } : {}),
|
|
26
|
+
...(line.weight ? { Weight: line.weight } : {}),
|
|
27
|
+
}));
|
|
28
|
+
const toOriginConfig = (origin) => [
|
|
29
|
+
{ OriginAction: { OriginLines: toOriginLines(origin) } },
|
|
30
|
+
];
|
|
31
|
+
const mapDomainInfo = (entry) => ({
|
|
32
|
+
domain: entry.Domain,
|
|
33
|
+
cname: entry.Cname,
|
|
34
|
+
serviceType: entry.ServiceType,
|
|
35
|
+
serviceRegion: entry.ServiceRegion,
|
|
36
|
+
status: entry.Status,
|
|
37
|
+
originProtocol: entry.OriginProtocol,
|
|
38
|
+
https: entry.HTTPS,
|
|
39
|
+
origin: entry.PrimaryOrigin ?? undefined,
|
|
40
|
+
});
|
|
41
|
+
const createCdnOperations = (cdnClient) => {
|
|
42
|
+
const fetchCdn = async (action, body) => {
|
|
43
|
+
if (!cdnClient) {
|
|
44
|
+
throw new Error(lang_1.lang.__('VOLCENGINE_CDN_CLIENT_NOT_INITIALIZED'));
|
|
45
|
+
}
|
|
46
|
+
const response = (await cdnClient.fetchOpenAPI({
|
|
47
|
+
Action: action,
|
|
48
|
+
Version: '2021-03-01',
|
|
49
|
+
method: 'POST',
|
|
50
|
+
headers: {
|
|
51
|
+
'content-type': 'application/json',
|
|
52
|
+
},
|
|
53
|
+
data: body,
|
|
54
|
+
}));
|
|
55
|
+
return response.Result;
|
|
56
|
+
};
|
|
57
|
+
const isNotFound = (error) => {
|
|
58
|
+
const code = error?.code ?? '';
|
|
59
|
+
return code.includes('NotFound') || code === 'ResourceNotFound';
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
// AddCdnDomain (https://docs.volcengine.com/docs/6454/97340): Domain /
|
|
63
|
+
// ServiceType (web·download·video) / Origin / OriginProtocol
|
|
64
|
+
// (http·https·followclient); 20 requests/second.
|
|
65
|
+
addCdnDomain: async (config) => {
|
|
66
|
+
await fetchCdn('AddCdnDomain', {
|
|
67
|
+
Domain: config.domain,
|
|
68
|
+
ServiceType: config.serviceType,
|
|
69
|
+
...(config.serviceRegion ? { ServiceRegion: config.serviceRegion } : {}),
|
|
70
|
+
Origin: toOriginConfig(config.origin),
|
|
71
|
+
...(config.originProtocol ? { OriginProtocol: config.originProtocol } : {}),
|
|
72
|
+
});
|
|
73
|
+
logger_1.logger.info(lang_1.lang.__('CDN_DOMAIN_CREATED', { domain: config.domain }));
|
|
74
|
+
},
|
|
75
|
+
describeCdnDomain: async (domainName) => {
|
|
76
|
+
try {
|
|
77
|
+
const result = await fetchCdn('ListCdnDomains', {
|
|
78
|
+
Domain: domainName,
|
|
79
|
+
ExactMatch: true,
|
|
80
|
+
PageNum: 1,
|
|
81
|
+
PageSize: 10,
|
|
82
|
+
});
|
|
83
|
+
const entry = result?.Data?.[0];
|
|
84
|
+
return entry ? mapDomainInfo(entry) : null;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
if (isNotFound(error))
|
|
88
|
+
return null;
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
deleteCdnDomain: async (domainName) => {
|
|
93
|
+
try {
|
|
94
|
+
await fetchCdn('DeleteCdnDomain', { Domain: domainName });
|
|
95
|
+
logger_1.logger.info(lang_1.lang.__('CDN_DOMAIN_DELETED', { domain: domainName }));
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
if (isNotFound(error)) {
|
|
99
|
+
logger_1.logger.warn(lang_1.lang.__('RESOURCE_NOT_FOUND_PROVIDER', {
|
|
100
|
+
resourceType: 'CDN domain',
|
|
101
|
+
name: domainName,
|
|
102
|
+
}));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
// UpdateCdnConfig applies only the modules present in the body — delivery
|
|
109
|
+
// fields (ServiceType/ServiceRegion/Origin/OriginProtocol) go through here.
|
|
110
|
+
updateCdnDelivery: async (domainName, update) => {
|
|
111
|
+
await fetchCdn('UpdateCdnConfig', {
|
|
112
|
+
Domain: domainName,
|
|
113
|
+
...(update.serviceType ? { ServiceType: update.serviceType } : {}),
|
|
114
|
+
...(update.serviceRegion ? { ServiceRegion: update.serviceRegion } : {}),
|
|
115
|
+
...(update.origin ? { Origin: toOriginConfig(update.origin) } : {}),
|
|
116
|
+
...(update.originProtocol ? { OriginProtocol: update.originProtocol } : {}),
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
// Cache rules are seconds-based TTLs (si time-unit convention). The Cache
|
|
120
|
+
// module has a built-in lowest-priority default rule matching everything,
|
|
121
|
+
// so a single match-all rule is the domain-wide TTL.
|
|
122
|
+
// `null` renders the provider-default behavior — follow-origin caching /
|
|
123
|
+
// query string kept in the cache key — so a dropped si option converges
|
|
124
|
+
// the cloud instead of leaving the previous rule behind (issue #294).
|
|
125
|
+
// CacheKey: `exclude` drops the whole query string from the cache key,
|
|
126
|
+
// `include` (with Subobject '*') restores the default. `excludePart` is
|
|
127
|
+
// for naming specific parameters and rejects '*'.
|
|
128
|
+
applyCacheConfig: async (domainName, cacheTtl, ignoreQueryString) => {
|
|
129
|
+
const body = { Domain: domainName };
|
|
130
|
+
body.Cache = [
|
|
131
|
+
{
|
|
132
|
+
Condition: MATCH_ALL_CONDITION,
|
|
133
|
+
...(cacheTtl != null
|
|
134
|
+
? { CacheAction: { Action: 'cache', Ttl: cacheTtl } }
|
|
135
|
+
: { CacheAction: { Action: 'follow_origin' } }),
|
|
136
|
+
},
|
|
137
|
+
];
|
|
138
|
+
body.CacheKey = [
|
|
139
|
+
{
|
|
140
|
+
CacheKeyAction: {
|
|
141
|
+
CacheKeyComponents: [
|
|
142
|
+
ignoreQueryString
|
|
143
|
+
? { Object: 'queryString', Action: 'exclude', Subobject: '*' }
|
|
144
|
+
: { Object: 'queryString', Action: 'include', Subobject: '*', IgnoreCase: true },
|
|
145
|
+
],
|
|
146
|
+
},
|
|
147
|
+
Condition: MATCH_ALL_CONDITION,
|
|
148
|
+
},
|
|
149
|
+
];
|
|
150
|
+
await fetchCdn('UpdateCdnConfig', body);
|
|
151
|
+
},
|
|
152
|
+
// Smart compression: `Switch` enables the module and `CompressionRules`
|
|
153
|
+
// carries a match-all rule. CompressionType takes lowercase algorithm
|
|
154
|
+
// names ('gzip' / 'br').
|
|
155
|
+
applyCompression: async (domainName, enabled) => {
|
|
156
|
+
if (enabled == null)
|
|
157
|
+
return;
|
|
158
|
+
await fetchCdn('UpdateCdnConfig', {
|
|
159
|
+
Domain: domainName,
|
|
160
|
+
Compression: {
|
|
161
|
+
Switch: enabled,
|
|
162
|
+
...(enabled
|
|
163
|
+
? {
|
|
164
|
+
CompressionRules: [
|
|
165
|
+
{
|
|
166
|
+
Condition: MATCH_ALL_CONDITION,
|
|
167
|
+
CompressionAction: { CompressionType: ['gzip'] },
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
}
|
|
171
|
+
: {}),
|
|
172
|
+
},
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
// HTTP→HTTPS redirect lives under HTTPS.ForcedRedirect (not the
|
|
176
|
+
// HttpForcedRedirect module, which downgrades HTTPS to HTTP and is
|
|
177
|
+
// mutually exclusive with it). The provider requires HTTPS to be enabled
|
|
178
|
+
// first, so the caller applies the certificate before this.
|
|
179
|
+
applyHttpsRedirect: async (domainName, enabled) => {
|
|
180
|
+
if (enabled == null)
|
|
181
|
+
return;
|
|
182
|
+
await fetchCdn('UpdateCdnConfig', {
|
|
183
|
+
Domain: domainName,
|
|
184
|
+
HTTPS: {
|
|
185
|
+
Switch: true,
|
|
186
|
+
ForcedRedirect: {
|
|
187
|
+
EnableForcedRedirect: enabled,
|
|
188
|
+
StatusCode: '301',
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
},
|
|
193
|
+
// HTTPS must be on for any redirect; HTTP2 is left at the provider default
|
|
194
|
+
// (the API currently rejects enabling it).
|
|
195
|
+
applyCertificate: async (domainName, certificateId) => {
|
|
196
|
+
await fetchCdn('UpdateCdnConfig', {
|
|
197
|
+
Domain: domainName,
|
|
198
|
+
HTTPS: {
|
|
199
|
+
Switch: true,
|
|
200
|
+
CertInfo: { CertId: certificateId },
|
|
201
|
+
},
|
|
202
|
+
});
|
|
203
|
+
},
|
|
204
|
+
// AddCertificate uploads a PEM pair; Repeatable false makes a same-content
|
|
205
|
+
// re-upload return the existing certificate id (mirrors the Tencent SSL flow).
|
|
206
|
+
addCertificate: async (input) => {
|
|
207
|
+
const result = await fetchCdn('AddCertificate', {
|
|
208
|
+
Certificate: input.certificate,
|
|
209
|
+
PrivateKey: input.privateKey,
|
|
210
|
+
Repeatable: false,
|
|
211
|
+
...(input.name ? { Desc: input.name } : {}),
|
|
212
|
+
});
|
|
213
|
+
const certificateId = result?.CertId;
|
|
214
|
+
if (!certificateId) {
|
|
215
|
+
throw new Error(lang_1.lang.__('CDN_CERT_UPLOAD_FAILED', {}));
|
|
216
|
+
}
|
|
217
|
+
return { certificateId };
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
exports.createCdnOperations = createCdnOperations;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDnsOperations = void 0;
|
|
4
|
+
const logger_1 = require("../logger");
|
|
5
|
+
const lang_1 = require("../../lang");
|
|
6
|
+
/**
|
|
7
|
+
* Volcengine TrafficRoute public DNS operations (issue #294). API host
|
|
8
|
+
* `dns.volcengineapi.com`, Version `2018-08-01`; records are addressed by
|
|
9
|
+
* RecordID and belong to a zone identified by a numeric ZID. si resolves the
|
|
10
|
+
* zone by name (ListZones) on every record write — the domain must be hosted
|
|
11
|
+
* in Volcengine DNS (same constraint class as Tencent DNSPod).
|
|
12
|
+
*/
|
|
13
|
+
const createDnsOperations = (dnsClient) => {
|
|
14
|
+
const fetchDns = async (action, body) => {
|
|
15
|
+
if (!dnsClient) {
|
|
16
|
+
throw new Error(lang_1.lang.__('VOLCENGINE_DNS_CLIENT_NOT_INITIALIZED'));
|
|
17
|
+
}
|
|
18
|
+
const response = (await dnsClient.fetchOpenAPI({
|
|
19
|
+
Action: action,
|
|
20
|
+
Version: '2018-08-01',
|
|
21
|
+
method: 'POST',
|
|
22
|
+
headers: {
|
|
23
|
+
'content-type': 'application/json',
|
|
24
|
+
},
|
|
25
|
+
data: body,
|
|
26
|
+
}));
|
|
27
|
+
return response.Result;
|
|
28
|
+
};
|
|
29
|
+
const resolveZoneId = async (domainName) => {
|
|
30
|
+
const pageSize = 100;
|
|
31
|
+
for (let pageNumber = 1; pageNumber <= 20; pageNumber++) {
|
|
32
|
+
const result = await fetchDnsListZones(pageNumber, pageSize);
|
|
33
|
+
const zones = (result?.Zones ?? []);
|
|
34
|
+
const match = zones.find((zone) => zone.ZoneName === domainName);
|
|
35
|
+
if (match && typeof match.ZID === 'number')
|
|
36
|
+
return match.ZID;
|
|
37
|
+
const total = result?.Total ?? 0;
|
|
38
|
+
if (zones.length === 0 || pageNumber * pageSize >= total)
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
throw new Error(lang_1.lang.__('DNS_ZONE_NOT_FOUND', { domain: domainName }));
|
|
42
|
+
};
|
|
43
|
+
const fetchDnsListZones = async (pageNumber, pageSize) => fetchDns('ListZones', {
|
|
44
|
+
PageSize: pageSize,
|
|
45
|
+
PageNumber: pageNumber,
|
|
46
|
+
});
|
|
47
|
+
const describeZoneRecords = async (domainName, host, zid) => {
|
|
48
|
+
const resolvedZid = zid ?? (await resolveZoneId(domainName));
|
|
49
|
+
const result = await fetchDns('ListRecords', {
|
|
50
|
+
ZID: resolvedZid,
|
|
51
|
+
Host: host,
|
|
52
|
+
Type: 'CNAME',
|
|
53
|
+
PageSize: 100,
|
|
54
|
+
});
|
|
55
|
+
return (result?.Records ?? []).map((record) => ({
|
|
56
|
+
recordId: String(record.RecordID),
|
|
57
|
+
domain: record.FQDN ?? domainName,
|
|
58
|
+
host: record.Host ?? host,
|
|
59
|
+
type: record.Type ?? 'CNAME',
|
|
60
|
+
value: record.Value ?? '',
|
|
61
|
+
}));
|
|
62
|
+
};
|
|
63
|
+
return {
|
|
64
|
+
/**
|
|
65
|
+
* Value-matched record management (unified with the Tencent DNSPod flow):
|
|
66
|
+
* a record that already points at the requested target is adopted as-is,
|
|
67
|
+
* a missing one is created. Records pointing elsewhere are never touched —
|
|
68
|
+
* the create fails on the provider's duplicate-host guard and si reports
|
|
69
|
+
* the domain as not managed rather than silently repointing traffic.
|
|
70
|
+
*/
|
|
71
|
+
addDomainRecord: async (config) => {
|
|
72
|
+
const zid = await resolveZoneId(config.domainName);
|
|
73
|
+
const existing = await describeZoneRecords(config.domainName, config.host, zid);
|
|
74
|
+
const matched = existing.find((record) => record.value === config.value);
|
|
75
|
+
if (matched) {
|
|
76
|
+
logger_1.logger.info(lang_1.lang.__('DNS_RECORD_EXISTS', {
|
|
77
|
+
domain: `${config.host}.${config.domainName}`,
|
|
78
|
+
value: config.value,
|
|
79
|
+
}));
|
|
80
|
+
return matched.recordId;
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
const result = await fetchDns('CreateRecord', {
|
|
84
|
+
ZID: zid,
|
|
85
|
+
Host: config.host,
|
|
86
|
+
Type: config.type,
|
|
87
|
+
Value: config.value,
|
|
88
|
+
Line: 'default',
|
|
89
|
+
...(config.ttl ? { TTL: config.ttl } : {}),
|
|
90
|
+
});
|
|
91
|
+
logger_1.logger.info(lang_1.lang.__('DNS_RECORD_CREATED', { domain: `${config.host}.${config.domainName}` }));
|
|
92
|
+
return result?.RecordID != null ? String(result.RecordID) : undefined;
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
logger_1.logger.warn(lang_1.lang.__('DNS_RECORD_FOREIGN_EXISTS', {
|
|
96
|
+
domain: `${config.host}.${config.domainName}`,
|
|
97
|
+
value: config.value,
|
|
98
|
+
}));
|
|
99
|
+
logger_1.logger.debug(lang_1.lang.__('DNS_OPERATION_ERROR', { error: String(error) }));
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
// UpdateRecord requires Host and Line on every call, so the full record
|
|
104
|
+
// config is passed instead of a partial patch.
|
|
105
|
+
updateDomainRecord: async (recordId, config) => {
|
|
106
|
+
await fetchDns('UpdateRecord', {
|
|
107
|
+
RecordID: recordId,
|
|
108
|
+
Host: config.host,
|
|
109
|
+
Line: 'default',
|
|
110
|
+
Type: config.type,
|
|
111
|
+
Value: config.value,
|
|
112
|
+
...(config.ttl ? { TTL: config.ttl } : {}),
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
deleteDomainRecord: async (recordId) => {
|
|
116
|
+
try {
|
|
117
|
+
await fetchDns('DeleteRecord', { RecordID: recordId });
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
const code = error?.code ?? '';
|
|
121
|
+
if (code.includes('NotFound') || code === 'ResourceNotFound') {
|
|
122
|
+
logger_1.logger.warn(lang_1.lang.__('RESOURCE_NOT_FOUND_PROVIDER', { resourceType: 'DNS record', name: recordId }));
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
logger_1.logger.debug(lang_1.lang.__('DNS_RECORD_DELETED', { recordId }));
|
|
128
|
+
},
|
|
129
|
+
describeDomainRecords: async (domainName, host) => describeZoneRecords(domainName, host),
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
exports.createDnsOperations = createDnsOperations;
|
|
@@ -24,12 +24,16 @@ const iamOperations_1 = require("./iamOperations");
|
|
|
24
24
|
const apigwOperations_1 = require("./apigwOperations");
|
|
25
25
|
const stsOperations_1 = require("./stsOperations");
|
|
26
26
|
const tlsOperations_1 = require("./tlsOperations");
|
|
27
|
+
const cdnOperations_1 = require("./cdnOperations");
|
|
28
|
+
const dnsOperations_1 = require("./dnsOperations");
|
|
27
29
|
__exportStar(require("./types"), exports);
|
|
28
30
|
__exportStar(require("./vefaasOperations"), exports);
|
|
29
31
|
__exportStar(require("./tosOperations"), exports);
|
|
30
32
|
__exportStar(require("./iamOperations"), exports);
|
|
31
33
|
__exportStar(require("./apigwOperations"), exports);
|
|
32
34
|
__exportStar(require("./tlsOperations"), exports);
|
|
35
|
+
__exportStar(require("./cdnOperations"), exports);
|
|
36
|
+
__exportStar(require("./dnsOperations"), exports);
|
|
33
37
|
/**
|
|
34
38
|
* fetchOpenAPI resolves with { ResponseMetadata: { Error } } on API errors
|
|
35
39
|
* (validateStatus: null) — rethrow with .code so callers' error.code checks work.
|
|
@@ -105,6 +109,26 @@ const initializeSdkClients = (context) => {
|
|
|
105
109
|
region: context.region,
|
|
106
110
|
...(context.securityToken && { sessionToken: context.securityToken }),
|
|
107
111
|
}));
|
|
112
|
+
// CDN is a global service with a fixed endpoint (docs/6454/97340).
|
|
113
|
+
const cdnService = wrapService(new openapi_1.Service({
|
|
114
|
+
serviceName: 'cdn',
|
|
115
|
+
defaultVersion: '2021-03-01',
|
|
116
|
+
host: 'cdn.volcengineapi.com',
|
|
117
|
+
accessKeyId: context.accessKeyId,
|
|
118
|
+
secretKey: context.accessKeySecret,
|
|
119
|
+
region: context.region,
|
|
120
|
+
...(context.securityToken && { sessionToken: context.securityToken }),
|
|
121
|
+
}));
|
|
122
|
+
// TrafficRoute public DNS; records are managed under a numeric zone id.
|
|
123
|
+
const dnsService = wrapService(new openapi_1.Service({
|
|
124
|
+
serviceName: 'dns',
|
|
125
|
+
defaultVersion: '2018-08-01',
|
|
126
|
+
host: 'dns.volcengineapi.com',
|
|
127
|
+
accessKeyId: context.accessKeyId,
|
|
128
|
+
secretKey: context.accessKeySecret,
|
|
129
|
+
region: context.region,
|
|
130
|
+
...(context.securityToken && { sessionToken: context.securityToken }),
|
|
131
|
+
}));
|
|
108
132
|
return {
|
|
109
133
|
vefaas: vefaasService,
|
|
110
134
|
tos: tosService,
|
|
@@ -112,6 +136,8 @@ const initializeSdkClients = (context) => {
|
|
|
112
136
|
tls: tlsService,
|
|
113
137
|
apigw: apigwService,
|
|
114
138
|
sts: stsService,
|
|
139
|
+
cdn: cdnService,
|
|
140
|
+
dns: dnsService,
|
|
115
141
|
};
|
|
116
142
|
};
|
|
117
143
|
const createVolcengineClient = (context) => {
|
|
@@ -123,6 +149,8 @@ const createVolcengineClient = (context) => {
|
|
|
123
149
|
tls: (0, tlsOperations_1.createTlsOperations)(sdkClients.tls),
|
|
124
150
|
apigw: (0, apigwOperations_1.createApigwOperations)(sdkClients.apigw),
|
|
125
151
|
sts: (0, stsOperations_1.createStsOperations)(sdkClients.sts),
|
|
152
|
+
cdn: (0, cdnOperations_1.createCdnOperations)(sdkClients.cdn),
|
|
153
|
+
dns: (0, dnsOperations_1.createDnsOperations)(sdkClients.dns),
|
|
126
154
|
};
|
|
127
155
|
};
|
|
128
156
|
exports.createVolcengineClient = createVolcengineClient;
|