heirloom 0.11.0.beta.2 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,7 @@
1
1
  ## HEAD:
2
2
 
3
+ ## 0.11.0 (04/26/2013):
4
+
3
5
  * Add support for multiple environments
4
6
  * Environment named 'default' is now the default
5
7
  * Added functionality to the show command to include permissions of objects
@@ -9,6 +11,7 @@
9
11
  * Catalog output renamed Bucket Prefix to bucket_prefix
10
12
  * Catalog output renamed Region to region
11
13
  * Add `rotate` command to allow for encryption key rotation
14
+ * Add support for IAM instance roles
12
15
 
13
16
  ## 0.10.1 (02/28/2013):
14
17
 
@@ -9,10 +9,16 @@ module Heirloom
9
9
  @region = args[:region]
10
10
  @logger = @config.logger
11
11
 
12
- @s3 = Fog::Storage.new :provider => 'AWS',
13
- :aws_access_key_id => @config.access_key,
14
- :aws_secret_access_key => @config.secret_key,
15
- :region => @region
12
+ fog_args = { :region => @region, :provider => 'AWS' }
13
+
14
+ if @config.use_iam_profile
15
+ fog_args[:use_iam_profile] = true
16
+ else
17
+ fog_args[:aws_access_key_id] = @config.access_key
18
+ fog_args[:aws_secret_access_key] = @config.secret_key
19
+ end
20
+
21
+ @s3 = Fog::Storage.new fog_args
16
22
  end
17
23
 
18
24
  def delete_object(bucket_name, object_name, options = {})
@@ -6,9 +6,17 @@ module Heirloom
6
6
 
7
7
  def initialize(args)
8
8
  @config = args[:config]
9
- @sdb = Fog::AWS::SimpleDB.new :aws_access_key_id => @config.access_key,
10
- :aws_secret_access_key => @config.secret_key,
11
- :region => @config.metadata_region
9
+
10
+ fog_args = { :region => @config.metadata_region }
11
+
12
+ if @config.use_iam_profile
13
+ fog_args[:use_iam_profile] = true
14
+ else
15
+ fog_args[:aws_access_key_id] = @config.access_key
16
+ fog_args[:aws_secret_access_key] = @config.secret_key
17
+ end
18
+
19
+ @sdb = Fog::AWS::SimpleDB.new fog_args
12
20
  end
13
21
 
14
22
  def domains
@@ -60,6 +60,7 @@ EOS
60
60
  :short => :none
61
61
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
62
62
  :short => :none
63
+ opt :use_iam_profile, "Use IAM EC2 Profile", :short => :none
63
64
  opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
64
65
  end
65
66
  end
@@ -59,6 +59,7 @@ EOS
59
59
  :short => :none
60
60
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
61
61
  :short => :none
62
+ opt :use_iam_profile, "Use IAM EC2 Profile", :short => :none
62
63
  opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
63
64
  end
64
65
  end
@@ -55,6 +55,7 @@ EOS
55
55
  :short => :none
56
56
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
57
57
  :short => :none
58
+ opt :use_iam_profile, "Use IAM EC2 Profile", :short => :none
58
59
  opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
59
60
  end
60
61
  end
@@ -86,6 +86,7 @@ EOS
86
86
  :short => :none
87
87
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
88
88
  :short => :none
89
+ opt :use_iam_profile, "Use IAM EC2 Profile", :short => :none
89
90
  opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
90
91
  end
91
92
  end
@@ -58,6 +58,7 @@ EOS
58
58
  :short => :none
59
59
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
60
60
  :short => :none
61
+ opt :use_iam_profile, "Use IAM EC2 Profile", :short => :none
61
62
  opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
62
63
  end
63
64
  end
@@ -88,6 +88,7 @@ Can be specified multiple times.", :type => :string,
88
88
  :short => :none
89
89
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
90
90
  :short => :none
91
+ opt :use_iam_profile, "Use IAM EC2 Profile", :short => :none
91
92
  opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
92
93
  end
93
94
  end
@@ -9,6 +9,7 @@ module Heirloom
9
9
  config.access_key = opts[:aws_access_key] if opts[:aws_access_key]
10
10
  config.secret_key = opts[:aws_secret_key] if opts[:aws_secret_key]
11
11
  config.metadata_region = opts[:metadata_region] if opts[:metadata_region]
12
+ config.use_iam_profile = opts[:use_iam_profile] if opts[:use_iam_profile]
12
13
  config
13
14
  end
14
15
 
@@ -28,8 +29,10 @@ module Heirloom
28
29
  config = args[:config]
29
30
  logger = config.logger
30
31
 
31
- required << :aws_access_key unless config.access_key
32
- required << :aws_secret_key unless config.secret_key
32
+ unless config.use_iam_profile
33
+ required << :aws_access_key unless config.access_key
34
+ required << :aws_secret_key unless config.secret_key
35
+ end
33
36
 
34
37
  missing_opts = required.sort.map do |opt|
35
38
  case provided[opt]
@@ -69,6 +69,7 @@ EOS
69
69
  :short => :none
70
70
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
71
71
  :short => :none
72
+ opt :use_iam_profile, "Use IAM EC2 Profile", :short => :none
72
73
  opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
73
74
  end
74
75
  end
@@ -61,6 +61,7 @@ EOS
61
61
  :short => :none
62
62
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
63
63
  :short => :none
64
+ opt :use_iam_profile, "Use IAM EC2 Profile", :short => :none
64
65
  opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
65
66
  end
66
67
  end
@@ -72,6 +72,7 @@ EOS
72
72
  :short => :none
73
73
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
74
74
  :short => :none
