def close_tasks(self, instance, project, region, request_id=None, task_id=None, user=None, requester=None): """Close Turbinia Tasks based on Request ID. Args: instance (string): The Turbinia instance name (by default the same as the INSTANCE_ID in the config). project (string): The name of the project. region (string): The name of the zone to execute in. request_id (string): The Id of the request we want tasks for. task_id (string): The Id of the request we want task for. user (string): The user of the request we want tasks for. requester (string): The user making the request to close tasks. Returns: String of closed Task IDs. """ cloud_function = GoogleCloudFunction(project_id=project, region=region) func_args = { 'instance': instance, 'kind': 'TurbiniaTask', 'request_id': request_id, 'task_id': task_id, 'user': user, 'requester': requester } response = cloud_function.ExecuteFunction('closetasks', func_args) return 'Closed Task IDs: %s' % response.get('result')
def get_task_data(self, instance, project, region, days=0, task_id=None, request_id=None, user=None, function_name='gettasks'): """Gets task data from Google Cloud Functions. Args: instance (string): The Turbinia instance name (by default the same as the INSTANCE_ID in the config). project (string): The name of the project. region (string): The name of the region to execute in. 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. function_name (string): The GCF function we want to call Returns: List of Task dict objects. """ cloud_function = GoogleCloudFunction(project_id=project, region=region) func_args = {'instance': instance, 'kind': 'TurbiniaTask'} if days: start_time = datetime.now() - timedelta(days=days) # Format this like '1990-01-01T00:00:00z' so we can cast it directly to a # javascript Date() object in the cloud function. start_string = start_time.strftime('%Y-%m-%dT%H:%M:%S') func_args.update({'start_time': start_string}) elif task_id: func_args.update({'task_id': task_id}) elif request_id: func_args.update({'request_id': request_id}) if user: func_args.update({'user': user}) response = cloud_function.ExecuteFunction(function_name, func_args) if 'result' not in response: log.error('No results found') if response.get('error', '{}') != '{}': msg = 'Error executing Cloud Function: [{0!s}].'.format( response.get('error')) log.error(msg) log.debug('GCF response: {0!s}'.format(response)) raise TurbiniaException( 'Cloud Function {0:s} returned no results.'.format(function_name)) try: results = json.loads(response['result']) except (TypeError, ValueError) as e: raise TurbiniaException( 'Could not deserialize result from GCF: [{0!s}]'.format(e)) return results[0]