heirloom 0.7.4 → 0.8.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 (40) hide show
  1. data/CHANGELOG +18 -0
  2. data/lib/heirloom/archive/builder.rb +13 -13
  3. data/lib/heirloom/archive/downloader.rb +8 -8
  4. data/lib/heirloom/archive/writer.rb +4 -4
  5. data/lib/heirloom/catalog.rb +2 -2
  6. data/lib/heirloom/catalog/add.rb +4 -3
  7. data/lib/heirloom/catalog/show.rb +2 -2
  8. data/lib/heirloom/cipher/data.rb +3 -3
  9. data/lib/heirloom/cli.rb +1 -0
  10. data/lib/heirloom/cli/catalog.rb +6 -3
  11. data/lib/heirloom/cli/download.rb +9 -9
  12. data/lib/heirloom/cli/formatter.rb +2 -0
  13. data/lib/heirloom/cli/formatter/catalog.rb +42 -0
  14. data/lib/heirloom/cli/formatter/show.rb +55 -0
  15. data/lib/heirloom/cli/list.rb +8 -2
  16. data/lib/heirloom/cli/setup.rb +15 -17
  17. data/lib/heirloom/cli/shared.rb +20 -7
  18. data/lib/heirloom/cli/show.rb +10 -1
  19. data/lib/heirloom/cli/teardown.rb +2 -2
  20. data/lib/heirloom/cli/upload.rb +11 -11
  21. data/lib/heirloom/version.rb +1 -1
  22. data/spec/archive/downloader_spec.rb +15 -15
  23. data/spec/archive/setup_spec.rb +6 -6
  24. data/spec/archive/teardowner_spec.rb +3 -3
  25. data/spec/archive/writer_spec.rb +1 -1
  26. data/spec/catalog/add_spec.rb +8 -7
  27. data/spec/catalog/show_spec.rb +6 -4
  28. data/spec/catalog_spec.rb +12 -12
  29. data/spec/cipher/data_spec.rb +1 -1
  30. data/spec/cli/catalog_spec.rb +46 -15
  31. data/spec/cli/download_spec.rb +13 -13
  32. data/spec/cli/formatter/catalog_spec.rb +39 -0
  33. data/spec/cli/formatter/show_spec.rb +29 -0
  34. data/spec/cli/list_spec.rb +31 -11
  35. data/spec/cli/setup_spec.rb +5 -4
  36. data/spec/cli/shared_spec.rb +9 -1
  37. data/spec/cli/show_spec.rb +45 -12
  38. data/spec/cli/teardown_spec.rb +2 -1
  39. data/spec/cli/upload_spec.rb +12 -12
  40. metadata +19 -12
data/CHANGELOG CHANGED
@@ -1,3 +1,21 @@
1
+ ## v0.8.0:
2
+
3
+ * Change base to bucket prefix through out code base
4
+ * Prevent setup from overwriting existing heirlooms
5
+ * Add human readable format as default for show
6
+ * Included JSON option to show
7
+ * Hide heirloom internal attribts in show
8
+ * Added all option to display all attributes via show
9
+ * Add human readable format as default for list
10
+ * Included JSON option in list
11
+ * Add human readable format as default for catalog
12
+ * Included JSON option in catalog
13
+ * Add name filter option to catalog
14
+
15
+ ## v0.7.5:
16
+
17
+ * Create random base if not specified by setup.
18
+
1
19
  ## v0.7.4:
2
20
 
3
21
  * Add support to read password from file
@@ -9,20 +9,20 @@ module Heirloom
9
9
 
10
10
  def initialize(args)
11
11
  @config = args[:config]
12
- @name = args[:name]
12
+ @name = args[:name]
13
13
  @domain = "heirloom_#{@name}"
14
- @id = args[:id]
14
+ @id = args[:id]
15
15
  @logger = @config.logger
16
16
  end
17
17
 
18
18
  def build(args)