75
+ opt :use_iam_profile, "Use IAM EC2 Profile", :short => :none
75
76
  opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
76
77
  end
77
78
  end
@@ -100,6 +100,7 @@ Can be specified multiple times.", :type => :string, :multi => true, :short =>
100
100
  :short => :none
101
101
  opt :aws_secret_key, "AWS Secret Access Key", :type => :string,
102
102
  :short => :none
103
+ opt :use_iam_profile, "Use IAM EC2 Profile", :short => :none
103
104
  opt :environment, "Environment (defined in ~/.heirloom.yml)", :type => :string
104
105
  end
105
106
  end
@@ -1,7 +1,7 @@
1
1
  module Heirloom
2
2
  class Config
3
3
 
4
- attr_accessor :access_key, :secret_key, :metadata_region, :logger, :environment
4
+ attr_accessor :access_key, :secret_key, :metadata_region, :logger, :environment, :use_iam_profile
5
5
 
6
6
  def initialize(args={})
7
7
  @opts = args[:opts] ||= Hash.new
@@ -18,6 +18,8 @@ module Heirloom
18
18
  @config['secret_key']
19
19
  @metadata_region = @opts.fetch :metadata_region,
20
20
  @config['metadata_region']
21
+ @use_iam_profile = @opts.fetch :use_iam_profile,
22
+ false
21
23
  end
22
24
 
23
25
  private
@@ -1,3 +1,3 @@
1
1
  module Heirloom
2
- VERSION = "0.11.0.beta.2"
2
+ VERSION = "0.11.0"
3
3
  end
@@ -1,244 +1,267 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Heirloom do
4
- before do
5
- @directories_mock = mock 'directories'
6
- @bucket_mock = mock 'bucket'
7
- @logger_stub = stub 'logger', :debug => true,
8
- :info => true,
9
- :warn => true
10
- @config_mock = mock 'config'
11
- @config_mock.stub :access_key => 'the-key',
12
- :secret_key => 'the-secret',
13
- :logger => @logger_stub
14
- @fog_mock = mock 'fog'
15
- @fog_mock.stub :directories => @directories_mock
16
- Fog::Storage.should_receive(:new).and_return @fog_mock
17
- @s3 = Heirloom::AWS::S3.new :config => @config_mock,
18
- :region => 'us-west-1'
19
- end
4
+ context "using IAM roles" do
20
5
 
21
- context "bucket_exists?" do
22
- it "should return true if the bucket exists" do
23
- @directories_mock.should_receive(:get).
24
- with('bucket').and_return @bucket_mock
25
- @s3.bucket_exists?('bucket').should be_true
26
- end
6
+ it "should use the access and secret keys by default" do
27
7
 
28
- it "should return false if the bucket does not exist" do
29
- @directories_mock.should_receive(:get).
30
- with('bucket').and_return nil
31
- @s3.bucket_exists?('bucket').should be_false
32
- end
8
+ config = mock_config :aws_access_key_id => 'key',
9
+ :aws_secret_access_key => 'secret'
33
10
 
34
- it "should return false if bucket owned by another account" do
35
- @directories_mock.should_receive(:get).
36
- with('bucket').
37
- and_raise Excon::Errors::Forbidden.new('msg')
38
- @s3.bucket_exists?('bucket').should be_false
39
- end
40
- end
11
+ Fog::Storage.should_receive(:new).
12
+ with :provider => 'AWS',
13
+ :aws_access_key_id => 'key',
14
+ :aws_secret_access_key => 'secret',
15
+ :region => 'us-west-1'
16
+ s3 = Heirloom::AWS::S3.new :config => config, :region => 'us-west-1'
41
17
 
42
- context "bucket_exists_in_another_region?" do
43
- it "should return true if the bucket exists in another region" do
44
- @bucket_mock.stub :location => 'us-east-1'
45
- @directories_mock.should_receive(:get).
46
- with('bucket').at_least(:once).
47
- and_return @bucket_mock
48
- @s3.bucket_exists_in_another_region?('bucket').should be_true
49
18
  end
50
19
 
51
- it "should return false if the bucket exists in the curren region" do
52
- @bucket_mock.stub :location => 'us-west-1'
53
- @directories_mock.should_receive(:get).
54
- with('bucket').at_least(:once).
55
- and_return @bucket_mock
56
- @s3.bucket_exists_in_another_region?('bucket').should be_false
57
- end
20
+ it "should use the iam role if asked to" do
21
+
22
+ config = mock_config :use_iam_profile => true
23
+
24
+ Fog::Storage.should_receive(:new).
25
+ with :provider => 'AWS',
26
+ :use_iam_profile => true,
27
+ :region => 'us-west-1'
28
+ s3 = Heirloom::AWS::S3.new :config => config, :region => 'us-west-1'
58
29
 
59
- it "should return false if bucket owned by another account" do
60
- @directories_mock.should_receive(:get).
61
- with('bucket').
62
- and_raise Excon::Errors::Forbidden.new('msg')
63
- @s3.bucket_exists_in_another_region?('bucket').should be_false
64
30
  end
65
31
  end
66
32
 
67
- context "bucket_owned_by_another_account?" do
68
- it "should return false if bucket owned by this account" do
69
- @directories_mock.should_receive(:get).
70
- with('bucket').
71
- and_return @bucket_mock
72
- @s3.bucket_owned_by_another_account?('bucket').should be_false
73
- end
33
+ context "s3 / bucket operations" do
74
34
 
