diff --git a/pkg/cmd/attestation/verification/attestation.go b/pkg/cmd/attestation/verification/attestation.go index fdfd667bd..f613ba2d5 100644 --- a/pkg/cmd/attestation/verification/attestation.go +++ b/pkg/cmd/attestation/verification/attestation.go @@ -29,34 +29,28 @@ type FetchRemoteAttestationsParams struct { // GetLocalAttestations returns a slice of attestations read from a local bundle file. func GetLocalAttestations(path string) ([]*api.Attestation, error) { + var attestations []*api.Attestation + var err error fileExt := filepath.Ext(path) - switch fileExt { - case ".json": - attestations, err := loadBundleFromJSONFile(path) - if err != nil { - var pathErr *os.PathError - if errors.As(err, &pathErr) { - return nil, fmt.Errorf("bundle could not be loaded from JSON file at %s", path) - } else if errors.Is(err, bundle.ErrValidation) { - return nil, err - } - return nil, fmt.Errorf("bundle content could not be parsed") - } - return attestations, nil - case ".jsonl": - attestations, err := loadBundlesFromJSONLinesFile(path) - if err != nil { - var pathErr *os.PathError - if errors.As(err, &pathErr) { - return nil, fmt.Errorf("bundles could not be loaded from JSON lines file at %s", path) - } else if errors.Is(err, bundle.ErrValidation) { - return nil, err - } - return nil, fmt.Errorf("bundle content could not be parsed") - } - return attestations, nil + if fileExt == ".json" { + attestations, err = loadBundleFromJSONFile(path) + } else if fileExt == ".jsonl" { + attestations, err = loadBundlesFromJSONLinesFile(path) + } else { + return nil, ErrUnrecognisedBundleExtension } - return nil, ErrUnrecognisedBundleExtension + + if err != nil { + var pathErr *os.PathError + if errors.As(err, &pathErr) { + return nil, fmt.Errorf("could not load content from file path %s", path) + } else if errors.Is(err, bundle.ErrValidation) { + return nil, err + } + return nil, fmt.Errorf("bundle content could not be parsed") + } + + return attestations, nil } func loadBundleFromJSONFile(path string) ([]*api.Attestation, error) { diff --git a/pkg/cmd/attestation/verification/attestation_test.go b/pkg/cmd/attestation/verification/attestation_test.go index 08f0ccfef..8acff0c37 100644 --- a/pkg/cmd/attestation/verification/attestation_test.go +++ b/pkg/cmd/attestation/verification/attestation_test.go @@ -92,7 +92,7 @@ func TestGetLocalAttestations(t *testing.T) { path := "../test/data/not-found-bundle.json" attestations, err := GetLocalAttestations(path) - require.ErrorContains(t, err, "bundle could not be loaded from JSON file") + require.ErrorContains(t, err, "could not load content from file path") require.Nil(t, attestations) }) @@ -100,7 +100,7 @@ func TestGetLocalAttestations(t *testing.T) { path := "../test/data/not-found-bundle.jsonl" attestations, err := GetLocalAttestations(path) - require.ErrorContains(t, err, "bundles could not be loaded from JSON lines file") + require.ErrorContains(t, err, "could not load content from file path") require.Nil(t, attestations) })