heirloom 0.11.0 → 0.11.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/.gitignore +1 -0
  2. data/.ruby-gemset +1 -0
  3. data/.ruby-version +1 -0
  4. data/CHANGELOG.md +4 -1
  5. data/README.md +9 -0
  6. data/heirloom.gemspec +8 -2
  7. data/lib/heirloom.rb +9 -0
  8. data/lib/heirloom/acl/s3.rb +1 -1
  9. data/lib/heirloom/aws/simpledb.rb +25 -2
  10. data/lib/heirloom/catalog.rb +37 -0
  11. data/lib/heirloom/cli.rb +36 -3
  12. data/lib/heirloom/cli/authorize.rb +5 -1
  13. data/lib/heirloom/cli/catalog.rb +5 -1
  14. data/lib/heirloom/cli/cleanup.rb +74 -0
  15. data/lib/heirloom/cli/destroy.rb +5 -1
  16. data/lib/heirloom/cli/download.rb +5 -1
  17. data/lib/heirloom/cli/list.rb +5 -1
  18. data/lib/heirloom/cli/rotate.rb +5 -1
  19. data/lib/heirloom/cli/setup.rb +5 -1
  20. data/lib/heirloom/cli/show.rb +5 -1
  21. data/lib/heirloom/cli/tag.rb +5 -1
  22. data/lib/heirloom/cli/teardown.rb +21 -11
  23. data/lib/heirloom/cli/upload.rb +5 -1
  24. data/lib/heirloom/exceptions.rb +3 -0
  25. data/lib/heirloom/logger.rb +6 -1
  26. data/lib/heirloom/version.rb +1 -1
  27. data/spec/acl/s3_spec.rb +3 -2
  28. data/spec/aws/simpledb_spec.rb +35 -1
  29. data/spec/catalog_spec.rb +45 -2
  30. data/spec/cli/teardown_spec.rb +60 -28
  31. data/spec/cli_spec.rb +12 -0
  32. data/spec/fixtures/cassettes/Heirloom_AWS_SimpleDB/select/should_be_able_to_offset_results.yml +81 -0
  33. data/spec/fixtures/cassettes/Heirloom_AWS_SimpleDB/select/should_get_results.yml +34 -0
  34. data/spec/fixtures/cassettes/Heirloom_AWS_SimpleDB/select/should_yield_when_requested.yml +81 -0
  35. data/spec/fixtures/create_test_data.sh +28 -0
  36. data/spec/heirloom_spec.rb +11 -0
  37. data/spec/integration/authorize_spec.rb +79 -0
  38. data/spec/integration/cleanup_spec.rb +77 -0
  39. data/spec/logger_spec.rb +1 -1
  40. data/spec/spec_helper.rb +89 -5
  41. data/watchr.rb +101 -0
  42. metadata +84 -35
  43. data/.rvmrc +0 -1
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  .idea/
6
+ coverage
@@ -0,0 +1 @@
1
+ heirloom
@@ -0,0 +1 @@
1
+ 1.9.3
@@ -1,4 +1,7 @@
1
- ## HEAD:
1
+ ## 0.11.1 (06/18/2013):
2
+
3
+ * Fixes bug #139 by using get_object_acl instead of removed get_bucket_acl.
4
+ * Move to .ruby-version and .ruby-gemset instead of .rvmrc
2
5
 
3
6
  ## 0.11.0 (04/26/2013):
4
7
 
data/README.md CHANGED
@@ -44,3 +44,12 @@ Documentation
44
44
  -------------
45
45
 
