not working

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman 2020-09-05 11:16:46 -04:00
parent 30bb7cf992
commit c348d97fe0
No known key found for this signature in database
GPG Key ID: 86E2870463D5E890
10 changed files with 50 additions and 18 deletions

View File

@ -84,7 +84,7 @@ func setGlobalCliOptions() {
rootCmd.Flags().CountVarP(&cliOpts.Verbosity, "verbose", "v", "increase verbosity (-v = info, -vv = debug)")
// plugins
defaultPluginDir := path.Join(xdg.ConfigHome, internal.ApplicationName, "plugins")
defaultPluginDir := path.Join(xdg.CacheHome, internal.ApplicationName, "plugins")
flag = "plugins.dir"
rootCmd.Flags().String(
flag, defaultPluginDir,

2
go.mod
View File

@ -17,13 +17,13 @@ require (
github.com/google/uuid v1.1.1
github.com/gookit/color v1.2.7
github.com/gopherjs/gopherjs v0.0.0-20190910122728-9d188e94fb99 // indirect
github.com/hashicorp/go-hclog v0.9.2
github.com/hashicorp/go-multierror v1.1.0
github.com/hashicorp/go-plugin v1.3.0
github.com/hashicorp/go-version v1.2.0
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.3.1
github.com/olekukonko/tablewriter v0.0.4
github.com/opencontainers/runc v0.1.1 // indirect
github.com/package-url/packageurl-go v0.1.0
github.com/pelletier/go-toml v1.8.0
github.com/rogpeppe/go-internal v1.5.2

3
go.sum
View File

@ -131,8 +131,6 @@ github.com/anchore/go-testutils v0.0.0-20200624184116-66aa578126db/go.mod h1:D3r
github.com/anchore/go-version v1.2.2-0.20200701162849-18adb9c92b9b h1:e1bmaoJfZVsCYMrIZBpFxwV26CbsuoEh5muXD5I1Ods=
github.com/anchore/go-version v1.2.2-0.20200701162849-18adb9c92b9b/go.mod h1:Bkc+JYWjMCF8OyZ340IMSIi2Ebf3uwByOk6ho4wne1E=
github.com/anchore/stereoscope v0.0.0-20200520221116-025e07f1c93e/go.mod h1:bkyLl5VITnrmgErv4S1vDfVz/TGAZ5il6161IQo7w2g=
github.com/anchore/stereoscope v0.0.0-20200813152757-548b22c8a0b3 h1:pl+txuYlhK8Mmio4d+4zQI/1xg8X6BtNErTASrx23Wk=
github.com/anchore/stereoscope v0.0.0-20200813152757-548b22c8a0b3/go.mod h1:WntReQTI/I27FOQ87UgLVVzWgku6+ZsqfOTLxpIZFCs=
github.com/anchore/stereoscope v0.0.0-20200903223322-a3806f515470 h1:apXyPyfiaL/YQF7VeXRbDDB9TA7dA9rxdq8YbzPk9ko=
github.com/anchore/stereoscope v0.0.0-20200903223322-a3806f515470/go.mod h1:WntReQTI/I27FOQ87UgLVVzWgku6+ZsqfOTLxpIZFCs=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
@ -518,6 +516,7 @@ github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJ
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jarcoal/httpmock v1.0.5/go.mod h1:ATjnClrvW/3tijVmpL/va5Z3aAyGvqU3gCT8nX0Txik=
github.com/jhump/protoreflect v1.6.0 h1:h5jfMVslIg6l29nsMs0D8Wj17RDVdNYti0vDN/PZZoE=
github.com/jhump/protoreflect v1.6.0/go.mod h1:eaTn3RZAmMBcV0fifFvlm6VHNz3wSkYyXYWUh7ymB74=
github.com/jingyugao/rowserrcheck v0.0.0-20191204022205-72ab7603b68a h1:GmsqmapfzSJkm28dhRoHz2tLRbJmqhU86IPgBtN3mmk=
github.com/jingyugao/rowserrcheck v0.0.0-20191204022205-72ab7603b68a/go.mod h1:xRskid8CManxVta/ALEhJha/pweKBaVG6fWgc0yH25s=

View File

@ -11,7 +11,6 @@ import (
"github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/syft/syft/cataloger/apkdb"
"github.com/anchore/syft/syft/cataloger/bundler"
"github.com/anchore/syft/syft/cataloger/dpkg"
"github.com/anchore/syft/syft/cataloger/golang"
"github.com/anchore/syft/syft/cataloger/java"
"github.com/anchore/syft/syft/cataloger/javascript"
@ -37,7 +36,7 @@ type Cataloger interface {
// All returns a slice of all locally defined catalogers (defined in child packages).
func BuiltIn() []Cataloger {
return []Cataloger{
dpkg.New(),
//dpkg.New(),
bundler.New(),
python.New(),
rpmdb.New(),

View File

@ -13,13 +13,10 @@ import (
// integrity check
var _ plugin.GRPCPlugin = &CatalogerPlugin{}
// Cataloger is the interface exposed as a plugin.
type Cataloger cataloger.Cataloger
// CatalogerPlugin is the implementation of plugin.Plugin that is served/consumed.
type CatalogerPlugin struct {
plugin.NetRPCUnsupportedPlugin
Impl Cataloger
Impl cataloger.Cataloger
}
func (p *CatalogerPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {

View File

@ -3,6 +3,8 @@ package grpc
import (
"context"
"fmt"
"github.com/anchore/syft/internal/log"
"github.com/anchore/syft/syft/cataloger"
"io"
"io/ioutil"
@ -14,6 +16,8 @@ import (
"google.golang.org/grpc"
)
var _ cataloger.Cataloger = &CatalogerClient{}
type CatalogerClient struct {
broker *plugin.GRPCBroker
client proto.CatalogerClient
@ -35,7 +39,7 @@ func (c *CatalogerClient) Name() string {
return resp.Name
}
func (c *CatalogerClient) SelectFiles(resolver scope.FileResolver) error {
func (c *CatalogerClient) SelectFiles(resolver scope.FileResolver) []file.Reference {
fileResolverServer := &FileResolverServer{Impl: resolver}
var s *grpc.Server
@ -49,12 +53,25 @@ func (c *CatalogerClient) SelectFiles(resolver scope.FileResolver) error {
brokerID := c.broker.NextId()
go c.broker.AcceptAndServe(brokerID, serverFunc)
_, err := c.client.SelectFiles(context.Background(), &proto.SelectFilesRequest{
resp, err := c.client.SelectFiles(context.Background(), &proto.SelectFilesRequest{
FileResolverBrokerId: brokerID,
})
log.Debugf("Select Files Response: %+v", resp)
if err != nil {
// TODO: nope
panic(err)
}
s.Stop()
return err
var result []file.Reference
for _, f := range resp.Files {
result = append(result, file.NewFileReferenceWithID(file.Path(f.Path), uint64(f.Id)))
}
return result
}
func (c *CatalogerClient) Catalog(contents map[file.Reference]io.Reader) ([]pkg.Package, error) {

View File

@ -2,6 +2,7 @@ package grpc
import (
"context"
"github.com/anchore/syft/internal/log"
"github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/syft/syft/plugin/proto"
@ -37,6 +38,8 @@ func (m *FileResolverClient) FilesByGlob(patterns ...string) ([]file.Reference,
return nil, err
}
log.Debugf("FilesByGlob Response: %+v", resp)
var result []file.Reference
for _, ref := range resp.Files {
result = append(result, file.NewFileReferenceWithID(file.Path(ref.Path), uint64(ref.Id)))

View File

@ -2,6 +2,7 @@ package grpc
import (
"context"
"github.com/anchore/syft/internal/log"
"github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/syft/syft/plugin/proto"
@ -36,11 +37,15 @@ func (m *FileResolverServer) FilesByPath(ctx context.Context, req *proto.FileRes
}
func (m *FileResolverServer) FilesByGlob(ctx context.Context, req *proto.FileResolverRequest) (resp *proto.FileResolverResponse, err error) {
log.Debugf("FilesByGlob Request: %+v", req)
r, err := m.Impl.FilesByGlob(req.Paths...)
if err != nil {
return nil, err
}
log.Debugf("FilesByGlob Result: %+v", r)
var refs []*proto.FileReference
for _, ref := range r {
refs = append(refs, &proto.FileReference{

View File

@ -2,12 +2,14 @@ package plugin
import (
"fmt"
"github.com/hashicorp/go-hclog"
"os"
"os/exec"
"github.com/hashicorp/go-plugin"
)
var plugins = map[int]plugin.PluginSet{
var versionedPlugins = map[int]plugin.PluginSet{
1: {
TypeCataloger.String(): &CatalogerPlugin{},
},
@ -19,8 +21,10 @@ type Plugin struct {
client *plugin.Client
}
// TODO: type should be in the name like with terraform "terraform-<TYPE>-<NAME>"
func NewPlugin(config Config) Plugin {
cmd := exec.Command(config.Command, config.Args...)
cmd := exec.Command("sh", "-c", config.Command) //, config.Args...)
cmd.Env = append(cmd.Env, config.Env...)
//secureConfig := &plugin.SecureConfig{
@ -28,11 +32,19 @@ func NewPlugin(config Config) Plugin {
// Hash: sha256.New(),
//}
// TODO: temp?
logger := hclog.New(&hclog.LoggerOptions{
Name: config.Name,
Level: hclog.Trace,
Output: os.Stderr,
})
clientConfig := plugin.ClientConfig{
HandshakeConfig: config.Type.HandshakeConfig(),
VersionedPlugins: plugins,
VersionedPlugins: versionedPlugins,
//SecureConfig: secureConfig,
Cmd: cmd,
Cmd: cmd,
Logger: logger,
AllowedProtocols: []plugin.Protocol{
plugin.ProtocolGRPC,
},

View File

@ -63,7 +63,7 @@ func (c *Repository) ActivateCatalogers() ([]cataloger.Cataloger, func(), error)
theCataloger, ok := raw.(cataloger.Cataloger)
if !ok {
return nil, deactivateFn, fmt.Errorf("activation of cataloger did not return a cataloger object (name=%s)", plugin.Config.Name)
return nil, deactivateFn, fmt.Errorf("activation of cataloger did not return a cataloger object (name=%s type=%T)", plugin.Config.Name, theCataloger)
}
result = append(result, theCataloger)