heirloom 0.5.0rc3 → 0.5.0rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/CHANGELOG +11 -4
  2. data/README.md +3 -1
  3. data/heirloom.gemspec +3 -4
  4. data/lib/heirloom/archive.rb +15 -4
  5. data/lib/heirloom/archive/authorizer.rb +20 -3
  6. data/lib/heirloom/archive/builder.rb +2 -1
  7. data/lib/heirloom/archive/destroyer.rb +9 -2
  8. data/lib/heirloom/archive/setuper.rb +48 -0
  9. data/lib/heirloom/archive/verifier.rb +20 -10
  10. data/lib/heirloom/aws/s3.rb +7 -0
  11. data/lib/heirloom/cipher/data.rb +5 -2
  12. data/lib/heirloom/cipher/file.rb +1 -1
  13. data/lib/heirloom/cli.rb +14 -14
  14. data/lib/heirloom/cli/authorize.rb +3 -1
  15. data/lib/heirloom/cli/destroy.rb +1 -1
  16. data/lib/heirloom/cli/shared.rb +8 -9
  17. data/lib/heirloom/cli/{update.rb → tag.rb} +14 -9
  18. data/lib/heirloom/cli/{build.rb → upload.rb} +22 -25
  19. data/lib/heirloom/directory/directory.rb +2 -2
  20. data/lib/heirloom/uploader/s3.rb +2 -2
  21. data/lib/heirloom/version.rb +1 -1
  22. data/spec/archive/authorizer_spec.rb +14 -4
  23. data/spec/archive/builder_spec.rb +12 -5
  24. data/spec/archive/destroyer_spec.rb +24 -14
  25. data/spec/archive/setup_spec.rb +66 -0
  26. data/spec/archive/verifier_spec.rb +54 -22
  27. data/spec/archive/writer_spec.rb +2 -2
  28. data/spec/archive_spec.rb +3 -2
  29. data/spec/aws/s3_spec.rb +16 -0
  30. data/spec/cipher/data_spec.rb +3 -3
  31. data/spec/cipher/file_spec.rb +4 -3
  32. data/spec/cli/authorize_spec.rb +9 -2
  33. data/spec/cli/destroy_spec.rb +1 -1
  34. data/spec/cli/shared_spec.rb +2 -1
  35. data/spec/cli/{update_spec.rb → tag_spec.rb} +19 -13
  36. data/spec/cli/{build_spec.rb → upload_spec.rb} +26 -26
  37. data/spec/directory/directory_spec.rb +4 -2
  38. metadata +26 -34
@@ -1,6 +1,6 @@
1
1
  module Heirloom
2
2
  module CLI
3
- class Update
3
+ class Tag
4
4
 
5
5
  include Heirloom::CLI::Shared
6
6
 
@@ -11,7 +11,7 @@ module Heirloom
11
11
  :opts => @opts
12
12
 
13
13
  ensure_valid_options :provided => @opts,
14
- :required => [:name, :id, :attribute, :updated_value],
14
+ :required => [:name, :id, :attribute, :value],
15
15
  :config => @config
16
16
 
17
17
  ensure_domain_exists :name => @opts[:name], :config => @config
@@ -21,9 +21,13 @@ module Heirloom
21
21
  :config => @config
22
22
  end
23
23
 
24
- def update
24
+ def tag
25
+ unless @archive.exists?
26
+ @logger.error "Archive does not exist"
27
+ exit 1
28
+ end
25
29
  @archive.update :attribute => @opts[:attribute],
26
- :value => @opts[:updated_value]
30
+ :value => @opts[:value]
27
31
  end
28
32
 
29
33
  private
@@ -33,11 +37,11 @@ module Heirloom
33
37
  version Heirloom::VERSION
34
38
  banner <<-EOS
35
39
 
36
- Update an archive's attribute.
40
+ Tag an archive with an attribute and value.
37
41
 
38
42
  Usage:
39
43
 
