heirloom 0.5.0rc4 → 0.6.0rc1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ ## v0.6.0:
2
+
3
+ * Allowing engineer to specify region for metadata
4
+ * Ensuring metadata is in an upload region
5
+ * Split setup into seperate subcommand
6
+ * Perform additional validation on CLI options
7
+
1
8
  ## v0.5.0:
2
9
 
3
10
  * Verify domain exists for all cmds except build & download
data/README.md CHANGED
@@ -24,11 +24,22 @@ aws:
24
24
 
25
25
  * **access_key / secret_key**: AWS account credentials where you would like the archives stored.
26
26
 
27
+ Proxy Support
28
+ -------------
29
+
30
+ Heirloom uses the http_proxy & https_proxy variables.
31
+
32
+ ```
33
+ export http_proxy=http://1.2.3.4:80
34
+ export http_proxys=http://1.2.3.4:80
35
+ ```
36
+
27
37
  Platforms
28
38
  ---------
29
39
 
30
40
  Currently I support AWS S3 for object storage and AWS SimpleDB for metadata management. One day I'd like to expand to other providers.
31
41
 
42
+
32
43
  Documentation
33
44
  -------------
34
45
 
@@ -14,6 +14,7 @@ module Heirloom
14
14
  @bucket_prefix = args[:bucket_prefix]
15
15
  create_buckets
16
16
  create_domain
17
+ @logger.info "Setup complete."
17
18
  end
18
19
 
19
20
  private
@@ -33,7 +34,12 @@ module Heirloom
33
34
  end
34
35
 
35
36
  def create_domain
36
- sdb.create_domain @domain unless verifier.domain_exists?
37
+ region = @config.metadata_region
38
+
39
+ unless verifier.domain_exists?
40
+ @logger.info "Creating domain #{@name} in #{region}."
41
+ sdb.create_domain @domain
42
+ end
37
43
  end
38
44
 
39
45
  def verifier
@@ -16,7 +16,7 @@ module Heirloom
16
16
  value = args[:value]
17
17
 
18
18
  sdb.put_attributes @domain, @id, { attribute => value }, { :replace => attribute }
19
- @logger.info "Updated #{@name} (#{@id}): #{attribute} = #{value}."
19
+ @logger.info "Tagged #{@name} (#{@id}): #{attribute} = #{value}."
20
20
  end
21
21
 
22
22
  private
@@ -33,17 +33,24 @@ module Heirloom
33
33
  :region => region
34
34
 
35
35
  if s3.get_bucket bucket
36
- @logger.debug "Bucket #{bucket} exists in #{region}"
36
+ @logger.debug "Bucket '#{bucket}' exists in '#{region}'."
37
37
  true
38
38
  else
39
- @logger.debug "Bucket #{bucket} in #{region} does not exist"
39
+ @logger.info "Bucket '#{bucket}' does not exist in '#{region}'."
40
40
  false
41
41
  end
42
42
  end
43
43
 
44
44
  def domain_exists?
45
45
  domain = "heirloom_#{@name}"
46
- sdb.domain_exists? domain
46
+ region = @config.metadata_region
47
+ if sdb.domain_exists? domain
48
+ @logger.debug "Domain '#{@name}' exists in '#{region}'."
49
+ true
50
+ else
51
+ @logger.info "Domain '#{@name}' does not exist in '#{region}'."
52
+ false
53
+ end
47
54
  end
48
55
 
49
56
  private
@@ -8,7 +8,7 @@ module Heirloom
8
8
  @config = args[:config]
9
9
  @sdb = Fog::AWS::SimpleDB.new :aws_access_key_id => @config.access_key,
10
10
  :aws_secret_access_key => @config.secret_key,
11
- :region => @config.primary_region
11
+ :region => @config.metadata_region
12
12
  end
13
13
 
14
14
  def domains
@@ -13,12 +13,15 @@ module Heirloom
13
13
  ensure_valid_options :provided => @opts,
14
14
  :required => [:accounts, :name, :id],
15
15
  :config => @config
16
-
17
- ensure_domain_exists :name => @opts[:name], :config => @config
18
-
16
+ ensure_valid_region :region => @opts[:metadata_region],
17
+ :config => @config
18
+ ensure_domain_exists :name => @opts[:name],
19
+ :config => @config
19
20
  @archive = Archive.new :name => @opts[:name],
20
21
  :id => @opts[:id],
21
22
  :config => @config
23
+ ensure_archive_exists :archive => @archive,
24
+ :config => @config
22
25
  end
23
26
 
24
27
  def authorize
@@ -49,6 +52,8 @@ EOS
49
52
  opt :id, "ID of the archive to authorize.", :type => :string
50
53
  opt :level, "Log level [debug|info|warn|error].", :type => :string,
51
54
  :default => 'info'
55
+ opt :metadata_region, "AWS region to store Heirloom metadata.", :type => :string,
56
+ :default => 'us-west-1'
52
57
  opt :name, "Name of archive.", :type => :string
53
58
  opt :aws_access_key, "AWS Access Key ID", :type => :string,
54
59
  :short => :none
@@ -13,7 +13,8 @@ module Heirloom
13
13
  ensure_valid_options :provided => @opts,
14
14
  :required => [:name, :id],
15
15
  :config => @config
16
-
16
+ ensure_valid_region :region => @opts[:metadata_region],
17
+ :config => @config
17
18
  ensure_domain_exists :name => @opts[:name], :config => @config
18
19
 
19
20
  @name = @opts[:name]
@@ -21,6 +22,8 @@ module Heirloom
21
22
  @archive = Archive.new :name => @name,
22
23
  :id => @id,
23
24
  :config => @config
25
+ ensure_archive_exists :archive => @archive,
26
+ :config => @config
24
27
  end
25
28
 
26
29
  def destroy
@@ -45,6 +48,8 @@ EOS
45
48
  opt :id, "ID of the archive to display.", :type => :string
46
49
  opt :level, "Log level [debug|info|warn|error].", :type => :string,
47
50
  :default => 'info'
