Skip to content

Commit 3806665

Browse files
committed
feat(cloud): 添加云服务提供商支持和配置功能
- 更新 `README.md`,增加云服务支持的说明和配置示例 - 在 `go.mod` 中添加阿里云和七牛云相关依赖 - 实现云服务提供商的连接测试和证书上传功能 - 更新配置结构以支持多个云服务提供商的配置 - 修改 protobuf 定义,增加获取提供商信息和执行业务的请求类型 - 重构客户端逻辑以支持云服务的证书管理
1 parent a77204d commit 3806665

File tree

17 files changed

+2389
-326
lines changed

17 files changed

+2389
-326
lines changed

README.md

Lines changed: 91 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- 🚀 **自动化部署**:自动下载证书、解压、部署到指定目录
1010
- 🔄 **智能重载**:自动测试 Nginx 配置并重载服务
1111
- 🌐 **实时通知**:通过长连接接收服务器推送的证书更新通知
12+
- ☁️ **云服务支持**:支持自动上传证书到云服务提供商
1213
- 🛡️ **稳定可靠**:心跳保活、自动重连机制
1314
- 🔧 **守护进程**:支持后台运行,可通过命令管理进程状态
1415
- 📦 **开箱即用**:单一可执行文件,无需依赖
@@ -78,6 +79,8 @@ make build-compress
7879
server:
7980
# 从网站的 设置 -> 个人资料 中获取 AccessKey
8081
accessKey: "your_access_key_here"
82+
# 环境类型:local(本地开发)或 prod(生产环境)
83+
env: "prod"
8184

