mirror of
https://github.com/mudler/luet.git
synced 2025-07-12 14:48:28 +00:00
Update go-pluggable
This commit is contained in:
parent
186ac33156
commit
45c8dfa19f
2
go.mod
2
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
|
||||
|
4
go.sum
4
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=
|
||||
|
7
vendor/github.com/mudler/go-pluggable/events.go
generated
vendored
7
vendor/github.com/mudler/go-pluggable/events.go
generated
vendored
@ -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))
|
||||
}
|
||||
|
31
vendor/github.com/mudler/go-pluggable/plugin.go
generated
vendored
31
vendor/github.com/mudler/go-pluggable/plugin.go
generated
vendored
@ -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 {
|
||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user