75
- it "should return false if bucket does not exist" do
76
- @directories_mock.should_receive(:get).
77
- with('bucket').
78
- and_return nil
79
- @s3.bucket_owned_by_another_account?('bucket').should be_false
35
+ before do
36
+ @directories_mock = mock 'directories'
37
+ @bucket_mock = mock 'bucket'
38
+ @fog_mock = mock 'fog'
39
+ @fog_mock.stub :directories => @directories_mock
40
+ Fog::Storage.stub :new => @fog_mock
41
+ @s3 = Heirloom::AWS::S3.new :config => mock_config, :region => 'us-west-1'
80
42
  end
81
43
 
82
- it "should return true if bucket is not owned by another account" do
83
- @directories_mock.should_receive(:get).
84
- with('bucket').
85
- and_raise Excon::Errors::Forbidden.new('msg')
86
- @s3.bucket_owned_by_another_account?('bucket').should be_true
44
+ context "bucket_exists?" do
45
+ it "should return true if the bucket exists" do
46
+ @directories_mock.should_receive(:get).
47
+ with('bucket').and_return @bucket_mock
48
+ @s3.bucket_exists?('bucket').should be_true
49
+ end
50
+
51
+ it "should return false if the bucket does not exist" do
52
+ @directories_mock.should_receive(:get).
53
+ with('bucket').and_return nil
54
+ @s3.bucket_exists?('bucket').should be_false
55
+ end
56
+
57
+ it "should return false if bucket owned by another account" do
58
+ @directories_mock.should_receive(:get).
59
+ with('bucket').
60
+ and_raise Excon::Errors::Forbidden.new('msg')
61
+ @s3.bucket_exists?('bucket').should be_false
62
+ end
87
63
  end
88
- end
89
-
90
- it "should delete an object from s3" do
91
- @fog_mock.should_receive(:delete_object).
92
- with('bucket', 'object', { :option => 'test' })
93
- @s3.delete_object('bucket', 'object', { :option => 'test' })
94
- end
95
-
96
- it "should get a bucket from s3" do
97
- @directories_mock.should_receive(:get).with 'bucket'
98
- @s3.get_bucket 'bucket'
99
- end
100
-
101
- context "testing bucket availability" do
102
64
 
103
- it "should return false if the bucket is forbidden" do
104
- @directories_mock.should_receive(:get).
105
- with('bucket').
106
- and_raise Excon::Errors::Forbidden.new('msg')
107
- @s3.bucket_name_available?('bucket').should be_false
65
+ context "bucket_exists_in_another_region?" do
66
+ it "should return true if the bucket exists in another region" do
67
+ @bucket_mock.stub :location => 'us-east-1'
68
+ @directories_mock.should_receive(:get).
69
+ with('bucket').at_least(:once).
70
+ and_return @bucket_mock
71
+ @s3.bucket_exists_in_another_region?('bucket').should be_true
72
+ end
73
+
74
+ it "should return false if the bucket exists in the curren region" do
75
+ @bucket_mock.stub :location => 'us-west-1'
76
+ @directories_mock.should_receive(:get).
77
+ with('bucket').at_least(:once).
78
+ and_return @bucket_mock
79
+ @s3.bucket_exists_in_another_region?('bucket').should be_false
80
+ end
81
+
82
+ it "should return false if bucket owned by another account" do
83
+ @directories_mock.should_receive(:get).
84
+ with('bucket').
85
+ and_raise Excon::Errors::Forbidden.new('msg')
86
+ @s3.bucket_exists_in_another_region?('bucket').should be_false
87
+ end
108
88
  end
109
89
 
110
- it "should return false if bucket in different region" do
111
- @directories_mock.should_receive(:get).
112
- with('bucket').at_least(:once).
113
- and_return @bucket_mock
114
- @bucket_mock.stub :location => 'us-east-1'
115
- @s3.bucket_name_available?('bucket').should be_false
90
+ context "bucket_owned_by_another_account?" do
91
+ it "should return false if bucket owned by this account" do
92
+ @directories_mock.should_receive(:get).
93
+ with('bucket').
94
+ and_return @bucket_mock
95
+ @s3.bucket_owned_by_another_account?('bucket').should be_false
96
+ end
97
+
98
+ it "should return false if bucket does not exist" do
99
+ @directories_mock.should_receive(:get).
100
+ with('bucket').
101
+ and_return nil
102
+ @s3.bucket_owned_by_another_account?('bucket').should be_false
103
+ end
104
+
105
+ it "should return true if bucket is not owned by another account" do
106
+ @directories_mock.should_receive(:get).
107
+ with('bucket').
108
+ and_raise Excon::Errors::Forbidden.new('msg')
109
+ @s3.bucket_owned_by_another_account?('bucket').should be_true
110
+ end
116
111
  end
117
112
 
118
- it "should return true if the bucket is in this account / region" do
119
- @directories_mock.should_receive(:get).
120
- with('bucket').at_least(:once).
121
- and_return @bucket_mock
122
- @bucket_mock.stub :location => 'us-west-1'
123
- @s3.bucket_name_available?('bucket').should be_true
113
+ it "should delete an object from s3" do
114
+ @fog_mock.should_receive(:delete_object).
115
+ with('bucket', 'object', { :option => 'test' })
116
+ @s3.delete_object('bucket', 'object', { :option => 'test' })
124
117
  end
125
118
 
126
- it "should return true if the bucket is not found" do
127
- @directories_mock.should_receive(:get).
128
- with('bucket').at_least(:once).
129
- and_return nil
130
- @s3.bucket_name_available?('bucket').should be_true
119
+ it "should get a bucket from s3" do
120
+ @directories_mock.should_receive(:get).with 'bucket'
121
+ @s3.get_bucket 'bucket'
131
122
  end
132
123
 
