mingle-storage 0.0.13 → 0.1.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
- SHA1:
3
- metadata.gz: d0f5c1a6490805c1d46aa244bea09839689e5b17
4
- data.tar.gz: ef239446fa00f2a0130667baba8e015d98c3bcd4
2
+ SHA256:
3
+ metadata.gz: 3657d919376dec9d78341d9dc72d91319c9c6b3880a79ddc2b09eb4c2d8c20fa
4
+ data.tar.gz: 5804abb38219d867467fdafe4c379b4a3639ea3ee1921193d3d902ce0a07099e
5
5
  SHA512:
6
- metadata.gz: be939eea8f100403f2fe3d287f620e37c33b598c62957e5341cd4c9011b95b79042aa1f451a53e7096f936d1c751343bf49202f929fbcc2bd9055d0ca615a2cb
7
- data.tar.gz: bfb1b834b17b24cf7872ced73149cb14c04e7c137ec455d6e8021f8778daa46f30dba466d8fc837c760b8b73ee55acc0680cfa2a7bac70e55958f10fb2babaa2
6
+ metadata.gz: 79eda50792dbcf9e70fe5a5c18079b09ad9b6394389df3b56e35667869e1debf56ee1b8d4bf665eacfa2799581bc1519c01677346ced7e8e4ce2e551950637e8
7
+ data.tar.gz: 5ec411b3f14451e04ed1b25aab3c507b17e3e415be6e6fc8b959388e928d3049bf3cae9acdd67ad1e12e4d6afd0ae8d1feb243830be669c6a0810ea2b805f47f
@@ -1,5 +1,5 @@
1
1
  require 'rubygems'
2
- require 'aws-sdk-v1'
2
+ require 'aws-sdk-s3'
3
3
  require 'storage/filesystem_store.rb'
4
4
  require 'storage/s3_store.rb'
5
5
 
@@ -125,52 +125,51 @@ module Storage
125
125
 
126
126
  def upload(path, local_file, options={})
127
127
  local_file_name = File.basename(local_file)
128
- bucket.objects.create(
129
- s3_path(path, local_file_name),
130
- Pathname.new(local_file),
131
- { :content_type => derive_content_type(local_file_name) }.merge(options)
132
- )
128
+ object = bucket.object(s3_path(path, local_file_name))
129
+ object.upload_file(Pathname.new(local_file), { :content_type => derive_content_type(local_file_name) }.merge(options))
133
130
  end
134
131
 
135
132
  def upload_dir(path, local_dir)
136
- bucket.objects.with_prefix(s3_path(path)).delete_all
133
+ bucket.objects(prefix: s3_path(path)).batch_delete!
137
134
  Dir[File.join(local_dir, "*")].each do |f|
138
135
  upload(path, f)
139
136
  end
140
137
  end
141
138
 
142
139
  def content_type(path)
143
- object(path).content_type
140
+ object(path).get.content_type
144
141
  end
145
142
 
146
143
  def copy(path, to_local_path)
147
- obj = object(path)
148
- raise "File(#{path}) does not exist in the bucket #{bucket.name}" unless obj.exists?
144
+ obj_content = read(path)
145
+ raise "File(#{path}) does not exist in the bucket #{bucket.name}" if obj_content.nil?
149
146
  File.open(to_local_path, 'w') do |f|
150
- obj.read do |c|
151
- f.write(c)
152
- end
147
+ f.write(obj_content)
153
148
  end
154
149
  end
155
150
 
156
151
  def write_to_file(path, content, options={})
157
- object(path).write(content, options)
152
+ object = bucket.object(s3_path(path))
153
+ object.put({body: content}.merge(options))
158
154
  end
159
155
 
160
156
  def read(path)
161
- object(path).read
157
+ object = object(path)
158
+ return object.get.body.read unless object.nil?
159
+ object
162
160
  end
163
161
 
164
162
  def exists?(path)
165
- object(path).exists?
163
+ !object(path).nil?
166
164
  end
167
165
 
168
- def url_for(path, opts={})
166
+ def url_for(path, opts = {})
169
167
  url_opts = {
170
- :expires => opts.delete(:expires_in) || @url_expires,
171
- :response_content_type => derive_content_type(path)
168
+ :expires_in => opts.delete(:expires_in) || @url_expires,
169
+ :response_content_type => derive_content_type(path)
172
170
  }.merge(opts)
173
- object(path).url_for(:read, url_opts).to_s
171
+ _object = object(path)
172
+ _object.nil? ? '' : _object.presigned_url(:get, url_opts)
174
173
  end
175
174
 
176
175
  def public_url(path, opts={})
@@ -183,19 +182,19 @@ module Storage
183
182
  end
184
183
 
185
184
  def delete(path)
186
- bucket.objects.with_prefix(s3_path(path)).delete_all
185
+ bucket.objects(prefix: s3_path(path)).batch_delete!
187
186
  end
188
187
 
189
188
  def clear
190
189
  if s3_path.nil? || s3_path.empty?
191
190
  bucket.clear
192
191
  else
193
- bucket.objects.with_prefix(s3_path).delete_all
192
+ bucket.objects(prefix: s3_path).batch_delete!
194
193
  end
195
194
  end
196
195
 
197
196
  def objects(path)
198
- bucket.objects.with_prefix(s3_path(path))
197
+ bucket.objects(prefix: s3_path(path))
199
198
  end
200
199
 
201
200
  private
@@ -205,11 +204,11 @@ module Storage
205
204
  end
206
205
 
207
206
  def s3
208
- AWS::S3.new
207
+ Aws::S3::Resource.new
209
208
  end
210
209
 
211
210
  def object(path)
212
- bucket.objects[s3_path(path)]
211
+ bucket.objects.find { |object| object.key == s3_path(path) }
213
212
  end
214
213
 
215
214
  def namespace
@@ -221,7 +220,7 @@ module Storage
221
220
  end
222
221
 
223
222
  def bucket
224
- @bucket ||= s3.buckets[bucket_name]
223
+ @bucket ||= s3.bucket(bucket_name)
225
224
  end
226
225
 
227
226
  def bucket_name
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mingle-storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ThoughtWorks Studios
@@ -13,15 +13,15 @@ dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - '>='
16
+ - - ">="
17
17
  - !ruby/object:Gem::Version
18
18
  version: '0'
19
- name: aws-sdk-v1
19
+ name: aws-sdk-s3
20
20
  prerelease: false
21
21
  type: :runtime
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  description: Mingle storage API to support filesystem and AWS S3 backed storage
@@ -43,17 +43,17 @@ require_paths:
43
43
  - lib
44
44
  required_ruby_version: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '>='
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - '>='
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  requirements: []
55
55
  rubyforge_project:
56
- rubygems_version: 2.4.8
56
+ rubygems_version: 2.6.13
57
57
  signing_key:
58
58
  specification_version: 4
59
59
  summary: Mingle storage API to support filesystem and AWS S3 backed storage