51
+ opt :metadata_region, "AWS region to store Heirloom metadata.", :type => :string,
52
+ :default => 'us-west-1'
48
53
  opt :name, "Name of archive.", :type => :string
49
54
  opt :aws_access_key, "AWS Access Key ID", :type => :string,
50
55
  :short => :none
@@ -11,7 +11,7 @@ module Heirloom
11
11
  :opts => @opts
12
12
 
13
13
  ensure_valid_options :provided => @opts,
14
- :required => [:base_prefix, :name, :id, :output],
14
+ :required => [:base, :name, :id, :output],
15
15
  :config => @config
16
16
 
17
17
  @archive = Archive.new :name => @opts[:name],
@@ -25,7 +25,7 @@ module Heirloom
25
25
  archive = @archive.download :output => @opts[:output],
26
26
  :region => @opts[:region],
27
27
  :extract => @opts[:extract],
28
- :base_prefix => @opts[:base_prefix],
28
+ :base_prefix => @opts[:base],
29
29
  :secret => @opts[:secret]
30
30
  exit 1 unless archive
31
31
  end
@@ -44,14 +44,14 @@ Usage:
44
44
  heirloom download -n NAME -i ID -r REGION -o OUTPUT_DIRECTORY
45
45
 
46
46
  EOS
47
- opt :base_prefix, "Base prefix of the archive to download.", :type => :string
47
+ opt :base, "Base of the archive to download.", :type => :string
48
+ opt :extract, "Extract the archive in the given output path.", :short => "-x"
48
49
  opt :help, "Display Help"
49
50
  opt :id, "ID of the archive to download.", :type => :string
50
- opt :name, "Name of archive.", :type => :string
51
51
  opt :level, "Log level [debug|info|warn|error].", :type => :string,
52
52
  :default => 'info'
53
- opt :output, "Path to download archive. Must be existing directory.", :type => :string
54
- opt :extract, "Extract the archive in the given output path.", :short => "-x"
53
+ opt :name, "Name of archive.", :type => :string
54
+ opt :output, "Path to output downloaded archive. Must be existing directory.", :type => :string
55
55
  opt :region, "Region to download archive.", :type => :string,
56
56
  :default => 'us-west-1'
57
57
  opt :secret, "Secret for ecrypted archive.", :type => :string
@@ -13,7 +13,8 @@ module Heirloom
13
13
  ensure_valid_options :provided => @opts,
14
14
  :required => [:name],
15
15
  :config => @config
16
-
16
+ ensure_valid_region :region => @opts[:metadata_region],
17
+ :config => @config
17
18
  ensure_domain_exists :name => @opts[:name], :config => @config
18
19
 
19
20
  @archive = Archive.new :name => @opts[:name],
@@ -44,6 +45,8 @@ EOS
44
45
  opt :help, "Display Help"
45
46
  opt :level, "Log level [debug|info|warn|error].", :type => :string,
46
47
  :default => 'info'
48
+ opt :metadata_region, "AWS region to store Heirloom metadata.", :type => :string,
49
+ :default => 'us-west-1'
47
50
  opt :name, "Name of archive.", :type => :string
48
51
  opt :aws_access_key, "AWS Access Key ID", :type => :string,
49
52
  :short => :none
@@ -0,0 +1,69 @@
1
+ module Heirloom
2
+ module CLI
3
+ class Setup
4
+
5
+ include Heirloom::CLI::Shared
6
+
7
+ def initialize
8
+ @opts = read_options
9
+ @logger = HeirloomLogger.new :log_level => @opts[:level]
10
+ @config = load_config :logger => @logger,
11
+ :opts => @opts
12
+
13
+ ensure_valid_options :provided => @opts,
14
+ :required => [:metadata_region, :region,
15
+ :name, :base],
16
+ :config => @config
17
+ ensure_valid_region :region => @opts[:metadata_region],
18
+ :config => @config
19
+ ensure_valid_regions :regions => @opts[:region],
20
+ :config => @config
21
+
22
+ @archive = Archive.new :name => @opts[:name],
23
+ :config => @config
24
+ end
25
+
26
+ def setup
27
+ ensure_metadata_in_upload_region :config => @config,
28
+ :regions => @opts[:region]
29
+ @archive.setup :regions => @opts[:region],
30
+ :bucket_prefix => @opts[:base]
31
+ end
32
+
33
+ private
34
+
35
+ def read_options
36
+ Trollop::options do
37
+ version Heirloom::VERSION
38
+ banner <<-EOS
39
+
40
+ Setup S3 and SimpleDB in the given regions.
41
+
42
+ Usage:
43
+
44
+ heirloom setup -b BASE -n NAME -m REGION1 -r REGION1 -r REGION2
45
+
46
+ EOS
47
+ opt :base, "Base prefix which will be combined with given regions \
48
+ region. For example: '-b test -r us-west-1 -r us-east-1' will create bucket test-us-west-1 \
49
+ in us-west-1 and test-us-east-1 in us-east-1.", :type => :string
50
+ opt :help, "Display Help"
51
+ opt :level, "Log level [debug|info|warn|error].", :type => :string,
52
+ :default => 'info'
53
+ opt :metadata_region, "AWS region to store Heirloom metadata.", :type => :string,
54
+ :default => 'us-west-1'
55
+ opt :name, "Name of archive.", :type => :string
56
+ opt :region, "AWS Region(s) to upload archive. \
57
+ Can be specified multiple times.", :type => :string,
58
+ :multi => true,
59
+ :default => 'us-west-1'
60
+ opt :aws_access_key, "AWS Access Key ID", :type => :string,
61
+ :short => :none
62
+ opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
63
+ :short => :none
64
+ end
65
+ end
66
+
67
+ end
68
+ end
69
+ end
@@ -6,8 +6,9 @@ module Heirloom
6
6
  opts = args[:opts]
7
7
  logger = args[:logger]
8
8
  config = Config.new :logger => logger
9
- config.access_key = opts[:aws_access_key] if opts[:aws_access_key_given]
10
- config.secret_key = opts[:aws_secret_key] if opts[:aws_secret_key_given]
9
+ config.access_key = opts[:aws_access_key] if opts[:aws_access_key]
10
+ config.secret_key = opts[:aws_secret_key] if opts[:aws_secret_key]
11
+ config.metadata_region = opts[:metadata_region] if opts[:metadata_region]
11
12
  config
