MCPcopy
hub / github.com/cli/cli / createMetadataFile

Method createMetadataFile

pkg/cmd/attestation/download/metadata.go:38–72  ·  view source on GitHub ↗
(artifactDigest string, attestationsResp []*api.Attestation)

Source from the content-addressed store, hash-verified

36}
37
38func (s *LiveStore) createMetadataFile(artifactDigest string, attestationsResp []*api.Attestation) (string, error) {
39 metadataFilePath := s.createJSONLinesFilePath(artifactDigest)
40
41 f, err := os.Create(metadataFilePath)
42 if err != nil {
43 return "", errors.Join(ErrAttestationFileCreation, fmt.Errorf("failed to create file: %v", err))
44 }
45
46 for _, resp := range attestationsResp {
47 bundle := resp.Bundle
48 attBytes, err := json.Marshal(bundle)
49 if err != nil {
50 if err = f.Close(); err != nil {
51 return "", errors.Join(ErrAttestationFileCreation, fmt.Errorf("failed to close file while marshalling JSON: %v", err))
52 }
53 return "", errors.Join(ErrAttestationFileCreation, fmt.Errorf("failed to marshall attestation to JSON while writing to file: %v", err))
54 }
55
56 withNewline := fmt.Sprintf("%s\n", attBytes)
57 _, err = f.Write([]byte(withNewline))
58 if err != nil {
59 if err = f.Close(); err != nil {
60 return "", errors.Join(ErrAttestationFileCreation, fmt.Errorf("failed to close file while handling write error: %v", err))
61 }
62
63 return "", errors.Join(ErrAttestationFileCreation, fmt.Errorf("failed to write attestations: %v", err))
64 }
65 }
66
67 if err = f.Close(); err != nil {
68 return "", errors.Join(ErrAttestationFileCreation, fmt.Errorf("failed to close file after writing attestations: %v", err))
69 }
70
71 return metadataFilePath, nil
72}
73
74func NewLiveStore(outputPath string) *LiveStore {
75 return &LiveStore{

Callers

nothing calls this directly

Calls 6

JoinMethod · 0.80
CreateMethod · 0.65
ErrorfMethod · 0.65
CloseMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected