From 71765b61e4167d63a1bd822789335a178626a039 Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 20 Jun 2023 11:32:51 +0200 Subject: [PATCH] hooks: Allow pre-create to change upload ID, meta data and storage details (#962) * hooks: Allow pre-create to change upload ID, meta data and storage details * fixup! hooks: Allow pre-create to change upload ID, meta data and storage details * hooks: Add support for ChangeFileInfo in gRPC --- cmd/tusd/cli/hooks.go | 10 +- cmd/tusd/cli/hooks/grpc.go | 7 + cmd/tusd/cli/hooks/hooks.go | 7 + cmd/tusd/cli/hooks/proto/v2/hook.proto | 45 +- examples/hooks/grpc/Makefile | 4 +- examples/hooks/grpc/hook_pb2.py | 128 +-- examples/hooks/grpc/hook_pb2_grpc.py | 6 +- examples/hooks/grpc/server.py | 14 +- examples/hooks/http/server.py | 16 +- go.mod | 2 +- pkg/handler/config.go | 5 +- pkg/handler/datastore.go | 28 + pkg/handler/unrouted_handler.go | 15 +- pkg/proto/v2/hook.pb.go | 1076 +++++++++++++++--------- pkg/proto/v2/hook_grpc.pb.go | 115 +++ 15 files changed, 973 insertions(+), 505 deletions(-) create mode 100644 pkg/proto/v2/hook_grpc.pb.go diff --git a/cmd/tusd/cli/hooks.go b/cmd/tusd/cli/hooks.go index fd87cf2..3f8abbd 100644 --- a/cmd/tusd/cli/hooks.go +++ b/cmd/tusd/cli/hooks.go @@ -18,10 +18,10 @@ func hookTypeInSlice(a hooks.HookType, list []hooks.HookType) bool { return false } -func preCreateCallback(event handler.HookEvent) (handler.HTTPResponse, error) { +func preCreateCallback(event handler.HookEvent) (handler.HTTPResponse, handler.FileInfoChanges, error) { ok, hookRes, err := invokeHookSync(hooks.HookPreCreate, event) if !ok || err != nil { - return handler.HTTPResponse{}, err + return handler.HTTPResponse{}, handler.FileInfoChanges{}, err } httpRes := hookRes.HTTPResponse @@ -32,10 +32,12 @@ func preCreateCallback(event handler.HookEvent) (handler.HTTPResponse, error) { err := handler.ErrUploadRejectedByServer err.HTTPResponse = err.HTTPResponse.MergeWith(httpRes) - return handler.HTTPResponse{}, err + return handler.HTTPResponse{}, handler.FileInfoChanges{}, err } - return httpRes, nil + // Pass any changes regarding file info from the hook to the handler. + changes := hookRes.ChangeFileInfo + return httpRes, changes, nil } func preFinishCallback(event handler.HookEvent) (handler.HTTPResponse, error) { diff --git a/cmd/tusd/cli/hooks/grpc.go b/cmd/tusd/cli/hooks/grpc.go index 3c56b84..d3007a9 100644 --- a/cmd/tusd/cli/hooks/grpc.go +++ b/cmd/tusd/cli/hooks/grpc.go @@ -94,5 +94,12 @@ func unmarshal(res *pb.HookResponse) (hookRes HookResponse) { hookRes.HTTPResponse.Body = httpRes.Body } + changes := res.ChangeFileInfo + if changes != nil { + hookRes.ChangeFileInfo.ID = changes.Id + hookRes.ChangeFileInfo.MetaData = changes.MetaData + hookRes.ChangeFileInfo.Storage = changes.Storage + } + return hookRes } diff --git a/cmd/tusd/cli/hooks/hooks.go b/cmd/tusd/cli/hooks/hooks.go index bbd3583..4a24e37 100644 --- a/cmd/tusd/cli/hooks/hooks.go +++ b/cmd/tusd/cli/hooks/hooks.go @@ -48,6 +48,13 @@ type HookResponse struct { // to the client. RejectUpload bool + // ChangeFileInfo can be set to change selected properties of an upload before + // it has been created. See the handler.FileInfoChanges type for more details. + // Changes are applied on a per-property basis, meaning that specifying just + // one property leaves all others unchanged. + // This value is only respected for pre-create hooks. + ChangeFileInfo handler.FileInfoChanges + // StopUpload will cause the upload to be stopped during a PATCH request. // This value is only respected for post-receive hooks. For other hooks, // it is ignored. Use the HTTPResponse field to send details about the stop diff --git a/cmd/tusd/cli/hooks/proto/v2/hook.proto b/cmd/tusd/cli/hooks/proto/v2/hook.proto index d792ce9..d006e5d 100644 --- a/cmd/tusd/cli/hooks/proto/v2/hook.proto +++ b/cmd/tusd/cli/hooks/proto/v2/hook.proto @@ -1,13 +1,15 @@ // If this file gets changed, you must recompile the generate package in pkg/proto. // To do this, install the Go protobuf toolchain as mentioned in -// https://github.com/golang/protobuf#installation. -// Then use following command to recompile it with gRPC support: -// protoc --go_out=plugins=grpc:../../../../../pkg/proto/ v2/hook.proto +// https://grpc.io/docs/languages/go/quickstart/#prerequisites. +// Then use following command from the repository's root to recompile it with gRPC support: +// protoc --go-grpc_out=./pkg/ --go_out=./pkg/ ./cmd/tusd/cli/hooks/proto/v2/hook.proto // In addition, it may be necessary to update the protobuf or gRPC dependencies as well. syntax = "proto3"; package v2; +option go_package = "proto/v2"; + // HookRequest contains the information about the hook type, the involved upload, // and causing HTTP request. message HookRequest { @@ -56,6 +58,35 @@ message FileInfo { map storage = 9; } +// FileInfoChanges collects changes the should be made to a FileInfo object. This +// can be done using the PreUploadCreateCallback to modify certain properties before +// an upload is created. Properties which should not be modified (e.g. Size or Offset) +// are intentionally left out here. +message FileInfoChanges { + // If ID is not empty, it will be passed to the data store, allowing + // hooks to influence the upload ID. Be aware that a data store is not required to + // respect a pre-defined upload ID and might overwrite or modify it. However, + // all data stores in the github.com/tus/tusd package do respect pre-defined IDs. + string id = 1; + + // If MetaData is not nil, it replaces the entire user-defined meta data from + // the upload creation request. You can add custom meta data fields this way + // or ensure that only certain fields from the user-defined meta data are saved. + // If you want to retain only specific entries from the user-defined meta data, you must + // manually copy them into this MetaData field. + // If you do not want to store any meta data, set this field to an empty map (`MetaData{}`). + // If you want to keep the entire user-defined meta data, set this field to nil. + map metaData = 2; + + // If Storage is not nil, it is passed to the data store to allow for minor adjustments + // to the upload storage (e.g. destination file name). The details are specific for each + // data store and should be looked up in their respective documentation. + // Please be aware that this behavior is currently not supported by any data store in + // the github.com/tus/tusd package. + map storage = 3; +} + + // HTTPRequest contains basic details of an incoming HTTP request. message HTTPRequest { // Method is the HTTP method, e.g. POST or PATCH. @@ -87,6 +118,13 @@ message HookResponse { // to the client. bool rejectUpload = 2; + // ChangeFileInfo can be set to change selected properties of an upload before + // it has been created. See the handler.FileInfoChanges type for more details. + // Changes are applied on a per-property basis, meaning that specifying just + // one property leaves all others unchanged. + // This value is only respected for pre-create hooks. + FileInfoChanges changeFileInfo = 4; + // StopUpload will cause the upload to be stopped during a PATCH request. // This value is only respected for post-receive hooks. For other hooks, // it is ignored. Use the HTTPResponse field to send details about the stop @@ -104,7 +142,6 @@ message HTTPResponse { string body = 3; } - // The hook service definition. service HookHandler { // InvokeHook is invoked for every hook that is executed. HookRequest contains the diff --git a/examples/hooks/grpc/Makefile b/examples/hooks/grpc/Makefile index f0d6ea4..20053d3 100644 --- a/examples/hooks/grpc/Makefile +++ b/examples/hooks/grpc/Makefile @@ -1,2 +1,2 @@ -hook_pb2.py: - python -m grpc_tools.protoc --proto_path=../../../cmd/tusd/cli/hooks/proto/v2/ hook.proto --python_out=. --grpc_python_out=. +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=. diff --git a/examples/hooks/grpc/hook_pb2.py b/examples/hooks/grpc/hook_pb2.py index b0366d8..634c7e9 100644 --- a/examples/hooks/grpc/hook_pb2.py +++ b/examples/hooks/grpc/hook_pb2.py @@ -2,10 +2,9 @@ # Generated by the protocol buffer compiler. DO NOT EDIT! # source: hook.proto """Generated protocol buffer code.""" +from google.protobuf.internal import builder as _builder from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool -from google.protobuf import message as _message -from google.protobuf import reflection as _reflection from google.protobuf import symbol_database as _symbol_database # @@protoc_insertion_point(imports) @@ -14,95 +13,10 @@ _sym_db = _symbol_database.Default() -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\nhook.proto\x12\x02v2\"5\n\x0bHookRequest\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x18\n\x05\x65vent\x18\x02 \x01(\x0b\x32\t.v2.Event\"K\n\x05\x45vent\x12\x1c\n\x06upload\x18\x01 \x01(\x0b\x32\x0c.v2.FileInfo\x12$\n\x0bhttpRequest\x18\x02 \x01(\x0b\x32\x0f.v2.HTTPRequest\"\xc3\x02\n\x08\x46ileInfo\x12\n\n\x02id\x18\x01 \x01(\t\x12\x0c\n\x04size\x18\x02 \x01(\x03\x12\x16\n\x0esizeIsDeferred\x18\x03 \x01(\x08\x12\x0e\n\x06offset\x18\x04 \x01(\x03\x12,\n\x08metaData\x18\x05 \x03(\x0b\x32\x1a.v2.FileInfo.MetaDataEntry\x12\x11\n\tisPartial\x18\x06 \x01(\x08\x12\x0f\n\x07isFinal\x18\x07 \x01(\x08\x12\x16\n\x0epartialUploads\x18\x08 \x03(\t\x12*\n\x07storage\x18\t \x03(\x0b\x32\x19.v2.FileInfo.StorageEntry\x1a/\n\rMetaDataEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a.\n\x0cStorageEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\x9a\x01\n\x0bHTTPRequest\x12\x0e\n\x06method\x18\x01 \x01(\t\x12\x0b\n\x03uri\x18\x02 \x01(\t\x12\x12\n\nremoteAddr\x18\x03 \x01(\t\x12+\n\x06header\x18\x04 \x03(\x0b\x32\x1b.v2.HTTPRequest.HeaderEntry\x1a-\n\x0bHeaderEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"`\n\x0cHookResponse\x12&\n\x0chttpResponse\x18\x01 \x01(\x0b\x32\x10.v2.HTTPResponse\x12\x14\n\x0crejectUpload\x18\x02 \x01(\x08\x12\x12\n\nstopUpload\x18\x03 \x01(\x08\"\x90\x01\n\x0cHTTPResponse\x12\x12\n\nstatusCode\x18\x01 \x01(\x03\x12.\n\x07headers\x18\x02 \x03(\x0b\x32\x1d.v2.HTTPResponse.HeadersEntry\x12\x0c\n\x04\x62ody\x18\x03 \x01(\t\x1a.\n\x0cHeadersEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x32@\n\x0bHookHandler\x12\x31\n\nInvokeHook\x12\x0f.v2.HookRequest\x1a\x10.v2.HookResponse\"\x00\x62\x06proto3') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\nhook.proto\x12\x02v2\"5\n\x0bHookRequest\x12\x0c\n\x04type\x18\x01 \x01(\t\x12\x18\n\x05\x65vent\x18\x02 \x01(\x0b\x32\t.v2.Event\"K\n\x05\x45vent\x12\x1c\n\x06upload\x18\x01 \x01(\x0b\x32\x0c.v2.FileInfo\x12$\n\x0bhttpRequest\x18\x02 \x01(\x0b\x32\x0f.v2.HTTPRequest\"\xc3\x02\n\x08\x46ileInfo\x12\n\n\x02id\x18\x01 \x01(\t\x12\x0c\n\x04size\x18\x02 \x01(\x03\x12\x16\n\x0esizeIsDeferred\x18\x03 \x01(\x08\x12\x0e\n\x06offset\x18\x04 \x01(\x03\x12,\n\x08metaData\x18\x05 \x03(\x0b\x32\x1a.v2.FileInfo.MetaDataEntry\x12\x11\n\tisPartial\x18\x06 \x01(\x08\x12\x0f\n\x07isFinal\x18\x07 \x01(\x08\x12\x16\n\x0epartialUploads\x18\x08 \x03(\t\x12*\n\x07storage\x18\t \x03(\x0b\x32\x19.v2.FileInfo.StorageEntry\x1a/\n\rMetaDataEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a.\n\x0cStorageEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\xe6\x01\n\x0f\x46ileInfoChanges\x12\n\n\x02id\x18\x01 \x01(\t\x12\x33\n\x08metaData\x18\x02 \x03(\x0b\x32!.v2.FileInfoChanges.MetaDataEntry\x12\x31\n\x07storage\x18\x03 \x03(\x0b\x32 .v2.FileInfoChanges.StorageEntry\x1a/\n\rMetaDataEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a.\n\x0cStorageEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\x9a\x01\n\x0bHTTPRequest\x12\x0e\n\x06method\x18\x01 \x01(\t\x12\x0b\n\x03uri\x18\x02 \x01(\t\x12\x12\n\nremoteAddr\x18\x03 \x01(\t\x12+\n\x06header\x18\x04 \x03(\x0b\x32\x1b.v2.HTTPRequest.HeaderEntry\x1a-\n\x0bHeaderEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\x8d\x01\n\x0cHookResponse\x12&\n\x0chttpResponse\x18\x01 \x01(\x0b\x32\x10.v2.HTTPResponse\x12\x14\n\x0crejectUpload\x18\x02 \x01(\x08\x12+\n\x0e\x63hangeFileInfo\x18\x04 \x01(\x0b\x32\x13.v2.FileInfoChanges\x12\x12\n\nstopUpload\x18\x03 \x01(\x08\"\x90\x01\n\x0cHTTPResponse\x12\x12\n\nstatusCode\x18\x01 \x01(\x03\x12.\n\x07headers\x18\x02 \x03(\x0b\x32\x1d.v2.HTTPResponse.HeadersEntry\x12\x0c\n\x04\x62ody\x18\x03 \x01(\t\x1a.\n\x0cHeadersEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x32@\n\x0bHookHandler\x12\x31\n\nInvokeHook\x12\x0f.v2.HookRequest\x1a\x10.v2.HookResponse\"\x00\x62\x06proto3') - - -_HOOKREQUEST = DESCRIPTOR.message_types_by_name['HookRequest'] -_EVENT = DESCRIPTOR.message_types_by_name['Event'] -_FILEINFO = DESCRIPTOR.message_types_by_name['FileInfo'] -_FILEINFO_METADATAENTRY = _FILEINFO.nested_types_by_name['MetaDataEntry'] -_FILEINFO_STORAGEENTRY = _FILEINFO.nested_types_by_name['StorageEntry'] -_HTTPREQUEST = DESCRIPTOR.message_types_by_name['HTTPRequest'] -_HTTPREQUEST_HEADERENTRY = _HTTPREQUEST.nested_types_by_name['HeaderEntry'] -_HOOKRESPONSE = DESCRIPTOR.message_types_by_name['HookResponse'] -_HTTPRESPONSE = DESCRIPTOR.message_types_by_name['HTTPResponse'] -_HTTPRESPONSE_HEADERSENTRY = _HTTPRESPONSE.nested_types_by_name['HeadersEntry'] -HookRequest = _reflection.GeneratedProtocolMessageType('HookRequest', (_message.Message,), { - 'DESCRIPTOR' : _HOOKREQUEST, - '__module__' : 'hook_pb2' - # @@protoc_insertion_point(class_scope:v2.HookRequest) - }) -_sym_db.RegisterMessage(HookRequest) - -Event = _reflection.GeneratedProtocolMessageType('Event', (_message.Message,), { - 'DESCRIPTOR' : _EVENT, - '__module__' : 'hook_pb2' - # @@protoc_insertion_point(class_scope:v2.Event) - }) -_sym_db.RegisterMessage(Event) - -FileInfo = _reflection.GeneratedProtocolMessageType('FileInfo', (_message.Message,), { - - 'MetaDataEntry' : _reflection.GeneratedProtocolMessageType('MetaDataEntry', (_message.Message,), { - 'DESCRIPTOR' : _FILEINFO_METADATAENTRY, - '__module__' : 'hook_pb2' - # @@protoc_insertion_point(class_scope:v2.FileInfo.MetaDataEntry) - }) - , - - 'StorageEntry' : _reflection.GeneratedProtocolMessageType('StorageEntry', (_message.Message,), { - 'DESCRIPTOR' : _FILEINFO_STORAGEENTRY, - '__module__' : 'hook_pb2' - # @@protoc_insertion_point(class_scope:v2.FileInfo.StorageEntry) - }) - , - 'DESCRIPTOR' : _FILEINFO, - '__module__' : 'hook_pb2' - # @@protoc_insertion_point(class_scope:v2.FileInfo) - }) -_sym_db.RegisterMessage(FileInfo) -_sym_db.RegisterMessage(FileInfo.MetaDataEntry) -_sym_db.RegisterMessage(FileInfo.StorageEntry) - -HTTPRequest = _reflection.GeneratedProtocolMessageType('HTTPRequest', (_message.Message,), { - - 'HeaderEntry' : _reflection.GeneratedProtocolMessageType('HeaderEntry', (_message.Message,), { - 'DESCRIPTOR' : _HTTPREQUEST_HEADERENTRY, - '__module__' : 'hook_pb2' - # @@protoc_insertion_point(class_scope:v2.HTTPRequest.HeaderEntry) - }) - , - 'DESCRIPTOR' : _HTTPREQUEST, - '__module__' : 'hook_pb2' - # @@protoc_insertion_point(class_scope:v2.HTTPRequest) - }) -_sym_db.RegisterMessage(HTTPRequest) -_sym_db.RegisterMessage(HTTPRequest.HeaderEntry) - -HookResponse = _reflection.GeneratedProtocolMessageType('HookResponse', (_message.Message,), { - 'DESCRIPTOR' : _HOOKRESPONSE, - '__module__' : 'hook_pb2' - # @@protoc_insertion_point(class_scope:v2.HookResponse) - }) -_sym_db.RegisterMessage(HookResponse) - -HTTPResponse = _reflection.GeneratedProtocolMessageType('HTTPResponse', (_message.Message,), { - - 'HeadersEntry' : _reflection.GeneratedProtocolMessageType('HeadersEntry', (_message.Message,), { - 'DESCRIPTOR' : _HTTPRESPONSE_HEADERSENTRY, - '__module__' : 'hook_pb2' - # @@protoc_insertion_point(class_scope:v2.HTTPResponse.HeadersEntry) - }) - , - 'DESCRIPTOR' : _HTTPRESPONSE, - '__module__' : 'hook_pb2' - # @@protoc_insertion_point(class_scope:v2.HTTPResponse) - }) -_sym_db.RegisterMessage(HTTPResponse) -_sym_db.RegisterMessage(HTTPResponse.HeadersEntry) - -_HOOKHANDLER = DESCRIPTOR.services_by_name['HookHandler'] +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'hook_pb2', globals()) if _descriptor._USE_C_DESCRIPTORS == False: DESCRIPTOR._options = None @@ -110,6 +24,10 @@ if _descriptor._USE_C_DESCRIPTORS == False: _FILEINFO_METADATAENTRY._serialized_options = b'8\001' _FILEINFO_STORAGEENTRY._options = None _FILEINFO_STORAGEENTRY._serialized_options = b'8\001' + _FILEINFOCHANGES_METADATAENTRY._options = None + _FILEINFOCHANGES_METADATAENTRY._serialized_options = b'8\001' + _FILEINFOCHANGES_STORAGEENTRY._options = None + _FILEINFOCHANGES_STORAGEENTRY._serialized_options = b'8\001' _HTTPREQUEST_HEADERENTRY._options = None _HTTPREQUEST_HEADERENTRY._serialized_options = b'8\001' _HTTPRESPONSE_HEADERSENTRY._options = None @@ -124,16 +42,22 @@ if _descriptor._USE_C_DESCRIPTORS == False: _FILEINFO_METADATAENTRY._serialized_end=426 _FILEINFO_STORAGEENTRY._serialized_start=428 _FILEINFO_STORAGEENTRY._serialized_end=474 - _HTTPREQUEST._serialized_start=477 - _HTTPREQUEST._serialized_end=631 - _HTTPREQUEST_HEADERENTRY._serialized_start=586 - _HTTPREQUEST_HEADERENTRY._serialized_end=631 - _HOOKRESPONSE._serialized_start=633 - _HOOKRESPONSE._serialized_end=729 - _HTTPRESPONSE._serialized_start=732 - _HTTPRESPONSE._serialized_end=876 - _HTTPRESPONSE_HEADERSENTRY._serialized_start=830 - _HTTPRESPONSE_HEADERSENTRY._serialized_end=876 - _HOOKHANDLER._serialized_start=878 - _HOOKHANDLER._serialized_end=942 + _FILEINFOCHANGES._serialized_start=477 + _FILEINFOCHANGES._serialized_end=707 + _FILEINFOCHANGES_METADATAENTRY._serialized_start=379 + _FILEINFOCHANGES_METADATAENTRY._serialized_end=426 + _FILEINFOCHANGES_STORAGEENTRY._serialized_start=428 + _FILEINFOCHANGES_STORAGEENTRY._serialized_end=474 + _HTTPREQUEST._serialized_start=710 + _HTTPREQUEST._serialized_end=864 + _HTTPREQUEST_HEADERENTRY._serialized_start=819 + _HTTPREQUEST_HEADERENTRY._serialized_end=864 + _HOOKRESPONSE._serialized_start=867 + _HOOKRESPONSE._serialized_end=1008 + _HTTPRESPONSE._serialized_start=1011 + _HTTPRESPONSE._serialized_end=1155 + _HTTPRESPONSE_HEADERSENTRY._serialized_start=1109 + _HTTPRESPONSE_HEADERSENTRY._serialized_end=1155 + _HOOKHANDLER._serialized_start=1157 + _HOOKHANDLER._serialized_end=1221 # @@protoc_insertion_point(module_scope) diff --git a/examples/hooks/grpc/hook_pb2_grpc.py b/examples/hooks/grpc/hook_pb2_grpc.py index 3d0d49d..241c0d0 100644 --- a/examples/hooks/grpc/hook_pb2_grpc.py +++ b/examples/hooks/grpc/hook_pb2_grpc.py @@ -27,7 +27,11 @@ class HookHandlerServicer(object): """ def InvokeHook(self, request, context): - """Sends a hook + """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!') diff --git a/examples/hooks/grpc/server.py b/examples/hooks/grpc/server.py index 05fd0e9..15c8b3a 100644 --- a/examples/hooks/grpc/server.py +++ b/examples/hooks/grpc/server.py @@ -1,6 +1,7 @@ import grpc from concurrent import futures import time +import uuid import hook_pb2_grpc as pb2_grpc import hook_pb2 as pb2 @@ -19,13 +20,22 @@ class HookHandler(pb2_grpc.HookHandlerServicer): # Example: Use the pre-create hook to check if a filename has been supplied # using metadata. If not, the upload is rejected with a custom HTTP response. + # In addition, a custom upload ID with a choosable prefix is supplied. + # Metadata is configured, so that it only retains the filename meta data + # and the creation time. if hook_request.type == 'pre-create': - filename = hook_request.event.upload.metaData['filename'] - if filename == "": + metaData = hook_request.event.upload.metaData + isValid = 'filename' in metaData + if not isValid: hook_response.rejectUpload = True hook_response.httpResponse.statusCode = 400 hook_response.httpResponse.body = 'no filename provided' hook_response.httpResponse.headers['X-Some-Header'] = 'yes' + else: + hook_response.changeFileInfo.id = f'prefix-{uuid.uuid4()}' + hook_response.changeFileInfo.metaData + hook_response.changeFileInfo.metaData['filename'] = metaData['filename'] + hook_response.changeFileInfo.metaData['creation_time'] = time.ctime() # Example: Use the post-finish hook to print information about a completed upload, # including its storage location. diff --git a/examples/hooks/http/server.py b/examples/hooks/http/server.py index 8fe7faf..4f69212 100644 --- a/examples/hooks/http/server.py +++ b/examples/hooks/http/server.py @@ -2,6 +2,8 @@ from http.server import HTTPServer, BaseHTTPRequestHandler from io import BytesIO import json +import time +import uuid class HTTPHookHandler(BaseHTTPRequestHandler): @@ -29,13 +31,25 @@ class HTTPHookHandler(BaseHTTPRequestHandler): # Example: Use the pre-create hook to check if a filename has been supplied # using metadata. If not, the upload is rejected with a custom HTTP response. + # In addition, a custom upload ID with a choosable prefix is supplied. + # Metadata is configured, so that it only retains the filename meta data + # and the creation time. if hook_request['Type'] == 'pre-create': metaData = hook_request['Event']['Upload']['MetaData'] - if 'filename' not in metaData: + isValid = 'filename' in metaData + if not isValid: hook_response['RejectUpload'] = True hook_response['HTTPResponse']['StatusCode'] = 400 hook_response['HTTPResponse']['Body'] = 'no filename provided' hook_response['HTTPResponse']['Headers']['X-Some-Header'] = 'yes' + else: + hook_response['ChangeFileInfo'] = {} + hook_response['ChangeFileInfo']['ID'] = f'prefix-{uuid.uuid4()}' + hook_response['ChangeFileInfo']['MetaData'] = { + 'filename': metaData['filename'], + 'creation_time': time.ctime(), + } + # Example: Use the post-finish hook to print information about a completed upload, # including its storage location. diff --git a/go.mod b/go.mod index 61f1b38..7c7f55d 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,6 @@ require ( github.com/felixge/fgprof v0.9.2 github.com/goji/httpauth v0.0.0-20160601135302-2da839ab0f4d github.com/golang/mock v1.6.0 - github.com/golang/protobuf v1.5.3 github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 github.com/hashicorp/go-hclog v0.14.1 github.com/hashicorp/go-plugin v1.4.3 @@ -24,6 +23,7 @@ require ( github.com/vimeo/go-util v1.4.1 google.golang.org/api v0.125.0 google.golang.org/grpc v1.55.0 + google.golang.org/protobuf v1.30.0 gopkg.in/Acconut/lockfile.v1 v1.1.0 gopkg.in/h2non/gock.v1 v1.1.2 ) diff --git a/pkg/handler/config.go b/pkg/handler/config.go index db52982..e9233df 100644 --- a/pkg/handler/config.go +++ b/pkg/handler/config.go @@ -60,7 +60,10 @@ type Config struct { // If the error is non-nil, the upload will not be created. This can be used to implement // validation of upload metadata etc. Furthermore, HTTPResponse will be ignored and // the error value can contain values for the HTTP response. - PreUploadCreateCallback func(hook HookEvent) (HTTPResponse, error) + // If the error is nil, FileInfoChanges can be filled out to specify individual properties + // that should be overwriten before the upload is create. See its type definition for + // more details on its behavior. If you do not want to make any changes, return an empty struct. + PreUploadCreateCallback func(hook HookEvent) (HTTPResponse, FileInfoChanges, error) // PreFinishResponseCallback will be invoked after an upload is completed but before // a response is returned to the client. This can be used to implement post-processing validation. // If the callback returns no error, optional values from HTTPResponse will be contained in the HTTP response. diff --git a/pkg/handler/datastore.go b/pkg/handler/datastore.go index 2321141..7218f9e 100644 --- a/pkg/handler/datastore.go +++ b/pkg/handler/datastore.go @@ -50,6 +50,34 @@ func (f FileInfo) StopUpload() { } } +// FileInfoChanges collects changes the should be made to a FileInfo struct. This +// can be done using the PreUploadCreateCallback to modify certain properties before +// an upload is created. Properties which should not be modified (e.g. Size or Offset) +// are intentionally left out here. +type FileInfoChanges struct { + // If ID is not empty, it will be passed to the data store, allowing + // hooks to influence the upload ID. Be aware that a data store is not required to + // respect a pre-defined upload ID and might overwrite or modify it. However, + // all data stores in the github.com/tus/tusd package do respect pre-defined IDs. + ID string + + // If MetaData is not nil, it replaces the entire user-defined meta data from + // the upload creation request. You can add custom meta data fields this way + // or ensure that only certain fields from the user-defined meta data are saved. + // If you want to retain only specific entries from the user-defined meta data, you must + // manually copy them into this MetaData field. + // If you do not want to store any meta data, set this field to an empty map (`MetaData{}`). + // If you want to keep the entire user-defined meta data, set this field to nil. + MetaData MetaData + + // If Storage is not nil, it is passed to the data store to allow for minor adjustments + // to the upload storage (e.g. destination file name). The details are specific for each + // data store and should be looked up in their respective documentation. + // Please be aware that this behavior is currently not supported by any data store in + // the github.com/tus/tusd package. + Storage map[string]string +} + type Upload interface { // Write the chunk read from src into the file specified by the id at the // given offset. The handler will take care of validating the offset and diff --git a/pkg/handler/unrouted_handler.go b/pkg/handler/unrouted_handler.go index 0a93feb..f371791 100644 --- a/pkg/handler/unrouted_handler.go +++ b/pkg/handler/unrouted_handler.go @@ -322,12 +322,25 @@ func (handler *UnroutedHandler) PostFile(w http.ResponseWriter, r *http.Request) } if handler.config.PreUploadCreateCallback != nil { - resp2, err := handler.config.PreUploadCreateCallback(newHookEvent(info, r)) + resp2, changes, err := handler.config.PreUploadCreateCallback(newHookEvent(info, r)) if err != nil { handler.sendError(c, err) return } resp = resp.MergeWith(resp2) + + // Apply changes returned from the pre-create hook. + if changes.ID != "" { + info.ID = changes.ID + } + + if changes.MetaData != nil { + info.MetaData = changes.MetaData + } + + if changes.Storage != nil { + info.Storage = changes.Storage + } } upload, err := handler.composer.Core.NewUpload(c, info) diff --git a/pkg/proto/v2/hook.pb.go b/pkg/proto/v2/hook.pb.go index 65814d9..c3d8254 100644 --- a/pkg/proto/v2/hook.pb.go +++ b/pkg/proto/v2/hook.pb.go @@ -1,128 +1,158 @@ +// If this file gets changed, you must recompile the generate package in pkg/proto. +// To do this, install the Go protobuf toolchain as mentioned in +// https://grpc.io/docs/languages/go/quickstart/#prerequisites. +// Then use following command from the repository's root to recompile it with gRPC support: +// protoc --go-grpc_out=./pkg/ ./cmd/tusd/cli/hooks/proto/v2/hook.protoo +// In addition, it may be necessary to update the protobuf or gRPC dependencies as well. + // Code generated by protoc-gen-go. DO NOT EDIT. -// source: v2/hook.proto +// versions: +// protoc-gen-go v1.28.1 +// protoc v3.21.12 +// source: cmd/tusd/cli/hooks/proto/v2/hook.proto package v2 import ( - context "context" - fmt "fmt" - proto "github.com/golang/protobuf/proto" - grpc "google.golang.org/grpc" - codes "google.golang.org/grpc/codes" - status "google.golang.org/grpc/status" - math "math" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" ) -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package - -// Hook's data +// HookRequest contains the information about the hook type, the involved upload, +// and causing HTTP request. type HookRequest struct { - Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` - Event *Event `protobuf:"bytes,2,opt,name=event,proto3" json:"event,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Type is the name of the hook. + Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` + // Event contains the involved upload and causing HTTP request. + Event *Event `protobuf:"bytes,2,opt,name=event,proto3" json:"event,omitempty"` } -func (m *HookRequest) Reset() { *m = HookRequest{} } -func (m *HookRequest) String() string { return proto.CompactTextString(m) } -func (*HookRequest) ProtoMessage() {} +func (x *HookRequest) Reset() { + *x = HookRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *HookRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HookRequest) ProtoMessage() {} + +func (x *HookRequest) ProtoReflect() protoreflect.Message { + mi := &file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HookRequest.ProtoReflect.Descriptor instead. func (*HookRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_938ab51c60d4b622, []int{0} + return file_cmd_tusd_cli_hooks_proto_v2_hook_proto_rawDescGZIP(), []int{0} } -func (m *HookRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_HookRequest.Unmarshal(m, b) -} -func (m *HookRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_HookRequest.Marshal(b, m, deterministic) -} -func (m *HookRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_HookRequest.Merge(m, src) -} -func (m *HookRequest) XXX_Size() int { - return xxx_messageInfo_HookRequest.Size(m) -} -func (m *HookRequest) XXX_DiscardUnknown() { - xxx_messageInfo_HookRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_HookRequest proto.InternalMessageInfo - -func (m *HookRequest) GetType() string { - if m != nil { - return m.Type +func (x *HookRequest) GetType() string { + if x != nil { + return x.Type } return "" } -func (m *HookRequest) GetEvent() *Event { - if m != nil { - return m.Event +func (x *HookRequest) GetEvent() *Event { + if x != nil { + return x.Event } return nil } +// Event represents an event from tusd which can be handled by the application. type Event struct { - Upload *FileInfo `protobuf:"bytes,1,opt,name=upload,proto3" json:"upload,omitempty"` - HttpRequest *HTTPRequest `protobuf:"bytes,2,opt,name=httpRequest,proto3" json:"httpRequest,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Upload contains information about the upload that caused this hook + // to be fired. + Upload *FileInfo `protobuf:"bytes,1,opt,name=upload,proto3" json:"upload,omitempty"` + // HTTPRequest contains details about the HTTP request that reached + // tusd. + HttpRequest *HTTPRequest `protobuf:"bytes,2,opt,name=httpRequest,proto3" json:"httpRequest,omitempty"` } -func (m *Event) Reset() { *m = Event{} } -func (m *Event) String() string { return proto.CompactTextString(m) } -func (*Event) ProtoMessage() {} +func (x *Event) Reset() { + *x = Event{} + if protoimpl.UnsafeEnabled { + mi := &file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Event) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Event) ProtoMessage() {} + +func (x *Event) ProtoReflect() protoreflect.Message { + mi := &file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Event.ProtoReflect.Descriptor instead. func (*Event) Descriptor() ([]byte, []int) { - return fileDescriptor_938ab51c60d4b622, []int{1} + return file_cmd_tusd_cli_hooks_proto_v2_hook_proto_rawDescGZIP(), []int{1} } -func (m *Event) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_Event.Unmarshal(m, b) -} -func (m *Event) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_Event.Marshal(b, m, deterministic) -} -func (m *Event) XXX_Merge(src proto.Message) { - xxx_messageInfo_Event.Merge(m, src) -} -func (m *Event) XXX_Size() int { - return xxx_messageInfo_Event.Size(m) -} -func (m *Event) XXX_DiscardUnknown() { - xxx_messageInfo_Event.DiscardUnknown(m) -} - -var xxx_messageInfo_Event proto.InternalMessageInfo - -func (m *Event) GetUpload() *FileInfo { - if m != nil { - return m.Upload +func (x *Event) GetUpload() *FileInfo { + if x != nil { + return x.Upload } return nil } -func (m *Event) GetHttpRequest() *HTTPRequest { - if m != nil { - return m.HttpRequest +func (x *Event) GetHttpRequest() *HTTPRequest { + if x != nil { + return x.HttpRequest } return nil } -// TODO: Keep consistent naming capitalization -// Uploaded data +// FileInfo contains information about a single upload resource. type FileInfo struct { - // Unique integer identifier of the uploaded file + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // ID is the unique identifier of the upload resource. Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` // Total file size in bytes specified in the NewUpload call Size int64 `protobuf:"varint,2,opt,name=size,proto3" json:"size,omitempty"` @@ -144,412 +174,686 @@ type FileInfo struct { // Storage contains information about where the data storage saves the upload, // for example a file path. The available values vary depending on what data // store is used. This map may also be nil. - Storage map[string]string `protobuf:"bytes,9,rep,name=storage,proto3" json:"storage,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + Storage map[string]string `protobuf:"bytes,9,rep,name=storage,proto3" json:"storage,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } -func (m *FileInfo) Reset() { *m = FileInfo{} } -func (m *FileInfo) String() string { return proto.CompactTextString(m) } -func (*FileInfo) ProtoMessage() {} +func (x *FileInfo) Reset() { + *x = FileInfo{} + if protoimpl.UnsafeEnabled { + mi := &file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *FileInfo) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FileInfo) ProtoMessage() {} + +func (x *FileInfo) ProtoReflect() protoreflect.Message { + mi := &file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FileInfo.ProtoReflect.Descriptor instead. func (*FileInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_938ab51c60d4b622, []int{2} + return file_cmd_tusd_cli_hooks_proto_v2_hook_proto_rawDescGZIP(), []int{2} } -func (m *FileInfo) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_FileInfo.Unmarshal(m, b) -} -func (m *FileInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_FileInfo.Marshal(b, m, deterministic) -} -func (m *FileInfo) XXX_Merge(src proto.Message) { - xxx_messageInfo_FileInfo.Merge(m, src) -} -func (m *FileInfo) XXX_Size() int { - return xxx_messageInfo_FileInfo.Size(m) -} -func (m *FileInfo) XXX_DiscardUnknown() { - xxx_messageInfo_FileInfo.DiscardUnknown(m) -} - -var xxx_messageInfo_FileInfo proto.InternalMessageInfo - -func (m *FileInfo) GetId() string { - if m != nil { - return m.Id +func (x *FileInfo) GetId() string { + if x != nil { + return x.Id } return "" } -func (m *FileInfo) GetSize() int64 { - if m != nil { - return m.Size +func (x *FileInfo) GetSize() int64 { + if x != nil { + return x.Size } return 0 } -func (m *FileInfo) GetSizeIsDeferred() bool { - if m != nil { - return m.SizeIsDeferred +func (x *FileInfo) GetSizeIsDeferred() bool { + if x != nil { + return x.SizeIsDeferred } return false } -func (m *FileInfo) GetOffset() int64 { - if m != nil { - return m.Offset +func (x *FileInfo) GetOffset() int64 { + if x != nil { + return x.Offset } return 0 } -func (m *FileInfo) GetMetaData() map[string]string { - if m != nil { - return m.MetaData +func (x *FileInfo) GetMetaData() map[string]string { + if x != nil { + return x.MetaData } return nil } -func (m *FileInfo) GetIsPartial() bool { - if m != nil { - return m.IsPartial +func (x *FileInfo) GetIsPartial() bool { + if x != nil { + return x.IsPartial } return false } -func (m *FileInfo) GetIsFinal() bool { - if m != nil { - return m.IsFinal +func (x *FileInfo) GetIsFinal() bool { + if x != nil { + return x.IsFinal } return false } -func (m *FileInfo) GetPartialUploads() []string { - if m != nil { - return m.PartialUploads +func (x *FileInfo) GetPartialUploads() []string { + if x != nil { + return x.PartialUploads } return nil } -func (m *FileInfo) GetStorage() map[string]string { - if m != nil { - return m.Storage +func (x *FileInfo) GetStorage() map[string]string { + if x != nil { + return x.Storage } return nil } +// FileInfoChanges collects changes the should be made to a FileInfo object. This +// can be done using the PreUploadCreateCallback to modify certain properties before +// an upload is created. Properties which should not be modified (e.g. Size or Offset) +// are intentionally left out here. +type FileInfoChanges struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // If ID is not empty, it will be passed to the data store, allowing + // hooks to influence the upload ID. Be aware that a data store is not required to + // respect a pre-defined upload ID and might overwrite or modify it. However, + // all data stores in the github.com/tus/tusd package do respect pre-defined IDs. + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + // If MetaData is not nil, it replaces the entire user-defined meta data from + // the upload creation request. You can add custom meta data fields this way + // or ensure that only certain fields from the user-defined meta data are saved. + // If you want to retain only specific entries from the user-defined meta data, you must + // manually copy them into this MetaData field. + // If you do not want to store any meta data, set this field to an empty map (`MetaData{}`). + // If you want to keep the entire user-defined meta data, set this field to nil. + MetaData map[string]string `protobuf:"bytes,2,rep,name=metaData,proto3" json:"metaData,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + // If Storage is not nil, it is passed to the data store to allow for minor adjustments + // to the upload storage (e.g. destination file name). The details are specific for each + // data store and should be looked up in their respective documentation. + // Please be aware that this behavior is currently not supported by any data store in + // the github.com/tus/tusd package. + Storage map[string]string `protobuf:"bytes,3,rep,name=storage,proto3" json:"storage,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` +} + +func (x *FileInfoChanges) Reset() { + *x = FileInfoChanges{} + if protoimpl.UnsafeEnabled { + mi := &file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *FileInfoChanges) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FileInfoChanges) ProtoMessage() {} + +func (x *FileInfoChanges) ProtoReflect() protoreflect.Message { + mi := &file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FileInfoChanges.ProtoReflect.Descriptor instead. +func (*FileInfoChanges) Descriptor() ([]byte, []int) { + return file_cmd_tusd_cli_hooks_proto_v2_hook_proto_rawDescGZIP(), []int{3} +} + +func (x *FileInfoChanges) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *FileInfoChanges) GetMetaData() map[string]string { + if x != nil { + return x.MetaData + } + return nil +} + +func (x *FileInfoChanges) GetStorage() map[string]string { + if x != nil { + return x.Storage + } + return nil +} + +// HTTPRequest contains basic details of an incoming HTTP request. type HTTPRequest struct { - // Method is the HTTP method, e.g. POST or PATCH + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Method is the HTTP method, e.g. POST or PATCH. Method string `protobuf:"bytes,1,opt,name=method,proto3" json:"method,omitempty"` - // URI is the full HTTP request URI, e.g. /files/fooo + // URI is the full HTTP request URI, e.g. /files/fooo. Uri string `protobuf:"bytes,2,opt,name=uri,proto3" json:"uri,omitempty"` - // RemoteAddr contains the network address that sent the request - RemoteAddr string `protobuf:"bytes,3,opt,name=remoteAddr,proto3" json:"remoteAddr,omitempty"` - Header map[string]string `protobuf:"bytes,4,rep,name=header,proto3" json:"header,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + // RemoteAddr contains the network address that sent the request. + RemoteAddr string `protobuf:"bytes,3,opt,name=remoteAddr,proto3" json:"remoteAddr,omitempty"` + // Header contains all HTTP headers as present in the HTTP request. + Header map[string]string `protobuf:"bytes,4,rep,name=header,proto3" json:"header,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` } -func (m *HTTPRequest) Reset() { *m = HTTPRequest{} } -func (m *HTTPRequest) String() string { return proto.CompactTextString(m) } -func (*HTTPRequest) ProtoMessage() {} +func (x *HTTPRequest) Reset() { + *x = HTTPRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *HTTPRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HTTPRequest) ProtoMessage() {} + +func (x *HTTPRequest) ProtoReflect() protoreflect.Message { + mi := &file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HTTPRequest.ProtoReflect.Descriptor instead. func (*HTTPRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_938ab51c60d4b622, []int{3} + return file_cmd_tusd_cli_hooks_proto_v2_hook_proto_rawDescGZIP(), []int{4} } -func (m *HTTPRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_HTTPRequest.Unmarshal(m, b) -} -func (m *HTTPRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_HTTPRequest.Marshal(b, m, deterministic) -} -func (m *HTTPRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_HTTPRequest.Merge(m, src) -} -func (m *HTTPRequest) XXX_Size() int { - return xxx_messageInfo_HTTPRequest.Size(m) -} -func (m *HTTPRequest) XXX_DiscardUnknown() { - xxx_messageInfo_HTTPRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_HTTPRequest proto.InternalMessageInfo - -func (m *HTTPRequest) GetMethod() string { - if m != nil { - return m.Method +func (x *HTTPRequest) GetMethod() string { + if x != nil { + return x.Method } return "" } -func (m *HTTPRequest) GetUri() string { - if m != nil { - return m.Uri +func (x *HTTPRequest) GetUri() string { + if x != nil { + return x.Uri } return "" } -func (m *HTTPRequest) GetRemoteAddr() string { - if m != nil { - return m.RemoteAddr +func (x *HTTPRequest) GetRemoteAddr() string { + if x != nil { + return x.RemoteAddr } return "" } -func (m *HTTPRequest) GetHeader() map[string]string { - if m != nil { - return m.Header +func (x *HTTPRequest) GetHeader() map[string]string { + if x != nil { + return x.Header } return nil } +// HookResponse is the response after a hook is executed. type HookResponse struct { - HttpResponse *HTTPResponse `protobuf:"bytes,1,opt,name=httpResponse,proto3" json:"httpResponse,omitempty"` - RejectUpload bool `protobuf:"varint,2,opt,name=rejectUpload,proto3" json:"rejectUpload,omitempty"` - StopUpload bool `protobuf:"varint,3,opt,name=stopUpload,proto3" json:"stopUpload,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // HTTPResponse's fields can be filled to modify the HTTP response. + // This is only possible for pre-create, pre-finish and post-receive hooks. + // For other hooks this value is ignored. + // If multiple hooks modify the HTTP response, a later hook may overwrite the + // modified values from a previous hook (e.g. if multiple post-receive hooks + // are executed). + // Example usages: Send an error to the client if RejectUpload/StopUpload are + // set in the pre-create/post-receive hook. Send more information to the client + // in the pre-finish hook. + HttpResponse *HTTPResponse `protobuf:"bytes,1,opt,name=httpResponse,proto3" json:"httpResponse,omitempty"` + // RejectUpload will cause the upload to be rejected and not be created during + // POST request. This value is only respected for pre-create hooks. For other hooks, + // it is ignored. Use the HTTPResponse field to send details about the rejection + // to the client. + RejectUpload bool `protobuf:"varint,2,opt,name=rejectUpload,proto3" json:"rejectUpload,omitempty"` + // ChangeFileInfo can be set to change selected properties of an upload before + // it has been created. See the handler.FileInfoChanges type for more details. + // Changes are applied on a per-property basis, meaning that specifying just + // one property leaves all others unchanged. + // This value is only respected for pre-create hooks. + ChangeFileInfo *FileInfoChanges `protobuf:"bytes,4,opt,name=changeFileInfo,proto3" json:"changeFileInfo,omitempty"` + // StopUpload will cause the upload to be stopped during a PATCH request. + // This value is only respected for post-receive hooks. For other hooks, + // it is ignored. Use the HTTPResponse field to send details about the stop + // to the client. + StopUpload bool `protobuf:"varint,3,opt,name=stopUpload,proto3" json:"stopUpload,omitempty"` } -func (m *HookResponse) Reset() { *m = HookResponse{} } -func (m *HookResponse) String() string { return proto.CompactTextString(m) } -func (*HookResponse) ProtoMessage() {} +func (x *HookResponse) Reset() { + *x = HookResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *HookResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HookResponse) ProtoMessage() {} + +func (x *HookResponse) ProtoReflect() protoreflect.Message { + mi := &file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HookResponse.ProtoReflect.Descriptor instead. func (*HookResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_938ab51c60d4b622, []int{4} + return file_cmd_tusd_cli_hooks_proto_v2_hook_proto_rawDescGZIP(), []int{5} } -func (m *HookResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_HookResponse.Unmarshal(m, b) -} -func (m *HookResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_HookResponse.Marshal(b, m, deterministic) -} -func (m *HookResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_HookResponse.Merge(m, src) -} -func (m *HookResponse) XXX_Size() int { - return xxx_messageInfo_HookResponse.Size(m) -} -func (m *HookResponse) XXX_DiscardUnknown() { - xxx_messageInfo_HookResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_HookResponse proto.InternalMessageInfo - -func (m *HookResponse) GetHttpResponse() *HTTPResponse { - if m != nil { - return m.HttpResponse +func (x *HookResponse) GetHttpResponse() *HTTPResponse { + if x != nil { + return x.HttpResponse } return nil } -func (m *HookResponse) GetRejectUpload() bool { - if m != nil { - return m.RejectUpload +func (x *HookResponse) GetRejectUpload() bool { + if x != nil { + return x.RejectUpload } return false } -func (m *HookResponse) GetStopUpload() bool { - if m != nil { - return m.StopUpload +func (x *HookResponse) GetChangeFileInfo() *FileInfoChanges { + if x != nil { + return x.ChangeFileInfo + } + return nil +} + +func (x *HookResponse) GetStopUpload() bool { + if x != nil { + return x.StopUpload } return false } +// HTTPResponse contains basic details of an outgoing HTTP response. type HTTPResponse struct { - StatusCode int64 `protobuf:"varint,1,opt,name=statusCode,proto3" json:"statusCode,omitempty"` - Headers map[string]string `protobuf:"bytes,2,rep,name=headers,proto3" json:"headers,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - Body string `protobuf:"bytes,3,opt,name=body,proto3" json:"body,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // StatusCode is status code, e.g. 200 or 400. + StatusCode int64 `protobuf:"varint,1,opt,name=statusCode,proto3" json:"statusCode,omitempty"` + // Headers contains additional HTTP headers for the response. + Headers map[string]string `protobuf:"bytes,2,rep,name=headers,proto3" json:"headers,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + // Body is the response body. + Body string `protobuf:"bytes,3,opt,name=body,proto3" json:"body,omitempty"` } -func (m *HTTPResponse) Reset() { *m = HTTPResponse{} } -func (m *HTTPResponse) String() string { return proto.CompactTextString(m) } -func (*HTTPResponse) ProtoMessage() {} +func (x *HTTPResponse) Reset() { + *x = HTTPResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *HTTPResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*HTTPResponse) ProtoMessage() {} + +func (x *HTTPResponse) ProtoReflect() protoreflect.Message { + mi := &file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use HTTPResponse.ProtoReflect.Descriptor instead. func (*HTTPResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_938ab51c60d4b622, []int{5} + return file_cmd_tusd_cli_hooks_proto_v2_hook_proto_rawDescGZIP(), []int{6} } -func (m *HTTPResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_HTTPResponse.Unmarshal(m, b) -} -func (m *HTTPResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_HTTPResponse.Marshal(b, m, deterministic) -} -func (m *HTTPResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_HTTPResponse.Merge(m, src) -} -func (m *HTTPResponse) XXX_Size() int { - return xxx_messageInfo_HTTPResponse.Size(m) -} -func (m *HTTPResponse) XXX_DiscardUnknown() { - xxx_messageInfo_HTTPResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_HTTPResponse proto.InternalMessageInfo - -func (m *HTTPResponse) GetStatusCode() int64 { - if m != nil { - return m.StatusCode +func (x *HTTPResponse) GetStatusCode() int64 { + if x != nil { + return x.StatusCode } return 0 } -func (m *HTTPResponse) GetHeaders() map[string]string { - if m != nil { - return m.Headers +func (x *HTTPResponse) GetHeaders() map[string]string { + if x != nil { + return x.Headers } return nil } -func (m *HTTPResponse) GetBody() string { - if m != nil { - return m.Body +func (x *HTTPResponse) GetBody() string { + if x != nil { + return x.Body } return "" } -func init() { - proto.RegisterType((*HookRequest)(nil), "v2.HookRequest") - proto.RegisterType((*Event)(nil), "v2.Event") - proto.RegisterType((*FileInfo)(nil), "v2.FileInfo") - proto.RegisterMapType((map[string]string)(nil), "v2.FileInfo.MetaDataEntry") - proto.RegisterMapType((map[string]string)(nil), "v2.FileInfo.StorageEntry") - proto.RegisterType((*HTTPRequest)(nil), "v2.HTTPRequest") - proto.RegisterMapType((map[string]string)(nil), "v2.HTTPRequest.HeaderEntry") - proto.RegisterType((*HookResponse)(nil), "v2.HookResponse") - proto.RegisterType((*HTTPResponse)(nil), "v2.HTTPResponse") - proto.RegisterMapType((map[string]string)(nil), "v2.HTTPResponse.HeadersEntry") +var File_cmd_tusd_cli_hooks_proto_v2_hook_proto protoreflect.FileDescriptor + +var file_cmd_tusd_cli_hooks_proto_v2_hook_proto_rawDesc = []byte{ + 0x0a, 0x26, 0x63, 0x6d, 0x64, 0x2f, 0x74, 0x75, 0x73, 0x64, 0x2f, 0x63, 0x6c, 0x69, 0x2f, 0x68, + 0x6f, 0x6f, 0x6b, 0x73, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x76, 0x32, 0x2f, 0x68, 0x6f, + 0x6f, 0x6b, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x76, 0x32, 0x22, 0x42, 0x0a, 0x0b, + 0x48, 0x6f, 0x6f, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x74, + 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, + 0x1f, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x09, + 0x2e, 0x76, 0x32, 0x2e, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, + 0x22, 0x60, 0x0a, 0x05, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x24, 0x0a, 0x06, 0x75, 0x70, 0x6c, + 0x6f, 0x61, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0c, 0x2e, 0x76, 0x32, 0x2e, 0x46, + 0x69, 0x6c, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x06, 0x75, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x12, + 0x31, 0x0a, 0x0b, 0x68, 0x74, 0x74, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f, 0x2e, 0x76, 0x32, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x0b, 0x68, 0x74, 0x74, 0x70, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x22, 0xb4, 0x03, 0x0a, 0x08, 0x46, 0x69, 0x6c, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x12, + 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, + 0x12, 0x0a, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x73, + 0x69, 0x7a, 0x65, 0x12, 0x26, 0x0a, 0x0e, 0x73, 0x69, 0x7a, 0x65, 0x49, 0x73, 0x44, 0x65, 0x66, + 0x65, 0x72, 0x72, 0x65, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0e, 0x73, 0x69, 0x7a, + 0x65, 0x49, 0x73, 0x44, 0x65, 0x66, 0x65, 0x72, 0x72, 0x65, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x6f, + 0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6f, 0x66, 0x66, + 0x73, 0x65, 0x74, 0x12, 0x36, 0x0a, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x44, 0x61, 0x74, 0x61, 0x18, + 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x76, 0x32, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x49, + 0x6e, 0x66, 0x6f, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, + 0x79, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x44, 0x61, 0x74, 0x61, 0x12, 0x1c, 0x0a, 0x09, 0x69, + 0x73, 0x50, 0x61, 0x72, 0x74, 0x69, 0x61, 0x6c, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, + 0x69, 0x73, 0x50, 0x61, 0x72, 0x74, 0x69, 0x61, 0x6c, 0x12, 0x18, 0x0a, 0x07, 0x69, 0x73, 0x46, + 0x69, 0x6e, 0x61, 0x6c, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x46, 0x69, + 0x6e, 0x61, 0x6c, 0x12, 0x26, 0x0a, 0x0e, 0x70, 0x61, 0x72, 0x74, 0x69, 0x61, 0x6c, 0x55, 0x70, + 0x6c, 0x6f, 0x61, 0x64, 0x73, 0x18, 0x08, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0e, 0x70, 0x61, 0x72, + 0x74, 0x69, 0x61, 0x6c, 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x73, 0x12, 0x33, 0x0a, 0x07, 0x73, + 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x18, 0x09, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x76, + 0x32, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x2e, 0x53, 0x74, 0x6f, 0x72, 0x61, + 0x67, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, + 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, + 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, + 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x3a, 0x0a, + 0x0c, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, + 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, + 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x95, 0x02, 0x0a, 0x0f, 0x46, 0x69, + 0x6c, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x73, 0x12, 0x0e, 0x0a, + 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x3d, 0x0a, + 0x08, 0x6d, 0x65, 0x74, 0x61, 0x44, 0x61, 0x74, 0x61, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x21, 0x2e, 0x76, 0x32, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x43, 0x68, 0x61, + 0x6e, 0x67, 0x65, 0x73, 0x2e, 0x4d, 0x65, 0x74, 0x61, 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, + 0x72, 0x79, 0x52, 0x08, 0x6d, 0x65, 0x74, 0x61, 0x44, 0x61, 0x74, 0x61, 0x12, 0x3a, 0x0a, 0x07, + 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x20, 0x2e, + 0x76, 0x32, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x43, 0x68, 0x61, 0x6e, 0x67, + 0x65, 0x73, 0x2e, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, + 0x07, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x1a, 0x3b, 0x0a, 0x0d, 0x4d, 0x65, 0x74, 0x61, + 0x44, 0x61, 0x74, 0x61, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x3a, 0x0a, 0x0c, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, + 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, + 0x01, 0x22, 0xc7, 0x01, 0x0a, 0x0b, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x69, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x72, 0x69, 0x12, 0x1e, 0x0a, 0x0a, 0x72, + 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x41, 0x64, 0x64, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0a, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x41, 0x64, 0x64, 0x72, 0x12, 0x33, 0x0a, 0x06, 0x68, + 0x65, 0x61, 0x64, 0x65, 0x72, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1b, 0x2e, 0x76, 0x32, + 0x2e, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x48, 0x65, 0x61, + 0x64, 0x65, 0x72, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x06, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, + 0x1a, 0x39, 0x0a, 0x0b, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, + 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, + 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xc5, 0x01, 0x0a, 0x0c, + 0x48, 0x6f, 0x6f, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x34, 0x0a, 0x0c, + 0x68, 0x74, 0x74, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x76, 0x32, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x52, 0x0c, 0x68, 0x74, 0x74, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x22, 0x0a, 0x0c, 0x72, 0x65, 0x6a, 0x65, 0x63, 0x74, 0x55, 0x70, 0x6c, 0x6f, + 0x61, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0c, 0x72, 0x65, 0x6a, 0x65, 0x63, 0x74, + 0x55, 0x70, 0x6c, 0x6f, 0x61, 0x64, 0x12, 0x3b, 0x0a, 0x0e, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, + 0x46, 0x69, 0x6c, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, + 0x2e, 0x76, 0x32, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x49, 0x6e, 0x66, 0x6f, 0x43, 0x68, 0x61, 0x6e, + 0x67, 0x65, 0x73, 0x52, 0x0e, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x46, 0x69, 0x6c, 0x65, 0x49, + 0x6e, 0x66, 0x6f, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x74, 0x6f, 0x70, 0x55, 0x70, 0x6c, 0x6f, 0x61, + 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x73, 0x74, 0x6f, 0x70, 0x55, 0x70, 0x6c, + 0x6f, 0x61, 0x64, 0x22, 0xb7, 0x01, 0x0a, 0x0c, 0x48, 0x54, 0x54, 0x50, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x6f, + 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x43, 0x6f, 0x64, 0x65, 0x12, 0x37, 0x0a, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x18, + 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1d, 0x2e, 0x76, 0x32, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x45, + 0x6e, 0x74, 0x72, 0x79, 0x52, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x12, 0x12, 0x0a, + 0x04, 0x62, 0x6f, 0x64, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x62, 0x6f, 0x64, + 0x79, 0x1a, 0x3a, 0x0a, 0x0c, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, + 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, + 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x32, 0x40, 0x0a, + 0x0b, 0x48, 0x6f, 0x6f, 0x6b, 0x48, 0x61, 0x6e, 0x64, 0x6c, 0x65, 0x72, 0x12, 0x31, 0x0a, 0x0a, + 0x49, 0x6e, 0x76, 0x6f, 0x6b, 0x65, 0x48, 0x6f, 0x6f, 0x6b, 0x12, 0x0f, 0x2e, 0x76, 0x32, 0x2e, + 0x48, 0x6f, 0x6f, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x76, 0x32, + 0x2e, 0x48, 0x6f, 0x6f, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, + 0x0a, 0x5a, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x76, 0x32, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } -func init() { - proto.RegisterFile("v2/hook.proto", fileDescriptor_938ab51c60d4b622) +var ( + file_cmd_tusd_cli_hooks_proto_v2_hook_proto_rawDescOnce sync.Once + file_cmd_tusd_cli_hooks_proto_v2_hook_proto_rawDescData = file_cmd_tusd_cli_hooks_proto_v2_hook_proto_rawDesc +) + +func file_cmd_tusd_cli_hooks_proto_v2_hook_proto_rawDescGZIP() []byte { + file_cmd_tusd_cli_hooks_proto_v2_hook_proto_rawDescOnce.Do(func() { + file_cmd_tusd_cli_hooks_proto_v2_hook_proto_rawDescData = protoimpl.X.CompressGZIP(file_cmd_tusd_cli_hooks_proto_v2_hook_proto_rawDescData) + }) + return file_cmd_tusd_cli_hooks_proto_v2_hook_proto_rawDescData } -var fileDescriptor_938ab51c60d4b622 = []byte{ - // 578 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xdb, 0x6e, 0xd3, 0x40, - 0x10, 0xc5, 0x71, 0x73, 0xf1, 0x38, 0x2d, 0xd5, 0x0a, 0xa1, 0x25, 0xdc, 0x22, 0x0b, 0xa1, 0x3c, - 0x05, 0xd5, 0x45, 0x5c, 0xca, 0x0b, 0x97, 0xb6, 0x4a, 0x1f, 0x90, 0xaa, 0xa5, 0xbc, 0xb3, 0xc5, - 0x13, 0x62, 0xe2, 0x7a, 0xcd, 0xee, 0xc6, 0x52, 0xf8, 0x02, 0x3e, 0x08, 0x89, 0x4f, 0xe0, 0xb7, - 0xd0, 0x5e, 0x42, 0x9c, 0xbc, 0xe5, 0xc9, 0x3b, 0x67, 0xce, 0xcc, 0x9e, 0x3d, 0x3b, 0x5e, 0xd8, - 0xaf, 0xd3, 0x67, 0x33, 0x21, 0xe6, 0xe3, 0x4a, 0x0a, 0x2d, 0x48, 0xab, 0x4e, 0x93, 0xf7, 0x10, - 0x4f, 0x84, 0x98, 0x33, 0xfc, 0xb1, 0x40, 0xa5, 0x09, 0x81, 0x3d, 0xbd, 0xac, 0x90, 0x06, 0xc3, - 0x60, 0x14, 0x31, 0xbb, 0x26, 0x8f, 0xa1, 0x8d, 0x35, 0x96, 0x9a, 0xb6, 0x86, 0xc1, 0x28, 0x4e, - 0xa3, 0x71, 0x9d, 0x8e, 0xcf, 0x0c, 0xc0, 0x1c, 0x9e, 0x7c, 0x81, 0xb6, 0x8d, 0xc9, 0x13, 0xe8, - 0x2c, 0xaa, 0x42, 0xf0, 0xcc, 0xd6, 0xc7, 0x69, 0xdf, 0x50, 0xcf, 0xf3, 0x02, 0x2f, 0xca, 0xa9, - 0x60, 0x3e, 0x47, 0x8e, 0x20, 0x9e, 0x69, 0x5d, 0xf9, 0x2d, 0x7d, 0xd7, 0xdb, 0x86, 0x3a, 0xb9, - 0xba, 0xba, 0xf4, 0x30, 0x6b, 0x72, 0x92, 0xdf, 0x21, 0xf4, 0x56, 0x7d, 0xc8, 0x01, 0xb4, 0xf2, - 0xcc, 0x2b, 0x6c, 0xe5, 0x99, 0xd1, 0xac, 0xf2, 0x9f, 0x68, 0x1b, 0x85, 0xcc, 0xae, 0xc9, 0x53, - 0x38, 0x30, 0xdf, 0x0b, 0x75, 0x8a, 0x53, 0x94, 0x12, 0x33, 0x1a, 0x0e, 0x83, 0x51, 0x8f, 0x6d, - 0xa1, 0xe4, 0x2e, 0x74, 0xc4, 0x74, 0xaa, 0x50, 0xd3, 0x3d, 0x5b, 0xed, 0x23, 0xf2, 0x02, 0x7a, - 0x37, 0xa8, 0xf9, 0x29, 0xd7, 0x9c, 0xb6, 0x87, 0xe1, 0x28, 0x4e, 0x07, 0xcd, 0xb3, 0x8c, 0x3f, - 0xfa, 0xe4, 0x59, 0xa9, 0xe5, 0x92, 0xfd, 0xe7, 0x92, 0x07, 0x10, 0xe5, 0xea, 0x92, 0x4b, 0x9d, - 0xf3, 0x82, 0x76, 0xec, 0x96, 0x6b, 0x80, 0x50, 0xe8, 0xe6, 0xea, 0x3c, 0x2f, 0x79, 0x41, 0xbb, - 0x36, 0xb7, 0x0a, 0x8d, 0xde, 0xca, 0x91, 0x3e, 0x5b, 0x93, 0x14, 0xed, 0x0d, 0xc3, 0x51, 0xc4, - 0xb6, 0x50, 0x72, 0x0c, 0x5d, 0xa5, 0x85, 0xe4, 0xdf, 0x90, 0x46, 0x56, 0xd6, 0xbd, 0x0d, 0x59, - 0x9f, 0x5c, 0xce, 0xa9, 0x5a, 0x31, 0x07, 0x6f, 0x60, 0x7f, 0x43, 0x2f, 0x39, 0x84, 0x70, 0x8e, - 0x4b, 0x6f, 0xa1, 0x59, 0x92, 0x3b, 0xd0, 0xae, 0x79, 0xb1, 0x70, 0x26, 0x46, 0xcc, 0x05, 0x27, - 0xad, 0x57, 0xc1, 0xe0, 0x04, 0xfa, 0xcd, 0xae, 0xbb, 0xd4, 0x26, 0x7f, 0x03, 0x88, 0x1b, 0x77, - 0x6a, 0xdc, 0xbe, 0x41, 0x3d, 0x13, 0xab, 0xdb, 0xf3, 0x91, 0xe9, 0xb9, 0x90, 0xb9, 0xaf, 0x37, - 0x4b, 0xf2, 0x08, 0x40, 0xe2, 0x8d, 0xd0, 0xf8, 0x2e, 0xcb, 0xa4, 0xbd, 0xbb, 0x88, 0x35, 0x10, - 0x72, 0x0c, 0x9d, 0x19, 0xf2, 0x0c, 0x25, 0xdd, 0xb3, 0x36, 0xdc, 0xdf, 0x1a, 0x9f, 0xf1, 0xc4, - 0x66, 0x9d, 0x11, 0x9e, 0x3a, 0x78, 0x0d, 0x71, 0x03, 0xde, 0xe9, 0x24, 0xbf, 0x02, 0xe8, 0xbb, - 0xff, 0x44, 0x55, 0xa2, 0x54, 0x48, 0x9e, 0x43, 0xdf, 0x0d, 0xa8, 0x8b, 0xfd, 0xc0, 0x1f, 0xae, - 0x65, 0x38, 0x9c, 0x6d, 0xb0, 0x48, 0x02, 0x7d, 0x89, 0xdf, 0xf1, 0xab, 0x76, 0xf7, 0x69, 0xf7, - 0xe9, 0xb1, 0x0d, 0xcc, 0x1c, 0x5d, 0x69, 0x51, 0x79, 0x86, 0x1b, 0xdb, 0x06, 0x92, 0xfc, 0x31, - 0x52, 0x1a, 0x5b, 0xb8, 0x02, 0xae, 0x17, 0xea, 0x83, 0xc8, 0x9c, 0x90, 0x90, 0x35, 0x10, 0xf2, - 0x12, 0xba, 0xce, 0x00, 0x45, 0x5b, 0xd6, 0xac, 0x87, 0xdb, 0x2a, 0xbd, 0x5b, 0xca, 0xcf, 0x8d, - 0x67, 0x9b, 0x1f, 0xeb, 0x5a, 0x64, 0x4b, 0x6f, 0xbf, 0x5d, 0x9b, 0x71, 0x68, 0x92, 0x77, 0x31, - 0x31, 0x7d, 0xeb, 0xde, 0x9a, 0x09, 0x2f, 0xb3, 0x02, 0x25, 0x39, 0x02, 0xb8, 0x28, 0x6b, 0x31, - 0x47, 0x03, 0x12, 0xf7, 0x00, 0xac, 0x9f, 0xa2, 0xc1, 0xe1, 0x1a, 0x70, 0x2a, 0x93, 0x5b, 0xd7, - 0x1d, 0xfb, 0x70, 0x1d, 0xff, 0x0b, 0x00, 0x00, 0xff, 0xff, 0xdc, 0x73, 0x61, 0x1c, 0xc9, 0x04, - 0x00, 0x00, +var file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes = make([]protoimpl.MessageInfo, 13) +var file_cmd_tusd_cli_hooks_proto_v2_hook_proto_goTypes = []interface{}{ + (*HookRequest)(nil), // 0: v2.HookRequest + (*Event)(nil), // 1: v2.Event + (*FileInfo)(nil), // 2: v2.FileInfo + (*FileInfoChanges)(nil), // 3: v2.FileInfoChanges + (*HTTPRequest)(nil), // 4: v2.HTTPRequest + (*HookResponse)(nil), // 5: v2.HookResponse + (*HTTPResponse)(nil), // 6: v2.HTTPResponse + nil, // 7: v2.FileInfo.MetaDataEntry + nil, // 8: v2.FileInfo.StorageEntry + nil, // 9: v2.FileInfoChanges.MetaDataEntry + nil, // 10: v2.FileInfoChanges.StorageEntry + nil, // 11: v2.HTTPRequest.HeaderEntry + nil, // 12: v2.HTTPResponse.HeadersEntry +} +var file_cmd_tusd_cli_hooks_proto_v2_hook_proto_depIdxs = []int32{ + 1, // 0: v2.HookRequest.event:type_name -> v2.Event + 2, // 1: v2.Event.upload:type_name -> v2.FileInfo + 4, // 2: v2.Event.httpRequest:type_name -> v2.HTTPRequest + 7, // 3: v2.FileInfo.metaData:type_name -> v2.FileInfo.MetaDataEntry + 8, // 4: v2.FileInfo.storage:type_name -> v2.FileInfo.StorageEntry + 9, // 5: v2.FileInfoChanges.metaData:type_name -> v2.FileInfoChanges.MetaDataEntry + 10, // 6: v2.FileInfoChanges.storage:type_name -> v2.FileInfoChanges.StorageEntry + 11, // 7: v2.HTTPRequest.header:type_name -> v2.HTTPRequest.HeaderEntry + 6, // 8: v2.HookResponse.httpResponse:type_name -> v2.HTTPResponse + 3, // 9: v2.HookResponse.changeFileInfo:type_name -> v2.FileInfoChanges + 12, // 10: v2.HTTPResponse.headers:type_name -> v2.HTTPResponse.HeadersEntry + 0, // 11: v2.HookHandler.InvokeHook:input_type -> v2.HookRequest + 5, // 12: v2.HookHandler.InvokeHook:output_type -> v2.HookResponse + 12, // [12:13] is the sub-list for method output_type + 11, // [11:12] is the sub-list for method input_type + 11, // [11:11] is the sub-list for extension type_name + 11, // [11:11] is the sub-list for extension extendee + 0, // [0:11] is the sub-list for field type_name } -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConnInterface - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion6 - -// HookHandlerClient is the client API for HookHandler service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type HookHandlerClient interface { - // Sends a hook - InvokeHook(ctx context.Context, in *HookRequest, opts ...grpc.CallOption) (*HookResponse, error) -} - -type hookHandlerClient struct { - cc grpc.ClientConnInterface -} - -func NewHookHandlerClient(cc grpc.ClientConnInterface) HookHandlerClient { - return &hookHandlerClient{cc} -} - -func (c *hookHandlerClient) InvokeHook(ctx context.Context, in *HookRequest, opts ...grpc.CallOption) (*HookResponse, error) { - out := new(HookResponse) - err := c.cc.Invoke(ctx, "/v2.HookHandler/InvokeHook", in, out, opts...) - if err != nil { - return nil, err +func init() { file_cmd_tusd_cli_hooks_proto_v2_hook_proto_init() } +func file_cmd_tusd_cli_hooks_proto_v2_hook_proto_init() { + if File_cmd_tusd_cli_hooks_proto_v2_hook_proto != nil { + return } - return out, nil -} - -// HookHandlerServer is the server API for HookHandler service. -type HookHandlerServer interface { - // Sends a hook - InvokeHook(context.Context, *HookRequest) (*HookResponse, error) -} - -// UnimplementedHookHandlerServer can be embedded to have forward compatible implementations. -type UnimplementedHookHandlerServer struct { -} - -func (*UnimplementedHookHandlerServer) InvokeHook(ctx context.Context, req *HookRequest) (*HookResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method InvokeHook not implemented") -} - -func RegisterHookHandlerServer(s *grpc.Server, srv HookHandlerServer) { - s.RegisterService(&_HookHandler_serviceDesc, srv) -} - -func _HookHandler_InvokeHook_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(HookRequest) - if err := dec(in); err != nil { - return nil, err + if !protoimpl.UnsafeEnabled { + file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HookRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Event); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*FileInfo); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*FileInfoChanges); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HTTPRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HookResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*HTTPResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } - if interceptor == nil { - return srv.(HookHandlerServer).InvokeHook(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/v2.HookHandler/InvokeHook", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(HookHandlerServer).InvokeHook(ctx, req.(*HookRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _HookHandler_serviceDesc = grpc.ServiceDesc{ - ServiceName: "v2.HookHandler", - HandlerType: (*HookHandlerServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "InvokeHook", - Handler: _HookHandler_InvokeHook_Handler, + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_cmd_tusd_cli_hooks_proto_v2_hook_proto_rawDesc, + NumEnums: 0, + NumMessages: 13, + NumExtensions: 0, + NumServices: 1, }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "v2/hook.proto", + GoTypes: file_cmd_tusd_cli_hooks_proto_v2_hook_proto_goTypes, + DependencyIndexes: file_cmd_tusd_cli_hooks_proto_v2_hook_proto_depIdxs, + MessageInfos: file_cmd_tusd_cli_hooks_proto_v2_hook_proto_msgTypes, + }.Build() + File_cmd_tusd_cli_hooks_proto_v2_hook_proto = out.File + file_cmd_tusd_cli_hooks_proto_v2_hook_proto_rawDesc = nil + file_cmd_tusd_cli_hooks_proto_v2_hook_proto_goTypes = nil + file_cmd_tusd_cli_hooks_proto_v2_hook_proto_depIdxs = nil } diff --git a/pkg/proto/v2/hook_grpc.pb.go b/pkg/proto/v2/hook_grpc.pb.go new file mode 100644 index 0000000..9affec9 --- /dev/null +++ b/pkg/proto/v2/hook_grpc.pb.go @@ -0,0 +1,115 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v3.21.12 +// source: cmd/tusd/cli/hooks/proto/v2/hook.proto + +package v2 + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// HookHandlerClient is the client API for HookHandler service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type HookHandlerClient interface { + // 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. + InvokeHook(ctx context.Context, in *HookRequest, opts ...grpc.CallOption) (*HookResponse, error) +} + +type hookHandlerClient struct { + cc grpc.ClientConnInterface +} + +func NewHookHandlerClient(cc grpc.ClientConnInterface) HookHandlerClient { + return &hookHandlerClient{cc} +} + +func (c *hookHandlerClient) InvokeHook(ctx context.Context, in *HookRequest, opts ...grpc.CallOption) (*HookResponse, error) { + out := new(HookResponse) + err := c.cc.Invoke(ctx, "/v2.HookHandler/InvokeHook", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// HookHandlerServer is the server API for HookHandler service. +// All implementations must embed UnimplementedHookHandlerServer +// for forward compatibility +type HookHandlerServer interface { + // 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. + InvokeHook(context.Context, *HookRequest) (*HookResponse, error) + mustEmbedUnimplementedHookHandlerServer() +} + +// UnimplementedHookHandlerServer must be embedded to have forward compatible implementations. +type UnimplementedHookHandlerServer struct { +} + +func (UnimplementedHookHandlerServer) InvokeHook(context.Context, *HookRequest) (*HookResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method InvokeHook not implemented") +} +func (UnimplementedHookHandlerServer) mustEmbedUnimplementedHookHandlerServer() {} + +// UnsafeHookHandlerServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to HookHandlerServer will +// result in compilation errors. +type UnsafeHookHandlerServer interface { + mustEmbedUnimplementedHookHandlerServer() +} + +func RegisterHookHandlerServer(s grpc.ServiceRegistrar, srv HookHandlerServer) { + s.RegisterService(&HookHandler_ServiceDesc, srv) +} + +func _HookHandler_InvokeHook_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(HookRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(HookHandlerServer).InvokeHook(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/v2.HookHandler/InvokeHook", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(HookHandlerServer).InvokeHook(ctx, req.(*HookRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// HookHandler_ServiceDesc is the grpc.ServiceDesc for HookHandler service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var HookHandler_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "v2.HookHandler", + HandlerType: (*HookHandlerServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "InvokeHook", + Handler: _HookHandler_InvokeHook_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "cmd/tusd/cli/hooks/proto/v2/hook.proto", +}