From ce6d11e41611f2bc439d5f0cc73505bd6784b371 Mon Sep 17 00:00:00 2001
From: Karel van Klink <karel.vanklink@geant.org>
Date: Tue, 16 Apr 2024 14:26:42 +0200
Subject: [PATCH] extend the LSO client with an interaction that does not
 include an input step

---
 gso/services/lso_client.py | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/gso/services/lso_client.py b/gso/services/lso_client.py
index 92898940..6bd5e9c0 100644
--- a/gso/services/lso_client.py
+++ b/gso/services/lso_client.py
@@ -134,10 +134,14 @@ def _show_results(state: State) -> FormGenerator:
         run_results: ReadOnlyField(json.dumps(state["callback_result"], indent=4), default_type=LongText)  # type: ignore[valid-type]
 
     yield ConfirmRunPage
-    [state.pop(key, None) for key in ["run_results", "lso_result_title", "lso_result_extra_label"]]
     return state
 
 
+@step("Clean up keys from state")
+def _clean_state() -> State:
+    return {"__remove_keys": ["run_results", "lso_result_title", "lso_result_extra_label", "callback_result"]}
+
+
 def lso_interaction(provisioning_step: Step) -> StepList:
     """Interact with the provisioning proxy :term:`LSO` using a callback step.
 
@@ -159,6 +163,7 @@ def lso_interaction(provisioning_step: Step) -> StepList:
         >> callback_step(name=provisioning_step.name, action_step=provisioning_step, validate_step=_evaluate_results)
         >> step("Inject result title")(lambda: {"lso_result_title": provisioning_step.name})
         >> _show_results
+        >> _clean_state
     )
 
 
@@ -183,4 +188,23 @@ def indifferent_lso_interaction(provisioning_step: Step) -> StepList:
         >> callback_step(name=provisioning_step.name, action_step=provisioning_step, validate_step=_ignore_results)
         >> step("Inject result title")(lambda: {"lso_result_title": provisioning_step.name})
         >> _show_results
+        >> _clean_state
+    )
+
+
+def anonymous_lso_interaction(provisioning_step: Step, validation_step: Step = _ignore_results) -> StepList:
+    """Interact with the provisioning proxy :term:`LSO` without any user input.
+
+    Going one step further than the indifferent :term:`LSO` interaction, is the anonymous interaction. Output is ignored
+    and no input step is created to display the results.
+    A custom validation step may be given as input. This validation step should look inside the ``callback_result`` key
+    in the current state.
+
+    :param Step provisioning_step: A workflow step to remotely provision a subscription.
+    :param Step validation_step: An optional validation step which defaults to a step that ignores the results.
+    """
+    return (
+        begin
+        >> callback_step(name=provisioning_step.name, action_step=provisioning_step, validate_step=validation_step)
+        >> _clean_state
     )
-- 
GitLab