133
- end
124
+ context "testing bucket availability" do
125
+
126
+ it "should return false if the bucket is forbidden" do
127
+ @directories_mock.should_receive(:get).
128
+ with('bucket').
129
+ and_raise Excon::Errors::Forbidden.new('msg')
130
+ @s3.bucket_name_available?('bucket').should be_false
131
+ end
132
+
133
+ it "should return false if bucket in different region" do
134
+ @directories_mock.should_receive(:get).
135
+ with('bucket').at_least(:once).
136
+ and_return @bucket_mock
137
+ @bucket_mock.stub :location => 'us-east-1'
138
+ @s3.bucket_name_available?('bucket').should be_false
139
+ end
140
+
141
+ it "should return true if the bucket is in this account / region" do
142
+ @directories_mock.should_receive(:get).
143
+ with('bucket').at_least(:once).
144
+ and_return @bucket_mock
145
+ @bucket_mock.stub :location => 'us-west-1'
146
+ @s3.bucket_name_available?('bucket').should be_true
147
+ end
148
+
149
+ it "should return true if the bucket is not found" do
150
+ @directories_mock.should_receive(:get).
151
+ with('bucket').at_least(:once).
152
+ and_return nil
153
+ @s3.bucket_name_available?('bucket').should be_true
154
+ end
134
155
 
135
- it "should return object versions for a given bucket" do
136
- body_mock = mock 'body'
137
- @fog_mock.should_receive(:get_bucket_object_versions).
138
- with('bucket').
139
- and_return body_mock
140
- body_mock.stub :body => 'body_hash'
141
- @s3.get_bucket_object_versions('bucket').should == 'body_hash'
142
- end
156
+ end
143
157
 
144
- context "testing bucket deletion" do
145
- it "should return true if the bucket has 0 objects" do
158
+ it "should return object versions for a given bucket" do
146
159
  body_mock = mock 'body'
147
160
  @fog_mock.should_receive(:get_bucket_object_versions).
148
161
  with('bucket').
149
162
  and_return body_mock
150
- body_mock.stub :body => { "Versions" => [ ] }
151
- @s3.bucket_empty?('bucket').should be_true
163
+ body_mock.stub :body => 'body_hash'
164
+ @s3.get_bucket_object_versions('bucket').should == 'body_hash'
152
165
  end
153
166
 
154
- it "should return false if the bucket has any objects" do
155
- body_mock = mock 'body'
156
- @fog_mock.should_receive(:get_bucket_object_versions).
157
- with('bucket').
158
- and_return body_mock
159
- body_mock.stub :body => { "Versions" => [ 'obj1', 'obj2' ] }
160
- @s3.bucket_empty?('bucket').should be_false
167
+ context "testing bucket deletion" do
168
+ it "should return true if the bucket has 0 objects" do
169
+ body_mock = mock 'body'
170
+ @fog_mock.should_receive(:get_bucket_object_versions).
171
+ with('bucket').
172
+ and_return body_mock
173
+ body_mock.stub :body => { "Versions" => [ ] }
174
+ @s3.bucket_empty?('bucket').should be_true
175
+ end
176
+
177
+ it "should return false if the bucket has any objects" do
178
+ body_mock = mock 'body'
179
+ @fog_mock.should_receive(:get_bucket_object_versions).
180
+ with('bucket').
181
+ and_return body_mock
182
+ body_mock.stub :body => { "Versions" => [ 'obj1', 'obj2' ] }
183
+ @s3.bucket_empty?('bucket').should be_false
184
+ end
185
+
186
+ it "should delete a bucket from s3 if empty" do
187
+ body_mock = mock 'body'
188
+ @fog_mock.should_receive(:get_bucket_object_versions).
189
+ with('bucket').
190
+ and_return body_mock
191
+ body_mock.stub :body => { "Versions" => [ ] }
192
+ @fog_mock.should_receive(:delete_bucket).
193
+ with('bucket').and_return true
194
+ @s3.delete_bucket('bucket').should be_true
195
+ end
196
+
197
+ it "should return false and not attempt to delete a non empty s3 bucket" do
198
+ body_mock = mock 'body'
199
+ @fog_mock.should_receive(:get_bucket_object_versions).
200
+ with('bucket').
201
+ and_return body_mock
202
+ body_mock.stub :body => { "Versions" => [ 'obj1', 'obj2' ] }
203
+ @fog_mock.should_receive(:delete_bucket).never
204
+ @s3.delete_bucket('bucket').should be_false
205
+ end
206
+
207
+ it "should return true if Excon::Errors::NotFound raised when deleting bucket" do
208
+ @fog_mock.should_receive(:get_bucket_object_versions).
209
+ with('bucket').
210
+ and_raise Excon::Errors::NotFound.new 'Bucket does not exist.'
211
+ @fog_mock.should_receive(:delete_bucket).never
212
+ @s3.delete_bucket('bucket').should be_true
213
+ end
161
214
  end
162
215
 
163
- it "should delete a bucket from s3 if empty" do
216
+ it "should get an object from s3" do
164
217
  body_mock = mock 'body'
165
- @fog_mock.should_receive(:get_bucket_object_versions).
166
- with('bucket').
218
+ @fog_mock.should_receive(:get_object).
219
+ with('bucket', 'object').
167
220
  and_return body_mock
168
- body_mock.stub :body => { "Versions" => [ ] }
169
- @fog_mock.should_receive(:delete_bucket).
170
- with('bucket').and_return true
171
- @s3.delete_bucket('bucket').should be_true
221
+ body_mock.stub :body => 'body_hash'
222
+ @s3.get_object('bucket', 'object').should == 'body_hash'
172
223
  end
