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

Commit

Permalink
fix(plugin): make output file path configurable by plugin runtime han…
Browse files Browse the repository at this point in the history
…dler
  • Loading branch information
zsoltkacsandi committed Jul 22, 2024
1 parent c2b984b commit b74d467
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
13 changes: 10 additions & 3 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 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
2 changes: 1 addition & 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,6 @@ type PluginRuntimeHandler interface {
func WithOverrides(c plugintypes.Config) plugintypes.Config {
return plugintypes.Config{
InputDir: RemoteScanInputDirOverride,
OutputFile: RemoteScanResultFileOverride,
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

0 comments on commit b74d467

Please sign in to comment.