19
- @source = args[:directory] ||= '.'
20
- @secret = args[:secret]
21
- @base = args[:base]
19
+ @source = args[:directory] ||= '.'
20
+ @secret = args[:secret]
21
+ @bucket_prefix = args[:bucket_prefix]
22
22
 
23
- directory = Directory.new :path => @source,
24
- :exclude => args[:exclude],
25
- :config => @config
23
+ directory = Directory.new :path => @source,
24
+ :exclude => args[:exclude],
25
+ :config => @config
26
26
 
27
27
  unless directory.build_artifact_from_directory :secret => @secret
28
28
  return false
@@ -63,11 +63,11 @@ module Heirloom
63
63
  end
64
64
 
65
65
  def create_artifact_record
66
- attributes = { 'built_by' => "#{user}@#{hostname}",
67
- 'built_at' => Time.now.utc.iso8601,
68
- 'encrypted' => encrypted?,
69
- 'base' => @base,
70
- 'id' => @id }
66
+ attributes = { 'built_by' => "#{user}@#{hostname}",
67
+ 'built_at' => Time.now.utc.iso8601,
68
+ 'encrypted' => encrypted?,
69
+ 'bucket_prefix' => @bucket_prefix,
70
+ 'id' => @id }
71
71
  @logger.info "Adding entry #{@id}."
72
72
  sdb.put_attributes @domain, @id, attributes
73
73
  end
@@ -4,17 +4,17 @@ module Heirloom
4
4
 
5
5
  def initialize(args)
6
6
  @config = args[:config]
7
- @name = args[:name]
8
- @id = args[:id]
7
+ @name = args[:name]
8
+ @id = args[:id]
9
9
  @logger = @config.logger
10
10
  end
11
11
 
12
12
  def download(args)
13
- @region = args[:region]
14
- @base_prefix = args[:base_prefix]
15
- extract = args[:extract]
16
- secret = args[:secret]
17
- output = args[:output] ||= './'
13
+ @region = args[:region]
14
+ @bucket_prefix = args[:bucket_prefix]
15
+ extract = args[:extract]
16
+ secret = args[:secret]
17
+ output = args[:output] ||= './'
18
18
 
19
19
  @logger.info "Downloading s3://#{bucket}/#{key} from #{@region}."
20
20
 
@@ -51,7 +51,7 @@ module Heirloom
51
51
  end
52
52
 
53
53
  def bucket
54
- "#{@base_prefix}-#{@region}"
54
+ "#{@bucket_prefix}-#{@region}"
55
55
  end
56
56
 
57
57
  def writer
@@ -26,7 +26,7 @@ module Heirloom
26
26
 
27
27
  def write_archive
28
28
  output_file = File.join @output, @file
29
- @logger.info "Writing archive to '#{output_file}'."
29
+ @logger.info "Writing Heirloom to '#{output_file}'."
30
30
  File.open(output_file, 'w') { |local_file| local_file.write @archive }
31
31
  end
32
32
 
@@ -35,15 +35,15 @@ module Heirloom
35
35
  end
36
36
 
37
37
  def extract_tmp_archive
38
- @logger.info "Extracting archive to '#{@output}'."
38
+ @logger.info "Extracting Heirloom to '#{@output}'."
39
39
  cmd = "tar xzf #{@tmp_archive} -C #{@output}"
40
40
  @logger.debug "Executing '#{cmd}'."
41
41
  `#{cmd}`
42
42
  if $?.success?
43
- @logger.debug "Archive succesfully extracted."
43
+ @logger.debug "Heirloom succesfully extracted."
44
44
  true
45
45
  else
46
- @logger.error "Error extracting archive."
46
+ @logger.error "Error extracting Heirloom."
47
47
  false
48
48
  end
49
49
  end
@@ -37,8 +37,8 @@ module Heirloom
37
37
  show.regions
38
38
  end
39
39
 
40
- def base
41
- show.base
40
+ def bucket_prefix
41
+ show.bucket_prefix
42
42
  end
43
43
 
44
44
  def all
@@ -9,14 +9,15 @@ module Heirloom
9
9
  end
10
10
 
11
11
  def add_to_catalog(args)