173
224
 
174
- it "should return false and not attempt to delete a non empty s3 bucket" do
225
+ it "should get a buckets acl from s3" do
175
226
  body_mock = mock 'body'
176
- @fog_mock.should_receive(:get_bucket_object_versions).
177
- with('bucket').
227
+ @fog_mock.should_receive(:get_object).
228
+ with('bucket', 'object').
178
229
  and_return body_mock
179
- body_mock.stub :body => { "Versions" => [ 'obj1', 'obj2' ] }
180
- @fog_mock.should_receive(:delete_bucket).never
181
- @s3.delete_bucket('bucket').should be_false
230
+ body_mock.should_receive(:body)
231
+ @s3.get_object('bucket', 'object')
182
232
  end
183
233
 
184
- it "should return true if Excon::Errors::NotFound raised when deleting bucket" do
185
- @fog_mock.should_receive(:get_bucket_object_versions).
186
- with('bucket').
187
- and_raise Excon::Errors::NotFound.new 'Bucket does not exist.'
188
- @fog_mock.should_receive(:delete_bucket).never
189
- @s3.delete_bucket('bucket').should be_true
234
+ it "should get an objects acl from s3" do
235
+ body_mock = mock 'body'
236
+ @fog_mock.should_receive(:get_object_acl).
237
+ with('bucket', 'object').and_return(body_mock)
238
+ body_mock.stub :body => 'data'
239
+ @s3.get_object_acl({ :bucket => 'bucket', :object_name => 'object'}).
240
+ should == 'data'
190
241
  end
191
- end
192
242
 
193
- it "should get an object from s3" do
194
- body_mock = mock 'body'
195
- @fog_mock.should_receive(:get_object).
196
- with('bucket', 'object').
197
- and_return body_mock
198
- body_mock.stub :body => 'body_hash'
199
- @s3.get_object('bucket', 'object').should == 'body_hash'
200
- end
201
-
202
- it "should get a buckets acl from s3" do
203
- body_mock = mock 'body'
204
- @fog_mock.should_receive(:get_object).
205
- with('bucket', 'object').
206
- and_return body_mock
207
- body_mock.should_receive(:body)
208
- @s3.get_object('bucket', 'object')
209
- end
210
-
211
- it "should get an objects acl from s3" do
212
- body_mock = mock 'body'
213
- @fog_mock.should_receive(:get_object_acl).
214
- with('bucket', 'object').and_return(body_mock)
215
- body_mock.stub :body => 'data'
216
- @s3.get_object_acl({ :bucket => 'bucket', :object_name => 'object'}).
217
- should == 'data'
218
- end
219
243
 
244
+ it "should set object acls" do
245
+ @fog_mock.should_receive(:put_object_acl).
246
+ with 'bucket', 'object', 'grants'
247
+ @s3.put_object_acl 'bucket', 'object', 'grants'
248
+ end
220
249
 
221
- it "should set object acls" do
222
- @fog_mock.should_receive(:put_object_acl).
223
- with 'bucket', 'object', 'grants'
224
- @s3.put_object_acl 'bucket', 'object', 'grants'
225
- end
250
+ it "should call put bucket with location_constraint us-west-1" do
251
+ options = { 'LocationConstraint' => 'us-west-1',
252
+ 'x-amz-acl' => 'private' }
253
+ @fog_mock.should_receive(:put_bucket).
254
+ with('name', options)
255
+ @s3.put_bucket 'name', 'us-west-1'
256
+ end
226
257
 
227
- it "should call put bucket with location_constraint us-west-1" do
228
- options = { 'LocationConstraint' => 'us-west-1',
229
- 'x-amz-acl' => 'private' }
230
- @fog_mock.should_receive(:put_bucket).
231
- with('name', options)
232
- @s3.put_bucket 'name', 'us-west-1'
233
- end
258
+ it "should call put bucket with location_constraint nil when region us-west-1" do
259
+ options = { 'LocationConstraint' => nil,
260
+ 'x-amz-acl' => 'private' }
261
+ @fog_mock.should_receive(:put_bucket).
262
+ with('name', options)
263
+ @s3.put_bucket 'name', 'us-east-1'
264
+ end
234
265
 
235
- it "should call put bucket with location_constraint nil when region us-west-1" do
236
- options = { 'LocationConstraint' => nil,
237
- 'x-amz-acl' => 'private' }
238
- @fog_mock.should_receive(:put_bucket).
239
- with('name', options)
240
- @s3.put_bucket 'name', 'us-east-1'
241
266
  end
242
-
243
-
244
267
  end
@@ -1,97 +1,121 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Heirloom do
4
- before do
5
- @config_mock = mock 'config'
6
- @config_mock.should_receive(:access_key).and_return 'the-key'
7
- @config_mock.should_receive(:secret_key).and_return 'the-secret'
8
- @config_mock.should_receive(:metadata_region).and_return 'us-west-1'
9
- @fog_mock = mock 'fog'
10
- Fog::AWS::SimpleDB.should_receive(:new).
11
- with(:aws_access_key_id => 'the-key',
12
- :aws_secret_access_key => 'the-secret',
13
- :region => 'us-west-1').
14
- and_return @fog_mock
15
- @sdb = Heirloom::AWS::SimpleDB.new :config => @config_mock
16
- end
17
4
 
18
- it "should list the domains in simples db" do
19
- body_mock = mock 'body'
20
- @fog_mock.should_receive(:list_domains).
21
- and_return body_mock
22
- body_mock.should_receive(:body).
23
- and_return 'Domains' => ['domain1']
24
- @sdb.domains.should == ['domain1']
25
- end
5
+ context "credential management" do
26
6
 
