Example #1
0
    def evidence_process(self, evidence_uuid, pipeline):
        """Starts the evidence processing, using the selected pipeline.
        @param evidence_uuid: Evidence id
        @param pipeline: Pipeline identifier
        """
        # Check for valid storage_url, this must be set before
        # processing can begin.
        item = self._storage_driver.get("evidence", evidence_uuid)
        if "_storage_url" not in item:
            raise MissingKeyError("_storage_url")

        # Get the evidence container in the storage driver to
        # hold the processing information for this piece of evidence.
        container = self._storage_driver.create_container(evidence_uuid)

        # Create object in container that maps to the evidence
        obj = container.create()

        # Update evidence information
        item = self._storage_driver.update(
            "evidence",
            evidence_uuid,
            {
                "status": "processing",
                "process_start_date": timeutils.strtime(),
                "process_pipeline": pipeline,
                "_root_uuid": obj["uuid"],
            },
        )

        # Start the processing
        self._process_client.process_url(evidence_uuid, pipeline, obj, item["storage_url"])
Example #2
0
    def evidence_process(self, evidence_uuid, pipeline):
        """Starts the evidence processing, using the selected pipeline.
        @param evidence_uuid: Evidence id
        @param pipeline: Pipeline identifier
        """
        # Check for valid storage_url, this must be set before
        # processing can begin.
        item = self._storage_driver.get('evidence', evidence_uuid)
        if '_storage_url' not in item:
            raise MissingKeyError('_storage_url')

        # Get the evidence container in the storage driver to
        # hold the processing information for this piece of evidence.
        container = self._storage_driver.create_container(evidence_uuid)

        # Create object in container that maps to the evidence
        obj = container.create()

        # Update evidence information
        item = self._storage_driver.update('evidence', evidence_uuid, {
            'status': 'processing',
            'process_start_date': timeutils.strtime(),
            'process_pipeline': pipeline,
            '_root_uuid': obj['uuid']
        })

        # Start the processing
        self._process_client.process_url(evidence_uuid, pipeline, obj, item['storage_url'])
Example #3
0
 def case_create(self, *args, **kwargs):
     """Create a case.
     @param account_uuid: Account id
     @param **kwargs: Default key-value pairs
     @returns: Key-value pairs
     """
     if 'account_uuid' not in kwargs:
         raise MissingKeyError('account_uuid')
     kwargs['create_date'] = timeutils.strtime()
     kwargs['update_date'] = kwargs['create_date']
     return self._storage_driver.create('case', **kwargs)
Example #4
0
 def case_create(self, *args, **kwargs):
     """Create a case.
     @param account_uuid: Account id
     @param **kwargs: Default key-value pairs
     @returns: Key-value pairs
     """
     if "account_uuid" not in kwargs:
         raise MissingKeyError("account_uuid")
     kwargs["create_date"] = timeutils.strtime()
     kwargs["update_date"] = kwargs["create_date"]
     return self._storage_driver.create("case", **kwargs)
Example #5
0
    def case_update(self, *args, **kwargs):
        """Updates a case.
        @param case_uuid: Case id
        @param **kwargs: Key-value pairs to update
        @returns: Key-value pairs
        """
        if 'case_uuid' not in kwargs:
            raise MissingKeyError('case_uuid')
        if 'account_uuid' in kwargs:
            del kwargs['account_uuid']
        uuid = kwargs['case_uuid']
        del kwargs['case_uuid']

        kwargs['update_date'] = timeutils.strtime()
        return self._storage_driver.update('case', uuid, **kwargs)
Example #6
0
    def case_update(self, *args, **kwargs):
        """Updates a case.
        @param case_uuid: Case id
        @param **kwargs: Key-value pairs to update
        @returns: Key-value pairs
        """
        if "case_uuid" not in kwargs:
            raise MissingKeyError("case_uuid")
        if "account_uuid" in kwargs:
            del kwargs["account_uuid"]
        uuid = kwargs["case_uuid"]
        del kwargs["case_uuid"]

        kwargs["update_date"] = timeutils.strtime()
        return self._storage_driver.update("case", uuid, **kwargs)
Example #7
0
    def evidence_add(self, *args, **kwargs):
        """Adds evidence to case.
        @param case_uuid: Case id
        @param container_format: Format of container
        @param container_size: Total size of container
        @param **kwargs: Default key-value pairs
        @returns: Key-value pairs
        """
        if 'case_uuid' not in kwargs:
            raise MissingKeyError('case_uuid')
        if 'container_format' not in kwargs:
            raise MissingKeyError('container_format')
        if 'container_size' not in kwargs:
            raise MissingKeyError('container_size')

        kwargs['status'] = 'created'
        kwargs['create_date'] = timeutils.strtime()
        kwargs['update_date'] = kwargs['create_date']
        return self._storage_driver.create('evidence', **kwargs)
Example #8
0
    def evidence_add(self, *args, **kwargs):
        """Adds evidence to case.
        @param case_uuid: Case id
        @param container_format: Format of container
        @param container_size: Total size of container
        @param **kwargs: Default key-value pairs
        @returns: Key-value pairs
        """
        if "case_uuid" not in kwargs:
            raise MissingKeyError("case_uuid")
        if "container_format" not in kwargs:
            raise MissingKeyError("container_format")
        if "container_size" not in kwargs:
            raise MissingKeyError("container_size")

        kwargs["status"] = "created"
        kwargs["create_date"] = timeutils.strtime()
        kwargs["update_date"] = kwargs["create_date"]
        return self._storage_driver.create("evidence", **kwargs)
