canistor 0.2.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/canistor/error_handler.rb +1 -1
- data/lib/canistor/storage/bucket.rb +55 -1
- data/lib/canistor/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a72057225c71056a2dc5988c98c289bd510f8d3e4aa349122b0320b82ad37a8
|
4
|
+
data.tar.gz: b5955919a7e72c44068e83e4cb24ac531f2a35e32882008782ae4cf11e225f96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92d2ca4e756258bd8074343c113636758ac2e7a8816d9301aa00a93f31cfaafbbf45dc6f029d2eb165fa6e5494d35bfacecd2a82444352dc1564f4ad819d299b
|
7
|
+
data.tar.gz: 1eea263424389acb1d6350be042feeb9419c1b7a229f50b9d7aa093832765b8e601ec7a9649e0360b3c33a68ea045e2f6337970a3c0dccd4f19f7a3e2360ffe7
|
@@ -48,7 +48,9 @@ module Canistor
|
|
48
48
|
def get(context, access_key_id, subject)
|
49
49
|
if !access_keys.include?(access_key_id)
|
50
50
|
Canistor::ErrorHandler.serve_access_denied(context, subject)
|
51
|
-
elsif
|
51
|
+
elsif subject.key.nil? || subject.key == ''
|
52
|
+
list_bucket(context)
|
53
|
+
elsif object = objects[subject.key]
|
52
54
|
object.get(context, subject)
|
53
55
|
else
|
54
56
|
Canistor::ErrorHandler.serve_no_such_key(context, subject)
|
@@ -104,6 +106,58 @@ module Canistor
|
|
104
106
|
key: subject.key
|
105
107
|
)
|
106
108
|
end
|
109
|
+
|
110
|
+
# Iterate over all objects in the bucket using the filter and pagination
|
111
|
+
# options which exist in S3.
|
112
|
+
def each(prefix:, marker:, max_keys:, &block)
|
113
|
+
passed_marker = marker.nil? ? false : true
|
114
|
+
has_prefix = (prefix.to_s.strip == '') ? false : true
|
115
|
+
objects.each do |path, object|
|
116
|
+
if !passed_marker && (!has_prefix || object.key.start_with?(prefix))
|
117
|
+
yield object
|
118
|
+
max_keys -= 1 unless max_keys.nil?
|
119
|
+
end
|
120
|
+
break if max_keys && max_keys < 1
|
121
|
+
passed_marker = true if (!passed_marker && object.key == marker)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
def list_bucket(context)
|
126
|
+
context.http_response.signal_headers(
|
127
|
+
200,
|
128
|
+
'date' => Time.now.httpdate,
|
129
|
+
'x-amz-request-id' => SecureRandom.hex(8).upcase
|
130
|
+
)
|
131
|
+
unless context.http_request.http_method == 'HEAD'
|
132
|
+
context.http_response.signal_data(to_xml(context))
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def to_xml(context)
|
137
|
+
# Only returns objects with keys that start with the prefix.
|
138
|
+
prefix = context.params[:prefix]
|
139
|
+
# Return objects until we find a key that matches the marker. Can
|
140
|
+
# be used to group objects.
|
141
|
+
marker = context.params[:marker]
|
142
|
+
# Stop after returning a number of objects.
|
143
|
+
max_keys = context.params[:max_keys]
|
144
|
+
max_keys = max_keys ? max_keys.to_i : nil
|
145
|
+
Nokogiri::XML::Builder.new do |xml|
|
146
|
+
xml.ListBucketResult(xmlns: 'http://s3.amazonaws.com/doc/2006-03-01/') do
|
147
|
+
xml.Name name
|
148
|
+
xml.Prefix
|
149
|
+
xml.Marker
|
150
|
+
xml.MaxKeys max_keys
|
151
|
+
each(prefix: prefix, marker: marker, max_keys: max_keys) do |object|
|
152
|
+
xml.Contents do
|
153
|
+
xml.Key object.key
|
154
|
+
xml.Size object.size
|
155
|
+
xml.StorageClass 'STANDARD'
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end.to_xml
|
160
|
+
end
|
107
161
|
end
|
108
162
|
end
|
109
163
|
end
|
data/lib/canistor/version.rb
CHANGED
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.
|
4
|
+
version: 0.3.0
|
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
|
+
date: 2018-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|