MCPcopy Create free account
hub / github.com/google/go-github / main

Function main

example/verifyartifact/main.go:66–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

64}
65
66func main() {
67 flag.Parse()
68 if *artifactDigest == "" {
69 fmt.Fprintln(os.Stderr, "artifact-digest is required.")
70 usage()
71 os.Exit(1)
72 }
73
74 token := os.Getenv("GITHUB_AUTH_TOKEN")
75
76 if token == "" {
77 log.Fatal("Unauthorized: No token present. Please set the GITHUB_AUTH_TOKEN environment variable to a valid token with `attestations:read` permission.")
78 }
79
80 ctx := context.Background()
81 client, err := github.NewClient(github.WithAuthToken(token))
82 if err != nil {
83 log.Fatalf("Error creating GitHub client: %v", err)
84 }
85
86 // Fetch attestations from the GitHub API.
87 // The attestations API doesn't differentiate between users and orgs,
88 // so we can use the OrganizationsService to fetch attestations for both.
89 attestations, _, err := client.Organizations.ListAttestations(ctx, *owner, fmt.Sprintf("%v:%v", *artifactDigestAlgorithm, *artifactDigest), nil)
90 if err != nil {
91 log.Fatal(err)
92 }
93
94 if len(attestations.Attestations) == 0 {
95 log.Fatal("No attestations found.")
96 }
97
98 sev, err := getSignedEntityVerifier()
99 if err != nil {
100 log.Fatal(err)
101 }
102
103 pb, err := getPolicyBuilder()
104 if err != nil {
105 log.Fatal(err)
106 }
107
108 var b *bundle.Bundle
109 for _, attestation := range attestations.Attestations {
110 if err := json.Unmarshal(attestation.Bundle, &b); err != nil {
111 log.Fatal(err)
112 }
113
114 err := runVerification(sev, pb, b)
115 if err != nil {
116 log.Fatal(err)
117 }
118 }
119}
120
121func getTrustedMaterial() (root.TrustedMaterialCollection, error) {
122 trustedRootJSON, err := os.ReadFile(*trustedRootJSONPath)

Callers

nothing calls this directly

Calls 7

NewClientFunction · 0.92
WithAuthTokenFunction · 0.92
usageFunction · 0.85
getSignedEntityVerifierFunction · 0.85
getPolicyBuilderFunction · 0.85
runVerificationFunction · 0.85
ListAttestationsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…