39
39
@router .get (
40
40
"/setup" ,
41
41
responses = {
42
- 200 : {"model" : Config , "description" : "OK: The results for this request were retrieved successfully." },
43
- 429 : {"description" : "Too Many Requests: The user has exceeded the limit of allowed simultaneous requests." },
44
- 500 : {"description" : "Internal Server Error: Something went wrong on the server while retrieving the data." },
45
- 503 : {"description" : "Service Unavailable: The server is currently down, e.g. for maintenance. Please try again later." },
42
+ 200 : {
43
+ "model" : Config ,
44
+ "description" : "OK: The results for this request were retrieved successfully." ,
45
+ },
46
+ 429 : {
47
+ "description" : "Too Many Requests: The user has exceeded the limit of allowed simultaneous requests."
48
+ },
49
+ 500 : {
50
+ "description" : "Internal Server Error: Something went wrong on the server while retrieving the data."
51
+ },
52
+ 503 : {
53
+ "description" : "Service Unavailable: The server is currently down, e.g. for maintenance. Please try again later."
54
+ },
46
55
},
47
56
tags = ["general" ],
48
- response_class = ORJSONResponse
57
+ response_class = ORJSONResponse ,
49
58
)
50
- async def get_setup (
51
- request : Request = None
52
- ) -> Config :
59
+ async def get_setup (request : Request = None ) -> Config :
53
60
"""Get the current config for this flowkit-ui-backend server."""
54
61
55
- if not hasattr (general_api_impl , 'get_setup' ) or not callable (getattr (general_api_impl , 'get_setup' )):
62
+ if not hasattr (general_api_impl , "get_setup" ) or not callable (
63
+ getattr (general_api_impl , "get_setup" )
64
+ ):
56
65
raise NotImplementedError ("The /get_setup endpoint is not yet implemented" )
57
66
58
67
try :
@@ -65,38 +74,61 @@ async def get_setup(
65
74
# default to status 200/204 but give the impl the option to define a different status code when returning content
66
75
status_code = impl_result [1 ] if isinstance (impl_result , tuple ) else None
67
76
if content is not None :
68
- return ORJSONResponse (status_code = status_code if status_code is not None else HTTPStatus .OK , content = jsonable_encoder (content ))
77
+ return ORJSONResponse (
78
+ status_code = status_code if status_code is not None else HTTPStatus .OK ,
79
+ content = jsonable_encoder (content ),
80
+ )
69
81
else :
70
- return Response (status_code = status_code if status_code is not None else HTTPStatus .NO_CONTENT )
82
+ return Response (
83
+ status_code = status_code
84
+ if status_code is not None
85
+ else HTTPStatus .NO_CONTENT
86
+ )
71
87
72
88
# This is where we handle status codes via exceptions as raised by the impl methods
73
89
except HTTPException as e :
74
- logger .debug ("Request failed" , code = e .status_code , content = e .detail , traceback = traceback .print_exception (type (e ), e , e .__traceback__ ))
90
+ logger .debug (
91
+ "Request failed" ,
92
+ code = e .status_code ,
93
+ content = e .detail ,
94
+ traceback = traceback .print_exception (type (e ), e , e .__traceback__ ),
95
+ )
75
96
return JSONResponse (status_code = e .status_code , content = e .detail )
76
97
except Exception as e :
77
98
logger .error (e )
78
99
traceback .print_exception (type (e ), e , e .__traceback__ )
79
- return JSONResponse (status_code = HTTPStatus .INTERNAL_SERVER_ERROR , content = f"Something went wrong: { e } " )
80
-
100
+ return JSONResponse (
101
+ status_code = HTTPStatus .INTERNAL_SERVER_ERROR ,
102
+ content = f"Something went wrong: { e } " ,
103
+ )
81
104
82
105
83
106
@router .get (
84
107
"/heartbeat" ,
85
108
responses = {
86
- 200 : {"model" : Heartbeat , "description" : "OK: The results for this request were retrieved successfully." },
87
- 429 : {"description" : "Too Many Requests: The user has exceeded the limit of allowed simultaneous requests." },
88
- 500 : {"description" : "Internal Server Error: Something went wrong on the server while retrieving the data." },
89
- 503 : {"description" : "Service Unavailable: The server is currently down, e.g. for maintenance. Please try again later." },
109
+ 200 : {
110
+ "model" : Heartbeat ,
111
+ "description" : "OK: The results for this request were retrieved successfully." ,
112
+ },
113
+ 429 : {
114
+ "description" : "Too Many Requests: The user has exceeded the limit of allowed simultaneous requests."
115
+ },
116
+ 500 : {
117
+ "description" : "Internal Server Error: Something went wrong on the server while retrieving the data."
118
+ },
119
+ 503 : {
120
+ "description" : "Service Unavailable: The server is currently down, e.g. for maintenance. Please try again later."
121
+ },
90
122
},
91
123
tags = ["general" ],
92
- response_class = ORJSONResponse
124
+ response_class = ORJSONResponse ,
93
125
)
94
- async def heartbeat (
95
- request : Request = None
96
- ) -> Heartbeat :
126
+ async def heartbeat (request : Request = None ) -> Heartbeat :
97
127
"""Checks whether the API is up and running"""
98
128
99
- if not hasattr (general_api_impl , 'heartbeat' ) or not callable (getattr (general_api_impl , 'heartbeat' )):
129
+ if not hasattr (general_api_impl , "heartbeat" ) or not callable (
130
+ getattr (general_api_impl , "heartbeat" )
131
+ ):
100
132
raise NotImplementedError ("The /heartbeat endpoint is not yet implemented" )
101
133
102
134
try :
@@ -109,60 +141,101 @@ async def heartbeat(
109
141
# default to status 200/204 but give the impl the option to define a different status code when returning content
110
142
status_code = impl_result [1 ] if isinstance (impl_result , tuple ) else None
111
143
if content is not None :
112
- return ORJSONResponse (status_code = status_code if status_code is not None else HTTPStatus .OK , content = jsonable_encoder (content ))
144
+ return ORJSONResponse (
145
+ status_code = status_code if status_code is not None else HTTPStatus .OK ,
146
+ content = jsonable_encoder (content ),
147
+ )
113
148
else :
114
- return Response (status_code = status_code if status_code is not None else HTTPStatus .NO_CONTENT )
149
+ return Response (
150
+ status_code = status_code
151
+ if status_code is not None
152
+ else HTTPStatus .NO_CONTENT
153
+ )
115
154
116
155
# This is where we handle status codes via exceptions as raised by the impl methods
117
156
except HTTPException as e :
118
- logger .debug ("Request failed" , code = e .status_code , content = e .detail , traceback = traceback .print_exception (type (e ), e , e .__traceback__ ))
157
+ logger .debug (
158
+ "Request failed" ,
159
+ code = e .status_code ,
160
+ content = e .detail ,
161
+ traceback = traceback .print_exception (type (e ), e , e .__traceback__ ),
162
+ )
119
163
return JSONResponse (status_code = e .status_code , content = e .detail )
120
164
except Exception as e :
121
165
logger .error (e )
122
166
traceback .print_exception (type (e ), e , e .__traceback__ )
123
- return JSONResponse (status_code = HTTPStatus .INTERNAL_SERVER_ERROR , content = f"Something went wrong: { e } " )
124
-
167
+ return JSONResponse (
168
+ status_code = HTTPStatus .INTERNAL_SERVER_ERROR ,
169
+ content = f"Something went wrong: { e } " ,
170
+ )
125
171
126
172
127
173
@router .get (
128
174
"/data_providers" ,
129
175
responses = {
130
- 200 : {"model" : DataProviders , "description" : "OK: The results for this request were retrieved successfully." },
131
- 429 : {"description" : "Too Many Requests: The user has exceeded the limit of allowed simultaneous requests." },
132
- 500 : {"description" : "Internal Server Error: Something went wrong on the server while retrieving the data." },
133
- 503 : {"description" : "Service Unavailable: The server is currently down, e.g. for maintenance. Please try again later." },
176
+ 200 : {
177
+ "model" : DataProviders ,
178
+ "description" : "OK: The results for this request were retrieved successfully." ,
179
+ },
180
+ 429 : {
181
+ "description" : "Too Many Requests: The user has exceeded the limit of allowed simultaneous requests."
182
+ },
183
+ 500 : {
184
+ "description" : "Internal Server Error: Something went wrong on the server while retrieving the data."
185
+ },
186
+ 503 : {
187
+ "description" : "Service Unavailable: The server is currently down, e.g. for maintenance. Please try again later."
188
+ },
134
189
},
135
190
tags = ["general" ],
136
- response_class = ORJSONResponse
191
+ response_class = ORJSONResponse ,
137
192
)
138
- async def list_data_providers (
139
- request : Request = None
140
- ) -> DataProviders :
193
+ async def list_data_providers (request : Request = None ) -> DataProviders :
141
194
"""Gets a list of all data providers configured for this flowkit-ui-backend instance"""
142
195
143
- if not hasattr (general_api_impl , 'list_data_providers' ) or not callable (getattr (general_api_impl , 'list_data_providers' )):
144
- raise NotImplementedError ("The /list_data_providers endpoint is not yet implemented" )
196
+ if not hasattr (general_api_impl , "list_data_providers" ) or not callable (
197
+ getattr (general_api_impl , "list_data_providers" )
198
+ ):
199
+ raise NotImplementedError (
200
+ "The /list_data_providers endpoint is not yet implemented"
201
+ )
145
202
146
203
try :
147
204
logger .debug ("Starting request" )
148
- impl_result = await general_api_impl .list_data_providers (pool = request .app .state .pool )
205
+ impl_result = await general_api_impl .list_data_providers (
206
+ pool = request .app .state .pool
207
+ )
149
208
logger .debug ("Request ready" )
150
209
content = impl_result [0 ] if isinstance (impl_result , tuple ) else impl_result
151
210
if isinstance (impl_result , Response ):
152
211
return impl_result
153
212
# default to status 200/204 but give the impl the option to define a different status code when returning content
154
213
status_code = impl_result [1 ] if isinstance (impl_result , tuple ) else None
155
214
if content is not None :
156
- return ORJSONResponse (status_code = status_code if status_code is not None else HTTPStatus .OK , content = jsonable_encoder (content ))
215
+ return ORJSONResponse (
216
+ status_code = status_code if status_code is not None else HTTPStatus .OK ,
217
+ content = jsonable_encoder (content ),
218
+ )
157
219
else :
158
- return Response (status_code = status_code if status_code is not None else HTTPStatus .NO_CONTENT )
220
+ return Response (
221
+ status_code = status_code
222
+ if status_code is not None
223
+ else HTTPStatus .NO_CONTENT
224
+ )
159
225
160
226
# This is where we handle status codes via exceptions as raised by the impl methods
161
227
except HTTPException as e :
162
- logger .debug ("Request failed" , code = e .status_code , content = e .detail , traceback = traceback .print_exception (type (e ), e , e .__traceback__ ))
228
+ logger .debug (
229
+ "Request failed" ,
230
+ code = e .status_code ,
231
+ content = e .detail ,
232
+ traceback = traceback .print_exception (type (e ), e , e .__traceback__ ),
233
+ )
163
234
return JSONResponse (status_code = e .status_code , content = e .detail )
164
235
except Exception as e :
165
236
logger .error (e )
166
237
traceback .print_exception (type (e ), e , e .__traceback__ )
167
- return JSONResponse (status_code = HTTPStatus .INTERNAL_SERVER_ERROR , content = f"Something went wrong: { e } " )
168
-
238
+ return JSONResponse (
239
+ status_code = HTTPStatus .INTERNAL_SERVER_ERROR ,
240
+ content = f"Something went wrong: { e } " ,
241
+ )
0 commit comments