1
- from fastapi import FastAPI , Request
1
+ from fastapi import FastAPI , Request , status
2
2
from typing import Optional
3
- from fastapi .responses import Response
3
+ from fastapi .responses import Response , JSONResponse
4
4
import json
5
5
import base64
6
6
from multiprocessing import Process
@@ -49,7 +49,7 @@ async def process_algo_req(request: Request, username, algoname, output: Optiona
49
49
return output
50
50
51
51
52
- @regular_app .post ("/v1/algo/{username}/{algoname}/{githash}" )
52
+ @regular_app .post ("/v1/algo/{username}/{algoname}/{githash}" , status_code = status . HTTP_200_OK )
53
53
async def process_hello_world (request : Request , username , algoname , githash ):
54
54
metadata = {"request_id" : "req-55c0480d-6af3-4a21-990a-5c51d29f5725" , "duration" : 0.000306774 ,
55
55
'content_type' : "text" }
@@ -61,7 +61,7 @@ async def process_hello_world(request: Request, username, algoname, githash):
61
61
### Algorithm Routes
62
62
@regular_app .get ('/v1/algorithms/{username}/{algoname}' )
63
63
async def process_get_algo (request : Request , username , algoname ):
64
- if algoname == "echo" :
64
+ if algoname == "echo" and username == 'quality' :
65
65
return {"id" : "21df7a38-eab8-4ac8-954c-41a285535e69" , "name" : "echo" ,
66
66
"details" : {"summary" : "" , "label" : "echo" , "tagline" : "" },
67
67
"settings" : {"algorithm_callability" : "public" , "source_visibility" : "closed" ,
@@ -78,8 +78,11 @@ async def process_get_algo(request: Request, username, algoname):
78
78
"compilation" : {"successful" : True , "output" : "" },
79
79
"self_link" : "https://api.algorithmia.com/v1/algorithms/quality/echo/versions/0cfd7a6600f1fa05f9fe93016e661a9332c4ded2" ,
80
80
"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 )
81
84
else :
82
- return {"error" : "No such algorithm" }
85
+ return JSONResponse ( content = {"error" : "No such algorithm" }, status_code = 404 )
83
86
84
87
85
88
@regular_app .get ("/v1/algorithms/{username}/{algoname}/builds/{buildid}" )
@@ -101,7 +104,7 @@ async def get_scm_status(username, algoname):
101
104
102
105
@regular_app .get ("/v1/algorithms/{algo_id}/errors" )
103
106
async def get_algo_errors (algo_id ):
104
- return {"error" : {"message" : "not found" }}
107
+ return JSONResponse ( content = {"error" : {"message" : "not found" }}, status_code = 404 )
105
108
106
109
107
110
@regular_app .post ("/v1/algorithms/{username}" )
@@ -116,6 +119,7 @@ async def create_algorithm(request: Request, username):
116
119
"source" : {"scm" : {"id" : "internal" , "provider" : "internal" , "default" : True , "enabled" : True }},
117
120
"resource_type" : "algorithm" }
118
121
122
+
119
123
@regular_app .put ('/v1/algorithms/{username}/{algoname}' )
120
124
async def update_algorithm (request : Request , username , algoname ):
121
125
return {
@@ -255,7 +259,7 @@ async def get_algorithm_info(username, algoname, algohash):
255
259
"source" : {"scm" : {"id" : "internal" , "provider" : "internal" , "default" : True , "enabled" : True }},
256
260
"compilation" : {"successful" : True , "output" : "" }, "resource_type" : "algorithm" }
257
261
else :
258
- return {"error" : {"message" : "not found" }}
262
+ return JSONResponse ( content = {"error" : {"message" : "not found" }}, status_code = 404 )
259
263
260
264
261
265
### Admin Routes
0 commit comments