s3-publisher 0.9.3 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f80c63b946040a1ad65feb3d5ccf603f2dc8125
4
- data.tar.gz: 3d10cace13da6a1e150cc869394f738bc0687d27
3
+ metadata.gz: 4c5f5fd908bd87713d65bad6e7429c1090284f35
4
+ data.tar.gz: d58aabf2f780673028dd3b5e342dbba86aa00b21
5
5
  SHA512:
6
- metadata.gz: 28cd6ac4555baecede5cc524e37d8a187e3931db820f43345548c39334748684ad11db3f266f32505b220ee3bdc461f5ef51a08cc19aef001279a94c934efe87
7
- data.tar.gz: d991ec0ae159bad2c0687baa6df0edb840923491366f21f399915a088f34cc4e1a65ea90591d03fbfb4c133309330857dc60679412875c535fab2e6910020ed4
6
+ metadata.gz: 5281ecababe99562e4795a2f13072ec5791ba8c0a74f6087a5a298a844c8251208ddd3d3ce2d63779fbc92fa80059339b4e8283b43c4775ec8538e897ea0575f
7
+ data.tar.gz: 55284b8a3218c84982ad925297cd5fefd9d7d4a7bb59018c883622bf7a73611033cfcabf3286eb31faf34398492d5ffa86a684e45f7d381fbb6f7fe1f4880fa3
data/Gemfile.lock CHANGED
@@ -1,22 +1,48 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- s3-publisher (0.4.3)
5
- aws_credentials
6
- right_aws (>= 3.0.0)
4
+ s3-publisher (2.0.0)
5
+ aws-sdk (>= 2.0)
6
+ mime-types
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- aws_credentials (0.7.0)
12
- right_aws (3.1.0)
13
- right_http_connection (>= 1.2.5)
14
- right_http_connection (1.4.0)
15
- thoughtbot-shoulda (2.11.1)
11
+ aws-sdk (2.2.29)
12
+ aws-sdk-resources (= 2.2.29)
13
+ aws-sdk-core (2.2.29)
14
+ jmespath (~> 1.0)
15
+ aws-sdk-resources (2.2.29)
16
+ aws-sdk-core (= 2.2.29)
17
+ diff-lcs (1.2.5)
18
+ jmespath (1.1.3)
19
+ metaclass (0.0.4)
20
+ mime-types (3.0)
21
+ mime-types-data (~> 3.2015)
22
+ mime-types-data (3.2016.0221)
23
+ mocha (1.1.0)
24
+ metaclass (~> 0.0.1)
25
+ rspec (3.4.0)
26
+ rspec-core (~> 3.4.0)
27
+ rspec-expectations (~> 3.4.0)
28
+ rspec-mocks (~> 3.4.0)
29
+ rspec-core (3.4.4)
30
+ rspec-support (~> 3.4.0)
31
+ rspec-expectations (3.4.0)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.4.0)
34
+ rspec-mocks (3.4.1)
35
+ diff-lcs (>= 1.2.0, < 2.0)
36
+ rspec-support (~> 3.4.0)
37
+ rspec-support (3.4.1)
16
38
 
17
39
  PLATFORMS
18
40
  ruby
19
41
 
20
42
  DEPENDENCIES
43
+ mocha (>= 1.1.0)
44
+ rspec
21
45
  s3-publisher!
22
- thoughtbot-shoulda
46
+
47
+ BUNDLED WITH
48
+ 1.11.2
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Quickly pub your data files to S3.
4
4
 
5
+ **This version depends on aws-sdk 2.x. For aws-sdk 1.x projects, use version <= 1.0 of this gem.**
6
+
5
7
  Reasons you might want to use this instead of aws-sdk directly:
6
8
 
7
9
  * parallel uploads using ruby threads. Concurrency defaults to 3 but can be increased.
@@ -38,7 +40,7 @@ end
38
40
  ### Slightly more advanced example:
39
41
 
40
42
  ```
41
- S3Publisher.publish('my-bucket', :base_path => 'world_cup', :region => 'us-west-1') do |p|
43
+ S3Publisher.publish('my-bucket', base_path: 'world_cup', region: 'us-west-1') do |p|
42
44
  p.push('events.xml', data: '<xml>...', ttl: 15)
43
45
  end
44
46
  ```
