From 979221b839e2f58ed56ddf5ecca9156a2bf3413a Mon Sep 17 00:00:00 2001 From: Oleksandr Krutko Date: Wed, 10 Jul 2024 23:45:44 +0300 Subject: [PATCH] put some remarks from PR discussion Signed-off-by: Oleksandr Krutko --- pkg/bundle/source.go | 2 +- pkg/fspkg/package.go | 2 +- pkg/util/cert_pool.go | 2 +- test/env/data.go | 6 ++---- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pkg/bundle/source.go b/pkg/bundle/source.go index 819dccdc..1de112ca 100644 --- a/pkg/bundle/source.go +++ b/pkg/bundle/source.go @@ -63,7 +63,7 @@ type bundleData struct { // is each bundle is concatenated together with a new line character. func (b *bundle) buildSourceBundle(ctx context.Context, sources []trustapi.BundleSource, formats *trustapi.AdditionalFormats) (bundleData, error) { var resolvedBundle bundleData - var certPool = util.NewCertPool(util.WithFilteredExpiredCerts(b.FilterExpiredCerts)) + certPool := util.NewCertPool(util.WithFilteredExpiredCerts(b.FilterExpiredCerts)) for _, source := range sources { var ( diff --git a/pkg/fspkg/package.go b/pkg/fspkg/package.go index f608da19..3699b5aa 100644 --- a/pkg/fspkg/package.go +++ b/pkg/fspkg/package.go @@ -65,7 +65,7 @@ func (p *Package) Validate() error { // Ignore the sanitized bundle here and preserve the bundle as-is. // We'll sanitize later, when building a bundle on a reconcile. - var certPool = util.NewCertPool(util.WithFilteredExpiredCerts(false)) + certPool := util.NewCertPool(util.WithFilteredExpiredCerts(false)) err := util.ValidateAndSplitPEMBundle(certPool, []byte(p.Bundle)) if err != nil { diff --git a/pkg/util/cert_pool.go b/pkg/util/cert_pool.go index e268c23a..ec298b98 100644 --- a/pkg/util/cert_pool.go +++ b/pkg/util/cert_pool.go @@ -41,7 +41,7 @@ func WithFilteredExpiredCerts(filterExpired bool) Option { // newCertPool returns a new, empty CertPool. func NewCertPool(options ...Option) *CertPool { - var certPool = &CertPool{ + certPool := &CertPool{ certificates: make([]*x509.Certificate, 0), certificatesHashes: make(map[[32]byte]struct{}), } diff --git a/test/env/data.go b/test/env/data.go index 67e3d3df..3dfa3252 100644 --- a/test/env/data.go +++ b/test/env/data.go @@ -217,11 +217,9 @@ func CheckBundleSyncedStartsWith(ctx context.Context, cl client.Client, name str return fmt.Errorf("received data didn't start with expected data") } - var certPool = util.NewCertPool(util.WithFilteredExpiredCerts(false)) - remaining := strings.TrimPrefix(got, startingData) - // check that there are a nonzero number of valid certs remaining + certPool := util.NewCertPool(util.WithFilteredExpiredCerts(false)) err := util.ValidateAndSplitPEMBundle(certPool, []byte(remaining)) if err != nil { @@ -337,7 +335,7 @@ func CheckJKSFileSynced(jksData []byte, expectedPassword string, expectedCertPEM // that the count is the same aliasCount := len(ks.Aliases()) - expectedPEMCount := len(util.AsSplitPEMBundle(certPool)) + expectedPEMCount := util.GetCertificatesQuantity(certPool) if aliasCount != expectedPEMCount { return fmt.Errorf("expected %d certificates in JKS but found %d", expectedPEMCount, aliasCount)