Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
Signed-off-by: carabasdaniel <[email protected]>
  • Loading branch information
carabasdaniel committed Mar 13, 2023
1 parent 58a3052 commit aa792b2
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion pkg/app/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions pkg/app/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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"`
Expand All @@ -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++ {
Expand Down
6 changes: 3 additions & 3 deletions pkg/app/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ 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
}

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
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"crypto/tls"
"crypto/x509"
"encoding/json"
"fmt"
"net/http"
"strings"

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pkg/oci/remote_manager.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:gocritic, big parameter linter error passing ocispec.Descriptor, needed to implement oras.ReadOnlyTarget intarface
package oci

import (
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit aa792b2

Please sign in to comment.