From 48c7efcb6ded5f882e5b797e337e119f16315f03 Mon Sep 17 00:00:00 2001 From: Jia Rong Wu Date: Mon, 3 Oct 2022 12:14:08 -0400 Subject: [PATCH] Adding a gRPC server example written in Python. (#11) --- README.md | 57 +- .../grpc_python-pre-insert_header/README.md | 56 ++ .../proto/.gitignore | 4 + .../proto/coprocess_common_pb2.py | 115 +++ .../proto/coprocess_grpc_pb2.py | 34 + .../coprocess_mini_request_object_pb2.py | 402 +++++++++++ .../proto/coprocess_object_pb2.py | 87 +++ .../proto/coprocess_object_pb2_grpc.py | 99 +++ .../proto/coprocess_response_object_pb2.py | 139 ++++ .../proto/coprocess_return_overrides_pb2.py | 144 ++++ .../proto/coprocess_session_state_pb2.py | 657 ++++++++++++++++++ .../proto/sample_server.py | 75 ++ .../requirements.txt | 4 + 13 files changed, 1845 insertions(+), 28 deletions(-) create mode 100644 plugins/grpc_python-pre-insert_header/README.md create mode 100644 plugins/grpc_python-pre-insert_header/proto/.gitignore create mode 100644 plugins/grpc_python-pre-insert_header/proto/coprocess_common_pb2.py create mode 100644 plugins/grpc_python-pre-insert_header/proto/coprocess_grpc_pb2.py create mode 100644 plugins/grpc_python-pre-insert_header/proto/coprocess_mini_request_object_pb2.py create mode 100644 plugins/grpc_python-pre-insert_header/proto/coprocess_object_pb2.py create mode 100644 plugins/grpc_python-pre-insert_header/proto/coprocess_object_pb2_grpc.py create mode 100644 plugins/grpc_python-pre-insert_header/proto/coprocess_response_object_pb2.py create mode 100644 plugins/grpc_python-pre-insert_header/proto/coprocess_return_overrides_pb2.py create mode 100644 plugins/grpc_python-pre-insert_header/proto/coprocess_session_state_pb2.py create mode 100644 plugins/grpc_python-pre-insert_header/proto/sample_server.py create mode 100644 plugins/grpc_python-pre-insert_header/requirements.txt diff --git a/README.md b/README.md index 69e5f76..2c38ea0 100644 --- a/README.md +++ b/README.md @@ -5,34 +5,35 @@ This is a repository that contains examples of [Tyk Plugins](https://tyk.io/docs Here's the [different phases you can inject plugins](https://tyk.io/docs/concepts/middleware-execution-order/) in the request lifecycle. A [response plugin](https://tyk.io/docs/plugins/response-plugins/) is also possible. ## Examples -Language | Phase | Description | Link --------- | ----- |------------ | --- -Golang | All | Go plugin for v3.2.2 which uses Go Mods | [Link](plugins/go-plugin-v322-example) -Golang | Pre | Injects client certificate attributes as a Header | [Link](plugins/go-pre-cert_inject_dn) -GoLang | Post-Auth | OAuth2 Introspection | [Link](plugins/go-postauth-oauth2_introspection) -GoLang | Post-Auth | Authorizes request against OPA | [Link](plugins/go-postauth-opa_integration) -Golang | Post + Auth | Dummy one to test the 2 hooks in go | [Link](plugins/go-auth-multiple_hook_example) -Golang | Pre | Checks Basic Auth creds against an AWS DynamoDB instance | [Link](plugins/go-auth-basicauth_dynamodb) -gRPC (GoLang) | Pre | Header Injection & Auth example | [Link](plugins/grpc_go-auth-pre_headerinject_authhook) -gRPC (GoLang) | Pre | Invokes an AWS Lambda | [Link](plugins/grpc_go-pre-aws_lambda) -gRPC (Java) | Auth | Decodes JWT, inserts a claim and resigns it | [Link](plugins/grpc_java-auth-jwt_decoder_repackager) -gRPC (Java) | Post | Inserts Metadata from the portal requested key as an HTTP header | [Link](plugins/grpc_java-post-insert_metadata_as_header) -gRPC (.NET) | Auth | Performs auth check against a SQL server | [Link](plugins/grpc_dotnet-auth_sql_basicauth ) -gRPC (Ruby) | Pre | Modifies HTTP header | [Link](plugins/grpc_ruby-pre-header_modify) -Javascript | Pre | Inserts tracing ID in header | [Link](plugins/js-pre-insert_header) -Javascript | Pre | Auth Token & mTLS protection | [Link](plugins/js-pre-mtls_token_auth) -Javascript | Pre | Evaluates the validity of a Tyk Token | [Link](plugins/js-pre-token_inspection) -Javascript | Post | Checks API requests against a WAF | [Link](plugins/js-pre-post-waf) -Javascript | Post-Auth | Checks the request path against the user's meta data. If there is a cross-over, will deny the request | [Link](plugins/js-post_auth-checks_path_against_metadata) -Lua | Pre | header injection | [Link](plugins/lua-pre-header_injection) -Python | Auth | Checks API requests against a hard-coded token | [Link](plugins/py-auth_example) -Python | Auth | Validates credentials against an LDAP server | [Link](plugins/py-auth-ldap_example) -Python | Pre | This plugin sends a message to a queue server, it uses kombu as the messaging library | [Link](plugins/py-pre-message_queue_kombo) -Python | Pre | This plugin sends log data to a Datadog agent. | [Link](plugins/py-pre-datadog_logger) -Python | Pre | This plugin sends log data to a Loggly HTTPS endpoint | [Link](plugins/py-pre-loggly_integration) -Python | Pre | This plugin will block requests from specific user agents, using regular expressions. | [Link](plugins/py-pre-bot_detection) -Python | Pre + Post | Inserts a correlation ID as a header | [Link](plugins/py-pre_post-correlation_id_insert) -Python | Post | Injects a signed JWT as Authorization Header | [Link](plugins/py-post-jwt-injection) +Language | Phase | Description | Link +-------- | ----- |----------------------------------------------------------------------------------------------------------| --- +Golang | All | Go plugin for v3.2.2 which uses Go Mods | [Link](plugins/go-plugin-v322-example) +Golang | Pre | Injects client certificate attributes as a Header | [Link](plugins/go-pre-cert_inject_dn) +GoLang | Post-Auth | OAuth2 Introspection | [Link](plugins/go-postauth-oauth2_introspection) +GoLang | Post-Auth | Authorizes request against OPA | [Link](plugins/go-postauth-opa_integration) +Golang | Post + Auth | Dummy one to test the 2 hooks in go | [Link](plugins/go-auth-multiple_hook_example) +Golang | Pre | Checks Basic Auth creds against an AWS DynamoDB instance | [Link](plugins/go-auth-basicauth_dynamodb) +gRPC (GoLang) | Pre | Header Injection & Auth example | [Link](plugins/grpc_go-auth-pre_headerinject_authhook) +gRPC (GoLang) | Pre | Invokes an AWS Lambda | [Link](plugins/grpc_go-pre-aws_lambda) +gRPC (Java) | Auth | Decodes JWT, inserts a claim and resigns it | [Link](plugins/grpc_java-auth-jwt_decoder_repackager) +gRPC (Java) | Post | Inserts Metadata from the portal requested key as an HTTP header | [Link](plugins/grpc_java-post-insert_metadata_as_header) +gRPC (.NET) | Auth | Performs auth check against a SQL server | [Link](plugins/grpc_dotnet-auth_sql_basicauth ) +gRPC (Ruby) | Pre | Modifies HTTP header | [Link](plugins/grpc_ruby-pre-header_modify) +gRPC (Python) | Pre | Inserts a HTTP header | [Link](plugins/grpc_python-pre-insert_header) +Javascript | Pre | Inserts tracing ID in header | [Link](plugins/js-pre-insert_header) +Javascript | Pre | Auth Token & mTLS protection | [Link](plugins/js-pre-mtls_token_auth) +Javascript | Pre | Evaluates the validity of a Tyk Token | [Link](plugins/js-pre-token_inspection) +Javascript | Post | Checks API requests against a WAF | [Link](plugins/js-pre-post-waf) +Javascript | Post-Auth | Checks the request path against the user's meta data. If there is a cross-over, will deny the request | [Link](plugins/js-post_auth-checks_path_against_metadata) +Lua | Pre | header injection | [Link](plugins/lua-pre-header_injection) +Python | Auth | Checks API requests against a hard-coded token | [Link](plugins/py-auth_example) +Python | Auth | Validates credentials against an LDAP server | [Link](plugins/py-auth-ldap_example) +Python | Pre | This plugin sends a message to a queue server, it uses kombu as the messaging library | [Link](plugins/py-pre-message_queue_kombo) +Python | Pre | This plugin sends log data to a Datadog agent. | [Link](plugins/py-pre-datadog_logger) +Python | Pre | This plugin sends log data to a Loggly HTTPS endpoint | [Link](plugins/py-pre-loggly_integration) +Python | Pre | This plugin will block requests from specific user agents, using regular expressions. | [Link](plugins/py-pre-bot_detection) +Python | Pre + Post | Inserts a correlation ID as a header | [Link](plugins/py-pre_post-correlation_id_insert) +Python | Post | Injects a signed JWT as Authorization Header | [Link](plugins/py-post-jwt-injection) ## Virtual Endpoints diff --git a/plugins/grpc_python-pre-insert_header/README.md b/plugins/grpc_python-pre-insert_header/README.md new file mode 100644 index 0000000..3eaf6e8 --- /dev/null +++ b/plugins/grpc_python-pre-insert_header/README.md @@ -0,0 +1,56 @@ +# Tyk gRPC Plugin Demo (Python) +This plugin will allow users to write gRPC middleware for Tyk using [Python](https://www.python.org/). + +## Requirements: +Please find the pip3 requirements located in the `requirements.txt` file. +* Python 3.* +* Tyk Gateway 4.0.* + +## Deploying the gRPC Python Server +Assuming you are in the `custom-plugins/plugins/grpc_python-pre-insert_header/` directory, install the requirements, navigate into the `proto/` directory and launch the Python 3 server. +```bash +pip3 install -r requirements.txt + +cd proto/ + +python3 sample_server.py +``` +Please note that you may also launch the sample_server.py process by attaching a debugger to it. This allows you to intercept calls that the Tyk-Gateway makes to your gRPC server and is useful for debugging purposes. + +## Enabling gRPC on the Tyk-Gateway +The server now will be running on tcp://localhost:5555. Please find the documentation for enabling gRPC plugins [here](https://tyk.io/docs/plugins/supported-languages/rich-plugins/grpc/write-grpc-plugin/). + +At minimum, the Tyk-Gateway needs to know that coprocess is enabled, as well as where the gRPC server lives. These options can be set in the configuration file with the following definitions: +```json +"coprocess_options" : { + "enable_coprocess": true, + "coprocess_grpc_server": "tcp://localhost:5555" +} +``` + +However, if you prefer using [environment variables](https://tyk.io/docs/tyk-oss-gateway/configuration/), ensure that you have the following environment variables configured for the Tyk-Gateway. Environment variables supercede the configuration files when both are set. + +```bash +TYK_GW_COPROCESSOPTIONS_ENABLECOPROCESS=true +TYK_GW_COPROCESSOPTIONS_COPROCESSGRPCSERVER=tcp://localhost:5555 +``` + +## Adding gRPC to the API Definition +You'll notice that in `sample_server.py` there are a few example functions such as `MyPreMiddleware`, `MyPostMiddleware` and `MyAuthCheck`. These functions are where you can add your custom logic. Supposing you wish to inject a header at the `Custom pre-middlewares` section of the [request middleware chain](https://tyk.io/docs/concepts/middleware-execution-order/), you can add the following to your Tyk API definition: +```json + "custom_middleware": { + "pre": [ + { + "name": "MyPreMiddleware", + "path": "", + "require_session": false, + "raw_body_only": false + } + ], + "driver": "grpc" + }, +``` +Essentially this specifies that we are invoking some gRPC function `MyPreMiddlware` at the `pre` stage of the request. When making calls to your Tyk managed API, you will find that the header `MyPreMiddleware` gets inserted in the API request to your upstream service. + +## Updating protobuf definitions +Should you need to update the protobuf definitions, you simply need to generate them from the Tyk-Gateway repository [located here](https://github.com/TykTechnologies/tyk). The script to update the protobuf bindings is located [here](https://github.com/TykTechnologies/tyk/blob/master/coprocess/proto/update_bindings.sh), and the resultant protobuf definitions can be located under the directory `tyk/coprocess/bindings/python/*`. diff --git a/plugins/grpc_python-pre-insert_header/proto/.gitignore b/plugins/grpc_python-pre-insert_header/proto/.gitignore new file mode 100644 index 0000000..749ccda --- /dev/null +++ b/plugins/grpc_python-pre-insert_header/proto/.gitignore @@ -0,0 +1,4 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class diff --git a/plugins/grpc_python-pre-insert_header/proto/coprocess_common_pb2.py b/plugins/grpc_python-pre-insert_header/proto/coprocess_common_pb2.py new file mode 100644 index 0000000..f9e7af5 --- /dev/null +++ b/plugins/grpc_python-pre-insert_header/proto/coprocess_common_pb2.py @@ -0,0 +1,115 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: coprocess_common.proto + +from google.protobuf.internal import enum_type_wrapper +from google.protobuf import descriptor as _descriptor +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) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='coprocess_common.proto', + package='coprocess', + syntax='proto3', + serialized_options=None, + serialized_pb=b'\n\x16\x63oprocess_common.proto\x12\tcoprocess\"\x1c\n\x0bStringSlice\x12\r\n\x05items\x18\x01 \x03(\t*]\n\x08HookType\x12\x0b\n\x07Unknown\x10\x00\x12\x07\n\x03Pre\x10\x01\x12\x08\n\x04Post\x10\x02\x12\x0f\n\x0bPostKeyAuth\x10\x03\x12\x12\n\x0e\x43ustomKeyCheck\x10\x04\x12\x0c\n\x08Response\x10\x05\x62\x06proto3' +) + +_HOOKTYPE = _descriptor.EnumDescriptor( + name='HookType', + full_name='coprocess.HookType', + filename=None, + file=DESCRIPTOR, + values=[ + _descriptor.EnumValueDescriptor( + name='Unknown', index=0, number=0, + serialized_options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='Pre', index=1, number=1, + serialized_options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='Post', index=2, number=2, + serialized_options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='PostKeyAuth', index=3, number=3, + serialized_options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='CustomKeyCheck', index=4, number=4, + serialized_options=None, + type=None), + _descriptor.EnumValueDescriptor( + name='Response', index=5, number=5, + serialized_options=None, + type=None), + ], + containing_type=None, + serialized_options=None, + serialized_start=67, + serialized_end=160, +) +_sym_db.RegisterEnumDescriptor(_HOOKTYPE) + +HookType = enum_type_wrapper.EnumTypeWrapper(_HOOKTYPE) +Unknown = 0 +Pre = 1 +Post = 2 +PostKeyAuth = 3 +CustomKeyCheck = 4 +Response = 5 + + + +_STRINGSLICE = _descriptor.Descriptor( + name='StringSlice', + full_name='coprocess.StringSlice', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='items', full_name='coprocess.StringSlice.items', index=0, + number=1, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=37, + serialized_end=65, +) + +DESCRIPTOR.message_types_by_name['StringSlice'] = _STRINGSLICE +DESCRIPTOR.enum_types_by_name['HookType'] = _HOOKTYPE +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +StringSlice = _reflection.GeneratedProtocolMessageType('StringSlice', (_message.Message,), { + 'DESCRIPTOR' : _STRINGSLICE, + '__module__' : 'coprocess_common_pb2' + # @@protoc_insertion_point(class_scope:coprocess.StringSlice) + }) +_sym_db.RegisterMessage(StringSlice) + + +# @@protoc_insertion_point(module_scope) diff --git a/plugins/grpc_python-pre-insert_header/proto/coprocess_grpc_pb2.py b/plugins/grpc_python-pre-insert_header/proto/coprocess_grpc_pb2.py new file mode 100644 index 0000000..807c872 --- /dev/null +++ b/plugins/grpc_python-pre-insert_header/proto/coprocess_grpc_pb2.py @@ -0,0 +1,34 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: coprocess_grpc.proto + +import sys +_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +from google.protobuf import descriptor as _descriptor +from google.protobuf import message as _message +from google.protobuf import reflection as _reflection +from google.protobuf import symbol_database as _symbol_database +from google.protobuf import descriptor_pb2 +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + +import coprocess_mini_request_object_pb2 as coprocess__mini__request__object__pb2 +import coprocess_session_state_pb2 as coprocess__session__state__pb2 +import coprocess_common_pb2 as coprocess__common__pb2 + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='coprocess_grpc.proto', + package='coprocess', + syntax='proto3', + serialized_pb=_b('\n\x14\x63oprocess_grpc.proto\x12\tcoprocess\x1a#coprocess_mini_request_object.proto\x1a\x1d\x63oprocess_session_state.proto\x1a\x16\x63oprocess_common.protob\x06proto3') + , + dependencies=[coprocess__mini__request__object__pb2.DESCRIPTOR,coprocess__session__state__pb2.DESCRIPTOR,coprocess__common__pb2.DESCRIPTOR,]) +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + + + + + +# @@protoc_insertion_point(module_scope) diff --git a/plugins/grpc_python-pre-insert_header/proto/coprocess_mini_request_object_pb2.py b/plugins/grpc_python-pre-insert_header/proto/coprocess_mini_request_object_pb2.py new file mode 100644 index 0000000..e723be5 --- /dev/null +++ b/plugins/grpc_python-pre-insert_header/proto/coprocess_mini_request_object_pb2.py @@ -0,0 +1,402 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: coprocess_mini_request_object.proto + +from google.protobuf import descriptor as _descriptor +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) + +_sym_db = _symbol_database.Default() + + +import coprocess_return_overrides_pb2 as coprocess__return__overrides__pb2 + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='coprocess_mini_request_object.proto', + package='coprocess', + syntax='proto3', + serialized_options=None, + serialized_pb=b'\n#coprocess_mini_request_object.proto\x12\tcoprocess\x1a coprocess_return_overrides.proto\"\x9a\x06\n\x11MiniRequestObject\x12:\n\x07headers\x18\x01 \x03(\x0b\x32).coprocess.MiniRequestObject.HeadersEntry\x12\x41\n\x0bset_headers\x18\x02 \x03(\x0b\x32,.coprocess.MiniRequestObject.SetHeadersEntry\x12\x16\n\x0e\x64\x65lete_headers\x18\x03 \x03(\t\x12\x0c\n\x04\x62ody\x18\x04 \x01(\t\x12\x0b\n\x03url\x18\x05 \x01(\t\x12\x38\n\x06params\x18\x06 \x03(\x0b\x32(.coprocess.MiniRequestObject.ParamsEntry\x12?\n\nadd_params\x18\x07 \x03(\x0b\x32+.coprocess.MiniRequestObject.AddParamsEntry\x12I\n\x0f\x65xtended_params\x18\x08 \x03(\x0b\x32\x30.coprocess.MiniRequestObject.ExtendedParamsEntry\x12\x15\n\rdelete_params\x18\t \x03(\t\x12\x34\n\x10return_overrides\x18\n \x01(\x0b\x32\x1a.coprocess.ReturnOverrides\x12\x0e\n\x06method\x18\x0b \x01(\t\x12\x13\n\x0brequest_uri\x18\x0c \x01(\t\x12\x0e\n\x06scheme\x18\r \x01(\t\x12\x10\n\x08raw_body\x18\x0e \x01(\x0c\x1a.\n\x0cHeadersEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a\x31\n\x0fSetHeadersEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a-\n\x0bParamsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a\x30\n\x0e\x41\x64\x64ParamsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a\x35\n\x13\x45xtendedParamsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x62\x06proto3' + , + dependencies=[coprocess__return__overrides__pb2.DESCRIPTOR,]) + + + + +_MINIREQUESTOBJECT_HEADERSENTRY = _descriptor.Descriptor( + name='HeadersEntry', + full_name='coprocess.MiniRequestObject.HeadersEntry', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='key', full_name='coprocess.MiniRequestObject.HeadersEntry.key', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='value', full_name='coprocess.MiniRequestObject.HeadersEntry.value', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=b'8\001', + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=630, + serialized_end=676, +) + +_MINIREQUESTOBJECT_SETHEADERSENTRY = _descriptor.Descriptor( + name='SetHeadersEntry', + full_name='coprocess.MiniRequestObject.SetHeadersEntry', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='key', full_name='coprocess.MiniRequestObject.SetHeadersEntry.key', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='value', full_name='coprocess.MiniRequestObject.SetHeadersEntry.value', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=b'8\001', + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=678, + serialized_end=727, +) + +_MINIREQUESTOBJECT_PARAMSENTRY = _descriptor.Descriptor( + name='ParamsEntry', + full_name='coprocess.MiniRequestObject.ParamsEntry', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='key', full_name='coprocess.MiniRequestObject.ParamsEntry.key', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='value', full_name='coprocess.MiniRequestObject.ParamsEntry.value', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=b'8\001', + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=729, + serialized_end=774, +) + +_MINIREQUESTOBJECT_ADDPARAMSENTRY = _descriptor.Descriptor( + name='AddParamsEntry', + full_name='coprocess.MiniRequestObject.AddParamsEntry', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='key', full_name='coprocess.MiniRequestObject.AddParamsEntry.key', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='value', full_name='coprocess.MiniRequestObject.AddParamsEntry.value', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=b'8\001', + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=776, + serialized_end=824, +) + +_MINIREQUESTOBJECT_EXTENDEDPARAMSENTRY = _descriptor.Descriptor( + name='ExtendedParamsEntry', + full_name='coprocess.MiniRequestObject.ExtendedParamsEntry', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='key', full_name='coprocess.MiniRequestObject.ExtendedParamsEntry.key', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='value', full_name='coprocess.MiniRequestObject.ExtendedParamsEntry.value', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=b'8\001', + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=826, + serialized_end=879, +) + +_MINIREQUESTOBJECT = _descriptor.Descriptor( + name='MiniRequestObject', + full_name='coprocess.MiniRequestObject', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='headers', full_name='coprocess.MiniRequestObject.headers', index=0, + number=1, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='set_headers', full_name='coprocess.MiniRequestObject.set_headers', index=1, + number=2, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='delete_headers', full_name='coprocess.MiniRequestObject.delete_headers', index=2, + number=3, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='body', full_name='coprocess.MiniRequestObject.body', index=3, + number=4, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='url', full_name='coprocess.MiniRequestObject.url', index=4, + number=5, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='params', full_name='coprocess.MiniRequestObject.params', index=5, + number=6, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='add_params', full_name='coprocess.MiniRequestObject.add_params', index=6, + number=7, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='extended_params', full_name='coprocess.MiniRequestObject.extended_params', index=7, + number=8, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='delete_params', full_name='coprocess.MiniRequestObject.delete_params', index=8, + number=9, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='return_overrides', full_name='coprocess.MiniRequestObject.return_overrides', index=9, + number=10, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='method', full_name='coprocess.MiniRequestObject.method', index=10, + number=11, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='request_uri', full_name='coprocess.MiniRequestObject.request_uri', index=11, + number=12, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='scheme', full_name='coprocess.MiniRequestObject.scheme', index=12, + number=13, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='raw_body', full_name='coprocess.MiniRequestObject.raw_body', index=13, + number=14, type=12, cpp_type=9, label=1, + has_default_value=False, default_value=b"", + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[_MINIREQUESTOBJECT_HEADERSENTRY, _MINIREQUESTOBJECT_SETHEADERSENTRY, _MINIREQUESTOBJECT_PARAMSENTRY, _MINIREQUESTOBJECT_ADDPARAMSENTRY, _MINIREQUESTOBJECT_EXTENDEDPARAMSENTRY, ], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=85, + serialized_end=879, +) + +_MINIREQUESTOBJECT_HEADERSENTRY.containing_type = _MINIREQUESTOBJECT +_MINIREQUESTOBJECT_SETHEADERSENTRY.containing_type = _MINIREQUESTOBJECT +_MINIREQUESTOBJECT_PARAMSENTRY.containing_type = _MINIREQUESTOBJECT +_MINIREQUESTOBJECT_ADDPARAMSENTRY.containing_type = _MINIREQUESTOBJECT +_MINIREQUESTOBJECT_EXTENDEDPARAMSENTRY.containing_type = _MINIREQUESTOBJECT +_MINIREQUESTOBJECT.fields_by_name['headers'].message_type = _MINIREQUESTOBJECT_HEADERSENTRY +_MINIREQUESTOBJECT.fields_by_name['set_headers'].message_type = _MINIREQUESTOBJECT_SETHEADERSENTRY +_MINIREQUESTOBJECT.fields_by_name['params'].message_type = _MINIREQUESTOBJECT_PARAMSENTRY +_MINIREQUESTOBJECT.fields_by_name['add_params'].message_type = _MINIREQUESTOBJECT_ADDPARAMSENTRY +_MINIREQUESTOBJECT.fields_by_name['extended_params'].message_type = _MINIREQUESTOBJECT_EXTENDEDPARAMSENTRY +_MINIREQUESTOBJECT.fields_by_name['return_overrides'].message_type = coprocess__return__overrides__pb2._RETURNOVERRIDES +DESCRIPTOR.message_types_by_name['MiniRequestObject'] = _MINIREQUESTOBJECT +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +MiniRequestObject = _reflection.GeneratedProtocolMessageType('MiniRequestObject', (_message.Message,), { + + 'HeadersEntry' : _reflection.GeneratedProtocolMessageType('HeadersEntry', (_message.Message,), { + 'DESCRIPTOR' : _MINIREQUESTOBJECT_HEADERSENTRY, + '__module__' : 'coprocess_mini_request_object_pb2' + # @@protoc_insertion_point(class_scope:coprocess.MiniRequestObject.HeadersEntry) + }) + , + + 'SetHeadersEntry' : _reflection.GeneratedProtocolMessageType('SetHeadersEntry', (_message.Message,), { + 'DESCRIPTOR' : _MINIREQUESTOBJECT_SETHEADERSENTRY, + '__module__' : 'coprocess_mini_request_object_pb2' + # @@protoc_insertion_point(class_scope:coprocess.MiniRequestObject.SetHeadersEntry) + }) + , + + 'ParamsEntry' : _reflection.GeneratedProtocolMessageType('ParamsEntry', (_message.Message,), { + 'DESCRIPTOR' : _MINIREQUESTOBJECT_PARAMSENTRY, + '__module__' : 'coprocess_mini_request_object_pb2' + # @@protoc_insertion_point(class_scope:coprocess.MiniRequestObject.ParamsEntry) + }) + , + + 'AddParamsEntry' : _reflection.GeneratedProtocolMessageType('AddParamsEntry', (_message.Message,), { + 'DESCRIPTOR' : _MINIREQUESTOBJECT_ADDPARAMSENTRY, + '__module__' : 'coprocess_mini_request_object_pb2' + # @@protoc_insertion_point(class_scope:coprocess.MiniRequestObject.AddParamsEntry) + }) + , + + 'ExtendedParamsEntry' : _reflection.GeneratedProtocolMessageType('ExtendedParamsEntry', (_message.Message,), { + 'DESCRIPTOR' : _MINIREQUESTOBJECT_EXTENDEDPARAMSENTRY, + '__module__' : 'coprocess_mini_request_object_pb2' + # @@protoc_insertion_point(class_scope:coprocess.MiniRequestObject.ExtendedParamsEntry) + }) + , + 'DESCRIPTOR' : _MINIREQUESTOBJECT, + '__module__' : 'coprocess_mini_request_object_pb2' + # @@protoc_insertion_point(class_scope:coprocess.MiniRequestObject) + }) +_sym_db.RegisterMessage(MiniRequestObject) +_sym_db.RegisterMessage(MiniRequestObject.HeadersEntry) +_sym_db.RegisterMessage(MiniRequestObject.SetHeadersEntry) +_sym_db.RegisterMessage(MiniRequestObject.ParamsEntry) +_sym_db.RegisterMessage(MiniRequestObject.AddParamsEntry) +_sym_db.RegisterMessage(MiniRequestObject.ExtendedParamsEntry) + + +_MINIREQUESTOBJECT_HEADERSENTRY._options = None +_MINIREQUESTOBJECT_SETHEADERSENTRY._options = None +_MINIREQUESTOBJECT_PARAMSENTRY._options = None +_MINIREQUESTOBJECT_ADDPARAMSENTRY._options = None +_MINIREQUESTOBJECT_EXTENDEDPARAMSENTRY._options = None +# @@protoc_insertion_point(module_scope) diff --git a/plugins/grpc_python-pre-insert_header/proto/coprocess_object_pb2.py b/plugins/grpc_python-pre-insert_header/proto/coprocess_object_pb2.py new file mode 100644 index 0000000..c30870f --- /dev/null +++ b/plugins/grpc_python-pre-insert_header/proto/coprocess_object_pb2.py @@ -0,0 +1,87 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: coprocess_object.proto +"""Generated protocol buffer code.""" +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) + +_sym_db = _symbol_database.Default() + + +import coprocess_mini_request_object_pb2 as coprocess__mini__request__object__pb2 +import coprocess_response_object_pb2 as coprocess__response__object__pb2 +import coprocess_session_state_pb2 as coprocess__session__state__pb2 +import coprocess_common_pb2 as coprocess__common__pb2 + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x16\x63oprocess_object.proto\x12\tcoprocess\x1a#coprocess_mini_request_object.proto\x1a\x1f\x63oprocess_response_object.proto\x1a\x1d\x63oprocess_session_state.proto\x1a\x16\x63oprocess_common.proto\"\x85\x03\n\x06Object\x12&\n\thook_type\x18\x01 \x01(\x0e\x32\x13.coprocess.HookType\x12\x11\n\thook_name\x18\x02 \x01(\t\x12-\n\x07request\x18\x03 \x01(\x0b\x32\x1c.coprocess.MiniRequestObject\x12(\n\x07session\x18\x04 \x01(\x0b\x32\x17.coprocess.SessionState\x12\x31\n\x08metadata\x18\x05 \x03(\x0b\x32\x1f.coprocess.Object.MetadataEntry\x12)\n\x04spec\x18\x06 \x03(\x0b\x32\x1b.coprocess.Object.SpecEntry\x12+\n\x08response\x18\x07 \x01(\x0b\x32\x19.coprocess.ResponseObject\x1a/\n\rMetadataEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a+\n\tSpecEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"\x18\n\x05\x45vent\x12\x0f\n\x07payload\x18\x01 \x01(\t\"\x0c\n\nEventReply2|\n\nDispatcher\x12\x32\n\x08\x44ispatch\x12\x11.coprocess.Object\x1a\x11.coprocess.Object\"\x00\x12:\n\rDispatchEvent\x12\x10.coprocess.Event\x1a\x15.coprocess.EventReply\"\x00\x62\x06proto3') + + + +_OBJECT = DESCRIPTOR.message_types_by_name['Object'] +_OBJECT_METADATAENTRY = _OBJECT.nested_types_by_name['MetadataEntry'] +_OBJECT_SPECENTRY = _OBJECT.nested_types_by_name['SpecEntry'] +_EVENT = DESCRIPTOR.message_types_by_name['Event'] +_EVENTREPLY = DESCRIPTOR.message_types_by_name['EventReply'] +Object = _reflection.GeneratedProtocolMessageType('Object', (_message.Message,), { + + 'MetadataEntry' : _reflection.GeneratedProtocolMessageType('MetadataEntry', (_message.Message,), { + 'DESCRIPTOR' : _OBJECT_METADATAENTRY, + '__module__' : 'coprocess_object_pb2' + # @@protoc_insertion_point(class_scope:coprocess.Object.MetadataEntry) + }) + , + + 'SpecEntry' : _reflection.GeneratedProtocolMessageType('SpecEntry', (_message.Message,), { + 'DESCRIPTOR' : _OBJECT_SPECENTRY, + '__module__' : 'coprocess_object_pb2' + # @@protoc_insertion_point(class_scope:coprocess.Object.SpecEntry) + }) + , + 'DESCRIPTOR' : _OBJECT, + '__module__' : 'coprocess_object_pb2' + # @@protoc_insertion_point(class_scope:coprocess.Object) + }) +_sym_db.RegisterMessage(Object) +_sym_db.RegisterMessage(Object.MetadataEntry) +_sym_db.RegisterMessage(Object.SpecEntry) + +Event = _reflection.GeneratedProtocolMessageType('Event', (_message.Message,), { + 'DESCRIPTOR' : _EVENT, + '__module__' : 'coprocess_object_pb2' + # @@protoc_insertion_point(class_scope:coprocess.Event) + }) +_sym_db.RegisterMessage(Event) + +EventReply = _reflection.GeneratedProtocolMessageType('EventReply', (_message.Message,), { + 'DESCRIPTOR' : _EVENTREPLY, + '__module__' : 'coprocess_object_pb2' + # @@protoc_insertion_point(class_scope:coprocess.EventReply) + }) +_sym_db.RegisterMessage(EventReply) + +_DISPATCHER = DESCRIPTOR.services_by_name['Dispatcher'] +if _descriptor._USE_C_DESCRIPTORS == False: + + DESCRIPTOR._options = None + _OBJECT_METADATAENTRY._options = None + _OBJECT_METADATAENTRY._serialized_options = b'8\001' + _OBJECT_SPECENTRY._options = None + _OBJECT_SPECENTRY._serialized_options = b'8\001' + _OBJECT._serialized_start=163 + _OBJECT._serialized_end=552 + _OBJECT_METADATAENTRY._serialized_start=460 + _OBJECT_METADATAENTRY._serialized_end=507 + _OBJECT_SPECENTRY._serialized_start=509 + _OBJECT_SPECENTRY._serialized_end=552 + _EVENT._serialized_start=554 + _EVENT._serialized_end=578 + _EVENTREPLY._serialized_start=580 + _EVENTREPLY._serialized_end=592 + _DISPATCHER._serialized_start=594 + _DISPATCHER._serialized_end=718 +# @@protoc_insertion_point(module_scope) diff --git a/plugins/grpc_python-pre-insert_header/proto/coprocess_object_pb2_grpc.py b/plugins/grpc_python-pre-insert_header/proto/coprocess_object_pb2_grpc.py new file mode 100644 index 0000000..a45fe98 --- /dev/null +++ b/plugins/grpc_python-pre-insert_header/proto/coprocess_object_pb2_grpc.py @@ -0,0 +1,99 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc + +import coprocess_object_pb2 as coprocess__object__pb2 + + +class DispatcherStub(object): + """Missing associated documentation comment in .proto file.""" + + def __init__(self, channel): + """Constructor. + + Args: + channel: A grpc.Channel. + """ + self.Dispatch = channel.unary_unary( + '/coprocess.Dispatcher/Dispatch', + request_serializer=coprocess__object__pb2.Object.SerializeToString, + response_deserializer=coprocess__object__pb2.Object.FromString, + ) + self.DispatchEvent = channel.unary_unary( + '/coprocess.Dispatcher/DispatchEvent', + request_serializer=coprocess__object__pb2.Event.SerializeToString, + response_deserializer=coprocess__object__pb2.EventReply.FromString, + ) + + +class DispatcherServicer(object): + """Missing associated documentation comment in .proto file.""" + + def Dispatch(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + def DispatchEvent(self, request, context): + """Missing associated documentation comment in .proto file.""" + context.set_code(grpc.StatusCode.UNIMPLEMENTED) + context.set_details('Method not implemented!') + raise NotImplementedError('Method not implemented!') + + +def add_DispatcherServicer_to_server(servicer, server): + rpc_method_handlers = { + 'Dispatch': grpc.unary_unary_rpc_method_handler( + servicer.Dispatch, + request_deserializer=coprocess__object__pb2.Object.FromString, + response_serializer=coprocess__object__pb2.Object.SerializeToString, + ), + 'DispatchEvent': grpc.unary_unary_rpc_method_handler( + servicer.DispatchEvent, + request_deserializer=coprocess__object__pb2.Event.FromString, + response_serializer=coprocess__object__pb2.EventReply.SerializeToString, + ), + } + generic_handler = grpc.method_handlers_generic_handler( + 'coprocess.Dispatcher', rpc_method_handlers) + server.add_generic_rpc_handlers((generic_handler,)) + + + # This class is part of an EXPERIMENTAL API. +class Dispatcher(object): + """Missing associated documentation comment in .proto file.""" + + @staticmethod + def Dispatch(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, '/coprocess.Dispatcher/Dispatch', + coprocess__object__pb2.Object.SerializeToString, + coprocess__object__pb2.Object.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) + + @staticmethod + def DispatchEvent(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, '/coprocess.Dispatcher/DispatchEvent', + coprocess__object__pb2.Event.SerializeToString, + coprocess__object__pb2.EventReply.FromString, + options, channel_credentials, + insecure, call_credentials, compression, wait_for_ready, timeout, metadata) diff --git a/plugins/grpc_python-pre-insert_header/proto/coprocess_response_object_pb2.py b/plugins/grpc_python-pre-insert_header/proto/coprocess_response_object_pb2.py new file mode 100644 index 0000000..cc71177 --- /dev/null +++ b/plugins/grpc_python-pre-insert_header/proto/coprocess_response_object_pb2.py @@ -0,0 +1,139 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: coprocess_response_object.proto + +from google.protobuf import descriptor as _descriptor +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) + +_sym_db = _symbol_database.Default() + + +import coprocess_return_overrides_pb2 as coprocess__return__overrides__pb2 + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='coprocess_response_object.proto', + package='coprocess', + syntax='proto3', + serialized_options=None, + serialized_pb=b'\n\x1f\x63oprocess_response_object.proto\x12\tcoprocess\x1a coprocess_return_overrides.proto\"\xae\x01\n\x0eResponseObject\x12\x13\n\x0bstatus_code\x18\x01 \x01(\x05\x12\x10\n\x08raw_body\x18\x02 \x01(\x0c\x12\x0c\n\x04\x62ody\x18\x03 \x01(\t\x12\x37\n\x07headers\x18\x04 \x03(\x0b\x32&.coprocess.ResponseObject.HeadersEntry\x1a.\n\x0cHeadersEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x62\x06proto3' + , + dependencies=[coprocess__return__overrides__pb2.DESCRIPTOR,]) + + + + +_RESPONSEOBJECT_HEADERSENTRY = _descriptor.Descriptor( + name='HeadersEntry', + full_name='coprocess.ResponseObject.HeadersEntry', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='key', full_name='coprocess.ResponseObject.HeadersEntry.key', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='value', full_name='coprocess.ResponseObject.HeadersEntry.value', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=b'8\001', + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=209, + serialized_end=255, +) + +_RESPONSEOBJECT = _descriptor.Descriptor( + name='ResponseObject', + full_name='coprocess.ResponseObject', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='status_code', full_name='coprocess.ResponseObject.status_code', index=0, + number=1, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='raw_body', full_name='coprocess.ResponseObject.raw_body', index=1, + number=2, type=12, cpp_type=9, label=1, + has_default_value=False, default_value=b"", + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='body', full_name='coprocess.ResponseObject.body', index=2, + number=3, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='headers', full_name='coprocess.ResponseObject.headers', index=3, + number=4, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[_RESPONSEOBJECT_HEADERSENTRY, ], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=81, + serialized_end=255, +) + +_RESPONSEOBJECT_HEADERSENTRY.containing_type = _RESPONSEOBJECT +_RESPONSEOBJECT.fields_by_name['headers'].message_type = _RESPONSEOBJECT_HEADERSENTRY +DESCRIPTOR.message_types_by_name['ResponseObject'] = _RESPONSEOBJECT +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +ResponseObject = _reflection.GeneratedProtocolMessageType('ResponseObject', (_message.Message,), { + + 'HeadersEntry' : _reflection.GeneratedProtocolMessageType('HeadersEntry', (_message.Message,), { + 'DESCRIPTOR' : _RESPONSEOBJECT_HEADERSENTRY, + '__module__' : 'coprocess_response_object_pb2' + # @@protoc_insertion_point(class_scope:coprocess.ResponseObject.HeadersEntry) + }) + , + 'DESCRIPTOR' : _RESPONSEOBJECT, + '__module__' : 'coprocess_response_object_pb2' + # @@protoc_insertion_point(class_scope:coprocess.ResponseObject) + }) +_sym_db.RegisterMessage(ResponseObject) +_sym_db.RegisterMessage(ResponseObject.HeadersEntry) + + +_RESPONSEOBJECT_HEADERSENTRY._options = None +# @@protoc_insertion_point(module_scope) diff --git a/plugins/grpc_python-pre-insert_header/proto/coprocess_return_overrides_pb2.py b/plugins/grpc_python-pre-insert_header/proto/coprocess_return_overrides_pb2.py new file mode 100644 index 0000000..5bd3727 --- /dev/null +++ b/plugins/grpc_python-pre-insert_header/proto/coprocess_return_overrides_pb2.py @@ -0,0 +1,144 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: coprocess_return_overrides.proto + +from google.protobuf import descriptor as _descriptor +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) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='coprocess_return_overrides.proto', + package='coprocess', + syntax='proto3', + serialized_options=None, + serialized_pb=b'\n coprocess_return_overrides.proto\x12\tcoprocess\"\xd9\x01\n\x0fReturnOverrides\x12\x15\n\rresponse_code\x18\x01 \x01(\x05\x12\x16\n\x0eresponse_error\x18\x02 \x01(\t\x12\x38\n\x07headers\x18\x03 \x03(\x0b\x32\'.coprocess.ReturnOverrides.HeadersEntry\x12\x16\n\x0eoverride_error\x18\x04 \x01(\x08\x12\x15\n\rresponse_body\x18\x05 \x01(\t\x1a.\n\x0cHeadersEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x62\x06proto3' +) + + + + +_RETURNOVERRIDES_HEADERSENTRY = _descriptor.Descriptor( + name='HeadersEntry', + full_name='coprocess.ReturnOverrides.HeadersEntry', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='key', full_name='coprocess.ReturnOverrides.HeadersEntry.key', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='value', full_name='coprocess.ReturnOverrides.HeadersEntry.value', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=b'8\001', + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=219, + serialized_end=265, +) + +_RETURNOVERRIDES = _descriptor.Descriptor( + name='ReturnOverrides', + full_name='coprocess.ReturnOverrides', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='response_code', full_name='coprocess.ReturnOverrides.response_code', index=0, + number=1, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='response_error', full_name='coprocess.ReturnOverrides.response_error', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='headers', full_name='coprocess.ReturnOverrides.headers', index=2, + number=3, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='override_error', full_name='coprocess.ReturnOverrides.override_error', index=3, + number=4, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='response_body', full_name='coprocess.ReturnOverrides.response_body', index=4, + number=5, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[_RETURNOVERRIDES_HEADERSENTRY, ], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=48, + serialized_end=265, +) + +_RETURNOVERRIDES_HEADERSENTRY.containing_type = _RETURNOVERRIDES +_RETURNOVERRIDES.fields_by_name['headers'].message_type = _RETURNOVERRIDES_HEADERSENTRY +DESCRIPTOR.message_types_by_name['ReturnOverrides'] = _RETURNOVERRIDES +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +ReturnOverrides = _reflection.GeneratedProtocolMessageType('ReturnOverrides', (_message.Message,), { + + 'HeadersEntry' : _reflection.GeneratedProtocolMessageType('HeadersEntry', (_message.Message,), { + 'DESCRIPTOR' : _RETURNOVERRIDES_HEADERSENTRY, + '__module__' : 'coprocess_return_overrides_pb2' + # @@protoc_insertion_point(class_scope:coprocess.ReturnOverrides.HeadersEntry) + }) + , + 'DESCRIPTOR' : _RETURNOVERRIDES, + '__module__' : 'coprocess_return_overrides_pb2' + # @@protoc_insertion_point(class_scope:coprocess.ReturnOverrides) + }) +_sym_db.RegisterMessage(ReturnOverrides) +_sym_db.RegisterMessage(ReturnOverrides.HeadersEntry) + + +_RETURNOVERRIDES_HEADERSENTRY._options = None +# @@protoc_insertion_point(module_scope) diff --git a/plugins/grpc_python-pre-insert_header/proto/coprocess_session_state_pb2.py b/plugins/grpc_python-pre-insert_header/proto/coprocess_session_state_pb2.py new file mode 100644 index 0000000..ad25dcb --- /dev/null +++ b/plugins/grpc_python-pre-insert_header/proto/coprocess_session_state_pb2.py @@ -0,0 +1,657 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: coprocess_session_state.proto + +from google.protobuf import descriptor as _descriptor +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) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor.FileDescriptor( + name='coprocess_session_state.proto', + package='coprocess', + syntax='proto3', + serialized_options=None, + serialized_pb=b'\n\x1d\x63oprocess_session_state.proto\x12\tcoprocess\"*\n\nAccessSpec\x12\x0b\n\x03url\x18\x01 \x01(\t\x12\x0f\n\x07methods\x18\x02 \x03(\t\"s\n\x10\x41\x63\x63\x65ssDefinition\x12\x10\n\x08\x61pi_name\x18\x01 \x01(\t\x12\x0e\n\x06\x61pi_id\x18\x02 \x01(\t\x12\x10\n\x08versions\x18\x03 \x03(\t\x12+\n\x0c\x61llowed_urls\x18\x04 \x03(\x0b\x32\x15.coprocess.AccessSpec\"/\n\rBasicAuthData\x12\x10\n\x08password\x18\x01 \x01(\t\x12\x0c\n\x04hash\x18\x02 \x01(\t\"\x19\n\x07JWTData\x12\x0e\n\x06secret\x18\x01 \x01(\t\"!\n\x07Monitor\x12\x16\n\x0etrigger_limits\x18\x01 \x03(\x01\"\x96\x08\n\x0cSessionState\x12\x12\n\nlast_check\x18\x01 \x01(\x03\x12\x11\n\tallowance\x18\x02 \x01(\x01\x12\x0c\n\x04rate\x18\x03 \x01(\x01\x12\x0b\n\x03per\x18\x04 \x01(\x01\x12\x0f\n\x07\x65xpires\x18\x05 \x01(\x03\x12\x11\n\tquota_max\x18\x06 \x01(\x03\x12\x14\n\x0cquota_renews\x18\x07 \x01(\x03\x12\x17\n\x0fquota_remaining\x18\x08 \x01(\x03\x12\x1a\n\x12quota_renewal_rate\x18\t \x01(\x03\x12@\n\raccess_rights\x18\n \x03(\x0b\x32).coprocess.SessionState.AccessRightsEntry\x12\x0e\n\x06org_id\x18\x0b \x01(\t\x12\x17\n\x0foauth_client_id\x18\x0c \x01(\t\x12:\n\noauth_keys\x18\r \x03(\x0b\x32&.coprocess.SessionState.OauthKeysEntry\x12\x31\n\x0f\x62\x61sic_auth_data\x18\x0e \x01(\x0b\x32\x18.coprocess.BasicAuthData\x12$\n\x08jwt_data\x18\x0f \x01(\x0b\x32\x12.coprocess.JWTData\x12\x14\n\x0chmac_enabled\x18\x10 \x01(\x08\x12\x13\n\x0bhmac_secret\x18\x11 \x01(\t\x12\x13\n\x0bis_inactive\x18\x12 \x01(\x08\x12\x17\n\x0f\x61pply_policy_id\x18\x13 \x01(\t\x12\x14\n\x0c\x64\x61ta_expires\x18\x14 \x01(\x03\x12#\n\x07monitor\x18\x15 \x01(\x0b\x32\x12.coprocess.Monitor\x12!\n\x19\x65nable_detailed_recording\x18\x16 \x01(\x08\x12\x37\n\x08metadata\x18\x17 \x03(\x0b\x32%.coprocess.SessionState.MetadataEntry\x12\x0c\n\x04tags\x18\x18 \x03(\t\x12\r\n\x05\x61lias\x18\x19 \x01(\t\x12\x14\n\x0clast_updated\x18\x1a \x01(\t\x12\x1d\n\x15id_extractor_deadline\x18\x1b \x01(\x03\x12\x18\n\x10session_lifetime\x18\x1c \x01(\x03\x12\x16\n\x0e\x61pply_policies\x18\x1d \x03(\t\x12\x13\n\x0b\x63\x65rtificate\x18\x1e \x01(\t\x12\x17\n\x0fmax_query_depth\x18\x1f \x01(\x03\x1aP\n\x11\x41\x63\x63\x65ssRightsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12*\n\x05value\x18\x02 \x01(\x0b\x32\x1b.coprocess.AccessDefinition:\x02\x38\x01\x1a\x30\n\x0eOauthKeysEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x1a/\n\rMetadataEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x62\x06proto3' +) + + + + +_ACCESSSPEC = _descriptor.Descriptor( + name='AccessSpec', + full_name='coprocess.AccessSpec', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='url', full_name='coprocess.AccessSpec.url', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='methods', full_name='coprocess.AccessSpec.methods', index=1, + number=2, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=44, + serialized_end=86, +) + + +_ACCESSDEFINITION = _descriptor.Descriptor( + name='AccessDefinition', + full_name='coprocess.AccessDefinition', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='api_name', full_name='coprocess.AccessDefinition.api_name', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='api_id', full_name='coprocess.AccessDefinition.api_id', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='versions', full_name='coprocess.AccessDefinition.versions', index=2, + number=3, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='allowed_urls', full_name='coprocess.AccessDefinition.allowed_urls', index=3, + number=4, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=88, + serialized_end=203, +) + + +_BASICAUTHDATA = _descriptor.Descriptor( + name='BasicAuthData', + full_name='coprocess.BasicAuthData', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='password', full_name='coprocess.BasicAuthData.password', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='hash', full_name='coprocess.BasicAuthData.hash', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=205, + serialized_end=252, +) + + +_JWTDATA = _descriptor.Descriptor( + name='JWTData', + full_name='coprocess.JWTData', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='secret', full_name='coprocess.JWTData.secret', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=254, + serialized_end=279, +) + + +_MONITOR = _descriptor.Descriptor( + name='Monitor', + full_name='coprocess.Monitor', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='trigger_limits', full_name='coprocess.Monitor.trigger_limits', index=0, + number=1, type=1, cpp_type=5, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=281, + serialized_end=314, +) + + +_SESSIONSTATE_ACCESSRIGHTSENTRY = _descriptor.Descriptor( + name='AccessRightsEntry', + full_name='coprocess.SessionState.AccessRightsEntry', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='key', full_name='coprocess.SessionState.AccessRightsEntry.key', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='value', full_name='coprocess.SessionState.AccessRightsEntry.value', index=1, + number=2, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=b'8\001', + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1184, + serialized_end=1264, +) + +_SESSIONSTATE_OAUTHKEYSENTRY = _descriptor.Descriptor( + name='OauthKeysEntry', + full_name='coprocess.SessionState.OauthKeysEntry', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='key', full_name='coprocess.SessionState.OauthKeysEntry.key', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='value', full_name='coprocess.SessionState.OauthKeysEntry.value', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=b'8\001', + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1266, + serialized_end=1314, +) + +_SESSIONSTATE_METADATAENTRY = _descriptor.Descriptor( + name='MetadataEntry', + full_name='coprocess.SessionState.MetadataEntry', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='key', full_name='coprocess.SessionState.MetadataEntry.key', index=0, + number=1, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='value', full_name='coprocess.SessionState.MetadataEntry.value', index=1, + number=2, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[], + enum_types=[ + ], + serialized_options=b'8\001', + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=1316, + serialized_end=1363, +) + +_SESSIONSTATE = _descriptor.Descriptor( + name='SessionState', + full_name='coprocess.SessionState', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='last_check', full_name='coprocess.SessionState.last_check', index=0, + number=1, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='allowance', full_name='coprocess.SessionState.allowance', index=1, + number=2, type=1, cpp_type=5, label=1, + has_default_value=False, default_value=float(0), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='rate', full_name='coprocess.SessionState.rate', index=2, + number=3, type=1, cpp_type=5, label=1, + has_default_value=False, default_value=float(0), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='per', full_name='coprocess.SessionState.per', index=3, + number=4, type=1, cpp_type=5, label=1, + has_default_value=False, default_value=float(0), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='expires', full_name='coprocess.SessionState.expires', index=4, + number=5, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='quota_max', full_name='coprocess.SessionState.quota_max', index=5, + number=6, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='quota_renews', full_name='coprocess.SessionState.quota_renews', index=6, + number=7, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='quota_remaining', full_name='coprocess.SessionState.quota_remaining', index=7, + number=8, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='quota_renewal_rate', full_name='coprocess.SessionState.quota_renewal_rate', index=8, + number=9, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='access_rights', full_name='coprocess.SessionState.access_rights', index=9, + number=10, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='org_id', full_name='coprocess.SessionState.org_id', index=10, + number=11, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='oauth_client_id', full_name='coprocess.SessionState.oauth_client_id', index=11, + number=12, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='oauth_keys', full_name='coprocess.SessionState.oauth_keys', index=12, + number=13, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='basic_auth_data', full_name='coprocess.SessionState.basic_auth_data', index=13, + number=14, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='jwt_data', full_name='coprocess.SessionState.jwt_data', index=14, + number=15, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='hmac_enabled', full_name='coprocess.SessionState.hmac_enabled', index=15, + number=16, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='hmac_secret', full_name='coprocess.SessionState.hmac_secret', index=16, + number=17, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='is_inactive', full_name='coprocess.SessionState.is_inactive', index=17, + number=18, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='apply_policy_id', full_name='coprocess.SessionState.apply_policy_id', index=18, + number=19, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='data_expires', full_name='coprocess.SessionState.data_expires', index=19, + number=20, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='monitor', full_name='coprocess.SessionState.monitor', index=20, + number=21, type=11, cpp_type=10, label=1, + has_default_value=False, default_value=None, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='enable_detailed_recording', full_name='coprocess.SessionState.enable_detailed_recording', index=21, + number=22, type=8, cpp_type=7, label=1, + has_default_value=False, default_value=False, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='metadata', full_name='coprocess.SessionState.metadata', index=22, + number=23, type=11, cpp_type=10, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='tags', full_name='coprocess.SessionState.tags', index=23, + number=24, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='alias', full_name='coprocess.SessionState.alias', index=24, + number=25, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='last_updated', full_name='coprocess.SessionState.last_updated', index=25, + number=26, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='id_extractor_deadline', full_name='coprocess.SessionState.id_extractor_deadline', index=26, + number=27, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='session_lifetime', full_name='coprocess.SessionState.session_lifetime', index=27, + number=28, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='apply_policies', full_name='coprocess.SessionState.apply_policies', index=28, + number=29, type=9, cpp_type=9, label=3, + has_default_value=False, default_value=[], + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='certificate', full_name='coprocess.SessionState.certificate', index=29, + number=30, type=9, cpp_type=9, label=1, + has_default_value=False, default_value=b"".decode('utf-8'), + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + _descriptor.FieldDescriptor( + name='max_query_depth', full_name='coprocess.SessionState.max_query_depth', index=30, + number=31, type=3, cpp_type=2, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + serialized_options=None, file=DESCRIPTOR), + ], + extensions=[ + ], + nested_types=[_SESSIONSTATE_ACCESSRIGHTSENTRY, _SESSIONSTATE_OAUTHKEYSENTRY, _SESSIONSTATE_METADATAENTRY, ], + enum_types=[ + ], + serialized_options=None, + is_extendable=False, + syntax='proto3', + extension_ranges=[], + oneofs=[ + ], + serialized_start=317, + serialized_end=1363, +) + +_ACCESSDEFINITION.fields_by_name['allowed_urls'].message_type = _ACCESSSPEC +_SESSIONSTATE_ACCESSRIGHTSENTRY.fields_by_name['value'].message_type = _ACCESSDEFINITION +_SESSIONSTATE_ACCESSRIGHTSENTRY.containing_type = _SESSIONSTATE +_SESSIONSTATE_OAUTHKEYSENTRY.containing_type = _SESSIONSTATE +_SESSIONSTATE_METADATAENTRY.containing_type = _SESSIONSTATE +_SESSIONSTATE.fields_by_name['access_rights'].message_type = _SESSIONSTATE_ACCESSRIGHTSENTRY +_SESSIONSTATE.fields_by_name['oauth_keys'].message_type = _SESSIONSTATE_OAUTHKEYSENTRY +_SESSIONSTATE.fields_by_name['basic_auth_data'].message_type = _BASICAUTHDATA +_SESSIONSTATE.fields_by_name['jwt_data'].message_type = _JWTDATA +_SESSIONSTATE.fields_by_name['monitor'].message_type = _MONITOR +_SESSIONSTATE.fields_by_name['metadata'].message_type = _SESSIONSTATE_METADATAENTRY +DESCRIPTOR.message_types_by_name['AccessSpec'] = _ACCESSSPEC +DESCRIPTOR.message_types_by_name['AccessDefinition'] = _ACCESSDEFINITION +DESCRIPTOR.message_types_by_name['BasicAuthData'] = _BASICAUTHDATA +DESCRIPTOR.message_types_by_name['JWTData'] = _JWTDATA +DESCRIPTOR.message_types_by_name['Monitor'] = _MONITOR +DESCRIPTOR.message_types_by_name['SessionState'] = _SESSIONSTATE +_sym_db.RegisterFileDescriptor(DESCRIPTOR) + +AccessSpec = _reflection.GeneratedProtocolMessageType('AccessSpec', (_message.Message,), { + 'DESCRIPTOR' : _ACCESSSPEC, + '__module__' : 'coprocess_session_state_pb2' + # @@protoc_insertion_point(class_scope:coprocess.AccessSpec) + }) +_sym_db.RegisterMessage(AccessSpec) + +AccessDefinition = _reflection.GeneratedProtocolMessageType('AccessDefinition', (_message.Message,), { + 'DESCRIPTOR' : _ACCESSDEFINITION, + '__module__' : 'coprocess_session_state_pb2' + # @@protoc_insertion_point(class_scope:coprocess.AccessDefinition) + }) +_sym_db.RegisterMessage(AccessDefinition) + +BasicAuthData = _reflection.GeneratedProtocolMessageType('BasicAuthData', (_message.Message,), { + 'DESCRIPTOR' : _BASICAUTHDATA, + '__module__' : 'coprocess_session_state_pb2' + # @@protoc_insertion_point(class_scope:coprocess.BasicAuthData) + }) +_sym_db.RegisterMessage(BasicAuthData) + +JWTData = _reflection.GeneratedProtocolMessageType('JWTData', (_message.Message,), { + 'DESCRIPTOR' : _JWTDATA, + '__module__' : 'coprocess_session_state_pb2' + # @@protoc_insertion_point(class_scope:coprocess.JWTData) + }) +_sym_db.RegisterMessage(JWTData) + +Monitor = _reflection.GeneratedProtocolMessageType('Monitor', (_message.Message,), { + 'DESCRIPTOR' : _MONITOR, + '__module__' : 'coprocess_session_state_pb2' + # @@protoc_insertion_point(class_scope:coprocess.Monitor) + }) +_sym_db.RegisterMessage(Monitor) + +SessionState = _reflection.GeneratedProtocolMessageType('SessionState', (_message.Message,), { + + 'AccessRightsEntry' : _reflection.GeneratedProtocolMessageType('AccessRightsEntry', (_message.Message,), { + 'DESCRIPTOR' : _SESSIONSTATE_ACCESSRIGHTSENTRY, + '__module__' : 'coprocess_session_state_pb2' + # @@protoc_insertion_point(class_scope:coprocess.SessionState.AccessRightsEntry) + }) + , + + 'OauthKeysEntry' : _reflection.GeneratedProtocolMessageType('OauthKeysEntry', (_message.Message,), { + 'DESCRIPTOR' : _SESSIONSTATE_OAUTHKEYSENTRY, + '__module__' : 'coprocess_session_state_pb2' + # @@protoc_insertion_point(class_scope:coprocess.SessionState.OauthKeysEntry) + }) + , + + 'MetadataEntry' : _reflection.GeneratedProtocolMessageType('MetadataEntry', (_message.Message,), { + 'DESCRIPTOR' : _SESSIONSTATE_METADATAENTRY, + '__module__' : 'coprocess_session_state_pb2' + # @@protoc_insertion_point(class_scope:coprocess.SessionState.MetadataEntry) + }) + , + 'DESCRIPTOR' : _SESSIONSTATE, + '__module__' : 'coprocess_session_state_pb2' + # @@protoc_insertion_point(class_scope:coprocess.SessionState) + }) +_sym_db.RegisterMessage(SessionState) +_sym_db.RegisterMessage(SessionState.AccessRightsEntry) +_sym_db.RegisterMessage(SessionState.OauthKeysEntry) +_sym_db.RegisterMessage(SessionState.MetadataEntry) + + +_SESSIONSTATE_ACCESSRIGHTSENTRY._options = None +_SESSIONSTATE_OAUTHKEYSENTRY._options = None +_SESSIONSTATE_METADATAENTRY._options = None +# @@protoc_insertion_point(module_scope) diff --git a/plugins/grpc_python-pre-insert_header/proto/sample_server.py b/plugins/grpc_python-pre-insert_header/proto/sample_server.py new file mode 100644 index 0000000..a0009ae --- /dev/null +++ b/plugins/grpc_python-pre-insert_header/proto/sample_server.py @@ -0,0 +1,75 @@ +import coprocess_object_pb2, coprocess_object_pb2_grpc +from coprocess_session_state_pb2 import SessionState + +import grpc, time, json + +_ONE_DAY_IN_SECONDS = 60 * 60 * 24 + +from concurrent import futures + +def MyPreMiddleware(coprocess_object): + coprocess_object.request.set_headers["MyPreMiddleware"] = "MyPreMiddleware" + return coprocess_object + +def MyPostMiddleware(coprocess_object): + #coprocess_object.request.set_headers["MyResponseMiddleware"] = "MyResponseMiddleware" + + body = coprocess_object.response.body + json_body = json.loads(body) + json_body['Transform'] = 'Custom Field' + + coprocess_object.response.body = json.dumps(json_body) + coprocess_object.response.raw_body=json.dumps(json_body).encode('utf-8') + coprocess_object.response.headers['Content-Length'] = str(len(coprocess_object.response.raw_body)) + + return coprocess_object + +def MyAuthCheck(coprocess_object): + valid_token = 'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d' + request_token = coprocess_object.request.headers["Authorization"] + + if request_token == valid_token: + new_session = SessionState() + new_session.rate = 1000.0 + new_session.per = 1.0 + coprocess_object.metadata["token"] = "mytoken" + coprocess_object.session.CopyFrom(new_session) + + else: + coprocess_object.request.return_overrides.response_code = 401 + coprocess_object.request.return_overrides.response_error = 'Not authorized (Python middleware)' + + return coprocess_object + +class MyDispatcher(coprocess_object_pb2_grpc.DispatcherServicer): + def Dispatch(self, coprocess_object, context): + if coprocess_object.hook_name == "MyPreMiddleware": + coprocess_object = MyPreMiddleware(coprocess_object) + + if coprocess_object.hook_name == "MyPostMiddleware": + coprocess_object = MyPostMiddleware(coprocess_object) + + if coprocess_object.hook_name == "MyAuthCheck": + coprocess_object = MyAuthCheck(coprocess_object) + + return coprocess_object + + def DispatchEvent(self, event_wrapper, context): + event = json.loads(event_wrapper.payload) + return coprocess_object_pb2_grpc.EventReply() + + +def serve(): + server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) + coprocess_object_pb2_grpc.add_DispatcherServicer_to_server( + MyDispatcher(), server) + server.add_insecure_port('[::]:5555') + server.start() + try: + while True: + time.sleep(_ONE_DAY_IN_SECONDS) + except KeyboardInterrupt: + server.stop(0) + +if __name__ == '__main__': + serve() diff --git a/plugins/grpc_python-pre-insert_header/requirements.txt b/plugins/grpc_python-pre-insert_header/requirements.txt new file mode 100644 index 0000000..dca0d2c --- /dev/null +++ b/plugins/grpc_python-pre-insert_header/requirements.txt @@ -0,0 +1,4 @@ +grpcio==1.47.0 +grpcio-tools==1.47.0 +protobuf==3.20.1 +six==1.16.0