diff --git a/.github/workflows/validations.yaml b/.github/workflows/validations.yaml index f3dacae6e..e29cc2e78 100644 --- a/.github/workflows/validations.yaml +++ b/.github/workflows/validations.yaml @@ -305,6 +305,10 @@ jobs: needs: [Build-Snapshot-Artifacts] runs-on: ubuntu-20.04 steps: + - uses: actions/setup-go@v2 + with: + go-version: ${{ env.GO_VERSION }} + - uses: actions/checkout@v2 - name: Restore go cache diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 2317d3bbf..c9f5d5053 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -12,8 +12,7 @@ builds: env: - CGO_ENABLED=0 goos: - # windows not supported yet (due to jotframe) - # - windows + - windows - linux goarch: - amd64 @@ -27,7 +26,7 @@ builds: -X github.com/anchore/syft/internal/version.gitCommit={{.Commit}} -X github.com/anchore/syft/internal/version.buildDate={{.Date}} -X github.com/anchore/syft/internal/version.gitTreeState={{.Env.BUILD_GIT_TREE_STATE}} - # For more info on this macOS build, see: https://github.com/mitchellh/gon#usage-with-goreleaser + # For more info on this macOS build, see: https://github.com/mitchellh/gon#usage-with-goreleaser - binary: syft id: syft-macos env: diff --git a/cmd/root.go b/cmd/root.go index cb131972e..3792aad7b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -33,6 +33,7 @@ func init() { flag, "q", false, "suppress all logging output", ) + if err := viper.BindPFlag(flag, rootCmd.PersistentFlags().Lookup(flag)); err != nil { fmt.Printf("unable to bind flag '%s': %+v", flag, err) os.Exit(1) diff --git a/go.mod b/go.mod index b8457139a..9b1d4c633 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ require ( github.com/anchore/go-testutils v0.0.0-20200925183923-d5f45b0d3c04 github.com/anchore/go-version v1.2.2-0.20200701162849-18adb9c92b9b github.com/anchore/packageurl-go v0.0.0-20210922164639-b3fa992ebd29 - github.com/anchore/stereoscope v0.0.0-20211005213828-538011008578 + github.com/anchore/stereoscope v0.0.0-20211021140357-9f8395cd95af github.com/antihax/optional v1.0.0 github.com/bmatcuk/doublestar/v2 v2.0.4 github.com/docker/docker v17.12.0-ce-rc1.0.20200309214505-aa6a9891b09c+incompatible diff --git a/go.sum b/go.sum index 88aeb92a0..6571e6dbe 100644 --- a/go.sum +++ b/go.sum @@ -116,8 +116,8 @@ github.com/anchore/go-version v1.2.2-0.20200701162849-18adb9c92b9b h1:e1bmaoJfZV github.com/anchore/go-version v1.2.2-0.20200701162849-18adb9c92b9b/go.mod h1:Bkc+JYWjMCF8OyZ340IMSIi2Ebf3uwByOk6ho4wne1E= github.com/anchore/packageurl-go v0.0.0-20210922164639-b3fa992ebd29 h1:K9LfnxwhqvihqU0+MF325FNy7fsKV9EGaUxdfR4gnWk= github.com/anchore/packageurl-go v0.0.0-20210922164639-b3fa992ebd29/go.mod h1:Oc1UkGaJwY6ND6vtAqPSlYrptKRJngHwkwB6W7l1uP0= -github.com/anchore/stereoscope v0.0.0-20211005213828-538011008578 h1:gSpftl0RWfdTwlPmsOLgEawHIw16xwwG1mFD/wrVDRE= -github.com/anchore/stereoscope v0.0.0-20211005213828-538011008578/go.mod h1:kL7jfbXblrDcBhu5ja/s+VTYL3Mzof4eQNMJiSqcwXQ= +github.com/anchore/stereoscope v0.0.0-20211021140357-9f8395cd95af h1:0w24yOOJx6DiaLvptAfp/Mro2cQkEcR7P1WRbL2apHw= +github.com/anchore/stereoscope v0.0.0-20211021140357-9f8395cd95af/go.mod h1:Rqltg0KqVKoDy4kCuJMLPFDfUg7pEmSqUEA9pOO1L7c= github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8= github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= @@ -147,6 +147,8 @@ github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb/go.mod h1:PkYb9DJNAw github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/bmatcuk/doublestar/v2 v2.0.4 h1:6I6oUiT/sU27eE2OFcWqBhL1SwjyvQuOssxT4a1yidI= github.com/bmatcuk/doublestar/v2 v2.0.4/go.mod h1:QMmcs3H2AUQICWhfzLXz+IYln8lRQmTZRptLie8RgRw= +github.com/bmatcuk/doublestar/v4 v4.0.2 h1:X0krlUVAVmtr2cRoTqR8aDMrDqnB36ht8wpWTiQ3jsA= +github.com/bmatcuk/doublestar/v4 v4.0.2/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= github.com/bombsimon/wsl/v2 v2.0.0/go.mod h1:mf25kr/SqFEPhhcxW1+7pxzGlW+hIl/hYTKY95VwV8U= github.com/bombsimon/wsl/v2 v2.2.0/go.mod h1:Azh8c3XGEJl9LyX0/sFC+CKMc7Ssgua0g+6abzXN4Pg= github.com/bombsimon/wsl/v3 v3.0.0/go.mod h1:st10JtZYLE4D5sC7b8xV4zTKZwAQjCH/Hy2Pm1FNZIc= diff --git a/internal/ui/common_event_handlers.go b/internal/ui/common_event_handlers.go new file mode 100644 index 000000000..7617e0b98 --- /dev/null +++ b/internal/ui/common_event_handlers.go @@ -0,0 +1,24 @@ +package ui + +import ( + "fmt" + "io" + + syftEventParsers "github.com/anchore/syft/syft/event/parsers" + "github.com/wagoodman/go-partybus" +) + +// handleCatalogerPresenterReady is a UI function for processing the CatalogerFinished bus event, displaying the catalog +// via the given presenter to stdout. +func handleCatalogerPresenterReady(event partybus.Event, reportOutput io.Writer) error { + // show the report to stdout + pres, err := syftEventParsers.ParsePresenterReady(event) + if err != nil { + return fmt.Errorf("bad CatalogerFinished event: %w", err) + } + + if err := pres.Present(reportOutput); err != nil { + return fmt.Errorf("unable to show package catalog report: %w", err) + } + return nil +} diff --git a/internal/ui/ephemeral_terminal_ui.go b/internal/ui/ephemeral_terminal_ui.go index 289b34a05..964a59479 100644 --- a/internal/ui/ephemeral_terminal_ui.go +++ b/internal/ui/ephemeral_terminal_ui.go @@ -1,3 +1,6 @@ +//go:build linux || darwin +// +build linux darwin + package ui import ( diff --git a/internal/ui/event_handlers.go b/internal/ui/etui_event_handlers.go similarity index 60% rename from internal/ui/event_handlers.go rename to internal/ui/etui_event_handlers.go index 8daf70688..fcd998e44 100644 --- a/internal/ui/event_handlers.go +++ b/internal/ui/etui_event_handlers.go @@ -1,3 +1,6 @@ +//go:build linux || darwin +// +build linux darwin + package ui import ( @@ -14,21 +17,6 @@ import ( "github.com/wagoodman/go-partybus" ) -// handleCatalogerPresenterReady is a UI function for processing the CatalogerFinished bus event, displaying the catalog -// via the given presenter to stdout. -func handleCatalogerPresenterReady(event partybus.Event, reportOutput io.Writer) error { - // show the report to stdout - pres, err := syftEventParsers.ParsePresenterReady(event) - if err != nil { - return fmt.Errorf("bad CatalogerFinished event: %w", err) - } - - if err := pres.Present(reportOutput); err != nil { - return fmt.Errorf("unable to show package catalog report: %w", err) - } - return nil -} - // handleAppUpdateAvailable is a UI handler function to display a new application version to the top of the screen. func handleAppUpdateAvailable(_ context.Context, fr *frame.Frame, event partybus.Event, _ *sync.WaitGroup) error { newVersion, err := syftEventParsers.ParseAppUpdateAvailable(event) diff --git a/internal/ui/select.go b/internal/ui/select.go index 39e036c3b..55071b0e1 100644 --- a/internal/ui/select.go +++ b/internal/ui/select.go @@ -1,3 +1,6 @@ +//go:build linux || darwin +// +build linux darwin + package ui import ( diff --git a/internal/ui/select_windows.go b/internal/ui/select_windows.go new file mode 100644 index 000000000..20e7e58f9 --- /dev/null +++ b/internal/ui/select_windows.go @@ -0,0 +1,17 @@ +//go:build windows +// +build windows + +package ui + +import ( + "io" +) + +// Select is responsible for determining the specific UI function given select user option, the current platform +// config values, and environment status (such as a TTY being present). The first UI in the returned slice of UIs +// is intended to be used and the UIs that follow are meant to be attempted only in a fallback posture when there +// are environmental problems (e.g. cannot write to the terminal). A writer is provided to capture the output of +// the final SBOM report. +func Select(verbose, quiet bool, reportWriter io.Writer) (uis []UI) { + return append(uis, NewLoggerUI(reportWriter)) +} diff --git a/syft/source/file_details.go b/syft/source/file_details.go new file mode 100644 index 000000000..f656c071d --- /dev/null +++ b/syft/source/file_details.go @@ -0,0 +1,21 @@ +//go:build linux || darwin +// +build linux darwin + +package source + +import ( + "os" + "syscall" +) + +// GetXid is the UID GID system info for unix +func GetXid(info os.FileInfo) (uid, gid int) { + uid = -1 + gid = -1 + if stat, ok := info.Sys().(*syscall.Stat_t); ok { + uid = int(stat.Uid) + gid = int(stat.Gid) + } + + return uid, gid +} diff --git a/syft/source/file_details_win.go b/syft/source/file_details_win.go new file mode 100644 index 000000000..31fd05063 --- /dev/null +++ b/syft/source/file_details_win.go @@ -0,0 +1,13 @@ +//go:build windows +// +build windows + +package source + +import ( + "os" +) + +// GetXid is a placeholder for windows file information +func GetXid(info os.FileInfo) (uid, gid int) { + return -1, -1 +} diff --git a/syft/source/file_metadata.go b/syft/source/file_metadata.go index ac9d18de8..463c336bc 100644 --- a/syft/source/file_metadata.go +++ b/syft/source/file_metadata.go @@ -2,7 +2,6 @@ package source import ( "os" - "syscall" "github.com/anchore/syft/internal/log" @@ -39,12 +38,7 @@ func fileMetadataByLocation(img *image.Image, location Location) (FileMetadata, } func fileMetadataFromPath(path string, info os.FileInfo) FileMetadata { - uid := -1 - gid := -1 - if stat, ok := info.Sys().(*syscall.Stat_t); ok { - uid = int(stat.Uid) - gid = int(stat.Gid) - } + uid, gid := GetXid(info) f, err := os.Open(path) if err != nil {