19
19
import secrets
20
20
from collections .abc import Callable
21
21
from dataclasses import asdict , dataclass
22
- from functools import update_wrapper
23
- from http import HTTPStatus
24
22
from itertools import dropwhile
25
23
from typing import (
26
24
Any ,
27
25
Generic ,
28
26
NoReturn ,
29
27
Protocol ,
30
- TypeAlias ,
31
28
TypeVar ,
32
29
cast ,
33
30
overload ,
42
39
43
40
from nwastdlib import const , identity
44
41
from oauth2_lib .fastapi import OIDCUserModel
45
- from orchestrator .api .error_handling import raise_status
46
42
from orchestrator .config .assignee import Assignee
47
43
from orchestrator .db import db , transactional
48
44
from orchestrator .services .settings import get_engine_settings
@@ -181,7 +177,7 @@ def __repr__(self) -> str:
181
177
182
178
183
179
def _handle_simple_input_form_generator (f : StateInputStepFunc ) -> StateInputFormGenerator :
184
- """Processes f into a form generator and injects a pre-hook for user authorization"""
180
+ """Processes f into a form generator and injects a pre-hook for user authorization. """
185
181
if inspect .isgeneratorfunction (f ):
186
182
return cast (StateInputFormGenerator , f )
187
183
if inspect .isgenerator (f ):
@@ -219,7 +215,9 @@ def wrapping_function() -> NoReturn:
219
215
wrapping_function .description = description
220
216
wrapping_function .authorize_callback = allow if authorize_callback is None else authorize_callback
221
217
# If no retry auth policy is given, defer to policy for process creation.
222
- wrapping_function .retry_auth_callback = wrapping_function .authorize_callback if retry_auth_callback is None else retry_auth_callback
218
+ wrapping_function .retry_auth_callback = (
219
+ wrapping_function .authorize_callback if retry_auth_callback is None else retry_auth_callback
220
+ )
223
221
224
222
if initial_input_form is None :
225
223
# We always need a form to prevent starting a workflow when no input is needed.
@@ -288,8 +286,15 @@ def wrapper(state: State) -> Process:
288
286
return decorator
289
287
290
288
291
- def inputstep (name : str , assignee : Assignee , resume_auth_callback : Authorizer | None = None , retry_auth_callback : Authorizer | None = None ) -> Callable [[InputStepFunc ], Step ]:
289
+ def inputstep (
290
+ name : str ,
291
+ assignee : Assignee ,
292
+ resume_auth_callback : Authorizer | None = None ,
293
+ retry_auth_callback : Authorizer | None = None
294
+ ) -> Callable [[InputStepFunc ], Step ]:
292
295
"""Add user input step to workflow.
296
+
297
+ Any authorization callbacks will be attached to the resulting Step.
293
298
294
299
IMPORTANT: In contrast to other workflow steps, the `@inputstep` wrapped function will not run in the
295
300
workflow engine! This means that it must be free of side effects!
@@ -317,7 +322,14 @@ def wrapper(state: State) -> FormGenerator:
317
322
def suspend (state : State ) -> Process :
318
323
return Suspend (state )
319
324
320
- return make_step_function (suspend , name , wrapper , assignee , resume_auth_callback = resume_auth_callback , retry_auth_callback = retry_auth_callback )
325
+ return make_step_function (
326
+ suspend ,
327
+ name ,
328
+ wrapper ,
329
+ assignee ,
330
+ resume_auth_callback = resume_auth_callback ,
331
+ retry_auth_callback = retry_auth_callback
332
+ )
321
333
322
334
return decorator
323
335
@@ -497,8 +509,8 @@ def workflow(
497
509
description : str ,
498
510
initial_input_form : InputStepFunc | None = None ,
499
511
target : Target = Target .SYSTEM ,
500
- authorize_callback : Authorizer | None = None ,
501
- retry_auth_callback : Authorizer | None = None ,
512
+ authorize_callback : Authorizer | None = None ,
513
+ retry_auth_callback : Authorizer | None = None ,
502
514
) -> Callable [[Callable [[], StepList ]], Workflow ]:
503
515
"""Transform an initial_input_form and a step list into a workflow.
504
516
@@ -519,7 +531,13 @@ def create_service_port():
519
531
520
532
def _workflow (f : Callable [[], StepList ]) -> Workflow :
521
533
return make_workflow (
522
- f , description , initial_input_form_in_form_inject_args , target , f (), authorize_callback = authorize_callback , retry_auth_callback = retry_auth_callback
534
+ f ,
535
+ description ,
536
+ initial_input_form_in_form_inject_args ,
537
+ target ,
538
+ f (),
539
+ authorize_callback = authorize_callback ,
540
+ retry_auth_callback = retry_auth_callback ,
523
541
)
524
542
525
543
return _workflow
0 commit comments