heirloom 0.7.4 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/CHANGELOG +18 -0
  2. data/lib/heirloom/archive/builder.rb +13 -13
  3. data/lib/heirloom/archive/downloader.rb +8 -8
  4. data/lib/heirloom/archive/writer.rb +4 -4
  5. data/lib/heirloom/catalog.rb +2 -2
  6. data/lib/heirloom/catalog/add.rb +4 -3
  7. data/lib/heirloom/catalog/show.rb +2 -2
  8. data/lib/heirloom/cipher/data.rb +3 -3
  9. data/lib/heirloom/cli.rb +1 -0
  10. data/lib/heirloom/cli/catalog.rb +6 -3
  11. data/lib/heirloom/cli/download.rb +9 -9
  12. data/lib/heirloom/cli/formatter.rb +2 -0
  13. data/lib/heirloom/cli/formatter/catalog.rb +42 -0
  14. data/lib/heirloom/cli/formatter/show.rb +55 -0
  15. data/lib/heirloom/cli/list.rb +8 -2
  16. data/lib/heirloom/cli/setup.rb +15 -17
  17. data/lib/heirloom/cli/shared.rb +20 -7
  18. data/lib/heirloom/cli/show.rb +10 -1
  19. data/lib/heirloom/cli/teardown.rb +2 -2
  20. data/lib/heirloom/cli/upload.rb +11 -11
  21. data/lib/heirloom/version.rb +1 -1
  22. data/spec/archive/downloader_spec.rb +15 -15
  23. data/spec/archive/setup_spec.rb +6 -6
  24. data/spec/archive/teardowner_spec.rb +3 -3
  25. data/spec/archive/writer_spec.rb +1 -1
  26. data/spec/catalog/add_spec.rb +8 -7
  27. data/spec/catalog/show_spec.rb +6 -4
  28. data/spec/catalog_spec.rb +12 -12
  29. data/spec/cipher/data_spec.rb +1 -1
  30. data/spec/cli/catalog_spec.rb +46 -15
  31. data/spec/cli/download_spec.rb +13 -13
  32. data/spec/cli/formatter/catalog_spec.rb +39 -0
  33. data/spec/cli/formatter/show_spec.rb +29 -0
  34. data/spec/cli/list_spec.rb +31 -11
  35. data/spec/cli/setup_spec.rb +5 -4
  36. data/spec/cli/shared_spec.rb +9 -1
  37. data/spec/cli/show_spec.rb +45 -12
  38. data/spec/cli/teardown_spec.rb +2 -1
  39. data/spec/cli/upload_spec.rb +12 -12
  40. metadata +19 -12
@@ -93,18 +93,18 @@ module Heirloom
93
93
  end
94
94
 
95
95
  def ensure_buckets_exist(args)
96
- config = args[:config]
97
- base = args[:base]
98
- name = args[:name]
99
- regions = args[:regions]
100
- logger = config.logger
96
+ config = args[:config]
97
+ bucket_prefix = args[:bucket_prefix]
98
+ name = args[:name]
99
+ regions = args[:regions]
100
+ logger = config.logger
101
101
 
102
102
  archive = Archive.new :name => name,
103
103
  :config => config
104
104
 
105
105
  unless archive.buckets_exist? :regions => regions,
106
- :bucket_prefix => base
107
- logger.error "Required buckets for '#{base}' do not exist."
106
+ :bucket_prefix => bucket_prefix
107
+ logger.error "Required buckets for '#{bucket_prefix}' do not exist."
108
108
  exit 1
109
109
  end
110
110
  end
@@ -170,6 +170,19 @@ module Heirloom
170
170
  end
171
171
  end
172
172
 
173
+ def ensure_entry_does_not_exist_in_catalog(args)
174
+ config = args[:config]
175
+ catalog = args[:catalog]
176
+ entry = args[:entry]
177
+ logger = config.logger
178
+ region = config.metadata_region
179
+
180
+ if catalog.entry_exists_in_catalog? entry
181
+ logger.error "Entry for #{entry} exists in #{region} catalog."
182
+ exit 1
183
+ end
184
+ end
185
+
173
186
  def latest_id(args)
174
187
  archive = Archive.new :name => args[:name],
175
188
  :config => args[:config]
@@ -30,7 +30,14 @@ module Heirloom
30
30
  end
31
31
 
32
32
  def show