40
- heirloom update -n NAME -i ID -a ATTRIBUTE_TO_UPDATE -u UPDATED_VALUE
44
+ heirloom tag -n NAME -i ID -a ATTRIBUTE -u VALUE
41
45
 
42
46
  EOS
43
47
  opt :attribute, "Attribute to update.", :type => :string
@@ -46,10 +50,11 @@ EOS
46
50
  opt :level, "Log level [debug|info|warn|error].", :type => :string,
47
51
  :default => 'info'
48
52
  opt :name, "Name of archive.", :type => :string
49
- opt :updated_value, "Updated value of attribute.", :type => :string
50
- opt :aws_access_key, "AWS Access Key ID", :type => :string,
53
+ opt :value, "Value of attribute.", :type => :string,
54
+ :short => 'u'
55
+ opt :aws_access_key, "AWS Access Key ID", :type => :string,
51
56
  :short => :none
52
- opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
57
+ opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
53
58
  :short => :none
54
59
  end
55
60
  end
@@ -1,6 +1,6 @@
1
1
  module Heirloom
2
2
  module CLI
3
- class Build
3
+ class Upload
4
4
 
5
5
  include Heirloom::CLI::Shared
6
6
 
@@ -12,7 +12,7 @@ module Heirloom
12
12
 
13
13
  ensure_valid_options :provided => @opts,
14
14
  :required => [:name, :id, :region,
15
- :base_prefix, :directory],
15
+ :base, :directory],
16
16
  :config => @config
17
17
 
18
18
  @archive = Archive.new :name => @opts[:name],
@@ -20,33 +20,30 @@ module Heirloom
20
20
  :config => @config
21
21
  end
22
22
 
23
- def build
24
- unless @archive.buckets_exist? :bucket_prefix => @opts[:base_prefix],
25
- :regions => @opts[:region]
26
- @logger.error "Buckets do no exist in required regions."
27
- exit 1
28
- end
29
-
23
+ def upload
30
24
  ensure_directory :path => @opts[:directory], :config => @config
31
25
  ensure_valid_secret :secret => @opts[:secret], :config => @config
32
26
 
33
- @archive.destroy if @archive.exists?
27
+ @archive.setup :regions => @opts[:region],
28
+ :bucket_prefix => @opts[:base]
29
+
30
+ @archive.destroy :keep_domain => true if @archive.exists?
34
31
 
35
- build = @archive.build :bucket_prefix => @opts[:base_prefix],
36
- :directory => @opts[:directory],
37
- :exclude => @opts[:exclude],
38
- :git => @opts[:git],
39
- :secret => @opts[:secret]
40
-
41
- if build
42
- @archive.upload :bucket_prefix => @opts[:base_prefix],
43
- :regions => @opts[:region],
44
- :public_readable => @opts[:public],
45
- :file => build
46
- else
32
+ build = @archive.build :base => @opts[:base],
33
+ :directory => @opts[:directory],
34
+ :exclude => @opts[:exclude],
35
+ :git => @opts[:git],
36
+ :secret => @opts[:secret]
37
+
38
+ unless build
47
39
  @logger.error "Build failed."
48
40
  exit 1
49
41
  end
42
+
43
+ @archive.upload :bucket_prefix => @opts[:base],
44
+ :regions => @opts[:region],
45
+ :public_readable => @opts[:public],
46
+ :file => build
50
47
  end
51
48
 
52
49
  private
@@ -56,14 +53,14 @@ module Heirloom
56
53
  version Heirloom::VERSION
57
54
  banner <<-EOS
58
55
 
59
- Build and upload a new archive.
56
+ Upload a directory to Heirloom.
60
57
 
61
58
  Usage:
62
59
 
63
- heirloom build -n NAME -i ID -b BASE_PREFIX -r REGION1 -r REGION2 -d DIRECTORY_TO_BUILD
60
+ heirloom upload -n NAME -i ID -b BASE -r REGION1 -r REGION2 -d DIRECTORY_TO_UPLOAD
64
61
 
