diff --git a/go.mod b/go.mod index b1b5db70..5f091355 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ require ( github.com/moby/sys/mount v0.2.0 // indirect github.com/mudler/cobra-extensions v0.0.0-20200612154940-31a47105fe3d github.com/mudler/docker-companion v0.4.6-0.20200418093252-41846f112d87 - github.com/mudler/go-pluggable v0.0.0-20210510180427-ba09243a8c65 + github.com/mudler/go-pluggable v0.0.0-20210513155700-54c6443073af github.com/mudler/topsort v0.0.0-20201103161459-db5c7901c290 github.com/onsi/ginkgo v1.14.2 github.com/onsi/gomega v1.10.3 diff --git a/go.sum b/go.sum index 2abe5b0b..cc914e30 100644 --- a/go.sum +++ b/go.sum @@ -758,8 +758,8 @@ github.com/mudler/cobra-extensions v0.0.0-20200612154940-31a47105fe3d h1:fKh+rvw github.com/mudler/cobra-extensions v0.0.0-20200612154940-31a47105fe3d/go.mod h1:puRUWSwyecW2V355tKncwPVPRAjQBduPsFjG0mrV/Nw= github.com/mudler/docker-companion v0.4.6-0.20200418093252-41846f112d87 h1:mGz7T8KvmHH0gLWPI5tQne8xl2cO3T8wrrb6Aa16Jxo= github.com/mudler/docker-companion v0.4.6-0.20200418093252-41846f112d87/go.mod h1:1w4zI1LYXDeiUXqedPcrT5eQJnmKR6dbg5iJMgSIP/Y= -github.com/mudler/go-pluggable v0.0.0-20210510180427-ba09243a8c65 h1:Xmfr2g3QU/Ci1mvLswuOhrzXnJ5OXGqAk/skUD1aOsY= -github.com/mudler/go-pluggable v0.0.0-20210510180427-ba09243a8c65/go.mod h1:WmKcT8ONmhDQIqQ+HxU+tkGWjzBEyY/KFO8LTGCu4AI= +github.com/mudler/go-pluggable v0.0.0-20210513155700-54c6443073af h1:jixIxEgLSqu24eMiyzfCI+roa5IaOUhF546ePSFyHeY= +github.com/mudler/go-pluggable v0.0.0-20210513155700-54c6443073af/go.mod h1:WmKcT8ONmhDQIqQ+HxU+tkGWjzBEyY/KFO8LTGCu4AI= github.com/mudler/topsort v0.0.0-20201103161459-db5c7901c290 h1:426hFyXMpXeqIeGJn2cGAW9ogvM2Jf+Jv23gtVPvBLM= github.com/mudler/topsort v0.0.0-20201103161459-db5c7901c290/go.mod h1:uP5BBgFxq2wNWo7n1vnY5SSbgL0WDshVJrOO12tZ/lA= github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= diff --git a/vendor/github.com/mudler/go-pluggable/events.go b/vendor/github.com/mudler/go-pluggable/events.go index 4e4ad958..3e8df3be 100644 --- a/vendor/github.com/mudler/go-pluggable/events.go +++ b/vendor/github.com/mudler/go-pluggable/events.go @@ -29,6 +29,7 @@ type EventType string type Event struct { Name EventType `json:"name"` Data string `json:"data"` + File string `json:"file"` // If Data >> 10K write content to file instead } // EventResponse describes the event response structure @@ -45,6 +46,12 @@ func (e Event) JSON() (string, error) { return string(dat), err } +// Copy returns a copy of Event +func (e Event) Copy() *Event { + copy := &e + return copy +} + func (e Event) ResponseEventName(s string) EventType { return EventType(fmt.Sprintf("%s-%s", e.Name, s)) } diff --git a/vendor/github.com/mudler/go-pluggable/plugin.go b/vendor/github.com/mudler/go-pluggable/plugin.go index 35062ac6..0c706017 100644 --- a/vendor/github.com/mudler/go-pluggable/plugin.go +++ b/vendor/github.com/mudler/go-pluggable/plugin.go @@ -16,7 +16,9 @@ package pluggable import ( + "bytes" "encoding/json" + "io/ioutil" "os" "os/exec" @@ -29,19 +31,42 @@ type Plugin struct { Executable string } +// A safe threshold to avoid unpleasant exec buffer fill for argv too big. Seems 128K is the limit on Linux. +const maxMessageSize = 1 << 13 + // Run runs the Event on the plugin, and returns an EventResponse func (p Plugin) Run(e Event) (EventResponse, error) { r := EventResponse{} - k, err := e.JSON() + + eventToprocess := &e + + if len(e.Data) > maxMessageSize { + copy := e.Copy() + copy.Data = "" + f, err := ioutil.TempFile(os.TempDir(), "pluggable") + if err != nil { + return r, errors.Wrap(err, "while creating temporary file") + } + if err := ioutil.WriteFile(f.Name(), []byte(e.Data), os.ModePerm); err != nil { + return r, errors.Wrap(err, "while writing to temporary file") + } + copy.File = f.Name() + eventToprocess = copy + defer os.RemoveAll(f.Name()) + } + + k, err := eventToprocess.JSON() if err != nil { return r, errors.Wrap(err, "while marshalling event") } cmd := exec.Command(p.Executable, string(e.Name), k) cmd.Env = os.Environ() + var b bytes.Buffer + cmd.Stderr = &b out, err := cmd.Output() if err != nil { - r.Error = err.Error() - return r, errors.Wrap(err, "while executing plugin") + r.Error = "error while executing plugin: " + err.Error() + string(b.String()) + return r, errors.Wrap(err, "while executing plugin: "+string(b.String())) } if err := json.Unmarshal(out, &r); err != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index e76c3ccc..0397a5be 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -475,7 +475,7 @@ github.com/mudler/cobra-extensions # github.com/mudler/docker-companion v0.4.6-0.20200418093252-41846f112d87 ## explicit github.com/mudler/docker-companion/api -# github.com/mudler/go-pluggable v0.0.0-20210510180427-ba09243a8c65 +# github.com/mudler/go-pluggable v0.0.0-20210513155700-54c6443073af ## explicit github.com/mudler/go-pluggable # github.com/mudler/topsort v0.0.0-20201103161459-db5c7901c290