Skip to content

Commit

Permalink
Document Dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
dkubek committed Jan 31, 2024
1 parent c8b9fbb commit 132c0e3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
19 changes: 7 additions & 12 deletions leapp/actors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ def validate(cls, value):
return value in cls.ALLOWED_VALUES




class Actor(object):
"""
The Actor class represents the smallest step in the workflow. It defines what kind
Expand Down Expand Up @@ -146,7 +144,7 @@ def get_answers(self, dialog):
else:
answer = self._messaging.request_answers(dialog)

_store_dialog(dialog, answer)
_store_dialog_db(dialog, answer)

return answer

Expand Down Expand Up @@ -504,29 +502,26 @@ def get_actors():
return actors


def _store_dialog(dialog, answer):
# NOTE(dkubek): Should an audit entry be created? One audit entry is
# created when store.get(...) is called
def _store_dialog_db(dialog, answer):
component_keys = ('key', 'label', 'description', 'default', 'value', 'reason')
dialog_keys = ('title', 'reason', 'scope')

data = dialog.serialize()
data = {
'components': [dict((key, component[key]) for key in component_keys) for component in data['components']],
**dict((key, data[key]) for key in dialog_keys),
# NOTE(dkubek): Storing answer here is a bit redundant as it is already

# NOTE(dkubek): Storing answer here is redundant as it is already
# being stored in audit when we query from the answerstore, however,
# this keeps the information coupled with the question more closely
'answer':
answer
'answer': answer
}

md = DialogDB(
DialogDB(
scope=dialog.scope,
data=data,
context=os.environ['LEAPP_EXECUTION_ID'],
actor=os.environ['LEAPP_CURRENT_ACTOR'],
phase=os.environ['LEAPP_CURRENT_PHASE'],
hostname=os.environ['LEAPP_HOSTNAME'],
)
md.store()
).store()
3 changes: 3 additions & 0 deletions leapp/messaging/answerstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ def get(self, scope, fallback=None):
# NOTE(ivasilev) self.storage.get() will return a DictProxy. To avoid TypeError during later
# JSON serialization a copy() should be invoked to get a shallow copy of data
answer = self._storage.get(scope, fallback).copy()

# NOTE(dkubek): It is possible that we do not need to save the 'answer'
# here as it is being stored with dialog question right after query
create_audit_entry('dialog-answer', {'scope': scope, 'fallback': fallback, 'answer': answer})
return answer

Expand Down
9 changes: 6 additions & 3 deletions leapp/utils/audit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ def do_store(self, connection):


class Dialog(DataSource):
"""
Stores information about dialog questions and their answers
"""

def __init__(self, scope=None, data=None, actor=None, phase=None, hostname=None, context=None):
"""
Expand All @@ -320,12 +323,12 @@ def __init__(self, scope=None, data=None, actor=None, phase=None, hostname=None,
:type data: dict
:param actor: Name of the actor that triggered the entry
:type actor: str
:param phase: In which phase of the workflow execution the message was created
:param phase: In which phase of the workflow execution the dialog was triggered
:type phase: str
:param context: The execution context
:type context: str
:param hostname: Hostname of the system that produced the message
:type hostname: str
:param context: The execution context
:type context: str
"""
super(Dialog, self).__init__(actor=actor, phase=phase, hostname=hostname, context=context)
self.scope = scope or ''
Expand Down

0 comments on commit 132c0e3

Please sign in to comment.