generateVSAsDSSE generates DSSE VSA envelopes for all validated components
(cmd *cobra.Command, report applicationsnapshot.Report, outputDir string)
| 667 | |
| 668 | // generateVSAsDSSE generates DSSE VSA envelopes for all validated components |
| 669 | func (data *imageData) generateVSAsDSSE(cmd *cobra.Command, report applicationsnapshot.Report, outputDir string) error { |
| 670 | // Use service for DSSE envelopes |
| 671 | signer, err := vsa.NewSigner(cmd.Context(), data.vsaSigningKey, utils.FS(cmd.Context())) |
| 672 | if err != nil { |
| 673 | log.Error(err) |
| 674 | return err |
| 675 | } |
| 676 | |
| 677 | // Create VSA service with output directory |
| 678 | vsaService := vsa.NewServiceWithFS(signer, utils.FS(cmd.Context()), data.policySource, data.policy, outputDir) |
| 679 | |
| 680 | // Define helper functions for getting git URL and digest |
| 681 | getGitURL := func(comp applicationsnapshot.Component) string { |
| 682 | if comp.Source.GitSource != nil { |
| 683 | return comp.Source.GitSource.URL |
| 684 | } |
| 685 | return "" |
| 686 | } |
| 687 | |
| 688 | getDigest := func(comp applicationsnapshot.Component) (string, error) { |
| 689 | imageRef, err := name.ParseReference(comp.ContainerImage) |
| 690 | if err != nil { |
| 691 | return "", fmt.Errorf("failed to parse image reference %s: %v", comp.ContainerImage, err) |
| 692 | } |
| 693 | |
| 694 | digest, err := oci.NewClient(cmd.Context()).ResolveDigest(imageRef) |
| 695 | if err != nil { |
| 696 | return "", fmt.Errorf("failed to resolve digest for image %s: %v", comp.ContainerImage, err) |
| 697 | } |
| 698 | |
| 699 | return digest, nil |
| 700 | } |
| 701 | |
| 702 | // Process all VSAs using the service |
| 703 | vsaResult, err := vsaService.ProcessAllVSAs(cmd.Context(), report, getGitURL, getDigest) |
| 704 | if err != nil { |
| 705 | log.Errorf("Failed to process VSAs: %v", err) |
| 706 | // Don't return error here, continue with the rest of the command |
| 707 | } else { |
| 708 | // Upload VSAs to configured storage backends |
| 709 | if len(data.vsaUpload) > 0 { |
| 710 | log.Infof("[VSA] Starting upload to %d storage backend(s)", len(data.vsaUpload)) |
| 711 | |
| 712 | // Upload component VSA envelopes |
| 713 | for imageRef, envelopePath := range vsaResult.ComponentEnvelopes { |
| 714 | uploadErr := vsa.UploadVSAEnvelope(cmd.Context(), envelopePath, data.vsaUpload, signer) |
| 715 | if uploadErr != nil { |
| 716 | log.Errorf("[VSA] Upload failed for component %s: %v", imageRef, uploadErr) |
| 717 | } else { |
| 718 | log.Infof("[VSA] Uploaded Component VSA") |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | // Upload snapshot VSA envelope if it exists |
| 723 | if vsaResult.SnapshotEnvelope != "" { |
| 724 | uploadErr := vsa.UploadVSAEnvelope(cmd.Context(), vsaResult.SnapshotEnvelope, data.vsaUpload, signer) |
| 725 | if uploadErr != nil { |
| 726 | log.Errorf("[VSA] Upload failed for snapshot: %v", uploadErr) |
no test coverage detected