heirloom 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. data/CHANGELOG +7 -0
  2. data/README.md +4 -6
  3. data/heirloom.gemspec +2 -2
  4. data/lib/heirloom.rb +1 -1
  5. data/lib/heirloom/archive.rb +121 -0
  6. data/lib/heirloom/{artifact/artifact_authorizer.rb → archive/authorizer.rb} +6 -6
  7. data/lib/heirloom/{artifact/artifact_builder.rb → archive/builder.rb} +1 -6
  8. data/lib/heirloom/archive/destroyer.rb +50 -0
  9. data/lib/heirloom/{artifact/artifact_downloader.rb → archive/downloader.rb} +7 -7
  10. data/lib/heirloom/{artifact/artifact_lister.rb → archive/lister.rb} +1 -7
  11. data/lib/heirloom/archive/reader.rb +74 -0
  12. data/lib/heirloom/{artifact/artifact_updater.rb → archive/updater.rb} +4 -4
  13. data/lib/heirloom/{artifact/artifact_uploader.rb → archive/uploader.rb} +8 -5
  14. data/lib/heirloom/archive/verifier.rb +34 -0
  15. data/lib/heirloom/aws/simpledb.rb +5 -1
  16. data/lib/heirloom/cli.rb +8 -62
  17. data/lib/heirloom/cli/build.rb +53 -25
  18. data/lib/heirloom/cli/destroy.rb +30 -8
  19. data/lib/heirloom/cli/download.rb +32 -11
  20. data/lib/heirloom/cli/list.rb +30 -6
  21. data/lib/heirloom/cli/show.rb +33 -11
  22. data/lib/heirloom/cli/update.rb +31 -11
  23. data/lib/heirloom/config.rb +3 -3
  24. data/lib/heirloom/destroyer/s3.rb +1 -1
  25. data/lib/heirloom/directory/directory.rb +1 -1
  26. data/lib/heirloom/downloader/s3.rb +1 -1
  27. data/lib/heirloom/logger.rb +23 -0
  28. data/lib/heirloom/uploader/s3.rb +6 -11
  29. data/lib/heirloom/version.rb +1 -1
  30. data/spec/acl/s3_spec.rb +2 -10
  31. data/spec/config_spec.rb +15 -4
  32. data/spec/directory/directory_spec.rb +1 -1
  33. data/spec/{artifact/artifact_authorizer_spec.rb → heirloom/authorizer_spec.rb} +7 -7
  34. data/spec/{artifact/artifact_builder_spec.rb → heirloom/builder_spec.rb} +3 -3
  35. data/spec/{artifact/artifact_destroyer_spec.rb → heirloom/destroyer_spec.rb} +7 -7
  36. data/spec/{artifact/artifact_downloader_spec.rb → heirloom/downloader_spec.rb} +17 -17
  37. data/spec/{artifact/artifact_lister_spec.rb → heirloom/lister_spec.rb} +3 -3
  38. data/spec/heirloom/reader_spec.rb +90 -0
  39. data/spec/heirloom/updater_spec.rb +16 -0
  40. data/spec/heirloom/uploader_spec.rb +16 -0
  41. data/spec/heirloom/verifier_spec.rb +38 -0
  42. data/spec/heirloom_spec.rb +74 -0
  43. data/spec/logger_spec.rb +9 -0
  44. metadata +49 -45
  45. data/lib/heirloom/artifact.rb +0 -111
  46. data/lib/heirloom/artifact/artifact_destroyer.rb +0 -49
  47. data/lib/heirloom/artifact/artifact_reader.rb +0 -44
  48. data/spec/artifact/artifact_reader_spec.rb +0 -55
  49. data/spec/artifact/artifact_updater_spec.rb +0 -16
  50. data/spec/artifact/artifact_uploader_spec.rb +0 -16
  51. data/spec/artifact_spec.rb +0 -74
@@ -3,10 +3,11 @@ module Heirloom
3
3
 
4
4
  attr_accessor :access_key, :secret_key, :regions,
5
5
  :primary_region, :bucket_prefix, :authorized_aws_accounts,
6
- :logger
6
+ :logger, :simpledb
7
7
 
8
8
  def initialize(args = {})
9
9
  @config = args[:config]
