log internal errors
parent: tbd commit: 3923b5f
1 | |
2 | |
3 | use ; |
4 | |
5 | use OperationError; |
6 | use Instance; |
7 | use |
8 | AnyObject, GiteratedObject, Object, ObjectRequest, ObjectRequestError, |
9 | ; |
10 | use ObjectBackend; |
11 | use GiteratedOperation; |
12 | use Repository; |
13 | use User; |
14 | use Debug; |
15 | use Mutex; |
16 | |
17 | use crate; |
18 | |
19 | use |
20 | repository_commit_before, repository_diff, repository_file_from_id, repository_get_setting, |
21 | repository_get_value, repository_info, repository_set_setting, user_get_repositories, |
22 | user_get_setting, user_get_value, user_set_setting, OperationHandlers, |
23 | ; |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | async |
31 | &self, |
32 | _object: O, |
33 | _operation: &str, |
34 | _payload: D, |
35 | |
36 | // We don't handle operations with this backend |
37 | Err |
38 | |
39 | |
40 | async |
41 | &self, |
42 | _object_str: &str, |
43 | |
44 | Err |
45 | |
46 | |
47 | |
48 | /// A backend implementation which attempts to resolve data from the instance's database. |
49 | |
50 | |
51 | pub(self) our_instance: Instance, |
52 | pub(self) user_backend: , |
53 | pub(self) repository_backend: , |
54 | |
55 | |
56 | |
57 | |
58 | instance: Instance, |
59 | user_backend: , |
60 | repository_backend: , |
61 | |
62 | Self |
63 | our_instance: instance, |
64 | user_backend, |
65 | repository_backend, |
66 | |
67 | |
68 | |
69 | |
70 | |
71 | |
72 | f.debug_struct .finish |
73 | |
74 | |
75 | |
76 | |
77 | |
78 | async |
79 | &self, |
80 | object: O, |
81 | operation: &str, |
82 | payload: D, |
83 | |
84 | let serialized = |
85 | map_err?; | to_value .
86 | let object = object.to_string; |
87 | if let Ok = from_str |
88 | let mut handler = default; |
89 | |
90 | handler |
91 | .insert |
92 | .insert |
93 | .insert |
94 | .insert; |
95 | |
96 | match handler |
97 | .handle |
98 | &user, |
99 | operation, |
100 | unwrap, | from_value .
101 | self.clone, |
102 | |
103 | .await |
104 | |
105 | Ok => Ok |
106 | .map_err?, |
107 | Err => match err |
108 | => | Internal
109 | warn!; |
110 | |
111 | Err |
112 | , |
113 | => Err, | Unhandled
114 | => Err | Operation
115 | from_slice |
116 | .map_err?, |
117 | , |
118 | , |
119 | |
120 | else if let Ok = from_str |
121 | let mut handler = default; |
122 | |
123 | handler |
124 | .insert |
125 | .insert |
126 | .insert |
127 | .insert |
128 | .insert |
129 | .insert |
130 | .insert; |
131 | |
132 | match handler |
133 | .handle |
134 | &repository, |
135 | operation, |
136 | unwrap, | from_value .
137 | self.clone, |
138 | |
139 | .await |
140 | |
141 | Ok => Ok |
142 | .map_err?, |
143 | Err => match err |
144 | => | Internal
145 | warn!; |
146 | |
147 | Err |
148 | , |
149 | => Err, | Unhandled
150 | => Err | Operation
151 | from_slice |
152 | .map_err?, |
153 | , |
154 | , |
155 | |
156 | else if let Ok = from_str |
157 | if instance != self.our_instance |
158 | // We don't handle other objects currently |
159 | return Err; |
160 | |
161 | |
162 | if let Ok = |
163 | |
164 | let result = self. .await; |
165 | |
166 | let result = result |
167 | .map |
168 | .map_err |
169 | => | Operation
170 | Operation |
171 | |
172 | => Internal, | Internal
173 | => Unhandled, | Unhandled
174 | ; |
175 | |
176 | match result |
177 | Ok => Ok |
178 | .map_err?, |
179 | Err => match err |
180 | => | Internal
181 | warn!; |
182 | |
183 | Err |
184 | |
185 | => Err, | Unhandled
186 | => Err | Operation
187 | from_slice |
188 | .map_err?, |
189 | , |
190 | , |
191 | |
192 | else |
193 | Err |
194 | |
195 | else |
196 | Err |
197 | |
198 | |
199 | |
200 | async |
201 | &self, |
202 | object_str: &str, |
203 | |
204 | if let Ok = from_str |
205 | let mut user_backend = self.user_backend.lock .await; |
206 | |
207 | if user_backend |
208 | .exists |
209 | .await |
210 | .map_err? |
211 | |
212 | Ok |
213 | new_unchecked |
214 | from_object_str |
215 | .map_err?, |
216 | self.clone, |
217 | |
218 | |
219 | else |
220 | return Err; |
221 | |
222 | else if let Ok = from_str |
223 | let mut repository_backend = self.repository_backend.lock .await; |
224 | |
225 | if repository_backend |
226 | .exists |
227 | .await |
228 | .map_err? |
229 | |
230 | Ok |
231 | new_unchecked |
232 | from_object_str |
233 | .map_err?, |
234 | self.clone, |
235 | |
236 | |
237 | else |
238 | return Err; |
239 | |
240 | else if let Ok = from_str |
241 | if instance != self.our_instance |
242 | // We don't handle other objects currently |
243 | return Err; |
244 | |
245 | |
246 | return Err; |
247 | else |
248 | // Invalid object type |
249 | return Err; |
250 | |
251 | |
252 | |
253 | |
254 | // These tests verify that the essential handling of the database backend is |
255 | // functional and correct. |
256 | |
257 | |
258 | use ; |
259 | |
260 | use Error; |
261 | |
262 | use UserAuthenticationToken; |
263 | |
264 | use |
265 | AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest, |
266 | ; |
267 | |
268 | use ObjectBackend; |
269 | |
270 | use |
271 | Commit, Description, Repository, RepositoryCommitBeforeRequest, RepositoryDiff, |
272 | RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest, |
273 | RepositoryFileInspectRequest, RepositorySummary, RepositoryTreeEntry, |
274 | ; |
275 | use AnySetting; |
276 | use ; |
277 | use ; |
278 | use Value; |
279 | use Mutex; |
280 | |
281 | use crate; |
282 | |
283 | use DatabaseBackend; |
284 | ; |
285 | |
286 | |
287 | |
288 | async |
289 | assert_eq!; |
290 | |
291 | Ok |
292 | & to_vec .unwrap, |
293 | |
294 | .unwrap |
295 | |
296 | async |
297 | Ok |
298 | & to_vec .unwrap, |
299 | |
300 | .unwrap |
301 | |
302 | async |
303 | &mut self, |
304 | _user: &User, |
305 | _name: &str, |
306 | _setting: &Value, |
307 | |
308 | Ok |
309 | |
310 | async |
311 | Ok |
312 | |
313 | async |
314 | &mut self, |
315 | requester: , |
316 | user: &User, |
317 | |
318 | todo! |
319 | |
320 | |
321 | |
322 | |
323 | |
324 | async |
325 | &mut self, |
326 | _request: RegisterAccountRequest, |
327 | |
328 | todo! |
329 | |
330 | |
331 | async |
332 | &mut self, |
333 | _source: &Instance, |
334 | _request: AuthenticationTokenRequest, |
335 | |
336 | todo! |
337 | |
338 | |
339 | |
340 | ; |
341 | |
342 | |
343 | |
344 | async |
345 | &mut self, |
346 | _user: &User, |
347 | _request: &RepositoryCreateRequest, |
348 | |
349 | todo! |
350 | |
351 | async |
352 | &mut self, |
353 | requester: , |
354 | repository: &Repository, |
355 | request: &RepositoryFileInspectRequest, |
356 | |
357 | todo! |
358 | |
359 | async |
360 | &mut self, |
361 | requester: , |
362 | repository: &Repository, |
363 | request: &RepositoryFileFromIdRequest, |
364 | |
365 | todo! |
366 | |
367 | async |
368 | &mut self, |
369 | requester: , |
370 | repository: &Repository, |
371 | request: &RepositoryDiffRequest, |
372 | |
373 | todo! |
374 | |
375 | async |
376 | &mut self, |
377 | requester: , |
378 | repository: &Repository, |
379 | request: &RepositoryCommitBeforeRequest, |
380 | |
381 | todo! |
382 | |
383 | async |
384 | &mut self, |
385 | _repository: &Repository, |
386 | _name: &str, |
387 | |
388 | Ok |
389 | & to_vec .unwrap, |
390 | |
391 | .unwrap |
392 | |
393 | async |
394 | &mut self, |
395 | _repository: &Repository, |
396 | _name: &str, |
397 | |
398 | Ok |
399 | & to_vec .unwrap, |
400 | |
401 | .unwrap |
402 | |
403 | async |
404 | &mut self, |
405 | _repository: &Repository, |
406 | _name: &str, |
407 | _setting: &Value, |
408 | |
409 | Ok |
410 | |
411 | |
412 | async |
413 | // Ok(true) |
414 | Ok |
415 | == & from_str |
416 | "test_user:test.giterated.dev/[email protected]", |
417 | |
418 | .unwrap |
419 | |
420 | |
421 | |
422 | |
423 | DatabaseBackend |
424 | our_instance: from_str .unwrap, |
425 | user_backend: new as _, |
426 | repository_backend: new as _, |
427 | |
428 | |
429 | |
430 | |
431 | async |
432 | let backend = test_backend; |
433 | |
434 | let mut user = backend |
435 | . |
436 | .await |
437 | .expect; |
438 | |
439 | user. |
440 | .await |
441 | .expect; |
442 | |
443 | |
444 | |
445 | async |
446 | let backend = test_backend; |
447 | |
448 | let mut user = backend |
449 | . |
450 | .await |
451 | .expect; |
452 | |
453 | user. |
454 | .await |
455 | .expect; |
456 | |
457 | |
458 | |
459 | async |
460 | let backend = test_backend; |
461 | |
462 | let mut user = backend |
463 | . |
464 | .await |
465 | .expect; |
466 | |
467 | user. |
468 | .await |
469 | .expect; |
470 | |
471 | |
472 | |
473 | async |
474 | let backend = test_backend; |
475 | |
476 | let mut repository = backend |
477 | . |
478 | .await |
479 | .expect; |
480 | |
481 | repository |
482 | . |
483 | .await |
484 | .expect; |
485 | |
486 | |
487 | |
488 | async |
489 | let backend = test_backend; |
490 | |
491 | let mut repository = backend |
492 | . |
493 | .await |
494 | .expect; |
495 | |
496 | repository |
497 | . |
498 | .await |
499 | .expect; |
500 | |
501 | |
502 | |
503 | async |
504 | let backend = test_backend; |
505 | |
506 | let mut repository = backend |
507 | . |
508 | .await |
509 | .expect; |
510 | |
511 | repository |
512 | . |
513 | .await |
514 | .expect; |
515 | |
516 | |
517 |