Skip to content

Commit

Permalink
Store dialog data (temporary to metadata)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkubek committed Dec 5, 2023
1 parent aeb5e34 commit 5e81b36
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions leapp/dialogs/dialog.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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

0 comments on commit 5e81b36

Please sign in to comment.