10
+ self.logger = args[:logger] ||= HeirloomLogger.new
10
11
  load_config_file
11
12
  end
12
13
 
@@ -14,8 +15,6 @@ module Heirloom
14
15
  config_file = "#{ENV['HOME']}/.heirloom.yml"
15
16
  c = @config ? @config : YAML::load( File.open( config_file ) )
16
17
 
17
- self.logger = c['logger'] ||= HeirloomLogger.new
18
-
19
18
  aws = c['aws']
20
19
 
21
20
  self.access_key = aws['access_key']
@@ -23,6 +22,7 @@ module Heirloom
23
22
  self.regions = aws['regions']
24
23
  self.bucket_prefix = aws['bucket_prefix']
25
24
  self.authorized_aws_accounts = aws['authorized_aws_accounts']
25
+ self.simpledb = aws['simpledb'] ||= true
26
26
  self.primary_region = regions ? regions.first : 'us-west-1'
27
27
  end
28
28
 
@@ -1,5 +1,5 @@
1
1
  module Heirloom
2
- module Destroyer
2
+ class Destroyer
3
3
  class S3
4
4
 
5
5
  attr_accessor :config, :region
@@ -24,7 +24,7 @@ module Heirloom
24
24
  self.local_build = File.join(Dir.tmpdir, random_text + ".tar.gz")
25
25
  end
26
26
 
27
- logger.info "Building artifact '#{local_build}' from '#{path}'."
27
+ logger.info "Building Heirloom '#{local_build}' from '#{path}'."
28
28
  logger.info "Excluding #{exclude.to_s}."
29
29
  logger.info "Adding #{files_to_pack.to_s}."
30
30
 
@@ -1,5 +1,5 @@
1
1
  module Heirloom
2
- module Downloader
2
+ class Downloader
3
3
  class S3
4
4
 
5
5
  def initialize(args)
@@ -3,6 +3,7 @@ module Heirloom
3
3
 
4
4
  def initialize(args = {})
5
5
  @logger = args[:logger] ||= Logger.new(STDOUT)
6
+ @log_level = args[:log_level] ||= 'info'
6
7
 
7
8
  unless args[:logger]
8
9
  @logger.datetime_format = "%Y-%m-%d %H:%M:%S"
@@ -11,9 +12,31 @@ module Heirloom
11
12
  end
12
13
  end
13
14
 
15
+ case @log_level.downcase
16
+ when 'info'
17
+ @logger.level = Logger::INFO
18
+ when 'debug'
19
+ @logger.level = Logger::DEBUG
20
+ when 'warn'
21
+ @logger.level = Logger::WARN
22
+ when 'error'
23
+ @logger.level = Logger::ERROR
24
+ end
14
25
  @logger
15
26
  end
16
27
 
28
+ def debug(msg)
29
+ @logger.debug msg
30
+ end
31
+
32
+ def info(msg)
33
+ @logger.info msg
34
+ end
35
+
36
+ def error(msg)
37
+ @logger.error msg
38
+ end
39
+
17
40
  def info(msg)
18
41
  @logger.info msg
19
42
  end
@@ -1,5 +1,5 @@
1
1
  module Heirloom
2
- module Uploader
2
+ class Uploader
3
3
  class S3
4
4
 
5
5
  def initialize(args)
@@ -26,22 +26,14 @@ module Heirloom
26
26
  :public => public_readable
27
27
 
28
28
  @logger.info "File is readable by the public internet." if public_readable
29
-
30
- add_endpoint_attributes :bucket => bucket,
31
- :id => id,
32
- :key_folder => key_folder,
33
- :key_name => key_name,
34
- :name => name
35
29
  end
36
30
 
37
- private
38
-
39
31
  def add_endpoint_attributes(args)
40
32
  bucket = args[:bucket]
41
33
  id = args[:id]
42
- key_name = args[:key_name]
43
- key_folder = args[:key_folder]
44
34
  name = args[:name]
35
+ key_folder = name
36
+ key_name = "#{id}.tar.gz"
45
37
 
46
38
  s3_endpoint = "s3://#{bucket}/#{key_folder}/#{key_name}"
47
39
  http_endpoint = "http://#{endpoints[@region]}/#{bucket}/#{key_folder}/#{key_name}"
