bfs-s3 0.3.7 → 0.4.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
  SHA256:
3
- metadata.gz: 1278091b90948c44f8af9063da019a7995b614a2ab4b773404b8dce4cbfbf830
4
- data.tar.gz: 7da078d9683005df07103b486da20490cd4a3198cc13b7d3db16547a098378b8
3
+ metadata.gz: 4c616f522880311f4ca6a584e333c1f7980cd2ea28d49edcf43ae5f13543bb43
4
+ data.tar.gz: '067807a2b22a0777b177cc570a5f6919230c749d79f0ce569b021c5c802b715a'
5
5
  SHA512:
6
- metadata.gz: de52d76401dc6a99665713efc288cabc82a3d3c6ea89e3b4532779f164c96140e85de16edf96a13a2bf4f932cd9a8e807e77a1d3d562779f028d141a5818f7d1
7
- data.tar.gz: 1f253f6f75a5f011281cc6fc35347185d4a838a958ab7a80b812f88fde714bb24e035ccbe919588458b24d5622df16c6a74cf11ffb18a6accf6788df0bdfcb4d
6
+ metadata.gz: 58f0f83dbb3774297246e8a32e047bb1490d16ddca825565a704cf9f68815f397cf7cf56acd9b61784e3b30bb19b2806724ecc657e6d645044978c1450b2bf62
7
+ data.tar.gz: 97e5fa58ae4774a0703f143d41240df804858de8061b70eedfd0da36fc474d3e186e97d0a2ec0bd32d16f083ee6f543301a79e9eea55b6290c1d4f4799d6a157
data/bfs-s3.gemspec CHANGED
@@ -15,8 +15,8 @@ Gem::Specification.new do |s|
15
15
  s.files = `git ls-files`.split("\n")
16
16
  s.test_files = `git ls-files -- spec/*`.split("\n")
17
17
  s.require_paths = ['lib']
18
- s.required_ruby_version = '>= 2.2.0'
18
+ s.required_ruby_version = '>= 2.4.0'
19
19
 
20
- s.add_dependency 'aws-sdk-s3'
20
+ s.add_dependency 'aws-sdk-s3', '~> 1.38'
21
21
  s.add_dependency 'bfs', s.version
22
22
  end
data/lib/bfs/bucket/s3.rb CHANGED
@@ -6,8 +6,6 @@ module BFS
6
6
  module Bucket
7
7
  # S3 buckets are operating on s3
8
8
  class S3 < Abstract
9
- NF_ERRORS = [Aws::S3::Errors::NoSuchKey, Aws::S3::Errors::NoSuchBucket, Aws::S3::Errors::NotFound].freeze
10
-
11
9
  attr_reader :name, :sse, :acl, :storage_class
12
10
 
13
11
  # Initializes a new S3 bucket
@@ -23,12 +21,14 @@ module BFS
23
21
  # @option opts [Symbol] :acl canned ACL
24
22
  # @option opts [String] :storage_class storage class
25
23
  # @option opts [Aws::S3::Client] :client custom client, uses default_client by default
24
+ # @option opts [String] :encoding default encoding to use, default: 'binary'
26
25
  def initialize(name, opts={})
27
26
  opts = opts.dup
28
27
  opts.keys.each do |key|
29
28
  val = opts.delete(key)
30
29
  opts[key.to_sym] = val unless val.nil?
31
30
  end
31
+ super(opts)
32
32
 
33
33
  @name = name
34
34
  @sse = opts[:sse] || opts[:server_side_encryption]
@@ -68,13 +68,20 @@ module BFS
68
68
  raise BFS::FileNotFound, path unless info
69
69
 
70
70
  BFS::FileInfo.new(path, info.content_length, info.last_modified, info.content_type, info.metadata)
71
- rescue *NF_ERRORS
71
+ rescue Aws::S3::Errors::NoSuchKey, Aws::S3::Errors::NoSuchBucket, Aws::S3::Errors::NotFound
72
72
  raise BFS::FileNotFound, path
73
73
  end
74
74
 
75
75
  # Creates a new file and opens it for writing
76
+ # @param [String] path
77
+ # @param [Hash] opts options
78
+ # @option opts [String] :encoding file encoding to use, default: 'binary'
79
+ # @option opts [String] :acl custom ACL override
80
+ # @option opts [String] :server_side_encryption SSE override
81
+ # @option opts [String] :storage_class storage class override
76
82
  def create(path, opts={}, &block)
77
83
  path = full_path(path)
