github.com/anchore/syft@v1.38.2/cmd/syft/internal/options/golang.go (about) 1 package options 2 3 import ( 4 "strings" 5 6 "github.com/anchore/clio" 7 "github.com/anchore/syft/syft/pkg/cataloger/golang" 8 ) 9 10 type golangConfig struct { 11 SearchLocalModCacheLicenses *bool `json:"search-local-mod-cache-licenses" yaml:"search-local-mod-cache-licenses" mapstructure:"search-local-mod-cache-licenses"` 12 LocalModCacheDir string `json:"local-mod-cache-dir" yaml:"local-mod-cache-dir" mapstructure:"local-mod-cache-dir"` 13 SearchLocalVendorLicenses *bool `json:"search-local-vendor-licenses" yaml:"search-local-vendor-licenses" mapstructure:"search-local-vendor-licenses"` 14 LocalVendorDir string `json:"local-vendor-dir" yaml:"local-vendor-dir" mapstructure:"local-vendor-dir"` 15 SearchRemoteLicenses *bool `json:"search-remote-licenses" yaml:"search-remote-licenses" mapstructure:"search-remote-licenses"` 16 Proxy string `json:"proxy" yaml:"proxy" mapstructure:"proxy"` 17 NoProxy string `json:"no-proxy" yaml:"no-proxy" mapstructure:"no-proxy"` 18 MainModuleVersion golangMainModuleVersionConfig `json:"main-module-version" yaml:"main-module-version" mapstructure:"main-module-version"` 19 } 20 21 var _ interface { 22 clio.FieldDescriber 23 } = (*golangConfig)(nil) 24 25 func (o *golangConfig) DescribeFields(descriptions clio.FieldDescriptionSet) { 26 descriptions.Add(&o.SearchLocalModCacheLicenses, `search for go package licences in the GOPATH of the system running Syft, note that this is outside the 27 container filesystem and potentially outside the root of a local directory scan`) 28 descriptions.Add(&o.LocalModCacheDir, `specify an explicit go mod cache directory, if unset this defaults to $GOPATH/pkg/mod or $HOME/go/pkg/mod`) 29 descriptions.Add(&o.SearchLocalVendorLicenses, `search for go package licences in the vendor folder on the system running Syft, note that this is outside the 30 container filesystem and potentially outside the root of a local directory scan`) 31 descriptions.Add(&o.LocalVendorDir, `specify an explicit go vendor directory, if unset this defaults to ./vendor`) 32 descriptions.Add(&o.SearchRemoteLicenses, `search for go package licences by retrieving the package from a network proxy`) 33 descriptions.Add(&o.Proxy, `remote proxy to use when retrieving go packages from the network, 34 if unset this defaults to $GOPROXY followed by https://proxy.golang.org`) 35 descriptions.Add(&o.NoProxy, `specifies packages which should not be fetched by proxy 36 if unset this defaults to $GONOPROXY`) 37 descriptions.Add(&o.MainModuleVersion, `the go main module version discovered from binaries built with the go compiler will 38 always show (devel) as the version. Use these options to control heuristics to guess 39 a more accurate version from the binary.`) 40 descriptions.Add(&o.MainModuleVersion.FromLDFlags, `look for LD flags that appear to be setting a version (e.g. -X main.version=1.0.0)`) 41 descriptions.Add(&o.MainModuleVersion.FromBuildSettings, `use the build settings (e.g. vcs.version & vcs.time) to craft a v0 pseudo version 42 (e.g. v0.0.0-20220308212642-53e6d0aaf6fb) when a more accurate version cannot be found otherwise`) 43 descriptions.Add(&o.MainModuleVersion.FromContents, `search for semver-like strings in the binary contents`) 44 } 45 46 type golangMainModuleVersionConfig struct { 47 FromLDFlags bool `json:"from-ld-flags" yaml:"from-ld-flags" mapstructure:"from-ld-flags"` 48 FromContents bool `json:"from-contents" yaml:"from-contents" mapstructure:"from-contents"` 49 FromBuildSettings bool `json:"from-build-settings" yaml:"from-build-settings" mapstructure:"from-build-settings"` 50 } 51 52 func defaultGolangConfig() golangConfig { 53 def := golang.DefaultCatalogerConfig() 54 return golangConfig{ 55 SearchLocalModCacheLicenses: nil, // this defaults to false, which is the API default 56 LocalModCacheDir: def.LocalModCacheDir, 57 SearchLocalVendorLicenses: nil, // this defaults to false, which is the API default 58 LocalVendorDir: def.LocalVendorDir, 59 SearchRemoteLicenses: nil, // this defaults to false, which is the API default 60 Proxy: strings.Join(def.Proxies, ","), 61 NoProxy: strings.Join(def.NoProxy, ","), 62 MainModuleVersion: golangMainModuleVersionConfig{ 63 FromLDFlags: def.MainModuleVersion.FromLDFlags, 64 FromContents: def.MainModuleVersion.FromContents, 65 FromBuildSettings: def.MainModuleVersion.FromBuildSettings, 66 }, 67 } 68 }