Package: grpc-gateway-wrapper
grpc-gateway-wrapperThe goal of this project is to generates a REST gateway wrapper layer for a grpc server with minimal customization, along withswaggerdefinitions conforming toOpenAPI 2.0.ThegRPC-gateway(https://github.com/grpc-ecosystem/grpc-gateway) is a plugin of the Google protocol buffers compiler protoc. It reads protobuf service definitions and generates a reverse-proxy server which translates a RESTful HTTP API into gRPC.This repo, thegrpc-gateway-wrapperis a python library and executable that builds agobinary that encapsulates the reverse proxy server along withswaggerdefinitions conforming toOpenAPI 2.0.gRPC Gateway WrapperInstallation instructionsBuild from sourcePull from pypiUsageCLI optionsPrerequisiteBuild a GatewaygRPC MetadataUse a GatewayDockerized integration exampleCall a GatewayReferencesInstallation instructionsBuild from sourcepythonsetup.pybdist_wheelPull from pypipipinstallgrpc-gateway-wrapperUsagepython-mgrpc_gateway_wrapperor:grpc-gateway-wrapper(it should be installed on the system path).This is the main entrypoint script which can generate a working gRPC gateway server that can proxy between an equivalent REST API and a set of gRPC services.CLI options╰$python-mgrpc_gateway_wrapper--helpoptionalarguments:-h,--helpshowthishelpmessageandexit--proto_filesPROTO_FILES[PROTO_FILES...],-pPROTO_FILES[PROTO_FILES...]Theprotofiletogeneratefrom--working_dirWORKING_DIR,-wWORKING_DIRLocationforintermediatefiles.Ifnone,randomwillbegenerated--no_cleanup,-cDon't clean up working dir--output_dirOUTPUT_DIR,-oOUTPUT_DIRLocationforoutputfiles--metadata[METADATA...],-m[METADATA...]gRPCmetadataname(s)toaddtotheswagger--install_deps,-dInstallgodependenciesifthey're missing--gateway_versionGATEWAY_VERSION,-gGATEWAY_VERSIONVersionofthegrpc-gatewaytoolstoinstallifinstallingdependencies--log_levelLOG_LEVEL,-lLOG_LEVELLoglevelforinformationalloggingPrerequisitego:https://go.dev/doc/installprotoc:https://grpc.io/docs/protoc-installation/There are additionalgodependencies which the library needs which you can directly install by passing the--install_depsargument.Build a GatewayTo build a gateway for your server, you need to collect the full set ofprotofiles used to create the server interface, including files containing type definitions (the script is not smart enough to find them for you). With that, simply callgrpc_gateway_wrapperwith the--protosargument. For example:python-mgrpc_gateway_wrapper\--proto_filesexample/sample-messages.protoexample/sample-service.protogRPC MetadataSome gRPC APIs rely on the presence of certainmetadataentries (e.g.kserve model-meshrequires themm-model-idormm-vmodel-idheader). These headers are not represented in theprotofile, so they're not automatically represented in theswaggerAPI generated by this template. In order to add them, you can use the--metadataargument togrpc_gateway_wrapper. For example:python-mgrpc_gateway_wrapper\--proto_filesexample/sample-messages.protoexample/sample-service.proto\--metadatafoobar:default_valueUse a GatewayOnce you build the gateway using the commands above, abuilddirectory will be generated with the contents:build
├──app
└──swaggerThe generatedbinaryis theapp, along with theswaggerdirectory along side it.To see the flags that can be passed to the built binary, you can run:╰$./build/app--help

Usageof./build/app:-mtls_client_ca="":CAcertificatetousetoenablemutualTLS-proxy_cert="":Certtousewhenmakingtheproxyrpccall-proxy_cert_hname="":Hostnameoverrideforproxycert-proxy_endpoint="localhost:8004":Endpointfortheserverbeingproxiedto-proxy_no_cert_val=false:Ignorecertificatevalidation-serve_cert="":Publiccerttousewhenservingproxycalls-serve_key="":Privatekeytousewhenservingproxycalls-serve_port=8080:Porttoservethegatewayon-swagger_path="/swagger":AbsolutepathtoswaggerassetsYou can run it anywhere (locally, or within a deployment) and simply point it at the runninggRPCserver:./build/app\--swagger_path$PWD/build/swagger\--proxy_endpointlocalhost:8004\--serve_port8080(TODO- add TLS specific example)Call a GatewayOnce a gateway is running, you can access it directly using any HTTP client you like (curl,postman, etc...). You can also visit its swagger documentation by hitting the/swaggerendpoint (e.g.http://localhost:8080/swagger).ReferencesThis project relies heavily on a few external libraries.grpc-gateway: This project provides the guts of the gateway implementation, as well as the swagger spec generationgoogle api service: In order to avoid forcing annotations into the protobuf files, this project side-loads the REST spec using thegoogle api servicedefinition.