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