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