33
- jj @archive.show
33
+ data = @archive.show
34
+ if @opts[:json]
35
+ jj data
36
+ else
37
+ formatter = Heirloom::CLI::Formatter::Show.new
38
+ puts formatter.format :attributes => data,
39
+ :all => @opts[:all]
40
+ end
34
41
  end
35
42
 
36
43
  private
@@ -50,7 +57,9 @@ If -i is ommited, latest ID is displayed.
50
57
 
51
58
  EOS
52
59
  opt :help, "Display Help"
60
+ opt :all, "Display all attributes (includes internal heirloom settings)."
53
61
  opt :id, "ID of the Heirloom to display.", :type => :string
62
+ opt :json, "Display output as raw JSON."
54
63
  opt :level, "Log level [debug|info|warn|error].", :type => :string,
55
64
  :default => 'info'
56
65
  opt :metadata_region, "AWS region to store Heirloom metadata.", :type => :string,
@@ -34,11 +34,11 @@ module Heirloom
34
34
  :config => @config
35
35
 
36
36
  @regions = @catalog.regions
37
- @base = @catalog.base
37
+ @bucket_prefix = @catalog.bucket_prefix
38
38
 
39
39
  unless @opts[:keep_buckets]
40
40
  @archive.delete_buckets :regions => @regions,
41
- :bucket_prefix => @base
41
+ :bucket_prefix => @bucket_prefix
42
42
  end
43
43
 
44
44
  @archive.delete_domain
@@ -23,7 +23,7 @@ module Heirloom
23
23
  :id => @opts[:id],
24
24
  :config => @config
25
25
  @regions = @catalog.regions
26
- @base = @catalog.base
26
+ @bucket_prefix = @catalog.bucket_prefix
27
27
  end
28
28
 
29
29
  def upload
@@ -31,10 +31,10 @@ module Heirloom
31
31
  :config => @config
32
32
  ensure_domain_exists :name => @opts[:name],
33
33
  :config => @config
34
- ensure_buckets_exist :base => @base,
35
- :name => @opts[:name],
36
- :regions => @regions,
37
- :config => @config
34
+ ensure_buckets_exist :bucket_prefix => @bucket_prefix,
35
+ :name => @opts[:name],
36
+ :regions => @regions,
37
+ :config => @config
38
38
  ensure_directory :path => @opts[:directory],
39
39
  :config => @config
40
40
 
@@ -45,18 +45,18 @@ module Heirloom
45
45
 
46
46
  @archive.destroy if @archive.exists?
47
47
 
48
- build = @archive.build :base => @base,
49
- :directory => @opts[:directory],
50
- :exclude => @opts[:exclude],
51
- :git => @opts[:git],
52
- :secret => secret
48
+ build = @archive.build :bucket_prefix => @bucket_prefix,
49
+ :directory => @opts[:directory],
50
+ :exclude => @opts[:exclude],
51
+ :git => @opts[:git],
52
+ :secret => secret
53
53
 
54
54
  unless build
55
55
  @logger.error "Build failed."
56
56
  exit 1
57
57
  end
58
58
 
59
- @archive.upload :bucket_prefix => @base,
59
+ @archive.upload :bucket_prefix => @bucket_prefix,
60
60
  :regions => @regions,
61
61
  :public_readable => @opts[:public],
62
62
  :file => build
@@ -1,3 +1,3 @@
1
1
  module Heirloom
2
- VERSION = "0.7.4"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -42,10 +42,10 @@ describe Heirloom do
42
42
  :file => "123.tar.gz",
43
43
  :output => './',
44
44
  :extract => false).and_return true
45
- @downloader.download(:region => 'us-west-1',
46
- :base_prefix => 'bucket',
47
- :extract => false,
48
- :secret => nil).should == './'
45
+ @downloader.download(:region => 'us-west-1',
46
+ :bucket_prefix => 'bucket',
47
+ :extract => false,
48
+ :secret => nil).should == './'
49
49
  end
50
50
 
51
51
  it "should download arhcive to specified output" do
@@ -54,11 +54,11 @@ describe Heirloom do
54
54
  :file => "123.tar.gz",
55
55
  :output => '/tmp/dir',
56
56
  :extract => false).and_return true
57
- @downloader.download(:output => '/tmp/dir',
58
- :region => 'us-west-1',
59
- :base_prefix => 'bucket',
60
- :extract => false,
61
- :secret => nil).should == '/tmp/dir'
57
+ @downloader.download(:output => '/tmp/dir',
58
+ :region => 'us-west-1',
59
+ :bucket_prefix => 'bucket',
60
+ :extract => false,
61
+ :secret => nil).should == '/tmp/dir'
62
62
  end