12
- regions = args[:regions]
13
- base = args[:base]
12
+ regions = args[:regions]
13
+ bucket_prefix = args[:bucket_prefix]
14
14
 
15
15
  @logger.info "Adding #{@name} to catalog."
16
16
 
17
17
  sdb.put_attributes 'heirloom',
18
18
  "heirloom_#{@name}",
19
- "regions" => regions, "base" => base
19
+ { "regions" => regions,
20
+ "bucket_prefix" => bucket_prefix }
20
21
 
21
22
  end
22
23
 
@@ -11,8 +11,8 @@ module Heirloom
11
11
  lookup :name => @name, :attribute => 'regions'
12
12
  end
13
13
 
14
- def base
15
- lookup(:name => @name, :attribute => 'base').first
14
+ def bucket_prefix
15
+ lookup(:name => @name, :attribute => 'bucket_prefix').first
16
16
  end
17
17
 
18
18
  private
@@ -15,7 +15,7 @@ module Heirloom
15
15
 
16
16
  return data unless args[:secret]
17
17
 
18
- @logger.info "Secret provided. Decrypting archive."
18
+ @logger.info "Secret provided. Decrypting Heirloom."
19
19
 
20
20
  @aes = OpenSSL::Cipher::AES256.new(:CBC)
21
21
  @aes.decrypt
@@ -25,9 +25,9 @@ module Heirloom
25
25
  @aes.update(data) + @aes.final
26
26
  rescue OpenSSL::Cipher::CipherError => e
27
27
  if e.message == 'wrong final block length'
28
- @logger.error 'This archive does not appear to be encrypted.'
28
+ @logger.error 'This Heirloom does not appear to be encrypted.'
29
29
  end
30
- @logger.error "Unable to decrypt archive: '#{e.message}'"
30
+ @logger.error "Unable to decrypt Heirloom: '#{e.message}'"
31
31
  false
32
32
  end
33
33
  end
@@ -12,6 +12,7 @@ require 'heirloom/cli/tag'
12
12
  require 'heirloom/cli/download'
13
13
  require 'heirloom/cli/destroy'
14
14
  require 'heirloom/cli/teardown'
15
+ require 'heirloom/cli/formatter'
15
16
 
16
17
  module Heirloom
17
18
  module CLI
@@ -21,10 +21,12 @@ module Heirloom
21
21
  end
22
22
 
23
23
  def all
24
- if @opts[:details]
24
+ if @opts[:json]
25
25
  jj catalog_with_heirloom_prefix_removed
26
26
  else
27
- jj catalog_with_heirloom_prefix_removed.keys
27
+ formatter = Heirloom::CLI::Formatter::Catalog.new
28
+ puts formatter.format :catalog => catalog_with_heirloom_prefix_removed,
29
+ :name => @opts[:name]
28
30
  end
29
31
  end
30
32
 
@@ -49,7 +51,8 @@ EOS
49
51
  opt :help, "Display Help"
50
52
  opt :level, "Log level [debug|info|warn|error].", :type => :string,
51
53
  :default => 'info'
52
- opt :details, "Include details."
54
+ opt :json, "Dump full catalog as raw JSON."
55
+ opt :name, "Name of Heirloom to show full details.", :type => :string
53
56
  opt :metadata_region, "AWS region to store Heirloom metadata.", :type => :string,
54
57
  :default => 'us-west-1'
55
58
  opt :aws_access_key, "AWS Access Key ID", :type => :string,
@@ -25,10 +25,10 @@ module Heirloom
25
25
  :id => id,
26
26
  :config => @config
27
27
 
28
- # Lookup region & base from simpledb unless specified
28
+ # Lookup region & bucket_prefix from simpledb unless specified
29
29
  # To Do, valid validation message that simpledb exists
30
30
  @region = @opts[:region] || @catalog.regions.first
31
- @base = @opts[:base] || @catalog.base
31
+ @bucket_prefix = @opts[:bucket_prefix] || @catalog.bucket_prefix
32
32
  end
33
33
 
34
34
  def download
