1- from fastapi import FastAPI , Request
1+ from fastapi import FastAPI , Request , status
22from typing import Optional
3- from fastapi .responses import Response
3+ from fastapi .responses import Response , JSONResponse
44import json
55import base64
66from multiprocessing import Process
@@ -49,7 +49,7 @@ async def process_algo_req(request: Request, username, algoname, output: Optiona
4949 return output
5050
5151
52- @regular_app .post ("/v1/algo/{username}/{algoname}/{githash}" )
52+ @regular_app .post ("/v1/algo/{username}/{algoname}/{githash}" , status_code = status . HTTP_200_OK )
5353async def process_hello_world (request : Request , username , algoname , githash ):
5454 metadata = {"request_id" : "req-55c0480d-6af3-4a21-990a-5c51d29f5725" , "duration" : 0.000306774 ,
5555 'content_type' : "text" }
@@ -61,7 +61,7 @@ async def process_hello_world(request: Request, username, algoname, githash):
6161### Algorithm Routes
6262@regular_app .get ('/v1/algorithms/{username}/{algoname}' )
6363async def process_get_algo (request : Request , username , algoname ):
64- if algoname == "echo" :
64+ if algoname == "echo" and username == 'quality' :
6565 return {"id" : "21df7a38-eab8-4ac8-954c-41a285535e69" , "name" : "echo" ,
6666 "details" : {"summary" : "" , "label" : "echo" , "tagline" : "" },
6767 "settings" : {"algorithm_callability" : "public" , "source_visibility" : "closed" ,
@@ -78,8 +78,11 @@ async def process_get_algo(request: Request, username, algoname):
7878 "compilation" : {"successful" : True , "output" : "" },
7979 "self_link" : "https://api.algorithmia.com/v1/algorithms/quality/echo/versions/0cfd7a6600f1fa05f9fe93016e661a9332c4ded2" ,
8080 "resource_type" : "algorithm" }
81+ elif algoname == "echo" :
82+ return JSONResponse (content = {"error" : {"id" : "1cfb98c5-532e-4cbf-9192-fdd45b86969c" , "code" : 2001 ,
83+ "message" : "Caller is not authorized to perform the operation" }}, status_code = 403 )
8184 else :
82- return {"error" : "No such algorithm" }
85+ return JSONResponse ( content = {"error" : "No such algorithm" }, status_code = 404 )
8386
8487
8588@regular_app .get ("/v1/algorithms/{username}/{algoname}/builds/{buildid}" )
@@ -101,7 +104,7 @@ async def get_scm_status(username, algoname):
101104
102105@regular_app .get ("/v1/algorithms/{algo_id}/errors" )
103106async def get_algo_errors (algo_id ):
104- return {"error" : {"message" : "not found" }}
107+ return JSONResponse ( content = {"error" : {"message" : "not found" }}, status_code = 404 )
105108
106109
107110@regular_app .post ("/v1/algorithms/{username}" )
@@ -116,6 +119,7 @@ async def create_algorithm(request: Request, username):
116119 "source" : {"scm" : {"id" : "internal" , "provider" : "internal" , "default" : True , "enabled" : True }},
117120 "resource_type" : "algorithm" }
118121
122+
119123@regular_app .put ('/v1/algorithms/{username}/{algoname}' )
120124async def update_algorithm (request : Request , username , algoname ):
121125 return {
@@ -255,7 +259,7 @@ async def get_algorithm_info(username, algoname, algohash):
255259 "source" : {"scm" : {"id" : "internal" , "provider" : "internal" , "default" : True , "enabled" : True }},
256260 "compilation" : {"successful" : True , "output" : "" }, "resource_type" : "algorithm" }
257261 else :
258- return {"error" : {"message" : "not found" }}
262+ return JSONResponse ( content = {"error" : {"message" : "not found" }}, status_code = 404 )
259263
260264
261265### Admin Routes
0 commit comments