mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 13:39:53 +00:00
Support deployment to Alibaba Cloud CDN.
This commit is contained in:
parent
bbc6d094c3
commit
6d9fef3d2a
1
go.mod
1
go.mod
@ -6,6 +6,7 @@ toolchain go1.22.5
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/alibabacloud-go/cas-20200407/v2 v2.3.0
|
github.com/alibabacloud-go/cas-20200407/v2 v2.3.0
|
||||||
|
github.com/alibabacloud-go/cdn-20180510/v5 v5.0.0
|
||||||
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.8
|
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.8
|
||||||
github.com/alibabacloud-go/tea v1.2.1
|
github.com/alibabacloud-go/tea v1.2.1
|
||||||
github.com/alibabacloud-go/tea-utils/v2 v2.0.5
|
github.com/alibabacloud-go/tea-utils/v2 v2.0.5
|
||||||
|
2
go.sum
2
go.sum
@ -23,6 +23,8 @@ github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4 h1:iC9YFYKDGEy3n/FtqJ
|
|||||||
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4/go.mod h1:sCavSAvdzOjul4cEqeVtvlSaSScfNsTQ+46HwlTL1hc=
|
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4/go.mod h1:sCavSAvdzOjul4cEqeVtvlSaSScfNsTQ+46HwlTL1hc=
|
||||||
github.com/alibabacloud-go/cas-20200407/v2 v2.3.0 h1:nOrp0n2nFZiYN0wIG7S26YVVaMMzOBkX9GJqUvYnGeE=
|
github.com/alibabacloud-go/cas-20200407/v2 v2.3.0 h1:nOrp0n2nFZiYN0wIG7S26YVVaMMzOBkX9GJqUvYnGeE=
|
||||||
github.com/alibabacloud-go/cas-20200407/v2 v2.3.0/go.mod h1:yzkgdLANANu/v56k0ptslGl++JJL4Op1V09HTavfoCo=
|
github.com/alibabacloud-go/cas-20200407/v2 v2.3.0/go.mod h1:yzkgdLANANu/v56k0ptslGl++JJL4Op1V09HTavfoCo=
|
||||||
|
github.com/alibabacloud-go/cdn-20180510/v5 v5.0.0 h1:yTKngw4rBR3hdpoo/uCyBffYXfPfjNjlaDL8nTYUIds=
|
||||||
|
github.com/alibabacloud-go/cdn-20180510/v5 v5.0.0/go.mod h1:HxQrwVKBx3/6bIwmdDcpqBpSQt2tpi/j4LfEhl+QFPk=
|
||||||
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.6/go.mod h1:CzQnh+94WDnJOnKZH5YRyouL+OOcdBnXY5VWAf0McgI=
|
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.6/go.mod h1:CzQnh+94WDnJOnKZH5YRyouL+OOcdBnXY5VWAf0McgI=
|
||||||
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.8 h1:benoD0QHDrylMzEQVpX/6uKtrN8LohT66ZlKXVJh7pM=
|
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.8 h1:benoD0QHDrylMzEQVpX/6uKtrN8LohT66ZlKXVJh7pM=
|
||||||
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.8/go.mod h1:CzQnh+94WDnJOnKZH5YRyouL+OOcdBnXY5VWAf0McgI=
|
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.8/go.mod h1:CzQnh+94WDnJOnKZH5YRyouL+OOcdBnXY5VWAf0McgI=
|
||||||
|
68
internal/deployer/aliyun_cdn.go
Normal file
68
internal/deployer/aliyun_cdn.go
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
package deployer
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
cdn20180510 "github.com/alibabacloud-go/cdn-20180510/v5/client"
|
||||||
|
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||||
|
util "github.com/alibabacloud-go/tea-utils/v2/service"
|
||||||
|
"github.com/alibabacloud-go/tea/tea"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AliyunCdn struct {
|
||||||
|
client *cdn20180510.Client
|
||||||
|
option *DeployerOption
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAliyunCdn(option *DeployerOption) (*AliyunCdn, error) {
|
||||||
|
access := &aliyunAccess{}
|
||||||
|
json.Unmarshal([]byte(option.Access), access)
|
||||||
|
a := &AliyunCdn{
|
||||||
|
option: option,
|
||||||
|
}
|
||||||
|
client, err := a.createClient(access.AccessKeyId, access.AccessKeySecret)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &AliyunCdn{
|
||||||
|
client: client,
|
||||||
|
option: option,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AliyunCdn) Deploy(ctx context.Context) error {
|
||||||
|
|
||||||
|
certName := fmt.Sprintf("%s-%s", a.option.Domain, a.option.DomainId)
|
||||||
|
setCdnDomainSSLCertificateRequest := &cdn20180510.SetCdnDomainSSLCertificateRequest{
|
||||||
|
DomainName: tea.String(a.option.Domain),
|
||||||
|
CertName: tea.String(certName),
|
||||||
|
CertType: tea.String("upload"),
|
||||||
|
SSLProtocol: tea.String("on"),
|
||||||
|
SSLPub: tea.String(a.option.Certificate.Certificate),
|
||||||
|
SSLPri: tea.String(a.option.Certificate.PrivateKey),
|
||||||
|
CertRegion: tea.String("cn-hangzhou"),
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime := &util.RuntimeOptions{}
|
||||||
|
|
||||||
|
_, err := a.client.SetCdnDomainSSLCertificateWithOptions(setCdnDomainSSLCertificateRequest, runtime)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AliyunCdn) createClient(accessKeyId, accessKeySecret string) (_result *cdn20180510.Client, _err error) {
|
||||||
|
config := &openapi.Config{
|
||||||
|
AccessKeyId: tea.String(accessKeyId),
|
||||||
|
AccessKeySecret: tea.String(accessKeySecret),
|
||||||
|
}
|
||||||
|
config.Endpoint = tea.String("cdn.aliyuncs.com")
|
||||||
|
_result = &cdn20180510.Client{}
|
||||||
|
_result, _err = cdn20180510.NewClient(config)
|
||||||
|
return _result, _err
|
||||||
|
}
|
@ -13,7 +13,13 @@ const (
|
|||||||
configTypeAliyun = "aliyun"
|
configTypeAliyun = "aliyun"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
targetAliyunOss = "aliyun-oss"
|
||||||
|
targetAliyunCdn = "aliyun-cdn"
|
||||||
|
)
|
||||||
|
|
||||||
type DeployerOption struct {
|
type DeployerOption struct {
|
||||||
|
DomainId string `json:"domainId"`
|
||||||
Domain string `json:"domain"`
|
Domain string `json:"domain"`
|
||||||
Product string `json:"product"`
|
Product string `json:"product"`
|
||||||
Access string `json:"access"`
|
Access string `json:"access"`
|
||||||
@ -26,18 +32,21 @@ type Deployer interface {
|
|||||||
|
|
||||||
func Get(record *models.Record) (Deployer, error) {
|
func Get(record *models.Record) (Deployer, error) {
|
||||||
access := record.ExpandedOne("targetAccess")
|
access := record.ExpandedOne("targetAccess")
|
||||||
switch access.GetString("configType") {
|
option := &DeployerOption{
|
||||||
case configTypeAliyun:
|
DomainId: record.Id,
|
||||||
option := &DeployerOption{
|
Domain: record.GetString("domain"),
|
||||||
Domain: record.GetString("domain"),
|
Product: getProduct(record),
|
||||||
Product: getProduct(record),
|
Access: access.GetString("config"),
|
||||||
Access: access.GetString("config"),
|
Certificate: applicant.Certificate{
|
||||||
Certificate: applicant.Certificate{
|
Certificate: record.GetString("certificate"),
|
||||||
Certificate: record.GetString("certificate"),
|
PrivateKey: record.GetString("privateKey"),
|
||||||
PrivateKey: record.GetString("privateKey"),
|
},
|
||||||
},
|
}
|
||||||
}
|
switch record.GetString("targetType") {
|
||||||
|
case targetAliyunOss:
|
||||||
return NewAliyun(option)
|
return NewAliyun(option)
|
||||||
|
case targetAliyunCdn:
|
||||||
|
return NewAliyunCdn(option)
|
||||||
}
|
}
|
||||||
return nil, errors.New("not implemented")
|
return nil, errors.New("not implemented")
|
||||||
}
|
}
|
||||||
|
@ -243,6 +243,9 @@ const Edit = () => {
|
|||||||
<SelectItem value="aliyun-oss">
|
<SelectItem value="aliyun-oss">
|
||||||
阿里云-OSS
|
阿里云-OSS
|
||||||
</SelectItem>
|
</SelectItem>
|
||||||
|
<SelectItem value="aliyun-cdn">
|
||||||
|
阿里云-CDN
|
||||||
|
</SelectItem>
|
||||||
</SelectGroup>
|
</SelectGroup>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
|
@ -91,6 +91,13 @@ const Home = () => {
|
|||||||
return domain;
|
return domain;
|
||||||
});
|
});
|
||||||
setDomains(updatedDomains);
|
setDomains(updatedDomains);
|
||||||
|
toast.toast({
|
||||||
|
title: "执行成功",
|
||||||
|
description: "执行成功",
|
||||||
|
});
|
||||||
|
setTimeout(() => {
|
||||||
|
navigate(0);
|
||||||
|
}, 1000);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
toast.toast({
|
toast.toast({
|
||||||
title: "执行失败",
|
title: "执行失败",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user