From 5e81b36149d66e95d2b0d000c3a605f5451edc28 Mon Sep 17 00:00:00 2001 From: David Kubek Date: Tue, 5 Dec 2023 14:37:34 +0100 Subject: [PATCH] Store dialog data (temporary to metadata) --- leapp/dialogs/dialog.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/leapp/dialogs/dialog.py b/leapp/dialogs/dialog.py index 3ead810a1..ca152c294 100644 --- a/leapp/dialogs/dialog.py +++ b/leapp/dialogs/dialog.py @@ -1,3 +1,28 @@ +import os +from leapp.utils.audit import Metadata + + +def _store_metadata(dialog, answer): + # Note(dkubek): Should an audit entry be created? One audit entry is + # created when store.get(...) is called + component_keys = ('key', 'label', 'description', 'default', 'value', 'reason') + dialog_keys = ('title', 'reason', 'scope') + metadata = dialog.serialize() + + metadata = { + 'components': [dict((key, component[key]) for key in component_keys) for component in metadata['components']], + **dict((key, metadata[key]) for key in dialog_keys), + 'answer': answer, + } + + md = Metadata(kind='dialog', + name=dialog.scope, + context=os.environ['LEAPP_EXECUTION_ID'], + hostname=os.environ['LEAPP_HOSTNAME'], + metadata=metadata) + md.store() + + class Dialog(object): """ The dialog class is used to declare the information passed to the user and retrieved from the user @@ -98,7 +123,11 @@ def get_answers(self, store): :return: Dictionary with answers once retrieved """ store.translate(self) - return store.get(self.scope, {}) + + answer = store.get(self.scope, {}) + _store_metadata(self, answer) + + return answer def request_answers(self, store, renderer): """ @@ -114,4 +143,8 @@ def request_answers(self, store, renderer): self._store = store renderer.render(self) self._store = None - return store.get(self.scope, {}) + + answer = store.get(self.scope, {}) + _store_metadata(self, answer) + + return answer