12
13
  end
13
14
 
@@ -45,6 +46,41 @@ module Heirloom
45
46
  exit 1 unless missing_opts.empty?
46
47
  end
47
48
 
49
+ def ensure_valid_regions(args)
50
+ regions = args[:regions]
51
+ config = args[:config]
52
+ regions.each do |region|
53
+ ensure_valid_region :region => region,
54
+ :config => config
55
+ end
56
+ end
57
+
58
+ def ensure_valid_region(args)
59
+ config = args[:config]
60
+ region = args[:region]
61
+ logger = config.logger
62
+ valid_regions = ['us-east-1', 'us-west-1', 'us-west-2']
63
+
64
+ unless valid_regions.include? region
65
+ logger.error "'#{region}' is not a valid region."
66
+ logger.error "Valid regions: #{valid_regions.join(', ')}"
67
+ exit 1
68
+ end
69
+ end
70
+
71
+ def ensure_metadata_in_upload_region(args)
72
+ config = args[:config]
73
+ regions = args[:regions]
74
+ logger = config.logger
75
+
76
+ unless regions.include? config.metadata_region
77
+ logger.error "Upload Regions: '#{regions.join(', ')}'."
78
+ logger.error "Metadata Region: '#{config.metadata_region}'."
79
+ logger.error "Upload regions must include metadata region."
80
+ exit 1
81
+ end
82
+ end
83
+
48
84
  def ensure_directory(args)
49
85
  config = args[:config]
50
86
  path = args[:path]
@@ -56,16 +92,46 @@ module Heirloom
56
92
  end
57
93
  end
58
94
 
95
+ def ensure_buckets_exist(args)
96
+ config = args[:config]
97
+ base = args[:base]
98
+ name = args[:name]
99
+ regions = args[:regions]
100
+ logger = config.logger
101
+
102
+ archive = Archive.new :name => name,
103
+ :config => config
104
+
105
+ unless archive.buckets_exist? :regions => regions,
106
+ :bucket_prefix => base
107
+ logger.error "Required buckets for '#{base}' do not exist."
108
+ logger.error "Run 'heirloom setup -h' for help setting up new region."
109
+ exit 1
110
+ end
111
+ end
112
+
59
113
  def ensure_domain_exists(args)
60
114
  config = args[:config]
61
- name = args[:name]
115
+ name = args[:name]
62
116
  logger = config.logger
63
117
 
64
118
  archive = Archive.new :name => name,
65
119
  :config => config
66
120
 
67
121
  unless archive.domain_exists?
68
- logger.error "Heirloom domain does not exist."
122
+ logger.error "Metadata domain '#{name}' does not exist in '#{config.metadata_region}'."
123
+ logger.error "Run 'heirloom setup -h' for help setting up new region."
124
+ exit 1
125
+ end
126
+ end
127
+
128
+ def ensure_archive_exists(args)
129
+ config = args[:config]
130
+ archive = args[:archive]
131
+ logger = config.logger
132
+
133
+ unless archive.exists?
134
+ logger.error "Archive does not exist."
69
135
  exit 1
70
136
  end
71
137
  end
@@ -13,13 +13,15 @@ module Heirloom
13
13
  ensure_valid_options :provided => @opts,
14
14
  :required => [:name],
15
15
  :config => @config
16
-
16
+ ensure_valid_region :region => @opts[:metadata_region],
17
+ :config => @config
17
18
  ensure_domain_exists :name => @opts[:name], :config => @config
18
-
19
19
  id = @opts[:id] ? @opts[:id] : latest_id
20
20
  @archive = Archive.new :name => @opts[:name],
21
21
  :config => @config,
22
22
  :id => id
23
+ ensure_archive_exists :archive => @archive,
24
+ :config => @config
23
25
  end
24
26
 
25
27
  def show
@@ -49,10 +51,12 @@ If -i is ommited, latest ID is displayed.
49
51
 
50
52
  EOS
51
53
  opt :help, "Display Help"
54
+ opt :id, "ID of the archive to display.", :type => :string
52
55
  opt :level, "Log level [debug|info|warn|error].", :type => :string,
53
56
  :default => 'info'
57
+ opt :metadata_region, "AWS region to store Heirloom metadata.", :type => :string,
58
+ :default => 'us-west-1'
54
59
  opt :name, "Name of archive.", :type => :string
55
- opt :id, "ID of the archive to display.", :type => :string
56
60
  opt :aws_access_key, "AWS Access Key ID", :type => :string,
57
61
  :short => :none
58
62
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
@@ -13,12 +13,15 @@ module Heirloom
13
13
  ensure_valid_options :provided => @opts,
14
14
  :required => [:name, :id, :attribute, :value],
15
15
  :config => @config
16
-
16
+ ensure_valid_region :region => @opts[:metadata_region],
17
+ :config => @config
17
18
  ensure_domain_exists :name => @opts[:name], :config => @config
18
19
 
19
20
  @archive = Archive.new :name => @opts[:name],
20
21
  :id => @opts[:id],
21
22
  :config => @config
23
+ ensure_archive_exists :archive => @archive,
24
+ :config => @config
22
25
  end
23
26
 
24
27
  def tag
@@ -49,6 +52,8 @@ EOS
49
52
  opt :id, "ID of the archive to display.", :type => :string
50
53
  opt :level, "Log level [debug|info|warn|error].", :type => :string,
51
54
  :default => 'info'
55
+ opt :metadata_region, "AWS region to store Heirloom metadata.", :type => :string,
56
+ :default => 'us-west-1'
52
57
  opt :name, "Name of archive.", :type => :string
53
58
  opt :value, "Value of attribute.", :type => :string,
54
59
  :short => 'u'
@@ -21,11 +21,22 @@ module Heirloom
21
21
  end
22
22
 
23
23
  def upload
