heirloom 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,49 +0,0 @@
1
- module Heirloom
2
-
3
- class ArtifactDestroyer
4
-
5
- attr_accessor :config, :id, :logger, :name
6
-
7
- def initialize(args)
8
- self.config = args[:config]
9
- self.name = args[:name]
10
- self.id = args[:id]
11
- self.logger = config.logger
12
- end
13
-
14
- def destroy
15
- logger.info "Destroying #{@name} - #{@id}"
16
-
17
- config.regions.each do |region|
18
- bucket = artifact_reader.get_bucket :region => region
19
-
20
- key = "#{id}.tar.gz"
21
-
22
- logger.info "Destroying 's3://#{bucket}/#{name}/#{key}'."
23
-
24
- s3_destroyer = Destroyer::S3.new :config => config,
25
- :region => region
26
-
27
- s3_destroyer.destroy_file :key_name => key,
28
- :key_folder => name,
29
- :bucket => bucket
30
-
31
- end
32
- sdb.delete name, id
33
- logger.info "Destroy complete."
34
- end
35
-
36
- private
37
-
38
- def sdb
39
- @sdb ||= AWS::SimpleDB.new :config => @config
40
- end
41
-
42
- def artifact_reader
43
- @artifact_reader ||= ArtifactReader.new :config => config,
44
- :name => name,
45
- :id => id
46
- end
47
-
48
- end
49
- end
@@ -1,44 +0,0 @@
1
- module Heirloom
2
-
3
- class ArtifactReader
4
-
5
- attr_accessor :config, :id, :name
6
-
7
- def initialize(args)
8
- self.config = args[:config]
9
- self.name = args[:name]
10
- self.id = args[:id]
11
- end
12
-
13
- def show
14
- items = sdb.select "select * from #{name} where itemName() = '#{id}'"
15
- items[@id]
16
- end
17
-
18
- def exists?
19
- show != nil
20
- end
21
-
22
- def get_bucket(args)
23
- get_url(args).gsub('s3://', '').split('/').first
24
- end
25
-
26
- def get_key(args)
27
- bucket_path = get_bucket :region => args[:region]
28
- bucket = get_url(args).gsub('s3://', '').gsub(bucket_path, '')
29
- bucket.slice!(0)
30
- bucket
31
- end
32
-
33
- def get_url(args)
34
- show["#{args[:region]}-s3-url"].first
35
- end
36
-
37
- private
38
-
39
- def sdb
40
- @sdb ||= AWS::SimpleDB.new :config => @config
41
- end
42
-
43
- end
44
- end
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Heirloom do
4
-
5
- before do
6
- @config_mock = double 'config'
7
- @reader = Heirloom::ArtifactReader.new :config => @config_mock,
8
- :name => 'tim',
9
- :id => '123'
10
- end
11
-
12
- it "should show the item record" do
13
- sdb_mock = mock 'sdb'
14
- @reader.should_receive(:sdb).and_return sdb_mock
15
- sdb_mock.should_receive(:select).
16
- with("select * from tim where itemName() = '123'").
17
- and_return( { '123' => 'details' } )
18
- @reader.show.should == 'details'
19
- end
20
-
21
- it "should return true if the record exists" do
22
- @reader.should_receive(:show).and_return 'a record'
23
- @reader.exists?.should == true
24
- end
25
-
26
- it "should return false if the recrod does not exist" do
27
- @reader.should_receive(:show).and_return nil
28
- @reader.exists?.should == false
29
- end
30
-
31
- it "should return the bucket for the specified region" do
32
- @reader.should_receive(:get_url).
33
- with(:region => 'us-west-1').
34
- and_return 's3://bucket-us-west-1/tim/123.tar.gz'
35
- @reader.get_bucket(:region => 'us-west-1').should == 'bucket-us-west-1'
36
- end
37
-
38
- it "should return the key" do
39
- @reader.should_receive(:show).
40
- and_return( { 'us-west-1-s3-url' =>
41
- [ 's3://bucket-us-west-1/tim/123.tar.gz' ] } )
42
- @reader.should_receive(:get_bucket).
43
- with(:region => 'us-west-1').
44
- and_return 'bucket-us-west-1'
45
- @reader.get_key(:region => 'us-west-1').should == 'tim/123.tar.gz'
46
- end
47
-
48
- it "shoudl return the s3 url for the given region" do
49
- @reader.should_receive(:show).
50
- and_return( { 'us-west-1-s3-url' =>
51
- [ 's3://bucket-us-west-1/tim/123.tar.gz' ] } )
52
- @reader.get_url(:region => 'us-west-1').should == 's3://bucket-us-west-1/tim/123.tar.gz'
53
- end
54
-
55
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Heirloom do
4
-
5
- before do
6
- @config_mock = double 'config'
7
- @logger_mock = double 'logger'
8
- @config_mock.should_receive(:logger).and_return(@logger_mock)
9
- @reader = Heirloom::ArtifactUpdater.new :config => @config_mock,
10
- :name => 'tim',
11
- :id => '123'
12
- end
13
-
14
- it "should test the artifact updater methods"
15
-
16
- end
@@ -1,16 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Heirloom do
4
-
5
- before do
6
- @config_mock = double 'config'
7
- @logger_mock = double 'logger'
8
- @config_mock.should_receive(:logger).and_return(@logger_mock)
9
- @reader = Heirloom::ArtifactUploader.new :config => @config_mock,
10
- :name => 'tim',
11
- :id => '123'
12
- end
13
-
14
- it "should test the artifact uploader methods"
15
-
16
- end
@@ -1,74 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Heirloom do
4
-
5
- before do
6
- Heirloom::Config.should_receive(:new).and_return('config')
7
- @artifact = Heirloom::Artifact.new :logger => 'logger',
8
- :name => 'tim',
9
- :id => '123'
10
- end
11
-
12
-
13
- context "test public methods" do
14
- before do
15
- @mock = double('Mock')
16
- end
17
-
18
- it "should call build method with given args" do
19
- @artifact.should_receive(:artifact_builder).and_return(@mock)
20
- @mock.should_receive(:build).with('args')
21
- @artifact.build('args')
22
- end
23
-
24
- it "should call download method with given args" do
25
- @artifact.should_receive(:artifact_downloader).and_return(@mock)
26
- @mock.should_receive(:download).with('args')
27
- @artifact.download('args')
28
- end
29
-
30
- it "should call update artifact method with given args" do
31
- @artifact.should_receive(:artifact_updater).and_return(@mock)
32
- @mock.should_receive(:update).with('args')
33
- @artifact.update('args')
34
- end
35
-
36
- it "should call upload artifact method with given args" do
37
- @artifact.should_receive(:artifact_uploader).and_return(@mock)
38
- @mock.should_receive(:upload).with('args')
39
- @artifact.upload('args')
40
- end
41
-
42
- it "should call authorize method" do
43
- @artifact.should_receive(:artifact_authorizer).and_return(@mock)
44
- @mock.should_receive(:authorize)
45
- @artifact.authorize
46
- end
47
-
48
- it "should call artifact exists method" do
49
- @artifact.should_receive(:artifact_reader).and_return(@mock)
50
- @mock.should_receive(:exists?)
51
- @artifact.exists?
52
- end
53
-
54
- it "should call show method" do
55
- @artifact.should_receive(:artifact_reader).and_return(@mock)
56
- @mock.should_receive(:show)
57
- @artifact.show
58
- end
59
-
60
- it "should call list method" do
61
- @artifact.should_receive(:artifact_lister).and_return(@mock)
62
- @mock.should_receive(:list)
63
- @artifact.list
64
- end
65
-
66
- it "should call cleanup method" do
67
- @artifact.should_receive(:artifact_builder).and_return(@mock)
68
- @mock.should_receive(:cleanup)
69
- @artifact.cleanup
70
- end
71
-
72
- end
73
-
74
- end