mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-09 05:59:50 +00:00
feat: add huaweicloud cdn deployer
This commit is contained in:
parent
be3cdbf585
commit
952c6ef73d
@ -76,7 +76,7 @@ go run main.go serve
|
|||||||
| :--------: | :----------: | :----------: | ------------------------------------------------------------ |
|
| :--------: | :----------: | :----------: | ------------------------------------------------------------ |
|
||||||
| 阿里云 | √ | √ | 可签发在阿里云注册的域名;可部署到阿里云 OSS、CDN |
|
| 阿里云 | √ | √ | 可签发在阿里云注册的域名;可部署到阿里云 OSS、CDN |
|
||||||
| 腾讯云 | √ | √ | 可签发在腾讯云注册的域名;可部署到腾讯云 CDN |
|
| 腾讯云 | √ | √ | 可签发在腾讯云注册的域名;可部署到腾讯云 CDN |
|
||||||
| 华为云 | √ | | 可签发在华为云注册的域名 |
|
| 华为云 | √ | √ | 可签发在华为云注册的域名;可部署到华为云 CDN |
|
||||||
| 七牛云 | | √ | 可部署到七牛云 CDN |
|
| 七牛云 | | √ | 可部署到七牛云 CDN |
|
||||||
| AWS | √ | | 可签发在 AWS Route53 托管的域名 |
|
| AWS | √ | | 可签发在 AWS Route53 托管的域名 |
|
||||||
| CloudFlare | √ | | 可签发在 CloudFlare 注册的域名;CloudFlare 服务自带 SSL 证书 |
|
| CloudFlare | √ | | 可签发在 CloudFlare 注册的域名;CloudFlare 服务自带 SSL 证书 |
|
||||||
|
@ -75,7 +75,7 @@ password:1234567890
|
|||||||
| :-----------: | :----------: | :--------: | ------------------------------------------------------------------------------------------- |
|
| :-----------: | :----------: | :--------: | ------------------------------------------------------------------------------------------- |
|
||||||
| Alibaba Cloud | √ | √ | Supports domains registered on Alibaba Cloud; supports deployment to Alibaba Cloud OSS, CDN |
|
| Alibaba Cloud | √ | √ | Supports domains registered on Alibaba Cloud; supports deployment to Alibaba Cloud OSS, CDN |
|
||||||
| Tencent Cloud | √ | √ | Supports domains registered on Tencent Cloud; supports deployment to Tencent Cloud CDN |
|
| Tencent Cloud | √ | √ | Supports domains registered on Tencent Cloud; supports deployment to Tencent Cloud CDN |
|
||||||
| Huawei Cloud | √ | | Supports domains registered on Huawei Cloud |
|
| Huawei Cloud | √ | √ | Supports domains registered on Huawei; supports deployment to Huawei Cloud CDN |
|
||||||
| Qiniu Cloud | | √ | Supports deployment to Qiniu Cloud CDN |
|
| Qiniu Cloud | | √ | Supports deployment to Qiniu Cloud CDN |
|
||||||
| AWS | √ | | Supports domains managed on AWS Route53 |
|
| AWS | √ | | Supports domains managed on AWS Route53 |
|
||||||
| CloudFlare | √ | | Supports domains registered on CloudFlare; CloudFlare services come with SSL certificates |
|
| CloudFlare | √ | | Supports domains registered on CloudFlare; CloudFlare services come with SSL certificates |
|
||||||
|
2
go.mod
2
go.mod
@ -12,6 +12,7 @@ require (
|
|||||||
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
|
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
|
||||||
github.com/go-acme/lego/v4 v4.19.2
|
github.com/go-acme/lego/v4 v4.19.2
|
||||||
github.com/gojek/heimdall/v7 v7.0.3
|
github.com/gojek/heimdall/v7 v7.0.3
|
||||||
|
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.114
|
||||||
github.com/labstack/echo/v5 v5.0.0-20230722203903-ec5b858dab61
|
github.com/labstack/echo/v5 v5.0.0-20230722203903-ec5b858dab61
|
||||||
github.com/nikoksr/notify v1.0.0
|
github.com/nikoksr/notify v1.0.0
|
||||||
github.com/pkg/sftp v1.13.6
|
github.com/pkg/sftp v1.13.6
|
||||||
@ -46,7 +47,6 @@ require (
|
|||||||
github.com/google/gnostic-models v0.6.8 // indirect
|
github.com/google/gnostic-models v0.6.8 // indirect
|
||||||
github.com/google/go-cmp v0.6.0 // indirect
|
github.com/google/go-cmp v0.6.0 // indirect
|
||||||
github.com/google/gofuzz v1.2.0 // indirect
|
github.com/google/gofuzz v1.2.0 // indirect
|
||||||
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.1.114 // indirect
|
|
||||||
github.com/imdario/mergo v0.3.6 // indirect
|
github.com/imdario/mergo v0.3.6 // indirect
|
||||||
github.com/josharian/intern v1.0.0 // indirect
|
github.com/josharian/intern v1.0.0 // indirect
|
||||||
github.com/mailru/easyjson v0.7.7 // indirect
|
github.com/mailru/easyjson v0.7.7 // indirect
|
||||||
|
@ -19,6 +19,7 @@ const (
|
|||||||
targetAliyunCDN = "aliyun-cdn"
|
targetAliyunCDN = "aliyun-cdn"
|
||||||
targetAliyunESA = "aliyun-dcdn"
|
targetAliyunESA = "aliyun-dcdn"
|
||||||
targetTencentCDN = "tencent-cdn"
|
targetTencentCDN = "tencent-cdn"
|
||||||
|
targetHuaweiCloudCDN = "huaweicloud-cdn"
|
||||||
targetQiniuCdn = "qiniu-cdn"
|
targetQiniuCdn = "qiniu-cdn"
|
||||||
targetLocal = "local"
|
targetLocal = "local"
|
||||||
targetSSH = "ssh"
|
targetSSH = "ssh"
|
||||||
@ -104,6 +105,8 @@ func getWithDeployConfig(record *models.Record, cert *applicant.Certificate, dep
|
|||||||
return NewAliyunESADeployer(option)
|
return NewAliyunESADeployer(option)
|
||||||
case targetTencentCDN:
|
case targetTencentCDN:
|
||||||
return NewTencentCDNDeployer(option)
|
return NewTencentCDNDeployer(option)
|
||||||
|
case targetHuaweiCloudCDN:
|
||||||
|
return NewHuaweiCloudCDNDeployer(option)
|
||||||
case targetQiniuCdn:
|
case targetQiniuCdn:
|
||||||
return NewQiniuCDNDeployer(option)
|
return NewQiniuCDNDeployer(option)
|
||||||
case targetLocal:
|
case targetLocal:
|
||||||
|
150
internal/deployer/huaweicloud_cdn.go
Normal file
150
internal/deployer/huaweicloud_cdn.go
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
package deployer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/global"
|
||||||
|
cdn "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2"
|
||||||
|
cdnModel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/model"
|
||||||
|
cdnRegion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/region"
|
||||||
|
|
||||||
|
"certimate/internal/domain"
|
||||||
|
"certimate/internal/utils/rand"
|
||||||
|
)
|
||||||
|
|
||||||
|
type HuaweiCloudCDNDeployer struct {
|
||||||
|
option *DeployerOption
|
||||||
|
infos []string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewHuaweiCloudCDNDeployer(option *DeployerOption) (Deployer, error) {
|
||||||
|
return &HuaweiCloudCDNDeployer{
|
||||||
|
option: option,
|
||||||
|
infos: make([]string, 0),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *HuaweiCloudCDNDeployer) GetID() string {
|
||||||
|
return fmt.Sprintf("%s-%s", d.option.AceessRecord.GetString("name"), d.option.AceessRecord.Id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *HuaweiCloudCDNDeployer) GetInfo() []string {
|
||||||
|
return d.infos
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *HuaweiCloudCDNDeployer) Deploy(ctx context.Context) error {
|
||||||
|
access := &domain.HuaweiCloudAccess{}
|
||||||
|
if err := json.Unmarshal([]byte(d.option.Access), access); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := d.createClient(access)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
d.infos = append(d.infos, toStr("HuaweiCloudCdnClient 创建成功", nil))
|
||||||
|
|
||||||
|
// 查询加速域名配置
|
||||||
|
showDomainFullConfigReq := &cdnModel.ShowDomainFullConfigRequest{
|
||||||
|
DomainName: getDeployString(d.option.DeployConfig, "domain"),
|
||||||
|
}
|
||||||
|
showDomainFullConfigResp, err := client.ShowDomainFullConfig(showDomainFullConfigReq)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
d.infos = append(d.infos, toStr("已查询到加速域名配置", showDomainFullConfigResp))
|
||||||
|
|
||||||
|
// 更新加速域名配置
|
||||||
|
certName := fmt.Sprintf("%s-%s", d.option.DomainId, rand.RandStr(12))
|
||||||
|
updateDomainMultiCertificatesReq := &cdnModel.UpdateDomainMultiCertificatesRequest{
|
||||||
|
Body: &cdnModel.UpdateDomainMultiCertificatesRequestBody{
|
||||||
|
Https: mergeHuaweiCloudCDNConfig(showDomainFullConfigResp.Configs, &cdnModel.UpdateDomainMultiCertificatesRequestBodyContent{
|
||||||
|
DomainName: getDeployString(d.option.DeployConfig, "domain"),
|
||||||
|
HttpsSwitch: 1,
|
||||||
|
CertName: &certName,
|
||||||
|
Certificate: &d.option.Certificate.Certificate,
|
||||||
|
PrivateKey: &d.option.Certificate.PrivateKey,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
updateDomainMultiCertificatesResp, err := client.UpdateDomainMultiCertificates(updateDomainMultiCertificatesReq)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
d.infos = append(d.infos, toStr("已更新加速域名配置", updateDomainMultiCertificatesResp))
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *HuaweiCloudCDNDeployer) createClient(access *domain.HuaweiCloudAccess) (*cdn.CdnClient, error) {
|
||||||
|
auth, err := global.NewCredentialsBuilder().
|
||||||
|
WithAk(access.AccessKeyId).
|
||||||
|
WithSk(access.SecretAccessKey).
|
||||||
|
SafeBuild()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
region, err := cdnRegion.SafeValueOf(access.Region)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
hcClient, err := cdn.CdnClientBuilder().
|
||||||
|
WithRegion(region).
|
||||||
|
WithCredential(auth).
|
||||||
|
SafeBuild()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
client := cdn.NewCdnClient(hcClient)
|
||||||
|
return client, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func mergeHuaweiCloudCDNConfig(src *cdnModel.ConfigsGetBody, dest *cdnModel.UpdateDomainMultiCertificatesRequestBodyContent) *cdnModel.UpdateDomainMultiCertificatesRequestBodyContent {
|
||||||
|
if src == nil {
|
||||||
|
return dest
|
||||||
|
}
|
||||||
|
|
||||||
|
// 华为云 API 中不传的字段表示使用默认值、而非保留原值,因此这里需要把原配置中的参数重新赋值回去
|
||||||
|
// 而且蛋疼的是查询接口返回的数据结构和更新接口传入的参数结构不一致,需要做很多转化
|
||||||
|
// REF: https://support.huaweicloud.com/api-cdn/ShowDomainFullConfig.html
|
||||||
|
// REF: https://support.huaweicloud.com/api-cdn/UpdateDomainMultiCertificates.html
|
||||||
|
|
||||||
|
if *src.OriginProtocol == "follow" {
|
||||||
|
accessOriginWay := int32(1)
|
||||||
|
dest.AccessOriginWay = &accessOriginWay
|
||||||
|
} else if *src.OriginProtocol == "http" {
|
||||||
|
accessOriginWay := int32(2)
|
||||||
|
dest.AccessOriginWay = &accessOriginWay
|
||||||
|
} else if *src.OriginProtocol == "https" {
|
||||||
|
accessOriginWay := int32(3)
|
||||||
|
dest.AccessOriginWay = &accessOriginWay
|
||||||
|
}
|
||||||
|
|
||||||
|
if src.ForceRedirect != nil {
|
||||||
|
dest.ForceRedirectConfig = &cdnModel.ForceRedirect{}
|
||||||
|
|
||||||
|
if src.ForceRedirect.Status == "on" {
|
||||||
|
dest.ForceRedirectConfig.Switch = 1
|
||||||
|
dest.ForceRedirectConfig.RedirectType = src.ForceRedirect.Type
|
||||||
|
} else {
|
||||||
|
dest.ForceRedirectConfig.Switch = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if src.Https != nil {
|
||||||
|
if *src.Https.Http2Status == "on" {
|
||||||
|
http2 := int32(1)
|
||||||
|
dest.Http2 = &http2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dest
|
||||||
|
}
|
File diff suppressed because one or more lines are too long
2
ui/dist/index.html
vendored
2
ui/dist/index.html
vendored
@ -5,7 +5,7 @@
|
|||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Certimate - Your Trusted SSL Automation Partner</title>
|
<title>Certimate - Your Trusted SSL Automation Partner</title>
|
||||||
<script type="module" crossorigin src="/assets/index-C9KsIpHj.js"></script>
|
<script type="module" crossorigin src="/assets/index-tBXwi-8W.js"></script>
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-YqBWA4KK.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-YqBWA4KK.css">
|
||||||
</head>
|
</head>
|
||||||
<body class="bg-background">
|
<body class="bg-background">
|
||||||
|
@ -71,6 +71,7 @@ export const targetTypeMap: Map<string, [string, string]> = new Map([
|
|||||||
["aliyun-cdn", ["common.provider.aliyun.cdn", "/imgs/providers/aliyun.svg"]],
|
["aliyun-cdn", ["common.provider.aliyun.cdn", "/imgs/providers/aliyun.svg"]],
|
||||||
["aliyun-dcdn", ["common.provider.aliyun.dcdn", "/imgs/providers/aliyun.svg"]],
|
["aliyun-dcdn", ["common.provider.aliyun.dcdn", "/imgs/providers/aliyun.svg"]],
|
||||||
["tencent-cdn", ["common.provider.tencent.cdn", "/imgs/providers/tencent.svg"]],
|
["tencent-cdn", ["common.provider.tencent.cdn", "/imgs/providers/tencent.svg"]],
|
||||||
|
["huaweicloud-cdn", ["common.provider.huaweicloud.cdn", "/imgs/providers/huaweicloud.svg"]],
|
||||||
["qiniu-cdn", ["common.provider.qiniu.cdn", "/imgs/providers/qiniu.svg"]],
|
["qiniu-cdn", ["common.provider.qiniu.cdn", "/imgs/providers/qiniu.svg"]],
|
||||||
["local", ["common.provider.local", "/imgs/providers/local.svg"]],
|
["local", ["common.provider.local", "/imgs/providers/local.svg"]],
|
||||||
["ssh", ["common.provider.ssh", "/imgs/providers/ssh.svg"]],
|
["ssh", ["common.provider.ssh", "/imgs/providers/ssh.svg"]],
|
||||||
|
@ -59,6 +59,7 @@
|
|||||||
"common.provider.tencent": "Tencent",
|
"common.provider.tencent": "Tencent",
|
||||||
"common.provider.tencent.cdn": "Tencent - CDN",
|
"common.provider.tencent.cdn": "Tencent - CDN",
|
||||||
"common.provider.huaweicloud": "Huawei Cloud",
|
"common.provider.huaweicloud": "Huawei Cloud",
|
||||||
|
"common.provider.huaweicloud.cdn": "Huawei Cloud - CDN",
|
||||||
"common.provider.qiniu": "Qiniu",
|
"common.provider.qiniu": "Qiniu",
|
||||||
"common.provider.qiniu.cdn": "Qiniu - CDN",
|
"common.provider.qiniu.cdn": "Qiniu - CDN",
|
||||||
"common.provider.aws": "AWS",
|
"common.provider.aws": "AWS",
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
"domain.deploy.started.tips": "Deployment initiated, please check the deployment log later.",
|
"domain.deploy.started.tips": "Deployment initiated, please check the deployment log later.",
|
||||||
"domain.deploy.failed.message": "Execution Failed",
|
"domain.deploy.failed.message": "Execution Failed",
|
||||||
"domain.deploy.failed.tips": "Execution failed, please check the details in <1>Deployment History</1>.",
|
"domain.deploy.failed.tips": "Execution failed, please check the details in <1>Deployment History</1>.",
|
||||||
"domain.deploy_forced": "Force Deployment",
|
"domain.deploy_forced": "Force Deploy",
|
||||||
|
|
||||||
"domain.props.expiry": "Validity Period",
|
"domain.props.expiry": "Validity Period",
|
||||||
"domain.props.expiry.date1": "Valid for {{date}} days",
|
"domain.props.expiry.date1": "Valid for {{date}} days",
|
||||||
|
@ -59,6 +59,7 @@
|
|||||||
"common.provider.aliyun.cdn": "阿里云 - CDN",
|
"common.provider.aliyun.cdn": "阿里云 - CDN",
|
||||||
"common.provider.aliyun.dcdn": "阿里云 - DCDN",
|
"common.provider.aliyun.dcdn": "阿里云 - DCDN",
|
||||||
"common.provider.huaweicloud": "华为云",
|
"common.provider.huaweicloud": "华为云",
|
||||||
|
"common.provider.huaweicloud.cdn": "华为云 - CDN",
|
||||||
"common.provider.qiniu": "七牛云",
|
"common.provider.qiniu": "七牛云",
|
||||||
"common.provider.qiniu.cdn": "七牛云 - CDN",
|
"common.provider.qiniu.cdn": "七牛云 - CDN",
|
||||||
"common.provider.aws": "AWS",
|
"common.provider.aws": "AWS",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user