Class: Heirloom::CLI::Upload

Inherits:
Object
  • Object
show all
Includes:
Shared
Defined in:
lib/heirloom/cli/upload.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Shared

#ensure_archive_domain_empty, #ensure_archive_exists, #ensure_buckets_available, #ensure_buckets_exist, #ensure_catalog_domain_exists, #ensure_directory_is_writable, #ensure_domain_exists, #ensure_entry_does_not_exist_in_catalog, #ensure_entry_exists_in_catalog, #ensure_metadata_in_upload_region, #ensure_path_is_directory, #ensure_valid_bucket_prefix, #ensure_valid_name, #ensure_valid_options, #ensure_valid_region, #ensure_valid_regions, #ensure_valid_secret, #latest_id, #load_config, #read_secret

Constructor Details

#initializeUpload

Returns a new instance of Upload.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/heirloom/cli/upload.rb', line 13

def initialize
  @opts = read_options
  @logger = HeirloomLogger.new :log_level => @opts[:level]
  @config = load_config :logger => @logger,
                        :opts   => @opts
  @catalog = Heirloom::Catalog.new :name    => @opts[:name],
                                   :config  => @config
  ensure_valid_options :provided => @opts,
                       :required => [:name, :id, :directory],
                       :config   => @config
  ensure_catalog_domain_exists :config  => @config,
                               :catalog => @catalog
  ensure_entry_exists_in_catalog :config  => @config,
                                 :catalog => @catalog,
                                 :entry   => @opts[:name]
  @archive = Archive.new :name   => @opts[:name],
                         :id     => @opts[:id],
                         :config => @config
  @regions = @catalog.regions
  @bucket_prefix = @catalog.bucket_prefix
end

Class Method Details

.command_summaryObject



9
10
11
# File 'lib/heirloom/cli/upload.rb', line 9

def self.command_summary
  'Upload a directory to Heirloom'
end

Instance Method Details

#uploadObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/heirloom/cli/upload.rb', line 35

def upload
  ensure_valid_region :region => @opts[:metadata_region],
                      :config => @config
  ensure_domain_exists :name   => @opts[:name],
                       :config => @config
  ensure_buckets_exist :bucket_prefix => @bucket_prefix,
                       :name          => @opts[:name],
                       :regions       => @regions,
                       :config        => @config
  ensure_path_is_directory :path   => @opts[:directory],
                           :config => @config

  secret = read_secret :opts   => @opts,
                       :config => @config
  ensure_valid_secret :secret => secret,
                      :config => @config

  @archive.destroy if @archive.exists?

  @file = Tempfile.new('archive.tar.gz')

  unless @archive.build :bucket_prefix => @bucket_prefix,
                        :directory     => @opts[:directory],
                        :exclude       => @opts[:exclude],
                        :file          => @file.path,
                        :secret        => secret

    @logger.error "Build failed."
    exit 1
  end

  @archive.upload :bucket_prefix   => @bucket_prefix,
                  :regions         => @regions,
                  :public_readable => @opts[:public],
                  :file            => @file.path,
                  :secret          => secret

  @file.close!
end