canistor 0.5.1 → 0.5.2

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: 2edb558a153237b48ed0e9438b9e77d6f9d1f8e8c6435b56e51fb79c4fd32fc8
4
- data.tar.gz: 8993f393d9e18e7fd2f95873babdbf261e3fc27d4e736c7b8993d42baa797c12
3
+ metadata.gz: 7079760f9cc2acf2385c2073b80780bf1083d5972332774c35f4ea8ac0ff11e8
4
+ data.tar.gz: b7b31dcc1529d93ec687c82fa8f895edd62ed8be8854a0da985671a362690304
5
5
  SHA512:
6
- metadata.gz: 9cfd41769d311b131c28fd1515e3bfdec9fc1ca3912eb37ade3e00fe0796423adad0b9c7a7b4952d84a13b4fff0d163046ca4b8e1dad181f6879fb58e97c16fb
7
- data.tar.gz: 8c2ee77d44457b16fe37dffc1e85cb3e381a873a28f1d3c8112f2a5acfc3d69b7332e0031f00d9b7c591dc1f528312cd22c8d447159917585f781b2fa96198ac
6
+ metadata.gz: '086f2b966946f3bed4f5e56921be6db7015dcdf6bc56190be19f97cb38f28740b8616686e32d8be8ed1887da7dc7b43a75c725827660b7de666e3b899e8b0eb1'
7
+ data.tar.gz: 4baf02fa55c428023332a04c7b9404499404f652cc8a902bcf1b94ba5b8e685f014fb690dd5071fe08177c9e7b707c7163aaf8dd17d6bd849cf7fc9ac314f6ca
@@ -20,6 +20,14 @@ module Canistor
20
20
  context.http_response
21
21
  end
22
22
 
23
+ def serve_continue
24
+ response.signal_headers(
25
+ 100,
26
+ 'date' => Time.now.httpdate,
27
+ 'x-amz-request-id' => request_id
28
+ )
29
+ end
30
+
23
31
  def serve_bad_request
24
32
  serve_error(400, Nokogiri::XML::Builder.new do |xml|
25
33
  xml.Error do
@@ -166,6 +174,10 @@ module Canistor
166
174
  response.signal_error(RuntimeError.new("Fatal error."))
167
175
  end
168
176
 
177
+ def self.serve_continue(context)
178
+ new(context).serve_continue
179
+ end
180
+
169
181
  def self.serve_bad_request(context)
170
182
  new(context).serve_bad_request
171
183
  end
@@ -49,7 +49,12 @@ module Canistor
49
49
  end
50
50
  if credentials = Canistor.find_credentials(authorization)
51
51
  if authorization.valid_signature?(context.http_request, credentials)
52
- if bucket = Canistor.store.dig(subject.region, subject.bucket)
52
+ if bucket = Canistor.find_bucket(subject.region, subject.bucket)
53
+ # The AWS client has an optimization where it waits for a 100
54
+ # Continue status code before sending the request body.
55
+ if context.http_request.headers['expect'] == '100-continue'
56
+ Canistor::ErrorHandler.serve_continue(context)
57
+ end
53
58
  method = context.http_request.http_method.to_s.downcase
54
59
  bucket.send(
55
60
  method,
@@ -160,7 +160,7 @@ module Canistor
160
160
  def find_source(context, subject)
161
161
  if source = context.http_request.headers['x-amz-copy-source']
162
162
  bucket_name, key = source.split('/', 2)
163
- if bucket = Canistor.store.dig(region, bucket_name)
163
+ if bucket = Canistor.find_bucket(region, bucket_name)
164
164
  if object = bucket.dig(key)
165
165
  object
166
166
  else
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Canistor
4
- VERSION = '0.5.1'
4
+ VERSION = '0.5.2'
5
5
  end
data/lib/canistor.rb CHANGED
@@ -108,6 +108,31 @@ module Canistor
108
108
  nil
109
109
  end
110
110
 
111
+ def self.find_bucket(region, bucket)
112
+ store.dig(region, bucket) || find_bucket_by_name_and_warn(region, bucket)
113
+ end
114
+
115
+ def self.find_bucket_by_name_and_warn(region, bucket)
116
+ found = find_bucket_by_name(bucket)
117
+ return if found.nil?
118
+
119
+ logger.info(
120
+ "S3 client configured for \"#{region}\" but the bucket \"#{bucket}\" " \
121
+ "is in \"#{found.region}\"; Please configure the proper region to " \
122
+ "avoid multiple unnecessary redirects and signing attempts"
123
+ ) if logger
124
+ found
125
+ end
126
+
127
+ def self.find_bucket_by_name(bucket)
128
+ store.each do |_, buckets|
129
+ if bucket = buckets[bucket]
130
+ return bucket
131
+ end
132
+ end
133
+ nil
134
+ end
135
+
111
136
  def self.credentials=(accounts)
112
137
  accounts.each do |attributes|
113
138
  unless attributes.keys.map(&:to_s) == %w(access_key_id secret_access_key)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: canistor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manfred Stienstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-01 00:00:00.000000000 Z
11
+ date: 2019-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -125,8 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []
128
- rubyforge_project:
129
- rubygems_version: 2.7.6
128
+ rubygems_version: 3.0.1
130
129
  signing_key:
131
130
  specification_version: 4
132
131
  summary: Canistor is mock for Aws::S3 defined by the AWS SDK gem.