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

Function runVerify

pkg/cmd/attestation/verify/verify.go:273–358  ·  view source on GitHub ↗
(opts *Options)

Source from the content-addressed store, hash-verified

271}
272
273func runVerify(opts *Options) error {
274 ec, err := newEnforcementCriteria(opts)
275 if err != nil {
276 opts.Logger.Println(opts.Logger.ColorScheme.Red("✗ Failed to build verification policy"))
277 return err
278 }
279
280 if err := ec.Valid(); err != nil {
281 opts.Logger.Println(opts.Logger.ColorScheme.Red("✗ Invalid verification policy"))
282 return err
283 }
284
285 artifact, err := artifact.NewDigestedArtifact(opts.OCIClient, opts.ArtifactPath, opts.DigestAlgorithm)
286 if err != nil {
287 opts.Logger.Printf(opts.Logger.ColorScheme.Red("✗ Loading digest for %s failed\n"), opts.ArtifactPath)
288 return err
289 }
290
291 opts.Logger.Printf("Loaded digest %s for %s\n", artifact.DigestWithAlg(), artifact.URL)
292
293 attestations, logMsg, err := getAttestations(opts, *artifact)
294 if err != nil {
295 if ok := errors.Is(err, api.ErrNoAttestationsFound); ok {
296 opts.Logger.Printf(opts.Logger.ColorScheme.Red("✗ No attestations found for subject %s\n"), artifact.DigestWithAlg())
297 return err
298 }
299 // Print the message signifying failure fetching attestations
300 opts.Logger.Println(opts.Logger.ColorScheme.Red(logMsg))
301 return err
302 }
303 // Print the message signifying success fetching attestations
304 opts.Logger.Println(logMsg)
305
306 // print information about the policy that will be enforced against attestations
307 opts.Logger.Println("\nThe following policy criteria will be enforced:")
308 opts.Logger.Println(ec.BuildPolicyInformation())
309
310 verified, errMsg, err := verifyAttestations(*artifact, attestations, opts.SigstoreVerifier, ec)
311 if err != nil {
312 opts.Logger.Println(opts.Logger.ColorScheme.Red(errMsg))
313 return err
314 }
315
316 opts.Logger.Println(opts.Logger.ColorScheme.Green("✓ Verification succeeded!\n"))
317
318 // If an exporter is provided with the --json flag, write the results to the terminal in JSON format
319 if opts.exporter != nil {
320 // print the results to the terminal as an array of JSON objects
321 if err = opts.exporter.Write(opts.Logger.IO, verified); err != nil {
322 opts.Logger.Println(opts.Logger.ColorScheme.Red("✗ Failed to write JSON output"))
323 return err
324 }
325 return nil
326 }
327
328 opts.Logger.Printf("The following %s matched the policy criteria\n\n", text.Pluralize(len(verified), "attestation"))
329
330 // Otherwise print the results to the terminal

Callers 7

NewVerifyCmdFunction · 0.85
TestVerifyIntegrationFunction · 0.85
TestJSONOutputFunction · 0.85
TestRunVerifyFunction · 0.85

Calls 14

DigestWithAlgMethod · 0.95
PluralizeFunction · 0.92
newEnforcementCriteriaFunction · 0.85
getAttestationsFunction · 0.85
verifyAttestationsFunction · 0.85
extractAttestationDetailFunction · 0.85
PrintlnMethod · 0.80
RedMethod · 0.80
ValidMethod · 0.80
GreenMethod · 0.80
PrintBulletPointsMethod · 0.80