github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/internal/commands/download_sbom.go (about)

     1  package commands
     2  
     3  import (
     4  	"github.com/spf13/cobra"
     5  
     6  	cpkg "github.com/buildpacks/pack/pkg/client"
     7  	"github.com/buildpacks/pack/pkg/logging"
     8  )
     9  
    10  type DownloadSBOMFlags struct {
    11  	Remote         bool
    12  	DestinationDir string
    13  }
    14  
    15  func DownloadSBOM(
    16  	logger logging.Logger,
    17  	client PackClient,
    18  ) *cobra.Command {
    19  	var flags DownloadSBOMFlags
    20  	cmd := &cobra.Command{
    21  		Use:     "download <image-name>",
    22  		Args:    cobra.ExactArgs(1),
    23  		Short:   "Download SBoM from specified image",
    24  		Long:    "Download layer containing structured Software Bill of Materials (SBoM) from specified image",
    25  		Example: "pack sbom download buildpacksio/pack",
    26  		RunE: logError(logger, func(cmd *cobra.Command, args []string) error {
    27  			img := args[0]
    28  			options := cpkg.DownloadSBOMOptions{
    29  				Daemon:         !flags.Remote,
    30  				DestinationDir: flags.DestinationDir,
    31  			}
    32  
    33  			return client.DownloadSBOM(img, options)
    34  		}),
    35  	}
    36  	AddHelpFlag(cmd, "download")
    37  	cmd.Flags().BoolVar(&flags.Remote, "remote", false, "Download SBoM of image in remote registry (without pulling image)")
    38  	cmd.Flags().StringVarP(&flags.DestinationDir, "output-dir", "o", ".", "Path to export SBoM contents.\nIt defaults export to the current working directory.")
    39  	return cmd
    40  }