github.com/SAP/cloud-mta-build-tool@v1.2.27/cmd/sbom.go (about)

     1  package commands
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/SAP/cloud-mta-build-tool/internal/artifacts"
     7  	"github.com/spf13/cobra"
     8  )
     9  
    10  var projectSBomGenCmdSrc string
    11  var projectSBomGenCmdSBOMPath string
    12  
    13  var moduleSBomGenCmdSrc string
    14  var moduleSBomGenCmdModules []string
    15  var moduleSBomGenCmdAllDependencies bool
    16  var moduleSBomGenCmdSBOMPath string
    17  
    18  // Generate SBOM file for project
    19  var projectSBomGenCommand = &cobra.Command{
    20  	Use:   "sbom-gen",
    21  	Short: "(beta) Generates SBOM for project according to configurations in the MTA development descriptor (mta.yaml)",
    22  	Long:  "(beta) Generates SBOM for project according to configurations in the MTA development descriptor (mta.yaml)",
    23  	Args:  cobra.MaximumNArgs(4),
    24  	RunE: func(cmd *cobra.Command, args []string) error {
    25  		err := artifacts.ExecuteProjectSBomGenerate(projectSBomGenCmdSrc, projectSBomGenCmdSBOMPath, os.Getwd)
    26  		// output err info to stdout
    27  		logError(err)
    28  		return err
    29  	},
    30  	// Hidden:        true,
    31  	SilenceUsage: true,
    32  }
    33  
    34  // Generate SBOM file for modules
    35  var moduleSBomGenCommand = &cobra.Command{
    36  	Use:   "module-sbom-gen",
    37  	Short: "Generates SBOM for specified modules according to configurations in the MTA development descriptor (mta.yaml)",
    38  	Long:  "Generates SBOM for specified modules according to configurations in the MTA development descriptor (mta.yaml)",
    39  	Args:  cobra.MaximumNArgs(4),
    40  	RunE: func(cmd *cobra.Command, args []string) error {
    41  		err := artifacts.ExecuteModuleSBomGenerate(moduleSBomGenCmdSrc, moduleSBomGenCmdModules, moduleSBomGenCmdAllDependencies, moduleSBomGenCmdSBOMPath, os.Getwd)
    42  		logError(err)
    43  		return err
    44  	},
    45  	// Hidden:        true,
    46  	SilenceUsage:  true,
    47  	SilenceErrors: true,
    48  }
    49  
    50  func init() {
    51  
    52  	// set flags of sbom-gen command
    53  	projectSBomGenCommand.Flags().StringVarP(&projectSBomGenCmdSrc, "source", "s", "",
    54  		"The path of MTA project; project root path is set as default")
    55  	projectSBomGenCommand.Flags().StringVarP(&projectSBomGenCmdSBOMPath, "sbom-file-path", "b", "",
    56  		`The path of SBOM file, relative or absoluted; if relative path, it is relative to MTA project root; default value is <MTA project path>/<MTA project id>.bom.xml.`)
    57  
    58  	// set flags of module-sbom-gen command
    59  	moduleSBomGenCommand.Flags().StringVarP(&moduleSBomGenCmdSrc, "source", "s", "",
    60  		"The path to the MTA project; the current path is set as default")
    61  	moduleSBomGenCommand.Flags().StringSliceVarP(&moduleSBomGenCmdModules, "modules", "m", nil,
    62  		"The names of the modules")
    63  	moduleSBomGenCommand.Flags().BoolVarP(&moduleSBomGenCmdAllDependencies, "with-all-dependencies", "a", true,
    64  		"Build modules including all dependencies")
    65  	moduleSBomGenCommand.Flags().StringVarP(&moduleSBomGenCmdSBOMPath, "sbom-file-path", "b", "",
    66  		`The path of SBOM file, relative or absoluted; if relative path, it is relative to MTA project root; default value is <MTA project path>/<MTA project id>.bom.xml.`)
    67  }