Unified stack refactor clean up
Clean up obsolete code and some warnings
parent: tbd commit: 356f714
1 | |
2 | |
3 | |
4 | |
5 | |
6 | use ; |
7 | |
8 | use Debug; |
9 | use FutureExt; |
10 | use |
11 | , | OperationError
12 | |
13 | AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest, |
14 | , |
15 | , | GiteratedObject
16 | , | ObjectBackend
17 | , | GiteratedOperation
18 | , |
19 | , |
20 | , | User
21 | , |
22 | ; |
23 | use ; |
24 | use ; |
25 | |
26 | |
27 | |
28 | object_name: String, |
29 | operation_name: String, |
30 | |
31 | |
32 | |
33 | name: String, |
34 | deserialize: , |
35 | |
36 | |
37 | |
38 | name: String, |
39 | deserialize: , |
40 | |
41 | |
42 | |
43 | name: String, |
44 | from_str: , |
45 | any_is_same: , |
46 | |
47 | |
48 | |
49 | name: String, |
50 | object_kind: String, |
51 | deserialize: , |
52 | any_is_same: , |
53 | serialize_success: |
54 | , |
55 | serialize_error: , |
56 | |
57 | |
58 | |
59 | |
60 | pub object_kind: String, |
61 | pub value_kind: String, |
62 | |
63 | |
64 | |
65 | |
66 | L, |
67 | O: GiteratedObject, |
68 | D: GiteratedOperation<O>, |
69 | S: Send + Sync + Clone, |
70 | >: Send + Sync |
71 | |
72 | ; |
73 | ; |
74 | |
75 | async |
76 | &self, |
77 | object: &O, |
78 | operation: D, |
79 | state: S, |
80 | operation_state: &StackOperationState, |
81 | ; |
82 | |
83 | |
84 | |
85 | |
86 | |
87 | F: FnMut( |
88 | &O, |
89 | D, |
90 | S, |
91 | ) -> |
92 | , |
93 | > + Send |
94 | + Sync |
95 | + Clone, |
96 | O: GiteratedObject + Send + Sync, |
97 | D: + 'static, |
98 | : Send, | Failure
99 | S: Send + Sync + Clone + 'static, |
100 | |
101 | |
102 | operation_name |
103 | |
104 | |
105 | |
106 | object_name |
107 | |
108 | |
109 | async |
110 | &self, |
111 | object: &O, |
112 | operation: D, |
113 | state: S, |
114 | _operation_state: &StackOperationState, |
115 | |
116 | self.clone .await |
117 | |
118 | |
119 | |
120 | |
121 | |
122 | |
123 | F: FnMut( |
124 | &O, |
125 | D, |
126 | S, |
127 | O1, |
128 | ) -> |
129 | , |
130 | > + Send |
131 | + Sync |
132 | + Clone, |
133 | O: GiteratedObject + Send + Sync, |
134 | D: + 'static + Send + Sync, |
135 | : Send, | Failure
136 | S: Send + Sync + Clone + 'static, |
137 | O1: , |
138 | |
139 | |
140 | operation_name |
141 | |
142 | |
143 | |
144 | object_name |
145 | |
146 | |
147 | async |
148 | &self, |
149 | object: &O, |
150 | operation: D, |
151 | state: S, |
152 | operation_state: &StackOperationState, |
153 | |
154 | let o1 = O1 from_state |
155 | .await |
156 | .map_err?; |
157 | self.clone .await |
158 | |
159 | |
160 | |
161 | |
162 | |
163 | |
164 | F: FnMut( |
165 | &O, |
166 | D, |
167 | S, |
168 | O1, |
169 | O2, |
170 | ) -> |
171 | , |
172 | > + Send |
173 | + Sync |
174 | + Clone, |
175 | O: GiteratedObject + Send + Sync, |
176 | D: + 'static + Send + Sync, |
177 | : Send, | Failure
178 | S: Send + Sync + Clone + 'static, |
179 | O1: , |
180 | O2: , |
181 | |
182 | |
183 | operation_name |
184 | |
185 | |
186 | |
187 | object_name |
188 | |
189 | |
190 | async |
191 | &self, |
192 | object: &O, |
193 | operation: D, |
194 | state: S, |
195 | operation_state: &StackOperationState, |
196 | |
197 | let o1 = O1 from_state |
198 | .await |
199 | .map_err?; |
200 | let o2 = O2 from_state |
201 | .await |
202 | .map_err?; |
203 | self.clone .await |
204 | |
205 | |
206 | |
207 | |
208 | |
209 | |
210 | F: FnMut( |
211 | &O, |
212 | D, |
213 | S, |
214 | O1, |
215 | O2, |
216 | O3, |
217 | ) -> |
218 | , |
219 | > + Send |
220 | + Sync |
221 | + Clone, |
222 | O: GiteratedObject + Send + Sync, |
223 | D: + 'static + Send + Sync, |
224 | : Send, | Failure
225 | S: Send + Sync + Clone + 'static, |
226 | O1: , |
227 | O2: , |
228 | O3: , |
229 | |
230 | |
231 | operation_name |
232 | |
233 | |
234 | |
235 | object_name |
236 | |
237 | |
238 | async |
239 | &self, |
240 | object: &O, |
241 | operation: D, |
242 | state: S, |
243 | operation_state: &StackOperationState, |
244 | |
245 | let o1 = O1 from_state |
246 | .await |
247 | .map_err?; |
248 | let o2 = O2 from_state |
249 | .await |
250 | .map_err?; |
251 | let o3 = O3 from_state |
252 | .await |
253 | .map_err?; |
254 | self.clone .await |
255 | |
256 | |
257 | |
258 | |
259 | func: |
260 | dyn Fn( |
261 | , |
262 | , |
263 | &(dyn Any + Send + Sync), |
264 | StackOperationState, |
265 | ) |
266 | -> |
267 | + Send |
268 | + Sync, |
269 | >, |
270 | state: , |
271 | |
272 | |
273 | |
274 | |
275 | A, |
276 | O: GiteratedObject + Send + Sync + 'static, |
277 | D: + 'static, |
278 | F: + Send + Sync + 'static + Clone, |
279 | S: GiteratedRuntimeState + 'static, |
280 | > |
281 | handler: F, |
282 | state: S, |
283 | |
284 | let handler = new; |
285 | Self |
286 | func: Box new |
287 | let handler = handler.clone; |
288 | let state = state. .unwrap .clone; |
289 | async move |
290 | let handler = handler.clone; |
291 | let object: = object.downcast .unwrap; |
292 | let operation: = operation.downcast .unwrap; |
293 | |
294 | let result = handler |
295 | .handle |
296 | .await; |
297 | result |
298 | .map |
299 | .map_err |
300 | => | Operation
301 | Operation |
302 | |
303 | => | Internal
304 | Internal |
305 | |
306 | => Unhandled, | Unhandled
307 | |
308 | |
309 | .boxed |
310 | , |
311 | state: Box new, |
312 | |
313 | |
314 | |
315 | async |
316 | &self, |
317 | object: , |
318 | operation: , |
319 | operation_state: &StackOperationState, |
320 | |
321 | .await |
322 | |
323 | |
324 | |
325 | |
326 | |
327 | Sized + Clone + Send |
328 | |
329 | type Error: Serialize + DeserializeOwned; |
330 | |
331 | async |
332 | object: &O, |
333 | operation: &D, |
334 | state: &StackOperationState, |
335 | ; |
336 | |
337 | |
338 | |
339 | |
340 | for Arc |
341 | |
342 | type Error = ; |
343 | |
344 | async |
345 | _object: &O, |
346 | _operation: &D, |
347 | state: &StackOperationState, |
348 | |
349 | Ok |
350 | |
351 | |
352 | |
353 | |
354 | |
355 | for StackOperationState |
356 | |
357 | type Error = ; |
358 | |
359 | async |
360 | _object: &O, |
361 | _operation: &D, |
362 | state: &StackOperationState, |
363 | |
364 | Ok |
365 | |
366 | |
367 | |
368 | |
369 | |
370 | for AuthenticatedUser |
371 | |
372 | type Error = ; |
373 | |
374 | async |
375 | _object: &O, |
376 | _operation: &D, |
377 | state: &StackOperationState, |
378 | |
379 | state |
380 | .user |
381 | .clone |
382 | .ok_or_else |
383 | |
384 | |
385 | |
386 | |
387 | |
388 | for AuthenticatedInstance |
389 | |
390 | type Error = ; |
391 | |
392 | async |
393 | _object: &O, |
394 | _operation: &D, |
395 | state: &StackOperationState, |
396 | |
397 | state |
398 | .instance |
399 | .clone |
400 | .ok_or_else |
401 | |
402 | |
403 | |
404 | |
405 | |
406 | T: + Send + Sync, |
407 | O: GiteratedObject + Sync, |
408 | D: + Send + Sync, |
409 | > |
410 | |
411 | type Error = ; |
412 | |
413 | async |
414 | object: &O, |
415 | operation: &D, |
416 | state: &StackOperationState, |
417 | |
418 | Ok |
419 | |
420 | |
421 | |
422 | |
423 | ; |
424 | |
425 | |
426 | ; |
427 | |
428 | |
429 | |
430 | async |
431 | &self, |
432 | authorize_for: &O, |
433 | state: &StackOperationState, |
434 | ; |
435 | |
436 | |
437 | |
438 | |
439 | O: GiteratedObject + Send + Sync + Debug, |
440 | V: + Send + Sync, |
441 | > |
442 | |
443 | async |
444 | &self, |
445 | authorize_for: &O, |
446 | operation_state: &StackOperationState, |
447 | |
448 | Ok |
449 | .runtime |
450 | . |
451 | .await |
452 | .is_ok |
453 | |
454 | |
455 | |
456 | |
457 | |
458 | async |
459 | &self, |
460 | authorize_for: &User, |
461 | operation_state: &StackOperationState, |
462 | |
463 | let authenticated_user = operation_state |
464 | .user |
465 | .as_ref |
466 | .ok_or_else?; |
467 | |
468 | Ok |
469 | |
470 | |
471 | |
472 | |
473 | |
474 | async |
475 | &self, |
476 | authorize_for: &User, |
477 | operation_state: &StackOperationState, |
478 | |
479 | let authenticated_user = operation_state |
480 | .user |
481 | .as_ref |
482 | .ok_or_else?; |
483 | |
484 | Ok |
485 | |
486 | |
487 | |
488 | |
489 | |
490 | async |
491 | &self, |
492 | authorize_for: &Repository, |
493 | operation_state: &StackOperationState, |
494 | |
495 | let authenticated_user = operation_state |
496 | .user |
497 | .as_ref |
498 | .ok_or_else?; |
499 | |
500 | let mut object = operation_state |
501 | .runtime |
502 | . |
503 | .await |
504 | .map_err?; |
505 | |
506 | let access_list = object |
507 | . |
508 | .await |
509 | .map_err?; |
510 | |
511 | if access_list |
512 | .0 |
513 | .iter |
514 | .find |
515 | .is_some |
516 | |
517 | Ok |
518 | else |
519 | Ok |
520 | |
521 | |
522 | |
523 | |
524 | |
525 | |
526 | async |
527 | &self, |
528 | authorize_for: &Repository, |
529 | operation_state: &StackOperationState, |
530 | |
531 | let authenticated_user = operation_state |
532 | .user |
533 | .as_ref |
534 | .ok_or_else?; |
535 | |
536 | let mut object = operation_state |
537 | .runtime |
538 | . |
539 | .await |
540 | .map_err?; |
541 | |
542 | let access_list = object |
543 | . |
544 | .await |
545 | .map_err?; |
546 | |
547 | if access_list |
548 | .0 |
549 | .iter |
550 | .find |
551 | .is_some |
552 | |
553 | Ok |
554 | else |
555 | Ok |
556 | |
557 | |
558 | |
559 | |
560 | |
561 | |
562 | async |
563 | &self, |
564 | authorize_for: &Instance, |
565 | state: &StackOperationState, |
566 | |
567 | if state.our_instance == *authorize_for |
568 | Ok |
569 | else |
570 | Ok |
571 | |
572 | |
573 | |
574 | |
575 | |
576 | |
577 | async |
578 | &self, |
579 | authorize_for: &Instance, |
580 | state: &StackOperationState, |
581 | |
582 | if state.our_instance == *authorize_for |
583 | Ok |
584 | else |
585 | Ok |
586 | |
587 | |
588 | |
589 | |
590 | |
591 | |
592 | async |
593 | &self, |
594 | authorize_for: &Instance, |
595 | state: &StackOperationState, |
596 | |
597 | if state.our_instance == *authorize_for |
598 | Ok |
599 | else |
600 | Ok |
601 | |
602 | |
603 | |
604 | |
605 | |
606 | |
607 | type Error = ; |
608 | |
609 | async |
610 | object: &User, |
611 | operation: &A, |
612 | state: &StackOperationState, |
613 | |
614 | let authenticated = from_state .await?; |
615 | |
616 | match operation.authorize .await |
617 | Ok => |
618 | assert!; |
619 | |
620 | Err => return Err, |
621 | ; |
622 | |
623 | Ok |
624 | |
625 | |
626 | |
627 | |
628 | |
629 | for AuthorizedInstance |
630 | |
631 | type Error = ; |
632 | |
633 | async |
634 | object: &Instance, |
635 | operation: &A, |
636 | state: &StackOperationState, |
637 | |
638 | let authenticated = from_state .await?; |
639 | |
640 | match operation.authorize .await |
641 | Ok => |
642 | assert!; |
643 | |
644 | Err => return Err, |
645 | ; |
646 | |
647 | Ok |
648 | |
649 | |
650 | |
651 | // #[async_trait::async_trait> FromOperationState for Option<T> { |
652 | // type Error = (); |
653 | |
654 | // async fn from_state(state: &StackOperationState) -> Result<Option<T>, OperationError<()>> { |
655 | // Ok(T::from_state(] |
656 | // impl<T: FromOperationStatestate).await.ok()) |
657 | // } |
658 | // } |
659 | |
660 | |
661 | |
662 | pub our_instance: Instance, |
663 | pub runtime: , |
664 | pub instance: , |
665 | pub user: , |
666 | |
667 | |
668 | |
669 | ; |
670 | |
671 | |
672 | |
673 | AuthenticatedInstance |
674 | |
675 | |
676 | |
677 | |
678 | type Target = Instance; |
679 | |
680 | |
681 | &self.0 |
682 | |
683 | |
684 | |
685 | |
686 | ; |
687 | |
688 | |
689 | |
690 | AuthenticatedUser |
691 | |
692 | |
693 | |
694 | |
695 | type Target = User; |
696 | |
697 | |
698 | &self.0 |
699 | |
700 | |
701 |