heirloom 0.11.0 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +4 -1
- data/README.md +9 -0
- data/heirloom.gemspec +8 -2
- data/lib/heirloom.rb +9 -0
- data/lib/heirloom/acl/s3.rb +1 -1
- data/lib/heirloom/aws/simpledb.rb +25 -2
- data/lib/heirloom/catalog.rb +37 -0
- data/lib/heirloom/cli.rb +36 -3
- data/lib/heirloom/cli/authorize.rb +5 -1
- data/lib/heirloom/cli/catalog.rb +5 -1
- data/lib/heirloom/cli/cleanup.rb +74 -0
- data/lib/heirloom/cli/destroy.rb +5 -1
- data/lib/heirloom/cli/download.rb +5 -1
- data/lib/heirloom/cli/list.rb +5 -1
- data/lib/heirloom/cli/rotate.rb +5 -1
- data/lib/heirloom/cli/setup.rb +5 -1
- data/lib/heirloom/cli/show.rb +5 -1
- data/lib/heirloom/cli/tag.rb +5 -1
- data/lib/heirloom/cli/teardown.rb +21 -11
- data/lib/heirloom/cli/upload.rb +5 -1
- data/lib/heirloom/exceptions.rb +3 -0
- data/lib/heirloom/logger.rb +6 -1
- data/lib/heirloom/version.rb +1 -1
- data/spec/acl/s3_spec.rb +3 -2
- data/spec/aws/simpledb_spec.rb +35 -1
- data/spec/catalog_spec.rb +45 -2
- data/spec/cli/teardown_spec.rb +60 -28
- data/spec/cli_spec.rb +12 -0
- data/spec/fixtures/cassettes/Heirloom_AWS_SimpleDB/select/should_be_able_to_offset_results.yml +81 -0
- data/spec/fixtures/cassettes/Heirloom_AWS_SimpleDB/select/should_get_results.yml +34 -0
- data/spec/fixtures/cassettes/Heirloom_AWS_SimpleDB/select/should_yield_when_requested.yml +81 -0
- data/spec/fixtures/create_test_data.sh +28 -0
- data/spec/heirloom_spec.rb +11 -0
- data/spec/integration/authorize_spec.rb +79 -0
- data/spec/integration/cleanup_spec.rb +77 -0
- data/spec/logger_spec.rb +1 -1
- data/spec/spec_helper.rb +89 -5
- data/watchr.rb +101 -0
- metadata +84 -35
- data/.rvmrc +0 -1
data/.gitignore
CHANGED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
heirloom
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3
|
data/CHANGELOG.md
CHANGED
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
|
data/heirloom.gemspec
CHANGED
@@ -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 "
|
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 '
|
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
|
data/lib/heirloom.rb
CHANGED
data/lib/heirloom/acl/s3.rb
CHANGED
@@ -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
|
-
|
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)
|
data/lib/heirloom/catalog.rb
CHANGED
@@ -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
|
data/lib/heirloom/cli.rb
CHANGED
@@ -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 "
|
51
|
-
|
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
|
44
|
+
#{Authorize.command_summary}.
|
41
45
|
|
42
46
|
Usage:
|
43
47
|
|
data/lib/heirloom/cli/catalog.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/heirloom/cli/destroy.rb
CHANGED
@@ -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
|
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
|
63
|
+
#{Download.command_summary}.
|
60
64
|
|
61
65
|
Usage:
|
62
66
|
|
data/lib/heirloom/cli/list.rb
CHANGED
@@ -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
|
45
|
+
#{List.command_summary}.
|
42
46
|
|
43
47
|
Usage:
|
44
48
|
|
data/lib/heirloom/cli/rotate.rb
CHANGED
@@ -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
|
53
|
+
#{Rotate.command_summary}.
|
50
54
|
|
51
55
|
Will download the heirloom to temp directory, decrypt, encrypt, and upload, replacing original.
|
52
56
|
|
data/lib/heirloom/cli/setup.rb
CHANGED
@@ -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
|
70
|
+
#{Setup.command_summary}.
|
67
71
|
|
68
72
|
Usage:
|
69
73
|
|