65
62
  EOS
66
- opt :base_prefix, "Base bucket prefix which will be combined with region. \
63
+ opt :base, "Base prefix which will be combined with region. \
67
64
  For example: -b 'test' -r 'us-west-1' will expect bucket 'test-us-west-1' \
68
65
  to be present", :type => :string
69
66
  opt :directory, "Source directory of build.", :type => :string
@@ -19,8 +19,8 @@ module Heirloom
19
19
  @local_build = Tempfile.new('archive.tar.gz').path
20
20
 
21
21
  @logger.info "Building Heirloom '#{@local_build}' from '#{@path}'."
22
- @logger.info "Excluding #{@exclude.to_s}."
23
- @logger.info "Adding #{files_to_pack}."
22
+ @logger.debug "Excluding #{@exclude.to_s}."
23
+ @logger.debug "Adding #{files_to_pack}."
24
24
 
25
25
  return build_archive unless @secret
26
26
 
@@ -44,10 +44,10 @@ module Heirloom
44
44
  @logger.info "Adding attribute #{s3_endpoint}."
45
45
 
46
46
  sdb.put_attributes domain, id, { "#{@region}-http-url" => http_endpoint }
47
- @logger.info "Adding attribute #{http_endpoint}."
47
+ @logger.debug "Adding attribute #{http_endpoint}."
48
48
 
49
49
  sdb.put_attributes domain, id, { "#{@region}-https-url" => https_endpoint }
50
- @logger.info "Adding attribute #{https_endpoint}."
50
+ @logger.debug "Adding attribute #{https_endpoint}."
51
51
  end
52
52
 
53
53
  private
@@ -1,3 +1,3 @@
1
1
  module Heirloom
2
- VERSION = "0.5.0rc3"
2
+ VERSION = "0.5.0rc4"
3
3
  end
@@ -5,6 +5,7 @@ describe Heirloom do
5
5
  before do
6
6
  @config_mock = double('config')
7
7
  @logger_mock = double('logger')
8
+ @logger_mock.stub :info => true, :debug => true
8
9
  @config_mock.should_receive(:logger).and_return(@logger_mock)
9
10
  @authorizer = Heirloom::Authorizer.new :config => @config_mock,
10
11
  :name => 'tim',
@@ -14,7 +15,7 @@ describe Heirloom do
14
15
  it "should authorize access to an archive in all regions" do
15
16
  reader = double
16
17
  s3_acl = double
17
- @logger_mock.should_receive(:info).exactly(2).times
18
+ accounts = [ "test@a.com", "a@test.com", "test@test.co", "test@test.co.uk" ]
18
19
  @authorizer.should_receive(:reader).exactly(2).times.
19
20
  and_return(reader)
20
21
  reader.should_receive(:get_bucket).exactly(2).times.
@@ -26,9 +27,18 @@ describe Heirloom do
26
27
  with(:key_name => '123',
27
28
  :key_folder => 'tim',
28
29
  :bucket => 'the-bucket',
29
- :accounts => ["acct1", "acct2"])
30
- @authorizer.authorize :accounts => ['acct1', 'acct2'],
31
- :regions => ['us-west-1', 'us-west-2']
30
+ :accounts => accounts)
31
+ @authorizer.authorize(:accounts => accounts,
32
+ :regions => ['us-west-1', 'us-west-2']).
33
+ should be_true
32
34
  end
33
35
 
36
+ it "should exit when an account is not an email" do
37
+ @logger_mock.should_receive(:error)
38
+ @authorizer.authorize(:accounts => ['good@good.com', 'bad@blah'],
39
+ :regions => ['us-west-1', 'us-west-2']).
40
+ should be_false
41
+ end
42
+
43
+
34
44
  end
@@ -6,9 +6,6 @@ describe Heirloom::Builder do
6
6
  @logger_stub = stub :debug => 'true', :info => 'true', :warn => 'true'