24
- ensure_directory :path => @opts[:directory], :config => @config
25
- ensure_valid_secret :secret => @opts[:secret], :config => @config
26
-
27
- @archive.setup :regions => @opts[:region],
28
- :bucket_prefix => @opts[:base]
24
+ ensure_valid_region :region => @opts[:metadata_region],
25
+ :config => @config
26
+ ensure_valid_regions :regions => @opts[:region],
27
+ :config => @config
28
+ ensure_domain_exists :name => @opts[:name],
29
+ :config => @config
30
+ ensure_buckets_exist :base => @opts[:base],
31
+ :name => @opts[:name],
32
+ :regions => @opts[:region],
33
+ :config => @config
34
+ ensure_directory :path => @opts[:directory],
35
+ :config => @config
36
+ ensure_valid_secret :secret => @opts[:secret],
37
+ :config => @config
38
+ ensure_metadata_in_upload_region :config => @config,
39
+ :regions => @opts[:region]
29
40
 
30
41
  @archive.destroy :keep_domain => true if @archive.exists?
31
42
 
@@ -71,10 +82,14 @@ Can be specified multiple times.", :type => :string, :multi => true
71
82
  opt :id, "ID for archive (when -g specified, assumed to be GIT sha).", :type => :string
72
83
  opt :level, "Log level [debug|info|warn|error].", :type => :string,
73
84
  :default => 'info'
85
+ opt :metadata_region, "AWS region to store Heirloom metadata.", :type => :string,
86
+ :default => 'us-west-1'
74
87
  opt :name, "Name of archive.", :type => :string
75
88
  opt :public, "Set this archive as public readable?"
76
89
  opt :region, "Region(s) to upload archive. \
77
- Can be specified multiple times.", :type => :string, :multi => true
90
+ Can be specified multiple times.", :type => :string,
91
+ :multi => true,
92
+ :default => 'us-west-1'
78
93
  opt :secret, "Encrypt the archive with given secret.", :type => :string
79
94
  opt :aws_access_key, "AWS Access Key ID", :type => :string,
80
95
  :short => :none
data/lib/heirloom/cli.rb CHANGED
@@ -4,6 +4,7 @@ require 'trollop'
4
4
  require 'heirloom/cli/shared'
5
5
  require 'heirloom/cli/authorize'
6
6
  require 'heirloom/cli/upload'
7
+ require 'heirloom/cli/setup'
7
8
  require 'heirloom/cli/list'
8
9
  require 'heirloom/cli/show'
9
10
  require 'heirloom/cli/tag'
@@ -24,6 +25,8 @@ module Heirloom
24
25
  CLI::Download.new.download
25
26
  when 'list'
26
27
  CLI::List.new.list
28
+ when 'setup'
29
+ CLI::Setup.new.setup
27
30
  when 'show'
28
31
  CLI::Show.new.show
29
32
  when 'update', 'tag'
@@ -34,7 +37,7 @@ module Heirloom
34
37
  puts Heirloom::VERSION
35
38
  else
36
39
  puts "Unkown command: '#{cmd}'." unless cmd == '-h'
37
- puts "heirloom [list|show|upload|authorize|tag|download|destroy] OPTIONS"
40
+ puts "heirloom [authorize|destroy|download|list|setup|show|tag|upload] OPTIONS"
38
41
  puts "Append -h for help on specific command."
39
42
  end
40
43
  end
@@ -1,7 +1,7 @@
1
1
  module Heirloom
2
2
  class Config
3
3
 
4
- attr_accessor :access_key, :secret_key, :primary_region, :logger
4
+ attr_accessor :access_key, :secret_key, :metadata_region, :logger
5
5
 
6
6
  def initialize(args = {})
7
7
  @config = args.fetch :config, load_config_file
@@ -13,7 +13,7 @@ module Heirloom
13
13
  aws = @config['aws']
14
14
  self.access_key = aws['access_key']
15
15
  self.secret_key = aws['secret_key']
16
- self.primary_region = aws['primary_region'] ||= 'us-west-1'
16
+ self.metadata_region = aws['metadata_region']
17
17
  end
18
18
 
19
19
  def load_config_file
@@ -1,3 +1,3 @@
1
1
  module Heirloom
2
- VERSION = "0.5.0rc4"
2
+ VERSION = "0.6.0rc1"
3
3
  end
data/script/ci_setup CHANGED
@@ -11,4 +11,4 @@ rvm use "1.9.3-p125@heirloom" --create
11
11
  bundle
12
12
 
13
13
  # Run spec tests
14
- rspec spec
14
+ rake spec
@@ -5,7 +5,7 @@ describe Heirloom do
5
5
  before do
6
6
  @logger_stub = stub 'logger', :debug => true, :info => true
7
7
  @config_mock = mock 'config'
8
- @config_mock.stub :logger => @logger_stub
8
+ @config_mock.stub :logger => @logger_stub, :metadata_region => 'us-west-1'
9
9
  @verifier_mock = mock 'verifier'
10
10
  Heirloom::Verifier.should_receive(:new).