63
63
  end
64
64
 
@@ -87,10 +87,10 @@ describe Heirloom do
87
87
  :file => "123.tar.gz",
88
88
  :output => './',
89
89
  :extract => false).and_return true
90
- @downloader.download :region => 'us-west-1',
91
- :base_prefix => 'bucket',
92
- :extract => false,
93
- :secret => 'supersecret'
90
+ @downloader.download :region => 'us-west-1',
91
+ :bucket_prefix => 'bucket',
92
+ :extract => false,
93
+ :secret => 'supersecret'
94
94
  end
95
95
 
96
96
  it "should decrypt and extract the downloaded file with secret" do
@@ -100,7 +100,7 @@ describe Heirloom do
100
100
  :output => './',
101
101
  :extract => true).and_return true
102
102
  @downloader.download :region => 'us-west-1',
103
- :base_prefix => 'bucket',
103
+ :bucket_prefix => 'bucket',
104
104
  :extract => true,
105
105
  :secret => 'supersecret'
106
106
  end
@@ -115,7 +115,7 @@ describe Heirloom do
115
115
 
116
116
  it "should return false if the decrypt_data returns false" do
117
117
  @downloader.download(:region => 'us-west-1',
118
- :base_prefix => 'bucket',
118
+ :bucket_prefix => 'bucket',
119
119
  :extract => false,
120
120
  :secret => 'badsecret').should be_false
121
121
  end
@@ -28,14 +28,14 @@ describe Heirloom do
28
28
  @verifier_mock.stub :domain_exists? => false
29
29
  @sdb_mock.should_receive(:create_domain).with 'heirloom_archive'
30
30
  @setuper.setup :regions => ['us-west-1'],
31
- :bucket_prefix => 'base'
31
+ :bucket_prefix => 'bp'
32
32
 
33
33
  end
34
34
 
35
35
  it "should not create the domain if alrady exists" do
36
36
  @verifier_mock.stub :domain_exists? => true
37
37
  @setuper.setup :regions => ['us-west-1'],
38
- :bucket_prefix => 'base'
38
+ :bucket_prefix => 'bp'
39
39
  end
40
40
  end
41
41
 
@@ -46,10 +46,10 @@ describe Heirloom do
46
46
 
47
47
  it "should create required buckets that don't exist" do
48
48
  @verifier_mock.should_receive(:bucket_exists?).
49
- with(:region => "us-west-1", :bucket_prefix => "base").
49
+ with(:region => "us-west-1", :bucket_prefix => "bp").
50
50
  and_return true
51
51
  @verifier_mock.should_receive(:bucket_exists?).
52
- with(:region => "us-east-1", :bucket_prefix => "base").
52
+ with(:region => "us-east-1", :bucket_prefix => "bp").
53
53
  and_return false
54
54
  @s3_mock = mock 's3'
55
55
  Heirloom::AWS::S3.should_receive(:new).
@@ -57,9 +57,9 @@ describe Heirloom do
57
57
  :region => 'us-east-1').
58
58
  and_return @s3_mock
59
59
  @s3_mock.should_receive(:put_bucket).
60
- with 'base-us-east-1', 'us-east-1'
60
+ with 'bp-us-east-1', 'us-east-1'
61
61
  @setuper.setup :regions => ['us-west-1', 'us-east-1'],
62
- :bucket_prefix => 'base'
62
+ :bucket_prefix => 'bp'
63
63
  end
64
64
  end
65
65
 
@@ -24,10 +24,10 @@ describe Heirloom::Teardowner do
24
24
  with(:config => @config_stub,
25
25
  :region => 'us-west-2').
26
26
  and_return @s3_mock2
27
- @s3_mock1.should_receive(:delete_bucket).with('base-us-west-1')
28
- @s3_mock2.should_receive(:delete_bucket).with('base-us-west-2')
27
+ @s3_mock1.should_receive(:delete_bucket).with('bp-us-west-1')
28
+ @s3_mock2.should_receive(:delete_bucket).with('bp-us-west-2')
29
29
  @teardowner.delete_buckets :regions => @regions,
30
- :bucket_prefix => 'base'
30
+ :bucket_prefix => 'bp'
31
31
  end
32
32
 
33
33
  it "should delete the domain" do