@@ -37,11 +37,11 @@ module Heirloom
37
37
  :config => @config
38
38
  ensure_valid_secret :secret => secret,
39
39
  :config => @config
40
- archive = @archive.download :output => @opts[:output],
41
- :extract => @opts[:extract],
42
- :region => @region,
43
- :base_prefix => @base,
44
- :secret => secret
40
+ archive = @archive.download :output => @opts[:output],
41
+ :extract => @opts[:extract],
42
+ :region => @region,
43
+ :bucket_prefix => @bucket_prefix,
44
+ :secret => secret
45
45
  exit 1 unless archive
46
46
  end
47
47
 
@@ -60,10 +60,10 @@ heirloom download -n NAME -o OUTPUT_DIRECTORY
60
60
 
61
61
  If id (-i) is not specified, the latest id will be downloaded.
62
62
 
63
- To download Heirloom without looking up details in SimpleDB, specify region (-r), ID (-i) and base (-b) options.
63
+ To download Heirloom without looking up details in SimpleDB, specify region (-r), ID (-i) and bucket_prefix (-b) options.
64
64
 
65
65
  EOS
66
- opt :base, "Base of the Heirloom to download.", :type => :string
66
+ opt :bucket_prefix, "Bucket prefix of the Heirloom to download.", :type => :string
67
67
  opt :extract, "Extract the Heirloom into the given output path.", :short => "-x"
68
68
  opt :help, "Display Help"
69
69
  opt :id, "ID of the Heirloom to download.", :type => :string
@@ -0,0 +1,2 @@
1
+ require 'heirloom/cli/formatter/catalog'
2
+ require 'heirloom/cli/formatter/show'
@@ -0,0 +1,42 @@
1
+ module Heirloom
2
+ module CLI
3
+ module Formatter
4
+ class Catalog
5
+ def format(args)
6
+ @catalog = args[:catalog]
7
+ @name = args[:name]
8
+
9
+ return summary unless @name
10
+
11
+ return "Heirloom #{@name} not found in catalog." unless name_exists?
12
+
13
+ filter_by_name
14
+ details
15
+ end
16
+
17
+ private
18
+
19
+ def name_exists?
20
+ @catalog.include? @name
21
+ end
22
+
23
+ def filter_by_name
24
+ @catalog.select! {|k| @name == k }
25
+ end
26
+
27
+ def summary
28
+ @catalog.keys.join "\n"
29
+ end
30
+
31
+ def details
32
+ data = @catalog.each_pair.map do |k,v|
33
+ d = k + "\n"
34
+ d << " Regions : " + @catalog[k]["regions"].join(", ") + "\n"
35
+ d << " Bucket Prefix : " + @catalog[k]["bucket_prefix"].first
36
+ end
37
+ data.join "\n"
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,55 @@
1
+ module Heirloom
2
+ module CLI
3
+ module Formatter
4
+ class Show
5
+
6
+ def format(args)
7
+ @all = args[:all]
8
+ @attributes = args[:attributes]
9
+ format_attributes
10
+ end
11
+
12
+ private
13
+
14
+ def format_attributes
15
+ remove_internal_attributes unless @all
16
+ formated = @attributes.each_pair.map do |key,value|
17
+ "#{padded_key(key)}: #{value}"
18
+ end
19
+ formated.join("\n")
20
+ end
21
+
22
+ def padded_key(key)
23
+ max_length ||= longest_attribute_length
24
+ key + (" " * (max_length - key.length + 1))
25
+ end
26
+
27
+ def longest_attribute_length
28
+ longest_length = 0
29
+ @attributes.keys.each do |k|
30
+ longest_length = k.length if k.length > longest_length
31
+ end
32
+ longest_length
33
+ end
34
+
35
+ def remove_internal_attributes
36
+ @attributes.delete_if { |key| is_internal_attribute? key }
37
+ end
38
+
39
+ def is_internal_attribute?(attribute)
40
+ return true if is_reserved? attribute
41
+ return true if is_endpoint? attribute
42
+ false
43
+ end
44
+
45
+ def is_reserved?(attribute)
46
+ ['bucket_prefix', 'built_at', 'built_by'].include? attribute
47
+ end
48
+
49
+ def is_endpoint?(attribute)
50
+ attribute.match('^.*-.*-\d*-s3|http|https-url$')
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -22,8 +22,13 @@ module Heirloom
22
22
  end