11
11
  with(:config => @config_mock,
@@ -4,7 +4,7 @@ describe Heirloom do
4
4
 
5
5
  before do
6
6
  @config_mock = double 'config'
7
- @logger_stub = stub 'logger', :debug => true
7
+ @logger_stub = stub 'logger', :debug => true, :info => true
8
8
  @s3_mock = double 's3_mock'
9
9
  @config_mock.stub :logger => @logger_stub
10
10
  @verifier = Heirloom::Verifier.new :config => @config_mock,
@@ -5,7 +5,7 @@ describe Heirloom do
5
5
  @config_mock = mock 'config'
6
6
  @config_mock.should_receive(:access_key).and_return 'the-key'
7
7
  @config_mock.should_receive(:secret_key).and_return 'the-secret'
8
- @config_mock.should_receive(:primary_region).and_return 'us-west-1'
8
+ @config_mock.should_receive(:metadata_region).and_return 'us-west-1'
9
9
  @fog_mock = mock 'fog'
10
10
  Fog::AWS::SimpleDB.should_receive(:new).
11
11
  with(:aws_access_key_id => 'the-key',
@@ -4,16 +4,18 @@ require 'heirloom/cli'
4
4
  describe Heirloom do
5
5
 
6
6
  before do
7
- options = { :level => 'info',
8
- :accounts => ['test@test.com'],
9
- :name => 'archive_name',
10
- :id => '1.0.0' }
7
+ options = { :level => 'info',
8
+ :accounts => ['test@test.com'],
9
+ :name => 'archive_name',
10
+ :id => '1.0.0',
11
+ :metadata_region => 'us-west-1' }
11
12
  @logger_stub = stub 'logger', :error => true
12
13
  @config_mock = mock 'config'
13
14
  @archive_mock = mock 'archive'
14
- @config_mock.stub :logger => @logger_stub,
15
- :access_key => 'key',
16
- :secret_key => 'secret'
15
+ @config_mock.stub :logger => @logger_stub,
16
+ :access_key => 'key',
17
+ :secret_key => 'secret',
18
+ :metadata_region => 'us-west-1'
17
19
  Trollop.stub(:options).and_return options
18
20
  Heirloom::HeirloomLogger.should_receive(:new).with(:log_level => 'info').
19
21
  and_return @logger_stub
@@ -30,6 +32,7 @@ describe Heirloom do
30
32
  :name => 'archive_name',
31
33
  :config => @config_mock).
32
34
  and_return @archive_mock
35
+ @archive_mock.stub :exists? => true
33
36
  @archive_mock.should_receive(:domain_exists?).and_return true
34
37
  @cli_authorize = Heirloom::CLI::Authorize.new
35
38
  end
@@ -4,15 +4,17 @@ require 'heirloom/cli'
4
4
  describe Heirloom do
5
5
 
6
6
  before do
7
- options = { :name => 'archive_name',
8
- :id => '1.0.0',
9
- :level => 'info' }
7
+ options = { :name => 'archive_name',
8
+ :id => '1.0.0',
9
+ :level => 'info',
10
+ :metadata_region => 'us-west-1' }
10
11
  @logger_stub = stub 'logger'
11
12
  @config_mock = mock 'config'
12
13
  @archive_mock = mock 'archive'
13
- @config_mock.stub :logger => @logger_stub,
14
- :access_key => 'key',
15
- :secret_key => 'secret'
14
+ @config_mock.stub :logger => @logger_stub,
15
+ :access_key => 'key',
16
+ :secret_key => 'secret',
17
+ :metadata_region => 'us-west-1'
16
18
  Trollop.stub(:options).and_return options
17
19
  Heirloom::HeirloomLogger.should_receive(:new).with(:log_level => 'info').
18
20
  and_return @logger_stub
@@ -29,6 +31,7 @@ describe Heirloom do
29
31
  :name => 'archive_name',
30
32
  :config => @config_mock).
31
33
  and_return @archive_mock
34
+ @archive_mock.stub :exists? => true
32
35
  @archive_mock.should_receive(:domain_exists?).and_return true
33
36
  @cli_destroy = Heirloom::CLI::Destroy.new
34
37
  end
@@ -4,19 +4,21 @@ require 'heirloom/cli'
4
4
  describe Heirloom do
5
5
 
6
6
  before do
7
- options = { :name => 'archive_name',
8
- :id => '1.0.0',
9
- :level => 'info',
10
- :output => '/tmp/test123',
11
- :region => 'us-east-1',
12
- :extract => false,
13
- :base_prefix => 'base' }
7
+ options = { :name => 'archive_name',
8
+ :id => '1.0.0',
9
+ :level => 'info',
10
+ :output => '/tmp/test123',
11
+ :region => 'us-east-1',
12
+ :extract => false,
13
+ :metadata_region => 'us-west-1',
14
+ :base => 'base' }
14
15
  @logger_stub = stub 'logger'
15
16
  @config_mock = mock 'config'
16
17
  @archive_mock = mock 'archive'
17
18
  @config_mock.stub :logger => @logger_stub,
18
19
  :access_key => 'key',
19
- :secret_key => 'secret'
20
+ :secret_key => 'secret',
21
+ :metadata_region => 'us-west-1'
20
22
  Trollop.stub(:options).and_return options
21
23
  Heirloom::HeirloomLogger.should_receive(:new).
22
24
  with(:log_level => 'info').
@@ -4,15 +4,17 @@ require 'heirloom/cli'
4
4
  describe Heirloom do
5
5
 
6
6
  before do
7
- options = { :name => 'archive_name',
8
- :level => 'info',
9
- :count => 100 }
7
+ options = { :name => 'archive_name',
8
+ :level => 'info',
9
+ :metadata_region => 'us-west-1',
10
+ :count => 100 }
10
11
  @logger_stub = stub :debug => true
11
12
  @config_mock = mock 'config'
12
13
  @archive_mock = mock 'archive'
13
- @config_mock.stub :logger => @logger_mock,
14
- :access_key => 'key',
15
- :secret_key => 'secret'
14
+ @config_mock.stub :logger => @logger_mock,
15
+ :access_key => 'key',
16
+ :secret_key => 'secret',
17
+ :metadata_region => 'us-west-1'
16
18
  Trollop.stub(:options).and_return options
17
19
  Heirloom::HeirloomLogger.should_receive(:new).with(:log_level => 'info').