7
7
  @config_mock.stub(:logger).and_return(@logger_stub)
8
8
  @simpledb_mock = double 'simple db'
9
- Heirloom::AWS::SimpleDB.should_receive(:new).with(:config => @config_mock).
10
- and_return(@simpledb_mock)
11
- @simpledb_mock.should_receive(:create_domain).with 'heirloom_tim'
12
9
  @builder = Heirloom::Builder.new :config => @config_mock,
13
10
  :name => 'tim',
14
11
  :id => '123'
@@ -16,8 +13,7 @@ describe Heirloom::Builder do
16
13
 
17
14
  describe 'build' do
18
15
  context 'when successful' do
19
- context 'with a git directory' do
20
- before do
16
+ before do
21
17
  @author_stub = stub :name => 'weaver'
22
18
  @directory_stub = stub :build_artifact_from_directory => '/tmp/build_dir',
23
19
  :local_build => '/var/tmp/file.tar.gz'
@@ -32,6 +28,14 @@ describe Heirloom::Builder do
32
28
  with(:path => 'path_to_build').
33
29
  and_return @git_dir_mock
34
30
  @builder.should_receive(:create_artifact_record)
31
+ end
32
+
33
+ context 'with a git directory' do
34
+
35
+ before do
36
+ Heirloom::AWS::SimpleDB.should_receive(:new).
37
+ with(:config => @config_mock).
38
+ and_return(@simpledb_mock)
35
39
  end
36
40
 
37
41
  it "should build an archive" do
@@ -66,6 +70,9 @@ describe Heirloom::Builder do
66
70
  :git => 'true').should == '/var/tmp/file.tar.gz'
67
71
  end
68
72
 
73
+ end
74
+
75
+ context "without git dir" do
69
76
  it "should build an archive and log a warning if the git sha is not found" do
70
77
  @logger_stub.should_receive(:warn).with "Could not load Git sha '123' in 'path_to_build'."
71
78
  @git_dir_mock.should_receive(:commit).
@@ -11,33 +11,43 @@ describe Heirloom do
11
11
  :id => '123'
12
12
  end
13
13
 
14
- it "should destroy the given archive" do
14
+ before do
15
15
  @logger_mock.stub :info => true
16
- reader_mock = mock 'archive reader'
17
- @destroyer.should_receive(:reader).and_return reader_mock
18
- bucket_mock = mock 'bucket'
19
- reader_mock.should_receive(:get_bucket).
16
+ @reader_mock = mock 'archive reader'
17
+ @destroyer.stub :reader => @reader_mock
18
+ @reader_mock.should_receive(:get_bucket).
20
19
  with(:region => 'us-west-1').
21
20
  and_return 'bucket-us-west-1'
22
21
 
23
22
 
24
- s3_destroyer_mock = mock 's3 destroyer'
23
+ @s3_destroyer_mock = mock 's3 destroyer'
25
24
  Heirloom::Destroyer::S3.should_receive(:new).
26
25
  with(:config => @config_mock,
27
26
  :region => 'us-west-1').
28
- and_return s3_destroyer_mock
29
- s3_destroyer_mock.should_receive(:destroy_file).
27
+ and_return @s3_destroyer_mock
28
+ @s3_destroyer_mock.should_receive(:destroy_file).
30
29
  with :key_name => '123.tar.gz',
31
30
  :key_folder => 'tim',
32
31
  :bucket => 'bucket-us-west-1'
33
- sdb_mock = mock 'sdb'
34
- @destroyer.stub :sdb => sdb_mock
35
- sdb_mock.should_receive(:delete).with 'heirloom_tim', '123'
32
+ @sdb_mock = mock 'sdb'
33
+ @destroyer.stub :sdb => @sdb_mock
34
+ @sdb_mock.should_receive(:delete).with 'heirloom_tim', '123'
35
+ end
36
+
37
+ it "should destroy the given archive" do
36
38
  Kernel.should_receive(:sleep).with 3
