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