MCPcopy Create free account
hub / github.com/cli/cli / GetLocalAttestations

Function GetLocalAttestations

pkg/cmd/attestation/verification/attestation.go:24–46  ·  view source on GitHub ↗

GetLocalAttestations returns a slice of attestations read from a local bundle file.

(path string)

Source from the content-addressed store, hash-verified

22
23// GetLocalAttestations returns a slice of attestations read from a local bundle file.
24func 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 if _, ok := errors.AsType[*os.PathError](err); ok {
38 return nil, fmt.Errorf("could not load content from file path %s: %w", path, err)
39 } else if errors.Is(err, bundle.ErrValidation) {
40 return nil, err
41 }
42 return nil, fmt.Errorf("bundle content could not be parsed: %w", err)
43 }
44
45 return attestations, nil
46}
47
48func loadBundleFromJSONFile(path string) ([]*api.Attestation, error) {
49 b, err := bundle.LoadJSONFromPath(path)

Callers 6

runInspectFunction · 0.92
TestGetAttestationDetailFunction · 0.92
getAttestationsForFunction · 0.92
getAttestationsFunction · 0.92
getAttestationsForFunction · 0.85
TestGetLocalAttestationsFunction · 0.85

Calls 3

loadBundleFromJSONFileFunction · 0.85
ErrorfMethod · 0.65

Tested by 4

TestGetAttestationDetailFunction · 0.74
getAttestationsForFunction · 0.74
getAttestationsForFunction · 0.68
TestGetLocalAttestationsFunction · 0.68