ci: Remove plugin hook handler

This commit is contained in:
Marius 2021-10-19 17:38:27 +02:00
parent bc51cb05c0
commit 754aee8c3f
3 changed files with 0 additions and 77 deletions

View File

@ -46,7 +46,6 @@ var Flags struct {
GrpcHooksRetry int
GrpcHooksBackoff int
HooksStopUploadCode int
PluginHookPath string
EnabledHooks []hooks.HookType
ShowVersion bool
ExposeMetrics bool
@ -98,7 +97,6 @@ func ParseFlags() {
flag.IntVar(&Flags.GrpcHooksRetry, "hooks-grpc-retry", 3, "Number of times to retry on a server error or network timeout")
flag.IntVar(&Flags.GrpcHooksBackoff, "hooks-grpc-backoff", 1, "Number of seconds to wait before retrying each retry")
flag.IntVar(&Flags.HooksStopUploadCode, "hooks-stop-code", 0, "Return code from post-receive hook which causes tusd to stop and delete the current upload. A zero value means that no uploads will be stopped")
flag.StringVar(&Flags.PluginHookPath, "hooks-plugin", "", "Path to a Go plugin for loading hook functions (only supported on Linux and macOS; highly EXPERIMENTAL and may BREAK in the future)")
flag.BoolVar(&Flags.ShowVersion, "version", false, "Print tusd version information")
flag.BoolVar(&Flags.ExposeMetrics, "expose-metrics", true, "Expose metrics about tusd usage")
flag.StringVar(&Flags.MetricsPath, "metrics-path", "/metrics", "Path under which the metrics endpoint will be accessible")

View File

@ -82,12 +82,6 @@ func SetupPreHooks(config *handler.Config) error {
MaxRetries: Flags.GrpcHooksRetry,
Backoff: Flags.GrpcHooksBackoff,
}
} else if Flags.PluginHookPath != "" {
stdout.Printf("Using '%s' to load plugin for hooks", Flags.PluginHookPath)
hookHandler = &hooks.PluginHook{
Path: Flags.PluginHookPath,
}
} else {
return nil
}

View File

@ -1,69 +0,0 @@
package hooks
import (
"fmt"
"plugin"
"github.com/tus/tusd/pkg/handler"
)
type PluginHookHandler interface {
PreCreate(info handler.HookEvent) error
PostCreate(info handler.HookEvent) error
PostReceive(info handler.HookEvent) error
PostFinish(info handler.HookEvent) error
PostTerminate(info handler.HookEvent) error
PreFinish(info handler.HookEvent) error
}
type PluginHook struct {
Path string
handler PluginHookHandler
}
func (h *PluginHook) Setup() error {
p, err := plugin.Open(h.Path)
if err != nil {
return err
}
symbol, err := p.Lookup("TusdHookHandler")
if err != nil {
return err
}
handler, ok := symbol.(*PluginHookHandler)
if !ok {
return fmt.Errorf("hooks: could not cast TusdHookHandler from %s into PluginHookHandler interface", h.Path)
}
h.handler = *handler
return nil
}
func (h PluginHook) InvokeHook(typ HookType, info handler.HookEvent, captureOutput bool) ([]byte, int, error) {
var err error
switch typ {
case HookPostFinish:
err = h.handler.PostFinish(info)
case HookPostTerminate:
err = h.handler.PostTerminate(info)
case HookPostReceive:
err = h.handler.PostReceive(info)
case HookPostCreate:
err = h.handler.PostCreate(info)
case HookPreCreate:
err = h.handler.PreCreate(info)
case HookPreFinish:
err = h.handler.PreFinish(info)
default:
err = fmt.Errorf("hooks: unknown hook named %s", typ)
}
if err != nil {
return nil, 1, err
}
return nil, 0, nil
}