18
20
  and_return @logger_stub
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'heirloom/cli'
3
+
4
+ describe Heirloom do
5
+
6
+ before do
7
+ @regions = ['us-west-1', 'us-west-2']
8
+ options = { :level => 'info',
9
+ :base => 'base',
10
+ :region => @regions,
11
+ :name => 'archive_name',
12
+ :metadata_region => 'us-west-1' }
13
+
14
+ @logger_stub = stub 'logger', :error => true, :info => true
15
+ @config_mock = mock 'config'
16
+ @config_mock.stub :logger => @logger_stub,
17
+ :access_key => 'key',
18
+ :secret_key => 'secret',
19
+ :metadata_region => 'us-west-1'
20
+ @archive_mock = mock 'archive'
21
+ Trollop.stub(:options).and_return options
22
+ Heirloom::HeirloomLogger.should_receive(:new).with(:log_level => 'info').
23
+ and_return @logger_stub
24
+ Heirloom::CLI::Setup.any_instance.should_receive(:load_config).
25
+ with(:logger => @logger_stub,
26
+ :opts => options).
27
+ and_return @config_mock
28
+ Heirloom::Archive.should_receive(:new).
29
+ with(:name => 'archive_name',
30
+ :config => @config_mock).
31
+ and_return @archive_mock
32
+ @setup = Heirloom::CLI::Setup.new
33
+ end
34
+
35
+ it "should setup s3 buckets and simpledb domain" do
36
+ @setup.should_receive(:ensure_metadata_in_upload_region).
37
+ with(:config => @config_mock,
38
+ :regions => @regions)
39
+ @archive_mock.should_receive(:setup).
40
+ with(:regions => @regions,
41
+ :bucket_prefix => 'base')
42
+ @setup.setup
43
+ end
44
+
45
+ end
@@ -9,9 +9,10 @@ describe Heirloom do
9
9
  before do
10
10
  @config_mock = mock 'config'
11
11
  @logger_mock = mock 'logger'
12
- @config_mock.stub :logger => @logger_mock,
13
- :access_key => 'key',
14
- :secret_key => 'secret'
12
+ @config_mock.stub :logger => @logger_mock,
13
+ :access_key => 'key',
14
+ :secret_key => 'secret',
15
+ :metadata_region => 'us-west-1'
15
16
  @object = Object.new
16
17
  @object.extend Heirloom::CLI::Shared
17
18
  end
@@ -82,16 +83,20 @@ describe Heirloom do
82
83
  :opts => {}).should == @config_mock
83
84
  end
84
85
 
86
+ it "should set the metadata region if specified" do
87
+ opts = { :metadata_region => 'us-west-1' }
88
+ @config_mock.should_receive(:metadata_region=).with 'us-west-1'
89
+ @object.load_config :logger => @logger_mock, :opts => opts
90
+ end
91
+
85
92
  it "should set the access key if specified" do
86
- opts = { :aws_access_key => 'the_key',
87
- :aws_access_key_given => true }
93
+ opts = { :aws_access_key => 'the_key' }
88
94
  @config_mock.should_receive(:access_key=).with 'the_key'
89
95
  @object.load_config :logger => @logger_mock, :opts => opts
90
96
  end
91
97
 
92
98
  it "should set the secret key if specified" do
93
- opts = { :aws_secret_key => 'the_secret',
94
- :aws_secret_key_given => true }
99
+ opts = { :aws_secret_key => 'the_secret' }
95
100
  @config_mock.should_receive(:secret_key=).with 'the_secret'
96
101
  @object.load_config :logger => @logger_mock, :opts => opts
97
102
  end
@@ -127,7 +132,8 @@ describe Heirloom do
127
132
  before do
128
133
  @archive_mock = mock 'archive'
129
134
  @logger_stub = stub 'logger', :error => true
130
- @config_stub = stub 'config', :logger => @logger_stub
135
+ @config_stub = stub 'config', :logger => @logger_stub,
136
+ :metadata_region => 'us-west-1'
131
137
  @object = Object.new
132
138
  @object.extend Heirloom::CLI::Shared
133
139
  Heirloom::Archive.should_receive(:new).
@@ -136,17 +142,86 @@ describe Heirloom do
136
142
  end
137
143
 
138
144
  it "should ensure the domain for a given archive exists" do
139
- @archive_mock.should_receive(:domain_exists?).and_return true
145
+ @archive_mock.stub :domain_exists? => true
140
146
  @object.ensure_domain_exists :config => @config_stub,
141
147
  :name => 'test'
142
148
  end
143
149
 
144
150
  it "should exit if the domain does not exist" do
145
- @archive_mock.should_receive(:domain_exists?).and_return false
151
+ @archive_mock.stub :domain_exists? => false
146
152
  lambda { @object.ensure_domain_exists :config => @config_stub,
147
153
  :name => 'test'}.
148
154
  should raise_error SystemExit
149
155
  end
150
156
  end
151
157
 
158
+ context "testing ensure metadata domain" do
159
+ before do
160
+ @archive_mock = mock 'archive'
161
+ @logger_stub = stub 'logger', :error => true
162
+ @config_stub = stub 'config', :logger => @logger_stub,
163
+ :metadata_region => 'us-west-1'
164
+ @object = Object.new
165
+ @object.extend Heirloom::CLI::Shared
166
+ end
167
+
168
+ it "should ensure the metadata domain is included in the upload domains" do
169
+ options = { :config => @config_stub, :regions => ['us-west-1', 'us-east-1'] }
170
+ @object.ensure_metadata_in_upload_region options
171
+ end
172
+
173
+ it "should exit if the metadata region is not in an upload region" do
174
+ options = { :config => @config_stub, :regions => ['us-west-2', 'us-east-1'] }
175
+ lambda { @object.ensure_metadata_in_upload_region options }.
176
+ should raise_error SystemExit
177
+ end
178
+ end
179
+
180
+ context "testing ensure valid regions" do
181
+ before do
182
+ @logger_stub = stub 'logger', :error => true
183
+ @config_stub = stub 'config', :logger => @logger_stub,
184
+ :metadata_region => 'us-west-1'
185
+ @object = Object.new
186
+ @object.extend Heirloom::CLI::Shared
187
+ end
188
+
189
+ it "should ensure the metadata domain is included in the upload domains" do
190
+ options = { :config => @config_stub, :regions => ['us-west-2', 'us-east-1'] }
191
+ @object.ensure_valid_regions options
192
+ end
193
+
194
+ it "should exit if the region is not valid" do
195
+ options = { :config => @config_stub, :regions => ['us-west-2', 'us-bad-1'] }
196
+ lambda { @object.ensure_valid_regions options }.
197
+ should raise_error SystemExit
198
+ end
199
+
200
+ end
201
+
202
+ context "testing ensure archive exists" do
203
+ before do
204
+ @archive_mock = mock 'archive'
205
+ @logger_stub = stub 'logger', :error => true
206
+ @config_stub = stub 'config', :logger => @logger_stub,
207
+ :metadata_region => 'us-west-1'
208
+ @object = Object.new
209
+ @object.extend Heirloom::CLI::Shared
210
+ end
211
+
212
+ it "should ensure the archive exists" do
213
+ @archive_mock.should_receive(:exists?).and_return true
214
+ options = { :config => @config_stub, :archive => @archive_mock }
215
+ @object.ensure_archive_exists options
216
+ end
217
+
218
+ it "should exit if the archive does not exist" do
219
+ @archive_mock.should_receive(:exists?).and_return false
220
+ options = { :config => @config_stub, :archive => @archive_mock }
221
+ lambda { @object.ensure_archive_exists options }.
222
+ should raise_error SystemExit
223
+ end
224
+ end
225
+
226
+
152
227
  end
