Repository: google/turbinia

Issue:
get_task_data for celery stack is not supporting the user parameter
When requesting status or using the --wait parameter with turbiniactl on a local (redis/celery) stack the caller tries to call get_task_data with the user parameter. This is currently not implemented and throws an error.

Code flow:
* https://github.com/google/turbinia/blob/master/turbinia/turbiniactl.py#L704
* https://github.com/google/turbinia/blob/87d57dee532793be2b2b7b7b8b9165e3919f2d64/turbinia/client.py#L370
* https://github.com/google/turbinia/blob/87d57dee532793be2b2b7b7b8b9165e3919f2d64/turbinia/state_manager.py#L242

```
Traceback (most recent call last):
  File "/usr/local/bin/turbiniactl", line 33, in <module>
    sys.exit(load_entry_point('turbinia==20190819.4.dev224+gd8feb7a', 'console_scripts', 'turbiniactl')())
  File "/usr/local/lib/python3.6/dist-packages/turbinia-20190819.4.dev224+gd8feb7a-py3.6.egg/turbinia/turbiniactl.py", line 894, in main
    poll_interval=args.poll_interval)
  File "/usr/local/lib/python3.6/dist-packages/turbinia-20190819.4.dev224+gd8feb7a-py3.6.egg/turbinia/client.py", line 371, in wait_for_request
    instance, project, region, request_id=request_id, user=user)
TypeError: get_task_data() got an unexpected keyword argument 'user'
```


Discussion:

Resolving patch:
diff --git a/turbinia/client.py b/turbinia/client.py
--- a/turbinia/client.py
+++ b/turbinia/client.py
@@ -1106,7 +1106,7 @@ def send_request(self, request):
 
   # pylint: disable=arguments-differ
   def get_task_data(
-      self, instance, _, __, days=0, task_id=None, request_id=None,
+      self, instance, _, __, days=0, task_id=None, request_id=None, user=None,
       function_name=None, output_json=False):
     """Gets task data from Redis.
 
@@ -1118,11 +1118,12 @@ def get_task_data(
       days (int): The number of days we want history for.
       task_id (string): The Id of the task.
       request_id (string): The Id of the request we want tasks for.
+      user (string): The user of the request we want tasks for.
 
     Returns:
       List of Task dict objects.
     """
-    return self.redis.get_task_data(instance, days, task_id, request_id)
+    return self.redis.get_task_data(instance, days, task_id, request_id, user)
 
 
 class TurbiniaServer:
diff --git a/turbinia/state_manager.py b/turbinia/state_manager.py
--- a/turbinia/state_manager.py
+++ b/turbinia/state_manager.py
@@ -239,7 +239,8 @@ def __init__(self):
   def _validate_data(self, data):
     return data
 
-  def get_task_data(self, instance, days=0, task_id=None, request_id=None):
+  def get_task_data(
+      self, instance, days=0, task_id=None, request_id=None, user=None):
     """Gets task data from Redis.
 
     Args:
@@ -248,6 +249,7 @@ def get_task_data(self, instance, days=0, task_id=None, request_id=None):
       days (int): The number of days we want history for.
       task_id (string): The Id of the task.
       request_id (string): The Id of the request we want tasks for.
+      user (string): The user of the request we want tasks for.
 
     Returns:
       List of Task dict objects.
@@ -271,11 +273,14 @@ def get_task_data(self, instance, days=0, task_id=None, request_id=None):
     if days:
       start_time = datetime.now() - timedelta(days=days)
       # Redis only supports strings; we convert to/from datetime here and below
-      return [task for task in tasks if task.get('last_update') > start_time]
-    elif task_id:
-      return [task for task in tasks if task.get('task_id') == task_id]
-    elif request_id:
-      return [task for task in tasks if task.get('request_id') == request_id]
+      tasks = [task for task in tasks if task.get('last_update') > start_time]
+    if task_id:
+      tasks = [task for task in tasks if task.get('task_id') == task_id]
+    if request_id:
+      tasks = [task for task in tasks if task.get('request_id') == request_id]
+    if user:
+      tasks = [task for task in tasks if task.get('requester') == user]
+
     return tasks
 
   def update_task(self, task):


Test patch: