Export the presenter interface so it may be used by external projects

Signed-off-by: Samuel Dacanay <sam.dacanay@anchore.com>
This commit is contained in:
Samuel Dacanay 2021-06-09 09:36:52 -07:00 committed by Sam Dacanay
parent 801e662633
commit 5a2e2eb679
7 changed files with 14 additions and 11 deletions

View File

@ -6,13 +6,14 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"github.com/anchore/syft/syft/presenter/packages"
"github.com/spf13/viper" "github.com/spf13/viper"
"github.com/anchore/syft/internal" "github.com/anchore/syft/internal"
"github.com/anchore/syft/internal/anchore" "github.com/anchore/syft/internal/anchore"
"github.com/anchore/syft/internal/bus" "github.com/anchore/syft/internal/bus"
"github.com/anchore/syft/internal/log" "github.com/anchore/syft/internal/log"
"github.com/anchore/syft/internal/presenter/packages"
"github.com/anchore/syft/internal/ui" "github.com/anchore/syft/internal/ui"
"github.com/anchore/syft/syft" "github.com/anchore/syft/syft"
"github.com/anchore/syft/syft/distro" "github.com/anchore/syft/syft/distro"

View File

@ -6,9 +6,9 @@ package parsers
import ( import (
"fmt" "fmt"
"github.com/anchore/syft/syft/file" "github.com/anchore/syft/syft/presenter"
"github.com/anchore/syft/internal/presenter" "github.com/anchore/syft/syft/file"
"github.com/wagoodman/go-progress" "github.com/wagoodman/go-progress"

View File

@ -5,20 +5,21 @@ a specific Presenter implementation given user configuration.
package packages package packages
import ( import (
"github.com/anchore/syft/internal/presenter" "github.com/anchore/syft/internal/presenter/packages"
"github.com/anchore/syft/syft/presenter"
) )
// Presenter returns a presenter for images or directories // Presenter returns a presenter for images or directories
func Presenter(option PresenterOption, config PresenterConfig) presenter.Presenter { func Presenter(option PresenterOption, config PresenterConfig) presenter.Presenter {
switch option { switch option {
case JSONPresenterOption: case JSONPresenterOption:
return NewJSONPresenter(config.Catalog, config.SourceMetadata, config.Distro, config.Scope) return packages.NewJSONPresenter(config.Catalog, config.SourceMetadata, config.Distro, config.Scope)
case TextPresenterOption: case TextPresenterOption:
return NewTextPresenter(config.Catalog, config.SourceMetadata) return packages.NewTextPresenter(config.Catalog, config.SourceMetadata)
case TablePresenterOption: case TablePresenterOption:
return NewTablePresenter(config.Catalog) return packages.NewTablePresenter(config.Catalog)
case CycloneDxPresenterOption: case CycloneDxPresenterOption:
return NewCycloneDxPresenter(config.Catalog, config.SourceMetadata) return packages.NewCycloneDxPresenter(config.Catalog, config.SourceMetadata)
default: default:
return nil return nil
} }

View File

@ -3,9 +3,10 @@ package integration
import ( import (
"bytes" "bytes"
"encoding/json" "encoding/json"
exportedPackages "github.com/anchore/syft/syft/presenter/packages"
"testing" "testing"
"github.com/anchore/syft/internal/presenter/packages" internalPackages "github.com/anchore/syft/internal/presenter/packages"
) )
func TestPackageOwnershipRelationships(t *testing.T) { func TestPackageOwnershipRelationships(t *testing.T) {
@ -23,7 +24,7 @@ func TestPackageOwnershipRelationships(t *testing.T) {
t.Run(test.fixture, func(t *testing.T) { t.Run(test.fixture, func(t *testing.T) {
catalog, d, src := catalogFixtureImage(t, test.fixture) catalog, d, src := catalogFixtureImage(t, test.fixture)
p := packages.Presenter(packages.JSONPresenterOption, packages.PresenterConfig{ p := exportedPackages.Presenter(exportedPackages.JSONPresenterOption, exportedPackages.PresenterConfig{
SourceMetadata: src.Metadata, SourceMetadata: src.Metadata,
Catalog: catalog, Catalog: catalog,
Distro: d, Distro: d,
@ -38,7 +39,7 @@ func TestPackageOwnershipRelationships(t *testing.T) {
t.Fatalf("unable to present: %+v", err) t.Fatalf("unable to present: %+v", err)
} }
var doc packages.JSONDocument var doc internalPackages.JSONDocument
decoder := json.NewDecoder(output) decoder := json.NewDecoder(output)
if err := decoder.Decode(&doc); err != nil { if err := decoder.Decode(&doc); err != nil {
t.Fatalf("unable to decode json doc: %+v", err) t.Fatalf("unable to decode json doc: %+v", err)