@@ -4,15 +4,17 @@ require 'heirloom/cli'
4
4
  describe Heirloom do
5
5
 
6
6
  before do
7
- options = { :name => 'archive_name',
8
- :id => '1.0.0',
9
- :level => 'info' }
7
+ options = { :name => 'archive_name',
8
+ :id => '1.0.0',
9
+ :level => 'info',
10
+ :metadata_region => 'us-west-1' }
10
11
  @logger_stub = stub :debug => true
11
12
  @config_mock = mock 'config'
12
13
  @archive_mock = mock 'archive'
13
- @config_mock.stub :logger => @logger_stub,
14
- :access_key => 'key',
15
- :secret_key => 'secret'
14
+ @config_mock.stub :logger => @logger_stub,
15
+ :access_key => 'key',
16
+ :secret_key => 'secret',
17
+ :metadata_region => 'us-west-1'
16
18
  Trollop.stub(:options).and_return options
17
19
  Heirloom::HeirloomLogger.should_receive(:new).with(:log_level => 'info').
18
20
  and_return @logger_stub
@@ -29,7 +31,8 @@ describe Heirloom do
29
31
  :id => '1.0.0',
30
32
  :config => @config_mock).
31
33
  and_return @archive_mock
32
- @archive_mock.should_receive(:domain_exists?).and_return true
34
+ @archive_mock.stub :exists? => true
35
+ @archive_mock.stub :domain_exists? => true
33
36
  @cli_show = Heirloom::CLI::Show.new
34
37
  end
35
38
 
data/spec/cli/tag_spec.rb CHANGED
@@ -4,17 +4,19 @@ require 'heirloom/cli'
4
4
  describe Heirloom do
5
5
 
6
6
  before do
7
- options = { :name => 'archive_name',
8
- :id => '1.0.0',
9
- :level => 'info',
10
- :attribute => 'att',
11
- :value => 'val' }
7
+ options = { :name => 'archive_name',
8
+ :id => '1.0.0',
9
+ :level => 'info',
10
+ :attribute => 'att',
11
+ :value => 'val',
12
+ :metadata_region => 'us-west-1' }
12
13
  @logger_stub = stub :debug => true, :error => true
13
14
  @config_mock = mock 'config'
14
15
  @archive_mock = mock 'archive'
15
- @config_mock.stub :logger => @logger_stub,
16
- :access_key => 'key',
17
- :secret_key => 'secret'
16
+ @config_mock.stub :logger => @logger_stub,
17
+ :access_key => 'key',
18
+ :secret_key => 'secret',
19
+ :metadata_region => 'us-west-1'
18
20
  Trollop.stub(:options).and_return options
19
21
  Heirloom::HeirloomLogger.should_receive(:new).with(:log_level => 'info').
20
22
  and_return @logger_stub
@@ -31,6 +33,7 @@ describe Heirloom do
31
33
  :id => '1.0.0',
32
34
  :config => @config_mock).
33
35
  and_return @archive_mock
36
+ @archive_mock.stub :exists? => true
34
37
  @archive_mock.should_receive(:domain_exists?).and_return true
35
38
  @cli_tag = Heirloom::CLI::Tag.new
36
39
  end
@@ -4,21 +4,25 @@ require 'heirloom/cli'
4
4
  describe Heirloom do
5
5
 
6
6
  before do
7
- options = { :level => 'info',
8
- :base => 'base',
9
- :git => false,
10
- :exclude => ['exclude1', 'exclude2'],
11
- :region => ['us-west-1', 'us-west-2'],
12
- :directory => '/buildme',
13
- :public => false,
14
- :name => 'archive_name',
15
- :id => '1.0.0' }
7
+ @regions = ['us-west-1', 'us-west-2']
8
+ options = { :level => 'info',
9
+ :base => 'base',
10
+ :git => false,
11
+ :exclude => ['exclude1', 'exclude2'],
12
+ :region => @regions,
13
+ :directory => '/buildme',
14
+ :public => false,
15
+ :secret => 'secret12',
16
+ :name => 'archive_name',
17
+ :id => '1.0.0',
18
+ :metadata_region => 'us-west-1' }
16
19
 
17
20
  @logger_stub = stub 'logger', :error => true, :info => true
18
21
  @config_mock = mock 'config'
19
- @config_mock.stub :logger => @logger_stub,
20
- :access_key => 'key',
21
- :secret_key => 'secret'
22
+ @config_mock.stub :logger => @logger_stub,
23
+ :access_key => 'key',
24
+ :secret_key => 'secret',
25
+ :metadata_region => 'us-west-1'
22
26
  @archive_mock = mock 'archive'
23
27
  Trollop.stub(:options).and_return options
24
28
  Heirloom::HeirloomLogger.should_receive(:new).with(:log_level => 'info').
@@ -36,22 +40,34 @@ describe Heirloom do
36
40
  end
37
41
 
38
42
  it "should upload an archive" do