@@ -55,7 +57,11 @@ See class docs for more options.
55
57
 
56
58
  Since S3Publisher uses [aws-sdk](https://github.com/aws/aws-sdk-ruby) any of the usual credential stores will work, including:
57
59
 
58
- * `AWS.config(access_key_id: '...', secret_access_key: '...', region: 'us-west-2')`
59
- * `config/aws.yml` in a RAILS project
60
- * ENV vars
61
-
60
+ * `ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY'], ENV['AWS_REGION']`
61
+ * IAM role
62
+ * ```
63
+ Aws.config.update({
64
+ region: 'us-west-2',
65
+ credentials: Aws::Credentials.new('akid', 'secret')
66
+ })
67
+ ```
data/lib/s3-publisher.rb CHANGED
@@ -27,24 +27,19 @@ class S3Publisher
27
27
  # @option opts [String] :base_path Path prepended to supplied file_name on upload
28
28
  # @option opts [Integer] :workers Number of threads to use when pushing to S3. Defaults to 3.
29
29
  # @option opts [Object] :logger A logger object to recieve 'uploaded' messages. Defaults to STDOUT.
30
- # @option opts [String] :access_key_id AWS access key to use, if different than global AWS config
31
- # @option opts [String] :secret_access_key AWS secret access key to use, if different than global AWS config
32
- # @option opts [String] :region AWS region to use, if different than global AWS config
30
+ #
31
+ # Additional keys will be passed through to the Aws::S3::Client init, including:
32
+ # @option opts [String] :region AWS region to use, if different than global Aws config
33
+ # @option opts [Object] :credentials - :access_key_id, :secret_access_key, and :session_token options, if different than global Aws config
34
+ # See http://docs.aws.amazon.com/sdkforruby/api/Aws/S3/Client.html#initialize-instance_method for full details.
33
35
 
34
36
  def initialize bucket_name, opts={}
35
37
  @publish_queue = Queue.new
36
- @workers_to_use = opts[:workers] || 3
37
- @logger = opts[:logger] || $stdout
38
-
39
- s3_opts = {}
40
- s3_opts[:access_key_id] = opts[:access_key_id] if opts.key?(:access_key_id)
41
- s3_opts[:secret_access_key] = opts[:secret_access_key] if opts.key?(:secret_access_key)
42
- s3_opts[:region] = opts[:region] if opts.key?(:region)
43
-
44
- @s3 = AWS::S3.new(s3_opts)
38
+ @workers_to_use = opts.delete(:workers) || 3
39
+ @logger = opts.delete(:logger) || $stdout
40
+ @bucket_name, @base_path = bucket_name, opts.delete(:base_path)
45
41
 
46
- @bucket_name, @base_path = bucket_name, opts[:base_path]
47
- raise ArgumentError, "#{bucket_name} doesn't seem to be a valid bucket on your account" if @s3.buckets[bucket_name].nil?
42
+ @s3 = Aws::S3::Client.new(opts)
48
43
  end
49
44
 
50
45
  # Queues a file to be published.
@@ -124,8 +119,6 @@ class S3Publisher
124
119
 
125
120
  try_count = 0
126
121
  begin
127
- obj = @s3.buckets[bucket_name].objects[item[:key_name]]
128
-
129
122
  gzip = item[:gzip] != false && !item[:write_opts][:content_type].match('image/')
130
123
 
131
124
  if gzip
@@ -134,7 +127,14 @@ class S3Publisher
134
127
  item[:contents] = gzip(gzip_body)
135
128
  end
136
129
 
137
- obj.write(item[:contents], item[:write_opts])
130
+ write_opts = {
131
+ bucket: bucket_name,
132
+ key: item[:key_name],
133
+ body: item[:contents]
134
+ }
135
+ write_opts.merge!(item[:write_opts])
136
+
137
+ @s3.put_object(write_opts)
138
138
 
139
139
  rescue Exception => e # backstop against transient S3 errors
140
140
  raise e if try_count >= 1
data/s3-publisher.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "s3-publisher"
5
- s.version = "0.9.3"
5
+ s.version = "2.0.0"
6
6
  s.authors = ["Ben Koski"]
7
7
  s.email = "bkoski@nytimes.com"
8
8
  s.summary = "Publish data to S3 for the world to see"
@@ -16,7 +16,9 @@ Gem::Specification.new do |s|
16
16
 
17
17
  s.require_paths = ["lib"]
18
18
 
19
- s.add_development_dependency(%q<rspec>, [">= 0"])
20
- s.add_runtime_dependency(%q<aws-sdk>, ["~> 1.0"])
19
+ s.add_runtime_dependency(%q<aws-sdk>, [">= 2.0"])
21
20
  s.add_runtime_dependency(%q<mime-types>, [">= 0"])
21
+
22
+ s.add_development_dependency(%q<rspec>, [">= 0"])
23
+ s.add_development_dependency(%q<mocha>, [">= 1.1.0"])
22
24
  end
@@ -4,16 +4,16 @@ describe S3Publisher do
4
4
  describe "#push" do
5
5
 
6
6
  describe "file_name" do
7
- it "prepends base_path if provided" do
7
+ it "prepends base_path if provided", focus: true do
8
8
  set_put_expectation(key_name: 'world_cup_2010/events.xml')
9
- p = S3Publisher.new('test-bucket', :logger => Logger.new(nil), :base_path => 'world_cup_2010')
9
+ p = S3Publisher.new('test-bucket', logger: Logger.new(nil), base_path: 'world_cup_2010')
10
10
  p.push('events.xml', data: '1234')
11
11
  p.run
12
12
  end
13
13
 
14
14
  it "passes name through unaltered if base_path not specified" do
15
15
  set_put_expectation(key_name: 'events.xml')
16
- p = S3Publisher.new('test-bucket', :logger => Logger.new(nil))
16
+ p = S3Publisher.new('test-bucket', logger: Logger.new(nil))
17
17
  p.push('events.xml', data: '1234')
18
18
  p.run
19
19
  end
@@ -92,10 +92,6 @@ describe S3Publisher do
92
92
  # * :data
93
93
  # * :content_type, :cache_control, :content_encoding
94
94
  def set_put_expectation opts
95
- s3_stub = mock()
96
- bucket_stub = mock()
97
- object_stub = mock()
98
-
99
95
  key_name = opts[:key_name] || 'myfile.txt'
100
96
 
101
97
  expected_entries = {}
@@ -111,12 +107,9 @@ describe S3Publisher do
111
107
  expected_contents = anything
112
108
  end
113
109
 
114
- object_stub.expects(:write).with(expected_contents, has_entries(expected_entries))
110
+ expected_entries.merge!(bucket: 'test-bucket', key: key_name, body: expected_contents)
115
111
 
116
- s3_stub.stubs(:buckets).returns({'test-bucket' => bucket_stub })
117
- bucket_stub.stubs(:objects).returns({ key_name => object_stub })
118
-
119
- AWS::S3.stubs(:new).returns(s3_stub)
112
+ Aws::S3::Client.any_instance.expects(:put_object).with(has_entries(expected_entries))
120
113
  end
121
114
 
122
115
  def gzip data
@@ -130,7 +123,7 @@ describe S3Publisher do
130
123
  end
131
124
 
132
125
  def push_test_data file_name, opts
133
- p = S3Publisher.new('test-bucket', :logger => Logger.new(nil))
126
+ p = S3Publisher.new('test-bucket', logger: Logger.new(nil))
134
127
  p.push(file_name, opts)
135
128
  p.run
136
129
  end
data/spec/spec_helper.rb CHANGED
@@ -7,6 +7,8 @@
7
7
 
8
8
  require File.expand_path('../lib/s3-publisher.rb', File.dirname(__FILE__))
9
9
 
10
+ ENV['AWS_REGION'] = 'us-east-1'
11
+
10
12
  RSpec.configure do |config|
11
13
  # Limit the spec run to only specs with the focus metadata. If no specs have
12
14
  # the filtering metadata and `run_all_when_everything_filtered = true` then
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3-publisher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Koski
@@ -11,47 +11,61 @@ cert_chain: []
11
11
  date: 2016-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: aws-sdk
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
19
+ version: '2.0'
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: aws-sdk
28
+ name: mime-types
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '1.0'
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '1.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: mime-types
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
- type: :runtime
48
+ type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.1.0
55
69
  description: Publish data to S3 for the world to see
56
70
  email: bkoski@nytimes.com
57
71
  executables: []