37
- sdb_mock.should_receive(:domain_empty?).with('heirloom_tim').
39
+ @sdb_mock.should_receive(:domain_empty?).with('heirloom_tim').
38
40
  and_return true
39
- sdb_mock.should_receive(:delete_domain).with('heirloom_tim')
40
- @destroyer.destroy :regions => ['us-west-1']
41
+ @sdb_mock.should_receive(:delete_domain).with('heirloom_tim')
42
+ @destroyer.destroy :regions => ['us-west-1'],
43
+ :keep_domain => false
44
+ end
45
+
46
+ it "should destroy the given archive but keep the sbd domain" do
47
+ @sdb_mock.should_receive(:domain_empty?).exactly(0).times
48
+ @sdb_mock.should_receive(:delete_domain).exactly(0).times
49
+ @destroyer.destroy :regions => ['us-west-1'],
50
+ :keep_domain => true
41
51
  end
42
52
 
43
53
  end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe Heirloom do
4
+
5
+ before do
6
+ @logger_stub = stub 'logger', :debug => true, :info => true
7
+ @config_mock = mock 'config'
8
+ @config_mock.stub :logger => @logger_stub
9
+ @verifier_mock = mock 'verifier'
10
+ Heirloom::Verifier.should_receive(:new).
11
+ with(:config => @config_mock,
12
+ :name => 'archive').
13
+ and_return @verifier_mock
14
+ @setuper = Heirloom::Setuper.new :config => @config_mock,
15
+ :name => 'archive'
16
+ end
17
+
18
+ context "creating domains" do
19
+ before do
20
+ @verifier_mock.stub :bucket_exists? => true
21
+ end
22
+
23
+ it "should create the domain if it does not exist" do
24
+ @sdb_mock = mock 'sdb'
25
+ Heirloom::AWS::SimpleDB.should_receive(:new).
26
+ with(:config => @config_mock).
27
+ and_return @sdb_mock
28
+ @verifier_mock.stub :domain_exists? => false
29
+ @sdb_mock.should_receive(:create_domain).with 'heirloom_archive'
30
+ @setuper.setup :regions => ['us-west-1'],
31
+ :bucket_prefix => 'base'
32
+
33
+ end
34
+
35
+ it "should not create the domain if alrady exists" do
36
+ @verifier_mock.stub :domain_exists? => true
37
+ @setuper.setup :regions => ['us-west-1'],
38
+ :bucket_prefix => 'base'
39
+ end
40
+ end
41
+
42
+ context "creating buckets" do
43
+ before do
44
+ @verifier_mock.stub :domain_exists? => true
45
+ end
46
+
47
+ it "should create required buckets that don't exist" do
48
+ @verifier_mock.should_receive(:bucket_exists?).
49
+ with(:region => "us-west-1", :bucket_prefix => "base").
50
+ and_return true
51
+ @verifier_mock.should_receive(:bucket_exists?).
52
+ with(:region => "us-east-1", :bucket_prefix => "base").
53
+ and_return false
54
+ @s3_mock = mock 's3'
55
+ Heirloom::AWS::S3.should_receive(:new).
56
+ with(:config => @config_mock,
57
+ :region => 'us-east-1').
58
+ and_return @s3_mock
59
+ @s3_mock.should_receive(:put_bucket).
60
+ with 'base-us-east-1', 'us-east-1'
61
+ @setuper.setup :regions => ['us-west-1', 'us-east-1'],
62
+ :bucket_prefix => 'base'
63
+ end
64
+ end
65
+
66
+ end
@@ -4,35 +4,67 @@ describe Heirloom do
4
4
 
5
5
  before do
6
6
  @config_mock = double 'config'
7
- @logger_mock = double 'logger'
7
+ @logger_stub = stub 'logger', :debug => true
8
8
  @s3_mock = double 's3_mock'