39
- @upload.stub :ensure_directory => true
40
- @upload.stub :ensure_valid_secret => true
41
- @archive_mock.should_receive(:setup).
42
- with(:bucket_prefix => 'base',
43
- :regions => ["us-west-1", "us-west-2"])
43
+ @upload.should_receive(:ensure_domain_exists).
44
+ with(:name => 'archive_name',
45
+ :config => @config_mock)
46
+ @upload.should_receive(:ensure_buckets_exist).
47
+ with(:base => 'base',
48
+ :name => 'archive_name',
49
+ :regions => @regions,
50
+ :config => @config_mock)
51
+ @upload.should_receive(:ensure_directory).
52
+ with(:path => '/buildme',
53
+ :config => @config_mock)
54
+ @upload.should_receive(:ensure_valid_secret).
55
+ with(:secret => 'secret12',
56
+ :config => @config_mock)
57
+ @upload.should_receive(:ensure_metadata_in_upload_region).
58
+ with(:config => @config_mock,
59
+ :regions => @regions)
44
60
  @archive_mock.stub :exists? => false
45
61
  @archive_mock.should_receive(:build).
46
62
  with(:base => 'base',
47
63
  :directory => '/buildme',
48
64
  :exclude => ["exclude1", "exclude2"],
49
65
  :git => false,
50
- :secret => nil).
66
+ :secret => 'secret12').
51
67
  and_return '/tmp/build123.tar.gz'
52
68
  @archive_mock.should_receive(:upload).
53
69
  with(:bucket_prefix => 'base',
54
- :regions => ['us-west-1', 'us-west-2'],
70
+ :regions => @regions,
55
71
  :public_readable => false,
56
72
  :file => '/tmp/build123.tar.gz')
57
73
  @upload.upload
data/spec/config_spec.rb CHANGED
@@ -4,9 +4,9 @@ describe Heirloom do
4
4
 
5
5
  before do
6
6
  @config = { 'aws' =>
7
- { 'access_key' => 'key',
8
- 'secret_key' => 'secret',
9
- 'primary_region' => 'us-west-2'
7
+ { 'access_key ' => 'key',
8
+ 'secret_key ' => 'secret',
9
+ 'metadata_region' => 'us-west-2'
10
10
  }
11
11
  }
12
12
  end
@@ -16,7 +16,7 @@ describe Heirloom do
16
16
  :logger => 'da-logger'
17
17
  config.access_key.should == @config['aws']['access_key']
18
18
  config.secret_key.should == @config['aws']['secret_key']
19
- config.primary_region.should == @config['aws']['primary_region']
19
+ config.metadata_region.should == @config['aws']['metadata_region']
20
20
  config.logger.should == 'da-logger'
21
21
  end
22
22
 
@@ -27,14 +27,14 @@ describe Heirloom do
27
27
  config = Heirloom::Config.new
28
28
  config.access_key.should == @config['aws']['access_key']
29
29
  config.secret_key.should == @config['aws']['secret_key']
30
- config.primary_region.should == @config['aws']['primary_region']
30
+ config.metadata_region.should == @config['aws']['metadata_region']
31
31
  end
32
32
 
33
- it "should set the primary region to us-west-1 if not present in config" do
33
+ it "should return nil if metadata_region not present in config" do
34
34
  @config['aws'] = {}
35
35
  config = Heirloom::Config.new :config => @config,
36
36
  :logger => 'da-logger'
37
- config.primary_region.should == 'us-west-1'
37
+ config.metadata_region.should == nil
38
38
  end
39
39
 
40
40
  it "should load a blank config if the file does not exist and no config passed" do
@@ -42,7 +42,7 @@ describe Heirloom do
42
42
  config = Heirloom::Config.new
43
43
  config.access_key.should be_nil
44
44
  config.secret_key.should be_nil
45
- config.primary_region.should == 'us-west-1'
45
+ config.metadata_region.should be_nil
46
46
  end
47
47
 
48
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heirloom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0rc4
4
+ version: 0.6.0rc1
5
5
  prerelease: 5
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-21 00:00:00.000000000 Z
12
+ date: 2012-08-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70328442595660 !ruby/object:Gem::Requirement
16
+ requirement: &70322913192860 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70328442595660
24
+ version_requirements: *70322913192860
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: fog
27
- requirement: &70328442595020 !ruby/object:Gem::Requirement
27
+ requirement: &70322913202760 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.5.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70328442595020
35
+ version_requirements: *70322913202760
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: grit
38
- requirement: &70328442594520 !ruby/object:Gem::Requirement
38
+ requirement: &70322913214480 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.5.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70328442594520
46
+ version_requirements: *70322913214480
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: trollop
49
- requirement: &70328442594040 !ruby/object:Gem::Requirement
49
+ requirement: &70322913212440 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - =
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '2.0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70328442594040
57
+ version_requirements: *70322913212440
58
58
  description: I help build and manage building tar.gz files and deploying them into
59
59
  the cloud
60
60
  email:
@@ -99,6 +99,7 @@ files:
99
99
  - lib/heirloom/cli/destroy.rb
100
100
  - lib/heirloom/cli/download.rb
101
101
  - lib/heirloom/cli/list.rb
102
+ - lib/heirloom/cli/setup.rb
102
103
  - lib/heirloom/cli/shared.rb
103
104
  - lib/heirloom/cli/show.rb
104
105
  - lib/heirloom/cli/tag.rb
@@ -137,6 +138,7 @@ files:
137
138
  - spec/cli/destroy_spec.rb
138
139
  - spec/cli/download_spec.rb
139
140
  - spec/cli/list_spec.rb
141
+ - spec/cli/setup_spec.rb
140
142
  - spec/cli/shared_spec.rb
141
143
  - spec/cli/show_spec.rb
142
144
  - spec/cli/tag_spec.rb
@@ -162,7 +164,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
162
164
  version: '0'
163
165
  segments:
164
166
  - 0
165
- hash: -3871179857834754510
167
+ hash: -4439372529062381791
166
168
  required_rubygems_version: !ruby/object:Gem::Requirement
167
169
  none: false
168
170
  requirements:
@@ -197,6 +199,7 @@ test_files:
197
199
  - spec/cli/destroy_spec.rb
198
200
  - spec/cli/download_spec.rb
199
201
  - spec/cli/list_spec.rb
202
+ - spec/cli/setup_spec.rb
200
203
  - spec/cli/shared_spec.rb
201
204
  - spec/cli/show_spec.rb
202
205
  - spec/cli/tag_spec.rb