mirror of
https://github.com/certimate-go/certimate.git
synced 2026-07-20 21:01:41 +08:00
chore: improve logging
This commit is contained in:
parent
d543a6de90
commit
151ecba59d
@ -208,7 +208,6 @@ func (c *Certmgr) tryGetResultIfCertExists(ctx context.Context, certPEM string)
|
||||
continue
|
||||
}
|
||||
default:
|
||||
// 未知签名算法,跳过
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@ -412,7 +412,7 @@ func (d *Deployer) updateListenerSniCertificate(ctx context.Context, cloudListen
|
||||
// 关联监听和扩展证书
|
||||
// REF: https://help.aliyun.com/zh/slb/application-load-balancer/developer-reference/api-alb-2020-06-16-associateadditionalcertificateswithlistener
|
||||
if certificateIsAlreadyAssociated {
|
||||
d.logger.Info("no need to add alb listener sni certificate")
|
||||
d.logger.Info("no need to deploy alb listener sni certificate")
|
||||
return nil
|
||||
} else {
|
||||
if err := d.waitForListenerReady(ctx, cloudListenerId); err != nil {
|
||||
|
||||
@ -232,7 +232,7 @@ func (d *Deployer) updateListenerCertificate(ctx context.Context, cloudLoadbalan
|
||||
if d.config.Domain == "" {
|
||||
// 未指定 SNI,只需部署到监听器
|
||||
if tea.StringValue(describeLoadBalancerHTTPSListenerAttributeResp.Body.ServerCertificateId) == cloudCertId {
|
||||
d.logger.Info("no need to update clb listener default certificate")
|
||||
d.logger.Info("no need to deploy clb listener default certificate")
|
||||
return nil
|
||||
}
|
||||
return d.updateListenerDefaultCertificate(ctx, cloudLoadbalancerId, cloudListenerPort, cloudCertId)
|
||||
@ -285,7 +285,7 @@ func (d *Deployer) updateListenerSniCertificate(ctx context.Context, cloudLoadba
|
||||
}
|
||||
|
||||
if tea.StringValue(domainExtension.ServerCertificateId) == cloudCertId {
|
||||
d.logger.Info("no need to add clb listener sni certificate")
|
||||
d.logger.Info("no need to deploy clb listener sni certificate")
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@ -247,7 +247,7 @@ func (d *Deployer) updateListenerCertificate(ctx context.Context, cloudAccelerat
|
||||
if d.config.Domain == "" {
|
||||
// 未指定 SNI,只需部署到监听器
|
||||
if listenerDefaultCertificate != nil && tea.StringValue(listenerDefaultCertificate.CertificateId) == cloudCertId {
|
||||
d.logger.Info("no need to update ga listener default certificate")
|
||||
d.logger.Info("no need to deploy ga listener default certificate")
|
||||
return nil
|
||||
}
|
||||
return d.updateListenerDefaultCertificate(ctx, cloudListenerId, cloudCertId)
|
||||
@ -256,7 +256,7 @@ func (d *Deployer) updateListenerCertificate(ctx context.Context, cloudAccelerat
|
||||
if lo.SomeBy(listenerAdditionalCertificates, func(item *aliga.ListListenerCertificatesResponseBodyCertificates) bool {
|
||||
return tea.StringValue(item.CertificateId) == cloudCertId
|
||||
}) {
|
||||
d.logger.Info("no need to add ga listener sni certificate")
|
||||
d.logger.Info("no need to deploy ga listener sni certificate")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -215,10 +215,11 @@ func (d *Deployer) deployToWAF3WithCloudResource(ctx context.Context, cloudCertI
|
||||
// 未指定扩展域名,只需替换默认证书
|
||||
const certAppliedTypeDefault = "default"
|
||||
|
||||
// 已部署过,直接跳过更新
|
||||
// 已部署过,直接返回
|
||||
for _, certItem := range wafCloudResourceCertificates {
|
||||
if tea.StringValue(certItem.AppliedType) == certAppliedTypeDefault &&
|
||||
tea.StringValue(certItem.CertificateId) == cloudCertId {
|
||||
d.logger.Info("no need to deploy waf default certificate")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@ -245,10 +246,11 @@ func (d *Deployer) deployToWAF3WithCloudResource(ctx context.Context, cloudCertI
|
||||
// 指定扩展域名,替换或新增扩展证书
|
||||
const certAppliedTypeExtension = "extension"
|
||||
|
||||
// 已部署过,直接跳过更新
|
||||
// 已部署过,直接返回
|
||||
for _, certItem := range wafCloudResourceCertificates {
|
||||
if tea.StringValue(certItem.AppliedType) == certAppliedTypeExtension &&
|
||||
tea.StringValue(certItem.CertificateId) == cloudCertId {
|
||||
d.logger.Info("no need to deploy waf extension certificate")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
|
||||
certArn := upres.ExtendedData["Arn"].(string)
|
||||
for _, certItem := range listenerInfo.Certificates {
|
||||
if aws.ToString(certItem.CertificateArn) == certArn && aws.ToBool(certItem.IsDefault) {
|
||||
d.logger.Info("no need to update alb listener default certificate")
|
||||
d.logger.Info("no need to deploy alb listener default certificate")
|
||||
return &DeployResult{}, nil
|
||||
}
|
||||
}
|
||||
@ -167,7 +167,7 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
|
||||
certArn := upres.ExtendedData["Arn"].(string)
|
||||
for _, certItem := range listenerInfo.Certificates {
|
||||
if aws.ToString(certItem.CertificateArn) == certArn && !aws.ToBool(certItem.IsDefault) {
|
||||
d.logger.Info("no need to add alb listener sni certificate")
|
||||
d.logger.Info("no need to deploy alb listener sni certificate")
|
||||
return &DeployResult{}, nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -155,7 +155,7 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
|
||||
certArn := upres.ExtendedData["Arn"].(string)
|
||||
for _, certItem := range listenerInfo.Certificates {
|
||||
if aws.ToString(certItem.CertificateArn) == certArn && aws.ToBool(certItem.IsDefault) {
|
||||
d.logger.Info("no need to update nlb listener default certificate")
|
||||
d.logger.Info("no need to deploy nlb listener default certificate")
|
||||
return &DeployResult{}, nil
|
||||
}
|
||||
}
|
||||
@ -167,7 +167,7 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
|
||||
certArn := upres.ExtendedData["Arn"].(string)
|
||||
for _, certItem := range listenerInfo.Certificates {
|
||||
if aws.ToString(certItem.CertificateArn) == certArn && !aws.ToBool(certItem.IsDefault) {
|
||||
d.logger.Info("no need to add nlb listener sni certificate")
|
||||
d.logger.Info("no need to deploy nlb listener sni certificate")
|
||||
return &DeployResult{}, nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -269,7 +269,7 @@ func (d *Deployer) updateHttpsListenerCertificate(ctx context.Context, cloudLoad
|
||||
if d.config.Domain == "" {
|
||||
// 未指定 SNI,只需部署到监听器
|
||||
if lo.SomeBy(listenerInfo.CertIds, func(item string) bool { return item == cloudCertId }) {
|
||||
d.logger.Info("no need to update appblb listener default certificate")
|
||||
d.logger.Info("no need to deploy appblb listener default certificate")
|
||||
return nil
|
||||
}
|
||||
return d.updateHttpsListenerDefaultCertificate(ctx, cloudLoadbalancerId, &listenerInfo, cloudCertId)
|
||||
|
||||
@ -269,7 +269,7 @@ func (d *Deployer) updateHttpsListenerCertificate(ctx context.Context, cloudLoad
|
||||
if d.config.Domain == "" {
|
||||
// 未指定 SNI,只需部署到监听器
|
||||
if lo.SomeBy(listenerInfo.CertIds, func(item string) bool { return item == cloudCertId }) {
|
||||
d.logger.Info("no need to update blb listener default certificate")
|
||||
d.logger.Info("no need to deploy blb listener default certificate")
|
||||
return nil
|
||||
}
|
||||
return d.updateHttpsListenerDefaultCertificate(ctx, cloudLoadbalancerId, &listenerInfo, cloudCertId)
|
||||
|
||||
@ -220,7 +220,7 @@ func (d *Deployer) updateListenerCertificate(ctx context.Context, cloudListenerI
|
||||
if d.config.Domain == "" {
|
||||
// 未指定 SNI,只需部署到监听器
|
||||
if bp.StringValue(describeListenerAttributesResp.CertificateId) == cloudCertId {
|
||||
d.logger.Info("no need to update alb listener default certificate")
|
||||
d.logger.Info("no need to deploy alb listener default certificate")
|
||||
return nil
|
||||
}
|
||||
return d.updateListenerDefaultCertificate(ctx, *describeListenerAttributesResp, cloudCertId)
|
||||
|
||||
@ -247,7 +247,7 @@ func (d *Deployer) updateDomainCertificate(ctx context.Context, cloudDomainId in
|
||||
return fmt.Errorf("failed to execute sdk request 'ecdn.DescribeCdnCertificateDetail': %w", err)
|
||||
} else {
|
||||
if xcert.EqualCertificatesFromPEM(certPEM, lo.FromPtr(describeCdnCertificateDetailResp.Body.Certificate)) {
|
||||
d.logger.Info("no need to update cdn certificate")
|
||||
d.logger.Info("no need to deploy cdn certificate")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -254,14 +254,14 @@ func (d *Deployer) updateListenerCertificate(ctx context.Context, cloudListenerI
|
||||
if d.config.Domain == "" {
|
||||
// 未指定 SNI,只需部署到默认证书
|
||||
if lo.FromPtr(listenerInfo.DefaultTlsContainerId) == cloudCertId {
|
||||
d.logger.Info("no need to update vlb default certificate")
|
||||
d.logger.Info("no need to deploy vlb default certificate")
|
||||
return nil
|
||||
}
|
||||
return d.updateListenerDefaultCertificate(ctx, *listenerInfo, cloudCertId)
|
||||
} else {
|
||||
// 指定 SNI,需部署到 SNI 证书
|
||||
if lo.Contains(listenerInfo.SniContainerIdList, cloudCertId) {
|
||||
d.logger.Info("no need to update vlb sni certificate")
|
||||
d.logger.Info("no need to deploy vlb sni certificate")
|
||||
return nil
|
||||
}
|
||||
return d.updateListenerSniCertificate(ctx, *listenerInfo, cloudCertId)
|
||||
|
||||
@ -86,10 +86,11 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
|
||||
} else {
|
||||
faasCustomDomain = getCustomDomainResp.ReturnObj
|
||||
|
||||
// 已部署过此域名,跳过
|
||||
// 已部署过,直接返回
|
||||
if faasCustomDomain.CertConfig != nil &&
|
||||
faasCustomDomain.CertConfig.Certificate == certPEM &&
|
||||
faasCustomDomain.CertConfig.PrivateKey == privkeyPEM {
|
||||
d.logger.Info("no need to deploy faas custom domain certificate")
|
||||
return &DeployResult{}, nil
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,6 +138,12 @@ func (d *Deployer) deployToHost(ctx context.Context, certPEM, privkeyPEM string)
|
||||
d.logger.Info("ssl certificate uploaded", slog.Any("result", upres))
|
||||
}
|
||||
|
||||
// 获取全部可部署的主机列表
|
||||
hostsByType, err := d.getAllHosts(ctx, d.config.HostType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 获取待部署的主机列表
|
||||
var hostIds []int64
|
||||
switch d.config.HostMatchPattern {
|
||||
@ -152,11 +158,7 @@ func (d *Deployer) deployToHost(ctx context.Context, certPEM, privkeyPEM string)
|
||||
|
||||
case HOST_MATCH_PATTERN_CERTSAN:
|
||||
{
|
||||
hostCandidates, err := d.getAllHosts(ctx, d.config.HostType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
hostCandidates := hostsByType
|
||||
hostIds = lo.Map(
|
||||
lo.Filter(hostCandidates, func(hostItem *npmsdk.Host, _ int) bool {
|
||||
return len(hostItem.DomainNames) > 0 &&
|
||||
@ -171,18 +173,6 @@ func (d *Deployer) deployToHost(ctx context.Context, certPEM, privkeyPEM string)
|
||||
if len(hostIds) == 0 {
|
||||
return fmt.Errorf("could not find any hosts matched by certificate")
|
||||
}
|
||||
|
||||
// 跳过已部署过的主机
|
||||
hostIds = lo.Filter(hostIds, func(hostId int64, _ int) bool {
|
||||
hostInfo, _ := lo.Find(hostCandidates, func(hostItem *npmsdk.Host) bool {
|
||||
return hostId == hostItem.Id
|
||||
})
|
||||
if hostInfo != nil {
|
||||
return strconv.FormatInt(hostInfo.CertificateId, 10) != upres.CertId
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
default:
|
||||
@ -194,9 +184,21 @@ func (d *Deployer) deployToHost(ctx context.Context, certPEM, privkeyPEM string)
|
||||
d.logger.Info("no hosts to deploy")
|
||||
} else {
|
||||
d.logger.Info("found hosts to deploy", slog.Any("hostIds", hostIds))
|
||||
var errs []error
|
||||
|
||||
// 跳过已部署过的主机
|
||||
certId, _ := strconv.ParseInt(upres.CertId, 10, 64)
|
||||
hostIds = lo.Filter(hostIds, func(hostId int64, _ int) bool {
|
||||
hostInfo, _ := lo.Find(hostsByType, func(hostItem *npmsdk.Host) bool {
|
||||
return hostId == hostItem.Id
|
||||
})
|
||||
if hostInfo != nil {
|
||||
return hostInfo.CertificateId != certId
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
var errs []error
|
||||
for i, hostId := range hostIds {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
||||
@ -264,7 +264,7 @@ func (d *Deployer) updateDomainCertificate(ctx context.Context, domain string, c
|
||||
domainConfig.Https.CertInfo != nil &&
|
||||
domainConfig.Https.CertInfo.CertId != nil &&
|
||||
*domainConfig.Https.CertInfo.CertId == cloudCertId {
|
||||
// 已部署过此域名,跳过
|
||||
// 已部署过,直接返回
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -105,7 +105,7 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
|
||||
|
||||
// 避免多次部署,否则会报错 https://github.com/certimate-go/certimate/issues/897#issuecomment-3182904098
|
||||
if bind, _ := d.checkIsBind(ctx, upres.CertId); bind {
|
||||
d.logger.Info("no need to update cos custom domain certificate")
|
||||
d.logger.Info("no need to deploy cos custom domain certificate")
|
||||
return &DeployResult{}, nil
|
||||
}
|
||||
|
||||
|
||||
@ -261,7 +261,7 @@ func (d *Deployer) updateDomainCertificate(ctx context.Context, domain string, c
|
||||
|
||||
domainConfig := describeDomainsConfigResp.Response.Domains[0]
|
||||
if domainConfig.Https != nil && domainConfig.Https.CertInfo != nil && domainConfig.Https.CertInfo.CertId != nil && *domainConfig.Https.CertInfo.CertId == cloudCertId {
|
||||
// 已部署过此域名,跳过
|
||||
// 已部署过,直接返回
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -109,7 +109,7 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
|
||||
d.logger.Info("ssl certificate uploaded", slog.Any("result", upres))
|
||||
}
|
||||
|
||||
// 获取全部可部署的域名信息
|
||||
// 获取全部可部署的域名列表
|
||||
domainsInZone, err := d.getAllDomainsInZone(ctx, d.config.ZoneId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -166,28 +166,28 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
|
||||
return nil, fmt.Errorf("unsupported domain match pattern: '%s'", d.config.DomainMatchPattern)
|
||||
}
|
||||
|
||||
// 跳过已部署过的域名
|
||||
domains = lo.Filter(domains, func(domain string, _ int) bool {
|
||||
var deployed bool
|
||||
|
||||
domainInfo, _ := lo.Find(domainsInZone, func(domainInfo *tceo.AccelerationDomain) bool {
|
||||
return domain == lo.FromPtr(domainInfo.DomainName)
|
||||
})
|
||||
if domainInfo != nil && domainInfo.Certificate != nil {
|
||||
deployed = lo.SomeBy(domainInfo.Certificate.List, func(certInfo *tceo.CertificateInfo) bool {
|
||||
return upres.CertId == lo.FromPtr(certInfo.CertId)
|
||||
})
|
||||
}
|
||||
|
||||
return !deployed
|
||||
})
|
||||
|
||||
// 批量更新域名证书
|
||||
if len(domains) == 0 {
|
||||
d.logger.Info("no edgeone domains to deploy")
|
||||
} else {
|
||||
d.logger.Info("found edgeone domains to deploy", slog.Any("domains", domains))
|
||||
|
||||
// 跳过已部署过的域名
|
||||
domains = lo.Filter(domains, func(domain string, _ int) bool {
|
||||
var deployed bool
|
||||
|
||||
domainInfo, _ := lo.Find(domainsInZone, func(domainInfo *tceo.AccelerationDomain) bool {
|
||||
return domain == lo.FromPtr(domainInfo.DomainName)
|
||||
})
|
||||
if domainInfo != nil && domainInfo.Certificate != nil {
|
||||
deployed = lo.SomeBy(domainInfo.Certificate.List, func(certInfo *tceo.CertificateInfo) bool {
|
||||
return upres.CertId == lo.FromPtr(certInfo.CertId)
|
||||
})
|
||||
}
|
||||
|
||||
return !deployed
|
||||
})
|
||||
|
||||
// 配置域名证书
|
||||
// REF: https://cloud.tencent.com/document/api/1552/80764
|
||||
modifyHostsCertificateReqs := make([]*tceo.ModifyHostsCertificateRequest, 0)
|
||||
|
||||
@ -223,14 +223,14 @@ func (d *Deployer) updateListenerCertificate(ctx context.Context, cloudLoadbalan
|
||||
if d.config.Domain == "" {
|
||||
// 未指定 SNI,只需部署到监听器
|
||||
if lo.SomeBy(listenerInfo.Certificates, func(item ulb.Certificate) bool { return item.SSLId == cloudCertId && item.IsDefault }) {
|
||||
d.logger.Info("no need to update alb listener default certificate")
|
||||
d.logger.Info("no need to deploy alb listener default certificate")
|
||||
return nil
|
||||
}
|
||||
return d.updateListenerDefaultCertificate(ctx, cloudLoadbalancerId, cloudListenerId, cloudCertId)
|
||||
} else {
|
||||
// 指定 SNI,需部署到扩展域名
|
||||
if lo.SomeBy(listenerInfo.Certificates, func(item ulb.Certificate) bool { return item.SSLId == cloudCertId && !item.IsDefault }) {
|
||||
d.logger.Info("no need to add alb listener sni certificate")
|
||||
d.logger.Info("no need to deploy alb listener sni certificate")
|
||||
return nil
|
||||
}
|
||||
return d.updateListenerSniCertificate(ctx, cloudLoadbalancerId, listenerInfo, cloudCertId)
|
||||
|
||||
@ -222,7 +222,7 @@ func (d *Deployer) updateVServerCertificate(ctx context.Context, cloudLoadbalanc
|
||||
return fmt.Errorf("could not find uclb vserver '%s'", cloudVServerId)
|
||||
}
|
||||
|
||||
// 跳过已部署过的 VServer
|
||||
// 已部署过,直接返回
|
||||
vserverInfo := describeVServerResp.DataSet[0]
|
||||
if lo.SomeBy(vserverInfo.SSLSet, func(item ulb.ULBSSLSet) bool { return item.SSLId == cloudCertId }) {
|
||||
return nil
|
||||
|
||||
@ -223,7 +223,7 @@ func (d *Deployer) updateListenerCertificate(ctx context.Context, cloudListenerI
|
||||
if d.config.Domain == "" {
|
||||
// 未指定 SNI,只需部署到监听器
|
||||
if ve.StringValue(describeListenerAttributesResp.CertificateId) == cloudCertId {
|
||||
d.logger.Info("no need to update alb listener default certificate")
|
||||
d.logger.Info("no need to deploy alb listener default certificate")
|
||||
return nil
|
||||
}
|
||||
return d.updateListenerDefaultCertificate(ctx, *describeListenerAttributesResp, cloudCertId)
|
||||
|
||||
@ -2,7 +2,6 @@ package matrix
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
|
||||
@ -34,7 +33,7 @@ var _ notifier.Provider = (*Notifier)(nil)
|
||||
|
||||
func NewNotifier(config *NotifierConfig) (*Notifier, error) {
|
||||
if config == nil {
|
||||
return nil, errors.New("the configuration of the notifier provider is nil")
|
||||
return nil, fmt.Errorf("the configuration of the notifier provider is nil")
|
||||
}
|
||||
|
||||
return &Notifier{
|
||||
@ -53,7 +52,7 @@ func (n *Notifier) SetLogger(logger *slog.Logger) {
|
||||
|
||||
func (n *Notifier) Notify(ctx context.Context, subject string, message string) (*notifier.NotifyResult, error) {
|
||||
if n.config.RoomId == "" {
|
||||
return nil, errors.New("matrix: config `roomId` is required")
|
||||
return nil, fmt.Errorf("matrix: config `roomId` is required")
|
||||
}
|
||||
|
||||
client, err := matrixsdk.NewClient(n.config.ServerUrl,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user