diff --git a/cmd/tusd/cli/hooks.go b/cmd/tusd/cli/hooks.go index 1bbb254..fe3a03b 100644 --- a/cmd/tusd/cli/hooks.go +++ b/cmd/tusd/cli/hooks.go @@ -1,7 +1,6 @@ package cli import ( - "errors" "strconv" "strings" @@ -162,11 +161,6 @@ func invokeHookSync(typ hooks.HookType, event handler.HookEvent) (httpRes handle httpRes = hookRes.HTTPResponse - if hookRes.Error != "" { - // TODO: Is this actually useful? - return httpRes, errors.New(hookRes.Error) - } - // If the hook response includes the instruction to reject the upload, reuse the error code // and message from ErrUploadRejectedByServer, but also include custom HTTP response values if typ == hooks.HookPreCreate && hookRes.RejectUpload { diff --git a/cmd/tusd/cli/hooks/hooks.go b/cmd/tusd/cli/hooks/hooks.go index 3f3ebbe..4b87faf 100644 --- a/cmd/tusd/cli/hooks/hooks.go +++ b/cmd/tusd/cli/hooks/hooks.go @@ -17,10 +17,6 @@ type HookRequest struct { } type HookResponse struct { - // Error indicates whether a fault occurred while processing the hook request. - // If Error is an empty string, no fault is assumed. - Error string - HTTPResponse handler.HTTPResponse RejectUpload bool diff --git a/cmd/tusd/cli/hooks/plugin.go b/cmd/tusd/cli/hooks/plugin.go index cc33bc0..bd97c25 100644 --- a/cmd/tusd/cli/hooks/plugin.go +++ b/cmd/tusd/cli/hooks/plugin.go @@ -1,13 +1,11 @@ package hooks import ( - "fmt" "log" "net/rpc" "os/exec" "github.com/hashicorp/go-plugin" - "github.com/tus/tusd/pkg/handler" ) // TODO: When the tusd process stops, the plugin does not get properly killed @@ -67,13 +65,6 @@ var pluginMap = map[string]plugin.Plugin{ "hookHandler": &HookHandlerPlugin{}, } -// TODO: Explain, mention that it is internal only -// TODO: Do we actually need this? Maybe not... -type InvokeHookRPCAnswer struct { - HookResponse HookResponse - TusdError *handler.Error // Why is TusdError a pointer -} - // Here is an implementation that talks over RPC type HookHandlerRPC struct{ client *rpc.Client } @@ -83,19 +74,9 @@ func (g *HookHandlerRPC) Setup() error { return err } -func (g *HookHandlerRPC) InvokeHook(req HookRequest) (HookResponse, error) { - var answer InvokeHookRPCAnswer - err := g.client.Call("Plugin.InvokeHook", req, &answer) - fmt.Printf("Client: %#v\n", answer.TusdError) - if err != nil { - return answer.HookResponse, err - } - - if answer.TusdError != nil { - return answer.HookResponse, *answer.TusdError - } - - return answer.HookResponse, nil +func (g *HookHandlerRPC) InvokeHook(req HookRequest) (res HookResponse, err error) { + err = g.client.Call("Plugin.InvokeHook", req, &res) + return res, err } // Here is the RPC server that HookHandlerRPC talks to, conforming to @@ -109,21 +90,9 @@ func (s *HookHandlerRPCServer) Setup(args interface{}, resp *interface{}) error return s.Impl.Setup() } -func (s *HookHandlerRPCServer) InvokeHook(args HookRequest, answer *InvokeHookRPCAnswer) error { - resp, err := s.Impl.InvokeHook(args) - if err != nil { - - if tusdErr, ok := err.(handler.Error); ok { - answer.TusdError = &tusdErr - return nil - } else { - return err - } - } - - answer.HookResponse = resp - - return nil +func (s *HookHandlerRPCServer) InvokeHook(args HookRequest, resp *HookResponse) (err error) { + *resp, err = s.Impl.InvokeHook(args) + return err } // This is the implementation of plugin.Plugin so we can serve/consume this