1
1
import flask
2
- from flask_restx import Api , Resource
2
+ from flask_restx import Api , Resource , fields
3
3
import json
4
4
import humps
5
5
from typing import Dict , Callable , Any
10
10
from app .server .requestutils import httpify_excs , pubsubify_excs
11
11
12
12
routes = flask .Blueprint ('import-service' , __name__ , '/' )
13
+
14
+ authorizations = {
15
+ 'Bearer' : {
16
+ "type" : "apiKey" ,
17
+ "name" : "Authorization" ,
18
+ "in" : "header" ,
19
+ "description" : "Use your GCP auth token, i.e. `gcloud auth print-access-token`. Required scopes are [openid, email, profile]. Write `Bearer <yourtoken>` in the box."
20
+ }
21
+ }
22
+
13
23
api = Api (routes , version = '1.0' , title = 'Import Service' ,
14
- description = 'import service' )
24
+ description = 'import service' ,
25
+ authorizations = authorizations ,
26
+ security = [{"Bearer" : "[]" }])
15
27
16
28
ns = api .namespace ('/' , description = 'import handling' )
17
29
18
30
31
+ new_import_model = ns .model ("NewImport" ,
32
+ {"path" : fields .String (required = True ),
33
+ "filetype" : fields .String (enum = list (translate .FILETYPE_TRANSLATORS .keys ()), required = True )})
19
34
import_status_response_model = ns .model ("ImportStatusResponse" , model .ImportStatusResponse .get_model ())
20
35
21
36
22
- @ns .route ('/<ws_ns>/<ws_name>/imports/<import_id>' )
37
+ @ns .route ('/<workspace_project>/<workspace_name>/imports/<import_id>' )
38
+ @ns .param ('workspace_project' , 'Workspace project' )
39
+ @ns .param ('workspace_name' , 'Workspace name' )
40
+ @ns .param ('import_id' , 'Import id' )
23
41
class SpecificImport (Resource ):
24
42
@httpify_excs
25
43
@ns .marshal_with (import_status_response_model )
26
- def get (self , ws_ns , ws_name , import_id ):
44
+ def get (self , workspace_project , workspace_name , import_id ):
27
45
"""Return status for this import."""
28
- return status .handle_get_import_status (flask .request , ws_ns , ws_name , import_id )
46
+ return status .handle_get_import_status (flask .request , workspace_project , workspace_name , import_id )
29
47
30
48
31
- @ns .route ('/<ws_ns>/<ws_name>/imports' )
49
+ @ns .route ('/<workspace_project>/<workspace_name>/imports' )
50
+ @ns .param ('workspace_project' , 'Workspace project' )
51
+ @ns .param ('workspace_name' , 'Workspace name' )
32
52
class Imports (Resource ):
33
53
@httpify_excs
34
- @ns .marshal_with (import_status_response_model , 201 )
35
- def post (self , ws_ns , ws_name ):
54
+ @ns .expect (new_import_model , validate = True )
55
+ @ns .marshal_with (import_status_response_model , code = 201 )
56
+ def post (self , workspace_project , workspace_name ):
36
57
"""Accept an import request."""
37
- return new_import .handle (flask .request , ws_ns , ws_name ), 201
58
+ return new_import .handle (flask .request , workspace_project , workspace_name ), 201
38
59
39
60
@httpify_excs
40
- @ns .marshal_with (import_status_response_model , 200 )
41
- def get (self , ws_ns , ws_name ):
61
+ @ns .marshal_with (import_status_response_model , code = 200 , as_list = True )
62
+ def get (self , workspace_project , workspace_name ):
42
63
"""Return all imports in the workspace."""
43
- return status .handle_list_import_status (flask .request , ws_ns , ws_name )
64
+ return status .handle_list_import_status (flask .request , workspace_project , workspace_name )
44
65
45
66
46
67
# Dispatcher for pubsub messages.
@@ -55,7 +76,7 @@ def get(self, ws_ns, ws_name):
55
76
@ns .route ('/_ah/push-handlers/receive_messages' , doc = False )
56
77
class PubSub (Resource ):
57
78
@pubsubify_excs
58
- @ns .marshal_with (import_status_response_model , 200 )
79
+ @ns .marshal_with (import_status_response_model , code = 200 )
59
80
def post (self ) -> flask .Response :
60
81
app .auth .service_auth .verify_pubsub_jwt (flask .request )
61
82
0 commit comments