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