canistor 0.5.1 → 0.5.2
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 +4 -4
- data/lib/canistor/error_handler.rb +12 -0
- data/lib/canistor/handler.rb +6 -1
- data/lib/canistor/storage/object.rb +1 -1
- data/lib/canistor/version.rb +1 -1
- data/lib/canistor.rb +25 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7079760f9cc2acf2385c2073b80780bf1083d5972332774c35f4ea8ac0ff11e8
|
4
|
+
data.tar.gz: b7b31dcc1529d93ec687c82fa8f895edd62ed8be8854a0da985671a362690304
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/canistor/handler.rb
CHANGED
@@ -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.
|
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.
|
163
|
+
if bucket = Canistor.find_bucket(region, bucket_name)
|
164
164
|
if object = bucket.dig(key)
|
165
165
|
object
|
166
166
|
else
|
data/lib/canistor/version.rb
CHANGED
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.
|
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:
|
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
|
-
|
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.
|