feat: adapt new logging to uploader, deployer and notifier providers
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"time"
|
||||
|
||||
aliyunOpen "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
||||
@@ -12,7 +13,6 @@ import (
|
||||
xerrors "github.com/pkg/errors"
|
||||
|
||||
"github.com/usual2970/certimate/internal/pkg/core/deployer"
|
||||
"github.com/usual2970/certimate/internal/pkg/core/logger"
|
||||
)
|
||||
|
||||
type DeployerConfig struct {
|
||||
@@ -31,7 +31,7 @@ type DeployerConfig struct {
|
||||
|
||||
type DeployerProvider struct {
|
||||
config *DeployerConfig
|
||||
logger logger.Logger
|
||||
logger *slog.Logger
|
||||
sdkClients *wSdkClients
|
||||
}
|
||||
|
||||
@@ -54,13 +54,17 @@ func NewDeployer(config *DeployerConfig) (*DeployerProvider, error) {
|
||||
|
||||
return &DeployerProvider{
|
||||
config: config,
|
||||
logger: logger.NewNilLogger(),
|
||||
logger: slog.Default(),
|
||||
sdkClients: clients,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (d *DeployerProvider) WithLogger(logger logger.Logger) *DeployerProvider {
|
||||
d.logger = logger
|
||||
func (d *DeployerProvider) WithLogger(logger *slog.Logger) deployer.Deployer {
|
||||
if logger == nil {
|
||||
d.logger = slog.Default()
|
||||
} else {
|
||||
d.logger = logger
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
@@ -87,10 +91,9 @@ func (d *DeployerProvider) deployToFC3(ctx context.Context, certPem string, priv
|
||||
// 获取自定义域名
|
||||
// REF: https://help.aliyun.com/zh/functioncompute/fc-3-0/developer-reference/api-fc-2023-03-30-getcustomdomain
|
||||
getCustomDomainResp, err := d.sdkClients.fc3.GetCustomDomain(tea.String(d.config.Domain))
|
||||
d.logger.Debug("sdk request 'fc.GetCustomDomain'", slog.Any("response", getCustomDomainResp))
|
||||
if err != nil {
|
||||
return xerrors.Wrap(err, "failed to execute sdk request 'fc.GetCustomDomain'")
|
||||
} else {
|
||||
d.logger.Logt("已获取自定义域名", getCustomDomainResp)
|
||||
}
|
||||
|
||||
// 更新自定义域名
|
||||
@@ -107,10 +110,9 @@ func (d *DeployerProvider) deployToFC3(ctx context.Context, certPem string, priv
|
||||
},
|
||||
}
|
||||
updateCustomDomainResp, err := d.sdkClients.fc3.UpdateCustomDomain(tea.String(d.config.Domain), updateCustomDomainReq)
|
||||
d.logger.Debug("sdk request 'fc.UpdateCustomDomain'", slog.Any("request", updateCustomDomainReq), slog.Any("response", updateCustomDomainResp))
|
||||
if err != nil {
|
||||
return xerrors.Wrap(err, "failed to execute sdk request 'fc.UpdateCustomDomain'")
|
||||
} else {
|
||||
d.logger.Logt("已更新自定义域名", updateCustomDomainResp)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -120,10 +122,9 @@ func (d *DeployerProvider) deployToFC2(ctx context.Context, certPem string, priv
|
||||
// 获取自定义域名
|
||||
// REF: https://help.aliyun.com/zh/functioncompute/fc-2-0/developer-reference/api-fc-open-2021-04-06-getcustomdomain
|
||||
getCustomDomainResp, err := d.sdkClients.fc2.GetCustomDomain(tea.String(d.config.Domain))
|
||||
d.logger.Debug("sdk request 'fc.GetCustomDomain'", slog.Any("response", getCustomDomainResp))
|
||||
if err != nil {
|
||||
return xerrors.Wrap(err, "failed to execute sdk request 'fc.GetCustomDomain'")
|
||||
} else {
|
||||
d.logger.Logt("已获取自定义域名", getCustomDomainResp)
|
||||
}
|
||||
|
||||
// 更新自定义域名
|
||||
@@ -138,10 +139,9 @@ func (d *DeployerProvider) deployToFC2(ctx context.Context, certPem string, priv
|
||||
TlsConfig: getCustomDomainResp.Body.TlsConfig,
|
||||
}
|
||||
updateCustomDomainResp, err := d.sdkClients.fc2.UpdateCustomDomain(tea.String(d.config.Domain), updateCustomDomainReq)
|
||||
d.logger.Debug("sdk request 'fc.UpdateCustomDomain'", slog.Any("request", updateCustomDomainReq), slog.Any("response", updateCustomDomainResp))
|
||||
if err != nil {
|
||||
return xerrors.Wrap(err, "failed to execute sdk request 'fc.UpdateCustomDomain'")
|
||||
} else {
|
||||
d.logger.Logt("已更新自定义域名", updateCustomDomainResp)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -17,7 +17,7 @@ var (
|
||||
fAccessKeyId string
|
||||
fAccessKeySecret string
|
||||
fRegion string
|
||||
fSiteId int64
|
||||
fDomain string
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -28,7 +28,7 @@ func init() {
|
||||
flag.StringVar(&fAccessKeyId, argsPrefix+"ACCESSKEYID", "", "")
|
||||
flag.StringVar(&fAccessKeySecret, argsPrefix+"ACCESSKEYSECRET", "", "")
|
||||
flag.StringVar(&fRegion, argsPrefix+"REGION", "", "")
|
||||
flag.Int64Var(&fSiteId, argsPrefix+"SITEID", "", "")
|
||||
flag.StringVar(&fDomain, argsPrefix+"DOMAIN", "", "")
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -40,7 +40,7 @@ Shell command to run this test:
|
||||
--CERTIMATE_DEPLOYER_ALIYUNFC_ACCESSKEYID="your-access-key-id" \
|
||||
--CERTIMATE_DEPLOYER_ALIYUNFC_ACCESSKEYSECRET="your-access-key-secret" \
|
||||
--CERTIMATE_DEPLOYER_ALIYUNFC_REGION="cn-hangzhou" \
|
||||
--CERTIMATE_DEPLOYER_ALIYUNFC_SITEID="your-fc-site-id"
|
||||
--CERTIMATE_DEPLOYER_ALIYUNFC_DOMAIN="example.com"
|
||||
*/
|
||||
func TestDeploy(t *testing.T) {
|
||||
flag.Parse()
|
||||
@@ -53,14 +53,14 @@ func TestDeploy(t *testing.T) {
|
||||
fmt.Sprintf("ACCESSKEYID: %v", fAccessKeyId),
|
||||
fmt.Sprintf("ACCESSKEYSECRET: %v", fAccessKeySecret),
|
||||
fmt.Sprintf("REGION: %v", fRegion),
|
||||
fmt.Sprintf("SITEID: %v", fSiteId),
|
||||
fmt.Sprintf("DOMAIN: %v", fDomain),
|
||||
}, "\n"))
|
||||
|
||||
deployer, err := provider.NewDeployer(&provider.DeployerConfig{
|
||||
AccessKeyId: fAccessKeyId,
|
||||
AccessKeySecret: fAccessKeySecret,
|
||||
Region: fRegion,
|
||||
SiteId: fSiteId,
|
||||
Domain: fDomain,
|
||||
})
|
||||
if err != nil {
|
||||
t.Errorf("err: %+v", err)
|
||||
|
||||
Reference in New Issue
Block a user