mirror of
https://github.com/certimate-go/certimate.git
synced 2026-09-24 23:10:13 +08:00
refactor: use samber/lo
This commit is contained in:
@@ -130,6 +130,7 @@ require (
|
||||
github.com/qiniu/dyn v1.3.0 // indirect
|
||||
github.com/qiniu/x v1.10.5 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
|
||||
github.com/samber/lo v1.51.0 // indirect
|
||||
github.com/sirupsen/logrus v1.9.4-0.20230606125235-dd1b4c2e81af // indirect
|
||||
github.com/tidwall/gjson v1.18.0 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
@@ -211,10 +212,10 @@ require (
|
||||
golang.org/x/mod v0.25.0 // indirect
|
||||
golang.org/x/net v0.41.0 // indirect
|
||||
golang.org/x/oauth2 v0.30.0 // indirect
|
||||
golang.org/x/sync v0.15.0
|
||||
golang.org/x/sync v0.16.0
|
||||
golang.org/x/sys v0.33.0 // indirect
|
||||
golang.org/x/term v0.32.0 // indirect
|
||||
golang.org/x/text v0.26.0 // indirect
|
||||
golang.org/x/text v0.27.0 // indirect
|
||||
golang.org/x/time v0.11.0
|
||||
golang.org/x/tools v0.34.0 // indirect
|
||||
google.golang.org/protobuf v1.36.5 // indirect
|
||||
|
||||
@@ -796,6 +796,8 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
|
||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||
github.com/samber/lo v1.50.0 h1:XrG0xOeHs+4FQ8gJR97zDz5uOFMW7OwFWiFVzqopKgY=
|
||||
github.com/samber/lo v1.50.0/go.mod h1:RjZyNk6WSnUFRKK6EyOhsRJMqft3G+pg7dCWHQCWvsc=
|
||||
github.com/samber/lo v1.51.0 h1:kysRYLbHy/MB7kQZf5DSN50JHmMsNEdeY24VzJFu7wI=
|
||||
github.com/samber/lo v1.51.0/go.mod h1:4+MXEGsJzbKGaUEQFKBq2xtfuznW9oz/WrgyzMzRoM0=
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
@@ -1095,6 +1097,8 @@ golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
|
||||
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
|
||||
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
||||
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@@ -1212,6 +1216,8 @@ golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
|
||||
golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
|
||||
golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
|
||||
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
|
||||
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
|
||||
@@ -16,13 +16,13 @@ import (
|
||||
"github.com/go-acme/lego/v4/challenge"
|
||||
"github.com/go-acme/lego/v4/challenge/dns01"
|
||||
"github.com/go-acme/lego/v4/lego"
|
||||
"github.com/samber/lo"
|
||||
"golang.org/x/exp/slices"
|
||||
"golang.org/x/time/rate"
|
||||
|
||||
"github.com/certimate-go/certimate/internal/domain"
|
||||
"github.com/certimate-go/certimate/internal/repository"
|
||||
xmaps "github.com/certimate-go/certimate/pkg/utils/maps"
|
||||
xslices "github.com/certimate-go/certimate/pkg/utils/slices"
|
||||
)
|
||||
|
||||
type ApplyResult struct {
|
||||
@@ -55,7 +55,7 @@ func NewWithWorkflowNode(config ApplicantWithWorkflowNodeConfig) (Applicant, err
|
||||
|
||||
nodeCfg := config.Node.GetConfigForApply()
|
||||
options := &applicantProviderOptions{
|
||||
Domains: xslices.Filter(strings.Split(nodeCfg.Domains, ";"), func(s string) bool { return s != "" }),
|
||||
Domains: lo.Filter(strings.Split(nodeCfg.Domains, ";"), func(s string, _ int) bool { return s != "" }),
|
||||
ContactEmail: nodeCfg.ContactEmail,
|
||||
Provider: domain.ACMEDns01ProviderType(nodeCfg.Provider),
|
||||
ProviderAccessConfig: make(map[string]any),
|
||||
@@ -65,7 +65,7 @@ func NewWithWorkflowNode(config ApplicantWithWorkflowNodeConfig) (Applicant, err
|
||||
CAProviderServiceConfig: nodeCfg.CAProviderConfig,
|
||||
KeyAlgorithm: nodeCfg.KeyAlgorithm,
|
||||
ACMEProfile: nodeCfg.ACMEProfile,
|
||||
Nameservers: xslices.Filter(strings.Split(nodeCfg.Nameservers, ";"), func(s string) bool { return s != "" }),
|
||||
Nameservers: lo.Filter(strings.Split(nodeCfg.Nameservers, ";"), func(s string, _ int) bool { return s != "" }),
|
||||
DnsPropagationWait: nodeCfg.DnsPropagationWait,
|
||||
DnsPropagationTimeout: nodeCfg.DnsPropagationTimeout,
|
||||
DnsTTL: nodeCfg.DnsTTL,
|
||||
|
||||
@@ -5,6 +5,8 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/internal/domain"
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
p1PanelConsole "github.com/certimate-go/certimate/pkg/core/ssl-deployer/providers/1panel-console"
|
||||
@@ -107,7 +109,6 @@ import (
|
||||
pWebhook "github.com/certimate-go/certimate/pkg/core/ssl-deployer/providers/webhook"
|
||||
xhttp "github.com/certimate-go/certimate/pkg/utils/http"
|
||||
xmaps "github.com/certimate-go/certimate/pkg/utils/maps"
|
||||
xslices "github.com/certimate-go/certimate/pkg/utils/slices"
|
||||
)
|
||||
|
||||
type deployerProviderOptions struct {
|
||||
@@ -206,8 +207,8 @@ func createSSLDeployerProvider(options *deployerProviderOptions) (core.SSLDeploy
|
||||
AccessKeySecret: access.AccessKeySecret,
|
||||
ResourceGroupId: access.ResourceGroupId,
|
||||
Region: xmaps.GetString(options.ProviderServiceConfig, "region"),
|
||||
ResourceIds: xslices.Filter(strings.Split(xmaps.GetString(options.ProviderServiceConfig, "resourceIds"), ";"), func(s string) bool { return s != "" }),
|
||||
ContactIds: xslices.Filter(strings.Split(xmaps.GetString(options.ProviderServiceConfig, "contactIds"), ";"), func(s string) bool { return s != "" }),
|
||||
ResourceIds: lo.Filter(strings.Split(xmaps.GetString(options.ProviderServiceConfig, "resourceIds"), ";"), func(s string, _ int) bool { return s != "" }),
|
||||
ContactIds: lo.Filter(strings.Split(xmaps.GetString(options.ProviderServiceConfig, "contactIds"), ";"), func(s string, _ int) bool { return s != "" }),
|
||||
})
|
||||
return deployer, err
|
||||
|
||||
@@ -522,7 +523,7 @@ func createSSLDeployerProvider(options *deployerProviderOptions) (core.SSLDeploy
|
||||
AllowInsecureConnections: access.AllowInsecureConnections,
|
||||
SiteType: xmaps.GetOrDefaultString(options.ProviderServiceConfig, "siteType", "other"),
|
||||
SiteName: xmaps.GetString(options.ProviderServiceConfig, "siteName"),
|
||||
SiteNames: xslices.Filter(strings.Split(xmaps.GetString(options.ProviderServiceConfig, "siteNames"), ";"), func(s string) bool { return s != "" }),
|
||||
SiteNames: lo.Filter(strings.Split(xmaps.GetString(options.ProviderServiceConfig, "siteNames"), ";"), func(s string, _ int) bool { return s != "" }),
|
||||
})
|
||||
return deployer, err
|
||||
|
||||
@@ -1211,7 +1212,7 @@ func createSSLDeployerProvider(options *deployerProviderOptions) (core.SSLDeploy
|
||||
SecretKey: access.SecretKey,
|
||||
Endpoint: xmaps.GetString(options.ProviderServiceConfig, "endpoint"),
|
||||
ZoneId: xmaps.GetString(options.ProviderServiceConfig, "zoneId"),
|
||||
Domains: xslices.Filter(strings.Split(xmaps.GetString(options.ProviderServiceConfig, "domains"), ";"), func(s string) bool { return s != "" }),
|
||||
Domains: lo.Filter(strings.Split(xmaps.GetString(options.ProviderServiceConfig, "domains"), ";"), func(s string, _ int) bool { return s != "" }),
|
||||
})
|
||||
return deployer, err
|
||||
|
||||
@@ -1251,7 +1252,7 @@ func createSSLDeployerProvider(options *deployerProviderOptions) (core.SSLDeploy
|
||||
Endpoint: xmaps.GetString(options.ProviderServiceConfig, "endpoint"),
|
||||
Region: xmaps.GetString(options.ProviderServiceConfig, "region"),
|
||||
ResourceType: xmaps.GetString(options.ProviderServiceConfig, "resourceType"),
|
||||
ResourceIds: xslices.Filter(strings.Split(xmaps.GetString(options.ProviderServiceConfig, "resourceIds"), ";"), func(s string) bool { return s != "" }),
|
||||
ResourceIds: lo.Filter(strings.Split(xmaps.GetString(options.ProviderServiceConfig, "resourceIds"), ";"), func(s string, _ int) bool { return s != "" }),
|
||||
})
|
||||
return deployer, err
|
||||
|
||||
@@ -1262,8 +1263,8 @@ func createSSLDeployerProvider(options *deployerProviderOptions) (core.SSLDeploy
|
||||
Endpoint: xmaps.GetString(options.ProviderServiceConfig, "endpoint"),
|
||||
CertificateId: xmaps.GetString(options.ProviderServiceConfig, "certificateId"),
|
||||
IsReplaced: xmaps.GetBool(options.ProviderServiceConfig, "isReplaced"),
|
||||
ResourceTypes: xslices.Filter(strings.Split(xmaps.GetString(options.ProviderServiceConfig, "resourceTypes"), ";"), func(s string) bool { return s != "" }),
|
||||
ResourceRegions: xslices.Filter(strings.Split(xmaps.GetString(options.ProviderServiceConfig, "resourceRegions"), ";"), func(s string) bool { return s != "" }),
|
||||
ResourceTypes: lo.Filter(strings.Split(xmaps.GetString(options.ProviderServiceConfig, "resourceTypes"), ";"), func(s string, _ int) bool { return s != "" }),
|
||||
ResourceRegions: lo.Filter(strings.Split(xmaps.GetString(options.ProviderServiceConfig, "resourceRegions"), ";"), func(s string, _ int) bool { return s != "" }),
|
||||
})
|
||||
return deployer, err
|
||||
|
||||
@@ -1464,7 +1465,7 @@ func createSSLDeployerProvider(options *deployerProviderOptions) (core.SSLDeploy
|
||||
deployer, err := pWangsuCDN.NewSSLDeployerProvider(&pWangsuCDN.SSLDeployerProviderConfig{
|
||||
AccessKeyId: access.AccessKeyId,
|
||||
AccessKeySecret: access.AccessKeySecret,
|
||||
Domains: xslices.Filter(strings.Split(xmaps.GetString(options.ProviderServiceConfig, "domains"), ";"), func(s string) bool { return s != "" }),
|
||||
Domains: lo.Filter(strings.Split(xmaps.GetString(options.ProviderServiceConfig, "domains"), ";"), func(s string, _ int) bool { return s != "" }),
|
||||
})
|
||||
return deployer, err
|
||||
|
||||
|
||||
@@ -12,9 +12,10 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/internal/app"
|
||||
"github.com/certimate-go/certimate/internal/domain"
|
||||
xslices "github.com/certimate-go/certimate/pkg/utils/slices"
|
||||
)
|
||||
|
||||
var maxWorkers = 1
|
||||
@@ -126,7 +127,7 @@ func (d *WorkflowDispatcher) Cancel(runId string) {
|
||||
|
||||
// 移除排队中的 WorkflowRun
|
||||
d.queueMutex.Lock()
|
||||
d.queue = xslices.Filter(d.queue, func(d *WorkflowWorkerData) bool {
|
||||
d.queue = lo.Filter(d.queue, func(d *WorkflowWorkerData, _ int) bool {
|
||||
return d.RunId != runId
|
||||
})
|
||||
d.queueMutex.Unlock()
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
"github.com/go-acme/lego/v4/challenge"
|
||||
"github.com/go-acme/lego/v4/challenge/dns01"
|
||||
"github.com/go-acme/lego/v4/platform/config/env"
|
||||
"github.com/samber/lo"
|
||||
|
||||
ctyundns "github.com/certimate-go/certimate/pkg/sdk3rd/ctyun/dns"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -129,9 +129,9 @@ func (d *DNSProvider) findDNSRecordId(zoneName, subDomain string) (int32, error)
|
||||
// 查询解析记录列表
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=122&api=11264&data=181&isNormal=1&vid=259
|
||||
request := &ctyundns.QueryRecordListRequest{}
|
||||
request.Domain = xtypes.ToPtr(zoneName)
|
||||
request.Host = xtypes.ToPtr(subDomain)
|
||||
request.Type = xtypes.ToPtr("TXT")
|
||||
request.Domain = lo.ToPtr(zoneName)
|
||||
request.Host = lo.ToPtr(subDomain)
|
||||
request.Type = lo.ToPtr("TXT")
|
||||
|
||||
response, err := d.client.QueryRecordList(request)
|
||||
if err != nil {
|
||||
@@ -155,13 +155,13 @@ func (d *DNSProvider) addOrUpdateDNSRecord(zoneName, subDomain, value string) er
|
||||
// 新增解析记录
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=122&api=11259&data=181&isNormal=1&vid=259
|
||||
request := &ctyundns.AddRecordRequest{
|
||||
Domain: xtypes.ToPtr(zoneName),
|
||||
Host: xtypes.ToPtr(subDomain),
|
||||
Type: xtypes.ToPtr("TXT"),
|
||||
LineCode: xtypes.ToPtr("Default"),
|
||||
Value: xtypes.ToPtr(value),
|
||||
State: xtypes.ToPtr(int32(1)),
|
||||
TTL: xtypes.ToPtr(int32(d.config.TTL)),
|
||||
Domain: lo.ToPtr(zoneName),
|
||||
Host: lo.ToPtr(subDomain),
|
||||
Type: lo.ToPtr("TXT"),
|
||||
LineCode: lo.ToPtr("Default"),
|
||||
Value: lo.ToPtr(value),
|
||||
State: lo.ToPtr(int32(1)),
|
||||
TTL: lo.ToPtr(int32(d.config.TTL)),
|
||||
}
|
||||
_, err := d.client.AddRecord(request)
|
||||
return err
|
||||
@@ -169,14 +169,14 @@ func (d *DNSProvider) addOrUpdateDNSRecord(zoneName, subDomain, value string) er
|
||||
// 修改解析记录
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=122&api=11261&data=181&isNormal=1&vid=259
|
||||
request := &ctyundns.UpdateRecordRequest{
|
||||
RecordId: xtypes.ToPtr(recordId),
|
||||
Domain: xtypes.ToPtr(zoneName),
|
||||
Host: xtypes.ToPtr(subDomain),
|
||||
Type: xtypes.ToPtr("TXT"),
|
||||
LineCode: xtypes.ToPtr("Default"),
|
||||
Value: xtypes.ToPtr(value),
|
||||
State: xtypes.ToPtr(int32(1)),
|
||||
TTL: xtypes.ToPtr(int32(d.config.TTL)),
|
||||
RecordId: lo.ToPtr(recordId),
|
||||
Domain: lo.ToPtr(zoneName),
|
||||
Host: lo.ToPtr(subDomain),
|
||||
Type: lo.ToPtr("TXT"),
|
||||
LineCode: lo.ToPtr("Default"),
|
||||
Value: lo.ToPtr(value),
|
||||
State: lo.ToPtr(int32(1)),
|
||||
TTL: lo.ToPtr(int32(d.config.TTL)),
|
||||
}
|
||||
_, err := d.client.UpdateRecord(request)
|
||||
return err
|
||||
@@ -195,7 +195,7 @@ func (d *DNSProvider) removeDNSRecord(zoneName, subDomain string) error {
|
||||
// 删除解析记录
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=122&api=11262&data=181&isNormal=1&vid=259
|
||||
request := &ctyundns.DeleteRecordRequest{
|
||||
RecordId: xtypes.ToPtr(recordId),
|
||||
RecordId: lo.ToPtr(recordId),
|
||||
}
|
||||
_, err = d.client.DeleteRecord(request)
|
||||
return err
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
"github.com/go-acme/lego/v4/challenge"
|
||||
"github.com/go-acme/lego/v4/challenge/dns01"
|
||||
"github.com/go-acme/lego/v4/platform/config/env"
|
||||
"github.com/samber/lo"
|
||||
|
||||
gnamesdk "github.com/certimate-go/certimate/pkg/sdk3rd/gname"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -131,9 +131,9 @@ func (d *DNSProvider) findDNSRecord(zoneName, subDomain string) (*gnamesdk.Domai
|
||||
pageSize := int32(20)
|
||||
for {
|
||||
request := &gnamesdk.ListDomainResolutionRequest{
|
||||
ZoneName: xtypes.ToPtr(zoneName),
|
||||
Page: xtypes.ToPtr(page),
|
||||
PageSize: xtypes.ToPtr(pageSize),
|
||||
ZoneName: lo.ToPtr(zoneName),
|
||||
Page: lo.ToPtr(page),
|
||||
PageSize: lo.ToPtr(pageSize),
|
||||
}
|
||||
|
||||
response, err := d.client.ListDomainResolution(request)
|
||||
@@ -168,23 +168,23 @@ func (d *DNSProvider) addOrUpdateDNSRecord(zoneName, subDomain, value string) er
|
||||
|
||||
if record == nil {
|
||||
request := &gnamesdk.AddDomainResolutionRequest{
|
||||
ZoneName: xtypes.ToPtr(zoneName),
|
||||
RecordType: xtypes.ToPtr("TXT"),
|
||||
RecordName: xtypes.ToPtr(subDomain),
|
||||
RecordValue: xtypes.ToPtr(value),
|
||||
TTL: xtypes.ToPtr(int32(d.config.TTL)),
|
||||
ZoneName: lo.ToPtr(zoneName),
|
||||
RecordType: lo.ToPtr("TXT"),
|
||||
RecordName: lo.ToPtr(subDomain),
|
||||
RecordValue: lo.ToPtr(value),
|
||||
TTL: lo.ToPtr(int32(d.config.TTL)),
|
||||
}
|
||||
_, err := d.client.AddDomainResolution(request)
|
||||
return err
|
||||
} else {
|
||||
recordId, _ := record.ID.Int64()
|
||||
request := &gnamesdk.ModifyDomainResolutionRequest{
|
||||
ID: xtypes.ToPtr(recordId),
|
||||
ZoneName: xtypes.ToPtr(zoneName),
|
||||
RecordType: xtypes.ToPtr("TXT"),
|
||||
RecordName: xtypes.ToPtr(subDomain),
|
||||
RecordValue: xtypes.ToPtr(value),
|
||||
TTL: xtypes.ToPtr(int32(d.config.TTL)),
|
||||
ID: lo.ToPtr(recordId),
|
||||
ZoneName: lo.ToPtr(zoneName),
|
||||
RecordType: lo.ToPtr("TXT"),
|
||||
RecordName: lo.ToPtr(subDomain),
|
||||
RecordValue: lo.ToPtr(value),
|
||||
TTL: lo.ToPtr(int32(d.config.TTL)),
|
||||
}
|
||||
_, err := d.client.ModifyDomainResolution(request)
|
||||
return err
|
||||
@@ -203,8 +203,8 @@ func (d *DNSProvider) removeDNSRecord(zoneName, subDomain string) error {
|
||||
|
||||
recordId, _ := record.ID.Int64()
|
||||
request := &gnamesdk.DeleteDomainResolutionRequest{
|
||||
ZoneName: xtypes.ToPtr(zoneName),
|
||||
RecordID: xtypes.ToPtr(recordId),
|
||||
ZoneName: lo.ToPtr(zoneName),
|
||||
RecordID: lo.ToPtr(recordId),
|
||||
}
|
||||
_, err = d.client.DeleteDomainResolution(request)
|
||||
return err
|
||||
|
||||
@@ -13,11 +13,11 @@ import (
|
||||
alicas "github.com/alibabacloud-go/cas-20200407/v3/client"
|
||||
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||
"github.com/alibabacloud-go/tea/tea"
|
||||
"github.com/samber/lo"
|
||||
"golang.org/x/exp/slices"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/aliyun-cas"
|
||||
"github.com/certimate-go/certimate/pkg/utils/ifelse"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -70,9 +70,8 @@ func NewSSLDeployerProvider(config *SSLDeployerProviderConfig) (*SSLDeployerProv
|
||||
AccessKeyId: config.AccessKeyId,
|
||||
AccessKeySecret: config.AccessKeySecret,
|
||||
ResourceGroupId: config.ResourceGroupId,
|
||||
Region: ifelse.
|
||||
If[string](config.Region == "" || strings.HasPrefix(config.Region, "cn-")).
|
||||
Then("cn-hangzhou").
|
||||
Region: lo.
|
||||
If(config.Region == "" || strings.HasPrefix(config.Region, "cn-"), "cn-hangzhou").
|
||||
Else("ap-southeast-1"),
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -12,11 +12,10 @@ import (
|
||||
alicloudapi "github.com/alibabacloud-go/cloudapi-20160714/v5/client"
|
||||
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||
"github.com/alibabacloud-go/tea/tea"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/aliyun-cas"
|
||||
"github.com/certimate-go/certimate/pkg/utils/ifelse"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -68,9 +67,8 @@ func NewSSLDeployerProvider(config *SSLDeployerProviderConfig) (*SSLDeployerProv
|
||||
AccessKeyId: config.AccessKeyId,
|
||||
AccessKeySecret: config.AccessKeySecret,
|
||||
ResourceGroupId: config.ResourceGroupId,
|
||||
Region: ifelse.
|
||||
If[string](config.Region == "" || strings.HasPrefix(config.Region, "cn-")).
|
||||
Then("cn-hangzhou").
|
||||
Region: lo.
|
||||
If(config.Region == "" || strings.HasPrefix(config.Region, "cn-"), "cn-hangzhou").
|
||||
Else("ap-southeast-1"),
|
||||
})
|
||||
if err != nil {
|
||||
@@ -159,7 +157,7 @@ func (d *SSLDeployerProvider) deployToCloudNative(ctx context.Context, certPEM s
|
||||
}
|
||||
|
||||
listDomainsReq := &aliapig.ListDomainsRequest{
|
||||
ResourceGroupId: xtypes.ToPtrOrZeroNil(d.config.ResourceGroupId),
|
||||
ResourceGroupId: lo.EmptyableToPtr(d.config.ResourceGroupId),
|
||||
GatewayId: tea.String(d.config.GatewayId),
|
||||
NameLike: tea.String(d.config.Domain),
|
||||
PageNumber: tea.Int32(listDomainsPageNumber),
|
||||
|
||||
@@ -11,10 +11,10 @@ import (
|
||||
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||
aliddos "github.com/alibabacloud-go/ddoscoo-20200101/v4/client"
|
||||
"github.com/alibabacloud-go/tea/tea"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/aliyun-cas"
|
||||
"github.com/certimate-go/certimate/pkg/utils/ifelse"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -53,9 +53,8 @@ func NewSSLDeployerProvider(config *SSLDeployerProviderConfig) (*SSLDeployerProv
|
||||
AccessKeyId: config.AccessKeyId,
|
||||
AccessKeySecret: config.AccessKeySecret,
|
||||
ResourceGroupId: config.ResourceGroupId,
|
||||
Region: ifelse.
|
||||
If[string](config.Region == "" || strings.HasPrefix(config.Region, "cn-")).
|
||||
Then("cn-hangzhou").
|
||||
Region: lo.
|
||||
If(config.Region == "" || strings.HasPrefix(config.Region, "cn-"), "cn-hangzhou").
|
||||
Else("ap-southeast-1"),
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -11,10 +11,10 @@ import (
|
||||
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||
aliesa "github.com/alibabacloud-go/esa-20240910/v2/client"
|
||||
"github.com/alibabacloud-go/tea/tea"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/aliyun-cas"
|
||||
"github.com/certimate-go/certimate/pkg/utils/ifelse"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -53,9 +53,8 @@ func NewSSLDeployerProvider(config *SSLDeployerProviderConfig) (*SSLDeployerProv
|
||||
AccessKeyId: config.AccessKeyId,
|
||||
AccessKeySecret: config.AccessKeySecret,
|
||||
ResourceGroupId: config.ResourceGroupId,
|
||||
Region: ifelse.
|
||||
If[string](config.Region == "" || strings.HasPrefix(config.Region, "cn-")).
|
||||
Then("cn-hangzhou").
|
||||
Region: lo.
|
||||
If(config.Region == "" || strings.HasPrefix(config.Region, "cn-"), "cn-hangzhou").
|
||||
Else("ap-southeast-1"),
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||
aliga "github.com/alibabacloud-go/ga-20191120/v3/client"
|
||||
"github.com/alibabacloud-go/tea/tea"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/aliyun-cas"
|
||||
xslices "github.com/certimate-go/certimate/pkg/utils/slices"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -256,14 +256,14 @@ func (d *SSLDeployerProvider) updateListenerCertificate(ctx context.Context, clo
|
||||
}
|
||||
} else {
|
||||
// 指定 SNI,需部署到扩展域名
|
||||
if xslices.Some(listenerAdditionalCertificates, func(item *aliga.ListListenerCertificatesResponseBodyCertificates) bool {
|
||||
if lo.SomeBy(listenerAdditionalCertificates, func(item *aliga.ListListenerCertificatesResponseBodyCertificates) bool {
|
||||
return tea.StringValue(item.CertificateId) == cloudCertId
|
||||
}) {
|
||||
d.logger.Info("no need to update ga listener additional certificate")
|
||||
return nil
|
||||
}
|
||||
|
||||
if xslices.Some(listenerAdditionalCertificates, func(item *aliga.ListListenerCertificatesResponseBodyCertificates) bool {
|
||||
if lo.SomeBy(listenerAdditionalCertificates, func(item *aliga.ListListenerCertificatesResponseBodyCertificates) bool {
|
||||
return tea.StringValue(item.Domain) == d.config.Domain
|
||||
}) {
|
||||
// 为监听替换扩展证书
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||
alinlb "github.com/alibabacloud-go/nlb-20220430/v2/client"
|
||||
"github.com/alibabacloud-go/tea/tea"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/aliyun-cas"
|
||||
"github.com/certimate-go/certimate/pkg/utils/ifelse"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -58,9 +58,8 @@ func NewSSLDeployerProvider(config *SSLDeployerProviderConfig) (*SSLDeployerProv
|
||||
AccessKeyId: config.AccessKeyId,
|
||||
AccessKeySecret: config.AccessKeySecret,
|
||||
ResourceGroupId: config.ResourceGroupId,
|
||||
Region: ifelse.
|
||||
If[string](config.Region == "" || strings.HasPrefix(config.Region, "cn-")).
|
||||
Then("cn-hangzhou").
|
||||
Region: lo.
|
||||
If(config.Region == "" || strings.HasPrefix(config.Region, "cn-"), "cn-hangzhou").
|
||||
Else("ap-southeast-1"),
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -10,12 +10,10 @@ import (
|
||||
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||
"github.com/alibabacloud-go/tea/tea"
|
||||
aliwaf "github.com/alibabacloud-go/waf-openapi-20211001/v5/client"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/aliyun-cas"
|
||||
"github.com/certimate-go/certimate/pkg/utils/ifelse"
|
||||
xslices "github.com/certimate-go/certimate/pkg/utils/slices"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -58,9 +56,8 @@ func NewSSLDeployerProvider(config *SSLDeployerProviderConfig) (*SSLDeployerProv
|
||||
AccessKeyId: config.AccessKeyId,
|
||||
AccessKeySecret: config.AccessKeySecret,
|
||||
ResourceGroupId: config.ResourceGroupId,
|
||||
Region: ifelse.
|
||||
If[string](config.Region == "" || strings.HasPrefix(config.Region, "cn-")).
|
||||
Then("cn-hangzhou").
|
||||
Region: lo.
|
||||
If(config.Region == "" || strings.HasPrefix(config.Region, "cn-"), "cn-hangzhou").
|
||||
Else("ap-southeast-1"),
|
||||
})
|
||||
if err != nil {
|
||||
@@ -118,7 +115,7 @@ func (d *SSLDeployerProvider) deployToWAF3(ctx context.Context, certPEM string,
|
||||
// 查询默认 SSL/TLS 设置
|
||||
// REF: https://help.aliyun.com/zh/waf/web-application-firewall-3-0/developer-reference/api-waf-openapi-2021-10-01-describedefaulthttps
|
||||
describeDefaultHttpsReq := &aliwaf.DescribeDefaultHttpsRequest{
|
||||
ResourceManagerResourceGroupId: xtypes.ToPtrOrZeroNil(d.config.ResourceGroupId),
|
||||
ResourceManagerResourceGroupId: lo.EmptyableToPtr(d.config.ResourceGroupId),
|
||||
InstanceId: tea.String(d.config.InstanceId),
|
||||
RegionId: tea.String(d.config.Region),
|
||||
}
|
||||
@@ -131,7 +128,7 @@ func (d *SSLDeployerProvider) deployToWAF3(ctx context.Context, certPEM string,
|
||||
// 修改默认 SSL/TLS 设置
|
||||
// REF: https://help.aliyun.com/zh/waf/web-application-firewall-3-0/developer-reference/api-waf-openapi-2021-10-01-modifydefaulthttps
|
||||
modifyDefaultHttpsReq := &aliwaf.ModifyDefaultHttpsRequest{
|
||||
ResourceManagerResourceGroupId: xtypes.ToPtrOrZeroNil(d.config.ResourceGroupId),
|
||||
ResourceManagerResourceGroupId: lo.EmptyableToPtr(d.config.ResourceGroupId),
|
||||
InstanceId: tea.String(d.config.InstanceId),
|
||||
RegionId: tea.String(d.config.Region),
|
||||
CertId: tea.String(upres.CertId),
|
||||
@@ -245,7 +242,7 @@ func assign(source *aliwaf.ModifyDomainRequest, target *aliwaf.DescribeDomainDet
|
||||
}
|
||||
|
||||
if target.Listen.HttpPorts != nil {
|
||||
source.Listen.HttpPorts = xslices.Map(target.Listen.HttpPorts, func(v *int64) *int32 {
|
||||
source.Listen.HttpPorts = lo.Map(target.Listen.HttpPorts, func(v *int64, _ int) *int32 {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -254,7 +251,7 @@ func assign(source *aliwaf.ModifyDomainRequest, target *aliwaf.DescribeDomainDet
|
||||
}
|
||||
|
||||
if target.Listen.HttpsPorts != nil {
|
||||
source.Listen.HttpsPorts = xslices.Map(target.Listen.HttpsPorts, func(v *int64) *int32 {
|
||||
source.Listen.HttpsPorts = lo.Map(target.Listen.HttpsPorts, func(v *int64, _ int) *int32 {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -289,7 +286,7 @@ func assign(source *aliwaf.ModifyDomainRequest, target *aliwaf.DescribeDomainDet
|
||||
}
|
||||
|
||||
if target.Redirect.Backends != nil {
|
||||
source.Redirect.Backends = xslices.Map(target.Redirect.Backends, func(v *aliwaf.DescribeDomainDetailResponseBodyRedirectBackends) *string {
|
||||
source.Redirect.Backends = lo.Map(target.Redirect.Backends, func(v *aliwaf.DescribeDomainDetailResponseBodyRedirectBackends, _ int) *string {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -298,7 +295,7 @@ func assign(source *aliwaf.ModifyDomainRequest, target *aliwaf.DescribeDomainDet
|
||||
}
|
||||
|
||||
if target.Redirect.BackupBackends != nil {
|
||||
source.Redirect.BackupBackends = xslices.Map(target.Redirect.BackupBackends, func(v *aliwaf.DescribeDomainDetailResponseBodyRedirectBackupBackends) *string {
|
||||
source.Redirect.BackupBackends = lo.Map(target.Redirect.BackupBackends, func(v *aliwaf.DescribeDomainDetailResponseBodyRedirectBackupBackends, _ int) *string {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
@@ -335,7 +332,7 @@ func assign(source *aliwaf.ModifyDomainRequest, target *aliwaf.DescribeDomainDet
|
||||
}
|
||||
|
||||
if target.Redirect.RequestHeaders != nil {
|
||||
source.Redirect.RequestHeaders = xslices.Map(target.Redirect.RequestHeaders, func(v *aliwaf.DescribeDomainDetailResponseBodyRedirectRequestHeaders) *aliwaf.ModifyDomainRequestRedirectRequestHeaders {
|
||||
source.Redirect.RequestHeaders = lo.Map(target.Redirect.RequestHeaders, func(v *aliwaf.DescribeDomainDetailResponseBodyRedirectRequestHeaders, _ int) *aliwaf.ModifyDomainRequestRedirectRequestHeaders {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -7,10 +7,11 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
apisixsdk "github.com/certimate-go/certimate/pkg/sdk3rd/apisix"
|
||||
xcert "github.com/certimate-go/certimate/pkg/utils/cert"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -89,11 +90,11 @@ func (d *SSLDeployerProvider) deployToCertificate(ctx context.Context, certPEM s
|
||||
// 更新 SSL 证书
|
||||
// REF: https://apisix.apache.org/zh/docs/apisix/admin-api/#ssl
|
||||
updateSSLReq := &apisixsdk.UpdateSSLRequest{
|
||||
Cert: xtypes.ToPtr(certPEM),
|
||||
Key: xtypes.ToPtr(privkeyPEM),
|
||||
SNIs: xtypes.ToPtr(certX509.DNSNames),
|
||||
Type: xtypes.ToPtr("server"),
|
||||
Status: xtypes.ToPtr(int32(1)),
|
||||
Cert: lo.ToPtr(certPEM),
|
||||
Key: lo.ToPtr(privkeyPEM),
|
||||
SNIs: lo.ToPtr(certX509.DNSNames),
|
||||
Type: lo.ToPtr("server"),
|
||||
Status: lo.ToPtr(int32(1)),
|
||||
}
|
||||
updateSSLResp, err := d.sdkClient.UpdateSSL(d.config.CertificateId, updateSSLReq)
|
||||
d.logger.Debug("sdk request 'apisix.UpdateSSL'", slog.String("sslId", d.config.CertificateId), slog.Any("request", updateSSLReq), slog.Any("response", updateSSLResp))
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
|
||||
bceappblb "github.com/baidubce/bce-sdk-go/services/appblb"
|
||||
"github.com/google/uuid"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/baiducloud-cert"
|
||||
xslices "github.com/certimate-go/certimate/pkg/utils/slices"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -284,7 +284,7 @@ func (d *SSLDeployerProvider) updateHttpsListenerCertificate(ctx context.Context
|
||||
ListenerPort: uint16(cloudHttpsListenerPort),
|
||||
Scheduler: describeAppHTTPSListenersResp.ListenerList[0].Scheduler,
|
||||
CertIds: describeAppHTTPSListenersResp.ListenerList[0].CertIds,
|
||||
AdditionalCertDomains: xslices.Map(describeAppHTTPSListenersResp.ListenerList[0].AdditionalCertDomains, func(domain bceappblb.AdditionalCertDomainsModel) bceappblb.AdditionalCertDomainsModel {
|
||||
AdditionalCertDomains: lo.Map(describeAppHTTPSListenersResp.ListenerList[0].AdditionalCertDomains, func(domain bceappblb.AdditionalCertDomainsModel, _ int) bceappblb.AdditionalCertDomainsModel {
|
||||
if domain.Host == d.config.Domain {
|
||||
return bceappblb.AdditionalCertDomainsModel{
|
||||
Host: domain.Host,
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
|
||||
bceblb "github.com/baidubce/bce-sdk-go/services/blb"
|
||||
"github.com/google/uuid"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/baiducloud-cert"
|
||||
xslices "github.com/certimate-go/certimate/pkg/utils/slices"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -282,7 +282,7 @@ func (d *SSLDeployerProvider) updateHttpsListenerCertificate(ctx context.Context
|
||||
ClientToken: generateClientToken(),
|
||||
ListenerPort: uint16(cloudHttpsListenerPort),
|
||||
CertIds: describeHTTPSListenersResp.ListenerList[0].CertIds,
|
||||
AdditionalCertDomains: xslices.Map(describeHTTPSListenersResp.ListenerList[0].AdditionalCertDomains, func(domain bceblb.AdditionalCertDomainsModel) bceblb.AdditionalCertDomainsModel {
|
||||
AdditionalCertDomains: lo.Map(describeHTTPSListenersResp.ListenerList[0].AdditionalCertDomains, func(domain bceblb.AdditionalCertDomainsModel, _ int) bceblb.AdditionalCertDomainsModel {
|
||||
if domain.Host == d.config.Domain {
|
||||
return bceblb.AdditionalCertDomainsModel{
|
||||
Host: domain.Host,
|
||||
|
||||
@@ -10,9 +10,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
bssdk "github.com/certimate-go/certimate/pkg/sdk3rd/baishan"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -69,9 +70,9 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
// REF: https://portal.baishancloud.com/track/document/downloadPdf/1441
|
||||
certificateId := ""
|
||||
setDomainCertificateReq := &bssdk.SetDomainCertificateRequest{
|
||||
Name: xtypes.ToPtr(fmt.Sprintf("certimate_%d", time.Now().UnixMilli())),
|
||||
Certificate: xtypes.ToPtr(certPEM),
|
||||
Key: xtypes.ToPtr(privkeyPEM),
|
||||
Name: lo.ToPtr(fmt.Sprintf("certimate_%d", time.Now().UnixMilli())),
|
||||
Certificate: lo.ToPtr(certPEM),
|
||||
Key: lo.ToPtr(privkeyPEM),
|
||||
}
|
||||
setDomainCertificateResp, err := d.sdkClient.SetDomainCertificate(setDomainCertificateReq)
|
||||
d.logger.Debug("sdk request 'baishan.SetDomainCertificate'", slog.Any("request", setDomainCertificateReq), slog.Any("response", setDomainCertificateResp))
|
||||
@@ -94,8 +95,8 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
// 查询域名配置
|
||||
// REF: https://portal.baishancloud.com/track/document/api/1/1065
|
||||
getDomainConfigReq := &bssdk.GetDomainConfigRequest{
|
||||
Domains: xtypes.ToPtr(d.config.Domain),
|
||||
Config: xtypes.ToPtr([]string{"https"}),
|
||||
Domains: lo.ToPtr(d.config.Domain),
|
||||
Config: lo.ToPtr([]string{"https"}),
|
||||
}
|
||||
getDomainConfigResp, err := d.sdkClient.GetDomainConfig(getDomainConfigReq)
|
||||
d.logger.Debug("sdk request 'baishan.GetDomainConfig'", slog.Any("request", getDomainConfigReq), slog.Any("response", getDomainConfigResp))
|
||||
@@ -108,7 +109,7 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
// 设置域名配置
|
||||
// REF: https://portal.baishancloud.com/track/document/api/1/1045
|
||||
setDomainConfigReq := &bssdk.SetDomainConfigRequest{
|
||||
Domains: xtypes.ToPtr(d.config.Domain),
|
||||
Domains: lo.ToPtr(d.config.Domain),
|
||||
Config: &bssdk.DomainConfig{
|
||||
Https: &bssdk.DomainConfigHttps{
|
||||
CertId: json.Number(certificateId),
|
||||
@@ -128,9 +129,9 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
// REF: https://portal.baishancloud.com/track/document/downloadPdf/1441
|
||||
setDomainCertificateReq := &bssdk.SetDomainCertificateRequest{
|
||||
CertificateId: &d.config.CertificateId,
|
||||
Name: xtypes.ToPtr(fmt.Sprintf("certimate_%d", time.Now().UnixMilli())),
|
||||
Certificate: xtypes.ToPtr(certPEM),
|
||||
Key: xtypes.ToPtr(privkeyPEM),
|
||||
Name: lo.ToPtr(fmt.Sprintf("certimate_%d", time.Now().UnixMilli())),
|
||||
Certificate: lo.ToPtr(certPEM),
|
||||
Key: lo.ToPtr(privkeyPEM),
|
||||
}
|
||||
setDomainCertificateResp, err := d.sdkClient.SetDomainCertificate(setDomainCertificateReq)
|
||||
d.logger.Debug("sdk request 'baishan.SetDomainCertificate'", slog.Any("request", setDomainCertificateReq), slog.Any("response", setDomainCertificateResp))
|
||||
|
||||
@@ -7,9 +7,10 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
btsdk "github.com/certimate-go/certimate/pkg/sdk3rd/btpanel"
|
||||
xslices "github.com/certimate-go/certimate/pkg/utils/slices"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -101,7 +102,7 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
|
||||
// 设置站点证书
|
||||
sslSetBatchCertToSiteReq := &btsdk.SSLSetBatchCertToSiteRequest{
|
||||
BatchInfo: xslices.Map(d.config.SiteNames, func(siteName string) *btsdk.SSLSetBatchCertToSiteRequestBatchInfo {
|
||||
BatchInfo: lo.Map(d.config.SiteNames, func(siteName string, _ int) *btsdk.SSLSetBatchCertToSiteRequestBatchInfo {
|
||||
return &btsdk.SSLSetBatchCertToSiteRequestBatchInfo{
|
||||
SiteName: siteName,
|
||||
SSLHash: sslCertSaveCertResp.SSLHash,
|
||||
|
||||
@@ -7,9 +7,10 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
btwafsdk "github.com/certimate-go/certimate/pkg/sdk3rd/btwaf"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -57,8 +58,8 @@ func (d *SSLDeployerProvider) SetLogger(logger *slog.Logger) {
|
||||
func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privkeyPEM string) (*core.SSLDeployResult, error) {
|
||||
// 设置面板 SSL
|
||||
configSetCertReq := &btwafsdk.ConfigSetCertRequest{
|
||||
CertContent: xtypes.ToPtr(certPEM),
|
||||
KeyContent: xtypes.ToPtr(privkeyPEM),
|
||||
CertContent: lo.ToPtr(certPEM),
|
||||
KeyContent: lo.ToPtr(privkeyPEM),
|
||||
}
|
||||
configSetCertResp, err := d.sdkClient.ConfigSetCert(configSetCertReq)
|
||||
d.logger.Debug("sdk request 'bt.ConfigSetCert'", slog.Any("request", configSetCertReq), slog.Any("response", configSetCertResp))
|
||||
|
||||
@@ -7,9 +7,10 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
btwafsdk "github.com/certimate-go/certimate/pkg/sdk3rd/btwaf"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -80,9 +81,9 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
}
|
||||
|
||||
getSiteListReq := &btwafsdk.GetSiteListRequest{
|
||||
SiteName: xtypes.ToPtr(d.config.SiteName),
|
||||
Page: xtypes.ToPtr(getSitListPage),
|
||||
PageSize: xtypes.ToPtr(getSitListPageSize),
|
||||
SiteName: lo.ToPtr(d.config.SiteName),
|
||||
Page: lo.ToPtr(getSitListPage),
|
||||
PageSize: lo.ToPtr(getSitListPageSize),
|
||||
}
|
||||
getSiteListResp, err := d.sdkClient.GetSiteList(getSiteListReq)
|
||||
d.logger.Debug("sdk request 'bt.GetSiteList'", slog.Any("request", getSiteListReq), slog.Any("response", getSiteListResp))
|
||||
@@ -111,14 +112,14 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
|
||||
// 修改站点配置
|
||||
modifySiteReq := &btwafsdk.ModifySiteRequest{
|
||||
SiteId: xtypes.ToPtr(siteId),
|
||||
Type: xtypes.ToPtr("openCert"),
|
||||
SiteId: lo.ToPtr(siteId),
|
||||
Type: lo.ToPtr("openCert"),
|
||||
Server: &btwafsdk.SiteServerInfo{
|
||||
ListenSSLPorts: xtypes.ToPtr([]int32{d.config.SitePort}),
|
||||
ListenSSLPorts: lo.ToPtr([]int32{d.config.SitePort}),
|
||||
SSL: &btwafsdk.SiteServerSSLInfo{
|
||||
IsSSL: xtypes.ToPtr(int32(1)),
|
||||
FullChain: xtypes.ToPtr(certPEM),
|
||||
PrivateKey: xtypes.ToPtr(privkeyPEM),
|
||||
IsSSL: lo.ToPtr(int32(1)),
|
||||
FullChain: lo.ToPtr(certPEM),
|
||||
PrivateKey: lo.ToPtr(privkeyPEM),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -6,9 +6,10 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
cacheflysdk "github.com/certimate-go/certimate/pkg/sdk3rd/cachefly"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -53,8 +54,8 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
// 上传证书
|
||||
// REF: https://api.cachefly.com/api/2.5/docs#tag/Certificates/paths/~1certificates/post
|
||||
createCertificateReq := &cacheflysdk.CreateCertificateRequest{
|
||||
Certificate: xtypes.ToPtr(certPEM),
|
||||
CertificateKey: xtypes.ToPtr(privkeyPEM),
|
||||
Certificate: lo.ToPtr(certPEM),
|
||||
CertificateKey: lo.ToPtr(privkeyPEM),
|
||||
}
|
||||
createCertificateResp, err := d.sdkClient.CreateCertificate(createCertificateReq)
|
||||
d.logger.Debug("sdk request 'cachefly.CreateCertificate'", slog.Any("request", createCertificateReq), slog.Any("response", createCertificateResp))
|
||||
|
||||
@@ -9,9 +9,10 @@ import (
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
cdnflysdk "github.com/certimate-go/certimate/pkg/sdk3rd/cdnfly"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -102,10 +103,10 @@ func (d *SSLDeployerProvider) deployToSite(ctx context.Context, certPEM string,
|
||||
// 添加单个证书
|
||||
// REF: https://doc.cdnfly.cn/wangzhanzhengshu-v1-certs.html#%E6%B7%BB%E5%8A%A0%E5%8D%95%E4%B8%AA%E6%88%96%E5%A4%9A%E4%B8%AA%E8%AF%81%E4%B9%A6-%E5%A4%9A%E4%B8%AA%E8%AF%81%E4%B9%A6%E6%97%B6%E6%95%B0%E6%8D%AE%E6%A0%BC%E5%BC%8F%E4%B8%BA%E6%95%B0%E7%BB%84
|
||||
createCertificateReq := &cdnflysdk.CreateCertRequest{
|
||||
Name: xtypes.ToPtr(fmt.Sprintf("certimate-%d", time.Now().UnixMilli())),
|
||||
Type: xtypes.ToPtr("custom"),
|
||||
Cert: xtypes.ToPtr(certPEM),
|
||||
Key: xtypes.ToPtr(privkeyPEM),
|
||||
Name: lo.ToPtr(fmt.Sprintf("certimate-%d", time.Now().UnixMilli())),
|
||||
Type: lo.ToPtr("custom"),
|
||||
Cert: lo.ToPtr(certPEM),
|
||||
Key: lo.ToPtr(privkeyPEM),
|
||||
}
|
||||
createCertificateResp, err := d.sdkClient.CreateCert(createCertificateReq)
|
||||
d.logger.Debug("sdk request 'cdnfly.CreateCert'", slog.Any("request", createCertificateReq), slog.Any("response", createCertificateResp))
|
||||
@@ -120,7 +121,7 @@ func (d *SSLDeployerProvider) deployToSite(ctx context.Context, certPEM string,
|
||||
updateSiteHttpsListenMap["cert"] = createCertificateResp.Data
|
||||
updateSiteHttpsListenData, _ := json.Marshal(updateSiteHttpsListenMap)
|
||||
updateSiteReq := &cdnflysdk.UpdateSiteRequest{
|
||||
HttpsListen: xtypes.ToPtr(string(updateSiteHttpsListenData)),
|
||||
HttpsListen: lo.ToPtr(string(updateSiteHttpsListenData)),
|
||||
}
|
||||
updateSiteResp, err := d.sdkClient.UpdateSite(d.config.SiteId, updateSiteReq)
|
||||
d.logger.Debug("sdk request 'cdnfly.UpdateSite'", slog.String("siteId", d.config.SiteId), slog.Any("request", updateSiteReq), slog.Any("response", updateSiteResp))
|
||||
@@ -139,9 +140,9 @@ func (d *SSLDeployerProvider) deployToCertificate(ctx context.Context, certPEM s
|
||||
// 修改单个证书
|
||||
// REF: https://doc.cdnfly.cn/wangzhanzhengshu-v1-certs.html#%E4%BF%AE%E6%94%B9%E5%8D%95%E4%B8%AA%E8%AF%81%E4%B9%A6
|
||||
updateCertReq := &cdnflysdk.UpdateCertRequest{
|
||||
Type: xtypes.ToPtr("custom"),
|
||||
Cert: xtypes.ToPtr(certPEM),
|
||||
Key: xtypes.ToPtr(privkeyPEM),
|
||||
Type: lo.ToPtr("custom"),
|
||||
Cert: lo.ToPtr(certPEM),
|
||||
Key: lo.ToPtr(privkeyPEM),
|
||||
}
|
||||
updateCertResp, err := d.sdkClient.UpdateCert(d.config.CertificateId, updateCertReq)
|
||||
d.logger.Debug("sdk request 'cdnfly.UpdateCert'", slog.String("certId", d.config.CertificateId), slog.Any("request", updateCertReq), slog.Any("response", updateCertResp))
|
||||
|
||||
@@ -7,11 +7,11 @@ import (
|
||||
"log/slog"
|
||||
"strconv"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/ctcccloud-ao"
|
||||
ctyunao "github.com/certimate-go/certimate/pkg/sdk3rd/ctyun/ao"
|
||||
xslices "github.com/certimate-go/certimate/pkg/utils/slices"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -82,8 +82,8 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
// 域名基础及加速配置查询
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=113&api=13412&data=174&isNormal=1&vid=167
|
||||
getDomainConfigReq := &ctyunao.GetDomainConfigRequest{
|
||||
Domain: xtypes.ToPtr(d.config.Domain),
|
||||
ProductCode: xtypes.ToPtr("020"),
|
||||
Domain: lo.ToPtr(d.config.Domain),
|
||||
ProductCode: lo.ToPtr("020"),
|
||||
}
|
||||
getDomainConfigResp, err := d.sdkClient.GetDomainConfig(getDomainConfigReq)
|
||||
d.logger.Debug("sdk request 'cdn.GetDomainConfig'", slog.Any("request", getDomainConfigReq), slog.Any("response", getDomainConfigResp))
|
||||
@@ -94,9 +94,9 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
// 域名基础及加速配置修改
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=113&api=13413&data=174&isNormal=1&vid=167
|
||||
modifyDomainConfigReq := &ctyunao.ModifyDomainConfigRequest{
|
||||
Domain: xtypes.ToPtr(d.config.Domain),
|
||||
ProductCode: xtypes.ToPtr(getDomainConfigResp.ReturnObj.ProductCode),
|
||||
Origin: xslices.Map(getDomainConfigResp.ReturnObj.Origin, func(item *ctyunao.DomainOriginConfigWithWeight) *ctyunao.DomainOriginConfig {
|
||||
Domain: lo.ToPtr(d.config.Domain),
|
||||
ProductCode: lo.ToPtr(getDomainConfigResp.ReturnObj.ProductCode),
|
||||
Origin: lo.Map(getDomainConfigResp.ReturnObj.Origin, func(item *ctyunao.DomainOriginConfigWithWeight, _ int) *ctyunao.DomainOriginConfig {
|
||||
weight := item.Weight
|
||||
if weight == 0 {
|
||||
weight = 1
|
||||
@@ -107,8 +107,8 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
Weight: strconv.Itoa(int(weight)),
|
||||
}
|
||||
}),
|
||||
HttpsStatus: xtypes.ToPtr("on"),
|
||||
CertName: xtypes.ToPtr(upres.CertName),
|
||||
HttpsStatus: lo.ToPtr("on"),
|
||||
CertName: lo.ToPtr(upres.CertName),
|
||||
}
|
||||
modifyDomainConfigResp, err := d.sdkClient.ModifyDomainConfig(modifyDomainConfigReq)
|
||||
d.logger.Debug("sdk request 'cdn.ModifyDomainConfig'", slog.Any("request", modifyDomainConfigReq), slog.Any("response", modifyDomainConfigResp))
|
||||
|
||||
@@ -6,10 +6,11 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/ctcccloud-cdn"
|
||||
ctyuncdn "github.com/certimate-go/certimate/pkg/sdk3rd/ctyun/cdn"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -80,7 +81,7 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
// 查询域名配置信息
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=108&api=11304&data=161&isNormal=1&vid=154
|
||||
queryDomainDetailReq := &ctyuncdn.QueryDomainDetailRequest{
|
||||
Domain: xtypes.ToPtr(d.config.Domain),
|
||||
Domain: lo.ToPtr(d.config.Domain),
|
||||
}
|
||||
queryDomainDetailResp, err := d.sdkClient.QueryDomainDetail(queryDomainDetailReq)
|
||||
d.logger.Debug("sdk request 'cdn.QueryDomainDetail'", slog.Any("request", queryDomainDetailReq), slog.Any("response", queryDomainDetailResp))
|
||||
@@ -91,9 +92,9 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
// 修改域名配置
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=108&api=11308&data=161&isNormal=1&vid=154
|
||||
updateDomainReq := &ctyuncdn.UpdateDomainRequest{
|
||||
Domain: xtypes.ToPtr(d.config.Domain),
|
||||
HttpsStatus: xtypes.ToPtr("on"),
|
||||
CertName: xtypes.ToPtr(upres.CertName),
|
||||
Domain: lo.ToPtr(d.config.Domain),
|
||||
HttpsStatus: lo.ToPtr("on"),
|
||||
CertName: lo.ToPtr(upres.CertName),
|
||||
}
|
||||
updateDomainResp, err := d.sdkClient.UpdateDomain(updateDomainReq)
|
||||
d.logger.Debug("sdk request 'cdn.UpdateDomain'", slog.Any("request", updateDomainReq), slog.Any("response", updateDomainResp))
|
||||
|
||||
@@ -7,10 +7,11 @@ import (
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/ctcccloud-elb"
|
||||
ctyunelb "github.com/certimate-go/certimate/pkg/sdk3rd/ctyun/elb"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -118,8 +119,8 @@ func (d *SSLDeployerProvider) deployToLoadbalancer(ctx context.Context, cloudCer
|
||||
}
|
||||
|
||||
listListenersReq := &ctyunelb.ListListenersRequest{
|
||||
RegionID: xtypes.ToPtr(d.config.RegionId),
|
||||
LoadBalancerID: xtypes.ToPtr(d.config.LoadbalancerId),
|
||||
RegionID: lo.ToPtr(d.config.RegionId),
|
||||
LoadBalancerID: lo.ToPtr(d.config.LoadbalancerId),
|
||||
}
|
||||
listListenersResp, err := d.sdkClient.ListListeners(listListenersReq)
|
||||
d.logger.Debug("sdk request 'elb.ListListeners'", slog.Any("request", listListenersReq), slog.Any("response", listListenersResp))
|
||||
@@ -179,9 +180,9 @@ func (d *SSLDeployerProvider) updateListenerCertificate(ctx context.Context, clo
|
||||
// 更新监听器
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=24&api=5652&data=88&isNormal=1&vid=82
|
||||
setLoadBalancerHTTPSListenerAttributeReq := &ctyunelb.UpdateListenerRequest{
|
||||
RegionID: xtypes.ToPtr(d.config.RegionId),
|
||||
ListenerID: xtypes.ToPtr(cloudListenerId),
|
||||
CertificateID: xtypes.ToPtr(cloudCertId),
|
||||
RegionID: lo.ToPtr(d.config.RegionId),
|
||||
ListenerID: lo.ToPtr(cloudListenerId),
|
||||
CertificateID: lo.ToPtr(cloudCertId),
|
||||
}
|
||||
setLoadBalancerHTTPSListenerAttributeResp, err := d.sdkClient.UpdateListener(setLoadBalancerHTTPSListenerAttributeReq)
|
||||
d.logger.Debug("sdk request 'elb.UpdateListener'", slog.Any("request", setLoadBalancerHTTPSListenerAttributeReq), slog.Any("response", setLoadBalancerHTTPSListenerAttributeResp))
|
||||
|
||||
@@ -6,10 +6,11 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/ctcccloud-icdn"
|
||||
ctyunicdn "github.com/certimate-go/certimate/pkg/sdk3rd/ctyun/icdn"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -80,7 +81,7 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
// 查询域名配置信息
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=112&api=10849&data=173&isNormal=1&vid=166
|
||||
queryDomainDetailReq := &ctyunicdn.QueryDomainDetailRequest{
|
||||
Domain: xtypes.ToPtr(d.config.Domain),
|
||||
Domain: lo.ToPtr(d.config.Domain),
|
||||
}
|
||||
queryDomainDetailResp, err := d.sdkClient.QueryDomainDetail(queryDomainDetailReq)
|
||||
d.logger.Debug("sdk request 'icdn.QueryDomainDetail'", slog.Any("request", queryDomainDetailReq), slog.Any("response", queryDomainDetailResp))
|
||||
@@ -91,9 +92,9 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
// 修改域名配置
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=112&api=10853&data=173&isNormal=1&vid=166
|
||||
updateDomainReq := &ctyunicdn.UpdateDomainRequest{
|
||||
Domain: xtypes.ToPtr(d.config.Domain),
|
||||
HttpsStatus: xtypes.ToPtr("on"),
|
||||
CertName: xtypes.ToPtr(upres.CertName),
|
||||
Domain: lo.ToPtr(d.config.Domain),
|
||||
HttpsStatus: lo.ToPtr("on"),
|
||||
CertName: lo.ToPtr(upres.CertName),
|
||||
}
|
||||
updateDomainResp, err := d.sdkClient.UpdateDomain(updateDomainReq)
|
||||
d.logger.Debug("sdk request 'icdn.UpdateDomain'", slog.Any("request", updateDomainReq), slog.Any("response", updateDomainResp))
|
||||
|
||||
@@ -6,10 +6,11 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/ctcccloud-lvdn"
|
||||
ctyunlvdn "github.com/certimate-go/certimate/pkg/sdk3rd/ctyun/lvdn"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -80,8 +81,8 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
// 查询域名配置信息
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=125&api=11473&data=183&isNormal=1&vid=261
|
||||
queryDomainDetailReq := &ctyunlvdn.QueryDomainDetailRequest{
|
||||
Domain: xtypes.ToPtr(d.config.Domain),
|
||||
ProductCode: xtypes.ToPtr("005"),
|
||||
Domain: lo.ToPtr(d.config.Domain),
|
||||
ProductCode: lo.ToPtr("005"),
|
||||
}
|
||||
queryDomainDetailResp, err := d.sdkClient.QueryDomainDetail(queryDomainDetailReq)
|
||||
d.logger.Debug("sdk request 'lvdn.QueryDomainDetail'", slog.Any("request", queryDomainDetailReq), slog.Any("response", queryDomainDetailResp))
|
||||
@@ -92,10 +93,10 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
// 修改域名配置
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=108&api=11308&data=161&isNormal=1&vid=154
|
||||
updateDomainReq := &ctyunlvdn.UpdateDomainRequest{
|
||||
Domain: xtypes.ToPtr(d.config.Domain),
|
||||
ProductCode: xtypes.ToPtr("005"),
|
||||
HttpsSwitch: xtypes.ToPtr(int32(1)),
|
||||
CertName: xtypes.ToPtr(upres.CertName),
|
||||
Domain: lo.ToPtr(d.config.Domain),
|
||||
ProductCode: lo.ToPtr("005"),
|
||||
HttpsSwitch: lo.ToPtr(int32(1)),
|
||||
CertName: lo.ToPtr(upres.CertName),
|
||||
}
|
||||
updateDomainResp, err := d.sdkClient.UpdateDomain(updateDomainReq)
|
||||
d.logger.Debug("sdk request 'lvdn.UpdateDomain'", slog.Any("request", updateDomainReq), slog.Any("response", updateDomainResp))
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
hccdn "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2"
|
||||
hccdnmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/model"
|
||||
hccdnregion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cdn/v2/region"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/huaweicloud-scm"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -95,7 +95,7 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
// 查询加速域名配置
|
||||
// REF: https://support.huaweicloud.com/api-cdn/ShowDomainFullConfig.html
|
||||
showDomainFullConfigReq := &hccdnmodel.ShowDomainFullConfigRequest{
|
||||
EnterpriseProjectId: xtypes.ToPtrOrZeroNil(d.config.EnterpriseProjectId),
|
||||
EnterpriseProjectId: lo.EmptyableToPtr(d.config.EnterpriseProjectId),
|
||||
DomainName: d.config.Domain,
|
||||
}
|
||||
showDomainFullConfigResp, err := d.sdkClient.ShowDomainFullConfig(showDomainFullConfigReq)
|
||||
@@ -110,12 +110,12 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
updateDomainMultiCertificatesReqBodyContent := &hccdnmodel.UpdateDomainMultiCertificatesRequestBodyContent{}
|
||||
updateDomainMultiCertificatesReqBodyContent.DomainName = d.config.Domain
|
||||
updateDomainMultiCertificatesReqBodyContent.HttpsSwitch = 1
|
||||
updateDomainMultiCertificatesReqBodyContent.CertificateType = xtypes.ToPtr(int32(2))
|
||||
updateDomainMultiCertificatesReqBodyContent.ScmCertificateId = xtypes.ToPtr(upres.CertId)
|
||||
updateDomainMultiCertificatesReqBodyContent.CertName = xtypes.ToPtr(upres.CertName)
|
||||
updateDomainMultiCertificatesReqBodyContent.CertificateType = lo.ToPtr(int32(2))
|
||||
updateDomainMultiCertificatesReqBodyContent.ScmCertificateId = lo.ToPtr(upres.CertId)
|
||||
updateDomainMultiCertificatesReqBodyContent.CertName = lo.ToPtr(upres.CertName)
|
||||
updateDomainMultiCertificatesReqBodyContent = assign(updateDomainMultiCertificatesReqBodyContent, showDomainFullConfigResp.Configs)
|
||||
updateDomainMultiCertificatesReq := &hccdnmodel.UpdateDomainMultiCertificatesRequest{
|
||||
EnterpriseProjectId: xtypes.ToPtrOrZeroNil(d.config.EnterpriseProjectId),
|
||||
EnterpriseProjectId: lo.EmptyableToPtr(d.config.EnterpriseProjectId),
|
||||
Body: &hccdnmodel.UpdateDomainMultiCertificatesRequestBody{
|
||||
Https: updateDomainMultiCertificatesReqBodyContent,
|
||||
},
|
||||
@@ -168,11 +168,11 @@ func assign(source *hccdnmodel.UpdateDomainMultiCertificatesRequestBodyContent,
|
||||
}
|
||||
|
||||
if *target.OriginProtocol == "follow" {
|
||||
source.AccessOriginWay = xtypes.ToPtr(int32(1))
|
||||
source.AccessOriginWay = lo.ToPtr(int32(1))
|
||||
} else if *target.OriginProtocol == "http" {
|
||||
source.AccessOriginWay = xtypes.ToPtr(int32(2))
|
||||
source.AccessOriginWay = lo.ToPtr(int32(2))
|
||||
} else if *target.OriginProtocol == "https" {
|
||||
source.AccessOriginWay = xtypes.ToPtr(int32(3))
|
||||
source.AccessOriginWay = lo.ToPtr(int32(3))
|
||||
}
|
||||
|
||||
if target.ForceRedirect != nil {
|
||||
@@ -190,7 +190,7 @@ func assign(source *hccdnmodel.UpdateDomainMultiCertificatesRequestBodyContent,
|
||||
|
||||
if target.Https != nil {
|
||||
if *target.Https.Http2Status == "on" {
|
||||
source.Http2 = xtypes.ToPtr(int32(1))
|
||||
source.Http2 = lo.ToPtr(int32(1))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,11 @@ import (
|
||||
hciam "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3"
|
||||
hciammodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3/model"
|
||||
hciamregion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3/region"
|
||||
"github.com/samber/lo"
|
||||
"golang.org/x/exp/slices"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/huaweicloud-elb"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -126,8 +126,8 @@ func (d *SSLDeployerProvider) deployToCertificate(ctx context.Context, certPEM s
|
||||
CertificateId: d.config.CertificateId,
|
||||
Body: &hcelbmodel.UpdateCertificateRequestBody{
|
||||
Certificate: &hcelbmodel.UpdateCertificateOption{
|
||||
Certificate: xtypes.ToPtr(certPEM),
|
||||
PrivateKey: xtypes.ToPtr(privkeyPEM),
|
||||
Certificate: lo.ToPtr(certPEM),
|
||||
PrivateKey: lo.ToPtr(privkeyPEM),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -169,13 +169,13 @@ func (d *SSLDeployerProvider) deployToLoadbalancer(ctx context.Context, certPEM
|
||||
}
|
||||
|
||||
listListenersReq := &hcelbmodel.ListListenersRequest{
|
||||
Limit: xtypes.ToPtr(listListenersLimit),
|
||||
Limit: lo.ToPtr(listListenersLimit),
|
||||
Marker: listListenersMarker,
|
||||
Protocol: &[]string{"HTTPS", "TERMINATED_HTTPS"},
|
||||
LoadbalancerId: &[]string{showLoadBalancerResp.Loadbalancer.Id},
|
||||
}
|
||||
if d.config.EnterpriseProjectId != "" {
|
||||
listListenersReq.EnterpriseProjectId = xtypes.ToPtr([]string{d.config.EnterpriseProjectId})
|
||||
listListenersReq.EnterpriseProjectId = lo.ToPtr([]string{d.config.EnterpriseProjectId})
|
||||
}
|
||||
listListenersResp, err := d.sdkClient.ListListeners(listListenersReq)
|
||||
d.logger.Debug("sdk request 'elb.ListListeners'", slog.Any("request", listListenersReq), slog.Any("response", listListenersResp))
|
||||
@@ -269,7 +269,7 @@ func (d *SSLDeployerProvider) modifyListenerCertificate(ctx context.Context, clo
|
||||
ListenerId: cloudListenerId,
|
||||
Body: &hcelbmodel.UpdateListenerRequestBody{
|
||||
Listener: &hcelbmodel.UpdateListenerOption{
|
||||
DefaultTlsContainerRef: xtypes.ToPtr(cloudCertId),
|
||||
DefaultTlsContainerRef: lo.ToPtr(cloudCertId),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -317,7 +317,7 @@ func (d *SSLDeployerProvider) modifyListenerCertificate(ctx context.Context, clo
|
||||
}
|
||||
|
||||
if showListenerResp.Listener.SniMatchAlgo != "" {
|
||||
updateListenerReq.Body.Listener.SniMatchAlgo = xtypes.ToPtr(showListenerResp.Listener.SniMatchAlgo)
|
||||
updateListenerReq.Body.Listener.SniMatchAlgo = lo.ToPtr(showListenerResp.Listener.SniMatchAlgo)
|
||||
}
|
||||
}
|
||||
updateListenerResp, err := d.sdkClient.UpdateListener(updateListenerReq)
|
||||
|
||||
@@ -15,10 +15,10 @@ import (
|
||||
hcwaf "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/waf/v1"
|
||||
hcwafmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/waf/v1/model"
|
||||
hcwafregion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/waf/v1/region"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/huaweicloud-waf"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -128,7 +128,7 @@ func (d *SSLDeployerProvider) deployToCertificate(ctx context.Context, certPEM s
|
||||
// 查询证书
|
||||
// REF: https://support.huaweicloud.com/api-waf/ShowCertificate.html
|
||||
showCertificateReq := &hcwafmodel.ShowCertificateRequest{
|
||||
EnterpriseProjectId: xtypes.ToPtrOrZeroNil(d.config.EnterpriseProjectId),
|
||||
EnterpriseProjectId: lo.EmptyableToPtr(d.config.EnterpriseProjectId),
|
||||
CertificateId: d.config.CertificateId,
|
||||
}
|
||||
showCertificateResp, err := d.sdkClient.ShowCertificate(showCertificateReq)
|
||||
@@ -140,12 +140,12 @@ func (d *SSLDeployerProvider) deployToCertificate(ctx context.Context, certPEM s
|
||||
// 更新证书
|
||||
// REF: https://support.huaweicloud.com/api-waf/UpdateCertificate.html
|
||||
updateCertificateReq := &hcwafmodel.UpdateCertificateRequest{
|
||||
EnterpriseProjectId: xtypes.ToPtrOrZeroNil(d.config.EnterpriseProjectId),
|
||||
EnterpriseProjectId: lo.EmptyableToPtr(d.config.EnterpriseProjectId),
|
||||
CertificateId: d.config.CertificateId,
|
||||
Body: &hcwafmodel.UpdateCertificateRequestBody{
|
||||
Name: *showCertificateResp.Name,
|
||||
Content: xtypes.ToPtr(certPEM),
|
||||
Key: xtypes.ToPtr(privkeyPEM),
|
||||
Content: lo.ToPtr(certPEM),
|
||||
Key: lo.ToPtr(privkeyPEM),
|
||||
},
|
||||
}
|
||||
updateCertificateResp, err := d.sdkClient.UpdateCertificate(updateCertificateReq)
|
||||
@@ -183,10 +183,10 @@ func (d *SSLDeployerProvider) deployToCloudServer(ctx context.Context, certPEM s
|
||||
}
|
||||
|
||||
listHostReq := &hcwafmodel.ListHostRequest{
|
||||
EnterpriseProjectId: xtypes.ToPtrOrZeroNil(d.config.EnterpriseProjectId),
|
||||
Hostname: xtypes.ToPtr(strings.TrimPrefix(d.config.Domain, "*")),
|
||||
Page: xtypes.ToPtr(listHostPage),
|
||||
Pagesize: xtypes.ToPtr(listHostPageSize),
|
||||
EnterpriseProjectId: lo.EmptyableToPtr(d.config.EnterpriseProjectId),
|
||||
Hostname: lo.ToPtr(strings.TrimPrefix(d.config.Domain, "*")),
|
||||
Page: lo.ToPtr(listHostPage),
|
||||
Pagesize: lo.ToPtr(listHostPageSize),
|
||||
}
|
||||
listHostResp, err := d.sdkClient.ListHost(listHostReq)
|
||||
d.logger.Debug("sdk request 'waf.ListHost'", slog.Any("request", listHostReq), slog.Any("response", listHostResp))
|
||||
@@ -216,11 +216,11 @@ func (d *SSLDeployerProvider) deployToCloudServer(ctx context.Context, certPEM s
|
||||
// 更新云模式防护域名的配置
|
||||
// REF: https://support.huaweicloud.com/api-waf/UpdateHost.html
|
||||
updateHostReq := &hcwafmodel.UpdateHostRequest{
|
||||
EnterpriseProjectId: xtypes.ToPtrOrZeroNil(d.config.EnterpriseProjectId),
|
||||
EnterpriseProjectId: lo.EmptyableToPtr(d.config.EnterpriseProjectId),
|
||||
InstanceId: hostId,
|
||||
Body: &hcwafmodel.UpdateHostRequestBody{
|
||||
Certificateid: xtypes.ToPtr(upres.CertId),
|
||||
Certificatename: xtypes.ToPtr(upres.CertName),
|
||||
Certificateid: lo.ToPtr(upres.CertId),
|
||||
Certificatename: lo.ToPtr(upres.CertName),
|
||||
},
|
||||
}
|
||||
updateHostResp, err := d.sdkClient.UpdateHost(updateHostReq)
|
||||
@@ -258,10 +258,10 @@ func (d *SSLDeployerProvider) deployToPremiumHost(ctx context.Context, certPEM s
|
||||
}
|
||||
|
||||
listPremiumHostReq := &hcwafmodel.ListPremiumHostRequest{
|
||||
EnterpriseProjectId: xtypes.ToPtrOrZeroNil(d.config.EnterpriseProjectId),
|
||||
Hostname: xtypes.ToPtr(strings.TrimPrefix(d.config.Domain, "*")),
|
||||
Page: xtypes.ToPtr(fmt.Sprintf("%d", listPremiumHostPage)),
|
||||
Pagesize: xtypes.ToPtr(fmt.Sprintf("%d", listPremiumHostPageSize)),
|
||||
EnterpriseProjectId: lo.EmptyableToPtr(d.config.EnterpriseProjectId),
|
||||
Hostname: lo.ToPtr(strings.TrimPrefix(d.config.Domain, "*")),
|
||||
Page: lo.ToPtr(fmt.Sprintf("%d", listPremiumHostPage)),
|
||||
Pagesize: lo.ToPtr(fmt.Sprintf("%d", listPremiumHostPageSize)),
|
||||
}
|
||||
listPremiumHostResp, err := d.sdkClient.ListPremiumHost(listPremiumHostReq)
|
||||
d.logger.Debug("sdk request 'waf.ListPremiumHost'", slog.Any("request", listPremiumHostReq), slog.Any("response", listPremiumHostResp))
|
||||
@@ -291,11 +291,11 @@ func (d *SSLDeployerProvider) deployToPremiumHost(ctx context.Context, certPEM s
|
||||
// 修改独享模式域名配置
|
||||
// REF: https://support.huaweicloud.com/api-waf/UpdatePremiumHost.html
|
||||
updatePremiumHostReq := &hcwafmodel.UpdatePremiumHostRequest{
|
||||
EnterpriseProjectId: xtypes.ToPtrOrZeroNil(d.config.EnterpriseProjectId),
|
||||
EnterpriseProjectId: lo.EmptyableToPtr(d.config.EnterpriseProjectId),
|
||||
HostId: hostId,
|
||||
Body: &hcwafmodel.UpdatePremiumHostRequestBody{
|
||||
Certificateid: xtypes.ToPtr(upres.CertId),
|
||||
Certificatename: xtypes.ToPtr(upres.CertName),
|
||||
Certificateid: lo.ToPtr(upres.CertId),
|
||||
Certificatename: lo.ToPtr(upres.CertName),
|
||||
},
|
||||
}
|
||||
updatePremiumHostResp, err := d.sdkClient.UpdatePremiumHost(updatePremiumHostReq)
|
||||
|
||||
@@ -12,10 +12,10 @@ import (
|
||||
jdlbapi "github.com/jdcloud-api/jdcloud-sdk-go/services/lb/apis"
|
||||
jdlbclient "github.com/jdcloud-api/jdcloud-sdk-go/services/lb/client"
|
||||
jdlbmodel "github.com/jdcloud-api/jdcloud-sdk-go/services/lb/models"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/jdcloud-ssl"
|
||||
xslices "github.com/certimate-go/certimate/pkg/utils/slices"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -225,7 +225,7 @@ func (d *SSLDeployerProvider) updateListenerCertificate(ctx context.Context, clo
|
||||
} else {
|
||||
// 指定 SNI,需部署到扩展证书
|
||||
|
||||
extCertSpecs := xslices.Filter(describeListenerResp.Result.Listener.ExtensionCertificateSpecs, func(extCertSpec jdlbmodel.ExtensionCertificateSpec) bool {
|
||||
extCertSpecs := lo.Filter(describeListenerResp.Result.Listener.ExtensionCertificateSpecs, func(extCertSpec jdlbmodel.ExtensionCertificateSpec, _ int) bool {
|
||||
return extCertSpec.Domain == d.config.Domain
|
||||
})
|
||||
if len(extCertSpecs) == 0 {
|
||||
@@ -237,7 +237,7 @@ func (d *SSLDeployerProvider) updateListenerCertificate(ctx context.Context, clo
|
||||
updateListenerCertificatesReq := jdlbapi.NewUpdateListenerCertificatesRequest(
|
||||
d.config.RegionId,
|
||||
cloudListenerId,
|
||||
xslices.Map(extCertSpecs, func(extCertSpec jdlbmodel.ExtensionCertificateSpec) jdlbmodel.ExtCertificateUpdateSpec {
|
||||
lo.Map(extCertSpecs, func(extCertSpec jdlbmodel.ExtensionCertificateSpec, _ int) jdlbmodel.ExtCertificateUpdateSpec {
|
||||
return jdlbmodel.ExtCertificateUpdateSpec{
|
||||
CertificateBindId: extCertSpec.CertificateBindId,
|
||||
CertificateId: &cloudCertId,
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/samber/lo"
|
||||
tccdn "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn/v20180606"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||
@@ -14,7 +15,6 @@ import (
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/tencentcloud-ssl"
|
||||
"github.com/certimate-go/certimate/pkg/utils/ifelse"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -55,9 +55,8 @@ func NewSSLDeployerProvider(config *SSLDeployerProviderConfig) (*SSLDeployerProv
|
||||
sslmgr, err := sslmgrsp.NewSSLManagerProvider(&sslmgrsp.SSLManagerProviderConfig{
|
||||
SecretId: config.SecretId,
|
||||
SecretKey: config.SecretKey,
|
||||
Endpoint: ifelse.
|
||||
If[string](strings.HasSuffix(strings.TrimSpace(config.Endpoint), "intl.tencentcloudapi.com")).
|
||||
Then("ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
|
||||
Endpoint: lo.
|
||||
If(strings.HasSuffix(config.Endpoint, "intl.tencentcloudapi.com"), "ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
|
||||
Else(""),
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/samber/lo"
|
||||
tcclb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||
@@ -15,7 +16,6 @@ import (
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/tencentcloud-ssl"
|
||||
"github.com/certimate-go/certimate/pkg/utils/ifelse"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -67,9 +67,8 @@ func NewSSLDeployerProvider(config *SSLDeployerProviderConfig) (*SSLDeployerProv
|
||||
sslmgr, err := sslmgrsp.NewSSLManagerProvider(&sslmgrsp.SSLManagerProviderConfig{
|
||||
SecretId: config.SecretId,
|
||||
SecretKey: config.SecretKey,
|
||||
Endpoint: ifelse.
|
||||
If[string](strings.HasSuffix(strings.TrimSpace(config.Endpoint), "intl.tencentcloudapi.com")).
|
||||
Then("ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
|
||||
Endpoint: lo.
|
||||
If(strings.HasSuffix(config.Endpoint, "intl.tencentcloudapi.com"), "ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
|
||||
Else(""),
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -7,13 +7,13 @@ import (
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/samber/lo"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||
tclive "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/live/v20180801"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/tencentcloud-ssl"
|
||||
"github.com/certimate-go/certimate/pkg/utils/ifelse"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -49,9 +49,8 @@ func NewSSLDeployerProvider(config *SSLDeployerProviderConfig) (*SSLDeployerProv
|
||||
sslmgr, err := sslmgrsp.NewSSLManagerProvider(&sslmgrsp.SSLManagerProviderConfig{
|
||||
SecretId: config.SecretId,
|
||||
SecretKey: config.SecretKey,
|
||||
Endpoint: ifelse.
|
||||
If[string](strings.HasSuffix(strings.TrimSpace(config.Endpoint), "intl.tencentcloudapi.com")).
|
||||
Then("ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
|
||||
Endpoint: lo.
|
||||
If(strings.HasSuffix(config.Endpoint, "intl.tencentcloudapi.com"), "ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
|
||||
Else(""),
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/samber/lo"
|
||||
tccdn "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn/v20180606"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||
@@ -14,7 +15,6 @@ import (
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/tencentcloud-ssl"
|
||||
"github.com/certimate-go/certimate/pkg/utils/ifelse"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -55,9 +55,8 @@ func NewSSLDeployerProvider(config *SSLDeployerProviderConfig) (*SSLDeployerProv
|
||||
sslmgr, err := sslmgrsp.NewSSLManagerProvider(&sslmgrsp.SSLManagerProviderConfig{
|
||||
SecretId: config.SecretId,
|
||||
SecretKey: config.SecretKey,
|
||||
Endpoint: ifelse.
|
||||
If[string](strings.HasSuffix(strings.TrimSpace(config.Endpoint), "intl.tencentcloudapi.com")).
|
||||
Then("ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
|
||||
Endpoint: lo.
|
||||
If(strings.HasSuffix(config.Endpoint, "intl.tencentcloudapi.com"), "ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
|
||||
Else(""),
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -7,13 +7,13 @@ import (
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/samber/lo"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||
tcteo "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/teo/v20220901"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/tencentcloud-ssl"
|
||||
"github.com/certimate-go/certimate/pkg/utils/ifelse"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -51,9 +51,8 @@ func NewSSLDeployerProvider(config *SSLDeployerProviderConfig) (*SSLDeployerProv
|
||||
sslmgr, err := sslmgrsp.NewSSLManagerProvider(&sslmgrsp.SSLManagerProviderConfig{
|
||||
SecretId: config.SecretId,
|
||||
SecretKey: config.SecretKey,
|
||||
Endpoint: ifelse.
|
||||
If[string](strings.HasSuffix(strings.TrimSpace(config.Endpoint), "intl.tencentcloudapi.com")).
|
||||
Then("ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
|
||||
Endpoint: lo.
|
||||
If(strings.HasSuffix(config.Endpoint, "intl.tencentcloudapi.com"), "ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
|
||||
Else(""),
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -7,14 +7,13 @@ import (
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/samber/lo"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||
tcgaap "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/gaap/v20180529"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/tencentcloud-ssl"
|
||||
"github.com/certimate-go/certimate/pkg/utils/ifelse"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -56,9 +55,8 @@ func NewSSLDeployerProvider(config *SSLDeployerProviderConfig) (*SSLDeployerProv
|
||||
sslmgr, err := sslmgrsp.NewSSLManagerProvider(&sslmgrsp.SSLManagerProviderConfig{
|
||||
SecretId: config.SecretId,
|
||||
SecretKey: config.SecretKey,
|
||||
Endpoint: ifelse.
|
||||
If[string](strings.HasSuffix(strings.TrimSpace(config.Endpoint), "intl.tencentcloudapi.com")).
|
||||
Then("ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
|
||||
Endpoint: lo.
|
||||
If(strings.HasSuffix(config.Endpoint, "intl.tencentcloudapi.com"), "ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
|
||||
Else(""),
|
||||
})
|
||||
if err != nil {
|
||||
@@ -137,7 +135,7 @@ func (d *SSLDeployerProvider) modifyHttpsListenerCertificate(ctx context.Context
|
||||
// 修改 HTTPS 监听器配置
|
||||
// REF: https://cloud.tencent.com/document/api/608/36996
|
||||
modifyHTTPSListenerAttributeReq := tcgaap.NewModifyHTTPSListenerAttributeRequest()
|
||||
modifyHTTPSListenerAttributeReq.ProxyId = xtypes.ToPtrOrZeroNil(d.config.ProxyId)
|
||||
modifyHTTPSListenerAttributeReq.ProxyId = lo.EmptyableToPtr(d.config.ProxyId)
|
||||
modifyHTTPSListenerAttributeReq.ListenerId = common.StringPtr(cloudListenerId)
|
||||
modifyHTTPSListenerAttributeReq.CertificateId = common.StringPtr(cloudCertId)
|
||||
modifyHTTPSListenerAttributeResp, err := d.sdkClient.ModifyHTTPSListenerAttribute(modifyHTTPSListenerAttributeReq)
|
||||
|
||||
@@ -7,13 +7,13 @@ import (
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/samber/lo"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||
tcscf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/scf/v20180416"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/tencentcloud-ssl"
|
||||
"github.com/certimate-go/certimate/pkg/utils/ifelse"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -51,9 +51,8 @@ func NewSSLDeployerProvider(config *SSLDeployerProviderConfig) (*SSLDeployerProv
|
||||
sslmgr, err := sslmgrsp.NewSSLManagerProvider(&sslmgrsp.SSLManagerProviderConfig{
|
||||
SecretId: config.SecretId,
|
||||
SecretKey: config.SecretKey,
|
||||
Endpoint: ifelse.
|
||||
If[string](strings.HasSuffix(strings.TrimSpace(config.Endpoint), "intl.tencentcloudapi.com")).
|
||||
Then("ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
|
||||
Endpoint: lo.
|
||||
If(strings.HasSuffix(config.Endpoint, "intl.tencentcloudapi.com"), "ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
|
||||
Else(""),
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -7,13 +7,13 @@ import (
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/samber/lo"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||
tcvod "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vod/v20180717"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/tencentcloud-ssl"
|
||||
"github.com/certimate-go/certimate/pkg/utils/ifelse"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -51,9 +51,8 @@ func NewSSLDeployerProvider(config *SSLDeployerProviderConfig) (*SSLDeployerProv
|
||||
sslmgr, err := sslmgrsp.NewSSLManagerProvider(&sslmgrsp.SSLManagerProviderConfig{
|
||||
SecretId: config.SecretId,
|
||||
SecretKey: config.SecretKey,
|
||||
Endpoint: ifelse.
|
||||
If[string](strings.HasSuffix(strings.TrimSpace(config.Endpoint), "intl.tencentcloudapi.com")).
|
||||
Then("ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
|
||||
Endpoint: lo.
|
||||
If(strings.HasSuffix(config.Endpoint, "intl.tencentcloudapi.com"), "ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
|
||||
Else(""),
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -7,13 +7,13 @@ import (
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"github.com/samber/lo"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
|
||||
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
|
||||
tcwaf "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/waf/v20180125"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/tencentcloud-ssl"
|
||||
"github.com/certimate-go/certimate/pkg/utils/ifelse"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -55,9 +55,8 @@ func NewSSLDeployerProvider(config *SSLDeployerProviderConfig) (*SSLDeployerProv
|
||||
sslmgr, err := sslmgrsp.NewSSLManagerProvider(&sslmgrsp.SSLManagerProviderConfig{
|
||||
SecretId: config.SecretId,
|
||||
SecretKey: config.SecretKey,
|
||||
Endpoint: ifelse.
|
||||
If[string](strings.HasSuffix(strings.TrimSpace(config.Endpoint), "intl.tencentcloudapi.com")).
|
||||
Then("ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
|
||||
Endpoint: lo.
|
||||
If(strings.HasSuffix(config.Endpoint, "intl.tencentcloudapi.com"), "ssl.intl.tencentcloudapi.com"). // 国际站使用独立的接口端点
|
||||
Else(""),
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -6,13 +6,13 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
"github.com/samber/lo"
|
||||
vealb "github.com/volcengine/volcengine-go-sdk/service/alb"
|
||||
ve "github.com/volcengine/volcengine-go-sdk/volcengine"
|
||||
vesession "github.com/volcengine/volcengine-go-sdk/volcengine/session"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/volcengine-certcenter"
|
||||
xslices "github.com/certimate-go/certimate/pkg/utils/slices"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -232,14 +232,14 @@ func (d *SSLDeployerProvider) updateListenerCertificate(ctx context.Context, clo
|
||||
// REF: https://www.volcengine.com/docs/6767/113683
|
||||
modifyListenerAttributesReq := &vealb.ModifyListenerAttributesInput{
|
||||
ListenerId: ve.String(cloudListenerId),
|
||||
DomainExtensions: xslices.Map(
|
||||
xslices.Filter(
|
||||
DomainExtensions: lo.Map(
|
||||
lo.Filter(
|
||||
describeListenerAttributesResp.DomainExtensions,
|
||||
func(domain *vealb.DomainExtensionForDescribeListenerAttributesOutput) bool {
|
||||
func(domain *vealb.DomainExtensionForDescribeListenerAttributesOutput, _ int) bool {
|
||||
return *domain.Domain == d.config.Domain
|
||||
},
|
||||
),
|
||||
func(domain *vealb.DomainExtensionForDescribeListenerAttributesOutput) *vealb.DomainExtensionForModifyListenerAttributesInput {
|
||||
func(domain *vealb.DomainExtensionForDescribeListenerAttributesOutput, _ int) *vealb.DomainExtensionForModifyListenerAttributesInput {
|
||||
return &vealb.DomainExtensionForModifyListenerAttributesInput{
|
||||
DomainExtensionId: domain.DomainExtensionId,
|
||||
Domain: domain.Domain,
|
||||
|
||||
@@ -8,10 +8,11 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/wangsu-certificate"
|
||||
wangsusdk "github.com/certimate-go/certimate/pkg/sdk3rd/wangsu/cdn"
|
||||
xslices "github.com/certimate-go/certimate/pkg/utils/slices"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -84,7 +85,7 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
certId, _ := strconv.ParseInt(upres.CertId, 10, 64)
|
||||
batchUpdateCertificateConfigReq := &wangsusdk.BatchUpdateCertificateConfigRequest{
|
||||
CertificateId: certId,
|
||||
DomainNames: xslices.Map(d.config.Domains, func(domain string) string {
|
||||
DomainNames: lo.Map(d.config.Domains, func(domain string, _ int) string {
|
||||
// "*.example.com" → ".example.com",适配网宿云 CDN 要求的泛域名格式
|
||||
return strings.TrimPrefix(domain, "*")
|
||||
}),
|
||||
|
||||
@@ -16,10 +16,11 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
wangsucdn "github.com/certimate-go/certimate/pkg/sdk3rd/wangsu/cdnpro"
|
||||
xcert "github.com/certimate-go/certimate/pkg/utils/cert"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -98,10 +99,10 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
return nil, fmt.Errorf("failed to encrypt private key: %w", err)
|
||||
}
|
||||
certificateNewVersionInfo := &wangsucdn.CertificateVersionInfo{
|
||||
PrivateKey: xtypes.ToPtr(encryptedPrivateKey),
|
||||
Certificate: xtypes.ToPtr(certPEM),
|
||||
PrivateKey: lo.ToPtr(encryptedPrivateKey),
|
||||
Certificate: lo.ToPtr(certPEM),
|
||||
IdentificationInfo: &wangsucdn.CertificateVersionIdentificationInfo{
|
||||
CommonName: xtypes.ToPtr(certX509.Subject.CommonName),
|
||||
CommonName: lo.ToPtr(certX509.Subject.CommonName),
|
||||
SubjectAlternativeNames: &certX509.DNSNames,
|
||||
},
|
||||
}
|
||||
@@ -120,8 +121,8 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
// 创建证书
|
||||
createCertificateReq := &wangsucdn.CreateCertificateRequest{
|
||||
Timestamp: timestamp,
|
||||
Name: xtypes.ToPtr(fmt.Sprintf("certimate_%d", time.Now().UnixMilli())),
|
||||
AutoRenew: xtypes.ToPtr("Off"),
|
||||
Name: lo.ToPtr(fmt.Sprintf("certimate_%d", time.Now().UnixMilli())),
|
||||
AutoRenew: lo.ToPtr("Off"),
|
||||
NewVersion: certificateNewVersionInfo,
|
||||
}
|
||||
createCertificateResp, err := d.sdkClient.CreateCertificate(createCertificateReq)
|
||||
@@ -143,8 +144,8 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
// 更新证书
|
||||
updateCertificateReq := &wangsucdn.UpdateCertificateRequest{
|
||||
Timestamp: timestamp,
|
||||
Name: xtypes.ToPtr(fmt.Sprintf("certimate_%d", time.Now().UnixMilli())),
|
||||
AutoRenew: xtypes.ToPtr("Off"),
|
||||
Name: lo.ToPtr(fmt.Sprintf("certimate_%d", time.Now().UnixMilli())),
|
||||
AutoRenew: lo.ToPtr("Off"),
|
||||
NewVersion: certificateNewVersionInfo,
|
||||
}
|
||||
updateCertificateResp, err := d.sdkClient.UpdateCertificate(d.config.CertificateId, updateCertificateReq)
|
||||
@@ -171,18 +172,18 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
// 创建部署任务
|
||||
// REF: https://www.wangsu.com/document/api-doc/27034
|
||||
createDeploymentTaskReq := &wangsucdn.CreateDeploymentTaskRequest{
|
||||
Name: xtypes.ToPtr(fmt.Sprintf("certimate_%d", time.Now().UnixMilli())),
|
||||
Target: xtypes.ToPtr(d.config.Environment),
|
||||
Name: lo.ToPtr(fmt.Sprintf("certimate_%d", time.Now().UnixMilli())),
|
||||
Target: lo.ToPtr(d.config.Environment),
|
||||
Actions: &[]wangsucdn.DeploymentTaskActionInfo{
|
||||
{
|
||||
Action: xtypes.ToPtr("deploy_cert"),
|
||||
CertificateId: xtypes.ToPtr(wangsuCertId),
|
||||
Version: xtypes.ToPtr(wangsuCertVer),
|
||||
Action: lo.ToPtr("deploy_cert"),
|
||||
CertificateId: lo.ToPtr(wangsuCertId),
|
||||
Version: lo.ToPtr(wangsuCertVer),
|
||||
},
|
||||
},
|
||||
}
|
||||
if d.config.WebhookId != "" {
|
||||
createDeploymentTaskReq.Webhook = xtypes.ToPtr(d.config.WebhookId)
|
||||
createDeploymentTaskReq.Webhook = lo.ToPtr(d.config.WebhookId)
|
||||
}
|
||||
createDeploymentTaskResp, err := d.sdkClient.CreateDeploymentTask(createDeploymentTaskReq)
|
||||
d.logger.Debug("sdk request 'cdnpro.CreateCertificate'", slog.Any("request", createDeploymentTaskReq), slog.Any("response", createDeploymentTaskResp))
|
||||
|
||||
@@ -7,10 +7,11 @@ import (
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
sslmgrsp "github.com/certimate-go/certimate/pkg/core/ssl-manager/providers/wangsu-certificate"
|
||||
wangsusdk "github.com/certimate-go/certimate/pkg/sdk3rd/wangsu/certificate"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLDeployerProviderConfig struct {
|
||||
@@ -79,10 +80,10 @@ func (d *SSLDeployerProvider) Deploy(ctx context.Context, certPEM string, privke
|
||||
// 修改证书
|
||||
// REF: https://www.wangsu.com/document/api-doc/25568?productCode=certificatemanagement
|
||||
updateCertificateReq := &wangsusdk.UpdateCertificateRequest{
|
||||
Name: xtypes.ToPtr(fmt.Sprintf("certimate_%d", time.Now().UnixMilli())),
|
||||
Certificate: xtypes.ToPtr(certPEM),
|
||||
PrivateKey: xtypes.ToPtr(privkeyPEM),
|
||||
Comment: xtypes.ToPtr("upload from certimate"),
|
||||
Name: lo.ToPtr(fmt.Sprintf("certimate_%d", time.Now().UnixMilli())),
|
||||
Certificate: lo.ToPtr(certPEM),
|
||||
PrivateKey: lo.ToPtr(privkeyPEM),
|
||||
Comment: lo.ToPtr("upload from certimate"),
|
||||
}
|
||||
updateCertificateResp, err := d.sdkClient.UpdateCertificate(d.config.CertificateId, updateCertificateReq)
|
||||
d.logger.Debug("sdk request 'certificatemanagement.UpdateCertificate'", slog.Any("request", updateCertificateReq), slog.Any("response", updateCertificateResp))
|
||||
|
||||
@@ -11,10 +11,10 @@ import (
|
||||
alicas "github.com/alibabacloud-go/cas-20200407/v3/client"
|
||||
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||
"github.com/alibabacloud-go/tea/tea"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
xcert "github.com/certimate-go/certimate/pkg/utils/cert"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLManagerProviderConfig struct {
|
||||
@@ -81,7 +81,7 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
}
|
||||
|
||||
listUserCertificateOrderReq := &alicas.ListUserCertificateOrderRequest{
|
||||
ResourceGroupId: xtypes.ToPtrOrZeroNil(m.config.ResourceGroupId),
|
||||
ResourceGroupId: lo.EmptyableToPtr(m.config.ResourceGroupId),
|
||||
CurrentPage: tea.Int64(listUserCertificateOrderPage),
|
||||
ShowSize: tea.Int64(listUserCertificateOrderLimit),
|
||||
OrderType: tea.String("CERT"),
|
||||
@@ -157,7 +157,7 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
// 上传新证书
|
||||
// REF: https://help.aliyun.com/zh/ssl-certificate/developer-reference/api-cas-2020-04-07-uploadusercertificate
|
||||
uploadUserCertificateReq := &alicas.UploadUserCertificateRequest{
|
||||
ResourceGroupId: xtypes.ToPtrOrZeroNil(m.config.ResourceGroupId),
|
||||
ResourceGroupId: lo.EmptyableToPtr(m.config.ResourceGroupId),
|
||||
Name: tea.String(certName),
|
||||
Cert: tea.String(certPEM),
|
||||
Key: tea.String(privkeyPEM),
|
||||
|
||||
@@ -14,10 +14,10 @@ import (
|
||||
aliopen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||
alislb "github.com/alibabacloud-go/slb-20140515/v4/client"
|
||||
"github.com/alibabacloud-go/tea/tea"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
xcert "github.com/certimate-go/certimate/pkg/utils/cert"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLManagerProviderConfig struct {
|
||||
@@ -74,7 +74,7 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
// 查询证书列表,避免重复上传
|
||||
// REF: https://help.aliyun.com/zh/slb/classic-load-balancer/developer-reference/api-slb-2014-05-15-describeservercertificates
|
||||
describeServerCertificatesReq := &alislb.DescribeServerCertificatesRequest{
|
||||
ResourceGroupId: xtypes.ToPtrOrZeroNil(m.config.ResourceGroupId),
|
||||
ResourceGroupId: lo.EmptyableToPtr(m.config.ResourceGroupId),
|
||||
RegionId: tea.String(m.config.Region),
|
||||
}
|
||||
describeServerCertificatesResp, err := m.sdkClient.DescribeServerCertificates(describeServerCertificatesReq)
|
||||
@@ -113,7 +113,7 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
// 上传新证书
|
||||
// REF: https://help.aliyun.com/zh/slb/classic-load-balancer/developer-reference/api-slb-2014-05-15-uploadservercertificate
|
||||
uploadServerCertificateReq := &alislb.UploadServerCertificateRequest{
|
||||
ResourceGroupId: xtypes.ToPtrOrZeroNil(m.config.ResourceGroupId),
|
||||
ResourceGroupId: lo.EmptyableToPtr(m.config.ResourceGroupId),
|
||||
RegionId: tea.String(m.config.Region),
|
||||
ServerCertificateName: tea.String(certName),
|
||||
ServerCertificate: tea.String(certPEM),
|
||||
|
||||
@@ -9,10 +9,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
ctyunao "github.com/certimate-go/certimate/pkg/sdk3rd/ctyun/ao"
|
||||
xcert "github.com/certimate-go/certimate/pkg/utils/cert"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLManagerProviderConfig struct {
|
||||
@@ -74,9 +75,9 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
}
|
||||
|
||||
listCertsReq := &ctyunao.ListCertsRequest{
|
||||
Page: xtypes.ToPtr(listCertPage),
|
||||
PerPage: xtypes.ToPtr(listCertPerPage),
|
||||
UsageMode: xtypes.ToPtr(int32(0)),
|
||||
Page: lo.ToPtr(listCertPage),
|
||||
PerPage: lo.ToPtr(listCertPerPage),
|
||||
UsageMode: lo.ToPtr(int32(0)),
|
||||
}
|
||||
listCertsResp, err := m.sdkClient.ListCerts(listCertsReq)
|
||||
m.logger.Debug("sdk request 'ao.ListCerts'", slog.Any("request", listCertsReq), slog.Any("response", listCertsResp))
|
||||
@@ -106,7 +107,7 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
// 查询证书详情
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=113&api=13015&data=174&isNormal=1&vid=167
|
||||
queryCertReq := &ctyunao.QueryCertRequest{
|
||||
Id: xtypes.ToPtr(certRecord.Id),
|
||||
Id: lo.ToPtr(certRecord.Id),
|
||||
}
|
||||
queryCertResp, err := m.sdkClient.QueryCert(queryCertReq)
|
||||
m.logger.Debug("sdk request 'ao.QueryCert'", slog.Any("request", queryCertReq), slog.Any("response", queryCertResp))
|
||||
@@ -150,9 +151,9 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
// 创建证书
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=113&api=13014&data=174&isNormal=1&vid=167
|
||||
createCertReq := &ctyunao.CreateCertRequest{
|
||||
Name: xtypes.ToPtr(certName),
|
||||
Certs: xtypes.ToPtr(certPEM),
|
||||
Key: xtypes.ToPtr(privkeyPEM),
|
||||
Name: lo.ToPtr(certName),
|
||||
Certs: lo.ToPtr(certPEM),
|
||||
Key: lo.ToPtr(privkeyPEM),
|
||||
}
|
||||
createCertResp, err := m.sdkClient.CreateCert(createCertReq)
|
||||
m.logger.Debug("sdk request 'ao.CreateCert'", slog.Any("request", createCertReq), slog.Any("response", createCertResp))
|
||||
|
||||
@@ -9,10 +9,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
ctyuncdn "github.com/certimate-go/certimate/pkg/sdk3rd/ctyun/cdn"
|
||||
xcert "github.com/certimate-go/certimate/pkg/utils/cert"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLManagerProviderConfig struct {
|
||||
@@ -74,9 +75,9 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
}
|
||||
|
||||
queryCertListReq := &ctyuncdn.QueryCertListRequest{
|
||||
Page: xtypes.ToPtr(queryCertListPage),
|
||||
PerPage: xtypes.ToPtr(queryCertListPerPage),
|
||||
UsageMode: xtypes.ToPtr(int32(0)),
|
||||
Page: lo.ToPtr(queryCertListPage),
|
||||
PerPage: lo.ToPtr(queryCertListPerPage),
|
||||
UsageMode: lo.ToPtr(int32(0)),
|
||||
}
|
||||
queryCertListResp, err := m.sdkClient.QueryCertList(queryCertListReq)
|
||||
m.logger.Debug("sdk request 'cdn.QueryCertList'", slog.Any("request", queryCertListReq), slog.Any("response", queryCertListResp))
|
||||
@@ -106,7 +107,7 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
// 查询证书详情
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=108&api=10899&data=161&isNormal=1&vid=154
|
||||
queryCertDetailReq := &ctyuncdn.QueryCertDetailRequest{
|
||||
Id: xtypes.ToPtr(certRecord.Id),
|
||||
Id: lo.ToPtr(certRecord.Id),
|
||||
}
|
||||
queryCertDetailResp, err := m.sdkClient.QueryCertDetail(queryCertDetailReq)
|
||||
m.logger.Debug("sdk request 'cdn.QueryCertDetail'", slog.Any("request", queryCertDetailReq), slog.Any("response", queryCertDetailResp))
|
||||
@@ -150,9 +151,9 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
// 创建证书
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=108&api=10893&data=161&isNormal=1&vid=154
|
||||
createCertReq := &ctyuncdn.CreateCertRequest{
|
||||
Name: xtypes.ToPtr(certName),
|
||||
Certs: xtypes.ToPtr(certPEM),
|
||||
Key: xtypes.ToPtr(privkeyPEM),
|
||||
Name: lo.ToPtr(certName),
|
||||
Certs: lo.ToPtr(certPEM),
|
||||
Key: lo.ToPtr(privkeyPEM),
|
||||
}
|
||||
createCertResp, err := m.sdkClient.CreateCert(createCertReq)
|
||||
m.logger.Debug("sdk request 'cdn.CreateCert'", slog.Any("request", createCertReq), slog.Any("response", createCertResp))
|
||||
|
||||
@@ -10,10 +10,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
ctyuncms "github.com/certimate-go/certimate/pkg/sdk3rd/ctyun/cms"
|
||||
xcert "github.com/certimate-go/certimate/pkg/utils/cert"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLManagerProviderConfig struct {
|
||||
@@ -74,11 +75,11 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
// 上传证书
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=152&api=17243&data=204&isNormal=1&vid=283
|
||||
uploadCertificateReq := &ctyuncms.UploadCertificateRequest{
|
||||
Name: xtypes.ToPtr(certName),
|
||||
Certificate: xtypes.ToPtr(serverCertPEM),
|
||||
CertificateChain: xtypes.ToPtr(intermediaCertPEM),
|
||||
PrivateKey: xtypes.ToPtr(privkeyPEM),
|
||||
EncryptionStandard: xtypes.ToPtr("INTERNATIONAL"),
|
||||
Name: lo.ToPtr(certName),
|
||||
Certificate: lo.ToPtr(serverCertPEM),
|
||||
CertificateChain: lo.ToPtr(intermediaCertPEM),
|
||||
PrivateKey: lo.ToPtr(privkeyPEM),
|
||||
EncryptionStandard: lo.ToPtr("INTERNATIONAL"),
|
||||
}
|
||||
uploadCertificateResp, err := m.sdkClient.UploadCertificate(uploadCertificateReq)
|
||||
m.logger.Debug("sdk request 'cms.UploadCertificate'", slog.Any("request", uploadCertificateReq), slog.Any("response", uploadCertificateResp))
|
||||
@@ -126,10 +127,10 @@ func (m *SSLManagerProvider) findCertIfExists(ctx context.Context, certPEM strin
|
||||
}
|
||||
|
||||
getCertificateListReq := &ctyuncms.GetCertificateListRequest{
|
||||
PageNum: xtypes.ToPtr(getCertificateListPageNum),
|
||||
PageSize: xtypes.ToPtr(getCertificateListPageSize),
|
||||
Keyword: xtypes.ToPtr(certX509.Subject.CommonName),
|
||||
Origin: xtypes.ToPtr("UPLOAD"),
|
||||
PageNum: lo.ToPtr(getCertificateListPageNum),
|
||||
PageSize: lo.ToPtr(getCertificateListPageSize),
|
||||
Keyword: lo.ToPtr(certX509.Subject.CommonName),
|
||||
Origin: lo.ToPtr("UPLOAD"),
|
||||
}
|
||||
getCertificateListResp, err := m.sdkClient.GetCertificateList(getCertificateListReq)
|
||||
m.logger.Debug("sdk request 'cms.GetCertificateList'", slog.Any("request", getCertificateListReq), slog.Any("response", getCertificateListResp))
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
ctyunelb "github.com/certimate-go/certimate/pkg/sdk3rd/ctyun/elb"
|
||||
xcert "github.com/certimate-go/certimate/pkg/utils/cert"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLManagerProviderConfig struct {
|
||||
@@ -67,7 +67,7 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
// 查询证书列表,避免重复上传
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=24&api=5692&data=88&isNormal=1&vid=82
|
||||
listCertificatesReq := &ctyunelb.ListCertificatesRequest{
|
||||
RegionID: xtypes.ToPtr(m.config.RegionId),
|
||||
RegionID: lo.ToPtr(m.config.RegionId),
|
||||
}
|
||||
listCertificatesResp, err := m.sdkClient.ListCertificates(listCertificatesReq)
|
||||
m.logger.Debug("sdk request 'elb.ListCertificates'", slog.Any("request", listCertificatesReq), slog.Any("response", listCertificatesResp))
|
||||
@@ -104,13 +104,13 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
// 创建证书
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=24&api=5685&data=88&isNormal=1&vid=82
|
||||
createCertificateReq := &ctyunelb.CreateCertificateRequest{
|
||||
ClientToken: xtypes.ToPtr(generateClientToken()),
|
||||
RegionID: xtypes.ToPtr(m.config.RegionId),
|
||||
Name: xtypes.ToPtr(certName),
|
||||
Description: xtypes.ToPtr("upload from certimate"),
|
||||
Type: xtypes.ToPtr("Server"),
|
||||
Certificate: xtypes.ToPtr(certPEM),
|
||||
PrivateKey: xtypes.ToPtr(privkeyPEM),
|
||||
ClientToken: lo.ToPtr(generateClientToken()),
|
||||
RegionID: lo.ToPtr(m.config.RegionId),
|
||||
Name: lo.ToPtr(certName),
|
||||
Description: lo.ToPtr("upload from certimate"),
|
||||
Type: lo.ToPtr("Server"),
|
||||
Certificate: lo.ToPtr(certPEM),
|
||||
PrivateKey: lo.ToPtr(privkeyPEM),
|
||||
}
|
||||
createCertificateResp, err := m.sdkClient.CreateCertificate(createCertificateReq)
|
||||
m.logger.Debug("sdk request 'elb.CreateCertificate'", slog.Any("request", createCertificateReq), slog.Any("response", createCertificateResp))
|
||||
|
||||
@@ -9,10 +9,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
ctyunicdn "github.com/certimate-go/certimate/pkg/sdk3rd/ctyun/icdn"
|
||||
xcert "github.com/certimate-go/certimate/pkg/utils/cert"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLManagerProviderConfig struct {
|
||||
@@ -74,9 +75,9 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
}
|
||||
|
||||
queryCertListReq := &ctyunicdn.QueryCertListRequest{
|
||||
Page: xtypes.ToPtr(queryCertListPage),
|
||||
PerPage: xtypes.ToPtr(queryCertListPerPage),
|
||||
UsageMode: xtypes.ToPtr(int32(0)),
|
||||
Page: lo.ToPtr(queryCertListPage),
|
||||
PerPage: lo.ToPtr(queryCertListPerPage),
|
||||
UsageMode: lo.ToPtr(int32(0)),
|
||||
}
|
||||
queryCertListResp, err := m.sdkClient.QueryCertList(queryCertListReq)
|
||||
m.logger.Debug("sdk request 'icdn.QueryCertList'", slog.Any("request", queryCertListReq), slog.Any("response", queryCertListResp))
|
||||
@@ -106,7 +107,7 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
// 查询证书详情
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=112&api=10837&data=173&isNormal=1&vid=166
|
||||
queryCertDetailReq := &ctyunicdn.QueryCertDetailRequest{
|
||||
Id: xtypes.ToPtr(certRecord.Id),
|
||||
Id: lo.ToPtr(certRecord.Id),
|
||||
}
|
||||
queryCertDetailResp, err := m.sdkClient.QueryCertDetail(queryCertDetailReq)
|
||||
m.logger.Debug("sdk request 'icdn.QueryCertDetail'", slog.Any("request", queryCertDetailReq), slog.Any("response", queryCertDetailResp))
|
||||
@@ -150,9 +151,9 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
// 创建证书
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=112&api=10835&data=173&isNormal=1&vid=166
|
||||
createCertReq := &ctyunicdn.CreateCertRequest{
|
||||
Name: xtypes.ToPtr(certName),
|
||||
Certs: xtypes.ToPtr(certPEM),
|
||||
Key: xtypes.ToPtr(privkeyPEM),
|
||||
Name: lo.ToPtr(certName),
|
||||
Certs: lo.ToPtr(certPEM),
|
||||
Key: lo.ToPtr(privkeyPEM),
|
||||
}
|
||||
createCertResp, err := m.sdkClient.CreateCert(createCertReq)
|
||||
m.logger.Debug("sdk request 'icdn.CreateCert'", slog.Any("request", createCertReq), slog.Any("response", createCertResp))
|
||||
|
||||
@@ -9,10 +9,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
ctyunlvdn "github.com/certimate-go/certimate/pkg/sdk3rd/ctyun/lvdn"
|
||||
xcert "github.com/certimate-go/certimate/pkg/utils/cert"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLManagerProviderConfig struct {
|
||||
@@ -74,9 +75,9 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
}
|
||||
|
||||
queryCertListReq := &ctyunlvdn.QueryCertListRequest{
|
||||
Page: xtypes.ToPtr(queryCertListPage),
|
||||
PerPage: xtypes.ToPtr(queryCertListPerPage),
|
||||
UsageMode: xtypes.ToPtr(int32(0)),
|
||||
Page: lo.ToPtr(queryCertListPage),
|
||||
PerPage: lo.ToPtr(queryCertListPerPage),
|
||||
UsageMode: lo.ToPtr(int32(0)),
|
||||
}
|
||||
queryCertListResp, err := m.sdkClient.QueryCertList(queryCertListReq)
|
||||
m.logger.Debug("sdk request 'lvdn.QueryCertList'", slog.Any("request", queryCertListReq), slog.Any("response", queryCertListResp))
|
||||
@@ -106,7 +107,7 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
// 查询证书详情
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=125&api=11449&data=183&isNormal=1&vid=261
|
||||
queryCertDetailReq := &ctyunlvdn.QueryCertDetailRequest{
|
||||
Id: xtypes.ToPtr(certRecord.Id),
|
||||
Id: lo.ToPtr(certRecord.Id),
|
||||
}
|
||||
queryCertDetailResp, err := m.sdkClient.QueryCertDetail(queryCertDetailReq)
|
||||
m.logger.Debug("sdk request 'lvdn.QueryCertDetail'", slog.Any("request", queryCertDetailReq), slog.Any("response", queryCertDetailResp))
|
||||
@@ -150,9 +151,9 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
// 创建证书
|
||||
// REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=125&api=11436&data=183&isNormal=1&vid=261
|
||||
createCertReq := &ctyunlvdn.CreateCertRequest{
|
||||
Name: xtypes.ToPtr(certName),
|
||||
Certs: xtypes.ToPtr(certPEM),
|
||||
Key: xtypes.ToPtr(privkeyPEM),
|
||||
Name: lo.ToPtr(certName),
|
||||
Certs: lo.ToPtr(certPEM),
|
||||
Key: lo.ToPtr(privkeyPEM),
|
||||
}
|
||||
createCertResp, err := m.sdkClient.CreateCert(createCertReq)
|
||||
m.logger.Debug("sdk request 'lvdn.CreateCert'", slog.Any("request", createCertReq), slog.Any("response", createCertResp))
|
||||
|
||||
@@ -15,10 +15,10 @@ import (
|
||||
hciam "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3"
|
||||
hciammodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3/model"
|
||||
hciamregion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iam/v3/region"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
xcert "github.com/certimate-go/certimate/pkg/utils/cert"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLManagerProviderConfig struct {
|
||||
@@ -84,7 +84,7 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
}
|
||||
|
||||
listCertificatesReq := &hcelbmodel.ListCertificatesRequest{
|
||||
Limit: xtypes.ToPtr(listCertificatesLimit),
|
||||
Limit: lo.ToPtr(listCertificatesLimit),
|
||||
Marker: listCertificatesMarker,
|
||||
Type: &[]string{"server"},
|
||||
}
|
||||
@@ -141,11 +141,11 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
createCertificateReq := &hcelbmodel.CreateCertificateRequest{
|
||||
Body: &hcelbmodel.CreateCertificateRequestBody{
|
||||
Certificate: &hcelbmodel.CreateCertificateOption{
|
||||
EnterpriseProjectId: xtypes.ToPtrOrZeroNil(m.config.EnterpriseProjectId),
|
||||
ProjectId: xtypes.ToPtr(projectId),
|
||||
Name: xtypes.ToPtr(certName),
|
||||
Certificate: xtypes.ToPtr(certPEM),
|
||||
PrivateKey: xtypes.ToPtr(privkeyPEM),
|
||||
EnterpriseProjectId: lo.EmptyableToPtr(m.config.EnterpriseProjectId),
|
||||
ProjectId: lo.ToPtr(projectId),
|
||||
Name: lo.ToPtr(certName),
|
||||
Certificate: lo.ToPtr(certPEM),
|
||||
PrivateKey: lo.ToPtr(privkeyPEM),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -12,10 +12,10 @@ import (
|
||||
hcscm "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/scm/v3"
|
||||
hcscmmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/scm/v3/model"
|
||||
hcscmregion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/scm/v3/region"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
xcert "github.com/certimate-go/certimate/pkg/utils/cert"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLManagerProviderConfig struct {
|
||||
@@ -82,11 +82,11 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
}
|
||||
|
||||
listCertificatesReq := &hcscmmodel.ListCertificatesRequest{
|
||||
EnterpriseProjectId: xtypes.ToPtrOrZeroNil(m.config.EnterpriseProjectId),
|
||||
Limit: xtypes.ToPtr(listCertificatesLimit),
|
||||
Offset: xtypes.ToPtr(listCertificatesOffset),
|
||||
SortDir: xtypes.ToPtr("DESC"),
|
||||
SortKey: xtypes.ToPtr("certExpiredTime"),
|
||||
EnterpriseProjectId: lo.EmptyableToPtr(m.config.EnterpriseProjectId),
|
||||
Limit: lo.ToPtr(listCertificatesLimit),
|
||||
Offset: lo.ToPtr(listCertificatesOffset),
|
||||
SortDir: lo.ToPtr("DESC"),
|
||||
SortKey: lo.ToPtr("certExpiredTime"),
|
||||
}
|
||||
listCertificatesResp, err := m.sdkClient.ListCertificates(listCertificatesReq)
|
||||
m.logger.Debug("sdk request 'scm.ListCertificates'", slog.Any("request", listCertificatesReq), slog.Any("response", listCertificatesResp))
|
||||
@@ -156,7 +156,7 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
// REF: https://support.huaweicloud.com/api-ccm/ImportCertificate.html
|
||||
importCertificateReq := &hcscmmodel.ImportCertificateRequest{
|
||||
Body: &hcscmmodel.ImportCertificateRequestBody{
|
||||
EnterpriseProjectId: xtypes.ToPtrOrZeroNil(m.config.EnterpriseProjectId),
|
||||
EnterpriseProjectId: lo.EmptyableToPtr(m.config.EnterpriseProjectId),
|
||||
Name: certName,
|
||||
Certificate: certPEM,
|
||||
PrivateKey: privkeyPEM,
|
||||
|
||||
@@ -15,10 +15,10 @@ import (
|
||||
hcwaf "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/waf/v1"
|
||||
hcwafmodel "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/waf/v1/model"
|
||||
hcwafregion "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/waf/v1/region"
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
xcert "github.com/certimate-go/certimate/pkg/utils/cert"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLManagerProviderConfig struct {
|
||||
@@ -85,9 +85,9 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
}
|
||||
|
||||
listCertificatesReq := &hcwafmodel.ListCertificatesRequest{
|
||||
EnterpriseProjectId: xtypes.ToPtrOrZeroNil(m.config.EnterpriseProjectId),
|
||||
Page: xtypes.ToPtr(listCertificatesPage),
|
||||
Pagesize: xtypes.ToPtr(listCertificatesPageSize),
|
||||
EnterpriseProjectId: lo.EmptyableToPtr(m.config.EnterpriseProjectId),
|
||||
Page: lo.ToPtr(listCertificatesPage),
|
||||
Pagesize: lo.ToPtr(listCertificatesPageSize),
|
||||
}
|
||||
listCertificatesResp, err := m.sdkClient.ListCertificates(listCertificatesReq)
|
||||
m.logger.Debug("sdk request 'waf.ShowCertificate'", slog.Any("request", listCertificatesReq), slog.Any("response", listCertificatesResp))
|
||||
@@ -98,7 +98,7 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
if listCertificatesResp.Items != nil {
|
||||
for _, certItem := range *listCertificatesResp.Items {
|
||||
showCertificateReq := &hcwafmodel.ShowCertificateRequest{
|
||||
EnterpriseProjectId: xtypes.ToPtrOrZeroNil(m.config.EnterpriseProjectId),
|
||||
EnterpriseProjectId: lo.EmptyableToPtr(m.config.EnterpriseProjectId),
|
||||
CertificateId: certItem.Id,
|
||||
}
|
||||
showCertificateResp, err := m.sdkClient.ShowCertificate(showCertificateReq)
|
||||
@@ -143,7 +143,7 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
// 创建证书
|
||||
// REF: https://support.huaweicloud.com/api-waf/CreateCertificate.html
|
||||
createCertificateReq := &hcwafmodel.CreateCertificateRequest{
|
||||
EnterpriseProjectId: xtypes.ToPtrOrZeroNil(m.config.EnterpriseProjectId),
|
||||
EnterpriseProjectId: lo.EmptyableToPtr(m.config.EnterpriseProjectId),
|
||||
Body: &hcwafmodel.CreateCertificateRequestBody{
|
||||
Name: certName,
|
||||
Content: certPEM,
|
||||
|
||||
@@ -9,10 +9,11 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/samber/lo"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/core"
|
||||
wangsusdk "github.com/certimate-go/certimate/pkg/sdk3rd/wangsu/certificate"
|
||||
xcert "github.com/certimate-go/certimate/pkg/utils/cert"
|
||||
xtypes "github.com/certimate-go/certimate/pkg/utils/types"
|
||||
)
|
||||
|
||||
type SSLManagerProviderConfig struct {
|
||||
@@ -100,10 +101,10 @@ func (m *SSLManagerProvider) Upload(ctx context.Context, certPEM string, privkey
|
||||
// 新增证书
|
||||
// REF: https://www.wangsu.com/document/api-doc/25199?productCode=certificatemanagement
|
||||
createCertificateReq := &wangsusdk.CreateCertificateRequest{
|
||||
Name: xtypes.ToPtr(certName),
|
||||
Certificate: xtypes.ToPtr(certPEM),
|
||||
PrivateKey: xtypes.ToPtr(privkeyPEM),
|
||||
Comment: xtypes.ToPtr("upload from certimate"),
|
||||
Name: lo.ToPtr(certName),
|
||||
Certificate: lo.ToPtr(certPEM),
|
||||
PrivateKey: lo.ToPtr(privkeyPEM),
|
||||
Comment: lo.ToPtr("upload from certimate"),
|
||||
}
|
||||
createCertificateResp, err := m.sdkClient.CreateCertificate(createCertificateReq)
|
||||
m.logger.Debug("sdk request 'certificatemanagement.CreateCertificate'", slog.Any("request", createCertificateReq), slog.Any("response", createCertificateResp))
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
package ifelse
|
||||
|
||||
type branch[T any] struct {
|
||||
cond bool
|
||||
fn func() T
|
||||
}
|
||||
|
||||
type ifExpr[T any] struct {
|
||||
cond bool
|
||||
}
|
||||
|
||||
type thenExpr[T any] struct {
|
||||
branches []branch[T]
|
||||
}
|
||||
|
||||
type elseIfExpr[T any] struct {
|
||||
branches []branch[T]
|
||||
cond bool
|
||||
}
|
||||
|
||||
// 用法示例:
|
||||
//
|
||||
// result := ifelse.If[string](age < 18).Then("child").
|
||||
// ElseIf(age < 60).Then("adult").
|
||||
// ElseIf(age < 120).Then("senior").
|
||||
// Else("invalid")
|
||||
func If[T any](condition bool) *ifExpr[T] {
|
||||
return &ifExpr[T]{cond: condition}
|
||||
}
|
||||
|
||||
func (e *ifExpr[T]) Then(consequent T) *thenExpr[T] {
|
||||
return &thenExpr[T]{
|
||||
branches: []branch[T]{
|
||||
{cond: e.cond, fn: func() T { return consequent }},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (e *ifExpr[T]) ThenFunc(consequent func() T) *thenExpr[T] {
|
||||
return &thenExpr[T]{
|
||||
branches: []branch[T]{
|
||||
{cond: e.cond, fn: consequent},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (e *thenExpr[T]) ElseIf(condition bool) *elseIfExpr[T] {
|
||||
return &elseIfExpr[T]{
|
||||
branches: e.branches,
|
||||
cond: condition,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *elseIfExpr[T]) Then(alternative T) *thenExpr[T] {
|
||||
branch := branch[T]{cond: e.cond, fn: func() T { return alternative }}
|
||||
return &thenExpr[T]{
|
||||
branches: append(e.branches, branch),
|
||||
}
|
||||
}
|
||||
|
||||
func (e *elseIfExpr[T]) ThenFunc(alternativeFunc func() T) *thenExpr[T] {
|
||||
branch := branch[T]{cond: e.cond, fn: alternativeFunc}
|
||||
return &thenExpr[T]{
|
||||
branches: append(e.branches, branch),
|
||||
}
|
||||
}
|
||||
|
||||
func (e *thenExpr[T]) Else(alternative T) T {
|
||||
for _, b := range e.branches {
|
||||
if b.cond {
|
||||
return b.fn()
|
||||
}
|
||||
}
|
||||
return alternative
|
||||
}
|
||||
|
||||
func (e *thenExpr[T]) ElseFunc(alternativeFunc func() T) T {
|
||||
for _, b := range e.branches {
|
||||
if b.cond {
|
||||
return b.fn()
|
||||
}
|
||||
}
|
||||
return alternativeFunc()
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
package ifelse_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/certimate-go/certimate/pkg/utils/ifelse"
|
||||
)
|
||||
|
||||
func TestIfTrue(t *testing.T) {
|
||||
result := ifelse.If[string](true).
|
||||
Then("true branch").
|
||||
Else("false branch")
|
||||
|
||||
if result != "true branch" {
|
||||
t.Errorf("Expected 'true branch', got '%s'", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIfFalse(t *testing.T) {
|
||||
result := ifelse.If[string](false).
|
||||
Then("true branch").
|
||||
Else("false branch")
|
||||
|
||||
if result != "false branch" {
|
||||
t.Errorf("Expected 'false branch', got '%s'", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestElseIfFirstMatch(t *testing.T) {
|
||||
result := ifelse.If[string](false).
|
||||
Then("should not run").
|
||||
ElseIf(true).
|
||||
Then("elseif branch").
|
||||
Else("should not run")
|
||||
|
||||
if result != "elseif branch" {
|
||||
t.Errorf("Expected 'elseif branch', got '%s'", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestElseIfSecondMatch(t *testing.T) {
|
||||
result := ifelse.If[string](false).
|
||||
Then("should not run").
|
||||
ElseIf(false).
|
||||
Then("should not run").
|
||||
ElseIf(true).
|
||||
Then("second elseif").
|
||||
Else("should not run")
|
||||
|
||||
if result != "second elseif" {
|
||||
t.Errorf("Expected 'second elseif', got '%s'", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMultipleConditions(t *testing.T) {
|
||||
result := ifelse.If[string](1 > 2).
|
||||
Then("impossible").
|
||||
ElseIf(2+2 == 5).
|
||||
Then("false math").
|
||||
ElseIf(3*3 == 9).
|
||||
Then("correct math").
|
||||
Else("fallback")
|
||||
|
||||
if result != "correct math" {
|
||||
t.Errorf("Expected 'correct math', got '%s'", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAllConditionsFalse(t *testing.T) {
|
||||
result := ifelse.If[int](false).
|
||||
Then(1).
|
||||
ElseIf(false).
|
||||
Then(2).
|
||||
ElseIf(false).
|
||||
Then(3).
|
||||
Else(99)
|
||||
|
||||
if result != 99 {
|
||||
t.Errorf("Expected 99, got %d", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLazyEvaluationThen(t *testing.T) {
|
||||
called := []string{}
|
||||
|
||||
result := ifelse.If[string](true).
|
||||
ThenFunc(func() string {
|
||||
called = append(called, "then")
|
||||
return "then"
|
||||
}).
|
||||
ElseIf(true).
|
||||
ThenFunc(func() string {
|
||||
called = append(called, "elseif")
|
||||
return "elseif"
|
||||
}).
|
||||
ElseFunc(func() string {
|
||||
called = append(called, "else")
|
||||
return "else"
|
||||
})
|
||||
|
||||
// 验证结果和调用情况
|
||||
if result != "then" {
|
||||
t.Errorf("Expected 'then', got '%s'", result)
|
||||
}
|
||||
|
||||
if len(called) != 1 || called[0] != "then" {
|
||||
t.Errorf("Expected only 'then' called, got %v", called)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLazyEvaluationElseIf(t *testing.T) {
|
||||
called := []string{}
|
||||
|
||||
result := ifelse.If[string](false).
|
||||
ThenFunc(func() string {
|
||||
called = append(called, "then")
|
||||
return "then"
|
||||
}).
|
||||
ElseIf(true).
|
||||
ThenFunc(func() string {
|
||||
called = append(called, "elseif")
|
||||
return "elseif"
|
||||
}).
|
||||
ElseFunc(func() string {
|
||||
called = append(called, "else")
|
||||
return "else"
|
||||
})
|
||||
|
||||
// 验证结果和调用情况
|
||||
if result != "elseif" {
|
||||
t.Errorf("Expected 'elseif', got '%s'", result)
|
||||
}
|
||||
|
||||
if len(called) != 1 || called[0] != "elseif" {
|
||||
t.Errorf("Expected only 'elseif' called, got %v", called)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLazyEvaluationElse(t *testing.T) {
|
||||
called := []string{}
|
||||
|
||||
result := ifelse.If[string](false).
|
||||
ThenFunc(func() string {
|
||||
called = append(called, "then")
|
||||
return "then"
|
||||
}).
|
||||
ElseIf(false).
|
||||
ThenFunc(func() string {
|
||||
called = append(called, "elseif")
|
||||
return "elseif"
|
||||
}).
|
||||
ElseFunc(func() string {
|
||||
called = append(called, "else")
|
||||
return "else"
|
||||
})
|
||||
|
||||
// 验证结果和调用情况
|
||||
if result != "else" {
|
||||
t.Errorf("Expected 'else', got '%s'", result)
|
||||
}
|
||||
|
||||
if len(called) != 1 || called[0] != "else" {
|
||||
t.Errorf("Expected only 'else' called, got %v", called)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMixedValueAndFunc(t *testing.T) {
|
||||
result := ifelse.If[int](false).
|
||||
Then(0).
|
||||
ElseIf(false).
|
||||
ThenFunc(func() int {
|
||||
return 1
|
||||
}).
|
||||
ElseIf(true).
|
||||
Then(2).
|
||||
Else(3)
|
||||
|
||||
if result != 2 {
|
||||
t.Errorf("Expected 2, got %d", result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestComplexNumericLogic(t *testing.T) {
|
||||
x := 15
|
||||
result := ifelse.If[string](x < 10).
|
||||
Then("single digit").
|
||||
ElseIf(x < 20).
|
||||
Then("teens").
|
||||
ElseIf(x < 30).
|
||||
Then("twenties").
|
||||
Else("older")
|
||||
|
||||
if result != "teens" {
|
||||
t.Errorf("Expected 'teens', got '%s'", result)
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package ifelse
|
||||
|
||||
// 三目条件函数。
|
||||
//
|
||||
// 入参:
|
||||
// - condition: 条件。
|
||||
// - consequent: 条件为真时返回的值。
|
||||
// - alternative: 条件为假时返回的值。
|
||||
//
|
||||
// 出参:
|
||||
// - 若 condition 的为真,将返回 consequent;否则,将返回 alternative。
|
||||
func Ternary[T any](condition bool, consequent, alternative T) T {
|
||||
if condition {
|
||||
return consequent
|
||||
} else {
|
||||
return alternative
|
||||
}
|
||||
}
|
||||
|
||||
// 与 [Ternary] 类似,但返回值支持延迟计算函数。
|
||||
//
|
||||
// 入参:
|
||||
// - condition: 条件。
|
||||
// - consequentFunc: 条件为真时返回的计算函数。
|
||||
// - alternativeFunc: 条件为假时返回的计算函数。
|
||||
//
|
||||
// 出参:
|
||||
// - 若 condition 的为真,将返回 consequentFunc 的计算结果;否则,将返回 alternativeFunc 的计算结果。
|
||||
func TernaryFunc[T any](condition bool, consequentFunc, alternativeFunc func() T) T {
|
||||
if condition {
|
||||
return consequentFunc()
|
||||
} else {
|
||||
return alternativeFunc()
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
package slices
|
||||
|
||||
// 创建给定切片一部分的浅拷贝,其包含通过所提供函数实现的测试的所有元素。
|
||||
//
|
||||
// 入参:
|
||||
// - slice: 原切片。
|
||||
// - filter: 为切片中的每个元素执行的函数。它应该返回一个布尔值以指使是否将元素保留在结果切片中。
|
||||
//
|
||||
// 出参:
|
||||
// - 新切片。
|
||||
func Filter[T any](slice []T, filter func(T) bool) []T {
|
||||
var result []T
|
||||
for _, item := range slice {
|
||||
if filter(item) {
|
||||
result = append(result, item)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// 创建一个新切片,这个新切片由原切片中的每个元素都调用一次提供的函数后的返回值组成。
|
||||
//
|
||||
// 入参:
|
||||
// - slice: 原切片。
|
||||
// - mapper: 为切片中的每个元素执行的函数。它的返回值作为一个元素被添加为新切片中。
|
||||
//
|
||||
// 出参:
|
||||
// - 新切片。
|
||||
func Map[T1 any, T2 any](slice []T1, mapper func(T1) T2) []T2 {
|
||||
result := make([]T2, 0, len(slice))
|
||||
for _, item := range slice {
|
||||
result = append(result, mapper(item))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// 测试切片中是否每个元素都通过了由提供的函数实现的测试。
|
||||
//
|
||||
// 入参:
|
||||
// - slice: 切片。
|
||||
// - condition: 为切片中的每个元素执行的函数。它应该返回一个布尔值以指示元素是否通过测试。
|
||||
//
|
||||
// 出参:
|
||||
// - 测试结果。
|
||||
func Every[T any](slice []T, condition func(T) bool) bool {
|
||||
for _, item := range slice {
|
||||
if !condition(item) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// 测试切片中是否至少有一个元素通过了由提供的函数实现的测试。
|
||||
//
|
||||
// 入参:
|
||||
// - slice: 切片。
|
||||
// - condition: 为切片中的每个元素执行的函数。它应该返回一个布尔值以指示元素是否通过测试。
|
||||
//
|
||||
// 出参:
|
||||
// - 测试结果。
|
||||
func Some[T any](slice []T, condition func(T) bool) bool {
|
||||
for _, item := range slice {
|
||||
if condition(item) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// 判断对象是否为 nil。
|
||||
// 与直接使用 `obj == nil` 不同,该函数会正确判断接口类型对象的真实值是否为空。
|
||||
//
|
||||
// 入参:
|
||||
// - value:待判断的对象。
|
||||
//
|
||||
// 出参:
|
||||
// - 如果对象值为 nil,则返回 true;否则返回 false。
|
||||
func IsNil(obj any) bool {
|
||||
if obj == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
v := reflect.ValueOf(obj)
|
||||
if v.Kind() == reflect.Ptr {
|
||||
return v.IsNil()
|
||||
} else if v.Kind() == reflect.Interface {
|
||||
return v.Elem().IsNil()
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// 将对象转换为指针。
|
||||
//
|
||||
// 入参:
|
||||
// - 待转换的对象。
|
||||
//
|
||||
// 出参:
|
||||
// - 返回对象的指针。
|
||||
func ToPtr[T any](v T) (p *T) {
|
||||
return &v
|
||||
}
|
||||
|
||||
// 将非零值的对象转换为指针。
|
||||
// 与 [ToPtr] 不同的是,如果对象的值为零值,则返回 nil。
|
||||
//
|
||||
// 入参:
|
||||
// - 待转换的对象。
|
||||
//
|
||||
// 出参:
|
||||
// - 返回对象的指针。
|
||||
func ToPtrOrZeroNil[T any](v T) (p *T) {
|
||||
if reflect.ValueOf(v).IsZero() {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &v
|
||||
}
|
||||
|
||||
// 将指针转换为对象。
|
||||
//
|
||||
// 入参:
|
||||
// - 待转换的指针。
|
||||
//
|
||||
// 出参:
|
||||
// - 返回指针指向的对象。如果指针为空,则返回对象的零值。
|
||||
func ToVal[T any](p *T) (v T) {
|
||||
if IsNil(p) {
|
||||
return v
|
||||
}
|
||||
|
||||
return *p
|
||||
}
|
||||
Reference in New Issue
Block a user