update no attestations found err

Signed-off-by: Meredith Lancaster <malancas@github.com>
This commit is contained in:
Meredith Lancaster 2025-01-13 12:42:10 -07:00
parent fc0d0210c0
commit b7f6af03b5
7 changed files with 8 additions and 33 deletions

View file

@ -1,8 +1,7 @@
package api
import (
"fmt"
"errors"
"github.com/sigstore/sigstore-go/pkg/bundle"
)
@ -11,18 +10,7 @@ const (
GetAttestationByOwnerAndSubjectDigestPath = "orgs/%s/attestations/%s"
)
type ErrNoAttestations struct {
name string
digest string
}
func (e ErrNoAttestations) Error() string {
return fmt.Sprintf("no attestations found for digest %s in %s", e.name, e.digest)
}
func newErrNoAttestations(name, digest string) ErrNoAttestations {
return ErrNoAttestations{name, digest}
}
var ErrNoAttestationsFound = errors.New("no attestations found")
type Attestation struct {
Bundle *bundle.Bundle `json:"bundle"`

View file

@ -137,7 +137,7 @@ func (c *LiveClient) getAttestations(url string, limit int) ([]*Attestation, err
}
if len(attestations) == 0 {
return nil, ErrNoAttestations{}
return nil, ErrNoAttestationsFound
}
if len(attestations) > limit {

View file

@ -132,12 +132,12 @@ func TestGetByDigest_NoAttestationsFound(t *testing.T) {
attestations, err := c.GetByRepoAndDigest(testRepo, testDigest, DefaultLimit)
require.Error(t, err)
require.IsType(t, ErrNoAttestations{}, err)
require.IsType(t, ErrNoAttestationsFound, err)
require.Nil(t, attestations)
attestations, err = c.GetByOwnerAndDigest(testOwner, testDigest, DefaultLimit)
require.Error(t, err)
require.IsType(t, ErrNoAttestations{}, err)
require.IsType(t, ErrNoAttestationsFound, err)
require.Nil(t, attestations)
}

View file

@ -40,19 +40,6 @@ func (m *failHttpClient) Get(url string) (*http.Response, error) {
}, fmt.Errorf("failed to fetch with %s", url)
}
type failHttpClient5XX struct {
mock.Mock
}
func (m *failHttpClient5XX) Get(url string) (*http.Response, error) {
m.On("OnGetFail").Return()
m.MethodCalled("OnGetFail")
return &http.Response{
StatusCode: 500,
}, nil
}
type failAfterNCallsHttpClient struct {
mock.Mock
FailOnCallN int

View file

@ -135,7 +135,7 @@ func runDownload(opts *Options) error {
}
attestations, err := verification.GetRemoteAttestations(opts.APIClient, params)
if err != nil {
if errors.Is(err, api.ErrNoAttestations{}) {
if errors.Is(err, api.ErrNoAttestationsFound) {
fmt.Fprintf(opts.Logger.IO.Out, "No attestations found for %s\n", opts.ArtifactPath)
return nil
}

View file

@ -276,7 +276,7 @@ func TestRunDownload(t *testing.T) {
opts := baseOpts
opts.APIClient = api.MockClient{
OnGetByOwnerAndDigest: func(repo, digest string, limit int) ([]*api.Attestation, error) {
return nil, api.ErrNoAttestations{}
return nil, api.ErrNoAttestationsFound
},
}

View file

@ -220,7 +220,7 @@ func runVerify(opts *Options) error {
attestations, logMsg, err := getAttestations(opts, *artifact)
if err != nil {
if ok := errors.Is(err, api.ErrNoAttestations{}); ok {
if ok := errors.Is(err, api.ErrNoAttestationsFound); ok {
opts.Logger.Printf(opts.Logger.ColorScheme.Red("✗ No attestations found for subject %s\n"), artifact.DigestWithAlg())
return err
}