@ -574,39 +574,36 @@ def IdentifyAuthorize(inRequest:Request, inResponse:Response,
else :
raise HTTPException ( status_code = 401 , detail = " here is the details " , headers = { ' Content-type ' : ' text/html ' , ' WWW-Authenticate ' : ' Basic ' } )
def BackwardCompatibityWrapperAuth ( inRequest : Request , inResponse : Response , inBodyStr : str = Body ( " " ) ,
inAuthDict : dict = Depends ( IdentifyAuthorize ) ) : # Old from v1.3.1 (updated to FastAPI)
#print(f"{inRequest.url.path}, inAuthDict:{inAuthDict}")
def BackwardCompatibility ( inRequest : Request , inResponse : Response , inBodyStr : str = Body ( " " ) , inAuthDict = None ) :
lHTTPRequest = HTTPRequestOld ( inRequest = inRequest , inResponse = inResponse , inAuthDict = inAuthDict )
lHTTPRequest . path = inRequest . url . path
lHTTPRequest . body = inBodyStr
lHTTPRequest . client_address = [ inRequest . client . host ]
threading . current_thread ( ) . request = lHTTPRequest
lResult = lHTTPRequest . do_GET ( inBodyStr = inBodyStr )
if lResult is None :
lResult = lHTTPRequest . do_POST ( inBodyStr = inBodyStr )
#if lHTTPRequest.OpenRPAResponseDict['BodyIsText']==True: return lResult.decode("utf8")
#else: return StreamingResponse(io.BytesIO(lResult), media_type="image/png")
if lHTTPRequest . OpenRPAResponseDict [ " Headers " ] [ " Content-type " ] != None :
return StreamingResponse ( io . BytesIO ( lResult ) , media_type = lHTTPRequest . OpenRPAResponseDict [ " Headers " ] [ " Content-type " ] )
#WRAPPERS!
def BackwardCompatibityWrapperAuth ( inRequest : Request , inResponse : Response , inBodyStr : str = Body ( " " ) ,
inAuthDict : dict = Depends ( IdentifyAuthorize ) ) : # Old from v1.3.1 (updated to FastAPI)
return BackwardCompatibility ( inRequest = inRequest , inResponse = inResponse , inBodyStr = inBodyStr , inAuthDict = inAuthDict )
def BackwardCompatibityWrapperNoAuth ( inRequest : Request , inResponse : Response , inBodyStr : str = Body ( " " ) ) : # Old from v1.3.1 (updated to FastAPI)
#print(f"{inRequest.url.path}, BackwardCompatibityWrapperNoAuth")
lHTTPRequest = HTTPRequestOld ( inRequest = inRequest , inResponse = inResponse , inAuthDict = None )
lHTTPRequest . path = inRequest . url . path
lHTTPRequest . body = inBodyStr
threading . current_thread ( ) . request = lHTTPRequest
lResult = lHTTPRequest . do_GET ( inBodyStr = inBodyStr )
#print(f"RESULT VALUE: {lResult}")
if lResult is None :
lResult = lHTTPRequest . do_POST ( inBodyStr = inBodyStr )
#if lHTTPRequest.OpenRPAResponseDict['BodyIsText']==True: return lResult.decode("utf8")
#else: return StreamingResponse(io.BytesIO(lResult), media_type="image/png")
if lHTTPRequest . OpenRPAResponseDict [ " Headers " ] [ " Content-type " ] != None :
return StreamingResponse ( io . BytesIO ( lResult ) , media_type = lHTTPRequest . OpenRPAResponseDict [ " Headers " ] [ " Content-type " ] )
# Get thread list
@app.get ( path = " /threads " , response_class = PlainTextResponse )
def Threads ( ) :
return BackwardCompatibility ( inRequest = inRequest , inResponse = inResponse , inBodyStr = inBodyStr , inAuthDict = None )
def BackwardCompatibityBeginWrapperAuth ( inBeginTokenStr , inRequest : Request , inResponse : Response , inBodyStr : str = Body ( " " ) ,
inAuthDict : dict = Depends ( IdentifyAuthorize ) ) : # Old from v1.3.1 (updated to FastAPI)
return BackwardCompatibility ( inRequest = inRequest , inResponse = inResponse , inBodyStr = inBodyStr , inAuthDict = inAuthDict )
def BackwardCompatibityBeginWrapperNoAuth ( inBeginTokenStr , inRequest : Request , inResponse : Response , inBodyStr : str = Body ( " " ) ) : # Old from v1.3.1 (updated to FastAPI)
return BackwardCompatibility ( inRequest = inRequest , inResponse = inResponse , inBodyStr = inBodyStr , inAuthDict = None )
# Get thread list /orpa/threads
@app.get ( path = " /orpa/threads " , response_class = PlainTextResponse )
def Threads ( inRequest : Request ) :
#import pdb
#pdb.set_trace()
lThreadStr = " "
for thread in threading . enumerate ( ) :
lThreadStr + = f " ПОТОК: { thread . name } \n "
@ -625,6 +622,7 @@ def InitFastAPI():
StaticFiles ( directory = CrossOS . PathStr ( lConnectItemDict [ " ResponseFolderPath " ] ) ) ,
name = lConnectItemDict [ " URL " ] . replace ( ' / ' , " _ " ) )
else :
if lConnectItemDict . get ( " MatchType " ) in [ " EqualCase " , " Equal " , " EqualNoParam " ] :
if lConnectItemDict . get ( " UACBool " , True ) :
app . add_api_route (
path = lConnectItemDict [ " URL " ] ,
@ -639,6 +637,25 @@ def InitFastAPI():
response_class = PlainTextResponse ,
methods = [ lConnectItemDict [ " Method " ] ]
)
elif lConnectItemDict . get ( " MatchType " ) in [ " BeginWith " , " Contains " ] :
lURLStr = lConnectItemDict [ " URL " ]
if lURLStr [ - 1 ] != " / " : lURLStr + = " / "
lURLStr + = " {inBeginTokenStr} "
if lConnectItemDict . get ( " UACBool " , True ) :
app . add_api_route (
path = lURLStr ,
endpoint = BackwardCompatibityBeginWrapperAuth ,
response_class = PlainTextResponse ,
methods = [ lConnectItemDict [ " Method " ] ]
)
else :
app . add_api_route (
path = lURLStr ,
endpoint = BackwardCompatibityBeginWrapperNoAuth ,
response_class = PlainTextResponse ,
methods = [ lConnectItemDict [ " Method " ] ]
)
uvicorn . run ( ' pyOpenRPA.Orchestrator.Server:app ' , host = ' 0.0.0.0 ' , port = 1024 )