refactor: clean code

This commit is contained in:
Fu Diwei
2026-09-04 17:01:33 +08:00
committed by RHQYZ
parent c5f9b4cac5
commit f9a11e7f2d
10 changed files with 40 additions and 22 deletions
@@ -225,6 +225,7 @@ func (d *Deployer) updateListenerCertificate(ctx context.Context, cloudLoadbalan
d.logger.Info("no need to deploy clb listener default certificate")
return nil
}
return d.updateListenerDefaultCertificate(ctx, cloudLoadbalancerId, cloudListenerPort, cloudCertId)
} else {
// 指定 SNI,需部署到扩展域名
@@ -240,6 +240,7 @@ func (d *Deployer) updateListenerCertificate(ctx context.Context, cloudAccelerat
d.logger.Info("no need to deploy ga listener default certificate")
return nil
}
return d.updateListenerDefaultCertificate(ctx, cloudListenerId, cloudCertId)
} else {
// 指定 SNI,需部署到扩展域名
@@ -240,6 +240,7 @@ func (d *Deployer) updateHttpsListenerCertificate(ctx context.Context, cloudLoad
d.logger.Info("no need to deploy appblb listener default certificate")
return nil
}
return d.updateHttpsListenerDefaultCertificate(ctx, cloudLoadbalancerId, &listenerInfo, cloudCertId)
} else {
// 指定 SNI,需部署到扩展域名
@@ -240,6 +240,7 @@ func (d *Deployer) updateHttpsListenerCertificate(ctx context.Context, cloudLoad
d.logger.Info("no need to deploy blb listener default certificate")
return nil
}
return d.updateHttpsListenerDefaultCertificate(ctx, cloudLoadbalancerId, &listenerInfo, cloudCertId)
} else {
// 指定 SNI,需部署到扩展域名
@@ -213,6 +213,7 @@ func (d *Deployer) updateListenerCertificate(ctx context.Context, cloudListenerI
d.logger.Info("no need to deploy alb listener default certificate")
return nil
}
return d.updateListenerDefaultCertificate(ctx, *describeListenerAttributesResp, cloudCertId)
} else {
// 指定 SNI,需部署到扩展域名
@@ -252,7 +253,8 @@ func (d *Deployer) updateListenerSniCertificate(ctx context.Context, cloudListen
CertCenterCertificateId: bp.String(cloudCertId),
Action: bp.String("modify"),
}
}),
},
),
}
modifyListenerAttributesResp, err := d.sdkClient.ModifyListenerAttributesWithContext(ctx, modifyListenerAttributesReq)
d.logger.Debug("sdk request 'alb.ModifyListenerAttributes'", slog.Any("request", modifyListenerAttributesReq), slog.Any("response", modifyListenerAttributesResp))
@@ -112,6 +112,9 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
}
domains = domainCandidates
if len(domains) == 0 {
return nil, fmt.Errorf("could not find any domains matched by wildcard")
}
} else {
domains = []string{d.config.Domain}
}
@@ -125,6 +128,9 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
}
domains = domainCandidates
if len(domains) == 0 {
return nil, fmt.Errorf("could not find any domains matched by certificate")
}
}
default:
@@ -216,12 +222,6 @@ func (d *Deployer) getMatchedDomainsByCertId(ctx context.Context, cloudCertId st
}
}
if len(domains) == 0 {
if len(describeCertConfigResp.Result.SpecifiedCertConfig) == 0 {
return nil, fmt.Errorf("could not find any domains matched by certificate")
}
}
return domains, nil
}
@@ -220,6 +220,7 @@ func (d *Deployer) updateListenerCertificate(ctx context.Context, cloudLoadbalan
d.logger.Info("no need to deploy alb listener default certificate")
return nil
}
return d.updateListenerDefaultCertificate(ctx, cloudLoadbalancerId, cloudListenerId, cloudCertId)
} else {
// 指定 SNI,需部署到扩展域名
@@ -227,6 +228,7 @@ func (d *Deployer) updateListenerCertificate(ctx context.Context, cloudLoadbalan
d.logger.Info("no need to deploy alb listener sni certificate")
return nil
}
return d.updateListenerSniCertificate(ctx, cloudLoadbalancerId, listenerInfo, cloudCertId)
}
}
@@ -216,8 +216,16 @@ func (d *Deployer) updateListenerCertificate(ctx context.Context, cloudListenerI
d.logger.Info("no need to deploy alb listener default certificate")
return nil
}
return d.updateListenerDefaultCertificate(ctx, *describeListenerAttributesResp, cloudCertId)
} else {
if lo.SomeBy(describeListenerAttributesResp.DomainExtensions, func(domainExtension *vealb.DomainExtensionForDescribeListenerAttributesOutput) bool {
return ve.StringValue(domainExtension.Domain) == d.config.Domain && ve.StringValue(domainExtension.CertCenterCertificateId) == cloudCertId
}) {
d.logger.Info("no need to deploy alb listener sni certificate")
return nil
}
// 指定 SNI,需部署到扩展域名
return d.updateListenerSniCertificate(ctx, *describeListenerAttributesResp, cloudCertId)
}
@@ -247,7 +255,7 @@ func (d *Deployer) updateListenerSniCertificate(ctx context.Context, cloudListen
ListenerId: cloudListenerInfo.ListenerId,
DomainExtensions: lo.Map(
lo.Filter(cloudListenerInfo.DomainExtensions, func(domain *vealb.DomainExtensionForDescribeListenerAttributesOutput, _ int) bool {
return *domain.Domain == d.config.Domain
return ve.StringValue(domain.Domain) == d.config.Domain
}),
func(domain *vealb.DomainExtensionForDescribeListenerAttributesOutput, _ int) *vealb.DomainExtensionForModifyListenerAttributesInput {
return &vealb.DomainExtensionForModifyListenerAttributesInput{
@@ -257,7 +265,8 @@ func (d *Deployer) updateListenerSniCertificate(ctx context.Context, cloudListen
CertCenterCertificateId: ve.String(cloudCertId),
Action: ve.String("modify"),
}
}),
},
),
}
modifyListenerAttributesResp, err := d.sdkClient.ModifyListenerAttributesWithContext(ctx, modifyListenerAttributesReq)
d.logger.Debug("sdk request 'alb.ModifyListenerAttributes'", slog.Any("request", modifyListenerAttributesReq), slog.Any("response", modifyListenerAttributesResp))
@@ -117,6 +117,9 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
}
domains = domainCandidates
if len(domains) == 0 {
return nil, fmt.Errorf("could not find any domains matched by wildcard")
}
} else {
domains = []string{d.config.Domain}
}
@@ -130,6 +133,9 @@ func (d *Deployer) Deploy(ctx context.Context, certPEM, privkeyPEM string) (*Dep
}
domains = domainCandidates
if len(domains) == 0 {
return nil, fmt.Errorf("could not find any domains matched by certificate")
}
}
default:
@@ -192,10 +198,6 @@ func (d *Deployer) getMatchedDomainsByWildcard(ctx context.Context, wildcardDoma
listCdnDomainsPageSize++
}
if len(domains) == 0 {
return nil, fmt.Errorf("could not find any domains matched by wildcard")
}
return domains, nil
}
@@ -225,12 +227,6 @@ func (d *Deployer) getMatchedDomainsByCertId(ctx context.Context, cloudCertId st
}
}
if len(domains) == 0 {
if len(describeCertConfigResp.SpecifiedCertConfig) == 0 {
return nil, fmt.Errorf("could not find any domains matched by certificate")
}
}
return domains, nil
}
@@ -218,8 +218,16 @@ func (d *Deployer) updateListenerCertificate(ctx context.Context, cloudListenerI
d.logger.Info("no need to deploy clb listener default certificate")
return nil
}
return d.updateListenerDefaultCertificate(ctx, cloudListenerId, cloudCertId)
} else {
if lo.SomeBy(describeListenerAttributesResp.DomainExtensions, func(domainExtension *veclb.DomainExtensionForDescribeListenerAttributesOutput) bool {
return ve.StringValue(domainExtension.Domain) == d.config.Domain && ve.StringValue(domainExtension.CertCenterCertificateId) == cloudCertId
}) {
d.logger.Info("no need to deploy clb listener sni certificate")
return nil
}
// 指定 SNI,需部署到扩展域名
return d.updateListenerSniCertificate(ctx, describeListenerAttributesResp, cloudCertId)
}
@@ -248,9 +256,6 @@ func (d *Deployer) updateListenerSniCertificate(ctx context.Context, cloudListen
})
if domainExtension == nil {
return fmt.Errorf("could not find clb listener domain extension '%s' for listener '%s'", d.config.Domain, ve.StringValue(cloudListenerInfo.ListenerId))
} else if ve.StringValue(domainExtension.CertCenterCertificateId) == cloudCertId {
d.logger.Info("no need to deploy clb listener extension domain certificate")
return nil
}
// 修改指定监听器的扩展域名证书