46
46
  For more information, please view the [Heirloom Wiki](https://github.com/intuit/heirloom/wiki).
47
+
48
+ Contributing
49
+ -------------
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
@@ -19,10 +19,16 @@ Gem::Specification.new do |s|
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  # specify any dependencies here; for example:
22
- s.add_development_dependency "rspec", '~> 2.11.0'
22
+ s.add_development_dependency "hashie"
23
23
  s.add_development_dependency "rake"
24
+ s.add_development_dependency "rspec", '~> 2.11.0'
25
+ s.add_development_dependency "simplecov"
26
+ s.add_development_dependency "vcr", '= 2.4.0'
27
+ s.add_development_dependency "watchr"
24
28
 
25
- s.add_runtime_dependency 'fog', '~> 1.10.0'
29
+ s.add_runtime_dependency 'excon', '= 0.16'
30
+ s.add_runtime_dependency 'fog', '= 1.10.0'
26
31
  s.add_runtime_dependency 'trollop', '= 2.0'
27
32
  s.add_runtime_dependency 'xml-simple', '~> 1.1.2'
33
+
28
34
  end
@@ -13,3 +13,12 @@ require "heirloom/exceptions"
13
13
  require "heirloom/logger"
14
14
  require "heirloom/uploader"
15
15
  require "heirloom/version"
16
+
17
+ module Heirloom
18
+
19
+ def self.log
20
+ @logger ||= HeirloomLogger.new
21
+ end
22
+
23
+ end
24
+
@@ -19,7 +19,7 @@ module Heirloom
19
19
 
20
20
  key = "#{key_folder}/#{key_name}"
21
21
 
22
- current_acls = s3.get_bucket_acl bucket
22
+ current_acls = s3.get_object_acl :bucket => bucket, :object_name => key
23
23
  name = current_acls['Owner']['Name']
24
24
  id = current_acls['Owner']['ID']
25
25
 
@@ -43,8 +43,31 @@ module Heirloom
43
43
  @sdb.put_attributes domain, key, attributes, options
44
44
  end
45
45
 
46
- def select(query)
47
- @sdb.select(query).body['Items']
46
+ def select(query, opts = {})
47
+ has_more = true
48
+ next_token = nil
49
+ results = {}
50
+
51
+ if opts[:offset] && opts[:offset] > 0
52
+ limit = @sdb.select("#{query} limit #{opts[:offset]}").body
53
+ if limit['NextToken']
54
+ next_token = limit['NextToken']
55
+ else
56
+ has_more = false
57
+ end
58
+ end
59
+ while has_more
60
+ more = @sdb.select(query, 'NextToken' => next_token).body
61
+ more['Items'].each do |k, v|
62
+ block_given? ? yield(k, v) : results[k] = v
63
+ end
64
+ if more['NextToken']
65
+ next_token = more['NextToken']
66
+ else
67
+ has_more = false
68
+ end
69
+ end
70
+ results unless block_given?
48
71
  end
49
72
 
50
73
  def delete(domain, key)
@@ -13,6 +13,31 @@ module Heirloom
13
13
  @name = args[:name]
14
14
  end
15
15
 
16
+ def cleanup(opts = {})
17
+ opts[:num_to_keep] ||= 100
18
+ opts[:remove_preserved] ||= false
19
+
20
+ num_cleaned = 0
21
+
22
+ q = "select * from `#{domain}` where built_at > '2000-01-01T00:00:00.000Z' order by built_at desc"
23
+
24
+ sdb.select(q, :offset => opts[:num_to_keep]) do |key, item|
25
+ unless opts[:remove_preserved]
26
+ next if preserved?(item)
27
+ end
28
+
29
+ archive = Archive.new :config => @config, :name => @name, :id => key
30
+ archive.destroy
31
+ num_cleaned += 1
32
+ end
33
+
34
+ if num_cleaned == 0
35
+ Heirloom.log.info "No archives to delete."
36
+ else
37
+ Heirloom.log.info "#{num_cleaned} archive#{'s' unless num_cleaned == 1} deleted."
38
+ end
39
+ end
40
+
16
41
  def create_catalog_domain
17
42
  setup.create_catalog_domain
18
43
  end
@@ -47,6 +72,14 @@ module Heirloom
47
72
 
48
73
  private
49
74
 
75
+ def preserved?(item)
76
+ item['preserve'] && item['preserve'].include?('true')
77
+ end
78
+
79
+ def sdb
80
+ @sdb ||= Heirloom::AWS::SimpleDB.new :config => @config
81
+ end
82
+
50
83
  def add
51
84
  @add ||= Catalog::Add.new :config => @config,
52
85
  :name => @name
@@ -74,5 +107,9 @@ module Heirloom
74
107
  @verify ||= Catalog::Verify.new :config => @config
75
108
  end
76
109
 
110
+ def domain
111
+ "heirloom_#{@name}"
112
+ end
113
+
77
114
  end
78
115
  end
@@ -1,3 +1,4 @@
1
+ require 'hashie'
1
2
  require 'json'
2
3
  require 'trollop'
3
4
 
@@ -6,6 +7,7 @@ require 'heirloom/cli/shared'
6
7
 
7
8
  require 'heirloom/cli/authorize'
8
9
  require 'heirloom/cli/catalog'
10
+ require 'heirloom/cli/cleanup'
9
11
  require 'heirloom/cli/destroy'
10
12
  require 'heirloom/cli/download'
11
13
  require 'heirloom/cli/list'
@@ -26,6 +28,8 @@ module Heirloom
26
28
  CLI::Authorize.new.authorize
27
29
  when 'catalog'
28
30
  CLI::Catalog.new.all
31
+ when 'cleanup'
32
+ CLI::Cleanup.new.cleanup
29
33
  when 'destroy', 'delete'
30
34
  CLI::Destroy.new.destroy
31
35
  when 'download'
@@ -47,10 +51,39 @@ module Heirloom
47
51
  when '-v'
48
52
  puts Heirloom::VERSION
49
53
  else
50
- puts "Unkown command: '#{cmd}'." unless cmd == '-h'
51
- puts "heirloom [authorize|catalog|destroy|download|list|setup|show|tag|teardown|upload] OPTIONS"
52
- puts "Append -h for help on specific command."
54
+ puts "Unknown command: '#{cmd}'." unless cmd == '-h'
55
+ usage
53
56
  end
54
57
  end
58
+
59
+ def self.usage
60
+ puts ''
61
+ puts 'Usage: heirloom command [options]'
62
+ puts ''
63
+ puts 'Append -h for help on specific command.'
64
+ puts ''
65
+ puts 'Commands:'
66
+ commands.each do |cmd|
67
+ $stdout.printf " %-#{length_of_longest_command}s %s\n",
68
+ cmd.command_name,
69
+ cmd.command_summary
70
+ end
71
+ end
72
+
73
+ def self.commands
74
+ return @commands if @commands
75
+ klasses = Heirloom::CLI.constants.reject { |c| [:Shared, :Formatter].include?(c) }
76
+ @commands = klasses.map do |klass|
77
+ Hashie::Mash.new.tap do |h|
78
+ h[:command_name] = klass.downcase
79
+ h[:command_summary] = Heirloom::CLI.const_get(klass).command_summary
80
+ end
81
+ end
82
+ end
83
+
84
+ def self.length_of_longest_command
85
+ @length ||= commands.map { |c| c.command_name.length }.max
86
+ end
87
+
55
88
  end
56
89
  end
@@ -4,6 +4,10 @@ module Heirloom
4
4
 
5
5
  include Heirloom::CLI::Shared
6
6
 
7
+ def self.command_summary
8
+ 'Authorize access from another AWS account to an Heirloom'
9
+ end
10
+
7
11
  def initialize
8
12
  @opts = read_options
9
13
  @logger = HeirloomLogger.new :log_level => @opts[:level]
@@ -37,7 +41,7 @@ module Heirloom
37
41
  version Heirloom::VERSION
38
42
  banner <<-EOS
39
43
 
40
- Authorize access from another AWS account to an Heirloom.
44
+ #{Authorize.command_summary}.
41
45
 
42
46
  Usage:
43
47
 
@@ -4,6 +4,10 @@ module Heirloom
4
4
 
5
5
  include Heirloom::CLI::Shared
6
6
 
7
+ def self.command_summary
8
+ 'Show catalog of Heirlooms'
9
+ end
10
+
7
11
  def initialize
8
12
  @opts = read_options
9
13
  @logger = HeirloomLogger.new :log_level => @opts[:level]
@@ -41,7 +45,7 @@ module Heirloom
41
45
  version Heirloom::VERSION
42
46
  banner <<-EOS
43
47
 
44
- Show catalog of Heirlooms.
48
+ #{Catalog.command_summary}.
45
49
 
46
50
  Usage:
47
51
 
@@ -0,0 +1,74 @@
1
+ module Heirloom
2
+ module CLI
3
+ class Cleanup
4
+
5
+ include Heirloom::CLI::Shared
6
+
7
+ def self.command_summary
8
+ "Delete old heirlooms not tagged with 'preserve': true"
9
+ end
10
+
11
+ def initialize
12
+ @opts = read_options
13
+ @config = load_config :opts => @opts, :logger => Heirloom.log
14
+
15
+ Heirloom.log.level = @opts[:log_level]
16
+
17
+ ensure_valid_options(
18
+ :provided => @opts,
19
+ :required => [:name],
20
+ :config => @config
21
+ )
22
+
23
+ ensure_valid_region(
24
+ :region => @opts[:metadata_region],
25
+ :config => @config
26
+ )
27
+
28
+ ensure_domain_exists(
29
+ :name => @opts[:name],
30
+ :config => @config
31
+ )
32
+
33
+ end
34
+
35
+ def cleanup
36
+ cat = Heirloom::Catalog.new :name => @opts[:name], :config => @config
37
+ cat.cleanup :num_to_keep => @opts[:keep]
38
+ rescue Heirloom::Exceptions::CleanupFailed => e
39
+ Heirloom.log.error e.message
40
+ exit 1
41
+ end
42
+
43
+ private
44
+
45
+ def read_options
46
+ Trollop::options do
47
+ version Heirloom::VERSION
48
+ banner <<-EOS
49
+
50
+ #{Cleanup.command_summary}.
51
+
52
+ Usage:
53
+
54
+ heirloom cleanup -n NAME -k 10
55
+
56
+ EOS
57
+ opt :help, "Display Help"
58
+ opt :log_level, "Log level [debug|info|warn|error].", :type => :string,
59
+ :default => 'info'
60
+ opt :metadata_region, "AWS region to store Heirloom metadata.", :type => :string,
61
+ :default => 'us-west-1'
62
+ opt :name, "Name of Heirloom.", :type => :string
63
+ opt :keep, "Number of unpreserved heirlooms to keep.", :default => 100
64
+
65
+ opt :aws_access_key, "AWS Access Key ID", :type => :string,
66
+ :short => :none
67
+ opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
68
+ :short => :none
69
+ opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -4,6 +4,10 @@ module Heirloom
4
4
 
5
5
  include Heirloom::CLI::Shared
6
6
 
7
+ def self.command_summary
8
+ 'Destroy an Heirloom'
9
+ end
10
+
7
11
  def initialize
8
12
  @opts = read_options
9
13
  @logger = HeirloomLogger.new :log_level => @opts[:level]
@@ -37,7 +41,7 @@ module Heirloom
37
41
  version Heirloom::VERSION
38
42
  banner <<-EOS
39
43
 
40
- Destroy an Heirloom.
44
+ #{Destroy.command_summary}.
41
45
 
42
46
  Usage:
43
47
 
@@ -4,6 +4,10 @@ module Heirloom
4
4
 
5
5
  include Heirloom::CLI::Shared
6
6
 
7
+ def self.command_summary
8
+ 'Download Heirloom'
9
+ end
10
+
7
11
  def initialize
8
12
  @opts = read_options
9
13
  @logger = HeirloomLogger.new :log_level => @opts[:level]
@@ -56,7 +60,7 @@ module Heirloom
56
60
  version Heirloom::VERSION
57
61
  banner <<-EOS
58
62
 
59
- Download Heirloom.
63
+ #{Download.command_summary}.
60
64
 
61
65
  Usage:
62
66
 
@@ -4,6 +4,10 @@ module Heirloom
4
4
 
5
5
  include Heirloom::CLI::Shared
6
6
 
7
+ def self.command_summary
8
+ 'List Heirloom IDs'
9
+ end
10
+
7
11
  def initialize
8
12
  @opts = read_options
9
13
  @logger = HeirloomLogger.new :log_level => @opts[:level]
@@ -38,7 +42,7 @@ module Heirloom
38
42
  version Heirloom::VERSION
39
43
  banner <<-EOS
40
44
 
41
- List Heirloom IDs.
45
+ #{List.command_summary}.
42
46
 
43
47
  Usage:
44
48
 
@@ -4,6 +4,10 @@ module Heirloom
4
4
 
5
5
  include Heirloom::CLI::Shared
6
6
 
7
+ def self.command_summary
8
+ 'Rotate keys for an Heirloom'
9
+ end
10
+
7
11
  def initialize
8
12
  @opts = read_options
9
13
  @logger = HeirloomLogger.new :log_level => @opts[:level]
@@ -46,7 +50,7 @@ module Heirloom
46
50
  version Heirloom::VERSION
47
51
  banner <<-EOS
48
52
 
49
- Rotate keys for an Heirloom.
53
+ #{Rotate.command_summary}.
50
54
 
51
55
  Will download the heirloom to temp directory, decrypt, encrypt, and upload, replacing original.
52
56
 
@@ -4,6 +4,10 @@ module Heirloom
4
4
 
5
5
  include Heirloom::CLI::Shared
6
6
 
7
+ def self.command_summary
8
+ 'Setup S3 and SimpleDB in the given regions'
9
+ end
10
+
7
11
  def initialize
8
12
  @opts = read_options
9
13
  @logger = HeirloomLogger.new :log_level => @opts[:level]
@@ -63,7 +67,7 @@ module Heirloom
63
67
  version Heirloom::VERSION
64
68
  banner <<-EOS
65
69
 
66
- Setup S3 and SimpleDB in the given regions.
70
+ #{Setup.command_summary}.
67
71
 
68
72
  Usage:
69
73