示例#1
0
    def load_content(self, evidence, ignore_ttl=False, evidence_dt=None):
        """
        Populate the content of the evidence from the locker.

        :param evidence: an evidence object.
        :param ignore_ttl: Boolean for TTL validation.  Defaults to False.
        :param evidence_dt: The date of the evidence content to load.

        :returns: The evidence object with content.
        """
        self._validate_evidence(evidence, ignore_ttl)
        if getattr(evidence, 'is_partitioned', False):
            metadata = self.get_evidence_metadata(evidence.path, evidence_dt)
            content = None
            for part_hash in metadata['partitions'].keys():
                data = json.loads(
                    self._get_file_content(
                        f'{evidence.dir_path}/{part_hash}_{evidence.name}',
                        evidence_dt))
                if content is None:
                    content = data
                    root = content
                    if evidence.part_root:
                        root = parse_dot_key(root, evidence.part_root)
                    continue
                if evidence.part_root:
                    root.extend(parse_dot_key(data, evidence.part_root))
                else:
                    root.extend(data)
            evidence.set_content(format_json(content))
        else:
            evidence.set_content(
                self._get_file_content(evidence.path, evidence_dt))
        return evidence
 def _partition(self, data, key):
     idx = 0
     for field in self.part_fields:
         data = list(
             filter(lambda e: parse_dot_key(e, field) == key[idx], data))
         idx += 1
     return data
    def partition_keys(self):
        """
        All partition keys for this evidence object.

        Return all key values based on evidence content and the
        key fields provided during evidence instantiation.  Key values are
        relative to the root partition provided during evidence instantiation.

        :returns: A list of key values where the key values are lists as well.
        """
        if getattr(self, '_partition_keys', None) is None:
            keys = set()
            if self.part_root:
                root = parse_dot_key(json.loads(self._content), self.part_root)
            else:
                root = json.loads(self._content)
            for data in root:
                key_values = []
                for field in self.part_fields:
                    key_value = data
                    key_values.append(parse_dot_key(key_value, field))
                keys.add(tuple(key_values))
            self._partition_keys = [list(k) for k in keys]
        return self._partition_keys