def _GetMetadataForClients(self, client_urns):
        """Fetches metadata for a given list of clients."""

        result = {}
        metadata_to_fetch = set()

        for urn in client_urns:
            try:
                result[urn] = self._cached_metadata[urn]
            except KeyError:
                metadata_to_fetch.add(urn)

        if metadata_to_fetch:
            client_fds = aff4.FACTORY.MultiOpen(metadata_to_fetch,
                                                mode="r",
                                                token=self.token)

            fetched_metadata = [
                export.GetMetadata(client_fd, token=self.token)
                for client_fd in client_fds
            ]
            for metadata in fetched_metadata:
                metadata.source_urn = self.source_urn

                self._cached_metadata[metadata.client_urn] = metadata
                result[metadata.client_urn] = metadata
                metadata_to_fetch.remove(metadata.client_urn)

            for urn in metadata_to_fetch:
                default_mdata = export.ExportedMetadata(
                    source_urn=self.source_urn)
                result[urn] = default_mdata
                self._cached_metadata[urn] = default_mdata

        return [result[urn] for urn in client_urns]
示例#2
0
  def ProcessResponses(self, responses):
    default_metadata = export.ExportedMetadata(
        annotations=u",".join(self.args.export_options.annotations),
        source_urn=self.state.source_urn)

    if self.args.convert_values:
      # This is thread-safe - we just convert the values.
      converted_responses = export.ConvertValues(
          default_metadata,
          responses,
          token=self.token,
          options=self.args.export_options)
    else:
      converted_responses = responses

    # This is not thread-safe, therefore WriteValueToJSONFile is synchronized.
    self.WriteValuesToJSONFile(converted_responses)
示例#3
0
 def GetDefaultMetadata(self):
   """Returns metadata to be used by export converters."""
   return export.ExportedMetadata(source_urn=self.source_urn)