From 754aee8c3fd7a1b7aa638e043db55a19db8dbda8 Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 19 Oct 2021 17:38:27 +0200 Subject: [PATCH] ci: Remove plugin hook handler --- cmd/tusd/cli/flags.go | 2 -- cmd/tusd/cli/hooks.go | 6 ---- cmd/tusd/cli/hooks/plugin.go | 69 ------------------------------------ 3 files changed, 77 deletions(-) delete mode 100644 cmd/tusd/cli/hooks/plugin.go diff --git a/cmd/tusd/cli/flags.go b/cmd/tusd/cli/flags.go index 1e2c597..aed407c 100644 --- a/cmd/tusd/cli/flags.go +++ b/cmd/tusd/cli/flags.go @@ -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") diff --git a/cmd/tusd/cli/hooks.go b/cmd/tusd/cli/hooks.go index 2c7bcf3..c6e26c5 100644 --- a/cmd/tusd/cli/hooks.go +++ b/cmd/tusd/cli/hooks.go @@ -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 } diff --git a/cmd/tusd/cli/hooks/plugin.go b/cmd/tusd/cli/hooks/plugin.go deleted file mode 100644 index 8821527..0000000 --- a/cmd/tusd/cli/hooks/plugin.go +++ /dev/null @@ -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 -}