Add authentication back into the operation states
parent: tbd commit: 97a26fd
1 | |
2 | |
3 | |
4 | use ; |
5 | |
6 | use FutureExt; |
7 | use |
8 | , | OperationError
9 | , | Instance
10 | |
11 | AnyObject, GiteratedObject, Object, ObjectRequest, ObjectRequestError, ObjectResponse, |
12 | , |
13 | , | ObjectBackend
14 | , |
15 | , | Repository
16 | , | User
17 | ; |
18 | use GiteratedBackend; |
19 | use ; |
20 | use Value; |
21 | use HandlerState; |
22 | use ; |
23 | use ; |
24 | |
25 | |
26 | |
27 | object_name: String, |
28 | operation_name: String, |
29 | |
30 | |
31 | |
32 | operations: , |
33 | get_object: , |
34 | |
35 | |
36 | |
37 | |
38 | Self |
39 | operations: new, |
40 | get_object: Vec new, |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | A, |
48 | O: GiteratedObject + Send + Sync, |
49 | D: + 'static, |
50 | H: + Send + Sync + 'static + Clone, |
51 | > |
52 | &mut self, |
53 | handler: H, |
54 | |
55 | let object_name = handler.object_name .to_string; |
56 | let operation_name = handler.operation_name .to_string; |
57 | |
58 | let wrapped = new; |
59 | |
60 | let pair = ObjectOperationPair |
61 | object_name, |
62 | operation_name, |
63 | ; |
64 | |
65 | assert!; |
66 | |
67 | self |
68 | |
69 | |
70 | |
71 | let closure = |
72 | async move |
73 | if from_str .is_ok |
74 | Ok |
75 | else |
76 | Err |
77 | |
78 | |
79 | .boxed |
80 | ; |
81 | |
82 | let wrapped = new; |
83 | |
84 | self.get_object.push; |
85 | |
86 | self |
87 | |
88 | |
89 | pub async |
90 | &self, |
91 | object: &O, |
92 | operation_name: &str, |
93 | operation: AnyOperation, |
94 | state: S, |
95 | operation_state: &StackOperationState, |
96 | |
97 | // TODO |
98 | let object = object.to_string; |
99 | |
100 | let object_name = |
101 | if from_str .is_ok |
102 | object_name |
103 | else if from_str .is_ok |
104 | object_name |
105 | else if from_str .is_ok |
106 | object_name |
107 | else |
108 | return Err; |
109 | |
110 | |
111 | .to_string; |
112 | |
113 | let target_handler = ObjectOperationPair |
114 | object_name, |
115 | operation_name: operation_name.to_string, |
116 | ; |
117 | |
118 | if let Some = self.operations.get |
119 | handler |
120 | .handle |
121 | AnyObject, |
122 | operation.clone, |
123 | state.clone, |
124 | operation_state, |
125 | |
126 | .await |
127 | else |
128 | Err |
129 | |
130 | |
131 | |
132 | pub async |
133 | &self, |
134 | instance: AnyObject, |
135 | request: ObjectRequest, |
136 | state: S, |
137 | operation_state: &StackOperationState, |
138 | |
139 | for handler in self.get_object.iter |
140 | if let Ok = handler |
141 | .handle |
142 | instance.clone, |
143 | AnyOperation, |
144 | state.clone, |
145 | operation_state, |
146 | |
147 | .await |
148 | |
149 | return Ok; |
150 | |
151 | |
152 | |
153 | Err |
154 | |
155 | |
156 | |
157 | |
158 | |
159 | L, |
160 | O: GiteratedObject, |
161 | D: GiteratedOperation<O>, |
162 | S: Send + Sync + Clone, |
163 | > |
164 | |
165 | ; |
166 | ; |
167 | |
168 | async |
169 | &self, |
170 | object: &O, |
171 | operation: D, |
172 | state: S, |
173 | operation_state: &StackOperationState, |
174 | ; |
175 | |
176 | |
177 | |
178 | |
179 | |
180 | F: FnMut( |
181 | &O, |
182 | D, |
183 | S, |
184 | ) -> |
185 | , |
186 | > + Send |
187 | + Sync |
188 | + Clone, |
189 | O: GiteratedObject + Send + Sync, |
190 | D: + 'static, |
191 | : Send, | Failure
192 | S: Send + Sync + Clone + 'static, |
193 | |
194 | |
195 | operation_name |
196 | |
197 | |
198 | |
199 | object_name |
200 | |
201 | |
202 | async |
203 | &self, |
204 | object: &O, |
205 | operation: D, |
206 | state: S, |
207 | _operation_state: &StackOperationState, |
208 | |
209 | self.clone .await |
210 | |
211 | |
212 | |
213 | |
214 | |
215 | |
216 | F: FnMut( |
217 | &O, |
218 | D, |
219 | S, |
220 | O1, |
221 | ) -> |
222 | , |
223 | > + Send |
224 | + Sync |
225 | + Clone, |
226 | O: GiteratedObject + Send + Sync, |
227 | D: + 'static, |
228 | : Send, | Failure
229 | S: Send + Sync + Clone + 'static, |
230 | O1: FromOperationState, |
231 | |
232 | |
233 | operation_name |
234 | |
235 | |
236 | |
237 | object_name |
238 | |
239 | |
240 | async |
241 | &self, |
242 | object: &O, |
243 | operation: D, |
244 | state: S, |
245 | operation_state: &StackOperationState, |
246 | |
247 | let o1 = O1 from_state |
248 | .await |
249 | .map_err?; |
250 | self.clone .await |
251 | |
252 | |
253 | |
254 | |
255 | |
256 | |
257 | F: FnMut( |
258 | &O, |
259 | D, |
260 | S, |
261 | O1, |
262 | O2, |
263 | ) -> |
264 | , |
265 | > + Send |
266 | + Sync |
267 | + Clone, |
268 | O: GiteratedObject + Send + Sync, |
269 | D: + 'static, |
270 | : Send, | Failure
271 | S: Send + Sync + Clone + 'static, |
272 | O1: FromOperationState, |
273 | O2: FromOperationState, |
274 | |
275 | |
276 | operation_name |
277 | |
278 | |
279 | |
280 | object_name |
281 | |
282 | |
283 | async |
284 | &self, |
285 | object: &O, |
286 | operation: D, |
287 | state: S, |
288 | operation_state: &StackOperationState, |
289 | |
290 | let o1 = O1 from_state |
291 | .await |
292 | .map_err?; |
293 | let o2 = O2 from_state |
294 | .await |
295 | .map_err?; |
296 | self.clone .await |
297 | |
298 | |
299 | |
300 | |
301 | func: |
302 | dyn Fn( |
303 | AnyObject, |
304 | AnyOperation, |
305 | S, |
306 | StackOperationState, |
307 | ) |
308 | -> |
309 | + Send |
310 | + Sync, |
311 | >, |
312 | object_name: String, |
313 | |
314 | |
315 | |
316 | |
317 | A, |
318 | O: GiteratedObject + Send + Sync, |
319 | D: + 'static, |
320 | F: + Send + Sync + 'static + Clone, |
321 | > |
322 | handler: F, |
323 | |
324 | let handler = new; |
325 | Self |
326 | func: Box new |
327 | let handler = handler.clone; |
328 | async move |
329 | let handler = handler.clone; |
330 | let object: O = |
331 | map_err?; | from_object_str .
332 | let operation: D = from_value |
333 | .map_err?; |
334 | |
335 | let result = handler |
336 | .handle |
337 | .await; |
338 | result |
339 | .map |
340 | .map_err |
341 | => | Operation
342 | Operation |
343 | |
344 | => | Internal
345 | Internal |
346 | |
347 | => Unhandled, | Unhandled
348 | |
349 | |
350 | .boxed |
351 | , |
352 | object_name: object_name .to_string, |
353 | |
354 | |
355 | |
356 | async |
357 | &self, |
358 | object: AnyObject, |
359 | operation: AnyOperation, |
360 | state: S, |
361 | operation_state: &StackOperationState, |
362 | |
363 | .await |
364 | |
365 | |
366 | |
367 | |
368 | |
369 | type Error: Serialize + DeserializeOwned; |
370 | |
371 | async ; |
372 | |
373 | |
374 | |
375 | |
376 | type Error = ; |
377 | |
378 | async |
379 | Ok |
380 | |
381 | |
382 | |
383 | |
384 | |
385 | type Error = ; |
386 | |
387 | async |
388 | state: &StackOperationState, |
389 | |
390 | Ok |
391 | |
392 | |
393 | |
394 | |
395 | |
396 | pub giterated_backend: BackendWrapper, |
397 | pub instance: , |
398 | pub user: , |
399 | |
400 | |
401 | |
402 | ; |
403 | |
404 | |
405 | |
406 | AuthenticatedInstance |
407 | |
408 | |
409 | |
410 | |
411 | type Target = Instance; |
412 | |
413 | |
414 | &self.0 |
415 | |
416 | |
417 | |
418 | |
419 | ; |
420 | |
421 | |
422 | |
423 | AuthenticatedUser |
424 | |
425 | |
426 | |
427 | |
428 | type Target = User; |
429 | |
430 | |
431 | &self.0 |
432 | |
433 | |
434 | |
435 | |
436 | |
437 | sender: |
438 | , |
439 | WrappedOperation, |
440 | )>, |
441 | task: , |
442 | |
443 | |
444 | |
445 | object: AnyObject, |
446 | operation_payload: AnyOperation, |
447 | operation_name: String, |
448 | state: StackOperationState, |
449 | |
450 | |
451 | |
452 | |
453 | // Spawn listener task |
454 | |
455 | let = |
456 | , |
457 | WrappedOperation, |
458 | )>; |
459 | |
460 | let task = spawn |
461 | while let Some = recv.recv .await |
462 | let raw_result = backend |
463 | .object_operation |
464 | message.object, |
465 | &message.operation_name, |
466 | message.operation_payload, |
467 | &message.state, |
468 | |
469 | .await; |
470 | |
471 | responder.send .unwrap; |
472 | |
473 | error!; |
474 | ; |
475 | |
476 | Self |
477 | sender: send, |
478 | task: new, |
479 | |
480 | |
481 | |
482 | pub async |
483 | let = channel; |
484 | |
485 | self.sender |
486 | .send |
487 | .await |
488 | .map_err?; |
489 | |
490 | match response.await |
491 | Ok => Ok, |
492 | Err => Err, |
493 | |
494 | |
495 | |
496 | |
497 | use Debug; |
498 | |
499 | |
500 | |
501 | async |
502 | &self, |
503 | object: O, |
504 | operation: &str, |
505 | payload: D, |
506 | operation_state: &StackOperationState, |
507 | |
508 | |
509 | O: GiteratedObject + Debug, |
510 | D: + Debug, |
511 | |
512 | let operation = WrappedOperation |
513 | object: AnyObject, |
514 | operation_name: operation.to_string, |
515 | operation_payload: AnyOperation, |
516 | state: operation_state.clone, |
517 | ; |
518 | |
519 | let raw_result = self.call .await; |
520 | |
521 | match raw_result |
522 | Ok => Ok |
523 | .map_err?, |
524 | Err => match err |
525 | => | Internal
526 | warn! |
527 | "Internal Error: {:?}", |
528 | Internal |
529 | ; |
530 | |
531 | Err |
532 | |
533 | => Err, | Unhandled
534 | => Err | Operation
535 | from_value |
536 | .map_err?, |
537 | , |
538 | , |
539 | |
540 | |
541 | |
542 | async |
543 | &self, |
544 | object_str: &str, |
545 | operation_state: &StackOperationState, |
546 | |
547 | let operation = WrappedOperation |
548 | object: AnyObject, |
549 | operation_name: operation_name .to_string, |
550 | operation_payload: AnyOperation |
551 | unwrap, | to_value .
552 | , |
553 | state: operation_state.clone, |
554 | ; |
555 | |
556 | let raw_result = self.call .await; |
557 | |
558 | let object: ObjectResponse = match raw_result |
559 | Ok => Ok |
560 | .map_err?, |
561 | Err => match err |
562 | => | Internal
563 | warn! |
564 | "Internal Error: {:?}", |
565 | Internal |
566 | ; |
567 | |
568 | Err |
569 | |
570 | => Err, | Unhandled
571 | => Err | Operation
572 | from_value |
573 | .map_err?, |
574 | , |
575 | , |
576 | ?; |
577 | |
578 | unsafe |
579 | Ok |
580 | from_str |
581 | .map_err?, |
582 | self.clone, |
583 | |
584 | |
585 | |
586 | |
587 |