@@ -57,6 +49,8 @@ module Heirloom
57
49
  @logger.info "Adding attribute #{https_endpoint}."
58
50
  end
59
51
 
52
+ private
53
+
60
54
  def endpoints
61
55
  {
62
56
  'us-east-1' => 's3.amazonaws.com',
@@ -73,6 +67,7 @@ module Heirloom
73
67
  def sdb
74
68
  @sdb ||= AWS::SimpleDB.new :config => @config
75
69
  end
70
+
76
71
  end
77
72
  end
78
73
  end
@@ -1,3 +1,3 @@
1
1
  module Heirloom
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -27,25 +27,17 @@ describe Heirloom do
27
27
  s3_mock.should_receive(:get_bucket_acl).with('bucket').
28
28
  and_return acls
29
29
 
30
- grants_mock = mock 'grants'
31
- @s3.should_receive(:build_bucket_grants).
32
- with(:id => '123',
33
- :name => 'Brett',
34
- :accounts => ['acct1@test.com', 'acct2@test.com']).
35
- and_return grants_mock
36
-
37
30
  @logger_mock.should_receive(:info).
38
31
  with 'Authorizing acct1@test.com to s3://bucket/key-folder/key.tar.gz.'
39
32
  @logger_mock.should_receive(:info).
40
33
  with 'Authorizing acct2@test.com to s3://bucket/key-folder/key.tar.gz.'
41
34
 
42
- s3_mock.should_receive(:put_object_acl).with('bucket', 'key-folder/key.tar.gz', grants_mock)
35
+ s3_mock.should_receive(:put_object_acl).
36
+ with("bucket", "key-folder/key.tar.gz", {"Owner"=>{"DisplayName"=>"Brett", "ID"=>"123"}, "AccessControlList"=>[{"Grantee"=>{"EmailAddress"=>"acct1@test.com"}, "Permission"=>"READ"}, {"Grantee"=>{"EmailAddress"=>"acct2@test.com"}, "Permission"=>"READ"}, {"Grantee"=>{"DisplayName"=>"Brett", "ID"=>"123"}, "Permission"=>"FULL_CONTROL"}]})
43
37
 
44
38
  @s3.allow_read_access_from_accounts :bucket => 'bucket',
45
39
  :key_name => 'key',
46
40
  :key_folder => 'key-folder'
47
41
  end
48
42
 
49
- it "should test build_bucket_grants private method"
50
-
51
43
  end
@@ -8,21 +8,23 @@ describe Heirloom do
8
8
  'secret_key' => 'secret',
9
9
  'regions' => ['us-west-1', 'us-west-2'],
10
10
  'bucket_prefix' => 'prefix',
11
+ 'simpledb' => true,
11
12
  'authorized_aws_accounts' => [ 'test1 @acct.com', 'test2@acct.com' ]
12
- },
13
- 'logger' => 'da-logger'
13
+ }
14
14
  }
15
15
  end
16
16
 
17
17
  it "should create a new config object from the hash passed as config" do
18
- config = Heirloom::Config.new :config => @config
18
+ config = Heirloom::Config.new :config => @config,
19
+ :logger => 'da-logger'
19
20
  config.access_key.should == @config['aws']['access_key']
20
21
  config.secret_key.should == @config['aws']['secret_key']
21
22
  config.regions.should == @config['aws']['regions']
22
23
  config.primary_region.should == 'us-west-1'
23
24
  config.bucket_prefix.should == @config['aws']['bucket_prefix']
24
25
  config.authorized_aws_accounts.should == @config['aws']['authorized_aws_accounts']
25
- config.logger.should == @config['logger']
26
+ config.simpledb.should == true
27
+ config.logger.should == 'da-logger'
26
28
  end
27
29
 
28
30
  it "should create a new config object and read from ~/.heirloom.yml" do
@@ -34,7 +36,16 @@ describe Heirloom do
34
36
  config.regions.should == @config['aws']['regions']
35
37
  config.primary_region.should == 'us-west-1'
36
38
  config.bucket_prefix.should == @config['aws']['bucket_prefix']
39
+ config.simpledb.should == true
37
40
  config.authorized_aws_accounts.should == @config['aws']['authorized_aws_accounts']
38
41
  end
39
42
 
