syft/syft/plugin/grpc/file_resolver_server.go
Alex Goodman 3e27b6e93f
rough draft for plugin system
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
2020-09-02 23:34:00 -04:00

56 lines
1.2 KiB
Go

package grpc
import (
"context"
"github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/syft/syft/plugin/proto"
"github.com/anchore/syft/syft/scope"
)
type FileResolverServer struct {
Impl scope.FileResolver
}
func (m *FileResolverServer) FilesByPath(ctx context.Context, req *proto.FileResolverRequest) (resp *proto.FileResolverResponse, err error) {
var paths []file.Path
for _, p := range req.Paths {
paths = append(paths, file.Path(p))
}
r, err := m.Impl.FilesByPath(paths...)
if err != nil {
return nil, err
}
var refs []*proto.FileReference
for _, ref := range r {
refs = append(refs, &proto.FileReference{
Id: int64(ref.ID()),
Path: string(ref.Path),
})
}
return &proto.FileResolverResponse{
Files: refs,
}, nil
}
func (m *FileResolverServer) FilesByGlob(ctx context.Context, req *proto.FileResolverRequest) (resp *proto.FileResolverResponse, err error) {
r, err := m.Impl.FilesByGlob(req.Paths...)
if err != nil {
return nil, err
}
var refs []*proto.FileReference
for _, ref := range r {
refs = append(refs, &proto.FileReference{
Id: int64(ref.ID()),
Path: string(ref.Path),
})
}
return &proto.FileResolverResponse{
Files: refs,
}, nil
}