From aa792b2a6994b2715ea8d2ad79ba91b618341708 Mon Sep 17 00:00:00 2001 From: carabasdaniel Date: Mon, 13 Mar 2023 14:14:54 +0200 Subject: [PATCH] Fix linting errors Signed-off-by: carabasdaniel --- go.mod | 1 - pkg/app/build.go | 4 ++-- pkg/app/images.go | 5 ++++- pkg/app/rm.go | 10 +++++----- pkg/app/save.go | 6 +++--- pkg/oci/oci.go | 5 ++--- pkg/oci/remote_manager.go | 5 +++-- 7 files changed, 19 insertions(+), 17 deletions(-) diff --git a/go.mod b/go.mod index 6b7544e..64b92d9 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ require ( github.com/containerd/containerd v1.6.15 github.com/dustin/go-humanize v1.0.0 github.com/golang/mock v1.6.0 - github.com/google/uuid v1.3.0 github.com/google/wire v0.5.0 github.com/magefile/mage v1.14.0 github.com/mitchellh/mapstructure v1.5.0 diff --git a/pkg/app/build.go b/pkg/app/build.go index 7fe9bd3..ae4d9be 100644 --- a/pkg/app/build.go +++ b/pkg/app/build.go @@ -107,7 +107,7 @@ func (c *PolicyApp) Build(ref string, path []string, annotations map[string]stri annotations[AnnotationPolicyRegistryType] = PolicyTypePolicy annotations[ocispec.AnnotationCreated] = time.Now().UTC().Format(time.RFC3339) - desc, err := c.createImage(ociStore, outfile, ref, annotations) + desc, err := c.createImage(ociStore, outfile, annotations) if err != nil { return err } @@ -127,7 +127,7 @@ func (c *PolicyApp) Build(ref string, path []string, annotations map[string]stri return nil } -func (c *PolicyApp) createImage(ociStore *orasoci.Store, tarball, ref string, annotations map[string]string) (ocispec.Descriptor, error) { +func (c *PolicyApp) createImage(ociStore *orasoci.Store, tarball string, annotations map[string]string) (ocispec.Descriptor, error) { descriptor := ocispec.Descriptor{} ociStore.AutoSaveIndex = true fDigest, err := c.fileDigest(tarball) diff --git a/pkg/app/images.go b/pkg/app/images.go index 41809f4..feb6ba0 100644 --- a/pkg/app/images.go +++ b/pkg/app/images.go @@ -21,10 +21,13 @@ func (c *PolicyApp) Images() error { table := c.UI.Normal().WithTable("Repository", "Tag", "Image ID", "Size") var tgs []string - ociStore.Tags(c.Context, "", func(tags []string) error { + err = ociStore.Tags(c.Context, "", func(tags []string) error { tgs = append(tgs, tags...) return nil }) + if err != nil { + return err + } for _, tag := range tgs { descr, err := ociStore.Resolve(c.Context, tag) diff --git a/pkg/app/rm.go b/pkg/app/rm.go index 49cd81a..a5a05c0 100644 --- a/pkg/app/rm.go +++ b/pkg/app/rm.go @@ -50,11 +50,11 @@ func (c *PolicyApp) Rm(existingRef string, force bool) error { if !ok { return errors.Errorf("ref [%s] not found in the local store", existingRef) } - // attach ref name annotation for comparisson. + // attach ref name annotation for comparison. ref.Annotations = make(map[string]string) ref.Annotations[ocispec.AnnotationRefName] = existingRefParsed - err = c.removeFromIndex(ref) + err = c.removeFromIndex(&ref) if err != nil { return err } @@ -96,7 +96,7 @@ func (c *PolicyApp) Rm(existingRef string, force bool) error { return nil } -func (c *PolicyApp) removeFromIndex(ref ocispec.Descriptor) error { +func (c *PolicyApp) removeFromIndex(ref *ocispec.Descriptor) error { type index struct { Version int `json:"schemaVersion"` @@ -122,14 +122,14 @@ func (c *PolicyApp) removeFromIndex(ref ocispec.Descriptor) error { return err } - err = os.WriteFile(indexPath, newIndexBytes, 0664) + err = os.WriteFile(indexPath, newIndexBytes, 0664) //nolint:gosec,keep same permissions if err != nil { return err } return nil } -func removeFromManifests(manifests []ocispec.Descriptor, ref ocispec.Descriptor) []ocispec.Descriptor { +func removeFromManifests(manifests []ocispec.Descriptor, ref *ocispec.Descriptor) []ocispec.Descriptor { newarray := make([]ocispec.Descriptor, len(manifests)-1) k := 0 for i := 0; i < len(manifests); i++ { diff --git a/pkg/app/save.go b/pkg/app/save.go index b62ed6b..87aedc4 100644 --- a/pkg/app/save.go +++ b/pkg/app/save.go @@ -55,7 +55,7 @@ func (c *PolicyApp) Save(userRef, outputFilePath string) error { }() } - err = c.writePolicy(ociClient, refDescriptor, outputFile) + err = c.writePolicy(ociClient, &refDescriptor, outputFile) if err != nil { return err } @@ -63,8 +63,8 @@ func (c *PolicyApp) Save(userRef, outputFilePath string) error { return nil } -func (c *PolicyApp) writePolicy(ociStore *oci.Oci, refDescriptor v1.Descriptor, outputFile io.Writer) error { - reader, err := ociStore.GetStore().Fetch(c.Context, refDescriptor) +func (c *PolicyApp) writePolicy(ociStore *oci.Oci, refDescriptor *v1.Descriptor, outputFile io.Writer) error { + reader, err := ociStore.GetStore().Fetch(c.Context, *refDescriptor) if err != nil { return err } diff --git a/pkg/oci/oci.go b/pkg/oci/oci.go index 0fa984e..3b0b2bd 100644 --- a/pkg/oci/oci.go +++ b/pkg/oci/oci.go @@ -6,7 +6,6 @@ import ( "crypto/tls" "crypto/x509" "encoding/json" - "fmt" "net/http" "strings" @@ -59,7 +58,7 @@ func (o *Oci) Pull(ref string) (digest.Digest, error) { // Get tarball descriptor digest opts.OnCopySkipped = func(ctx context.Context, desc ocispec.Descriptor) error { if !IsAllowedMediaType(desc.MediaType) { - return fmt.Errorf("%s media type not allowed", desc.MediaType) + return errors.Errorf("%s media type not allowed", desc.MediaType) } if strings.Contains(desc.MediaType, "tar") { tarDescriptor = desc @@ -68,7 +67,7 @@ func (o *Oci) Pull(ref string) (digest.Digest, error) { } opts.PostCopy = func(ctx context.Context, desc ocispec.Descriptor) error { if !IsAllowedMediaType(desc.MediaType) { - return fmt.Errorf("%s media type not allowed", desc.MediaType) + return errors.Errorf("%s media type not allowed", desc.MediaType) } if strings.Contains(desc.MediaType, "tar") { tarDescriptor = desc diff --git a/pkg/oci/remote_manager.go b/pkg/oci/remote_manager.go index dd236cb..b953b95 100644 --- a/pkg/oci/remote_manager.go +++ b/pkg/oci/remote_manager.go @@ -1,3 +1,4 @@ +//nolint:gocritic, big parameter linter error passing ocispec.Descriptor, needed to implement oras.ReadOnlyTarget intarface package oci import ( @@ -69,14 +70,14 @@ func (r *remoteManager) Push(ctx context.Context, expected ocispec.Descriptor, c func (r *remoteManager) Tag(ctx context.Context, desc ocispec.Descriptor, reference string) error { originalRef := r.srcRef - content, err := r.fetcher.Fetch(ctx, desc) + reader, err := r.fetcher.Fetch(ctx, desc) if err != nil { return err } r.srcRef = reference desc.Annotations = make(map[string]string) desc.Annotations[ocispec.AnnotationRefName] = reference - err = r.Push(ctx, desc, content) + err = r.Push(ctx, desc, reader) if err != nil { return err }