43
+ it "should set simpledb to true by default" do
44
+ @config['aws']['simpledb'] = nil
45
+ File.should_receive(:open).with("#{ENV['HOME']}/.heirloom.yml").
46
+ and_return(@config.to_yaml)
47
+ config = Heirloom::Config.new
48
+ config.simpledb.should == true
49
+ end
50
+
40
51
  end
@@ -11,7 +11,7 @@ describe Heirloom do
11
11
  :path => '/target/dir'
12
12
  end
13
13
 
14
- it "should build an artifact from the latest commit in path" do
14
+ it "should build an archive from the latest commit in path" do
15
15
  @logger_mock.should_receive(:info).exactly(3).times
16
16
  file_mock = double 'file'
17
17
  File.should_receive(:open).and_return file_mock
@@ -6,20 +6,20 @@ describe Heirloom do
6
6
  @config_mock = double('config')
7
7
  @logger_mock = double('logger')
8
8
  @config_mock.should_receive(:logger).and_return(@logger_mock)
9
- @authorizer = Heirloom::ArtifactAuthorizer.new :config => @config_mock,
10
- :name => 'tim',
11
- :id => '123'
9
+ @authorizer = Heirloom::Authorizer.new :config => @config_mock,
10
+ :name => 'tim',
11
+ :id => '123'
12
12
  end
13
13
 
14
14
  it "should authorize access to an acl across all regions" do
15
- artifact_reader = double
15
+ reader = double
16
16
  s3_acl = double
17
17
  @logger_mock.should_receive(:info).exactly(2).times
18
18
  @config_mock.should_receive(:regions).
19
19
  and_return(['us-west-1', 'us-west-2'])
20
- @authorizer.should_receive(:artifact_reader).exactly(2).times.
21
- and_return(artifact_reader)
22
- artifact_reader.should_receive(:get_bucket).exactly(2).times.
20
+ @authorizer.should_receive(:reader).exactly(2).times.
21
+ and_return(reader)
22
+ reader.should_receive(:get_bucket).exactly(2).times.
23
23
  and_return('the-bucket')
24
24
  Heirloom::ACL::S3.should_receive(:new).exactly(2).
25
25
  times.and_return(s3_acl)
@@ -10,12 +10,12 @@ describe Heirloom do
10
10
  Heirloom::AWS::SimpleDB.should_receive(:new).with(:config => @config_mock).
11
11
  and_return(@simpledb_mock)
12
12
  @simpledb_mock.should_receive(:create_domain).with 'tim'
13
- @builder = Heirloom::ArtifactBuilder.new :config => @config_mock,
13
+ @builder = Heirloom::Builder.new :config => @config_mock,
14
14
  :name => 'tim',
15
15
  :id => '123'
16
16
  end
17
17
 
18
- it "should build an artifact" do
18
+ it "should build an archive" do
19
19
  directory_mock = double "directory"
20
20
  Heirloom::Directory.should_receive(:new).with(:path => 'path_to_build',
21
21
  :exclude => ['.dir_to_exclude'],
@@ -31,7 +31,7 @@ describe Heirloom do
31
31
  :git => 'true').should == '/tmp/file'
32
32
  end
33
33
 
34
- it "should cleanup the local artifact" do
34
+ it "should cleanup the local archive" do
35
35
  @builder.local_build = '/tmp/file'
36
36
  @logger_mock.should_receive(:info).with("Cleaning up local build /tmp/file.")
37
37
  File.should_receive(:delete).with('/tmp/file')
@@ -6,21 +6,21 @@ describe Heirloom do
6
6
  @config_mock = double 'config'
7
7
  @logger_mock = double 'logger'
8
8
  @config_mock.should_receive(:logger).and_return(@logger_mock)
9
- @destroyer = Heirloom::ArtifactDestroyer.new :config => @config_mock,
9
+ @destroyer = Heirloom::Destroyer.new :config => @config_mock,
10
10
  :name => 'tim',
11
11
  :id => '123'
12
12
  end
13
13
 
14
- it "should destroy the given artifact" do
14
+ it "should destroy the given archive" do
15
15
  @logger_mock.should_receive(:info).
16
16
  with "Destroying tim - 123"
17
17
  @config_mock.should_receive(:regions).and_return ['us-west-1']