9
- @config_mock.should_receive(:logger).and_return(@logger_mock)
9
+ @config_mock.stub :logger => @logger_stub
10
10
  @verifier = Heirloom::Verifier.new :config => @config_mock,
11
11
  :name => 'heirloom-name'
12
12
  end
13
13
 
14
- it "should return false if a bucket does not exist" do
15
- Heirloom::AWS::S3.should_receive(:new).
16
- with(:config => @config_mock,
17
- :region => 'us-west-1').
18
- and_return @s3_mock
19
- @s3_mock.should_receive(:get_bucket).with('bucket123-us-west-1').
20
- and_return nil
21
- @logger_mock.should_receive(:debug)
22
- @verifier.buckets_exist?(:bucket_prefix => 'bucket123',
23
- :regions => ['us-west-1']).should be_false
14
+ context "verifying all buckets exist" do
15
+ before do
16
+ Heirloom::AWS::S3.should_receive(:new).
17
+ with(:config => @config_mock,
18
+ :region => 'us-west-1').
19
+ and_return @s3_mock
20
+ Heirloom::AWS::S3.should_receive(:new).
21
+ with(:config => @config_mock,
22
+ :region => 'us-east-1').
23
+ and_return @s3_mock
24
+ end
25
+ it "should return false if a bucket does not exist in a region" do
26
+ @s3_mock.should_receive(:get_bucket).with('bucket123-us-west-1').
27
+ and_return nil
28
+ @s3_mock.should_receive(:get_bucket).with('bucket123-us-east-1').
29
+ and_return 'an s3 bucket'
30
+ @verifier.buckets_exist?(:bucket_prefix => 'bucket123',
31
+ :regions => ['us-west-1', 'us-east-1']).
32
+ should be_false
33
+ end
34
+
35
+ it "should true if all buckets exist" do
36
+ @s3_mock.should_receive(:get_bucket).with('bucket123-us-west-1').
37
+ and_return 'an s3 bucket'
38
+ @s3_mock.should_receive(:get_bucket).with('bucket123-us-east-1').
39
+ and_return 'an s3 bucket'
40
+ @verifier.buckets_exist?(:bucket_prefix => 'bucket123',
41
+ :regions => ['us-west-1', 'us-east-1']).
42
+ should be_true
43
+ end
24
44
  end
25
45
 
26
- it "should true if all buckets exist" do
27
- Heirloom::AWS::S3.should_receive(:new).
28
- with(:config => @config_mock,
29
- :region => 'us-west-1').
30
- and_return @s3_mock
31
- @s3_mock.should_receive(:get_bucket).with('bucket123-us-west-1').
32
- and_return 'an s3 bucket'
33
- @logger_mock.should_receive(:debug)
34
- @verifier.buckets_exist?(:bucket_prefix => 'bucket123',
35
- :regions => ['us-west-1']).should be_true
46
+ context "verifying a single bucket exist" do
47
+ it "should return true if the given bucket does not exist in the region" do
48
+ Heirloom::AWS::S3.should_receive(:new).
49
+ with(:config => @config_mock,
50
+ :region => 'us-west-1').
51
+ and_return @s3_mock
52
+ @s3_mock.should_receive(:get_bucket).with('bucket123-us-west-1').
53
+ and_return 'an s3 bucket'
54
+ @verifier.bucket_exists?(:bucket_prefix => 'bucket123',
55
+ :region => 'us-west-1').should be_true
56
+ end
57
+
58
+ it "should return false if the given bucket does not exist in the region" do
59
+ Heirloom::AWS::S3.should_receive(:new).
60
+ with(:config => @config_mock,
61
+ :region => 'us-west-1').
62
+ and_return @s3_mock
63
+ @s3_mock.should_receive(:get_bucket).with('bucket123-us-west-1').
64
+ and_return 'an s3 bucket'
65
+ @verifier.bucket_exists?(:bucket_prefix => 'bucket123',
66
+ :region => 'us-west-1').should be_true
67
+ end
36
68
  end
37
69
 
38
70
  end