-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add some README.md to guide usage - fix grpc example Makefile proto path
- Loading branch information
Showing
11 changed files
with
913 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Run file hook exemple | ||
|
||
tusd -hooks-dir=./ -hooks-enabled-events=pre-create,pre-finish,pre-access,post-create,post-receive,post-terminate,post-finish | ||
|
||
Adapt enabled-events hooks list for your needs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/sh | ||
|
||
# This example demonstrates how to read the hook event details | ||
# from stdin, and output debug messages. | ||
|
||
# We use >&2 to write debugging output to stderr. tusd | ||
# will forward these to its stderr. Any output from the | ||
# hook on stdout will be captured by tusd and interpreted | ||
# as a response. | ||
cat /dev/stdin | jq . >&2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
hook_pb2.py: ../../../cmd/tusd/cli/hooks/proto/v2/hook.proto | ||
python3 -m grpc_tools.protoc --proto_path=../../../cmd/tusd/cli/hooks/proto/v2/ hook.proto --python_out=. --grpc_python_out=. | ||
hook_pb2.py: ../../../pkg/hooks/grpc/proto/hook.proto | ||
python3 -m grpc_tools.protoc --proto_path=../../../pkg/hooks/grpc/proto/ hook.proto --python_out=. --grpc_python_out=. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Run grpc hook exemple | ||
|
||
python3 server.py | ||
|
||
tusd -hooks-grpc=localhost:8000 -hooks-enabled-events=pre-create,pre-finish,pre-access,post-create,post-receive,post-terminate,post-finish | ||
|
||
Adapt enabled-events hooks list for your needs. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,50 @@ | ||
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! | ||
"""Client and server classes corresponding to protobuf-defined services.""" | ||
import grpc | ||
|
||
import hook_pb2 as hook__pb2 | ||
|
||
|
||
class HookHandlerStub(object): | ||
"""The hook service definition. | ||
""" | ||
"""The hook service definition. | ||
""" | ||
|
||
def __init__(self, channel): | ||
"""Constructor. | ||
def __init__(self, channel): | ||
"""Constructor. | ||
Args: | ||
channel: A grpc.Channel. | ||
""" | ||
self.InvokeHook = channel.unary_unary( | ||
'/v2.HookHandler/InvokeHook', | ||
request_serializer=hook__pb2.HookRequest.SerializeToString, | ||
response_deserializer=hook__pb2.HookResponse.FromString, | ||
) | ||
Args: | ||
channel: A grpc.Channel. | ||
""" | ||
self.InvokeHook = channel.unary_unary( | ||
'/proto.HookHandler/InvokeHook', | ||
request_serializer=hook__pb2.HookRequest.SerializeToString, | ||
response_deserializer=hook__pb2.HookResponse.FromString, | ||
) | ||
|
||
|
||
class HookHandlerServicer(object): | ||
"""The hook service definition. | ||
"""The hook service definition. | ||
""" | ||
|
||
def InvokeHook(self, request, context): | ||
"""InvokeHook is invoked for every hook that is executed. HookRequest contains the | ||
corresponding information about the hook type, the involved upload, and | ||
causing HTTP request. | ||
The return value HookResponse allows to stop or reject an upload, as well as modifying | ||
the HTTP response. See the documentation for HookResponse for more details. | ||
""" | ||
|
||
def InvokeHook(self, request, context): | ||
"""InvokeHook is invoked for every hook that is executed. HookRequest contains the | ||
corresponding information about the hook type, the involved upload, and | ||
causing HTTP request. | ||
The return value HookResponse allows to stop or reject an upload, as well as modifying | ||
the HTTP response. See the documentation for HookResponse for more details. | ||
""" | ||
context.set_code(grpc.StatusCode.UNIMPLEMENTED) | ||
context.set_details('Method not implemented!') | ||
raise NotImplementedError('Method not implemented!') | ||
context.set_code(grpc.StatusCode.UNIMPLEMENTED) | ||
context.set_details('Method not implemented!') | ||
raise NotImplementedError('Method not implemented!') | ||
|
||
|
||
def add_HookHandlerServicer_to_server(servicer, server): | ||
rpc_method_handlers = { | ||
'InvokeHook': grpc.unary_unary_rpc_method_handler( | ||
servicer.InvokeHook, | ||
request_deserializer=hook__pb2.HookRequest.FromString, | ||
response_serializer=hook__pb2.HookResponse.SerializeToString, | ||
), | ||
} | ||
generic_handler = grpc.method_handlers_generic_handler( | ||
'v2.HookHandler', rpc_method_handlers) | ||
server.add_generic_rpc_handlers((generic_handler,)) | ||
|
||
|
||
# This class is part of an EXPERIMENTAL API. | ||
class HookHandler(object): | ||
"""The hook service definition. | ||
""" | ||
|
||
@staticmethod | ||
def InvokeHook(request, | ||
target, | ||
options=(), | ||
channel_credentials=None, | ||
call_credentials=None, | ||
insecure=False, | ||
compression=None, | ||
wait_for_ready=None, | ||
timeout=None, | ||
metadata=None): | ||
return grpc.experimental.unary_unary(request, target, '/v2.HookHandler/InvokeHook', | ||
hook__pb2.HookRequest.SerializeToString, | ||
hook__pb2.HookResponse.FromString, | ||
options, channel_credentials, | ||
insecure, call_credentials, compression, wait_for_ready, timeout, metadata) | ||
rpc_method_handlers = { | ||
'InvokeHook': grpc.unary_unary_rpc_method_handler( | ||
servicer.InvokeHook, | ||
request_deserializer=hook__pb2.HookRequest.FromString, | ||
response_serializer=hook__pb2.HookResponse.SerializeToString, | ||
), | ||
} | ||
generic_handler = grpc.method_handlers_generic_handler( | ||
'proto.HookHandler', rpc_method_handlers) | ||
server.add_generic_rpc_handlers((generic_handler,)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Run http hook exemple | ||
|
||
python3 server.py | ||
|
||
tusd -hooks-http=http://localhost:8000 -hooks-enabled-events=pre-create,pre-finish,pre-access,post-create,post-receive,post-terminate,post-finish | ||
|
||
Adapt enabled-events hooks list for your needs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Run plugin hook exemple | ||
|
||
make | ||
|
||
tusd -hooks-http=./hook_handler -hooks-enabled-events=pre-create,pre-finish,pre-access,post-create,post-receive,post-terminate,post-finish | ||
|
||
Adapt enabled-events hooks list for your needs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters