blobby-s3 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb92e09ebb4fb6aa87581485a6fb49e926f97746
4
- data.tar.gz: 426467d4d7cde0580260e569132c728fff71eea0
3
+ metadata.gz: 815ee79119fea852e7da5b17a52a0da336e0be7d
4
+ data.tar.gz: 8e1817e54d7ac8c92e7fe752e14cb1ffb11fdb88
5
5
  SHA512:
6
- metadata.gz: 0c2519c24da67688afb17718f8c9b1b49a4d3bd8be9d50592fab3e79e0f1e9a1e46561bbd3ba9d1c413a60a279b43abe843a8a18a5360453281ba86ae64cfc91
7
- data.tar.gz: abaf0b989d2a9ffa8e143fe3b6ac3a9c2898a8a74a5104d50d0bd602f670bddde6fcc7fa9254a33b4028b8f586dd2dc3b7becc5e8bb9daa9d1f973d1ad2a46a3
6
+ metadata.gz: 43ba0af1954d399a279969035cfc8480f998cd74e74cd71125cacdfe131e929113d16ff2516cb073abe39603a0d3fefc03f65549e7d676c64bb37ec0a7f216ad
7
+ data.tar.gz: 4504c6c2ba203320779a0374088c3dd00544a7ea73bdea31fa84d874b93ac548a7142112cd5423d3da4db1a3a547d08be72a6ef669f91d9238ecb7164bb49492
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ env:
5
+ global:
6
+ - AWS_DEFAULT_REGION=us-east-1
7
+ - BLOBBY_S3_TEST_BUCKET=fake-aws-sdk-s3-test
8
+ - AWS_ACCESS_KEY_ID=AKIAJ6LW4DFV3RH4Z6OQ
9
+ - secure: RozEwNe8txMO8jqo/hFWnusfiUSpvz2yN6bDe1G/8bW3pOmjYT319qL5jAIHBxQFohHpUsJMxwsjS07yNq1rlBDuiDJsNnZW6RGzOuVTztaxgjeauo8X4vV3PkZU6Ln0qoYPQiCsIwQfczBpno2Eor0E1BuOXcZGtHsFoQQxWiBG9RkCelGx+ZeMuP/v8EuV4Fd5YOJgzTqWGuaFXEONqeeTVmUoObltJnPCcdpYMzI/+Wn2/dU2gnpRxTJHGrgmVKRWn/M0I7aIEQ9FeJuPVahcdkCPHfzoceTySdl/YVMcjsu6PsHPAQywo6qo4MShV/VI0cUw6hWOf9X9tzdZamyKnaeY1EaIw0C/sZ2dn7dsbRzIn9ls+mI2y32khMX/AG8hze2udKhq3Ai1gREYjo0vvU6q/i2DAoDETaP/Ig3qJshzz1XntBx9NAGkzad3xbkRB9p/e60pfB9E4ZxZG+OSkUi7AGu68ZlI2ceSus46QkG6ya9FNUnJTQEuaUvrg7EASiuKBjQia8Ce9GwzujAxZWVRwWDjvTg3Wo5oGxfVmHWEleVVTFtuuvkroChyetgr/1iLXOigvssHRYFPlDhWKH/bJ9gjyYequEJxoBREwW/Qe3u4kCGgR0vz0CWcVP9RRejTm4RDUpmcreun423WTmq5UWmb9Pj5Fd1f3wM=
data/CHANGES.md ADDED
@@ -0,0 +1,8 @@
1
+ ## 1.1.0 (2016-05-22)
2
+
3
+ * Add support for streaming reads.
4
+ * Implement `Blobby.store("s3://bucket/prefix")`
5
+
6
+ ## 1.0.0 (2015-10-02)
7
+
8
+ * Initial release.
data/Gemfile CHANGED
@@ -3,6 +3,5 @@ source "https://rubygems.org"
3
3
  # Runtime dependencies in *.gemspec
4
4
  gemspec
5
5
 
6
- gem "blobby", :path => "../blobby"
7
6
  gem "rake"
8
7
  gem "rspec", "~> 3.1"
data/README.md CHANGED
@@ -1,10 +1,12 @@
1
1
  # Blobby::S3Store
2
2
 
3
+ [![Build Status](https://travis-ci.org/realestate-com-au/blobby-s3.svg?branch=master)](https://travis-ci.org/realestate-com-au/blobby-s3)
4
+
3
5
  This gem provides an S3-based implementation of the "store" interface defined by the ["blobby"](https://github.com/realestate-com-au/blobby) gem. It's been packaged separately, to avoid adding dependencies to the core gem.
4
6
 
5
7
  The simplest use-case is writing to a single bucket:
6
8
 
7
- s3_store = Blobby::S3Store.new("mybucket")
9
+ s3_store = Blobby.store("s3://mybucket")
8
10
  s3_store["key"].write("something big")
9
11
 
10
12
  Credentials can be provided, if required:
data/Rakefile CHANGED
@@ -6,4 +6,6 @@ Bundler::GemHelper.install_tasks
6
6
 
7
7
  require "rspec/core/rake_task"
8
8
 
9
+ RSpec::Core::RakeTask.new(:spec)
10
+
9
11
  task "default" => "spec"
data/blobby-s3.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
8
8
  gem.homepage = "https://github.com/realestate-com.au/blobby-s3"
9
9
 
10
10
  gem.name = "blobby-s3"
11
- gem.version = "1.0.0"
11
+ gem.version = "1.1.0"
12
12
 
13
13
  gem.files = `git ls-files`.split($OUTPUT_RECORD_SEPARATOR)
14
14
  gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
@@ -16,6 +16,6 @@ Gem::Specification.new do |gem|
16
16
  gem.require_paths = ["lib"]
17
17
 
18
18
  gem.add_runtime_dependency("aws-sdk-resources", "~> 2.1")
19
- gem.add_runtime_dependency("blobby")
19
+ gem.add_runtime_dependency("blobby", "~> 1.1.0")
20
20
 
21
21
  end
data/lib/blobby-s3.rb ADDED
@@ -0,0 +1 @@
1
+ require "blobby/s3_store"
@@ -1,5 +1,7 @@
1
1
  require "aws-sdk-resources"
2
- require "blobby/key_constraint"
2
+ require "blobby"
3
+ require "blobby/key_transforming_store"
4
+ require "uri"
3
5
 
4
6
  module Blobby
5
7
 
@@ -7,6 +9,19 @@ module Blobby
7
9
  #
8
10
  class S3Store
9
11
 
12
+ def self.from_uri(uri)
13
+ uri = URI(uri)
14
+ raise ArgumentError, "invalid S3 address: #{uri}" unless uri.scheme == "s3"
15
+ bucket_name = uri.host
16
+ prefix = uri.path.sub(%r{\A/}, "").sub(%r{/\Z}, "")
17
+ raise ArgumentError, "no bucket specified" if bucket_name.nil?
18
+ store = new(bucket_name)
19
+ unless prefix.empty?
20
+ store = KeyTransformingStore.new(store) { |key| prefix + "/" + key }
21
+ end
22
+ store
23
+ end
24
+
10
25
  # Create a new instance.
11
26
  #
12
27
  # bucket_name - name of the bucket to store things in
@@ -44,14 +59,13 @@ module Blobby
44
59
  end
45
60
 
46
61
  def read
47
- body = s3_object.get.body
48
62
  if block_given?
49
- body.each_line do |line|
50
- yield force_binary(line)
63
+ s3_object.get do |chunk|
64
+ yield force_binary(chunk)
51
65
  end
52
66
  nil
53
67
  else
54
- force_binary(body.read)
68
+ force_binary(s3_object.get.body.read)
55
69
  end
56
70
  rescue Aws::S3::Errors::NoSuchKey
57
71
  nil
@@ -110,4 +124,6 @@ module Blobby
110
124
 
111
125
  end
112
126
 
127
+ register_store_factory "s3", S3Store
128
+
113
129
  end
@@ -7,6 +7,62 @@ $LOAD_PATH << Gem.loaded_specs["blobby"].full_gem_path + "/spec"
7
7
 
8
8
  require "blobby/store_behaviour"
9
9
 
10
+ describe Blobby::S3Store do
11
+
12
+ describe ".from_uri" do
13
+
14
+ context "with s3://bucket" do
15
+
16
+ let(:store) { described_class.from_uri("s3://bucket") }
17
+
18
+ it "creates an S3Store" do
19
+ expect(store).to be_a(described_class)
20
+ end
21
+
22
+ it "maps objects to the specified bucket" do
23
+ expect(store["object"].send(:s3_object).bucket.name).to eql("bucket")
24
+ end
25
+
26
+ it "maps objects with the specified names" do
27
+ expect(store["object"].send(:s3_object).key).to eql("object")
28
+ end
29
+
30
+ end
31
+
32
+ context "with s3://bucket/prefix/" do
33
+
34
+ let(:store) { described_class.from_uri("s3://bucket/prefix/") }
35
+
36
+ it "maps objects with the specified prefix" do
37
+ expect(store["object"].send(:s3_object).key).to eql("prefix/object")
38
+ end
39
+
40
+ end
41
+
42
+ context "with non-S3 uri" do
43
+
44
+ it "raises ArgumentError" do
45
+ expect {
46
+ described_class.from_uri("http://bucket")
47
+ }.to raise_error(ArgumentError)
48
+ end
49
+
50
+ end
51
+
52
+ context "without a bucket" do
53
+
54
+ it "raises ArgumentError" do
55
+ expect {
56
+ described_class.from_uri("s3://")
57
+ }.to raise_error(ArgumentError)
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+
10
66
  describe Blobby::S3Store, :integration => true do
11
67
 
12
68
  before(:all) do
@@ -17,7 +73,7 @@ describe Blobby::S3Store, :integration => true do
17
73
 
18
74
  context "with a writable bucket" do
19
75
 
20
- EXISTING_BUCKET_NAME = "fake-aws-sdk-s3-test"
76
+ EXISTING_BUCKET_NAME = ENV.fetch("BLOBBY_S3_TEST_BUCKET", "fake-aws-sdk-s3-test")
21
77
 
22
78
  let(:s3_resource) { Aws::S3::Resource.new(:region => "us-east-1")}
23
79
  let(:bucket) { s3_resource.bucket(EXISTING_BUCKET_NAME) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blobby-s3
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-02 00:00:00.000000000 Z
11
+ date: 2016-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-resources
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: blobby
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 1.1.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: '0'
40
+ version: 1.1.0
41
41
  description:
42
42
  email:
43
43
  - mdub@dogbiscuit.org
@@ -48,10 +48,13 @@ files:
48
48
  - ".gitignore"
49
49
  - ".rspec"
50
50
  - ".rubocop.yml"
51
+ - ".travis.yml"
52
+ - CHANGES.md
51
53
  - Gemfile
52
54
  - README.md
53
55
  - Rakefile
54
56
  - blobby-s3.gemspec
57
+ - lib/blobby-s3.rb
55
58
  - lib/blobby/s3_store.rb
56
59
  - spec/blobby/s3_store_spec.rb
57
60
  homepage: https://github.com/realestate-com.au/blobby-s3
@@ -73,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
76
  version: '0'
74
77
  requirements: []
75
78
  rubyforge_project:
76
- rubygems_version: 2.4.8
79
+ rubygems_version: 2.5.1
77
80
  signing_key:
78
81
  specification_version: 4
79
82
  summary: Store BLOBs in S3