diff --git a/Makefile b/Makefile index de585168327f..01ec87a649a5 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,8 @@ else GOBIN=$(shell go env GOBIN) endif +GOFILES ?= $(shell find . -type f -name '*.go' -not -path "./vendor/*") + # Set version variables for LDFLAGS PROJECT_ID ?= projectsigstore RUNTIME_IMAGE ?= gcr.io/distroless/static @@ -55,6 +57,28 @@ export KO_DOCKER_REPO=$(KO_PREFIX) .PHONY: all lint test clean cosign cross all: cosign +log-%: + @grep -h -E '^$*:.*?## .*$$' $(MAKEFILE_LIST) | \ + awk \ + 'BEGIN { \ + FS = ":.*?## " \ + }; \ + { \ + printf "\033[36m==> %s\033[0m\n", $$2 \ + }' + +.PHONY: checkfmt +checkfmt: SHELL := /usr/bin/env bash +checkfmt: ## Check formatting of all go files + @ $(MAKE) --no-print-directory log-$@ + $(shell test -z "$(shell gofmt -l $(GOFILES) | tee /dev/stderr)") + $(shell test -z "$(shell goimports -l $(GOFILES) | tee /dev/stderr)") + +.PHONY: fmt +fmt: ## Format all go files + @ $(MAKE) --no-print-directory log-$@ + goimports -w $(GOFILES) + cosign: $(SRCS) CGO_ENABLED=0 go build -trimpath -ldflags "$(LDFLAGS)" -o $@ ./cmd/cosign diff --git a/pkg/cosign/remote/remote.go b/pkg/cosign/remote/remote.go index a0d26318e28c..24ba814c5c5d 100644 --- a/pkg/cosign/remote/remote.go +++ b/pkg/cosign/remote/remote.go @@ -43,7 +43,6 @@ type dd struct { type ro struct { predicateURI string - replace bool } var _ mutate.DupeDetector = (*dd)(nil) diff --git a/pkg/oci/mutate/mutate.go b/pkg/oci/mutate/mutate.go index 4605aa80163f..48ceb2c42529 100644 --- a/pkg/oci/mutate/mutate.go +++ b/pkg/oci/mutate/mutate.go @@ -212,11 +212,11 @@ func (si *signedImage) Attestations() (oci.Signatures, error) { } } if si.so.ro != nil { - if replace, err := si.so.ro.Replace(base, si.att); err != nil { + replace, err := si.so.ro.Replace(base, si.att) + if err != nil { return nil, err - } else { - return AppendSignatures(replace) } + return AppendSignatures(replace) } return AppendSignatures(base, si.att) } @@ -289,21 +289,11 @@ func (sii *signedImageIndex) Attestations() (oci.Signatures, error) { } } if sii.so.ro != nil { - if replace, err := sii.so.ro.Replace(base, sii.att); err != nil { + replace, err := sii.so.ro.Replace(base, sii.att) + if err != nil { return nil, err - } else { - //sigs, err := base.Get() - //if err != nil { - // return nil, err - //} - // - //if len(sigs) == 0 { - // return AppendSignatures(replace,sii.att) - //}else{ - // return ReplaceSignatures(replace) - //} - return ReplaceSignatures(replace) } + return ReplaceSignatures(replace) } return AppendSignatures(base, sii.att) } diff --git a/pkg/oci/mutate/signatures.go b/pkg/oci/mutate/signatures.go index cee8285ae55b..53f750d9e03e 100644 --- a/pkg/oci/mutate/signatures.go +++ b/pkg/oci/mutate/signatures.go @@ -76,14 +76,6 @@ func ReplaceSignatures(base oci.Signatures) (oci.Signatures, error) { }, nil } -//func SetSignatures(base oci.Signatures, sigs ...oci.Signature) oci.Signatures { -// return &sigAppender{ -// Image: img, -// base: base, -// sigs: sigs, -// } -//} - type sigAppender struct { v1.Image base oci.Signatures diff --git a/test/e2e_test.go b/test/e2e_test.go index 38ec1917dc28..7d46981c3573 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -184,7 +184,7 @@ func TestAttestVerify(t *testing.T) { // Now attest the image ko := sign.KeyOpts{KeyRef: privKeyPath, PassFunc: passFunc} must(attest.AttestCmd(ctx, ko, options.RegistryOptions{}, imgName, "", false, slsaAttestationPath, false, - "custom", time.Duration(30*time.Second)), t) + "custom", ftime.Duration(30*time.Second)), t) // Use cue to verify attestation policyPath := filepath.Join(td, "policy.cue")