canistor 0.2.3 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb028e5a37a0a861d629b957b7d180452aa6fc2561e948119a7350c28c7a2b47
4
- data.tar.gz: e009688e7c20b73064530ff3ce011b1013b466f15b6aecaf03b94576b50f3d13
3
+ metadata.gz: 1a72057225c71056a2dc5988c98c289bd510f8d3e4aa349122b0320b82ad37a8
4
+ data.tar.gz: b5955919a7e72c44068e83e4cb24ac531f2a35e32882008782ae4cf11e225f96
5
5
  SHA512:
6
- metadata.gz: 914228524001aefdf327d627798164241a666ba2a63dc280e1ab8414e48791c5584bb4347df8d2986a3bdf89320d1ff79fbab19601fd249ba0157b5ce07dbd02
7
- data.tar.gz: b625e9cfe54e19a73bfa36db8717885e484ad6fec637017055665ada06fccba83dba6c8bc4b0500df960a65f07041d0cddb5334cc56d04f07989460d96e0b259
6
+ metadata.gz: 92d2ca4e756258bd8074343c113636758ac2e7a8816d9301aa00a93f31cfaafbbf45dc6f029d2eb165fa6e5494d35bfacecd2a82444352dc1564f4ad819d299b
7
+ data.tar.gz: 1eea263424389acb1d6350be042feeb9419c1b7a229f50b9d7aa093832765b8e601ec7a9649e0360b3c33a68ea045e2f6337970a3c0dccd4f19f7a3e2360ffe7
@@ -105,7 +105,7 @@ module Canistor
105
105
  def serve_error(status_code, body)
106
106
  response.signal_headers(
107
107
  status_code,
108
- 'data' => Time.now.httpdate,
108
+ 'date' => Time.now.httpdate,
109
109
  'x-amz-request-id' => request_id
110
110
  )
111
111
  unless request.http_method == 'HEAD'
@@ -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 object = objects[subject.key]
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Canistor
4
- VERSION = '0.2.3'
4
+ VERSION = '0.3.0'
5
5
  end
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.2.3
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-04-09 00:00:00.000000000 Z
11
+ date: 2018-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler