@geek-fun/serverlessinsight 0.6.15 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +405 -10
- package/README.md +59 -1
- package/README.zh-CN.md +3 -1
- package/dist/package.json +42 -34
- package/dist/src/commands/deploy.js +4 -0
- package/dist/src/commands/destroy.js +4 -0
- package/dist/src/common/aliyunClient/apigwOperations.js +9 -4
- package/dist/src/common/aliyunClient/cdnOperations.js +191 -0
- package/dist/src/common/aliyunClient/ecsOperations.js +2 -2
- package/dist/src/common/aliyunClient/fc3Operations.js +1 -1
- package/dist/src/common/aliyunClient/index.js +8 -0
- package/dist/src/common/aliyunClient/ossOperations.js +62 -2
- package/dist/src/common/aliyunClient/ramOperations.js +1 -1
- package/dist/src/common/credentials.js +12 -0
- package/dist/src/common/hashUtils.js +4 -0
- package/dist/src/common/iacHelper.js +5 -0
- package/dist/src/common/lockManager.js +8 -0
- package/dist/src/common/planFormatter.js +4 -0
- package/dist/src/common/providerEnum.js +1 -0
- package/dist/src/common/retryUtils.js +1 -1
- package/dist/src/common/runtimeMapper.js +24 -3
- package/dist/src/common/stateManager.js +10 -0
- package/dist/src/common/volcengineClient/apigwOperations.js +271 -0
- package/dist/src/common/volcengineClient/iamOperations.js +349 -0
- package/dist/src/common/volcengineClient/index.js +99 -0
- package/dist/src/common/volcengineClient/tlsOperations.js +256 -0
- package/dist/src/common/volcengineClient/tosOperations.js +440 -0
- package/dist/src/common/volcengineClient/types.js +26 -0
- package/dist/src/common/volcengineClient/vefaasOperations.js +386 -0
- package/dist/src/lang/en.js +135 -0
- package/dist/src/lang/zh-CN.js +134 -0
- package/dist/src/parser/bucketParser.js +111 -46
- package/dist/src/stack/aliyunStack/apigwResource.js +310 -47
- package/dist/src/stack/aliyunStack/apigwTypes.js +61 -1
- package/dist/src/stack/aliyunStack/ossResource.js +401 -69
- package/dist/src/stack/aliyunStack/ossTypes.js +58 -16
- package/dist/src/stack/deploy.js +4 -0
- package/dist/src/stack/scfStack/cosTypes.js +3 -6
- package/dist/src/stack/volcengineStack/apigwExecutor.js +87 -0
- package/dist/src/stack/volcengineStack/apigwPlanner.js +110 -0
- package/dist/src/stack/volcengineStack/apigwResource.js +302 -0
- package/dist/src/stack/volcengineStack/apigwTypes.js +106 -0
- package/dist/src/stack/volcengineStack/deployer.js +59 -0
- package/dist/src/stack/volcengineStack/destroyer.js +72 -0
- package/dist/src/stack/volcengineStack/index.js +44 -0
- package/dist/src/stack/volcengineStack/planner.js +27 -0
- package/dist/src/stack/volcengineStack/tosExecutor.js +106 -0
- package/dist/src/stack/volcengineStack/tosPlanner.js +96 -0
- package/dist/src/stack/volcengineStack/tosResource.js +103 -0
- package/dist/src/stack/volcengineStack/tosTypes.js +63 -0
- package/dist/src/stack/volcengineStack/vefaasExecutor.js +102 -0
- package/dist/src/stack/volcengineStack/vefaasPlanner.js +84 -0
- package/dist/src/stack/volcengineStack/vefaasResource.js +513 -0
- package/dist/src/stack/volcengineStack/vefaasTypes.js +75 -0
- package/dist/src/types/domains/state.js +6 -0
- package/dist/src/validator/bucketSchema.js +124 -56
- package/dist/src/validator/eventSchema.js +20 -0
- package/dist/src/validator/functionSchema.js +13 -0
- package/dist/src/validator/rootSchema.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +42 -34
- package/samples/README_TENCENT_COS.md +3 -15
- package/samples/aliyun-poc-bucket-cdn.yml +63 -0
- package/samples/aliyun-poc-bucket.yml +0 -2
- package/samples/aliyun-poc-domain.yml +0 -2
- package/samples/tencent-poc-cos.yml +0 -2
- package/samples/volcengine-poc-advanced.yml +59 -0
- package/samples/volcengine-poc-api.yml +31 -0
- package/samples/volcengine-poc-bucket.yml +16 -0
- package/samples/volcengine-poc-function.yml +19 -0
- package/samples/volcengine-poc-vpc.yml +34 -0
|
@@ -7,6 +7,7 @@ const parser_1 = require("../parser");
|
|
|
7
7
|
const lang_1 = require("../lang");
|
|
8
8
|
const scfStack_1 = require("../stack/scfStack");
|
|
9
9
|
const aliyunStack_1 = require("../stack/aliyunStack");
|
|
10
|
+
const volcengineStack_1 = require("../stack/volcengineStack");
|
|
10
11
|
const destroyStack = async (options) => {
|
|
11
12
|
const iacLocation = (0, common_1.getIacLocation)(options.location);
|
|
12
13
|
const rawIac = (0, parser_1.parseYaml)(iacLocation);
|
|
@@ -33,6 +34,9 @@ const destroyStack = async (options) => {
|
|
|
33
34
|
else if (iac.provider.name === common_1.ProviderEnum.ALIYUN) {
|
|
34
35
|
await (0, aliyunStack_1.destroyAliyunStack)(backend);
|
|
35
36
|
}
|
|
37
|
+
else if (iac.provider.name === common_1.ProviderEnum.VOLCENGINE) {
|
|
38
|
+
await (0, volcengineStack_1.destroyVolcengineStack)(backend);
|
|
39
|
+
}
|
|
36
40
|
else {
|
|
37
41
|
throw new Error(`Unsupported provider: ${iac.provider.name}`);
|
|
38
42
|
}
|
|
@@ -47,6 +47,7 @@ const retryUtils_1 = require("../retryUtils");
|
|
|
47
47
|
const removeUndefined = (obj) => {
|
|
48
48
|
return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== undefined));
|
|
49
49
|
};
|
|
50
|
+
/* istanbul ignore next */
|
|
50
51
|
const isNetworkTimeoutError = (error) => {
|
|
51
52
|
if (!error || typeof error !== 'object')
|
|
52
53
|
return false;
|
|
@@ -59,6 +60,7 @@ const isNetworkTimeoutError = (error) => {
|
|
|
59
60
|
(err.message?.includes('RequestTimeoutError') ?? false));
|
|
60
61
|
};
|
|
61
62
|
exports.isNetworkTimeoutError = isNetworkTimeoutError;
|
|
63
|
+
/* istanbul ignore next */
|
|
62
64
|
const isDomainAlreadyBoundError = (error) => {
|
|
63
65
|
if (!error || typeof error !== 'object')
|
|
64
66
|
return false;
|
|
@@ -69,6 +71,7 @@ const isDomainAlreadyBoundError = (error) => {
|
|
|
69
71
|
(err.message?.toLowerCase().includes('domain bindedbyother') ?? false));
|
|
70
72
|
};
|
|
71
73
|
exports.isDomainAlreadyBoundError = isDomainAlreadyBoundError;
|
|
74
|
+
/* istanbul ignore next */
|
|
72
75
|
const createApigwOperations = (apigwClient, dnsClient, _context) => {
|
|
73
76
|
const dnsOps = (0, dnsOperations_1.createDnsOperations)(dnsClient);
|
|
74
77
|
const buildTxtVerificationRecord = (groupId, domainName, groupSubdomain, mainDomain) => {
|
|
@@ -660,7 +663,7 @@ const createApigwOperations = (apigwClient, dnsClient, _context) => {
|
|
|
660
663
|
* Per Aliyun docs: CNAME must exist BEFORE calling SetDomain.
|
|
661
664
|
* On SingleDomainOwnershipCheckFail, falls back to TXT verification with retry.
|
|
662
665
|
*/
|
|
663
|
-
bindCustomDomain: async (config, state, eventLogicalId) => {
|
|
666
|
+
bindCustomDomain: async (config, state, eventLogicalId, skipDns) => {
|
|
664
667
|
logger_1.logger.info(lang_1.lang.__('APIGW_BINDING_DOMAIN', { domain: config.domainName }));
|
|
665
668
|
const groupInfo = await apigwClient.describeApiGroup(new cloudapi.DescribeApiGroupRequest({ groupId: config.groupId }));
|
|
666
669
|
const region = groupInfo.body?.regionId || _context.region;
|
|
@@ -669,9 +672,11 @@ const createApigwOperations = (apigwClient, dnsClient, _context) => {
|
|
|
669
672
|
if (!groupSubdomain) {
|
|
670
673
|
throw new Error(`API group ${config.groupId} has no subDomain — cannot configure domain binding`);
|
|
671
674
|
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
+
if (!skipDns) {
|
|
676
|
+
logger_1.logger.info(lang_1.lang.__('APIGW_ENSURING_CNAME', { domain: config.domainName }));
|
|
677
|
+
state = await addDomainVerificationRecord(config.domainName, groupId, groupSubdomain, region, state, eventLogicalId);
|
|
678
|
+
await pollPublicDnsResolution(config.domainName);
|
|
679
|
+
}
|
|
675
680
|
const setDomainRequest = new cloudapi.SetDomainRequest({
|
|
676
681
|
groupId: config.groupId,
|
|
677
682
|
domainName: config.domainName,
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.createCdnOperations = void 0;
|
|
37
|
+
const cdn = __importStar(require("@alicloud/cdn20180510"));
|
|
38
|
+
const addCdnDomain = (cdnClient) => async (config) => {
|
|
39
|
+
const request = new cdn.AddCdnDomainRequest({
|
|
40
|
+
domainName: config.domainName,
|
|
41
|
+
cdnType: config.cdnType,
|
|
42
|
+
sources: JSON.stringify(config.sources.map((s) => ({
|
|
43
|
+
type: s.type,
|
|
44
|
+
content: s.content,
|
|
45
|
+
port: s.port ?? 80,
|
|
46
|
+
priority: s.priority ?? 20,
|
|
47
|
+
weight: s.weight ?? 10,
|
|
48
|
+
}))),
|
|
49
|
+
scope: config.scope ?? 'global',
|
|
50
|
+
checkUrl: config.checkUrl,
|
|
51
|
+
});
|
|
52
|
+
await cdnClient.addCdnDomain(request);
|
|
53
|
+
};
|
|
54
|
+
const describeCdnDomainDetail = (cdnClient) => async (domainName) => {
|
|
55
|
+
try {
|
|
56
|
+
const request = new cdn.DescribeCdnDomainDetailRequest({ domainName });
|
|
57
|
+
const response = await cdnClient.describeCdnDomainDetail(request);
|
|
58
|
+
const detail = response.body?.getDomainDetailModel;
|
|
59
|
+
if (!detail)
|
|
60
|
+
return null;
|
|
61
|
+
return {
|
|
62
|
+
domainName: detail.domainName,
|
|
63
|
+
cname: detail.cname,
|
|
64
|
+
status: detail.domainStatus,
|
|
65
|
+
scope: detail.scope,
|
|
66
|
+
cdnType: detail.cdnType,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
const deleteCdnDomain = (cdnClient) => async (domainName) => {
|
|
74
|
+
const request = new cdn.DeleteCdnDomainRequest({ domainName });
|
|
75
|
+
await cdnClient.deleteCdnDomain(request);
|
|
76
|
+
};
|
|
77
|
+
const modifyCdnDomain = (cdnClient) => async (config) => {
|
|
78
|
+
const request = new cdn.ModifyCdnDomainRequest({
|
|
79
|
+
domainName: config.domainName,
|
|
80
|
+
...(config.cdnType ? { cdnType: config.cdnType } : {}),
|
|
81
|
+
...(config.scope ? { scope: config.scope } : {}),
|
|
82
|
+
sources: config.sources
|
|
83
|
+
? JSON.stringify(config.sources.map((s) => ({
|
|
84
|
+
type: s.type,
|
|
85
|
+
content: s.content,
|
|
86
|
+
port: s.port ?? 80,
|
|
87
|
+
priority: s.priority ?? 20,
|
|
88
|
+
weight: s.weight ?? 10,
|
|
89
|
+
})))
|
|
90
|
+
: undefined,
|
|
91
|
+
});
|
|
92
|
+
await cdnClient.modifyCdnDomain(request);
|
|
93
|
+
};
|
|
94
|
+
const setDomainServerCertificate = (cdnClient) => async (domainName, certConfig) => {
|
|
95
|
+
const request = new cdn.SetCdnDomainSSLCertificateRequest({
|
|
96
|
+
domainName,
|
|
97
|
+
certName: certConfig.certName,
|
|
98
|
+
certType: certConfig.certType ?? 'upload',
|
|
99
|
+
certId: certConfig.certId,
|
|
100
|
+
SSLPub: certConfig.serverCertificate,
|
|
101
|
+
SSLPri: certConfig.privateKey,
|
|
102
|
+
SSLProtocol: certConfig.serverCertificateStatus ?? 'on',
|
|
103
|
+
certRegion: certConfig.certRegion,
|
|
104
|
+
});
|
|
105
|
+
await cdnClient.setCdnDomainSSLCertificate(request);
|
|
106
|
+
};
|
|
107
|
+
const applyCacheConfig = (cdnClient) => async (domainName, cacheTtl, ignoreQueryString) => {
|
|
108
|
+
const functions = [];
|
|
109
|
+
if (cacheTtl != null || ignoreQueryString != null) {
|
|
110
|
+
functions.push({
|
|
111
|
+
featureName: 'cache_expire',
|
|
112
|
+
featureParameters: {
|
|
113
|
+
cache_ttl: cacheTtl != null ? String(cacheTtl) : '0',
|
|
114
|
+
ignore_query_string: ignoreQueryString != null ? (ignoreQueryString ? 'on' : 'off') : 'off',
|
|
115
|
+
redirect_type: 'default',
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (functions.length > 0) {
|
|
120
|
+
const request = new cdn.BatchSetCdnDomainConfigRequest({
|
|
121
|
+
domainNames: domainName,
|
|
122
|
+
functions: JSON.stringify(functions),
|
|
123
|
+
});
|
|
124
|
+
await cdnClient.batchSetCdnDomainConfig(request);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const applyProtocolConfig = (cdnClient) => async (domainName, originProtocol) => {
|
|
128
|
+
if (originProtocol) {
|
|
129
|
+
const functions = [
|
|
130
|
+
{
|
|
131
|
+
featureName: 'forward_scheme',
|
|
132
|
+
featureParameters: {
|
|
133
|
+
enable: originProtocol,
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
];
|
|
137
|
+
const request = new cdn.BatchSetCdnDomainConfigRequest({
|
|
138
|
+
domainNames: domainName,
|
|
139
|
+
functions: JSON.stringify(functions),
|
|
140
|
+
});
|
|
141
|
+
await cdnClient.batchSetCdnDomainConfig(request);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const applyCompression = (cdnClient) => async (domainName, enabled) => {
|
|
145
|
+
if (enabled != null) {
|
|
146
|
+
const functions = [
|
|
147
|
+
{
|
|
148
|
+
featureName: 'page_compress',
|
|
149
|
+
featureParameters: {
|
|
150
|
+
enable: enabled ? 'on' : 'off',
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
];
|
|
154
|
+
const request = new cdn.BatchSetCdnDomainConfigRequest({
|
|
155
|
+
domainNames: domainName,
|
|
156
|
+
functions: JSON.stringify(functions),
|
|
157
|
+
});
|
|
158
|
+
await cdnClient.batchSetCdnDomainConfig(request);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const applyHttpsRedirect = (cdnClient) => async (domainName, enabled) => {
|
|
162
|
+
if (enabled != null) {
|
|
163
|
+
const functions = [
|
|
164
|
+
{
|
|
165
|
+
featureName: 'force_redirect',
|
|
166
|
+
featureParameters: {
|
|
167
|
+
redirect_code: '301',
|
|
168
|
+
redirect_type: enabled ? 'https' : 'http',
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
];
|
|
172
|
+
const request = new cdn.BatchSetCdnDomainConfigRequest({
|
|
173
|
+
domainNames: domainName,
|
|
174
|
+
functions: JSON.stringify(functions),
|
|
175
|
+
});
|
|
176
|
+
await cdnClient.batchSetCdnDomainConfig(request);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
/* istanbul ignore next */
|
|
180
|
+
const createCdnOperations = (cdnClient) => ({
|
|
181
|
+
addCdnDomain: addCdnDomain(cdnClient),
|
|
182
|
+
describeCdnDomainDetail: describeCdnDomainDetail(cdnClient),
|
|
183
|
+
deleteCdnDomain: deleteCdnDomain(cdnClient),
|
|
184
|
+
modifyCdnDomain: modifyCdnDomain(cdnClient),
|
|
185
|
+
setDomainServerCertificate: setDomainServerCertificate(cdnClient),
|
|
186
|
+
applyCacheConfig: applyCacheConfig(cdnClient),
|
|
187
|
+
applyProtocolConfig: applyProtocolConfig(cdnClient),
|
|
188
|
+
applyCompression: applyCompression(cdnClient),
|
|
189
|
+
applyHttpsRedirect: applyHttpsRedirect(cdnClient),
|
|
190
|
+
});
|
|
191
|
+
exports.createCdnOperations = createCdnOperations;
|
|
@@ -50,7 +50,7 @@ const transformPortRange = (protocol, portRange) => {
|
|
|
50
50
|
return portRange.includes('/') ? portRange : `${portRange}/${portRange}`;
|
|
51
51
|
};
|
|
52
52
|
const normalizeProtocol = (protocol) => protocol.trim().toUpperCase();
|
|
53
|
-
const parseSecurityGroupRule = (rule) => {
|
|
53
|
+
/* istanbul ignore next */ const parseSecurityGroupRule = (rule) => {
|
|
54
54
|
const [rawProtocol, second, third, ...rest] = rule.split(':');
|
|
55
55
|
if (rest.length > 0 || !rawProtocol || !second || !third) {
|
|
56
56
|
throw new Error(`Invalid security group rule format: ${rule}`);
|
|
@@ -78,7 +78,7 @@ const isDuplicateSecurityGroupRuleError = (error) => {
|
|
|
78
78
|
]);
|
|
79
79
|
return duplicateCodes.has(error.code);
|
|
80
80
|
};
|
|
81
|
-
const createEcsOperations = (ecsClient, context) => {
|
|
81
|
+
/* istanbul ignore next */ const createEcsOperations = (ecsClient, context) => {
|
|
82
82
|
const operations = {
|
|
83
83
|
createSecurityGroup: async (securityGroupName, vpcId, ingressRules, egressRules, description) => {
|
|
84
84
|
const createRequest = new ecs.CreateSecurityGroupRequest({
|
|
@@ -50,7 +50,7 @@ const buildCodeLocation = (codePath, ossCode) => {
|
|
|
50
50
|
const codeBase64 = codeBuffer.toString('base64');
|
|
51
51
|
return new fc.InputCodeLocation({ zipFile: codeBase64 });
|
|
52
52
|
};
|
|
53
|
-
const createFc3Operations = (fc3Client) => ({
|
|
53
|
+
/* istanbul ignore next */ const createFc3Operations = (fc3Client) => ({
|
|
54
54
|
createFunction: async (config, codePath, ossCode) => {
|
|
55
55
|
const createFunctionInput = new fc.CreateFunctionInput({
|
|
56
56
|
functionName: config.functionName,
|
|
@@ -50,6 +50,7 @@ const rds20140815_1 = __importDefault(require("@alicloud/rds20140815"));
|
|
|
50
50
|
const es_serverless20230627_1 = __importDefault(require("@alicloud/es-serverless20230627"));
|
|
51
51
|
const alidns20150109_1 = __importDefault(require("@alicloud/alidns20150109"));
|
|
52
52
|
const cas20200407_1 = __importDefault(require("@alicloud/cas20200407"));
|
|
53
|
+
const cdn20180510_1 = __importDefault(require("@alicloud/cdn20180510"));
|
|
53
54
|
const $OpenApi = __importStar(require("@alicloud/openapi-client"));
|
|
54
55
|
const ali_oss_1 = __importDefault(require("ali-oss"));
|
|
55
56
|
const constants_1 = require("../constants");
|
|
@@ -65,6 +66,7 @@ const esOperations_1 = require("./esOperations");
|
|
|
65
66
|
const tablestoreOperations_1 = require("./tablestoreOperations");
|
|
66
67
|
const dnsOperations_1 = require("./dnsOperations");
|
|
67
68
|
const casOperations_1 = require("./casOperations");
|
|
69
|
+
const cdnOperations_1 = require("./cdnOperations");
|
|
68
70
|
__exportStar(require("./types"), exports);
|
|
69
71
|
__exportStar(require("./apigwOperations"), exports);
|
|
70
72
|
__exportStar(require("./ossOperations"), exports);
|
|
@@ -73,6 +75,7 @@ __exportStar(require("./esOperations"), exports);
|
|
|
73
75
|
__exportStar(require("./tablestoreOperations"), exports);
|
|
74
76
|
__exportStar(require("./dnsOperations"), exports);
|
|
75
77
|
__exportStar(require("./casOperations"), exports);
|
|
78
|
+
__exportStar(require("./cdnOperations"), exports);
|
|
76
79
|
const initializeSdkClients = (context) => {
|
|
77
80
|
const baseConfig = {
|
|
78
81
|
accessKeyId: context.accessKeyId,
|
|
@@ -118,6 +121,9 @@ const initializeSdkClients = (context) => {
|
|
|
118
121
|
const casConfig = new $OpenApi.Config(baseConfig);
|
|
119
122
|
casConfig.endpoint = `cas.aliyuncs.com`;
|
|
120
123
|
const casClient = new cas20200407_1.default(casConfig);
|
|
124
|
+
const cdnConfig = new $OpenApi.Config(baseConfig);
|
|
125
|
+
cdnConfig.endpoint = `cdn.aliyuncs.com`;
|
|
126
|
+
const cdnClient = new cdn20180510_1.default(cdnConfig);
|
|
121
127
|
return {
|
|
122
128
|
fc3: fc3Client,
|
|
123
129
|
sls: slsClient,
|
|
@@ -130,6 +136,7 @@ const initializeSdkClients = (context) => {
|
|
|
130
136
|
es: esClient,
|
|
131
137
|
dns: dnsClient,
|
|
132
138
|
cas: casClient,
|
|
139
|
+
cdn: cdnClient,
|
|
133
140
|
};
|
|
134
141
|
};
|
|
135
142
|
const createAliyunClient = (context) => {
|
|
@@ -147,6 +154,7 @@ const createAliyunClient = (context) => {
|
|
|
147
154
|
es: (0, esOperations_1.createEsOperations)(sdkClients.es, context),
|
|
148
155
|
cas: (0, casOperations_1.createCasOperations)(sdkClients.cas),
|
|
149
156
|
dns: dnsOps,
|
|
157
|
+
cdn: (0, cdnOperations_1.createCdnOperations)(sdkClients.cdn),
|
|
150
158
|
tablestore: (instanceName) => (0, tablestoreOperations_1.createTablestoreOperations)(`https://${instanceName}.${context.region}.ots.aliyuncs.com`, instanceName, context),
|
|
151
159
|
};
|
|
152
160
|
};
|
|
@@ -36,7 +36,7 @@ const parseXmlResponse = (xml, tagName) => {
|
|
|
36
36
|
return null;
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
-
const createOssOperations = (ossClient, region, dnsOps) => {
|
|
39
|
+
/* istanbul ignore next */ const createOssOperations = (ossClient, region, dnsOps) => {
|
|
40
40
|
const useBucket = (bucketName) => {
|
|
41
41
|
ossClient.useBucket(bucketName);
|
|
42
42
|
};
|
|
@@ -232,7 +232,7 @@ const createOssOperations = (ossClient, region, dnsOps) => {
|
|
|
232
232
|
logger_1.logger.warn(lang_1.lang.__('OSS_CORS_RULE_REMOVE_FAILED', { domain, error: String(error) }));
|
|
233
233
|
}
|
|
234
234
|
};
|
|
235
|
-
const bindCustomDomain = async (bucketName, domain, certificate) => {
|
|
235
|
+
const bindCustomDomain = async (bucketName, domain, certificate, skipDns) => {
|
|
236
236
|
const normalizedDomain = (0, domainUtils_1.normalizeDomain)(domain);
|
|
237
237
|
const mainDomain = (0, domainUtils_1.extractMainDomain)(normalizedDomain);
|
|
238
238
|
const hostRecord = (0, domainUtils_1.extractHostRecord)(normalizedDomain, mainDomain);
|
|
@@ -249,6 +249,10 @@ const createOssOperations = (ossClient, region, dnsOps) => {
|
|
|
249
249
|
logger_1.logger.info(lang_1.lang.__('OSS_BUCKET_CERT_BOUND', { domain: normalizedDomain }));
|
|
250
250
|
}
|
|
251
251
|
await addCorsRuleForDomain(bucketName, normalizedDomain);
|
|
252
|
+
// When skipDns is true, caller manages DNS separately (e.g. CDN mode)
|
|
253
|
+
if (skipDns) {
|
|
254
|
+
return { domain: normalizedDomain, cname: ossEndpoint, bucketCnameBound, txtRecordId };
|
|
255
|
+
}
|
|
252
256
|
if (!dnsOps) {
|
|
253
257
|
logger_1.logger.warn(lang_1.lang.__('OSS_DNS_MANUAL_CONFIG_REQUIRED', { domain: normalizedDomain, cname: ossEndpoint }));
|
|
254
258
|
return { domain: normalizedDomain, cname: ossEndpoint, bucketCnameBound, txtRecordId };
|
|
@@ -501,6 +505,8 @@ const createOssOperations = (ossClient, region, dnsOps) => {
|
|
|
501
505
|
await ossClient.putBucketWebsite(config.bucketName, {
|
|
502
506
|
index: config.websiteConfig.indexDocument,
|
|
503
507
|
error: config.websiteConfig.errorDocument,
|
|
508
|
+
supportSubDir: true,
|
|
509
|
+
type: 2,
|
|
504
510
|
});
|
|
505
511
|
}
|
|
506
512
|
return {
|
|
@@ -653,6 +659,8 @@ const createOssOperations = (ossClient, region, dnsOps) => {
|
|
|
653
659
|
await ossClient.putBucketWebsite(bucketName, {
|
|
654
660
|
index: websiteConfig.indexDocument,
|
|
655
661
|
error: websiteConfig.errorDocument,
|
|
662
|
+
supportSubDir: true,
|
|
663
|
+
type: 2,
|
|
656
664
|
});
|
|
657
665
|
},
|
|
658
666
|
deleteBucketWebsite: async (bucketName) => {
|
|
@@ -709,9 +717,61 @@ const createOssOperations = (ossClient, region, dnsOps) => {
|
|
|
709
717
|
useBucket(bucketName);
|
|
710
718
|
await ossClient.put(objectKey, filePath);
|
|
711
719
|
},
|
|
720
|
+
enableTransferAcceleration: async (bucketName) => {
|
|
721
|
+
useBucket(bucketName);
|
|
722
|
+
try {
|
|
723
|
+
const xml = `<?xml version="1.0" encoding="UTF-8"?>
|
|
724
|
+
<TransferAccelerationConfiguration>
|
|
725
|
+
<Enabled>true</Enabled>
|
|
726
|
+
</TransferAccelerationConfiguration>`;
|
|
727
|
+
const params = {
|
|
728
|
+
method: 'PUT',
|
|
729
|
+
bucket: bucketName,
|
|
730
|
+
subres: { transferAcceleration: '' },
|
|
731
|
+
headers: { 'Content-Type': 'application/xml' },
|
|
732
|
+
content: xml,
|
|
733
|
+
successStatuses: [200],
|
|
734
|
+
};
|
|
735
|
+
await ossRequest(ossClient, params);
|
|
736
|
+
logger_1.logger.info(lang_1.lang.__('OSS_TRANSFER_ACCELERATION_ENABLED', { bucketName }));
|
|
737
|
+
return true;
|
|
738
|
+
}
|
|
739
|
+
catch (error) {
|
|
740
|
+
logger_1.logger.warn(lang_1.lang.__('OSS_TRANSFER_ACCELERATION_ENABLE_FAILED', {
|
|
741
|
+
bucketName,
|
|
742
|
+
error: String(error),
|
|
743
|
+
}));
|
|
744
|
+
return false;
|
|
745
|
+
}
|
|
746
|
+
},
|
|
747
|
+
getTransferAccelerationStatus: async (bucketName) => {
|
|
748
|
+
useBucket(bucketName);
|
|
749
|
+
try {
|
|
750
|
+
const params = {
|
|
751
|
+
method: 'GET',
|
|
752
|
+
bucket: bucketName,
|
|
753
|
+
subres: { transferAcceleration: '' },
|
|
754
|
+
successStatuses: [200],
|
|
755
|
+
};
|
|
756
|
+
const response = await ossRequest(ossClient, params);
|
|
757
|
+
const xml = response.data || '';
|
|
758
|
+
const match = /<Enabled>(\w+)<\/Enabled>/.exec(xml);
|
|
759
|
+
return match?.[1]?.toLowerCase() === 'true';
|
|
760
|
+
}
|
|
761
|
+
catch {
|
|
762
|
+
return false;
|
|
763
|
+
}
|
|
764
|
+
},
|
|
765
|
+
getAccelerateEndpoint: async (bucketName) => {
|
|
766
|
+
const infoResult = await ossClient.getBucketInfo(bucketName);
|
|
767
|
+
const bucket = infoResult.bucket;
|
|
768
|
+
const actualBucketName = bucket.Name || bucketName;
|
|
769
|
+
return `${actualBucketName}.oss-accelerate.aliyuncs.com`;
|
|
770
|
+
},
|
|
712
771
|
bindCustomDomain,
|
|
713
772
|
unbindCustomDomain,
|
|
714
773
|
createCnameToken,
|
|
774
|
+
getBucketCnameEndpoint,
|
|
715
775
|
};
|
|
716
776
|
};
|
|
717
777
|
exports.createOssOperations = createOssOperations;
|
|
@@ -92,7 +92,7 @@ const FC_EXECUTION_POLICY = JSON.stringify({
|
|
|
92
92
|
},
|
|
93
93
|
],
|
|
94
94
|
});
|
|
95
|
-
const createRamOperations = (ramClient) => {
|
|
95
|
+
/* istanbul ignore next */ const createRamOperations = (ramClient) => {
|
|
96
96
|
const attachRolePolicyForFc = async (roleName) => {
|
|
97
97
|
const policyName = `${roleName}-policy`;
|
|
98
98
|
// Create policy
|
|
@@ -11,6 +11,18 @@ const getCredentials = (config, provider) => {
|
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
switch (provider) {
|
|
14
|
+
case providerEnum_1.ProviderEnum.VOLCENGINE:
|
|
15
|
+
return {
|
|
16
|
+
accessKeyId: config?.accessKeyId ??
|
|
17
|
+
process.env.VOLCSTACK_ACCESS_KEY_ID ??
|
|
18
|
+
process.env.VOLCENGINE_ACCESS_KEY_ID,
|
|
19
|
+
accessKeySecret: config?.accessKeySecret ??
|
|
20
|
+
process.env.VOLCSTACK_SECRET_ACCESS_KEY ??
|
|
21
|
+
process.env.VOLCENGINE_ACCESS_KEY_SECRET,
|
|
22
|
+
securityToken: config?.securityToken ??
|
|
23
|
+
process.env.VOLCSTACK_SESSION_TOKEN ??
|
|
24
|
+
process.env.VOLCENGINE_SESSION_TOKEN,
|
|
25
|
+
};
|
|
14
26
|
case providerEnum_1.ProviderEnum.TENCENT:
|
|
15
27
|
return {
|
|
16
28
|
accessKeyId: config?.accessKeyId ?? process.env.TENCENTCLOUD_SECRET_ID,
|
|
@@ -7,11 +7,13 @@ exports.diffAttributes = exports.attributesEqual = exports.computeDirectoryHash
|
|
|
7
7
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
8
8
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
+
/* istanbul ignore next */
|
|
10
11
|
const computeFileHash = (filePath) => {
|
|
11
12
|
const fileBuffer = node_fs_1.default.readFileSync(filePath);
|
|
12
13
|
return node_crypto_1.default.createHash('sha256').update(fileBuffer).digest('hex');
|
|
13
14
|
};
|
|
14
15
|
exports.computeFileHash = computeFileHash;
|
|
16
|
+
/* istanbul ignore next */
|
|
15
17
|
const computeDirectoryHash = (dirPath) => {
|
|
16
18
|
const files = [];
|
|
17
19
|
const collectFiles = (currentPath) => {
|
|
@@ -105,6 +107,7 @@ const deepEqual = (a, b) => {
|
|
|
105
107
|
* @param b - Second attributes object
|
|
106
108
|
* @returns True if objects are equal, false otherwise
|
|
107
109
|
*/
|
|
110
|
+
/* istanbul ignore next */
|
|
108
111
|
const attributesEqual = (a, b) => {
|
|
109
112
|
return deepEqual(a, b);
|
|
110
113
|
};
|
|
@@ -116,6 +119,7 @@ exports.attributesEqual = attributesEqual;
|
|
|
116
119
|
* @param after - New attributes
|
|
117
120
|
* @returns Object with changed, added, and removed keys
|
|
118
121
|
*/
|
|
122
|
+
/* istanbul ignore next */
|
|
119
123
|
const diffAttributes = (before, after) => {
|
|
120
124
|
const changed = {};
|
|
121
125
|
const added = {};
|
|
@@ -10,12 +10,14 @@ const lodash_1 = require("lodash");
|
|
|
10
10
|
const parser_1 = require("../parser");
|
|
11
11
|
const logger_1 = require("./logger");
|
|
12
12
|
const lang_1 = require("../lang");
|
|
13
|
+
/* istanbul ignore next */
|
|
13
14
|
const resolveCode = (location) => {
|
|
14
15
|
const filePath = node_path_1.default.resolve(process.cwd(), location);
|
|
15
16
|
const fileContent = node_fs_1.default.readFileSync(filePath);
|
|
16
17
|
return fileContent.toString('base64');
|
|
17
18
|
};
|
|
18
19
|
exports.resolveCode = resolveCode;
|
|
20
|
+
/* istanbul ignore next */
|
|
19
21
|
const readCodeSize = (location) => {
|
|
20
22
|
const filePath = node_path_1.default.resolve(process.cwd(), location);
|
|
21
23
|
const stats = node_fs_1.default.statSync(filePath);
|
|
@@ -43,6 +45,7 @@ const inferType = (value, wasTemplateRef) => {
|
|
|
43
45
|
}
|
|
44
46
|
return value;
|
|
45
47
|
};
|
|
48
|
+
/* istanbul ignore next */
|
|
46
49
|
const calcValue = (rawValue, ctx, iacVars) => {
|
|
47
50
|
const containsStage = rawValue.match(/\$\{ctx.stage}/);
|
|
48
51
|
const containsVar = rawValue.match(/\$\{vars.\w+}/);
|
|
@@ -83,6 +86,7 @@ const calcValue = (rawValue, ctx, iacVars) => {
|
|
|
83
86
|
return inferType(value, isExactTemplateRef);
|
|
84
87
|
};
|
|
85
88
|
exports.calcValue = calcValue;
|
|
89
|
+
/* istanbul ignore next */
|
|
86
90
|
const getIacDefinition = (iac, rawValue) => {
|
|
87
91
|
const matchFn = rawValue.match(/^\$\{functions\.(\w+(\.\w+)?)}$/);
|
|
88
92
|
if (matchFn?.length) {
|
|
@@ -91,6 +95,7 @@ const getIacDefinition = (iac, rawValue) => {
|
|
|
91
95
|
return iac.functions?.find((fc) => fc.key === rawValue);
|
|
92
96
|
};
|
|
93
97
|
exports.getIacDefinition = getIacDefinition;
|
|
98
|
+
/* istanbul ignore next */
|
|
94
99
|
const isFunctionDomain = (def) => {
|
|
95
100
|
return def != null && typeof def.key === 'string';
|
|
96
101
|
};
|
|
@@ -20,10 +20,12 @@ class LockError extends Error {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
exports.LockError = LockError;
|
|
23
|
+
/* istanbul ignore next */
|
|
23
24
|
const getLockPath = (statePath) => {
|
|
24
25
|
return `${statePath}${constants_1.LOCK_FILE_SUFFIX}`;
|
|
25
26
|
};
|
|
26
27
|
exports.getLockPath = getLockPath;
|
|
28
|
+
/* istanbul ignore next */
|
|
27
29
|
const generateLockId = () => {
|
|
28
30
|
return node_crypto_1.default.randomBytes(16).toString('hex');
|
|
29
31
|
};
|
|
@@ -117,6 +119,7 @@ const getTimeAgo = (acquiredAt) => {
|
|
|
117
119
|
}
|
|
118
120
|
}
|
|
119
121
|
};
|
|
122
|
+
/* istanbul ignore next */
|
|
120
123
|
const formatLockInfo = (lock) => {
|
|
121
124
|
const acquiredAt = new Date(lock.acquiredAt);
|
|
122
125
|
const timeAgo = getTimeAgo(acquiredAt);
|
|
@@ -134,6 +137,7 @@ exports.formatLockInfo = formatLockInfo;
|
|
|
134
137
|
const sleep = (ms) => {
|
|
135
138
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
136
139
|
};
|
|
140
|
+
/* istanbul ignore next */
|
|
137
141
|
const acquireLockInternal = async (statePath, operation, options = {}) => {
|
|
138
142
|
const timeout = options.timeout ?? constants_1.DEFAULT_LOCK_TIMEOUT;
|
|
139
143
|
const retryDelay = options.retryDelay ?? constants_1.DEFAULT_LOCK_RETRY_DELAY;
|
|
@@ -199,6 +203,7 @@ const acquireLockInternal = async (statePath, operation, options = {}) => {
|
|
|
199
203
|
throw new LockError(`Failed to acquire lock.\n${existingLock ? (0, exports.formatLockInfo)(existingLock) : ''}\nIf you are certain no other operation is running, use:\n si force-unlock ${existingLock?.id || 'unknown'}`, existingLock || undefined);
|
|
200
204
|
};
|
|
201
205
|
exports.acquireLockInternal = acquireLockInternal;
|
|
206
|
+
/* istanbul ignore next */
|
|
202
207
|
const releaseLockInternal = (statePath, lockId) => {
|
|
203
208
|
const lockPath = (0, exports.getLockPath)(statePath);
|
|
204
209
|
const existingLock = readLockFile(lockPath);
|
|
@@ -208,6 +213,7 @@ const releaseLockInternal = (statePath, lockId) => {
|
|
|
208
213
|
}
|
|
209
214
|
};
|
|
210
215
|
exports.releaseLockInternal = releaseLockInternal;
|
|
216
|
+
/* istanbul ignore next */
|
|
211
217
|
const forceUnlock = (statePath, lockId) => {
|
|
212
218
|
const lockPath = (0, exports.getLockPath)(statePath);
|
|
213
219
|
const existingLock = readLockFile(lockPath);
|
|
@@ -221,6 +227,7 @@ const forceUnlock = (statePath, lockId) => {
|
|
|
221
227
|
return true;
|
|
222
228
|
};
|
|
223
229
|
exports.forceUnlock = forceUnlock;
|
|
230
|
+
/* istanbul ignore next */
|
|
224
231
|
const withLock = async (statePath, operation, fn, options) => {
|
|
225
232
|
let lock = null;
|
|
226
233
|
try {
|
|
@@ -235,6 +242,7 @@ const withLock = async (statePath, operation, fn, options) => {
|
|
|
235
242
|
};
|
|
236
243
|
exports.withLock = withLock;
|
|
237
244
|
// Export only for forceUnlock command which needs to read lock info
|
|
245
|
+
/* istanbul ignore next */
|
|
238
246
|
const readLockFileForCommand = (statePath) => {
|
|
239
247
|
const lockPath = (0, exports.getLockPath)(statePath);
|
|
240
248
|
return readLockFile(lockPath);
|
|
@@ -38,6 +38,7 @@ const isSimpleObject = (val) => {
|
|
|
38
38
|
const obj = val;
|
|
39
39
|
return Object.values(obj).every((v) => typeof v !== 'object' || v === null);
|
|
40
40
|
};
|
|
41
|
+
/* istanbul ignore next */
|
|
41
42
|
const computeAttributeDiffs = (before, after) => {
|
|
42
43
|
if (!before && !after)
|
|
43
44
|
return { diffs: [], unchangedCount: 0 };
|
|
@@ -205,6 +206,7 @@ const ACTION_COLOR = {
|
|
|
205
206
|
delete: 'RED',
|
|
206
207
|
refresh: 'CYAN',
|
|
207
208
|
};
|
|
209
|
+
/* istanbul ignore next */
|
|
208
210
|
const formatPlanItem = (item, config = DEFAULT_CONFIG) => {
|
|
209
211
|
const descKey = ACTION_DESC[item.action] ?? 'PLAN_NO_CHANGES';
|
|
210
212
|
const headerLine = ` # ${item.logicalId} ${lang_1.lang.__(descKey)}`;
|
|
@@ -230,6 +232,7 @@ const formatPlanItem = (item, config = DEFAULT_CONFIG) => {
|
|
|
230
232
|
return [headerLine, resourceLine, ...attrLines, ...hiddenLine].join('\n');
|
|
231
233
|
};
|
|
232
234
|
exports.formatPlanItem = formatPlanItem;
|
|
235
|
+
/* istanbul ignore next */
|
|
233
236
|
const formatPlan = (items, config = DEFAULT_CONFIG) => {
|
|
234
237
|
if (items.length === 0) {
|
|
235
238
|
return lang_1.lang.__('NO_CHANGES_INFRASTRUCTURE_UP_TO_DATE');
|
|
@@ -262,6 +265,7 @@ const formatPlan = (items, config = DEFAULT_CONFIG) => {
|
|
|
262
265
|
return [...header, ...itemLines, summary].join('\n');
|
|
263
266
|
};
|
|
264
267
|
exports.formatPlan = formatPlan;
|
|
268
|
+
/* istanbul ignore next */
|
|
265
269
|
const displayPlan = (planResult) => {
|
|
266
270
|
const output = (0, exports.formatPlan)(planResult.items);
|
|
267
271
|
logger_1.logger.info(output);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sleep = void 0;
|
|
4
|
-
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
4
|
+
/* istanbul ignore next */ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
5
5
|
exports.sleep = sleep;
|