@geek-fun/serverlessinsight 0.5.10 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -1
- package/README.zh-CN.md +94 -1
- package/dist/package.json +3 -1
- package/dist/src/common/aliyunClient/apigwOperations.js +5 -5
- package/dist/src/common/aliyunClient/casOperations.js +116 -0
- package/dist/src/common/aliyunClient/index.js +8 -0
- package/dist/src/common/aliyunClient/ossOperations.js +290 -18
- package/dist/src/common/certificateResolver.js +63 -0
- package/dist/src/common/constants.js +10 -4
- package/dist/src/common/iacHelper.js +9 -1
- package/dist/src/common/index.js +2 -0
- package/dist/src/common/planFormatter.js +269 -0
- package/dist/src/common/retryUtils.js +5 -0
- package/dist/src/common/tencentClient/index.js +18 -0
- package/dist/src/common/tencentClient/sslOperations.js +107 -0
- package/dist/src/lang/en.js +86 -1
- package/dist/src/lang/zh-CN.js +84 -0
- package/dist/src/parser/bucketParser.js +19 -1
- package/dist/src/parser/certificateParser.js +23 -0
- package/dist/src/parser/index.js +2 -0
- package/dist/src/stack/aliyunStack/apigwResource.js +41 -14
- package/dist/src/stack/aliyunStack/apigwTypes.js +32 -2
- package/dist/src/stack/aliyunStack/ossResource.js +44 -5
- package/dist/src/stack/localStack/event.js +1 -1
- package/dist/src/stack/scfStack/cosResource.js +35 -4
- package/dist/src/stack/scfStack/planner.js +1 -57
- package/dist/src/types/domains/certificate.js +2 -0
- package/dist/src/types/index.js +1 -0
- package/dist/src/validator/bucketSchema.js +23 -1
- package/dist/src/validator/certificateSchema.js +31 -0
- package/dist/src/validator/eventSchema.js +12 -0
- package/dist/src/validator/iacSchema.js +2 -0
- package/dist/src/validator/rootSchema.js +3 -0
- package/dist/src/validator/templateRefSchema.js +3 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -37,6 +37,7 @@ Whether you're building on AWS, Alibaba Cloud, Huawei Cloud, or other providers,
|
|
|
37
37
|
- 🏠 **Local Testing** - Run and debug serverless functions locally
|
|
38
38
|
- 🔄 **Template Generation** - Generate provider-specific IaC templates
|
|
39
39
|
- 🌐 **API Gateway Integration** - Configure HTTP endpoints for your functions
|
|
40
|
+
- 🌐 **Custom Domain Binding** - Automatic domain binding with DNS verification for OSS and API Gateway
|
|
40
41
|
- 💾 **Resource Management** - Manage storage, databases, and other cloud resources
|
|
41
42
|
- 🔐 **Security First** - Built-in validation and security best practices
|
|
42
43
|
- 📊 **Comprehensive Logging** - Debug and monitor your applications
|
|
@@ -143,10 +144,10 @@ For more examples, check out the [samples](./samples) directory:
|
|
|
143
144
|
|
|
144
145
|
- [API Gateway Example](./samples/aliyun-poc-api.yml) - Deploy functions with HTTP endpoints
|
|
145
146
|
- [Storage Example](./samples/aliyun-poc-bucket.yml) - Configure OSS buckets
|
|
147
|
+
- [Custom Domain Example](./samples/aliyun-poc-domain.yml) - Configure OSS static website with custom domain binding
|
|
146
148
|
- [Database Example](./samples/aliyun-poc-rds.yml) - Set up RDS databases
|
|
147
149
|
- [Table Store Example](./samples/aliyun-poc-table.yml) - Configure OTS table storage
|
|
148
150
|
- [Elasticsearch Example](./samples/aliyun-poc-es.yml) - Deploy Elasticsearch Serverless
|
|
149
|
-
- [Custom Domain Example](./samples/aliyun-poc-domain.yml) - Configure custom domains
|
|
150
151
|
- [GPU Functions Example](./samples/aliyun-poc-fc-gpu.yml) - Deploy GPU-enabled functions
|
|
151
152
|
- [Huawei Cloud Example](./samples/huawei-poc-fc.yml) - Deploy to Huawei Cloud FunctionGraph
|
|
152
153
|
|
|
@@ -249,6 +250,98 @@ This architecture enables:
|
|
|
249
250
|
|
|
250
251
|
---
|
|
251
252
|
|
|
253
|
+
## 🌐 Custom Domain Binding
|
|
254
|
+
|
|
255
|
+
ServerlessInsight provides automatic custom domain binding for OSS buckets and API Gateway with built-in DNS verification.
|
|
256
|
+
|
|
257
|
+
### OSS Custom Domain Binding
|
|
258
|
+
|
|
259
|
+
When you configure a custom domain for an OSS bucket (static website hosting), ServerlessInsight automatically:
|
|
260
|
+
|
|
261
|
+
1. **Binds the domain** to your OSS bucket
|
|
262
|
+
2. **Creates DNS CNAME records** pointing to the correct OSS endpoint
|
|
263
|
+
3. **Handles domain ownership verification** via DNS TXT records when required by the cloud provider
|
|
264
|
+
4. **Manages retry logic** with DNS propagation polling for reliable binding
|
|
265
|
+
|
|
266
|
+
```yaml
|
|
267
|
+
buckets:
|
|
268
|
+
my_website:
|
|
269
|
+
name: my-website-bucket
|
|
270
|
+
security:
|
|
271
|
+
acl: PUBLIC_READ
|
|
272
|
+
website:
|
|
273
|
+
code: ./dist
|
|
274
|
+
domain: www.example.com # Custom domain binding
|
|
275
|
+
index: index.html
|
|
276
|
+
error_page: 404.html
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### Domain Ownership Verification Flow
|
|
280
|
+
|
|
281
|
+
When binding a custom domain that requires ownership verification:
|
|
282
|
+
|
|
283
|
+
```
|
|
284
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
285
|
+
│ OSS Custom Domain Binding │
|
|
286
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
287
|
+
│
|
|
288
|
+
▼
|
|
289
|
+
┌───────────────────────┐
|
|
290
|
+
│ PutCname (Attempt) │
|
|
291
|
+
└───────────────────────┘
|
|
292
|
+
│
|
|
293
|
+
┌───────────────────┴───────────────────┐
|
|
294
|
+
│ │
|
|
295
|
+
▼ ▼
|
|
296
|
+
┌───────────────┐ ┌─────────────────┐
|
|
297
|
+
│ Success │ │ NeedVerifyDomain│
|
|
298
|
+
└───────────────┘ │ Ownership │
|
|
299
|
+
└─────────────────┘
|
|
300
|
+
│
|
|
301
|
+
▼
|
|
302
|
+
┌─────────────────────────┐
|
|
303
|
+
│ CreateCnameToken API │
|
|
304
|
+
│ (Get TXT record value) │
|
|
305
|
+
└─────────────────────────┘
|
|
306
|
+
│
|
|
307
|
+
▼
|
|
308
|
+
┌─────────────────────────┐
|
|
309
|
+
│ Check existing TXT │
|
|
310
|
+
│ records (avoid dupes) │
|
|
311
|
+
└─────────────────────────┘
|
|
312
|
+
│
|
|
313
|
+
▼
|
|
314
|
+
┌─────────────────────────┐
|
|
315
|
+
│ Add DNS TXT Record │
|
|
316
|
+
│ (_dnsauth.domain) │
|
|
317
|
+
└─────────────────────────┘
|
|
318
|
+
│
|
|
319
|
+
▼
|
|
320
|
+
┌─────────────────────────┐
|
|
321
|
+
│ Poll DNS Propagation │
|
|
322
|
+
│ (up to 10 × 1 min) │
|
|
323
|
+
└─────────────────────────┘
|
|
324
|
+
│
|
|
325
|
+
▼
|
|
326
|
+
┌─────────────────────────┐
|
|
327
|
+
│ Retry PutCname │
|
|
328
|
+
│ (up to 5 × 30 sec) │
|
|
329
|
+
└─────────────────────────┘
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### Supported Domain Types
|
|
333
|
+
|
|
334
|
+
For OSS static website hosting, ServerlessInsight supports:
|
|
335
|
+
|
|
336
|
+
| Domain Type | CNAME Target | Use Case |
|
|
337
|
+
| ----------------- | -------------------------------- | ---------------------------------------------- |
|
|
338
|
+
| Root domain (`@`) | `bucket.region.taihangcda.cn` | Bypasses DNS CNAME restriction on root domains |
|
|
339
|
+
| Subdomain (`www`) | `bucket.oss-region.aliyuncs.com` | Standard OSS endpoint |
|
|
340
|
+
|
|
341
|
+
For detailed configuration, see [OSS Custom Domain Binding Guide](./docs/oss-custom-domain-binding.md).
|
|
342
|
+
|
|
343
|
+
---
|
|
344
|
+
|
|
252
345
|
## 🗄️ State Management
|
|
253
346
|
|
|
254
347
|
ServerlessInsight uses a state-based deployment model that tracks all deployed resources in a local state file (`.serverlessinsight/state-{app}-{service}.json` in the project directory). This enables:
|
package/README.zh-CN.md
CHANGED
|
@@ -37,6 +37,7 @@ ServerlessInsight 是一个强大的 Serverless 框架,用于跨多个云服
|
|
|
37
37
|
- 🏠 **本地测试** - 在本地运行和调试 Serverless 函数
|
|
38
38
|
- 🔄 **模板生成** - 生成特定云服务商的 IaC 模板
|
|
39
39
|
- 🌐 **API 网关集成** - 为您的函数配置 HTTP 端点
|
|
40
|
+
- 🌐 **自定义域名绑定** - 支持 OSS 和 API 网关的自动域名绑定与 DNS 验证
|
|
40
41
|
- 💾 **资源管理** - 管理存储、数据库和其他云资源
|
|
41
42
|
- 🔐 **安全优先** - 内置验证和安全最佳实践
|
|
42
43
|
- 📊 **全面的日志记录** - 调试和监控您的应用
|
|
@@ -143,10 +144,10 @@ events:
|
|
|
143
144
|
|
|
144
145
|
- [API 网关示例](./samples/aliyun-poc-api.yml) - 部署带 HTTP 端点的函数
|
|
145
146
|
- [存储示例](./samples/aliyun-poc-bucket.yml) - 配置 OSS 存储桶
|
|
147
|
+
- [自定义域名示例](./samples/aliyun-poc-domain.yml) - 配置 OSS 静态网站托管与自定义域名绑定
|
|
146
148
|
- [数据库示例](./samples/aliyun-poc-rds.yml) - 设置 RDS 数据库
|
|
147
149
|
- [表格存储示例](./samples/aliyun-poc-table.yml) - 配置 OTS 表格存储
|
|
148
150
|
- [Elasticsearch 示例](./samples/aliyun-poc-es.yml) - 部署 Elasticsearch Serverless
|
|
149
|
-
- [自定义域名示例](./samples/aliyun-poc-domain.yml) - 配置自定义域名
|
|
150
151
|
- [GPU 函数示例](./samples/aliyun-poc-fc-gpu.yml) - 部署支持 GPU 的函数
|
|
151
152
|
- [华为云示例](./samples/huawei-poc-fc.yml) - 部署到华为云 FunctionGraph
|
|
152
153
|
|
|
@@ -176,6 +177,98 @@ npm run lint:check
|
|
|
176
177
|
|
|
177
178
|
---
|
|
178
179
|
|
|
180
|
+
## 🌐 自定义域名绑定
|
|
181
|
+
|
|
182
|
+
ServerlessInsight 为 OSS 存储桶和 API 网关提供自动化的自定义域名绑定,内置 DNS 验证功能。
|
|
183
|
+
|
|
184
|
+
### OSS 自定义域名绑定
|
|
185
|
+
|
|
186
|
+
当您为 OSS 存储桶(静态网站托管)配置自定义域名时,ServerlessInsight 会自动:
|
|
187
|
+
|
|
188
|
+
1. **绑定域名**到您的 OSS 存储桶
|
|
189
|
+
2. **创建 DNS CNAME 记录**,指向正确的 OSS Endpoint
|
|
190
|
+
3. **处理域名所有权验证**,通过 DNS TXT 记录完成云服务商要求的验证
|
|
191
|
+
4. **管理重试逻辑**,通过 DNS 传播轮询确保绑定可靠
|
|
192
|
+
|
|
193
|
+
```yaml
|
|
194
|
+
buckets:
|
|
195
|
+
my_website:
|
|
196
|
+
name: my-website-bucket
|
|
197
|
+
security:
|
|
198
|
+
acl: PUBLIC_READ
|
|
199
|
+
website:
|
|
200
|
+
code: ./dist
|
|
201
|
+
domain: www.example.com # 自定义域名绑定
|
|
202
|
+
index: index.html
|
|
203
|
+
error_page: 404.html
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### 域名所有权验证流程
|
|
207
|
+
|
|
208
|
+
当绑定需要所有权验证的自定义域名时:
|
|
209
|
+
|
|
210
|
+
```
|
|
211
|
+
┌─────────────────────────────────────────────────────────────────┐
|
|
212
|
+
│ OSS 自定义域名绑定流程 │
|
|
213
|
+
└─────────────────────────────────────────────────────────────────┘
|
|
214
|
+
│
|
|
215
|
+
▼
|
|
216
|
+
┌───────────────────────┐
|
|
217
|
+
│ PutCname (首次尝试) │
|
|
218
|
+
└───────────────────────┘
|
|
219
|
+
│
|
|
220
|
+
┌───────────────────┴───────────────────┐
|
|
221
|
+
│ │
|
|
222
|
+
▼ ▼
|
|
223
|
+
┌───────────────┐ ┌─────────────────┐
|
|
224
|
+
│ 绑定成功 │ │ 需要域名所有权 │
|
|
225
|
+
└───────────────┘ │ 验证 │
|
|
226
|
+
└─────────────────┘
|
|
227
|
+
│
|
|
228
|
+
▼
|
|
229
|
+
┌─────────────────────────┐
|
|
230
|
+
│ CreateCnameToken API │
|
|
231
|
+
│ (获取 TXT 记录值) │
|
|
232
|
+
└─────────────────────────┘
|
|
233
|
+
│
|
|
234
|
+
▼
|
|
235
|
+
┌─────────────────────────┐
|
|
236
|
+
│ 检查现有 TXT 记录 │
|
|
237
|
+
│ (避免重复创建) │
|
|
238
|
+
└─────────────────────────┘
|
|
239
|
+
│
|
|
240
|
+
▼
|
|
241
|
+
┌─────────────────────────┐
|
|
242
|
+
│ 添加 DNS TXT 记录 │
|
|
243
|
+
│ (_dnsauth.domain) │
|
|
244
|
+
└─────────────────────────┘
|
|
245
|
+
│
|
|
246
|
+
▼
|
|
247
|
+
┌─────────────────────────┐
|
|
248
|
+
│ 轮询 DNS 传播状态 │
|
|
249
|
+
│ (最多 10 次 × 1 分钟) │
|
|
250
|
+
└─────────────────────────┘
|
|
251
|
+
│
|
|
252
|
+
▼
|
|
253
|
+
┌─────────────────────────┐
|
|
254
|
+
│ 重试 PutCname │
|
|
255
|
+
│ (最多 5 次 × 30 秒) │
|
|
256
|
+
└─────────────────────────┘
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### 支持的域名类型
|
|
260
|
+
|
|
261
|
+
对于 OSS 静态网站托管,ServerlessInsight 支持:
|
|
262
|
+
|
|
263
|
+
| 域名类型 | CNAME 目标 | 使用场景 |
|
|
264
|
+
| -------------- | -------------------------------- | --------------------------- |
|
|
265
|
+
| 根域名 (`@`) | `bucket.region.taihangcda.cn` | 绕过根域名的 DNS CNAME 限制 |
|
|
266
|
+
| 子域名 (`www`) | `bucket.oss-region.aliyuncs.com` | 标准 OSS Endpoint |
|
|
267
|
+
|
|
268
|
+
详细配置请参考 [OSS 自定义域名绑定指南](./docs/oss-custom-domain-binding.md)。
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
179
272
|
## 📘 文档
|
|
180
273
|
|
|
181
274
|
完整文档请访问 [serverlessinsight.geekfun.club](https://serverlessinsight.geekfun.club)
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geek-fun/serverlessinsight",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Full life cycle cross providers serverless application management for your fast-growing business.",
|
|
5
5
|
"homepage": "https://serverlessinsight.geekfun.club",
|
|
6
6
|
"main": "dist/src/index.js",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@alicloud/alidns20150109": "^4.3.1",
|
|
53
|
+
"@alicloud/cas20200407": "^3.2.0",
|
|
53
54
|
"@alicloud/cloudapi20160714": "^4.7.9",
|
|
54
55
|
"@alicloud/ecs20140526": "^7.6.0",
|
|
55
56
|
"@alicloud/es-serverless20230627": "^2.3.0",
|
|
@@ -75,6 +76,7 @@
|
|
|
75
76
|
"tencentcloud-sdk-nodejs-dnspod": "^4.1.197",
|
|
76
77
|
"tencentcloud-sdk-nodejs-es": "^4.1.183",
|
|
77
78
|
"tencentcloud-sdk-nodejs-scf": "^4.1.168",
|
|
79
|
+
"tencentcloud-sdk-nodejs-ssl": "^4.1.191",
|
|
78
80
|
"yaml": "^2.8.2"
|
|
79
81
|
},
|
|
80
82
|
"devDependencies": {
|
|
@@ -43,10 +43,10 @@ const stateManager_1 = require("../stateManager");
|
|
|
43
43
|
const sidUtils_1 = require("../sidUtils");
|
|
44
44
|
const domainUtils_1 = require("../domainUtils");
|
|
45
45
|
const constants_1 = require("../constants");
|
|
46
|
+
const retryUtils_1 = require("../retryUtils");
|
|
46
47
|
const removeUndefined = (obj) => {
|
|
47
48
|
return Object.fromEntries(Object.entries(obj).filter(([, value]) => value !== undefined));
|
|
48
49
|
};
|
|
49
|
-
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
50
50
|
const isNetworkTimeoutError = (error) => {
|
|
51
51
|
if (!error || typeof error !== 'object')
|
|
52
52
|
return false;
|
|
@@ -103,7 +103,7 @@ const createApigwOperations = (apigwClient, dnsClient, _context) => {
|
|
|
103
103
|
attempt: String(attempt),
|
|
104
104
|
max: String(maxAttempts),
|
|
105
105
|
}));
|
|
106
|
-
await sleep(delayMs);
|
|
106
|
+
await (0, retryUtils_1.sleep)(delayMs);
|
|
107
107
|
const propagated = await checkPropagation();
|
|
108
108
|
if (propagated) {
|
|
109
109
|
logger_1.logger.info(lang_1.lang.__('APIGW_DNS_VERIFIED', { minutes: String(attempt) }));
|
|
@@ -135,7 +135,7 @@ const createApigwOperations = (apigwClient, dnsClient, _context) => {
|
|
|
135
135
|
return true;
|
|
136
136
|
}
|
|
137
137
|
if (attempt < constants_1.APIGW_DNS_PUBLIC_RESOLUTION_MAX_ATTEMPTS) {
|
|
138
|
-
await sleep(constants_1.APIGW_DNS_PUBLIC_RESOLUTION_DELAY_MS);
|
|
138
|
+
await (0, retryUtils_1.sleep)(constants_1.APIGW_DNS_PUBLIC_RESOLUTION_DELAY_MS);
|
|
139
139
|
}
|
|
140
140
|
}
|
|
141
141
|
logger_1.logger.warn(lang_1.lang.__('APIGW_PUBLIC_DNS_TIMEOUT', { domain: domainName }));
|
|
@@ -706,7 +706,7 @@ const createApigwOperations = (apigwClient, dnsClient, _context) => {
|
|
|
706
706
|
attempt: String(attempt),
|
|
707
707
|
max: String(constants_1.APIGW_DOMAIN_BIND_MAX_RETRIES),
|
|
708
708
|
}));
|
|
709
|
-
await sleep(constants_1.APIGW_DOMAIN_BIND_RETRY_DELAY_MS);
|
|
709
|
+
await (0, retryUtils_1.sleep)(constants_1.APIGW_DOMAIN_BIND_RETRY_DELAY_MS);
|
|
710
710
|
try {
|
|
711
711
|
await apigwClient.setDomain(setDomainRequest);
|
|
712
712
|
await setCertificate();
|
|
@@ -756,7 +756,7 @@ const createApigwOperations = (apigwClient, dnsClient, _context) => {
|
|
|
756
756
|
attempt: String(attempt),
|
|
757
757
|
max: String(constants_1.APIGW_DOMAIN_BIND_MAX_RETRIES),
|
|
758
758
|
}));
|
|
759
|
-
await sleep(constants_1.APIGW_DOMAIN_BIND_RETRY_DELAY_MS);
|
|
759
|
+
await (0, retryUtils_1.sleep)(constants_1.APIGW_DOMAIN_BIND_RETRY_DELAY_MS);
|
|
760
760
|
try {
|
|
761
761
|
await apigwClient.setDomain(setDomainRequest);
|
|
762
762
|
await setCertificate();
|
|
@@ -0,0 +1,116 @@
|
|
|
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.createCasOperations = void 0;
|
|
37
|
+
const cas = __importStar(require("@alicloud/cas20200407"));
|
|
38
|
+
const lang_1 = require("../../lang");
|
|
39
|
+
const logger_1 = require("../logger");
|
|
40
|
+
const createCasOperations = (casClient) => {
|
|
41
|
+
return {
|
|
42
|
+
uploadCertificate: async (name, cert, key, chain) => {
|
|
43
|
+
logger_1.logger.info(lang_1.lang.__('CAS_UPLOADING_CERT', { name }));
|
|
44
|
+
const request = new cas.UploadUserCertificateRequest({
|
|
45
|
+
name,
|
|
46
|
+
cert: chain ? `${cert}\n${chain}` : cert,
|
|
47
|
+
key,
|
|
48
|
+
});
|
|
49
|
+
const response = await casClient.uploadUserCertificate(request);
|
|
50
|
+
const certId = response.body?.certId;
|
|
51
|
+
if (certId == null) {
|
|
52
|
+
throw new Error(lang_1.lang.__('CAS_UPLOAD_NO_CERT_ID', { name }));
|
|
53
|
+
}
|
|
54
|
+
logger_1.logger.info(lang_1.lang.__('CAS_CERT_UPLOADED', { name, certId: String(certId) }));
|
|
55
|
+
return {
|
|
56
|
+
certificateId: certId,
|
|
57
|
+
name,
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
getCertificate: async (certificateId) => {
|
|
61
|
+
const numericId = Number(certificateId);
|
|
62
|
+
if (Number.isNaN(numericId)) {
|
|
63
|
+
throw new Error(lang_1.lang.__('CERT_INVALID_CONFIGURATION', { name: certificateId }));
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
const request = new cas.GetUserCertificateDetailRequest({
|
|
67
|
+
certId: numericId,
|
|
68
|
+
certFilter: false,
|
|
69
|
+
});
|
|
70
|
+
const response = await casClient.getUserCertificateDetail(request);
|
|
71
|
+
const body = response.body;
|
|
72
|
+
if (!body) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
certificateId: body.id ?? numericId,
|
|
77
|
+
name: body.name ?? undefined,
|
|
78
|
+
cert: body.cert ?? undefined,
|
|
79
|
+
key: body.key ?? undefined,
|
|
80
|
+
endDate: body.endDate ?? undefined,
|
|
81
|
+
expired: body.expired ?? undefined,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
if (error &&
|
|
86
|
+
typeof error === 'object' &&
|
|
87
|
+
'code' in error &&
|
|
88
|
+
(error.code === 'CertNotExist' || error.code === 'NotFound')) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
deleteCertificate: async (certificateId) => {
|
|
95
|
+
logger_1.logger.info(lang_1.lang.__('CAS_DELETING_CERT', { certId: String(certificateId) }));
|
|
96
|
+
const request = new cas.DeleteUserCertificateRequest({
|
|
97
|
+
certId: certificateId,
|
|
98
|
+
});
|
|
99
|
+
try {
|
|
100
|
+
await casClient.deleteUserCertificate(request);
|
|
101
|
+
logger_1.logger.info(lang_1.lang.__('CAS_CERT_DELETED', { certId: String(certificateId) }));
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (error &&
|
|
105
|
+
typeof error === 'object' &&
|
|
106
|
+
'code' in error &&
|
|
107
|
+
(error.code === 'CertNotExist' || error.code === 'NotFound')) {
|
|
108
|
+
logger_1.logger.warn(lang_1.lang.__('CAS_CERT_NOT_FOUND', { certId: String(certificateId) }));
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
throw error;
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
exports.createCasOperations = createCasOperations;
|
|
@@ -49,6 +49,7 @@ const cloudapi20160714_1 = __importDefault(require("@alicloud/cloudapi20160714")
|
|
|
49
49
|
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
|
+
const cas20200407_1 = __importDefault(require("@alicloud/cas20200407"));
|
|
52
53
|
const $OpenApi = __importStar(require("@alicloud/openapi-client"));
|
|
53
54
|
const ali_oss_1 = __importDefault(require("ali-oss"));
|
|
54
55
|
const constants_1 = require("../constants");
|
|
@@ -63,6 +64,7 @@ const rdsOperations_1 = require("./rdsOperations");
|
|
|
63
64
|
const esOperations_1 = require("./esOperations");
|
|
64
65
|
const tablestoreOperations_1 = require("./tablestoreOperations");
|
|
65
66
|
const dnsOperations_1 = require("./dnsOperations");
|
|
67
|
+
const casOperations_1 = require("./casOperations");
|
|
66
68
|
__exportStar(require("./types"), exports);
|
|
67
69
|
__exportStar(require("./apigwOperations"), exports);
|
|
68
70
|
__exportStar(require("./ossOperations"), exports);
|
|
@@ -70,6 +72,7 @@ __exportStar(require("./rdsOperations"), exports);
|
|
|
70
72
|
__exportStar(require("./esOperations"), exports);
|
|
71
73
|
__exportStar(require("./tablestoreOperations"), exports);
|
|
72
74
|
__exportStar(require("./dnsOperations"), exports);
|
|
75
|
+
__exportStar(require("./casOperations"), exports);
|
|
73
76
|
const initializeSdkClients = (context) => {
|
|
74
77
|
const baseConfig = {
|
|
75
78
|
accessKeyId: context.accessKeyId,
|
|
@@ -112,6 +115,9 @@ const initializeSdkClients = (context) => {
|
|
|
112
115
|
const dnsConfig = new $OpenApi.Config(baseConfig);
|
|
113
116
|
dnsConfig.endpoint = `alidns.aliyuncs.com`;
|
|
114
117
|
const dnsClient = new alidns20150109_1.default(dnsConfig);
|
|
118
|
+
const casConfig = new $OpenApi.Config(baseConfig);
|
|
119
|
+
casConfig.endpoint = `cas.aliyuncs.com`;
|
|
120
|
+
const casClient = new cas20200407_1.default(casConfig);
|
|
115
121
|
return {
|
|
116
122
|
fc3: fc3Client,
|
|
117
123
|
sls: slsClient,
|
|
@@ -123,6 +129,7 @@ const initializeSdkClients = (context) => {
|
|
|
123
129
|
rds: rdsClient,
|
|
124
130
|
es: esClient,
|
|
125
131
|
dns: dnsClient,
|
|
132
|
+
cas: casClient,
|
|
126
133
|
};
|
|
127
134
|
};
|
|
128
135
|
const createAliyunClient = (context) => {
|
|
@@ -138,6 +145,7 @@ const createAliyunClient = (context) => {
|
|
|
138
145
|
apigw: (0, apigwOperations_1.createApigwOperations)(sdkClients.apigw, sdkClients.dns, context),
|
|
139
146
|
rds: (0, rdsOperations_1.createRdsOperations)(sdkClients.rds, context),
|
|
140
147
|
es: (0, esOperations_1.createEsOperations)(sdkClients.es, context),
|
|
148
|
+
cas: (0, casOperations_1.createCasOperations)(sdkClients.cas),
|
|
141
149
|
dns: dnsOps,
|
|
142
150
|
tablestore: (instanceName) => (0, tablestoreOperations_1.createTablestoreOperations)(`https://${instanceName}.${context.region}.ots.aliyuncs.com`, instanceName, context),
|
|
143
151
|
};
|