Module: Nucleus::Adapters::ArchiveConverter

Extended by:
Logging
Defined in:
lib/nucleus/core/file_handling/archive_converter.rb

Overview

The ArchiveConverter shall be used within the adapters to prepare application containers for deployment on the endpoint, by converting archives, e.g. from tar.gz to zip, to match the endpoint APIs requirements.

Class Method Summary collapse

Methods included from Logging

configure_logger_for, log, logger_for

Class Method Details

.convert(file, current_format, destination_format, sanitize = false) ⇒ StringIO

Convert an archived application, the file, from the current_format to the destination_format.

Parameters:

  • file (IO)

    archive file that shall be converted

  • current_format (String)

    represented by well-known file extensions, e.g. zip or tar.gz

  • destination_format (String)

    represented by well-known file extensions, e.g. zip or tar.gz

  • sanitize (Boolean) (defaults to: false)

    if true, the application will be sanitized, meaning if all data is in one folder it will be moved one level up so that the application data is not nested in another directory

Returns:

  • (StringIO)

    the data of the input file in a new archive matching the destination format



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/nucleus/core/file_handling/archive_converter.rb', line 15

def self.convert(file, current_format, destination_format, sanitize = false)
  extraction_dir = "#{Dir.tmpdir}/nucleus.app.convert.cf.deploy.#{SecureRandom.uuid}"
  ArchiveExtractor.new.extract(file, extraction_dir, current_format)

  # sanitize if desired
  ApplicationRepoSanitizer.new.sanitize(extraction_dir) if sanitize

  return Archiver.new.compress(extraction_dir, destination_format)
ensure
  # now delete the tmp directory again
  FileUtils.rm_rf(extraction_dir) if extraction_dir
end