27
- it "should create a new domain when it does not exist" do
28
- @sdb.should_receive(:domains).and_return([])
29
- @fog_mock.should_receive(:create_domain).with('new_domain')
30
- @sdb.create_domain('new_domain')
31
- end
7
+ it "should use the access and secret keys by default" do
32
8
 
33
- it "should destroy the specified domain" do
34
- @fog_mock.should_receive(:delete_domain).with('new_domain')
35
- @sdb.delete_domain('new_domain')
36
- end
9
+ config = mock_config :aws_access_key_id => 'key',
10
+ :aws_secret_access_key => 'secret'
37
11
 
38
- it "should not create a new domain when already exists" do
39
- @sdb.should_receive(:domains).and_return(['new_domain'])
40
- @fog_mock.should_receive(:create_domain).exactly(0).times
41
- @sdb.create_domain('new_domain')
42
- end
12
+ Fog::AWS::SimpleDB.should_receive(:new).
13
+ with :aws_access_key_id => 'key',
14
+ :aws_secret_access_key => 'secret',
15
+ :region => 'us-west-1'
43
16
 
44
- it "should update the attributes for an entry" do
45
- @fog_mock.should_receive(:put_attributes).
46
- with('domain', 'key', {'key' => 'value'}, { "option" => "123" })
47
- @sdb.put_attributes('domain', 'key', {'key' => 'value'}, { "option" => "123" })
48
- end
17
+ s3 = Heirloom::AWS::SimpleDB.new :config => config
18
+
19
+ end
20
+
21
+ it "should use the iam role if asked to" do
22
+
23
+ config = mock_config :use_iam_profile => true
24
+
25
+ Fog::AWS::SimpleDB.should_receive(:new).
26
+ with :use_iam_profile => true,
27
+ :region => 'us-west-1'
28
+ s3 = Heirloom::AWS::SimpleDB.new :config => config
29
+
30
+ end
49
31
 
50
- it "should delete the given entry from sdb" do
51
- @fog_mock.should_receive(:delete_attributes).with('domain', 'key')
52
- @sdb.delete('domain', 'key')
53
32
  end
54
33
 
55
- context "testing counts" do
34
+ context "sdb operations" do
35
+
56
36
  before do
57
- @body_stub = stub 'body'
37
+ @fog_mock = mock 'fog'
38
+ Fog::AWS::SimpleDB.stub :new => @fog_mock
39
+ @sdb = Heirloom::AWS::SimpleDB.new :config => mock_config
58
40
  end
59
41
 
60
- it "should count the number of entries in the domain" do
61
- data = { 'Items' => { 'Domain' => { 'Count' => ['1'] } } }
62
- @fog_mock.should_receive(:select).
63
- with('SELECT count(*) FROM `heirloom_domain`').
64
- and_return @body_stub
65
- @body_stub.stub :body => data
66
- @sdb.count('heirloom_domain').should == 1
42
+ it "should list the domains in simples db" do
43
+ body_mock = mock 'body'
44
+ @fog_mock.should_receive(:list_domains).
45
+ and_return body_mock
46
+ body_mock.should_receive(:body).
47
+ and_return 'Domains' => ['domain1']
48
+ @sdb.domains.should == ['domain1']
67
49
  end
68
50
 
69
- it "should return true if no entries for the domain" do
70
- data = { 'Items' => { 'Domain' => { 'Count' => ['0'] } } }
71
- @fog_mock.should_receive(:select).
72
- with('SELECT count(*) FROM `heirloom_domain`').
73
- and_return @body_stub
74
- @body_stub.stub :body => data
75
- @sdb.domain_empty?('heirloom_domain').should be_true
51
+ it "should create a new domain when it does not exist" do
52
+ @sdb.should_receive(:domains).and_return([])
53
+ @fog_mock.should_receive(:create_domain).with('new_domain')
54
+ @sdb.create_domain('new_domain')
76
55
  end
77
56
 
78
- it "should return false if entries exist for the domain" do
79
- data = { 'Items' => { 'Domain' => { 'Count' => ['50'] } } }
80
- @fog_mock.should_receive(:select).
81
- with('SELECT count(*) FROM `heirloom_domain`').
82
- and_return @body_stub
83
- @body_stub.stub :body => data
84
- @sdb.domain_empty?('heirloom_domain').should be_false
57
+ it "should destroy the specified domain" do
58
+ @fog_mock.should_receive(:delete_domain).with('new_domain')
59
+ @sdb.delete_domain('new_domain')
85
60
  end
86
61
 
87
- it "should return the count for a specific itemName within a domain" do
88
- data = { 'Items' => { 'Domain' => { 'Count' => ['1'] } } }
89
- @fog_mock.should_receive(:select).
90
- with("SELECT count(*) FROM `heirloom` WHERE itemName() = 'archive'").
91
- and_return @body_stub
92
- @body_stub.stub :body => data
93
- @sdb.item_count('heirloom', 'archive').should == 1
62
+ it "should not create a new domain when already exists" do
63
+ @sdb.should_receive(:domains).and_return(['new_domain'])
64
+ @fog_mock.should_receive(:create_domain).exactly(0).times
65
+ @sdb.create_domain('new_domain')
66
+ end
67
+
68
+ it "should update the attributes for an entry" do
69
+ @fog_mock.should_receive(:put_attributes).
70
+ with('domain', 'key', {'key' => 'value'}, { "option" => "123" })
71
+ @sdb.put_attributes('domain', 'key', {'key' => 'value'}, { "option" => "123" })
72
+ end
73
+
74
+ it "should delete the given entry from sdb" do
75
+ @fog_mock.should_receive(:delete_attributes).with('domain', 'key')
76
+ @sdb.delete('domain', 'key')
94
77
  end
