Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions examples/hooks/grpc/hook_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions examples/hooks/grpc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ def InvokeHook(self, hook_request, context):
hook_response.changeFileInfo.metaData['filename'] = metaData['filename']
hook_response.changeFileInfo.metaData['creation_time'] = time.ctime()

# Example: Use the pre-terminate hook to prevent completed uploads from being
# deleted. The termination is rejected with a custom HTTP response.
if hook_request.type == 'pre-terminate':
upload = hook_request.event.upload
if not upload.sizeIsDeferred and upload.offset == upload.size:
hook_response.rejectTermination = True
hook_response.httpResponse.statusCode = 403
hook_response.httpResponse.body = 'completed uploads cannot be deleted'

# Example: Use the post-finish hook to print information about a completed upload,
# including its storage location.
if hook_request.type == 'post-finish':
Expand Down
1 change: 1 addition & 0 deletions pkg/hooks/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func getHeader(httpHeader http.Header) (hookHeader map[string]string) {
func unmarshal(res *pb.HookResponse) (hookRes hooks.HookResponse) {
hookRes.RejectUpload = res.RejectUpload
hookRes.StopUpload = res.StopUpload
hookRes.RejectTermination = res.RejectTermination

httpRes := res.HttpResponse
if httpRes != nil {
Expand Down
Loading
Loading