mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 13:39:53 +00:00
refactor: deprecate internal/utils/rand.RandStr
This commit is contained in:
parent
4fec0036cb
commit
0ceb44a7cd
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
aliyunCdn "github.com/alibabacloud-go/cdn-20180510/v5/client"
|
aliyunCdn "github.com/alibabacloud-go/cdn-20180510/v5/client"
|
||||||
aliyunOpen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
aliyunOpen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||||
@ -11,7 +12,6 @@ import (
|
|||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/domain"
|
"github.com/usual2970/certimate/internal/domain"
|
||||||
"github.com/usual2970/certimate/internal/utils/rand"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type AliyunCDNDeployer struct {
|
type AliyunCDNDeployer struct {
|
||||||
@ -51,14 +51,12 @@ func (d *AliyunCDNDeployer) GetInfos() []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *AliyunCDNDeployer) Deploy(ctx context.Context) error {
|
func (d *AliyunCDNDeployer) Deploy(ctx context.Context) error {
|
||||||
certName := fmt.Sprintf("%s-%s-%s", d.option.Domain, d.option.DomainId, rand.RandStr(6))
|
|
||||||
|
|
||||||
// 设置 CDN 域名域名证书
|
// 设置 CDN 域名域名证书
|
||||||
// REF: https://help.aliyun.com/zh/cdn/developer-reference/api-cdn-2018-05-10-setcdndomainsslcertificate
|
// REF: https://help.aliyun.com/zh/cdn/developer-reference/api-cdn-2018-05-10-setcdndomainsslcertificate
|
||||||
setCdnDomainSSLCertificateReq := &aliyunCdn.SetCdnDomainSSLCertificateRequest{
|
setCdnDomainSSLCertificateReq := &aliyunCdn.SetCdnDomainSSLCertificateRequest{
|
||||||
DomainName: tea.String(d.option.DeployConfig.GetConfigAsString("domain")),
|
DomainName: tea.String(d.option.DeployConfig.GetConfigAsString("domain")),
|
||||||
CertRegion: tea.String(d.option.DeployConfig.GetConfigOrDefaultAsString("region", "cn-hangzhou")),
|
CertRegion: tea.String(d.option.DeployConfig.GetConfigOrDefaultAsString("region", "cn-hangzhou")),
|
||||||
CertName: tea.String(certName),
|
CertName: tea.String(fmt.Sprintf("certimate-%d", time.Now().UnixMilli())),
|
||||||
CertType: tea.String("upload"),
|
CertType: tea.String("upload"),
|
||||||
SSLProtocol: tea.String("on"),
|
SSLProtocol: tea.String("on"),
|
||||||
SSLPub: tea.String(d.option.Certificate.Certificate),
|
SSLPub: tea.String(d.option.Certificate.Certificate),
|
||||||
|
@ -112,12 +112,11 @@ func (d *AliyunCLBDeployer) createSdkClient(accessKeyId, accessKeySecret, region
|
|||||||
|
|
||||||
func (d *AliyunCLBDeployer) deployToLoadbalancer(ctx context.Context) error {
|
func (d *AliyunCLBDeployer) deployToLoadbalancer(ctx context.Context) error {
|
||||||
aliLoadbalancerId := d.option.DeployConfig.GetConfigAsString("loadbalancerId")
|
aliLoadbalancerId := d.option.DeployConfig.GetConfigAsString("loadbalancerId")
|
||||||
|
aliListenerPorts := make([]int32, 0)
|
||||||
if aliLoadbalancerId == "" {
|
if aliLoadbalancerId == "" {
|
||||||
return errors.New("`loadbalancerId` is required")
|
return errors.New("`loadbalancerId` is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
aliListenerPorts := make([]int32, 0)
|
|
||||||
|
|
||||||
// 查询负载均衡实例的详细信息
|
// 查询负载均衡实例的详细信息
|
||||||
// REF: https://help.aliyun.com/zh/slb/classic-load-balancer/developer-reference/api-slb-2014-05-15-describeloadbalancerattribute
|
// REF: https://help.aliyun.com/zh/slb/classic-load-balancer/developer-reference/api-slb-2014-05-15-describeloadbalancerattribute
|
||||||
describeLoadBalancerAttributeReq := &aliyunSlb.DescribeLoadBalancerAttributeRequest{
|
describeLoadBalancerAttributeReq := &aliyunSlb.DescribeLoadBalancerAttributeRequest{
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
aliyunOpen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
aliyunOpen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||||
aliyunDcdn "github.com/alibabacloud-go/dcdn-20180115/v3/client"
|
aliyunDcdn "github.com/alibabacloud-go/dcdn-20180115/v3/client"
|
||||||
@ -12,7 +13,6 @@ import (
|
|||||||
xerrors "github.com/pkg/errors"
|
xerrors "github.com/pkg/errors"
|
||||||
|
|
||||||
"github.com/usual2970/certimate/internal/domain"
|
"github.com/usual2970/certimate/internal/domain"
|
||||||
"github.com/usual2970/certimate/internal/utils/rand"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type AliyunDCDNDeployer struct {
|
type AliyunDCDNDeployer struct {
|
||||||
@ -52,8 +52,6 @@ func (d *AliyunDCDNDeployer) GetInfos() []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *AliyunDCDNDeployer) Deploy(ctx context.Context) error {
|
func (d *AliyunDCDNDeployer) Deploy(ctx context.Context) error {
|
||||||
certName := fmt.Sprintf("%s-%s-%s", d.option.Domain, d.option.DomainId, rand.RandStr(6))
|
|
||||||
|
|
||||||
// 支持泛解析域名,在 Aliyun DCDN 中泛解析域名表示为 .example.com
|
// 支持泛解析域名,在 Aliyun DCDN 中泛解析域名表示为 .example.com
|
||||||
domain := d.option.DeployConfig.GetConfigAsString("domain")
|
domain := d.option.DeployConfig.GetConfigAsString("domain")
|
||||||
if strings.HasPrefix(domain, "*") {
|
if strings.HasPrefix(domain, "*") {
|
||||||
@ -65,7 +63,7 @@ func (d *AliyunDCDNDeployer) Deploy(ctx context.Context) error {
|
|||||||
setDcdnDomainSSLCertificateReq := &aliyunDcdn.SetDcdnDomainSSLCertificateRequest{
|
setDcdnDomainSSLCertificateReq := &aliyunDcdn.SetDcdnDomainSSLCertificateRequest{
|
||||||
DomainName: tea.String(domain),
|
DomainName: tea.String(domain),
|
||||||
CertRegion: tea.String(d.option.DeployConfig.GetConfigOrDefaultAsString("region", "cn-hangzhou")),
|
CertRegion: tea.String(d.option.DeployConfig.GetConfigOrDefaultAsString("region", "cn-hangzhou")),
|
||||||
CertName: tea.String(certName),
|
CertName: tea.String(fmt.Sprintf("certimate-%d", time.Now().UnixMilli())),
|
||||||
CertType: tea.String("upload"),
|
CertType: tea.String("upload"),
|
||||||
SSLProtocol: tea.String("on"),
|
SSLProtocol: tea.String("on"),
|
||||||
SSLPub: tea.String(d.option.Certificate.Certificate),
|
SSLPub: tea.String(d.option.Certificate.Certificate),
|
||||||
|
@ -5,7 +5,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RandStr 随机生成指定长度字符串
|
// Deprecated: this will be removed in the future.
|
||||||
|
// 随机生成指定长度字符串
|
||||||
func RandStr(n int) string {
|
func RandStr(n int) string {
|
||||||
seed := time.Now().UnixNano()
|
seed := time.Now().UnixNano()
|
||||||
source := rand.NewSource(seed)
|
source := rand.NewSource(seed)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user