Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

fix(plugin): make output file path configurable by pluginruntimehandler #1941

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/runner/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/deepmap/oapi-codegen/v2 v2.2.0
github.com/docker/docker v26.1.4+incompatible
github.com/docker/go-connections v0.5.0
github.com/google/uuid v1.6.0
github.com/hashicorp/go-multierror v1.1.1
github.com/openclarity/vmclarity/core v0.7.2
github.com/openclarity/vmclarity/plugins/sdk-go v0.7.2
Expand Down Expand Up @@ -54,7 +55,6 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-containerregistry v0.19.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/invopop/yaml v0.2.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand Down
15 changes: 11 additions & 4 deletions plugins/runner/internal/runtimehandler/binary/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"sync"
"syscall"

"github.com/google/uuid"
multierror "github.com/hashicorp/go-multierror"

"github.com/openclarity/vmclarity/plugins/runner/internal/runtimehandler"
Expand All @@ -45,18 +46,20 @@ type binaryRuntimeHandler struct {
stdoutPipe io.ReadCloser
stderrPipe io.ReadCloser

pluginServerEndpoint string
outputFilePath string
pluginDir string
inputDirMountPoint string
pluginServerEndpoint string
ready bool
imageCleanup func()
ready bool

mu sync.Mutex
}

func New(ctx context.Context, config types.PluginConfig) (runtimehandler.PluginRuntimeHandler, error) {
return &binaryRuntimeHandler{
config: config,
config: config,
outputFilePath: fmt.Sprintf("/tmp/%s.json", uuid.New().String()),
}, nil
}

Expand Down Expand Up @@ -196,6 +199,10 @@ func (h *binaryRuntimeHandler) GetPluginServerEndpoint(ctx context.Context) (str
return h.pluginServerEndpoint, nil
}

func (h *binaryRuntimeHandler) GetOutputFilePath(ctx context.Context) (string, error) {
return h.outputFilePath, nil
}

func (h *binaryRuntimeHandler) Logs(ctx context.Context) (io.ReadCloser, error) {
if h.cmd == nil {
return nil, errors.New("plugin process is not running")
Expand All @@ -216,7 +223,7 @@ func (h *binaryRuntimeHandler) Logs(ctx context.Context) (io.ReadCloser, error)
}

func (h *binaryRuntimeHandler) Result(ctx context.Context) (io.ReadCloser, error) {
f, err := os.Open(filepath.Join(h.pluginDir, runtimehandler.RemoteScanResultFileOverride))
f, err := os.Open(filepath.Join(h.pluginDir, h.outputFilePath))
if err != nil {
return nil, fmt.Errorf("unable to open result file: %w", err)
}
Expand Down
4 changes: 4 additions & 0 deletions plugins/runner/internal/runtimehandler/docker/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ func (h *containerRuntimeHandler) GetPluginServerEndpoint(ctx context.Context) (
return "http://" + net.JoinHostPort("127.0.0.1", hostPorts[0].HostPort), nil
}

func (h *containerRuntimeHandler) GetOutputFilePath(ctx context.Context) (string, error) {
return runtimehandler.RemoteScanResultFileOverride, nil
}

func (h *containerRuntimeHandler) Result(ctx context.Context) (io.ReadCloser, error) {
// Copy result file from container
reader, _, err := h.client.CopyFromContainer(ctx, h.containerID, runtimehandler.RemoteScanResultFileOverride)
Expand Down
3 changes: 2 additions & 1 deletion plugins/runner/internal/runtimehandler/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type PluginRuntimeHandler interface {
Start(ctx context.Context) error
Ready() (bool, error)
GetPluginServerEndpoint(ctx context.Context) (string, error)
GetOutputFilePath(ctx context.Context) (string, error)
Logs(ctx context.Context) (io.ReadCloser, error)
Result(ctx context.Context) (io.ReadCloser, error)
Remove(ctx context.Context) error
Expand All @@ -43,7 +44,7 @@ type PluginRuntimeHandler interface {
func WithOverrides(c plugintypes.Config) plugintypes.Config {
return plugintypes.Config{
InputDir: RemoteScanInputDirOverride,
OutputFile: RemoteScanResultFileOverride,
OutputFile: c.OutputFile,
ScannerConfig: c.ScannerConfig,
TimeoutSeconds: c.TimeoutSeconds,
}
Expand Down
7 changes: 6 additions & 1 deletion plugins/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,14 @@ func (r *pluginRunner) Run(ctx context.Context) error {
return errors.New("client missing, did not wait for ready state")
}

_, err := r.client.PostConfigWithResponse(
outputFilePath, err := r.runtimeHandler.GetOutputFilePath(ctx)
if err != nil {
return fmt.Errorf("failed to get plugin output file path: %w", err)
}
_, err = r.client.PostConfigWithResponse(
ctx,
runtimehandler.WithOverrides(plugintypes.Config{
OutputFile: outputFilePath,
ScannerConfig: to.Ptr(r.config.ScannerConfig),
TimeoutSeconds: int(types.ScanTimeout.Seconds()),
}),
Expand Down
Loading