23
23
 
24
24
  def list(count = @opts[:count])
25
- @logger.debug "#{@archive.count} archives found."
26
- jj @archive.list(count)
25
+ @logger.debug "#{@archive.count} IDs found."
26
+ list = @archive.list count
27
+ if @opts[:json]
28
+ jj list
29
+ else
30
+ puts list.join "\n"
31
+ end
27
32
  end
28
33
 
29
34
  private
@@ -43,6 +48,7 @@ EOS
43
48
  opt :count, "Number of IDs to return.", :type => :integer,
44
49
  :default => 10
45
50
  opt :help, "Display Help"
51
+ opt :json, "Display output as raw JSON."
46
52
  opt :level, "Log level [debug|info|warn|error].", :type => :string,
47
53
  :default => 'info'
48
54
  opt :metadata_region, "AWS region to store Heirloom metadata.", :type => :string,
@@ -11,8 +11,9 @@ module Heirloom
11
11
  :opts => @opts
12
12
 
13
13
  ensure_valid_options :provided => @opts,
14
- :required => [:metadata_region, :region,
15
- :name, :base],
14
+ :required => [:metadata_region,
15
+ :bucket_prefix,
16
+ :region, :name],
16
17
  :config => @config
17
18
 
18
19
  @catalog = Heirloom::Catalog.new :name => @opts[:name],
@@ -30,18 +31,16 @@ module Heirloom
30
31
  :regions => @opts[:region]
31
32
 
32
33
  @catalog.create_catalog_domain
33
- unless @catalog.add_to_catalog :regions => @opts[:region],
34
- :base => @opts[:base]
35
- if @opts[:force]
36
- @logger.warn "#{@opts[:name]} already exists."
37
- else
38
- @logger.warn "#{@opts[:name]} already exists, exiting."
39
- exit 1
40
- end
41
- end
34
+
35
+ ensure_entry_does_not_exist_in_catalog :config => @config,
36
+ :catalog => @catalog,
37
+ :entry => @opts[:name]
38
+
39
+ @catalog.add_to_catalog :regions => @opts[:region],
40
+ :bucket_prefix => @opts[:bucket_prefix]
42
41
 
43
42
  @archive.setup :regions => @opts[:region],
44
- :bucket_prefix => @opts[:base]
43
+ :bucket_prefix => @opts[:bucket_prefix]
45
44
  end
46
45
 
47
46
  private
@@ -55,14 +54,13 @@ Setup S3 and SimpleDB in the given regions.
55
54
 
56
55
  Usage:
57
56
 
58
- heirloom setup -b BASE -n NAME -m REGION1 -r REGION1 -r REGION2
57
+ heirloom setup -b BUCKET_PREFIX -n NAME -m REGION1 -r REGION1 -r REGION2
59
58
 
60
59
  EOS
61
- opt :base, "Base prefix which will be combined with given regions \
62
- region. For example: '-b test -r us-west-1 -r us-east-1' will create bucket test-us-west-1 \
63
- in us-west-1 and test-us-east-1 in us-east-1.", :type => :string
60
+ opt :bucket_prefix, "The bucket prefix will be combined with specified \
61
+ regions to create the required buckets. For example: '-b test -r us-west-1 -r \
62
+ us-east-1' will create bucket test-us-west-1 in us-west-1 and test-us-east-1 in us-east-1.", :type => :string
64
63
  opt :help, "Display Help"
65
- opt :force, "Force setup even if entry already exists in catalog."
66
64
  opt :level, "Log level [debug|info|warn|error].", :type => :string,
67
65
  :default => 'info'
68
66
  opt :metadata_region, "AWS region to store Heirloom metadata.", :type => :string,