84
+ enc = opts.delete(:encoding) || @encoding
78
85
  opts = opts.merge(
79
86
  bucket: name,
80
87
  key: path,
@@ -83,8 +90,8 @@ module BFS
83
90
  opts[:server_side_encryption] ||= @sse if @sse
84
91
  opts[:storage_class] ||= @storage_class if @storage_class
85
92
 
86
- temp = BFS::TempWriter.new(path, opts) do |t|
87
- File.open(t, binmode: true) do |file|
93
+ temp = BFS::TempWriter.new(path, encoding: enc) do |t|
94
+ File.open(t, encoding: enc) do |file|
88
95
  @client.put_object(opts.merge(body: file))
89
96
  end
90
97
  end
@@ -98,9 +105,13 @@ module BFS
98
105
  end
99
106
 
100
107
  # Opens an existing file for reading
108
+ # @param [String] path
109
+ # @param [Hash] opts options
110
+ # @option opts [String] :encoding file encoding to use, default: 'binary'
101
111
  def open(path, opts={}, &block)
102
112
  path = full_path(path)
103
- temp = Tempfile.new(File.basename(path), binmode: true)
113
+ enc = opts.delete(:encoding) || @encoding
114
+ temp = Tempfile.new(File.basename(path), encoding: enc)
104
115
  temp.close
105
116
 
106
117
  opts = opts.merge(
@@ -110,8 +121,8 @@ module BFS
110
121
  )
111
122
  @client.get_object(opts)
112
123
 
113
- File.open(temp.path, binmode: true, &block)
114
- rescue *NF_ERRORS
124
+ File.open(temp.path, encoding: enc, &block)
125
+ rescue Aws::S3::Errors::NoSuchKey, Aws::S3::Errors::NoSuchBucket, Aws::S3::Errors::NotFound
115
126
  raise BFS::FileNotFound, trim_prefix(path)
116
127
  end
117
128
 
@@ -123,7 +134,7 @@ module BFS
123
134
  key: path,
124
135
  )
125
136
  @client.delete_object(opts)
126
- rescue *NF_ERRORS # rubocop:disable Lint/HandleExceptions
137
+ rescue Aws::S3::Errors::NoSuchKey, Aws::S3::Errors::NoSuchBucket, Aws::S3::Errors::NotFound # rubocop:disable Lint/HandleExceptions
127
138
  end
128
139
 
129
140
  # Copies a file.
@@ -136,7 +147,7 @@ module BFS
136
147
  key: dst,
137
148
  )
138
149
  @client.copy_object(opts)
139
- rescue *NF_ERRORS
150
+ rescue Aws::S3::Errors::NoSuchKey, Aws::S3::Errors::NoSuchBucket, Aws::S3::Errors::NotFound
140
151
  raise BFS::FileNotFound, trim_prefix(src)
141
152
  end
142
153
 
@@ -157,8 +168,11 @@ end
157
168
 
158
169
  BFS.register('s3') do |url|
159
170
  params = CGI.parse(url.query.to_s)
171
+ prefix = BFS.norm_path(params.key?('prefix') ? params['prefix'].first : url.path)
172
+ prefix = nil if prefix.empty?
160
173
 
161
174
  BFS::Bucket::S3.new url.host,
175
+ prefix: prefix,
162
176
  region: params.key?('region') ? params['region'].first : nil,
163
177
  sse: params.key?('sse') ? params['sse'].first : nil,
164
178
  access_key_id: params.key?('access_key_id') ? params['access_key_id'].first : nil,
@@ -24,10 +24,16 @@ RSpec.describe BFS::Bucket::S3, if: run_spec do
24
24
  it_behaves_like 'a bucket'
25
25
 
26
26
  it 'should resolve from URL' do
27
- bucket = BFS.resolve("s3://#{sandbox[:bucket]}?acl=private")
27
+ bucket = BFS.resolve("s3://#{sandbox[:bucket]}/?acl=private")
28
28
  expect(bucket).to be_instance_of(described_class)
29
29
  expect(bucket.name).to eq(sandbox[:bucket])
30
30
  expect(bucket.acl).to eq(:private)
31
+ expect(bucket.instance_variable_get(:@prefix)).to be_nil
32
+
33
+ bucket = BFS.resolve("s3://#{sandbox[:bucket]}/a/b/")
34
+ expect(bucket).to be_instance_of(described_class)
35
+ expect(bucket.name).to eq(sandbox[:bucket])
36
+ expect(bucket.instance_variable_get(:@prefix)).to eq('a/b')
31
37
  end
32
38
 
33
39
  it 'should enumerate over a large number of files' do
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bfs-s3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitrij Denissenko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-02 00:00:00.000000000 Z
11
+ date: 2019-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-s3
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '1.38'
20
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: '1.38'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bfs
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.3.7
33
+ version: 0.4.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.3.7
40
+ version: 0.4.0
41
41
  description: https://github.com/bsm/bfs.rb
42
42
  email: dimitrij@blacksquaremedia.com
43
43
  executables: []
@@ -60,14 +60,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- version: 2.2.0
63
+ version: 2.4.0
64
64
  required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  requirements: []
70
- rubygems_version: 3.0.2
70
+ rubygems_version: 3.0.3
71
71
  signing_key:
72
72
  specification_version: 4
73
73
  summary: S3 bucket adapter for bfs