Exemple #1
0
  def Handle(self, args, token=None):
    flow_api_object, flow_results = self._GetFlow(args, token)

    description = ("Files downloaded by flow %s (%s) that ran on client %s by "
                   "user %s on %s" %
                   (flow_api_object.name, args.flow_id, args.client_id,
                    flow_api_object.creator, flow_api_object.started_at))

    target_file_prefix = "%s_flow_%s_%s" % (
        args.client_id, flow_api_object.name, str(
            flow_api_object.flow_id).replace(":", "_"))

    if args.archive_format == args.ArchiveFormat.ZIP:
      archive_format = archive_generator.CollectionArchiveGenerator.ZIP
      file_extension = ".zip"
    elif args.archive_format == args.ArchiveFormat.TAR_GZ:
      archive_format = archive_generator.CollectionArchiveGenerator.TAR_GZ
      file_extension = ".tar.gz"
    else:
      raise ValueError("Unknown archive format: %s" % args.archive_format)

    generator = archive_generator.CollectionArchiveGenerator(
        prefix=target_file_prefix,
        description=description,
        archive_format=archive_format,
        predicate=self._BuildPredicate(str(args.client_id), token=token),
        client_id=args.client_id.ToString())
    content_generator = self._WrapContentGenerator(
        generator, flow_results, args, token=token)
    return api_call_handler_base.ApiBinaryStream(
        target_file_prefix + file_extension,
        content_generator=content_generator)
Exemple #2
0
  def Handle(self, args, context=None):
    flow_object, flow_results = self._GetFlow(args, context)
    flow_api_object = ApiFlow().InitFromFlowObject(flow_object)
    flow_instance = flow_base.FlowBase.CreateFlowInstance(flow_object)
    try:
      mappings = flow_instance.GetFilesArchiveMappings(flow_results)
    except NotImplementedError:
      mappings = None

    description = ("Files downloaded by flow %s (%s) that ran on client %s by "
                   "user %s on %s" %
                   (flow_api_object.name, args.flow_id, args.client_id,
                    flow_api_object.creator, flow_api_object.started_at))

    target_file_prefix = "%s_flow_%s_%s" % (
        args.client_id, flow_api_object.name, str(
            flow_api_object.flow_id).replace(":", "_"))

    if args.archive_format == args.ArchiveFormat.ZIP:
      archive_format = archive_generator.CollectionArchiveGenerator.ZIP
      file_extension = ".zip"
    elif args.archive_format == args.ArchiveFormat.TAR_GZ:
      archive_format = archive_generator.CollectionArchiveGenerator.TAR_GZ
      file_extension = ".tar.gz"
    else:
      raise ValueError("Unknown archive format: %s" % args.archive_format)

    # Only use the new-style flow archive generator for the flows that
    # have the GetFilesArchiveMappings defined.
    if mappings:
      a_gen = archive_generator.FlowArchiveGenerator(flow_object,
                                                     archive_format)
      content_generator = self._WrapContentGeneratorWithMappings(
          a_gen, mappings, args, context=context)
    else:
      a_gen = archive_generator.CollectionArchiveGenerator(
          prefix=target_file_prefix,
          description=description,
          archive_format=archive_format,
          predicate=self._BuildPredicate(str(args.client_id), context=context),
          client_id=args.client_id.ToString())
      content_generator = self._WrapContentGenerator(
          a_gen, flow_results, args, context=context)

    return api_call_handler_base.ApiBinaryStream(
        target_file_prefix + file_extension,
        content_generator=content_generator)
Exemple #3
0
    def _GenerateArchive(
            self,
            collection,
            archive_format=archive_generator.CollectionArchiveGenerator.ZIP,
            predicate=None):

        fd_path = os.path.join(self.temp_dir, "archive")
        generator = archive_generator.CollectionArchiveGenerator(
            archive_format=archive_format,
            predicate=predicate,
            prefix="test_prefix",
            description="Test description",
            client_id=self.client_id)
        with open(fd_path, "wb") as out_fd:
            for chunk in generator.Generate(collection):
                out_fd.write(chunk)

        return fd_path
Exemple #4
0
  def Handle(self, args, context=None):
    collection, description = self._LoadData(args, context=context)
    target_file_prefix = "hunt_" + str(args.hunt_id).replace(":", "_")

    if args.archive_format == args.ArchiveFormat.ZIP:
      archive_format = archive_generator.CollectionArchiveGenerator.ZIP
      file_extension = ".zip"
    elif args.archive_format == args.ArchiveFormat.TAR_GZ:
      archive_format = archive_generator.CollectionArchiveGenerator.TAR_GZ
      file_extension = ".tar.gz"
    else:
      raise ValueError("Unknown archive format: %s" % args.archive_format)

    generator = archive_generator.CollectionArchiveGenerator(
        prefix=target_file_prefix,
        description=description,
        archive_format=archive_format)
    content_generator = self._WrapContentGenerator(
        generator, collection, args, context=context)
    return api_call_handler_base.ApiBinaryStream(
        target_file_prefix + file_extension,
        content_generator=content_generator)