Example #9
0
    def evidence_update(self, *args, **kwargs):
        """Updates evidence.
        @param evidence_uuid: Evidence id
        @param **kwargs: Key-value pairs to update
        @returns: Key-value pairs
        """
        if 'evidence_uuid' not in kwargs:
            raise MissingKeyError('evidence_uuid')
        if 'case_uuid' in kwargs:
            del kwargs['case_uuid']
        if 'container_format' in kwargs and not kwargs['container_format']:
            raise MissingKeyError('container_format')
        if 'container_size' in kwargs and not kwargs['container_size']:
            raise MissingKeyError('container_size')

        uuid = kwargs['evidence_uuid']
        del kwargs['evidence_uuid']
       
        kwargs['update_date'] = timeutils.strtime()
        item = self._storage_driver.update('evidence', uuid, **kwargs)

        return item
Example #10
0
    def evidence_update(self, *args, **kwargs):
        """Updates evidence.
        @param evidence_uuid: Evidence id
        @param **kwargs: Key-value pairs to update
        @returns: Key-value pairs
        """
        if "evidence_uuid" not in kwargs:
            raise MissingKeyError("evidence_uuid")
        if "case_uuid" in kwargs:
            del kwargs["case_uuid"]
        if "container_format" in kwargs and not kwargs["container_format"]:
            raise MissingKeyError("container_format")
        if "container_size" in kwargs and not kwargs["container_size"]:
            raise MissingKeyError("container_size")

        uuid = kwargs["evidence_uuid"]
        del kwargs["evidence_uuid"]

        kwargs["update_date"] = timeutils.strtime()
        item = self._storage_driver.update("evidence", uuid, **kwargs)

        return item
Example #11
0
def to_primitive(value, convert_instances=False, convert_datetime=True,
                 level=0, max_depth=3):
    """Convert a complex object into primitives.

    Handy for JSON serialization. We can optionally handle instances,
    but since this is a recursive function, we could have cyclical
    data structures.

    To handle cyclical data structures we could track the actual objects
    visited in a set, but not all objects are hashable. Instead we just
    track the depth of the object inspections and don't go too deep.

    Therefore, convert_instances=True is lossy ... be aware.

    """
    # handle obvious types first - order of basic types determined by running
    # full tests on nova project, resulting in the following counts:
    # 572754 <type 'NoneType'>
    # 460353 <type 'int'>
    # 379632 <type 'unicode'>
    # 274610 <type 'str'>
    # 199918 <type 'dict'>
    # 114200 <type 'datetime.datetime'>
    #  51817 <type 'bool'>
    #  26164 <type 'list'>
    #   6491 <type 'float'>
    #    283 <type 'tuple'>
    #     19 <type 'long'>
    if isinstance(value, _simple_types):
        return value

    if isinstance(value, datetime.datetime):
        if convert_datetime:
            return timeutils.strtime(value)
        else:
            return value

    # value of itertools.count doesn't get caught by nasty_type_tests
    # and results in infinite loop when list(value) is called.
    if type(value) == itertools.count:
        return six.text_type(value)

    # FIXME(vish): Workaround for LP bug 852095. Without this workaround,
    #              tests that raise an exception in a mocked method that
    #              has a @wrap_exception with a notifier will fail. If
    #              we up the dependency to 0.5.4 (when it is released) we
    #              can remove this workaround.
    if getattr(value, '__module__', None) == 'mox':
        return 'mock'

    if level > max_depth:
        return '?'

    # The try block may not be necessary after the class check above,
    # but just in case ...
    try:
        recursive = functools.partial(to_primitive,
                                      convert_instances=convert_instances,
                                      convert_datetime=convert_datetime,
                                      level=level,
                                      max_depth=max_depth)
        if isinstance(value, dict):
            return dict((k, recursive(v)) for k, v in value.iteritems())
        elif isinstance(value, (list, tuple)):
            return [recursive(lv) for lv in value]

        # It's not clear why xmlrpclib created their own DateTime type, but
        # for our purposes, make it a datetime type which is explicitly
        # handled
        if isinstance(value, xmlrpclib.DateTime):
            value = datetime.datetime(*tuple(value.timetuple())[:6])

        if convert_datetime and isinstance(value, datetime.datetime):
            return timeutils.strtime(value)
        elif hasattr(value, 'iteritems'):
            return recursive(dict(value.iteritems()), level=level + 1)
        elif hasattr(value, '__iter__'):
            return recursive(list(value))
        elif convert_instances and hasattr(value, '__dict__'):
            # Likely an instance of something. Watch for cycles.
            # Ignore class member vars.
            return recursive(value.__dict__, level=level + 1)
        elif isinstance(value, netaddr.IPAddress):
            return six.text_type(value)
        else:
            if any(test(value) for test in _nasty_type_tests):
                return six.text_type(value)
            return value
    except TypeError:
        # Class objects are tricky since they may define something like
        # __iter__ defined but it isn't callable as list().
        return six.text_type(value)