vault-tools 0.4.10 → 0.4.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,4 +3,3 @@ rvm:
3
3
  - 2.0.0
4
4
  - 1.9.3
5
5
  - jruby-19mode # JRuby in 1.9 mode
6
- - rbx-2.1.1
@@ -66,3 +66,4 @@ require 'vault-tools/web'
66
66
  require 'vault-tools/pipeline'
67
67
  require 'vault-tools/text_processor'
68
68
  require 'vault-tools/time'
69
+ require 'vault-tools/s3'
@@ -0,0 +1,35 @@
1
+ module S3
2
+ extend self
3
+
4
+ # Write value to key in S3 bucket, with logging.
5
+ #
6
+ # @param bucket [String]
7
+ # @param key [String]
8
+ # @param value [String]
9
+ def write(bucket, key, value)
10
+ Vault::Log.log(:fn => __method__, :key => key) do
11
+ s3.buckets[bucket].objects[key].write(value)
12
+ end
13
+ end
14
+
15
+ # Read value from key in S3 bucket, with logging.
16
+ #
17
+ # @param bucket [String]
18
+ # @param key [String]
19
+ def read(bucket, key)
20
+ Vault::Log.log(:fn => __method__, :key => key) do
21
+ s3.buckets[bucket].objects[key].read
22
+ end
23
+ end
24
+
25
+ # Get the underlying AWS::S3 instance, creating it using environment vars
26
+ # if necessary.
27
+ def s3
28
+ @s3 ||= AWS::S3.new(
29
+ :access_key_id => Config.env('AWS_ACCESS_KEY_ID'),
30
+ :secret_access_key => Config.env('AWS_SECRET_ACCESS_KEY'),
31
+ :use_ssl => true
32
+ )
33
+ end
34
+
35
+ end
@@ -1,5 +1,5 @@
1
1
  module Vault
2
2
  module Tools
3
- VERSION = '0.4.10'
3
+ VERSION = '0.4.11'
4
4
  end
5
5
  end
@@ -1,5 +1,7 @@
1
1
  require 'vault-test-tools'
2
2
  require 'vault-tools'
3
+ require 'aws-sdk'
4
+ require 'rr'
3
5
 
4
6
  ENV['RACK_ENV'] = 'test'
5
7
 
@@ -1,7 +1,6 @@
1
1
  require 'helper'
2
2
 
3
3
  class LogTest < Vault::TestCase
4
- include Vault::Test::EnvironmentHelpers
5
4
  include LoggedDataHelper
6
5
 
7
6
  def setup
@@ -0,0 +1,55 @@
1
+ require 'helper'
2
+
3
+ class SomeS3Consumer
4
+ include S3
5
+ end
6
+
7
+ class S3Test < Vault::TestCase
8
+ include LoggedDataHelper
9
+
10
+ def setup
11
+ super
12
+ set_env 'APP_DEPLOY', 'test'
13
+ set_env 'AWS_ACCESS_KEY_ID', 'fake access key id'
14
+ set_env 'AWS_SECRET_ACCESS_KEY', 'fake secret access key'
15
+ AWS.stub!
16
+ @consumer = SomeS3Consumer.new
17
+ end
18
+
19
+ def log_output
20
+ Scrolls.stream.string
21
+ end
22
+
23
+ # S3 writes should be logged.
24
+ def test_write_logs
25
+ @consumer.write('fake bucket', 'fake key', 'fake value')
26
+ assert_match /fake key/, log_output
27
+ end
28
+
29
+ # S3 reads should be logged.
30
+ def test_read_logs
31
+ @consumer.read('fake bucket', 'fake key')
32
+ assert_match /fake key/, log_output
33
+ end
34
+
35
+ # Should use S3 to write to bucket
36
+ def test_writes_to_s3_bucket
37
+ mock(@consumer).s3.mock!.buckets.
38
+ mock!.[]('fake bucket').
39
+ mock!.objects.
40
+ mock!.[]('fake key').
41
+ mock!.write('fake value')
42
+ @consumer.write('fake bucket', 'fake key', 'fake value')
43
+ end
44
+
45
+ # Should use S3 to read from bucket
46
+ def test_reads_from_s3_bucket
47
+ #s3.buckets[bucket].objects[key].read
48
+ mock(@consumer).s3.mock!.buckets.
49
+ mock!.[]('fake bucket').
50
+ mock!.objects.
51
+ mock!.[]('fake key').
52
+ mock!.read
53
+ @consumer.read('fake bucket', 'fake key')
54
+ end
55
+ end
@@ -26,4 +26,5 @@ Gem::Specification.new do |gem|
26
26
  gem.add_dependency 'honeybadger'
27
27
  gem.add_dependency 'rdoc'
28
28
  gem.add_dependency 'yard'
29
+ gem.add_dependency 'aws-sdk'
29
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vault-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.10
4
+ version: 0.4.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -156,6 +156,22 @@ dependencies:
156
156
  - - ! '>='
157
157
  - !ruby/object:Gem::Version
158
158
  version: '0'
159
+ - !ruby/object:Gem::Dependency
160
+ name: aws-sdk
161
+ requirement: !ruby/object:Gem::Requirement
162
+ none: false
163
+ requirements:
164
+ - - ! '>='
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ type: :runtime
168
+ prerelease: false
169
+ version_requirements: !ruby/object:Gem::Requirement
170
+ none: false
171
+ requirements:
172
+ - - ! '>='
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
159
175
  description: Basic tools for Heroku Vault's Ruby projects
160
176
  email:
161
177
  - christopher.continanza@gmail.com
@@ -185,6 +201,7 @@ files:
185
201
  - lib/vault-tools/payments_db_tasks.rb
186
202
  - lib/vault-tools/pipeline.rb
187
203
  - lib/vault-tools/product.rb
204
+ - lib/vault-tools/s3.rb
188
205
  - lib/vault-tools/sinatra_helpers/html_serializer.rb
189
206
  - lib/vault-tools/text_processor.rb
190
207
  - lib/vault-tools/time.rb
@@ -200,6 +217,7 @@ files:
200
217
  - test/log_test.rb
201
218
  - test/pipeline_test.rb
202
219
  - test/product_test.rb
220
+ - test/s3_test.rb
203
221
  - test/text_processor_test.rb
204
222
  - test/time_test.rb
205
223
  - test/user_test.rb
@@ -219,7 +237,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
219
237
  version: '0'
220
238
  segments:
221
239
  - 0
222
- hash: -3939315679602429457
240
+ hash: -4329855813357893782
223
241
  required_rubygems_version: !ruby/object:Gem::Requirement
224
242
  none: false
225
243
  requirements:
@@ -228,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
246
  version: '0'
229
247
  segments:
230
248
  - 0
231
- hash: -3939315679602429457
249
+ hash: -4329855813357893782
232
250
  requirements: []
233
251
  rubyforge_project:
234
252
  rubygems_version: 1.8.23