refactor: replace Append* to Log* in DeployerLogger

This commit is contained in:
Fu Diwei 2024-11-21 10:35:45 +08:00
parent 13582d1a7b
commit 30b66adc3b
24 changed files with 110 additions and 114 deletions

View File

@ -15,7 +15,7 @@ type Logger interface {
// 入参:
// - tag标签。
// - data数据。
Appendt(tag string, data ...any)
Logt(tag string, data ...any)
// 追加一条日志记录。
// 该方法会将 `args` 以 `format` 格式化。
@ -23,13 +23,13 @@ type Logger interface {
// 入参:
// - format格式化字符串。
// - args格式化参数。
Appendf(format string, args ...any)
Logf(format string, args ...any)
// 获取所有日志记录。
GetRecords() []string
// 清空
Flush()
// 清空所有日志记录
FlushRecords()
}
// 表示默认的日志记录器类型。
@ -39,7 +39,7 @@ type DefaultLogger struct {
var _ Logger = (*DefaultLogger)(nil)
func (l *DefaultLogger) Appendt(tag string, data ...any) {
func (l *DefaultLogger) Logt(tag string, data ...any) {
l.ensureInitialized()
temp := make([]string, len(data)+1)
@ -69,7 +69,7 @@ func (l *DefaultLogger) Appendt(tag string, data ...any) {
l.records = append(l.records, strings.Join(temp, ": "))
}
func (l *DefaultLogger) Appendf(format string, args ...any) {
func (l *DefaultLogger) Logf(format string, args ...any) {
l.ensureInitialized()
l.records = append(l.records, fmt.Sprintf(format, args...))
@ -83,7 +83,7 @@ func (l *DefaultLogger) GetRecords() []string {
return temp
}
func (l *DefaultLogger) Flush() {
func (l *DefaultLogger) FlushRecords() {
l.records = make([]string, 0)
}
@ -105,12 +105,12 @@ type NilLogger struct{}
var _ Logger = (*NilLogger)(nil)
func (l *NilLogger) Appendt(string, ...any) {}
func (l *NilLogger) Appendf(string, ...any) {}
func (l *NilLogger) Logt(string, ...any) {}
func (l *NilLogger) Logf(string, ...any) {}
func (l *NilLogger) GetRecords() []string {
return make([]string, 0)
}
func (l *NilLogger) Flush() {}
func (l *NilLogger) FlushRecords() {}
func NewNilLogger() *NilLogger {
return &NilLogger{}

View File

@ -15,19 +15,19 @@ func TestLogger(t *testing.T) {
t.Run("Logger_Appendt", func(t *testing.T) {
logger := deployer.NewDefaultLogger()
logger.Appendt("test")
logger.Appendt("test_nil", nil)
logger.Appendt("test_int", 1024)
logger.Appendt("test_string", "certimate")
logger.Appendt("test_map", map[string]interface{}{"key": "value"})
logger.Appendt("test_struct", struct{ Name string }{Name: "certimate"})
logger.Appendt("test_slice", []string{"certimate"})
logger.Logt("test")
logger.Logt("test_nil", nil)
logger.Logt("test_int", 1024)
logger.Logt("test_string", "certimate")
logger.Logt("test_map", map[string]interface{}{"key": "value"})
logger.Logt("test_struct", struct{ Name string }{Name: "certimate"})
logger.Logt("test_slice", []string{"certimate"})
t.Log(logger.GetRecords())
if len(logger.GetRecords()) != 7 {
t.Errorf("expected 7 records, got %d", len(logger.GetRecords()))
}
logger.Flush()
logger.FlushRecords()
if len(logger.GetRecords()) != 0 {
t.Errorf("expected 0 records, got %d", len(logger.GetRecords()))
}
@ -36,19 +36,19 @@ func TestLogger(t *testing.T) {
t.Run("Logger_Appendf", func(t *testing.T) {
logger := deployer.NewDefaultLogger()
logger.Appendf("test")
logger.Appendf("test_nil: %v", nil)
logger.Appendf("test_int: %v", 1024)
logger.Appendf("test_string: %v", "certimate")
logger.Appendf("test_map: %v", map[string]interface{}{"key": "value"})
logger.Appendf("test_struct: %v", struct{ Name string }{Name: "certimate"})
logger.Appendf("test_slice: %v", []string{"certimate"})
logger.Logf("test")
logger.Logf("test_nil: %v", nil)
logger.Logf("test_int: %v", 1024)
logger.Logf("test_string: %v", "certimate")
logger.Logf("test_map: %v", map[string]interface{}{"key": "value"})
logger.Logf("test_struct: %v", struct{ Name string }{Name: "certimate"})
logger.Logf("test_slice: %v", []string{"certimate"})
t.Log(logger.GetRecords())
if len(logger.GetRecords()) != 7 {
t.Errorf("expected 7 records, got %d", len(logger.GetRecords()))
}
logger.Flush()
logger.FlushRecords()
if len(logger.GetRecords()) != 0 {
t.Errorf("expected 0 records, got %d", len(logger.GetRecords()))
}

View File

@ -95,7 +95,7 @@ func (d *AliyunALBDeployer) Deploy(ctx context.Context, certPem string, privkeyP
return nil, xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded", upres)
d.logger.Logt("certificate file uploaded", upres)
// 根据部署资源类型决定部署方式
switch d.config.ResourceType {
@ -133,7 +133,7 @@ func (d *AliyunALBDeployer) deployToLoadbalancer(ctx context.Context, cloudCertI
return xerrors.Wrap(err, "failed to execute sdk request 'alb.GetLoadBalancerAttribute'")
}
d.logger.Appendt("已查询到 ALB 负载均衡实例", getLoadBalancerAttributeResp)
d.logger.Logt("已查询到 ALB 负载均衡实例", getLoadBalancerAttributeResp)
// 查询 HTTPS 监听列表
// REF: https://help.aliyun.com/zh/slb/application-load-balancer/developer-reference/api-alb-2020-06-16-listlisteners
@ -158,7 +158,7 @@ func (d *AliyunALBDeployer) deployToLoadbalancer(ctx context.Context, cloudCertI
}
}
if listListenersResp.Body.NextToken == nil {
if len(listListenersResp.Body.Listeners) == 0 || listListenersResp.Body.NextToken == nil {
break
} else {
listListenersToken = listListenersResp.Body.NextToken
@ -166,7 +166,7 @@ func (d *AliyunALBDeployer) deployToLoadbalancer(ctx context.Context, cloudCertI
}
}
d.logger.Appendt("已查询到 ALB 负载均衡实例下的全部 HTTPS 监听", listenerIds)
d.logger.Logt("已查询到 ALB 负载均衡实例下的全部 HTTPS 监听", listenerIds)
// 查询 QUIC 监听列表
// REF: https://help.aliyun.com/zh/slb/application-load-balancer/developer-reference/api-alb-2020-06-16-listlisteners
@ -190,7 +190,7 @@ func (d *AliyunALBDeployer) deployToLoadbalancer(ctx context.Context, cloudCertI
}
}
if listListenersResp.Body.NextToken == nil {
if len(listListenersResp.Body.Listeners) == 0 || listListenersResp.Body.NextToken == nil {
break
} else {
listListenersToken = listListenersResp.Body.NextToken
@ -198,7 +198,7 @@ func (d *AliyunALBDeployer) deployToLoadbalancer(ctx context.Context, cloudCertI
}
}
d.logger.Appendt("已查询到 ALB 负载均衡实例下的全部 QUIC 监听", listenerIds)
d.logger.Logt("已查询到 ALB 负载均衡实例下的全部 QUIC 监听", listenerIds)
// 批量更新监听证书
var errs []error
@ -238,7 +238,7 @@ func (d *AliyunALBDeployer) updateListenerCertificate(ctx context.Context, cloud
return xerrors.Wrap(err, "failed to execute sdk request 'alb.GetListenerAttribute'")
}
d.logger.Appendt("已查询到 ALB 监听配置", getListenerAttributeResp)
d.logger.Logt("已查询到 ALB 监听配置", getListenerAttributeResp)
// 修改监听的属性
// REF: https://help.aliyun.com/zh/slb/application-load-balancer/developer-reference/api-alb-2020-06-16-updatelistenerattribute
@ -253,7 +253,7 @@ func (d *AliyunALBDeployer) updateListenerCertificate(ctx context.Context, cloud
return xerrors.Wrap(err, "failed to execute sdk request 'alb.UpdateListenerAttribute'")
}
d.logger.Appendt("已更新 ALB 监听配置", updateListenerAttributeResp)
d.logger.Logt("已更新 ALB 监听配置", updateListenerAttributeResp)
// TODO: #347

View File

@ -72,7 +72,7 @@ func (d *AliyunCDNDeployer) Deploy(ctx context.Context, certPem string, privkeyP
return nil, xerrors.Wrap(err, "failed to execute sdk request 'cdn.SetCdnDomainSSLCertificate'")
}
d.logger.Appendt("已设置 CDN 域名证书", setCdnDomainSSLCertificateResp)
d.logger.Logt("已设置 CDN 域名证书", setCdnDomainSSLCertificateResp)
return &deployer.DeployResult{}, nil
}

View File

@ -83,7 +83,7 @@ func (d *AliyunCLBDeployer) Deploy(ctx context.Context, certPem string, privkeyP
return nil, xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded", upres)
d.logger.Logt("certificate file uploaded", upres)
// 根据部署资源类型决定部署方式
switch d.config.ResourceType {
@ -122,7 +122,7 @@ func (d *AliyunCLBDeployer) deployToLoadbalancer(ctx context.Context, cloudCertI
return xerrors.Wrap(err, "failed to execute sdk request 'slb.DescribeLoadBalancerAttribute'")
}
d.logger.Appendt("已查询到 CLB 负载均衡实例", describeLoadBalancerAttributeResp)
d.logger.Logt("已查询到 CLB 负载均衡实例", describeLoadBalancerAttributeResp)
// 查询 HTTPS 监听列表
// REF: https://help.aliyun.com/zh/slb/classic-load-balancer/developer-reference/api-slb-2014-05-15-describeloadbalancerlisteners
@ -148,7 +148,7 @@ func (d *AliyunCLBDeployer) deployToLoadbalancer(ctx context.Context, cloudCertI
}
}
if describeLoadBalancerListenersResp.Body.NextToken == nil {
if len(describeLoadBalancerListenersResp.Body.Listeners) == 0 || describeLoadBalancerListenersResp.Body.NextToken == nil {
break
} else {
listListenersToken = describeLoadBalancerListenersResp.Body.NextToken
@ -156,7 +156,7 @@ func (d *AliyunCLBDeployer) deployToLoadbalancer(ctx context.Context, cloudCertI
}
}
d.logger.Appendt("已查询到 CLB 负载均衡实例下的全部 HTTPS 监听", listenerPorts)
d.logger.Logt("已查询到 CLB 负载均衡实例下的全部 HTTPS 监听", listenerPorts)
// 批量更新监听证书
var errs []error
@ -200,7 +200,7 @@ func (d *AliyunCLBDeployer) updateListenerCertificate(ctx context.Context, cloud
return xerrors.Wrap(err, "failed to execute sdk request 'slb.DescribeLoadBalancerHTTPSListenerAttribute'")
}
d.logger.Appendt("已查询到 CLB HTTPS 监听配置", describeLoadBalancerHTTPSListenerAttributeResp)
d.logger.Logt("已查询到 CLB HTTPS 监听配置", describeLoadBalancerHTTPSListenerAttributeResp)
// 查询扩展域名
// REF: https://help.aliyun.com/zh/slb/classic-load-balancer/developer-reference/api-slb-2014-05-15-describedomainextensions
@ -214,7 +214,7 @@ func (d *AliyunCLBDeployer) updateListenerCertificate(ctx context.Context, cloud
return xerrors.Wrap(err, "failed to execute sdk request 'slb.DescribeDomainExtensions'")
}
d.logger.Appendt("已查询到 CLB 扩展域名", describeDomainExtensionsResp)
d.logger.Logt("已查询到 CLB 扩展域名", describeDomainExtensionsResp)
// 遍历修改扩展域名
// REF: https://help.aliyun.com/zh/slb/classic-load-balancer/developer-reference/api-slb-2014-05-15-setdomainextensionattribute
@ -253,7 +253,7 @@ func (d *AliyunCLBDeployer) updateListenerCertificate(ctx context.Context, cloud
return xerrors.Wrap(err, "failed to execute sdk request 'slb.SetLoadBalancerHTTPSListenerAttribute'")
}
d.logger.Appendt("已更新 CLB HTTPS 监听配置", setLoadBalancerHTTPSListenerAttributeResp)
d.logger.Logt("已更新 CLB HTTPS 监听配置", setLoadBalancerHTTPSListenerAttributeResp)
return nil
}

View File

@ -76,7 +76,7 @@ func (d *AliyunDCDNDeployer) Deploy(ctx context.Context, certPem string, privkey
return nil, xerrors.Wrap(err, "failed to execute sdk request 'dcdn.SetDcdnDomainSSLCertificate'")
}
d.logger.Appendt("已配置 DCDN 域名证书", setDcdnDomainSSLCertificateResp)
d.logger.Logt("已配置 DCDN 域名证书", setDcdnDomainSSLCertificateResp)
return &deployer.DeployResult{}, nil
}

View File

@ -95,7 +95,7 @@ func (d *AliyunNLBDeployer) Deploy(ctx context.Context, certPem string, privkeyP
return nil, xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded", upres)
d.logger.Logt("certificate file uploaded", upres)
// 根据部署资源类型决定部署方式
switch d.config.ResourceType {
@ -133,7 +133,7 @@ func (d *AliyunNLBDeployer) deployToLoadbalancer(ctx context.Context, cloudCertI
return xerrors.Wrap(err, "failed to execute sdk request 'nlb.GetLoadBalancerAttribute'")
}
d.logger.Appendt("已查询到 NLB 负载均衡实例", getLoadBalancerAttributeResp)
d.logger.Logt("已查询到 NLB 负载均衡实例", getLoadBalancerAttributeResp)
// 查询 TCPSSL 监听列表
// REF: https://help.aliyun.com/zh/slb/network-load-balancer/developer-reference/api-nlb-2022-04-30-listlisteners
@ -158,7 +158,7 @@ func (d *AliyunNLBDeployer) deployToLoadbalancer(ctx context.Context, cloudCertI
}
}
if listListenersResp.Body.NextToken == nil {
if len(listListenersResp.Body.Listeners) == 0 || listListenersResp.Body.NextToken == nil {
break
} else {
listListenersToken = listListenersResp.Body.NextToken
@ -166,7 +166,7 @@ func (d *AliyunNLBDeployer) deployToLoadbalancer(ctx context.Context, cloudCertI
}
}
d.logger.Appendt("已查询到 NLB 负载均衡实例下的全部 TCPSSL 监听", listenerIds)
d.logger.Logt("已查询到 NLB 负载均衡实例下的全部 TCPSSL 监听", listenerIds)
// 批量更新监听证书
var errs []error
@ -206,7 +206,7 @@ func (d *AliyunNLBDeployer) updateListenerCertificate(ctx context.Context, cloud
return xerrors.Wrap(err, "failed to execute sdk request 'nlb.GetListenerAttribute'")
}
d.logger.Appendt("已查询到 NLB 监听配置", getListenerAttributeResp)
d.logger.Logt("已查询到 NLB 监听配置", getListenerAttributeResp)
// 修改监听的属性
// REF: https://help.aliyun.com/zh/slb/network-load-balancer/developer-reference/api-nlb-2022-04-30-updatelistenerattribute
@ -219,7 +219,7 @@ func (d *AliyunNLBDeployer) updateListenerCertificate(ctx context.Context, cloud
return xerrors.Wrap(err, "failed to execute sdk request 'nlb.UpdateListenerAttribute'")
}
d.logger.Appendt("已更新 NLB 监听配置", updateListenerAttributeResp)
d.logger.Logt("已更新 NLB 监听配置", updateListenerAttributeResp)
return nil
}

View File

@ -71,7 +71,7 @@ func (d *BaiduCloudCDNDeployer) Deploy(ctx context.Context, certPem string, priv
return nil, xerrors.Wrap(err, "failed to execute sdk request 'cdn.PutCert'")
}
d.logger.Appendt("已修改域名证书", putCertResp)
d.logger.Logt("已修改域名证书", putCertResp)
return &deployer.DeployResult{}, nil
}

View File

@ -72,7 +72,7 @@ func (d *BytePlusCDNDeployer) Deploy(ctx context.Context, certPem string, privke
return nil, xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded", upres)
d.logger.Logt("certificate file uploaded", upres)
domains := make([]string, 0)
if strings.HasPrefix(d.config.Domain, "*.") {
@ -123,7 +123,7 @@ func (d *BytePlusCDNDeployer) Deploy(ctx context.Context, certPem string, privke
if err != nil {
errs = append(errs, err)
} else {
d.logger.Appendt(fmt.Sprintf("已关联证书到域名 %s", domain), batchDeployCertResp)
d.logger.Logt(fmt.Sprintf("已关联证书到域名 %s", domain), batchDeployCertResp)
}
}

View File

@ -69,7 +69,7 @@ func (d *DogeCloudCDNDeployer) Deploy(ctx context.Context, certPem string, privk
return nil, xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded", upres)
d.logger.Logt("certificate file uploaded", upres)
// 绑定证书
// REF: https://docs.dogecloud.com/cdn/api-cert-bind
@ -79,7 +79,7 @@ func (d *DogeCloudCDNDeployer) Deploy(ctx context.Context, certPem string, privk
return nil, xerrors.Wrap(err, "failed to execute sdk request 'cdn.BindCdnCert'")
}
d.logger.Appendt("已绑定证书", bindCdnCertResp)
d.logger.Logt("已绑定证书", bindCdnCertResp)
return &deployer.DeployResult{}, nil
}

View File

@ -82,7 +82,7 @@ func (d *HuaweiCloudCDNDeployer) Deploy(ctx context.Context, certPem string, pri
return nil, xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded", upres)
d.logger.Logt("certificate file uploaded", upres)
// 查询加速域名配置
// REF: https://support.huaweicloud.com/api-cdn/ShowDomainFullConfig.html
@ -94,7 +94,7 @@ func (d *HuaweiCloudCDNDeployer) Deploy(ctx context.Context, certPem string, pri
return nil, xerrors.Wrap(err, "failed to execute sdk request 'cdn.ShowDomainFullConfig'")
}
d.logger.Appendt("已查询到加速域名配置", showDomainFullConfigResp)
d.logger.Logt("已查询到加速域名配置", showDomainFullConfigResp)
// 更新加速域名配置
// REF: https://support.huaweicloud.com/api-cdn/UpdateDomainMultiCertificates.html
@ -116,7 +116,7 @@ func (d *HuaweiCloudCDNDeployer) Deploy(ctx context.Context, certPem string, pri
return nil, xerrors.Wrap(err, "failed to execute sdk request 'cdn.UploadDomainMultiCertificatesEx'")
}
d.logger.Appendt("已更新加速域名配置", updateDomainMultiCertificatesResp)
d.logger.Logt("已更新加速域名配置", updateDomainMultiCertificatesResp)
return &deployer.DeployResult{}, nil
}

View File

@ -93,7 +93,7 @@ func (d *HuaweiCloudELBDeployer) Deploy(ctx context.Context, certPem string, pri
return nil, xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded", upres)
d.logger.Logt("certificate file uploaded", upres)
// 根据部署资源类型决定部署方式
switch d.config.ResourceType {
@ -140,7 +140,7 @@ func (d *HuaweiCloudELBDeployer) deployToCertificate(ctx context.Context, certPe
return xerrors.Wrap(err, "failed to execute sdk request 'elb.UpdateCertificate'")
}
d.logger.Appendt("已更新 ELB 证书", updateCertificateResp)
d.logger.Logt("已更新 ELB 证书", updateCertificateResp)
return nil
}
@ -162,7 +162,7 @@ func (d *HuaweiCloudELBDeployer) deployToLoadbalancer(ctx context.Context, certP
return xerrors.Wrap(err, "failed to execute sdk request 'elb.ShowLoadBalancer'")
}
d.logger.Appendt("已查询到 ELB 负载均衡器", showLoadBalancerResp)
d.logger.Logt("已查询到 ELB 负载均衡器", showLoadBalancerResp)
// 查询监听器列表
// REF: https://support.huaweicloud.com/api-elb/ListListeners.html
@ -193,7 +193,7 @@ func (d *HuaweiCloudELBDeployer) deployToLoadbalancer(ctx context.Context, certP
}
}
d.logger.Appendt("已查询到 ELB 负载均衡器下的监听器", listenerIds)
d.logger.Logt("已查询到 ELB 负载均衡器下的监听器", listenerIds)
// 上传证书到 SCM
upres, err := d.sslUploader.Upload(ctx, certPem, privkeyPem)
@ -201,7 +201,7 @@ func (d *HuaweiCloudELBDeployer) deployToLoadbalancer(ctx context.Context, certP
return xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded", upres)
d.logger.Logt("certificate file uploaded", upres)
// 批量更新监听器证书
var errs []error
@ -228,7 +228,7 @@ func (d *HuaweiCloudELBDeployer) deployToListener(ctx context.Context, certPem s
return xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded", upres)
d.logger.Logt("certificate file uploaded", upres)
// 更新监听器证书
if err := d.modifyListenerCertificate(ctx, d.config.ListenerId, upres.CertId); err != nil {
@ -249,7 +249,7 @@ func (d *HuaweiCloudELBDeployer) modifyListenerCertificate(ctx context.Context,
return xerrors.Wrap(err, "failed to execute sdk request 'elb.ShowListener'")
}
d.logger.Appendt("已查询到 ELB 监听器", showListenerResp)
d.logger.Logt("已查询到 ELB 监听器", showListenerResp)
// 更新监听器
// REF: https://support.huaweicloud.com/api-elb/UpdateListener.html
@ -312,7 +312,7 @@ func (d *HuaweiCloudELBDeployer) modifyListenerCertificate(ctx context.Context,
return xerrors.Wrap(err, "failed to execute sdk request 'elb.UpdateListener'")
}
d.logger.Appendt("已更新 ELB 监听器", updateListenerResp)
d.logger.Logt("已更新 ELB 监听器", updateListenerResp)
return nil
}
@ -322,11 +322,7 @@ func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcElb.ElbCli
region = "cn-north-4" // ELB 服务默认区域:华北四北京
}
projectId, err := (&HuaweiCloudELBDeployer{}).getSdkProjectId(
accessKeyId,
secretAccessKey,
region,
)
projectId, err := getSdkProjectId(accessKeyId, secretAccessKey, region)
if err != nil {
return nil, err
}

View File

@ -111,7 +111,7 @@ func (d *K8sSecretDeployer) Deploy(ctx context.Context, certPem string, privkeyP
if err != nil {
return nil, xerrors.Wrap(err, "failed to create k8s secret")
} else {
d.logger.Appendf("k8s secret created", secretPayload)
d.logger.Logf("k8s secret created", secretPayload)
return &deployer.DeployResult{}, nil
}
}
@ -130,7 +130,7 @@ func (d *K8sSecretDeployer) Deploy(ctx context.Context, certPem string, privkeyP
return nil, xerrors.Wrap(err, "failed to update k8s secret")
}
d.logger.Appendf("k8s secret updated", secretPayload)
d.logger.Logf("k8s secret updated", secretPayload)
return &deployer.DeployResult{}, nil
}

View File

@ -77,7 +77,7 @@ func (d *LocalDeployer) Deploy(ctx context.Context, certPem string, privkeyPem s
return nil, xerrors.Wrapf(err, "failed to run pre-command, stdout: %s, stderr: %s", stdout, stderr)
}
d.logger.Appendt("pre-command executed", stdout)
d.logger.Logt("pre-command executed", stdout)
}
// 写入证书和私钥文件
@ -87,13 +87,13 @@ func (d *LocalDeployer) Deploy(ctx context.Context, certPem string, privkeyPem s
return nil, xerrors.Wrap(err, "failed to save certificate file")
}
d.logger.Appendt("certificate file saved")
d.logger.Logt("certificate file saved")
if err := fs.WriteFileString(d.config.OutputKeyPath, privkeyPem); err != nil {
return nil, xerrors.Wrap(err, "failed to save private key file")
}
d.logger.Appendt("private key file saved")
d.logger.Logt("private key file saved")
case OUTPUT_FORMAT_PFX:
pfxData, err := x509.TransformCertificateFromPEMToPFX(certPem, privkeyPem, d.config.PfxPassword)
@ -101,13 +101,13 @@ func (d *LocalDeployer) Deploy(ctx context.Context, certPem string, privkeyPem s
return nil, xerrors.Wrap(err, "failed to transform certificate to PFX")
}
d.logger.Appendt("certificate transformed to PFX")
d.logger.Logt("certificate transformed to PFX")
if err := fs.WriteFile(d.config.OutputCertPath, pfxData); err != nil {
return nil, xerrors.Wrap(err, "failed to save certificate file")
}
d.logger.Appendt("certificate file saved")
d.logger.Logt("certificate file saved")
case OUTPUT_FORMAT_JKS:
jksData, err := x509.TransformCertificateFromPEMToJKS(certPem, privkeyPem, d.config.JksAlias, d.config.JksKeypass, d.config.JksStorepass)
@ -115,13 +115,13 @@ func (d *LocalDeployer) Deploy(ctx context.Context, certPem string, privkeyPem s
return nil, xerrors.Wrap(err, "failed to transform certificate to JKS")
}
d.logger.Appendt("certificate transformed to JKS")
d.logger.Logt("certificate transformed to JKS")
if err := fs.WriteFile(d.config.OutputCertPath, jksData); err != nil {
return nil, xerrors.Wrap(err, "failed to save certificate file")
}
d.logger.Appendt("certificate file uploaded")
d.logger.Logt("certificate file uploaded")
default:
return nil, fmt.Errorf("unsupported output format: %s", d.config.OutputFormat)
@ -134,7 +134,7 @@ func (d *LocalDeployer) Deploy(ctx context.Context, certPem string, privkeyPem s
return nil, xerrors.Wrapf(err, "failed to run command, stdout: %s, stderr: %s", stdout, stderr)
}
d.logger.Appendt("post-command executed", stdout)
d.logger.Logt("post-command executed", stdout)
}
return &deployer.DeployResult{}, nil

View File

@ -70,7 +70,7 @@ func (d *QiniuCDNDeployer) Deploy(ctx context.Context, certPem string, privkeyPe
return nil, xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded", upres)
d.logger.Logt("certificate file uploaded", upres)
// "*.example.com" → ".example.com",适配七牛云 CDN 要求的泛域名格式
domain := strings.TrimPrefix(d.config.Domain, "*")
@ -82,7 +82,7 @@ func (d *QiniuCDNDeployer) Deploy(ctx context.Context, certPem string, privkeyPe
return nil, xerrors.Wrap(err, "failed to execute sdk request 'cdn.GetDomainInfo'")
}
d.logger.Appendt("已获取域名信息", getDomainInfoResp)
d.logger.Logt("已获取域名信息", getDomainInfoResp)
// 判断域名是否已启用 HTTPS。如果已启用修改域名证书否则启用 HTTPS
// REF: https://developer.qiniu.com/fusion/4246/the-domain-name
@ -92,14 +92,14 @@ func (d *QiniuCDNDeployer) Deploy(ctx context.Context, certPem string, privkeyPe
return nil, xerrors.Wrap(err, "failed to execute sdk request 'cdn.ModifyDomainHttpsConf'")
}
d.logger.Appendt("已修改域名证书", modifyDomainHttpsConfResp)
d.logger.Logt("已修改域名证书", modifyDomainHttpsConfResp)
} else {
enableDomainHttpsResp, err := d.sdkClient.EnableDomainHttps(domain, upres.CertId, true, true)
if err != nil {
return nil, xerrors.Wrap(err, "failed to execute sdk request 'cdn.EnableDomainHttps'")
}
d.logger.Appendt("已将域名升级为 HTTPS", enableDomainHttpsResp)
d.logger.Logt("已将域名升级为 HTTPS", enableDomainHttpsResp)
}
return &deployer.DeployResult{}, nil

View File

@ -96,7 +96,7 @@ func (d *SshDeployer) Deploy(ctx context.Context, certPem string, privkeyPem str
}
defer client.Close()
d.logger.Appendt("SSH connected")
d.logger.Logt("SSH connected")
// 执行前置命令
if d.config.PreCommand != "" {
@ -105,7 +105,7 @@ func (d *SshDeployer) Deploy(ctx context.Context, certPem string, privkeyPem str
return nil, xerrors.Wrapf(err, "failed to run pre-command: stdout: %s, stderr: %s", stdout, stderr)
}
d.logger.Appendt("SSH pre-command executed", stdout)
d.logger.Logt("SSH pre-command executed", stdout)
}
// 上传证书和私钥文件
@ -115,13 +115,13 @@ func (d *SshDeployer) Deploy(ctx context.Context, certPem string, privkeyPem str
return nil, xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded")
d.logger.Logt("certificate file uploaded")
if err := writeSftpFileString(client, d.config.OutputKeyPath, privkeyPem); err != nil {
return nil, xerrors.Wrap(err, "failed to upload private key file")
}
d.logger.Appendt("private key file uploaded")
d.logger.Logt("private key file uploaded")
case OUTPUT_FORMAT_PFX:
pfxData, err := x509.TransformCertificateFromPEMToPFX(certPem, privkeyPem, d.config.PfxPassword)
@ -129,13 +129,13 @@ func (d *SshDeployer) Deploy(ctx context.Context, certPem string, privkeyPem str
return nil, xerrors.Wrap(err, "failed to transform certificate to PFX")
}
d.logger.Appendt("certificate transformed to PFX")
d.logger.Logt("certificate transformed to PFX")
if err := writeSftpFile(client, d.config.OutputCertPath, pfxData); err != nil {
return nil, xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded")
d.logger.Logt("certificate file uploaded")
case OUTPUT_FORMAT_JKS:
jksData, err := x509.TransformCertificateFromPEMToJKS(certPem, privkeyPem, d.config.JksAlias, d.config.JksKeypass, d.config.JksStorepass)
@ -143,13 +143,13 @@ func (d *SshDeployer) Deploy(ctx context.Context, certPem string, privkeyPem str
return nil, xerrors.Wrap(err, "failed to transform certificate to JKS")
}
d.logger.Appendt("certificate transformed to JKS")
d.logger.Logt("certificate transformed to JKS")
if err := writeSftpFile(client, d.config.OutputCertPath, jksData); err != nil {
return nil, xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded")
d.logger.Logt("certificate file uploaded")
default:
return nil, fmt.Errorf("unsupported output format: %s", d.config.OutputFormat)
@ -162,7 +162,7 @@ func (d *SshDeployer) Deploy(ctx context.Context, certPem string, privkeyPem str
return nil, xerrors.Wrapf(err, "failed to run command, stdout: %s, stderr: %s", stdout, stderr)
}
d.logger.Appendt("SSH post-command executed", stdout)
d.logger.Logt("SSH post-command executed", stdout)
}
return &deployer.DeployResult{}, nil

View File

@ -81,7 +81,7 @@ func (d *TencentCloudCDNDeployer) Deploy(ctx context.Context, certPem string, pr
return nil, xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded", upres)
d.logger.Logt("certificate file uploaded", upres)
// 获取待部署的 CDN 实例
// 如果是泛域名,根据证书匹配 CDN 实例
@ -114,7 +114,7 @@ func (d *TencentCloudCDNDeployer) Deploy(ctx context.Context, certPem string, pr
}
if len(instanceIds) == 0 {
d.logger.Appendt("已部署过或没有要部署的 CDN 实例")
d.logger.Logt("已部署过或没有要部署的 CDN 实例")
} else {
// 证书部署到 CDN 实例
// REF: https://cloud.tencent.com/document/product/400/91667
@ -128,7 +128,7 @@ func (d *TencentCloudCDNDeployer) Deploy(ctx context.Context, certPem string, pr
return nil, xerrors.Wrap(err, "failed to execute sdk request 'ssl.DeployCertificateInstance'")
}
d.logger.Appendt("已部署证书到云资源实例", deployCertificateInstanceResp.Response)
d.logger.Logt("已部署证书到云资源实例", deployCertificateInstanceResp.Response)
}
return &deployer.DeployResult{}, nil

View File

@ -91,7 +91,7 @@ func (d *TencentCloudCLBDeployer) Deploy(ctx context.Context, certPem string, pr
return nil, xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded", upres)
d.logger.Logt("certificate file uploaded", upres)
// 根据部署资源类型决定部署方式
switch d.config.ResourceType {
@ -148,7 +148,7 @@ func (d *TencentCloudCLBDeployer) deployToInstanceUseSsl(ctx context.Context, cl
return xerrors.Wrap(err, "failed to execute sdk request 'ssl.DeployCertificateInstance'")
}
d.logger.Appendt("已部署证书到云资源实例", deployCertificateInstanceResp.Response)
d.logger.Logt("已部署证书到云资源实例", deployCertificateInstanceResp.Response)
return nil
}
@ -179,7 +179,7 @@ func (d *TencentCloudCLBDeployer) deployToLoadbalancer(ctx context.Context, clou
}
}
d.logger.Appendt("已查询到负载均衡器下的监听器", listenerIds)
d.logger.Logt("已查询到负载均衡器下的监听器", listenerIds)
// 批量更新监听器证书
if len(listenerIds) > 0 {
@ -241,7 +241,7 @@ func (d *TencentCloudCLBDeployer) deployToRuleDomain(ctx context.Context, cloudC
return xerrors.Wrap(err, "failed to execute sdk request 'clb.ModifyDomainAttributes'")
}
d.logger.Appendt("已修改七层监听器转发规则的域名级别属性", modifyDomainAttributesResp.Response)
d.logger.Logt("已修改七层监听器转发规则的域名级别属性", modifyDomainAttributesResp.Response)
return nil
}
@ -260,7 +260,7 @@ func (d *TencentCloudCLBDeployer) modifyListenerCertificate(ctx context.Context,
return errors.New("listener not found")
}
d.logger.Appendt("已查询到监听器属性", describeListenersResp.Response)
d.logger.Logt("已查询到监听器属性", describeListenersResp.Response)
// 修改监听器属性
// REF: https://cloud.tencent.com/document/product/214/30681
@ -279,7 +279,7 @@ func (d *TencentCloudCLBDeployer) modifyListenerCertificate(ctx context.Context,
return xerrors.Wrap(err, "failed to execute sdk request 'clb.ModifyListener'")
}
d.logger.Appendt("已修改监听器属性", modifyListenerResp.Response)
d.logger.Logt("已修改监听器属性", modifyListenerResp.Response)
return nil
}

View File

@ -85,7 +85,7 @@ func (d *TencentCloudCOSDeployer) Deploy(ctx context.Context, certPem string, pr
return nil, xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded", upres)
d.logger.Logt("certificate file uploaded", upres)
// 证书部署到 COS 实例
// REF: https://cloud.tencent.com/document/product/400/91667
@ -99,7 +99,7 @@ func (d *TencentCloudCOSDeployer) Deploy(ctx context.Context, certPem string, pr
return nil, xerrors.Wrap(err, "failed to execute sdk request 'ssl.DeployCertificateInstance'")
}
d.logger.Appendt("已部署证书到云资源实例", deployCertificateInstanceResp.Response)
d.logger.Logt("已部署证书到云资源实例", deployCertificateInstanceResp.Response)
return &deployer.DeployResult{}, nil
}

View File

@ -80,7 +80,7 @@ func (d *TencentCloudECDNDeployer) Deploy(ctx context.Context, certPem string, p
return nil, xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded", upres)
d.logger.Logt("certificate file uploaded", upres)
// 获取待部署的 CDN 实例
// 如果是泛域名,根据证书匹配 CDN 实例
@ -97,7 +97,7 @@ func (d *TencentCloudECDNDeployer) Deploy(ctx context.Context, certPem string, p
}
if len(instanceIds) == 0 {
d.logger.Appendt("已部署过或没有要部署的 ECDN 实例")
d.logger.Logt("已部署过或没有要部署的 ECDN 实例")
} else {
// 证书部署到 ECDN 实例
// REF: https://cloud.tencent.com/document/product/400/91667
@ -111,7 +111,7 @@ func (d *TencentCloudECDNDeployer) Deploy(ctx context.Context, certPem string, p
return nil, xerrors.Wrap(err, "failed to execute sdk request 'ssl.DeployCertificateInstance'")
}
d.logger.Appendt("已部署证书到云资源实例", deployCertificateInstanceResp.Response)
d.logger.Logt("已部署证书到云资源实例", deployCertificateInstanceResp.Response)
}
return &deployer.DeployResult{}, nil

View File

@ -85,7 +85,7 @@ func (d *TencentCloudTEODeployer) Deploy(ctx context.Context, certPem string, pr
return nil, xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded", upres)
d.logger.Logt("certificate file uploaded", upres)
// 配置域名证书
// REF: https://cloud.tencent.com/document/product/1552/80764
@ -99,7 +99,7 @@ func (d *TencentCloudTEODeployer) Deploy(ctx context.Context, certPem string, pr
return nil, xerrors.Wrap(err, "failed to execute sdk request 'teo.ModifyHostsCertificate'")
}
d.logger.Appendt("已配置域名证书", modifyHostsCertificateResp.Response)
d.logger.Logt("已配置域名证书", modifyHostsCertificateResp.Response)
return &deployer.DeployResult{}, nil
}

View File

@ -72,7 +72,7 @@ func (d *VolcEngineCDNDeployer) Deploy(ctx context.Context, certPem string, priv
return nil, xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded", upres)
d.logger.Logt("certificate file uploaded", upres)
domains := make([]string, 0)
if strings.HasPrefix(d.config.Domain, "*.") {
@ -123,7 +123,7 @@ func (d *VolcEngineCDNDeployer) Deploy(ctx context.Context, certPem string, priv
if err != nil {
errs = append(errs, err)
} else {
d.logger.Appendt(fmt.Sprintf("已关联证书到域名 %s", domain), batchDeployCertResp)
d.logger.Logt(fmt.Sprintf("已关联证书到域名 %s", domain), batchDeployCertResp)
}
}

View File

@ -73,7 +73,7 @@ func (d *VolcEngineLiveDeployer) Deploy(ctx context.Context, certPem string, pri
return nil, xerrors.Wrap(err, "failed to upload certificate file")
}
d.logger.Appendt("certificate file uploaded", upres)
d.logger.Logt("certificate file uploaded", upres)
domains := make([]string, 0)
if strings.HasPrefix(d.config.Domain, "*.") {
@ -133,7 +133,7 @@ func (d *VolcEngineLiveDeployer) Deploy(ctx context.Context, certPem string, pri
if err != nil {
errs = append(errs, err)
} else {
d.logger.Appendt(fmt.Sprintf("已绑定证书到域名 %s", domain), bindCertResp)
d.logger.Logt(fmt.Sprintf("已绑定证书到域名 %s", domain), bindCertResp)
}
}

View File

@ -75,7 +75,7 @@ func (d *WebhookDeployer) Deploy(ctx context.Context, certPem string, privkeyPem
return nil, xerrors.Wrap(err, "failed to send webhook request")
}
d.logger.Appendt("Webhook Response", string(resp))
d.logger.Logt("Webhook Response", string(resp))
return &deployer.DeployResult{
DeploymentData: map[string]any{