@@ -29,7 +29,7 @@ describe Heirloom do
29
29
  Heirloom::Writer.any_instance.should_receive(:`).
30
30
  with('tar xzf /tmp/tempfile -C /output')
31
31
  $?.stub :success? => false
32
- @logger_mock.should_receive(:error).with "Error extracting archive."
32
+ @logger_mock.should_receive(:error)
33
33
  @writer.save_archive(:archive => 'archive_data',
34
34
  :output => '/output',
35
35
  :file => 'id.tar.gz',
@@ -3,10 +3,11 @@ require 'spec_helper'
3
3
  describe Heirloom::Catalog::Add do
4
4
 
5
5
  before do
6
- @regions = ['us-west-1', 'us-west-2']
7
- @base = 'base'
8
- @logger_stub = stub 'logger', :info => true
9
- @config_stub = stub 'config', :logger => @logger_stub
6
+ @regions = ['us-west-1', 'us-west-2']
7
+ @bucket_prefix = 'bucket_prefix'
8
+ @logger_stub = stub 'logger', :info => true
9
+ @config_stub = stub 'config', :logger => @logger_stub
10
+
10
11
  @add = Heirloom::Catalog::Add.new :config => @config_stub,
11
12
  :name => 'new_archive'
12
13
  end
@@ -19,9 +20,9 @@ describe Heirloom::Catalog::Add do
19
20
  @sdb_mock.should_receive(:put_attributes).
20
21
  with 'heirloom',
21
22
  'heirloom_new_archive',
22
- "regions" => @regions, "base" => @base
23
- @add.add_to_catalog :regions => @regions,
24
- :base => @base
23
+ "regions" => @regions, "bucket_prefix" => @bucket_prefix
24
+ @add.add_to_catalog :regions => @regions,
25
+ :bucket_prefix => @bucket_prefix
25
26
  end
26
27
 
27
28
  end
@@ -12,12 +12,14 @@ describe Heirloom::Catalog::Show do
12
12
  :name => 'a_archive'
13
13
  end
14
14
 
15
- it "should return the base" do
16
- result = { 'heirloom_a_archive' => { 'base' => [ 'thebase' ] } }
15
+ it "should return the bucket_prefix" do
16
+ result = { 'heirloom_a_archive' =>
17
+ { 'bucket_prefix' => [ 'bp' ] }
18
+ }
17
19
  @sdb_mock.should_receive(:select).
18
- with("select base from heirloom where itemName() = 'heirloom_a_archive'").
20
+ with("select bucket_prefix from heirloom where itemName() = 'heirloom_a_archive'").
19
21
  and_return result
20
- @show.base.should == 'thebase'
22
+ @show.bucket_prefix.should == 'bp'
21
23
  end
22
24
 
23
25
  it "should return the regions" do
@@ -3,10 +3,10 @@ require 'spec_helper'
3
3
  describe Heirloom::Catalog do
4
4
 
5
5
  before do
6
- @config_mock = mock 'catalog'
7
- @regions = ['us-west-1', 'us-west-2']
8
- @base = 'thebase'
9
- @catalog = Heirloom::Catalog.new :config => @config_mock,
6
+ @config_mock = mock 'catalog'
7
+ @regions = ['us-west-1', 'us-west-2']
8
+ @bucket_prefix = 'bp'
9
+ @catalog = Heirloom::Catalog.new :config => @config_mock,
10
10
  :name => 'new_archive'
11
11
  end
12
12
 
@@ -29,19 +29,19 @@ describe Heirloom::Catalog do
29
29
  :name => 'new_archive').
30
30
  and_return @catalog_add_mock
31
31
  @catalog_add_mock.should_receive(:add_to_catalog).
32
- with(:base => @base,
33
- :regions => @regions).
32
+ with(:bucket_prefix => @bucket_prefix,
33
+ :regions => @regions).
34
34
  and_return true
35
- @catalog.add_to_catalog(:base => @base,
36
- :regions => @regions).
35
+ @catalog.add_to_catalog(:bucket_prefix => @bucket_prefix,
36
+ :regions => @regions).
37
37
  should be_true
38
38
  end
39
39
  end
40
40
 
41
41
  context "testing show" do
42
42
  before do
43
- @catalog_show_stub = stub 'show', :regions => @regions,
44
- :base => @base
43
+ @catalog_show_stub = stub 'show', :regions => @regions,
44
+ :bucket_prefix => @bucket_prefix
45
45
  Heirloom::Catalog::Show.should_receive(:new).
46
46
  with(:config => @config_mock,
47
47
  :name => 'new_archive').
@@ -52,8 +52,8 @@ describe Heirloom::Catalog do
52
52
  @catalog.regions.should == @regions
53
53
  end
54
54
 
55
- it "should call base from the show object" do
56
- @catalog.base.should == @base
55
+ it "should call bucket_prefix from the show object" do
56
+ @catalog.bucket_prefix.should == @bucket_prefix
57
57
  end
58
58
  end
59
59
 
@@ -29,7 +29,7 @@ describe Heirloom do
29
29
 
30
30
  it "should rescue bad key error and return false" do
31
31
  @logger_mock.should_receive(:error).
32
- with "Unable to decrypt archive: 'OpenSSL::Cipher::CipherError'"
32
+ with "Unable to decrypt Heirloom: 'OpenSSL::Cipher::CipherError'"
33
33
  @aes_mock.should_receive(:decrypt)
34
34
  @aes_mock.should_receive(:key=).with Digest::SHA256.hexdigest 'badsecret'
35
35
  @aes_mock.should_receive(:iv=).with 'firstsixteenchar'
@@ -4,12 +4,11 @@ require 'heirloom/cli'
4
4
  describe Heirloom do
5
5
 
6
6
  before do
7
- options = { :level => 'info',
8
- :metadata_region => 'us-west-1',
9
- :details => true }
7
+ @options = { :level => 'info',
8
+ :metadata_region => 'us-west-1' }
10
9
  @result = { 'heirloom_test' =>
11
- { 'regions' => ['us-west-1'],
12
- 'base' => ['base'] } }
10
+ { 'regions' => ['us-west-1'],
11
+ 'bucket_prefix' => ['bp'] } }
13
12
  @logger_stub = stub :debug => true
14
13
  @config_mock = mock 'config'
15
14
  @catalog_mock = mock 'catalog'
@@ -18,26 +17,58 @@ describe Heirloom do
18
17
  :access_key => 'key',
19
18
  :secret_key => 'secret',
20
19
  :metadata_region => 'us-west-1'
21
- Trollop.stub(:options).and_return options
22
20
  Heirloom::HeirloomLogger.should_receive(:new).with(:log_level => 'info').
23
21
  and_return @logger_stub
24
22
  Heirloom::CLI::Catalog.any_instance.should_receive(:load_config).
25
23
  with(:logger => @logger_stub,
26
- :opts => options).
24
+ :opts => @options).
27
25
  and_return @config_mock
28
26
  Heirloom::Catalog.should_receive(:new).
29
27
  with(:config => @config_mock).
30
28
  and_return @catalog_mock
31
- @cli_catalog = Heirloom::CLI::Catalog.new
32
29
  end
33
30
 
34
- it "should list the details about all heirlooms in the catalog" do
35
- @catalog_mock.should_receive(:all).and_return @result
36
- formated_result = { 'test' =>
37
- { 'regions' => ['us-west-1'],
38
- 'base' => ['base'] } }
39
- @cli_catalog.should_receive(:jj).with formated_result
40
- @cli_catalog.all
31
+ context "as json" do
32
+ before do
33
+ @options[:json] = true
34
+ Trollop.stub :options => @options
35
+ end
36
+
37
+ it "should list the details about all heirlooms in the catalog" do
38
+ @cli_catalog = Heirloom::CLI::Catalog.new
39
+ @catalog_mock.stub :all => @result
40
+ formated_result = { 'test' =>
41
+ { 'regions' => ['us-west-1'],
42
+ 'bucket_prefix' => ['bp'] } }
43
+ @cli_catalog.should_receive(:jj).with formated_result
44
+ @cli_catalog.all
45
+ end
46
+ end
47
+
48
+ context "as human readable" do
49
+ before do
50
+ @options[:json] = nil
51
+ Trollop.stub :options => @options
52
+ end
53
+
54
+ it "should list all heirlooms in the catalog" do
55
+ @cli_catalog = Heirloom::CLI::Catalog.new
56
+ @catalog_mock.stub :all => @result
57
+ formatter_mock = mock 'formatter'
58
+ catalog = { :catalog =>
59
+ { "test" =>
60
+ {
61
+ "regions" => ["us-west-1"],
62
+ "bucket_prefix" => ["bp"]
63
+ }
64
+ },
65
+ :name => nil
66
+ }
67
+ Heirloom::CLI::Formatter::Catalog.stub :new => formatter_mock
68
+ formatter_mock.should_receive(:format).with(catalog).and_return 'theoutput'
69
+ @cli_catalog.should_receive(:puts).with 'theoutput'
70
+ @cli_catalog.all
71
+ end
41
72
  end
42
73
 
43
74
  end