18
- artifact_reader_mock = mock 'artifact reader'
19
- @destroyer.should_receive(:artifact_reader).and_return artifact_reader_mock
18
+ reader_mock = mock 'archive reader'
19
+ @destroyer.should_receive(:reader).and_return reader_mock
20
20
  bucket_mock = mock 'bucket'
21
- artifact_reader_mock.should_receive(:get_bucket).
22
- with(:region => 'us-west-1').
23
- and_return 'bucket-us-west-1'
21
+ reader_mock.should_receive(:get_bucket).
22
+ with(:region => 'us-west-1').
23
+ and_return 'bucket-us-west-1'
24
24
 
25
25
  @logger_mock.should_receive(:info).
26
26
  with "Destroying 's3://bucket-us-west-1/tim/123.tar.gz'."
@@ -6,26 +6,26 @@ describe Heirloom do
6
6
  @config_mock = double 'config'
7
7
  @logger_mock = double 'logger'
8
8
  @config_mock.should_receive(:logger).and_return(@logger_mock)
9
- @downloader = Heirloom::ArtifactDownloader.new :config => @config_mock,
9
+ @downloader = Heirloom::Downloader.new :config => @config_mock,
10
10
  :name => 'tim',
11
11
  :id => '123'
12
12
  end
13
13
 
14
- it "should download an artifact" do
14
+ it "should download an archive" do
15
15
  s3_downloader_mock = mock 's3 downloader'
16
16
  Heirloom::Downloader::S3.should_receive(:new).
17
17
  with(:config => @config_mock,
18
18
  :logger => @logger_mock,
19
19
  :region => 'us-west-1').
20
20
  and_return s3_downloader_mock
21
- artifact_reader_mock = mock 'artifact_reader'
22
- @downloader.should_receive(:artifact_reader).
21
+ reader_mock = mock 'reader'
22
+ @downloader.should_receive(:reader).
23
23
  exactly(2).times.
24
- and_return artifact_reader_mock
25
- artifact_reader_mock.should_receive(:get_bucket).
24
+ and_return reader_mock
25
+ reader_mock.should_receive(:get_bucket).
26
26
  with(:region => 'us-west-1').
27
27
  and_return 'bucket-us-west-1'
28
- artifact_reader_mock.should_receive(:get_key).
28
+ reader_mock.should_receive(:get_key).
29
29
  with(:region => 'us-west-1').
30
30
  and_return 'key'
31
31
 
@@ -51,23 +51,23 @@ describe Heirloom do
51
51
  :region => 'us-west-1')
52
52
  end
53
53
 
54
- it "should download the artifact to the current path if output is unspecficief" do
54
+ it "should download the archive to the current path if output is unspecficief" do
55
55
  s3_downloader_mock = mock 's3 downloader'
56
56
  Heirloom::Downloader::S3.should_receive(:new).
57
57
  with(:config => @config_mock,
58
58
  :logger => @logger_mock,
59
59
  :region => 'us-west-1').
60
60
  and_return s3_downloader_mock
61
- artifact_reader_mock = mock 'artifact_reader'
62
- @downloader.should_receive(:artifact_reader).
61
+ reader_mock = mock 'reader'
62
+ @downloader.should_receive(:reader).
63
63
  exactly(2).times.
64
- and_return artifact_reader_mock
65
- artifact_reader_mock.should_receive(:get_bucket).
66
- with(:region => 'us-west-1').
67
- and_return 'bucket-us-west-1'
68
- artifact_reader_mock.should_receive(:get_key).
69
- with(:region => 'us-west-1').
70
- and_return 'key'
64
+ and_return reader_mock
65
+ reader_mock.should_receive(:get_bucket).
66
+ with(:region => 'us-west-1').
67
+ and_return 'bucket-us-west-1'
68
+ reader_mock.should_receive(:get_key).
69
+ with(:region => 'us-west-1').
70
+ and_return 'key'
71
71
 
72
72
  @logger_mock.should_receive(:info).
73
73
  with "Downloading s3://bucket-us-west-1/key from us-west-1."
@@ -4,11 +4,11 @@ describe Heirloom do
4
4
 
5
5
  before do
6
6
  @config_mock = double 'config'
