Skip to content

Commit

Permalink
add tencent cdn deployer
Browse files Browse the repository at this point in the history
  • Loading branch information
usual2970 committed Aug 29, 2024
1 parent 1861e73 commit 1e11b23
Show file tree
Hide file tree
Showing 15 changed files with 288 additions and 128 deletions.
43 changes: 20 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@ Certimate 是一个开源的 SSL 证书管理工具,具有以下特点:
Certimate 旨在为用户提供一个安全、简便的 SSL 证书管理解决方案。

- [Certimate](#certimate)
- [安装](#安装)
- [二进制文件](#二进制文件)
- [Docker 安装](#docker-安装)
- [默认账号:](#默认账号)
- [概念](#概念)
- [域名](#域名)
- [dns 服务商授权信息](#dns-服务商授权信息)
- [部署服务商授权信息](#部署服务商授权信息)
- [使用](#使用)
- [一、安装](#一安装)
- [1. 二进制文件](#1-二进制文件)
- [2. Docker 安装](#2-docker-安装)
- [二、概念](#二概念)
- [1. 域名](#1-域名)
- [2. dns 服务商授权信息](#2-dns-服务商授权信息)
- [3. 部署服务商授权信息](#3-部署服务商授权信息)
- [三、使用](#三使用)
- [许可证](#许可证)



## 安装
## 一、安装

### 二进制文件
### 1. 二进制文件

你可以直接从[Releases 页](https://github.com/usual2970/certimate/releases)下载预先编译好的二进制文件,解压后执行:

Expand All @@ -39,7 +38,7 @@ Certimate 旨在为用户提供一个安全、简便的 SSL 证书管理解决
```


### Docker 安装
### 2. Docker 安装

```bash

Expand All @@ -49,29 +48,27 @@ git clone [email protected]:usual2970/certimate.git && cd certimate/docker && docke

然后在浏览器中访问 http://127.0.0.1:8090 即可访问 Certimate 管理页面。

### 默认账号:

```bash
用户名:[email protected]
密码:1234567890
```

## 概念
## 二、概念

Certimate 的工作流程如下:

1. 用户通过 Certimate 管理页面填写申请证书的信息,包括域名、dns 服务商的授权信息、以及要部署到的服务商的授权信息。
2. Certimate 向证书场商的 API 发起申请请求,获取 SSL 证书。
3. Certimate 存储证书信息,包括证书内容、私钥、证书有效期等,并在证书即将过期时自动续期。
4. Certimate 向服务商的 API 发起部署请求,将证书部署到服务商的服务器上。
* 用户通过 Certimate 管理页面填写申请证书的信息,包括域名、dns 服务商的授权信息、以及要部署到的服务商的授权信息。
* Certimate 向证书场商的 API 发起申请请求,获取 SSL 证书。
* Certimate 存储证书信息,包括证书内容、私钥、证书有效期等,并在证书即将过期时自动续期。
* Certimate 向服务商的 API 发起部署请求,将证书部署到服务商的服务器上。

这就涉及域名、dns 服务商的授权信息、部署服务商的授权信息等。

### 域名
### 1. 域名

就是要申请证书的域名。

### dns 服务商授权信息
### 2. dns 服务商授权信息

给域名申请证书需要证明域名是你的,所以我们手动申请证书的时候一般需要在域名服务商的控制台解析记录中添加一个 TXT 记录。

Expand All @@ -91,13 +88,13 @@ secretId: xxx
secretKey: TOKEN
```

### 部署服务商授权信息
### 3. 部署服务商授权信息

Certimate 申请证书后,会自动将证书部署到你指定的目标上,比如阿里云 CDN 这时你需要填写阿里云的授权信息。Certimate 会根据你填写的授权信息及域名找到对应的 CDN 服务,并将证书部署到对应的 CDN 服务上。

部署服务商授权信息和 dns 服务商授权信息一致,区别在于 dns 服务商授权信息用于证明域名是你的,部署服务商授权信息用于提供证书部署的授权信息。

## 使用
## 三、使用

![Alt text](usage.gif)

Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ require (
github.com/pkg/sftp v1.13.6
github.com/pocketbase/dbx v1.10.1
github.com/pocketbase/pocketbase v0.22.18
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.992
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl v1.0.992
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tag v1.0.992
golang.org/x/crypto v0.26.0
)

Expand Down Expand Up @@ -90,7 +93,6 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.898 // indirect
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.898 // indirect
github.com/tjfoc/gmsm v1.3.2 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
Expand Down
7 changes: 6 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,15 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.898 h1:ERwcXqhc94L9cFxtiI0pvt7IJtlHl/p/Jayl3mLw+ms=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.898/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.992 h1:266lOve+E8vzhnrb/Mr05Ee+oxXD9C82JiusY/AZqXw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.992/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.898 h1:LoYv5u+gUoFpU/AmIuTRG/2KiEkdm9gCC0dTvk8WITQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/dnspod v1.0.898/go.mod h1:c1j6YQ+vCbeA8kJ59Im4UnMd1GxovlpPBDhGZoewfn8=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl v1.0.992 h1:A6O89OlCJQUpNxGqC/E5By04UNKBryIt5olQIGOx8mg=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl v1.0.992/go.mod h1:BcvC7ZPdSlhRggVq4J1ToJlgv8bmODIAuSo0naFZOLo=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tag v1.0.992 h1:ttCM2rrkGipHMFTavrPExKCWcfNjT7AMQ5ERrPExdI4=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tag v1.0.992/go.mod h1:WtzarrflM+eoyD8vcRuIPd8fT5UXD4IhUry6iSAUnxc=
github.com/tjfoc/gmsm v1.3.2 h1:7JVkAn5bvUJ7HtU08iW6UiD+UTmJTIToHCfeFzkcCxM=
github.com/tjfoc/gmsm v1.3.2/go.mod h1:HaUcFuY0auTiaHB9MHFGCPx5IaLhTUd2atbCFBQXn9w=
github.com/uber/jaeger-client-go v2.30.0+incompatible h1:D6wyKGCecFaSRUpo8lCVbaOOb6ThwMmTEbhRwtKR97o=
Expand Down
8 changes: 2 additions & 6 deletions internal/applicant/aliyun.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package applicant

import (
"certimate/internal/domain"
"encoding/json"
"os"

"github.com/go-acme/lego/v4/providers/dns/alidns"
)

type aliyunAccess struct {
AccessKeyId string `json:"accessKeyId"`
AccessKeySecret string `json:"accessKeySecret"`
}

type aliyun struct {
option *ApplyOption
}
Expand All @@ -24,7 +20,7 @@ func NewAliyun(option *ApplyOption) Applicant {

func (a *aliyun) Apply() (*Certificate, error) {

access := &aliyunAccess{}
access := &domain.AliyunAccess{}
json.Unmarshal([]byte(a.option.Access), access)

os.Setenv("ALICLOUD_ACCESS_KEY", access.AccessKeyId)
Expand Down
8 changes: 2 additions & 6 deletions internal/applicant/tencent.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
package applicant

import (
"certimate/internal/domain"
"encoding/json"
"os"

"github.com/go-acme/lego/v4/providers/dns/tencentcloud"
)

type tencentAccess struct {
SecretId string `json:"secretId"`
SecretKey string `json:"secretKey"`
}

type tencent struct {
option *ApplyOption
}
Expand All @@ -24,7 +20,7 @@ func NewTencent(option *ApplyOption) Applicant {

func (t *tencent) Apply() (*Certificate, error) {

access := &tencentAccess{}
access := &domain.TencentAccess{}
json.Unmarshal([]byte(t.option.Access), access)

os.Setenv("TENCENTCLOUD_SECRET_ID", access.SecretId)
Expand Down
8 changes: 2 additions & 6 deletions internal/deployer/aliyun.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package deployer

import (
"certimate/internal/applicant"
"certimate/internal/domain"
"certimate/internal/utils/rand"
"context"
"encoding/json"
Expand All @@ -15,18 +16,13 @@ import (
"github.com/alibabacloud-go/tea/tea"
)

type aliyunAccess struct {
AccessKeyId string `json:"accessKeyId"`
AccessKeySecret string `json:"accessKeySecret"`
}

type aliyun struct {
client *cas20200407.Client
option *DeployerOption
}

func NewAliyun(option *DeployerOption) (Deployer, error) {
access := &aliyunAccess{}
access := &domain.AliyunAccess{}
json.Unmarshal([]byte(option.Access), access)
a := &aliyun{
option: option,
Expand Down
3 changes: 2 additions & 1 deletion internal/deployer/aliyun_cdn.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package deployer

import (
"certimate/internal/domain"
"context"
"encoding/json"
"fmt"
Expand All @@ -17,7 +18,7 @@ type AliyunCdn struct {
}

func NewAliyunCdn(option *DeployerOption) (*AliyunCdn, error) {
access := &aliyunAccess{}
access := &domain.AliyunAccess{}
json.Unmarshal([]byte(option.Access), access)
a := &AliyunCdn{
option: option,
Expand Down
11 changes: 7 additions & 4 deletions internal/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ const (
)

const (
targetAliyunOss = "aliyun-oss"
targetAliyunCdn = "aliyun-cdn"
targetSSH = "ssh"
targetWebhook = "webhook"
targetAliyunOss = "aliyun-oss"
targetAliyunCdn = "aliyun-cdn"
targetSSH = "ssh"
targetWebhook = "webhook"
targetTencentCdn = "tencent-cdn"
)

type DeployerOption struct {
Expand Down Expand Up @@ -58,6 +59,8 @@ func Get(record *models.Record, cert *applicant.Certificate) (Deployer, error) {
return NewSSH(option)
case targetWebhook:
return NewWebhook(option)
case targetTencentCdn:
return NewTencentCdn(option)
}
return nil, errors.New("not implemented")
}
Expand Down
Loading

0 comments on commit 1e11b23

Please sign in to comment.