GetLocalAttestations returns a slice of attestations read from a local bundle file.
(path string)
| 22 | |
| 23 | // GetLocalAttestations returns a slice of attestations read from a local bundle file. |
| 24 | func GetLocalAttestations(path string) ([]*api.Attestation, error) { |
| 25 | var attestations []*api.Attestation |
| 26 | var err error |
| 27 | fileExt := filepath.Ext(path) |
| 28 | if fileExt == ".json" { |
| 29 | attestations, err = loadBundleFromJSONFile(path) |
| 30 | } else if fileExt == ".jsonl" { |
| 31 | attestations, err = loadBundlesFromJSONLinesFile(path) |
| 32 | } else { |
| 33 | return nil, ErrUnrecognisedBundleExtension |
| 34 | } |
| 35 | |
| 36 | if err != nil { |
| 37 | var pathErr *os.PathError |
| 38 | if errors.As(err, &pathErr) { |
| 39 | return nil, fmt.Errorf("could not load content from file path %s: %w", path, err) |
| 40 | } else if errors.Is(err, bundle.ErrValidation) { |
| 41 | return nil, err |
| 42 | } |
| 43 | return nil, fmt.Errorf("bundle content could not be parsed: %w", err) |
| 44 | } |
| 45 | |
| 46 | return attestations, nil |
| 47 | } |
| 48 | |
| 49 | func loadBundleFromJSONFile(path string) ([]*api.Attestation, error) { |
| 50 | b, err := bundle.LoadJSONFromPath(path) |