7
- @lister = Heirloom::ArtifactLister.new :config => @config_mock,
8
- :name => 'test123'
7
+ @lister = Heirloom::Lister.new :config => @config_mock,
8
+ :name => 'test123'
9
9
  end
10
10
 
11
- it "should list the known artifacts" do
11
+ it "should list the known archive" do
12
12
  sdb_mock = mock 'sdb'
13
13
  @lister.should_receive(:sdb).and_return sdb_mock
14
14
  sdb_mock.should_receive(:select).
@@ -0,0 +1,90 @@
1
+ require 'spec_helper'
2
+
3
+ describe Heirloom do
4
+
5
+ before do
6
+ @sdb_mock = mock 'sdb'
7
+ @config_mock = double 'config'
8
+ @logger_mock = double 'logger'
9
+ @config_mock.should_receive(:logger).and_return @logger_mock
10
+ Heirloom::AWS::SimpleDB.should_receive(:new).and_return @sdb_mock
11
+ @reader = Heirloom::Reader.new :config => @config_mock,
12
+ :name => 'tim',
13
+ :id => '123'
14
+ end
15
+
16
+ it "should show the item record" do
17
+ @sdb_mock.should_receive(:select).
18
+ with("select * from tim where itemName() = '123'").
19
+ and_return( { '123' => { 'value' => 'details' } } )
20
+ @reader.show.should == { 'value' => 'details' }
21
+ end
22
+
23
+ it "should return an empty hash if item does not exist" do
24
+ @sdb_mock.should_receive(:select).
25
+ with("select * from tim where itemName() = '123'").
26
+ and_return({})
27
+ @reader.show.should == {}
28
+ end
29
+
30
+ it "should return true if the record exists" do
31
+ @sdb_mock.should_receive(:select).
32
+ with("select * from tim where itemName() = '123'").
33
+ and_return( { '123' => { 'value' => 'details' } } )
34
+ @logger_mock.should_receive(:debug).exactly(1).times
35
+ @reader.exists?.should == true
36
+ end
37
+
38
+ it "should return false if the recrod does not exist" do
39
+ @sdb_mock.should_receive(:select).
40
+ with("select * from tim where itemName() = '123'").
41
+ and_return({})
42
+ @logger_mock.should_receive(:debug).exactly(1).times
43
+ @reader.exists?.should == false
44
+ end
45
+
46
+ it "should return the bucket if it exists" do
47
+ @logger_mock.should_receive(:debug).exactly(5).times
48
+ @sdb_mock.should_receive(:select).
49
+ exactly(3).times.
50
+ with("select * from tim where itemName() = '123'").
51
+ and_return( { '123' =>
52
+ { 'us-west-1-s3-url' =>
53
+ ['s3://the-url/the-buck/the-key']
54
+ }
55
+ } )
56
+ @reader.get_bucket(:region => 'us-west-1').should == 'the-url'
57
+ end
58
+
59
+ it "should return nil if the bucket does not exist" do
60
+ @logger_mock.should_receive(:debug).exactly(3).times
61
+ @sdb_mock.should_receive(:select).
62
+ exactly(1).times.
63
+ with("select * from tim where itemName() = '123'").
64
+ and_return( { } )
65
+ @reader.get_bucket(:region => 'us-west-1').should == nil
66
+ end
67
+
68
+ it "should return the key if it exists" do
69
+ @logger_mock.should_receive(:debug).exactly(8).times
70
+ @sdb_mock.should_receive(:select).
71
+ exactly(6).times.
72
+ with("select * from tim where itemName() = '123'").
73
+ and_return( { '123' =>
74
+ { 'us-west-1-s3-url' =>
75
+ ['s3://the-url/the-bucket/the-key']
76
+ }
77
+ } )
78
+ @reader.get_key(:region => 'us-west-1').should == 'the-bucket/the-key'
79
+ end
80
+
81
+ it "should return nil if the key does not exist" do
82
+ @logger_mock.should_receive(:debug).exactly(1).times
83
+ @sdb_mock.should_receive(:select).
84
+ exactly(1).times.
85
+ with("select * from tim where itemName() = '123'").
86
+ and_return( { } )
87
+ @reader.get_key(:region => 'us-west-1').should == nil
88
+ end
89
+
90
+ end