jfjoch_grpc2http.py: make it possible to use python requests
This commit is contained in:
@@ -5,7 +5,7 @@ from io import BytesIO
|
||||
|
||||
import grpc
|
||||
import numpy
|
||||
from fastapi import FastAPI, Body, HTTPException, Response
|
||||
from fastapi import FastAPI, HTTPException, Response, Request
|
||||
from fastapi.responses import RedirectResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from google.protobuf.json_format import Parse, ParseError, MessageToDict
|
||||
@@ -72,8 +72,9 @@ async def deactivate():
|
||||
|
||||
|
||||
@app.post("/detector/start")
|
||||
async def start(data: str = Body(...)):
|
||||
async def start(request: Request):
|
||||
try:
|
||||
data = await request.body()
|
||||
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
|
||||
stub.Start(Parse(data, jfjoch_pb2.DatasetSettings()))
|
||||
return {}
|
||||
@@ -127,8 +128,9 @@ async def get_settings():
|
||||
|
||||
|
||||
@app.put("/detector/settings")
|
||||
async def put_settings(data: str = Body(...)):
|
||||
async def put_settings(request: Request):
|
||||
try:
|
||||
data = await request.body()
|
||||
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
|
||||
stub.PutDetectorSettings(Parse(data, jfjoch_pb2.DetectorSettings()))
|
||||
return {}
|
||||
@@ -163,8 +165,9 @@ async def get_settings():
|
||||
|
||||
|
||||
@app.put("/data_processing/settings")
|
||||
async def put_data_processing_settings(data: str = Body(...)):
|
||||
async def put_data_processing_settings(request: Request):
|
||||
try:
|
||||
data = await request.body()
|
||||
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
|
||||
stub.PutDataProcessingSettings(Parse(data, jfjoch_pb2.DataProcessingSettings()))
|
||||
return {}
|
||||
@@ -175,8 +178,9 @@ async def put_data_processing_settings(data: str = Body(...)):
|
||||
|
||||
|
||||
@app.post("/data_processing/plots")
|
||||
async def get_settings(data: str = Body(...)):
|
||||
async def get_settings(request: Request):
|
||||
try:
|
||||
data = await request.body()
|
||||
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
|
||||
return MessageToDict(
|
||||
stub.GetPlots(Parse(data, jfjoch_pb2.PlotRequest())), including_default_value_fields=True
|
||||
@@ -208,8 +212,9 @@ async def get_detector_list():
|
||||
|
||||
|
||||
@app.put("/detector/select")
|
||||
async def put_detector_selection(data: str = Body(...)):
|
||||
async def put_detector_selection(request: Request):
|
||||
try:
|
||||
data = await request.body()
|
||||
stub = jfjoch_pb2_grpc.gRPC_JFJochBrokerStub(channel)
|
||||
stub.SelectDetector(Parse(data, jfjoch_pb2.DetectorSelection()))
|
||||
return {}
|
||||
|
||||
Reference in New Issue
Block a user