95
- end
96
78
 
79
+ context "testing counts" do
80
+ before do
81
+ @body_stub = stub 'body'
82
+ end
83
+
84
+ it "should count the number of entries in the domain" do
85
+ data = { 'Items' => { 'Domain' => { 'Count' => ['1'] } } }
86
+ @fog_mock.should_receive(:select).
87
+ with('SELECT count(*) FROM `heirloom_domain`').
88
+ and_return @body_stub
89
+ @body_stub.stub :body => data
90
+ @sdb.count('heirloom_domain').should == 1
91
+ end
92
+
93
+ it "should return true if no entries for the domain" do
94
+ data = { 'Items' => { 'Domain' => { 'Count' => ['0'] } } }
95
+ @fog_mock.should_receive(:select).
96
+ with('SELECT count(*) FROM `heirloom_domain`').
97
+ and_return @body_stub
98
+ @body_stub.stub :body => data
99
+ @sdb.domain_empty?('heirloom_domain').should be_true
100
+ end
101
+
102
+ it "should return false if entries exist for the domain" do
103
+ data = { 'Items' => { 'Domain' => { 'Count' => ['50'] } } }
104
+ @fog_mock.should_receive(:select).
105
+ with('SELECT count(*) FROM `heirloom_domain`').
106
+ and_return @body_stub
107
+ @body_stub.stub :body => data
108
+ @sdb.domain_empty?('heirloom_domain').should be_false
109
+ end
110
+
111
+ it "should return the count for a specific itemName within a domain" do
112
+ data = { 'Items' => { 'Domain' => { 'Count' => ['1'] } } }
113
+ @fog_mock.should_receive(:select).
114
+ with("SELECT count(*) FROM `heirloom` WHERE itemName() = 'archive'").
115
+ and_return @body_stub
116
+ @body_stub.stub :body => data
117
+ @sdb.item_count('heirloom', 'archive').should == 1
118
+ end
119
+ end
120
+ end
97
121
  end
@@ -10,12 +10,8 @@ describe Heirloom do
10
10
  :id => '1.0.0',
11
11
  :metadata_region => 'us-west-1' }
12
12
  @logger_stub = stub 'logger', :error => true
13
- @config_mock = mock 'config'
13
+ @config_mock = mock_config :logger => @logger_stub
14
14
  @archive_mock = mock 'archive'
15
- @config_mock.stub :logger => @logger_stub,
16
- :access_key => 'key',
17
- :secret_key => 'secret',
18
- :metadata_region => 'us-west-1'
19
15
  Trollop.stub(:options).and_return options
20
16
  Heirloom::HeirloomLogger.should_receive(:new).with(:log_level => 'info').
21
17
  and_return @logger_stub
@@ -10,13 +10,9 @@ describe Heirloom do
10
10
  { 'regions' => ['us-west-1'],
11
11
  'bucket_prefix' => ['bp'] } }
12
12
  @logger_stub = stub :debug => true
13
- @config_mock = mock 'config'
13
+ @config_mock = mock_config :logger => @logger_stub
14
14
  @catalog_mock = mock 'catalog'
15
15
  @catalog_mock.stub :catalog_domain_exists? => true
16
- @config_mock.stub :logger => @logger_mock,
17
- :access_key => 'key',
18
- :secret_key => 'secret',
19
- :metadata_region => 'us-west-1'
20
16
  Heirloom::HeirloomLogger.should_receive(:new).with(:log_level => 'info').
21
17
  and_return @logger_stub
22
18
  Heirloom::CLI::Catalog.any_instance.should_receive(:load_config).
@@ -9,12 +9,8 @@ describe Heirloom do
9
9
  :level => 'info',
10
10
  :metadata_region => 'us-west-1' }
11
11
  @logger_stub = stub 'logger'
12
- @config_mock = mock 'config'
12
+ @config_mock = mock_config :logger => @logger_stub
13
13
  @archive_mock = mock 'archive'
14
- @config_mock.stub :logger => @logger_stub,
15
- :access_key => 'key',
16
- :secret_key => 'secret',
17
- :metadata_region => 'us-west-1'
18
14
  Trollop.stub(:options).and_return options
19
15
  Heirloom::HeirloomLogger.should_receive(:new).with(:log_level => 'info').
20
16
  and_return @logger_stub
@@ -5,12 +5,8 @@ describe Heirloom do
5
5
 
6
6
  before do
7
7
  @logger_stub = stub 'logger'
8
- @config_mock = mock 'config'
8
+ @config_mock = mock_config :logger => @logger_stub
9
9
  @archive_mock = mock 'archive'
10
- @config_mock.stub :logger => @logger_stub,
11
- :access_key => 'key',
12
- :secret_key => 'secret',
13
- :metadata_region => 'us-west-1'
14
10
  Heirloom::HeirloomLogger.should_receive(:new).
15
11
  with(:log_level => 'info').
16
12
  and_return @logger_stub
@@ -9,12 +9,8 @@ describe Heirloom do
9
9
  :metadata_region => 'us-west-1',
10
10
  :count => 100 }
11
11
  @logger_stub = stub :debug => true
12
- @config_mock = mock 'config'
12
+ @config_mock = mock_config :logger => @logger_stub
13
13
  @archive_mock = mock 'archive'
14
- @config_mock.stub :logger => @logger_mock,
15
- :access_key => 'key',
16
- :secret_key => 'secret',
17
- :metadata_region => 'us-west-1'
18
14
  Heirloom::HeirloomLogger.should_receive(:new).with(:log_level => 'info').
