cli: Add hook name to gRPC message (#364)

* Make use of gRPC metadatas to pass on Hook-Name. Fixes #362

* Add Hook name in proto.

* Pass the hook name into the hook proto instead of gRPC metadatas.

Co-authored-by: Clément Peyrabère <clement.peyrabere@idcapture.fr>
This commit is contained in:
Clement Peyrabere 2020-03-27 20:48:02 +01:00 committed by GitHub
parent e5e9a74c66
commit acfa974c10
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -37,7 +37,7 @@ func (g *GrpcHook) Setup() error {
func (g *GrpcHook) InvokeHook(typ HookType, info handler.HookEvent, captureOutput bool) ([]byte, int, error) {
ctx := context.Background()
req := &pb.SendRequest{Hook: marshal(info)}
req := &pb.SendRequest{Hook: marshal(typ, info)}
resp, err := g.Client.Send(ctx, req)
if err != nil {
if e, ok := status.FromError(err); ok {
@ -51,7 +51,7 @@ func (g *GrpcHook) InvokeHook(typ HookType, info handler.HookEvent, captureOutpu
return nil, 0, err
}
func marshal(info handler.HookEvent) *pb.Hook {
func marshal(typ HookType, info handler.HookEvent) *pb.Hook {
return &pb.Hook{
Upload: &pb.Upload{
Id: info.Upload.ID,
@ -69,5 +69,6 @@ func marshal(info handler.HookEvent) *pb.Hook {
Uri: info.HTTPRequest.URI,
RemoteAddr: info.HTTPRequest.RemoteAddr,
},
Name: string(typ),
}
}

View File

@ -47,6 +47,8 @@ message Hook {
// HTTPRequest contains details about the HTTP request that reached
// tusd.
HTTPRequest httpRequest = 2;
// The hook name
string name = 3;
}
// Request data to send hook