github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/flag/sbom_flags.go (about)

     1  package flag
     2  
     3  import (
     4  	"golang.org/x/xerrors"
     5  
     6  	"github.com/devseccon/trivy/pkg/log"
     7  )
     8  
     9  var (
    10  	ArtifactTypeFlag = Flag{
    11  		Name:       "artifact-type",
    12  		ConfigName: "sbom.artifact-type",
    13  		Default:    "",
    14  		Usage:      "deprecated",
    15  		Deprecated: true,
    16  	}
    17  	SBOMFormatFlag = Flag{
    18  		Name:       "sbom-format",
    19  		ConfigName: "sbom.format",
    20  		Default:    "",
    21  		Usage:      "deprecated",
    22  		Deprecated: true,
    23  	}
    24  	VEXFlag = Flag{
    25  		Name:       "vex",
    26  		ConfigName: "sbom.vex",
    27  		Default:    "",
    28  		Usage:      "[EXPERIMENTAL] file path to VEX",
    29  	}
    30  )
    31  
    32  type SBOMFlagGroup struct {
    33  	ArtifactType *Flag // deprecated
    34  	SBOMFormat   *Flag // deprecated
    35  	VEXPath      *Flag
    36  }
    37  
    38  type SBOMOptions struct {
    39  	VEXPath string
    40  }
    41  
    42  func NewSBOMFlagGroup() *SBOMFlagGroup {
    43  	return &SBOMFlagGroup{
    44  		ArtifactType: &ArtifactTypeFlag,
    45  		SBOMFormat:   &SBOMFormatFlag,
    46  		VEXPath:      &VEXFlag,
    47  	}
    48  }
    49  
    50  func (f *SBOMFlagGroup) Name() string {
    51  	return "SBOM"
    52  }
    53  
    54  func (f *SBOMFlagGroup) Flags() []*Flag {
    55  	return []*Flag{
    56  		f.ArtifactType,
    57  		f.SBOMFormat,
    58  		f.VEXPath,
    59  	}
    60  }
    61  
    62  func (f *SBOMFlagGroup) ToOptions() (SBOMOptions, error) {
    63  	artifactType := getString(f.ArtifactType)
    64  	sbomFormat := getString(f.SBOMFormat)
    65  
    66  	if artifactType != "" || sbomFormat != "" {
    67  		log.Logger.Error("'trivy sbom' is now for scanning SBOM. " +
    68  			"See https://github.com/devseccon/trivy/discussions/2407 for the detail")
    69  		return SBOMOptions{}, xerrors.New("'--artifact-type' and '--sbom-format' are no longer available")
    70  	}
    71  
    72  	return SBOMOptions{
    73  		VEXPath: getString(f.VEXPath),
    74  	}, nil
    75  }