19
15
  and_return @logger_stub
20
16
  Heirloom::CLI::List.any_instance.should_receive(:load_config).
@@ -12,11 +12,7 @@ describe Heirloom do
12
12
  :metadata_region => 'us-west-1' }
13
13
 
14
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'
15
+ @config_mock = mock_config :logger => @logger_stub
20
16
  @archive_mock = mock 'archive'
21
17
  @catalog_mock = mock 'catalog'
22
18
  @checker_mock = mock 'checker'
@@ -7,12 +7,8 @@ describe Heirloom do
7
7
  context "testing ensure_valid_options" do
8
8
 
9
9
  before do
10
- @config_mock = mock 'config'
11
10
  @logger_mock = mock 'logger'
12
- @config_mock.stub :logger => @logger_mock,
13
- :access_key => 'key',
14
- :secret_key => 'secret',
15
- :metadata_region => 'us-west-1'
11
+ @config_mock = mock_config(:logger => @logger_mock)
16
12
  @object = Object.new
17
13
  @object.extend Heirloom::CLI::Shared
18
14
  end
@@ -10,12 +10,8 @@ describe Heirloom do
10
10
  :level => 'info',
11
11
  :metadata_region => 'us-west-1' }
12
12
  @logger_stub = stub :debug => true
13
- @config_mock = mock 'config'
13
+ @config_mock = mock_config(:logger => @logger_stub)
14
14
  @archive_mock = mock 'archive'
15
- @config_mock.stub :logger => @logger_stub,
16
- :access_key => 'key',
17
- :secret_key => 'secret',
18
- :metadata_region => 'us-west-1'
19
15
  Heirloom::HeirloomLogger.should_receive(:new).with(:log_level => 'info').
20
16
  and_return @logger_stub
21
17
  Heirloom::CLI::Show.any_instance.should_receive(:load_config).
@@ -11,12 +11,9 @@ describe Heirloom do
11
11
  :value => 'val',
12
12
  :metadata_region => 'us-west-1' }
13
13
  @logger_stub = stub :debug => true, :error => true
14
- @config_mock = mock 'config'
14
+ @config_mock = mock_config(:logger => @logger_stub)
15
15
  @archive_mock = mock 'archive'
16
- @config_mock.stub :logger => @logger_stub,
17
- :access_key => 'key',
18
- :secret_key => 'secret',
19
- :metadata_region => 'us-west-1'
16
+
20
17
  Trollop.stub(:options).and_return options
21
18
  Heirloom::HeirloomLogger.should_receive(:new).with(:log_level => 'info').
22
19
  and_return @logger_stub
@@ -9,11 +9,7 @@ describe Heirloom do
9
9
  :metadata_region => 'us-west-1' }
10
10
 
11
11
  @logger_stub = stub 'logger', :error => true, :info => true
12
- @config_mock = mock 'config'
13
- @config_mock.stub :logger => @logger_stub,
14
- :access_key => 'key',
15
- :secret_key => 'secret',
16
- :metadata_region => 'us-west-1'
12
+ @config_mock = mock_config(:logger => @logger_stub)
17
13
  @archive_mock = mock 'archive'
18
14
  @catalog_mock = mock 'catalog'
19
15
  @catalog_mock.stub :regions => ['us-west-1', 'us-west-2']
@@ -15,11 +15,7 @@ describe Heirloom do
15
15
  :metadata_region => 'us-west-1' }
16
16
 
17
17
  @logger_stub = stub 'logger', :error => true, :info => true
18
- @config_mock = mock 'config'
19
- @config_mock.stub :logger => @logger_stub,
20
- :access_key => 'key',
21
- :secret_key => 'secret',
22
- :metadata_region => 'us-west-1'
18
+ @config_mock = mock_config(:logger => @logger_stub)
23
19
  @archive_mock = mock 'archive'
24
20
  @catalog_mock = mock 'catalog'
25
21
  @catalog_mock.stub :regions => @regions,
@@ -3,6 +3,24 @@ require 'bundler/setup'
3
3
 
4
4
  require 'heirloom'
5
5
 
6
+ module SpecHelpers
7
+
8
+ def mock_config(args={})
9
+ args[:logger] ||= stub :debug => true, :info => true, :warn => true, :error => true
10
+ args[:access_key] ||= 'key'
11
+ args[:secret_key] ||= 'secret'
12
+ args[:metadata_region] ||= 'us-west-1'
13
+ args[:use_iam_profile] ||= false
14
+
15
+ config_mock = mock 'config'
16
+ config_mock.stub args
17
+
18
+ config_mock
19
+ end
20
+
21
+ end
22
+
6
23
  RSpec.configure do |config|
7
- #spec config
24
+ config.include SpecHelpers
8
25
  end
26
+
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heirloom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0.beta.2
5
- prerelease: 7
4
+ version: 0.11.0
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brett Weaver
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-12 00:00:00.000000000 Z
12
+ date: 2013-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -235,13 +235,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
235
235
  version: '0'
236
236
  segments:
237
237
  - 0
238
- hash: -211146683438990673
238
+ hash: -4406439853802667005
239
239
  required_rubygems_version: !ruby/object:Gem::Requirement
240
240
  none: false
241
241
  requirements:
242
- - - ! '>'
242
+ - - ! '>='
243
243
  - !ruby/object:Gem::Version
244
- version: 1.3.1
244
+ version: '0'
245
+ segments:
246
+ - 0
247
+ hash: -4406439853802667005
245
248
  requirements: []
246
249
  rubyforge_project: heirloom
247
250
  rubygems_version: 1.8.24