8285
# SSL 证书配置
8386
ssl:
@@ -104,17 +107,55 @@ update:
104107
# 示例: "socks5://127.0.0.1:1080"
105108
# 注意:也可以通过环境变量 HTTP_PROXY 和 HTTPS_PROXY 设置代理
106109
proxy: ""
110+
111+
# 云服务提供商配置(可选)
112+
# 配置后,工具可以自动将证书上传到对应的云服务
113+
provider:
114+
# 阿里云配置
115+
- name: "aliyun"
116+
remark: "阿里云"
117+
accessKeyId: "your_aliyun_access_key_id"
118+
accessKeySecret: "your_aliyun_access_key_secret"
119+
120+
# 七牛云配置
121+
- name: "qiniu"
122+
remark: "七牛云"
123+
accessKey: "your_qiniu_access_key"
124+
accessSecret: "your_qiniu_access_secret"
125+
126+
# 腾讯云配置(开发中)
127+
# - name: "cloudTencent"
128+
# remark: "腾讯云"
129+
# secretId: "your_tencent_secret_id"
130+
# secretKey: "your_tencent_secret_key"
107131
```
108132

109133
### 配置说明
110134

111-
| 配置项 | 必填 | 说明 |
112-
| ------------------ | ---- | ----------------------------------------------------- |
113-
| `server.accessKey` | ✅ | 从 [anssl.cn](https://anssl.cn) 获取的访问密钥 |
114-
| `ssl.path` | ❌ | 证书存储目录,留空则保存在程序目录下的 `certs` 文件夹 |
135+
| 配置项 | 必填 | 说明 |
136+
| ------------------------- | ---- | ------------------------------------------------------------ |
137+
| `server.accessKey` ||[anssl.cn](https://anssl.cn) 获取的访问密钥 |
138+
| `server.env` || 环境类型:`local`(本地开发)或 `prod`(生产环境),默认生产 |
139+
| `ssl.path` || 证书存储目录,留空则保存在程序目录下的 `certs` 文件夹 |
140+
| `provider` || 云服务提供商配置数组,支持多个提供商 |
141+
| `provider[].name` || 提供商名称:`aliyun`(阿里云)、`qiniu`(七牛云) |
142+
| `provider[].remark` || 备注信息,用于标识 |
143+
| `provider[].accessKeyId` || 阿里云 AccessKey ID(仅阿里云需要) |
144+
| `provider[].accessKeySecret` || 阿里云 AccessKey Secret(仅阿里云需要) |
145+
| `provider[].accessKey` || 七牛云 AccessKey(仅七牛云需要) |
146+
| `provider[].accessSecret` || 七牛云 AccessSecret(仅七牛云需要) |
115147

116148
## 🚀 使用方法
117149

150+
### 部署模式
151+
152+
工具支持两种部署模式:
153+
154+
1. **本地部署模式**`ansslCli`):下载证书到本地服务器并自动重载 Nginx
155+
2. **云服务上传模式**`aliyun``qiniu`):将证书上传到云服务提供商的证书管理平台
156+
157+
部署模式由服务器端根据配置自动选择,你只需要在配置文件中配置相应的云服务提供商凭证即可。
158+
118159
### 基本命令
119160

120161
```bash
@@ -270,6 +311,10 @@ make build-compress
270311
├── main.go # 主程序入口,Cobra CLI 命令定义
271312
├── internal/
272313
│ ├── client/ # RPC 客户端和证书部署逻辑
314+
│ │ ├── providers/ # 云服务提供商实现
315+
│ │ │ ├── aliyun/ # 阿里云提供商
316+
│ │ │ └── qiniu/ # 七牛云提供商
317+
│ │ └── ...
273318
│ ├── config/ # 配置管理
274319
│ ├── scheduler/ # 任务调度器
275320
│ └── system/ # 系统信息收集
@@ -285,6 +330,9 @@ make build-compress
285330
- **配置管理**[Viper](https://github.com/spf13/viper)
286331
- **RPC 通信**[Connect RPC](https://connectrpc.com/)
287332
- **协议**:Protocol Buffers
333+
- **云服务 SDK**
334+
- 阿里云:[Alibaba Cloud SDK](https://github.com/alibabacloud-go)
335+
- 七牛云:[Qiniu Go SDK](https://github.com/qiniu/go-sdk)
288336

289337
## 🐛 故障排除
290338

@@ -341,6 +389,22 @@ make build-compress
341389
- 工具会自动跳过 Nginx 相关操作,证书仍会正常下载
342390
- 如需自动重载功能,请先安装 Nginx
343391

392+
### 云服务上传失败
393+
394+
**问题**:证书上传到云服务失败
395+
396+
**解决方案**
397+
398+
1. **检查配置**:确认 `config.yaml` 中的云服务凭证是否正确
399+
2. **检查权限**:确保 AccessKey 具有 SSL 证书管理权限
400+
3. **查看日志**:使用 `./cert-deploy log` 查看详细错误信息
401+
4. **测试连接**:可以运行测试用例验证云服务连接(需要配置测试凭证)
402+
403+
**常见错误**
404+
- `提供商配置不存在`:检查 `provider` 配置段中的 `name` 是否正确(`aliyun``qiniu`
405+
- `配置不完整`:检查对应云服务的必填字段是否都已填写
406+
- `创建提供商实例失败`:检查 AccessKey 和 Secret 是否正确
407+
344408
## 📝 许可证
345409

346410
MIT License
@@ -363,9 +427,31 @@ MIT License
363427

364428
目前仅支持 Nginx 的自动重载。其他 Web 服务器(如 Apache、Caddy)可以使用本工具下载证书,但需要手动配置服务器重载。
365429

430+
### 2.1. 如何配置云服务提供商?
431+
432+
`config.yaml` 中添加 `provider` 配置段,填写对应云服务的凭证:
433+
434+
**阿里云配置:**
435+
- 登录 [阿里云控制台](https://home.console.aliyun.com/)
436+
- 进入 [访问控制](https://ram.console.aliyun.com/manage/ak) 创建 AccessKey
437+
- 确保 AccessKey 具有 SSL 证书管理权限
438+
439+
**七牛云配置:**
440+
- 登录 [七牛云控制台](https://portal.qiniu.com/)
441+
- 进入 [密钥管理](https://portal.qiniu.com/user/key) 获取 AccessKey 和 SecretKey
442+
443+
配置完成后,当服务器推送证书更新通知时,工具会自动将证书上传到配置的云服务提供商。
444+
366445
### 3. 证书更新频率是多少?
367446

368-
工具通过服务器推送实时接收证书更新通知,无需手动检查。客户端每 5 秒发送一次心跳保持连接。
447+
工具通过服务器推送实时接收证书更新通知,无需手动检查。客户端每 30 秒发送一次心跳保持连接。
448+
449+
### 3.1. 证书会同时部署到本地和云服务吗?
450+
451+
不会。部署模式由服务器端根据你的配置决定:
452+
- 如果配置了云服务提供商凭证,服务器会优先选择云服务上传模式
453+
- 如果没有配置云服务,则使用本地部署模式
454+
- 两种模式不会同时执行
369455

370456
### 4. 如何设置开机自启动?
371457

go.mod

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,39 @@ module github.com/orange-juzipi/cert-deploy
33
go 1.25
44

55
require (
6-
connectrpc.com/connect v1.19.0
6+
connectrpc.com/connect v1.19.1
7+
github.com/alibabacloud-go/cas-20200407/v4 v4.0.3
8+
github.com/alibabacloud-go/darabonba-openapi/v2 v2.1.13
9+
github.com/alibabacloud-go/tea v1.3.13
10+
github.com/alibabacloud-go/tea-utils/v2 v2.0.7
11+
github.com/qiniu/go-sdk/v7 v7.25.4
712
github.com/spf13/cobra v1.10.1
813
github.com/spf13/viper v1.21.0
9-
golang.org/x/net v0.46.0
10-
google.golang.org/protobuf v1.36.9
14+
google.golang.org/protobuf v1.36.10
1115
)
1216

1317
require (
18+
github.com/BurntSushi/toml v1.5.0 // indirect
19+
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.5 // indirect
20+
github.com/alibabacloud-go/debug v1.0.1 // indirect
21+
github.com/aliyun/credentials-go v1.4.8 // indirect
22+
github.com/clbanning/mxj/v2 v2.7.0 // indirect
1423
github.com/fsnotify/fsnotify v1.9.0 // indirect
1524
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
1625
github.com/inconshreveable/mousetrap v1.1.0 // indirect
26+
github.com/json-iterator/go v1.1.12 // indirect
27+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
28+
github.com/modern-go/reflect2 v1.0.2 // indirect
1729
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
1830
github.com/sagikazarmark/locafero v0.12.0 // indirect
1931
github.com/spf13/afero v1.15.0 // indirect
2032
github.com/spf13/cast v1.10.0 // indirect
2133
github.com/spf13/pflag v1.0.10 // indirect
2234
github.com/subosito/gotenv v1.6.0 // indirect
35+
github.com/tjfoc/gmsm v1.4.1 // indirect
2336
go.yaml.in/yaml/v3 v3.0.4 // indirect
37+
golang.org/x/net v0.46.0 // indirect
2438
golang.org/x/sys v0.37.0 // indirect
2539
golang.org/x/text v0.30.0 // indirect
26-
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
40+
gopkg.in/ini.v1 v1.67.0 // indirect
2741
)

0 commit comments

Comments
 (0)