Class: MachineConfigure::Exporter

Inherits:
Object
  • Object
show all
Includes:
Helpers::Message, Helpers::Shared
Defined in:
lib/machine_configure/exporter.rb

Overview

The Exporter is responsible for finding all necessary certificates for a given docker-machine, and bundle them all into a single zip archive.

Constant Summary

Constants included from Helpers::Message

Helpers::Message::MESSAGE_PADDING, Helpers::Message::STACK_TRACE_PADDING, Helpers::Message::STACK_TRACE_SIZE

Instance Method Summary collapse

Methods included from Helpers::Message

error_no_stack_trace!, error_yes_stack_trace!

Constructor Details

#initialize(name) ⇒ Exporter

Initialize with a docker-machine name.



10
11
12
13
14
15
16
17
18
19
# File 'lib/machine_configure/exporter.rb', line 10

def initialize name
  @machine_name = name
  VALIDATOR.validate_machine_name name
  @dir = {
    machine: DM_MACHINES_PATH.join(@machine_name),
    certs:   DM_CERTS_PATH.join(@machine_name)
  }
  VALIDATOR.validate_directories @dir[:machine]
  @contents = nil
end

Instance Method Details

#export_to(zip_file) ⇒ Object

Export certificates for the machine.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/machine_configure/exporter.rb', line 22

def export_to zip_file
  zip_file = Pathname.new "#{zip_file.to_s}#{zip_file.to_s.match(/\.zip\z/i) ? '' : '.zip'}"
  VALIDATOR.validate_zip_file_export zip_file
  files     = get_files
  @contents = get_contents_from_files(*files)
  config_json_path = get_config_json_path
  @contents[config_json_path] = remove_home_in @contents[config_json_path]
  @contents[MACHINE_NAME_FILENAME] = @machine_name
  write_zip_file_to zip_file
  message(
    "Successfully created zip archive",
    "  `#{zip_file.to_s}'",
    "with the keys and certificates from docker-machine",
    "  `#{@machine_name}'"
  )
end