swift-storage 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/swift_storage/account.rb +2 -4
- data/lib/swift_storage/container.rb +4 -12
- data/lib/swift_storage/container_collection.rb +1 -6
- data/lib/swift_storage/errors.rb +0 -2
- data/lib/swift_storage/headers.rb +0 -2
- data/lib/swift_storage/node.rb +3 -18
- data/lib/swift_storage/object.rb +15 -19
- data/lib/swift_storage/object_collection.rb +1 -6
- data/lib/swift_storage/service.rb +39 -50
- data/lib/swift_storage/version.rb +1 -1
- data/spec/swift/temp_url_spec.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77665fc3b1c075760f657ba0c9e192191c2d7f5c
|
4
|
+
data.tar.gz: 52089eaac7b7ca0f42b9c2bc1cdf0bd61e8daca6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 735a05bc0ca64009df31ec04dc41702d3b17eb030dfdbb8fd2d23824e9e93423c0f9e528252f39b251b246f0e959affc91411cdd548be820c0bc189b2cb600e2
|
7
|
+
data.tar.gz: a6076078bd7adbed2dbf0bb82fb32428ac356715241859c21b63bfcb64fd2a2422152c615046351729fb40b993ef1b414739b416a5c2634572f0e82789e6137c
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,12 @@
|
|
3
3
|
This file is written in reverse chronological order, newer releases will
|
4
4
|
appear at the top.
|
5
5
|
|
6
|
+
## 0.0.11
|
7
|
+
|
8
|
+
* Some refactoring
|
9
|
+
[#11](https://github.com/PredicSis/swift-ruby/pull/1)
|
10
|
+
@ArmandPredicSis
|
11
|
+
|
6
12
|
## 0.0.10
|
7
13
|
|
8
14
|
* Retry on connection error before giving up
|
@@ -1,7 +1,5 @@
|
|
1
1
|
class SwiftStorage::Account < SwiftStorage::Node
|
2
|
-
|
3
|
-
parent_node :service
|
4
|
-
|
2
|
+
parent_node :service
|
5
3
|
|
6
4
|
# Write account meta data
|
7
5
|
#
|
@@ -12,7 +10,7 @@ class SwiftStorage::Account < SwiftStorage::Node
|
|
12
10
|
#
|
13
11
|
def write(temp_url_key: nil)
|
14
12
|
h = {}
|
15
|
-
h[
|
13
|
+
h[ACCOUNT_TEMP_URL_KEY] = temp_url_key if temp_url_key
|
16
14
|
|
17
15
|
request(relative_path, :method => :post, :headers => h)
|
18
16
|
end
|
@@ -1,16 +1,11 @@
|
|
1
1
|
class SwiftStorage::Container < SwiftStorage::Node
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
parent_node :service
|
3
|
+
header_attributes :bytes_used, :object_count
|
5
4
|
|
6
5
|
def relative_path
|
7
6
|
name
|
8
7
|
end
|
9
8
|
|
10
|
-
header_attributes :bytes_used,
|
11
|
-
:object_count
|
12
|
-
|
13
|
-
|
14
9
|
# Returns the object collection for this container
|
15
10
|
#
|
16
11
|
# @return [SwiftStorage::ObjectCollection]
|
@@ -45,8 +40,8 @@ class SwiftStorage::Container < SwiftStorage::Node
|
|
45
40
|
read_acl = read_acl.join(',') if read_acl.respond_to?(:to_ary)
|
46
41
|
write_acl = write_acl.join(',') if write_acl.respond_to?(:to_ary)
|
47
42
|
|
48
|
-
h[
|
49
|
-
h[
|
43
|
+
h[CONTAINER_READ] = read_acl
|
44
|
+
h[CONTAINER_WRITE] = write_acl
|
50
45
|
|
51
46
|
request(relative_path, :method => :post, :headers => h)
|
52
47
|
end
|
@@ -61,7 +56,4 @@ class SwiftStorage::Container < SwiftStorage::Node
|
|
61
56
|
w = headers.write.split(',') rescue nil
|
62
57
|
struct(:read => r, :write => w)
|
63
58
|
end
|
64
|
-
|
65
|
-
|
66
59
|
end
|
67
|
-
|
@@ -1,7 +1,5 @@
|
|
1
1
|
class SwiftStorage::ContainerCollection < SwiftStorage::Node
|
2
|
-
|
3
|
-
parent_node :service
|
4
|
-
|
2
|
+
parent_node :service
|
5
3
|
|
6
4
|
# Return all containers
|
7
5
|
#
|
@@ -28,7 +26,4 @@ class SwiftStorage::ContainerCollection < SwiftStorage::Node
|
|
28
26
|
def [](name)
|
29
27
|
SwiftStorage::Container.new(service, name) if name
|
30
28
|
end
|
31
|
-
|
32
29
|
end
|
33
|
-
|
34
|
-
|
data/lib/swift_storage/errors.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
module SwiftStorage
|
2
|
-
|
3
2
|
module Headers
|
4
3
|
STORAGE_URL = 'X-Storage-Url'.freeze
|
5
4
|
AUTH_TOKEN = 'X-Auth-Token'.freeze
|
@@ -20,5 +19,4 @@ module SwiftStorage
|
|
20
19
|
ACCOUNT_TEMP_URL_KEY = 'X-Account-Meta-Temp-URL-Key'.freeze
|
21
20
|
DESTINATION = 'Destination'.freeze
|
22
21
|
end
|
23
|
-
|
24
22
|
end
|
data/lib/swift_storage/node.rb
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
class SwiftStorage::Node
|
2
|
-
|
3
2
|
include SwiftStorage::Utils
|
3
|
+
include SwiftStorage::Headers
|
4
4
|
|
5
|
-
attr_accessor
|
6
|
-
:name
|
5
|
+
attr_accessor :parent, :name
|
7
6
|
|
8
7
|
def initialize(parent, name=nil)
|
9
8
|
@parent = parent
|
@@ -90,14 +89,7 @@ class SwiftStorage::Node
|
|
90
89
|
end
|
91
90
|
|
92
91
|
def delete
|
93
|
-
|
94
|
-
3.times do |i|
|
95
|
-
begin
|
96
|
-
return request(relative_path, :method => :delete)
|
97
|
-
rescue SwiftStorage::Errors::ServerError
|
98
|
-
sleep(i**2)
|
99
|
-
end
|
100
|
-
end
|
92
|
+
request(relative_path, :method => :delete)
|
101
93
|
end
|
102
94
|
|
103
95
|
def delete_if_exists
|
@@ -106,7 +98,6 @@ class SwiftStorage::Node
|
|
106
98
|
false
|
107
99
|
end
|
108
100
|
|
109
|
-
|
110
101
|
private
|
111
102
|
|
112
103
|
def self.header_name
|
@@ -138,10 +129,4 @@ class SwiftStorage::Node
|
|
138
129
|
headers[full_key] = v.to_s
|
139
130
|
end
|
140
131
|
end
|
141
|
-
|
142
|
-
private
|
143
|
-
H = SwiftStorage::Headers
|
144
|
-
|
145
132
|
end
|
146
|
-
|
147
|
-
|
data/lib/swift_storage/object.rb
CHANGED
@@ -13,15 +13,11 @@ require "time"
|
|
13
13
|
# Object cache control header.
|
14
14
|
#
|
15
15
|
class SwiftStorage::Object < SwiftStorage::Node
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
header_attributes :content_length,
|
22
|
-
:content_type,
|
23
|
-
:expires,
|
24
|
-
:cache_control
|
16
|
+
parent_node :container
|
17
|
+
header_attributes :content_length,
|
18
|
+
:content_type,
|
19
|
+
:expires,
|
20
|
+
:cache_control
|
25
21
|
|
26
22
|
# Read the object data
|
27
23
|
#
|
@@ -130,16 +126,16 @@ class SwiftStorage::Object < SwiftStorage::Node
|
|
130
126
|
cache_control = "public, max_age=4000000000"
|
131
127
|
end
|
132
128
|
|
133
|
-
h[
|
134
|
-
h[
|
135
|
-
h[
|
136
|
-
h[
|
137
|
-
h[
|
129
|
+
h[CONTENT_DISPOSITION] = attachment ? 'attachment' : 'inline'
|
130
|
+
h[OBJECT_MANIFEST] = object_manifest if object_manifest
|
131
|
+
h[CONTENT_TYPE] = content_type if content_type
|
132
|
+
h[EXPIRES] = expires.httpdate if expires
|
133
|
+
h[CACHE_CONTROL] = cache_control if cache_control
|
138
134
|
|
139
135
|
if delete_at
|
140
|
-
h[
|
136
|
+
h[DELETE_AT] = delete_at.to_i.to_s
|
141
137
|
elsif delete_after
|
142
|
-
h[
|
138
|
+
h[DELETE_AFTER] = delete_after.to_i.to_s
|
143
139
|
end
|
144
140
|
|
145
141
|
merge_metadata(h, metadata)
|
@@ -175,7 +171,7 @@ class SwiftStorage::Object < SwiftStorage::Node
|
|
175
171
|
raise ArgumentError.new('Invalid source type')
|
176
172
|
end
|
177
173
|
|
178
|
-
request(path + '?multipart-manifest=get', method: :copy, headers: optional_headers.merge(
|
174
|
+
request(path + '?multipart-manifest=get', method: :copy, headers: optional_headers.merge(DESTINATION => relative_path))
|
179
175
|
self
|
180
176
|
end
|
181
177
|
|
@@ -191,9 +187,9 @@ class SwiftStorage::Object < SwiftStorage::Node
|
|
191
187
|
# A temporary URL to the object.
|
192
188
|
#
|
193
189
|
# @!parse def temp_url(expires=Time.now + 3600, method: :get);end
|
194
|
-
def temp_url(expires=nil, method: :get)
|
190
|
+
def temp_url(expires = nil, ssl: true, method: :get, params: {})
|
195
191
|
expires ||= Time.now + 3600
|
196
|
-
service.create_temp_url(container.name, name, expires, method)
|
192
|
+
service.create_temp_url(container.name, name, expires, method, ssl, params)
|
197
193
|
end
|
198
194
|
|
199
195
|
# Returns the object's URL
|
@@ -1,7 +1,5 @@
|
|
1
1
|
class SwiftStorage::ObjectCollection < SwiftStorage::Node
|
2
|
-
|
3
|
-
parent_node :container
|
4
|
-
|
2
|
+
parent_node :container
|
5
3
|
|
6
4
|
# Return all objects
|
7
5
|
#
|
@@ -37,7 +35,4 @@ class SwiftStorage::ObjectCollection < SwiftStorage::Node
|
|
37
35
|
def get_objects(prefix=nil)
|
38
36
|
get_lines(container.name, :prefix => prefix).map { |name| SwiftStorage::Object.new(container, name)}
|
39
37
|
end
|
40
|
-
|
41
38
|
end
|
42
|
-
|
43
|
-
|
@@ -9,19 +9,19 @@ class SwiftStorage::Service
|
|
9
9
|
extend Forwardable
|
10
10
|
def_delegators SwiftStorage, :configuration
|
11
11
|
|
12
|
-
attr_reader
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
12
|
+
attr_reader :tenant,
|
13
|
+
:endpoint,
|
14
|
+
:storage_url,
|
15
|
+
:auth_token,
|
16
|
+
:auth_at,
|
17
|
+
:expires,
|
18
|
+
:storage_token,
|
19
|
+
:storage_scheme,
|
20
|
+
:storage_host,
|
21
|
+
:storage_port,
|
22
|
+
:storage_path,
|
23
|
+
:temp_url_key,
|
24
|
+
:retries
|
25
25
|
|
26
26
|
def initialize(tenant: configuration.tenant,
|
27
27
|
username: configuration.username,
|
@@ -69,13 +69,12 @@ class SwiftStorage::Service
|
|
69
69
|
@storage_path = uri.path
|
70
70
|
end
|
71
71
|
|
72
|
-
def create_temp_url(container, object, expires, method,
|
73
|
-
|
74
|
-
scheme = options[:scheme] || storage_scheme
|
72
|
+
def create_temp_url(container, object, expires, method, ssl = true, params = {})
|
73
|
+
scheme = ssl ? 'https' : 'http'
|
75
74
|
|
76
75
|
method = method.to_s.upcase
|
77
76
|
# Limit methods
|
78
|
-
%w{GET PUT HEAD}.include?(method) or raise ArgumentError, 'Only GET, PUT, HEAD supported'
|
77
|
+
%w{GET POST PUT HEAD}.include?(method) or raise ArgumentError, 'Only GET, POST, PUT, HEAD supported'
|
79
78
|
|
80
79
|
expires = expires.to_i
|
81
80
|
object_path_escaped = File.join(storage_path, escape(container), escape(object, '/'))
|
@@ -85,7 +84,7 @@ class SwiftStorage::Service
|
|
85
84
|
|
86
85
|
sig = sig_to_hex(hmac('sha1', temp_url_key, string_to_sign))
|
87
86
|
|
88
|
-
klass = scheme == 'http' ? URI::HTTP : URI::HTTPS
|
87
|
+
klass = (scheme == 'http') ? URI::HTTP : URI::HTTPS
|
89
88
|
|
90
89
|
temp_url_options = {
|
91
90
|
scheme: scheme,
|
@@ -93,8 +92,9 @@ class SwiftStorage::Service
|
|
93
92
|
port: storage_port,
|
94
93
|
path: object_path_escaped,
|
95
94
|
query: URI.encode_www_form(
|
96
|
-
|
97
|
-
|
95
|
+
params.merge(
|
96
|
+
temp_url_sig: sig,
|
97
|
+
temp_url_expires: expires)
|
98
98
|
)
|
99
99
|
}
|
100
100
|
klass.build(temp_url_options).to_s
|
@@ -113,12 +113,12 @@ class SwiftStorage::Service
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def request(path_or_url,
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
116
|
+
method: :get,
|
117
|
+
headers: nil,
|
118
|
+
params: nil,
|
119
|
+
json_data: nil,
|
120
|
+
input_stream: nil,
|
121
|
+
output_stream: nil)
|
122
122
|
|
123
123
|
tries = retries
|
124
124
|
|
@@ -189,34 +189,24 @@ class SwiftStorage::Service
|
|
189
189
|
end
|
190
190
|
end
|
191
191
|
|
192
|
-
|
193
|
-
|
194
|
-
rescue Errno::EPIPE, Errno::EAGAIN, Errno::EWOULDBLOCK, Timeout::Error, Errno::EINVAL, EOFError
|
195
|
-
# Server closed the connection, retry
|
196
|
-
sleep 5
|
197
|
-
retry unless (tries -= 1) <= 0
|
198
|
-
raise OpenStack::Exception::Connection, "Unable to connect to OpenStack::Swift after #{retries} retries"
|
199
|
-
end
|
200
|
-
|
201
|
-
begin
|
202
|
-
check_response!(response)
|
203
|
-
rescue AuthError
|
204
|
-
# If token is at least 60 second old, we try to get a new one
|
205
|
-
if @auth_at && (Time.now - @auth_at).to_i > 60
|
206
|
-
authenticate!
|
207
|
-
response = s.request(req, &output_proc)
|
208
|
-
else
|
209
|
-
raise
|
210
|
-
end
|
211
|
-
end
|
192
|
+
response = s.request(req, &output_proc)
|
193
|
+
check_response!(response)
|
212
194
|
response
|
195
|
+
rescue AuthError => e
|
196
|
+
# If token is at least 60 second old, we try to get a new one
|
197
|
+
raise e unless @auth_at && (Time.now - @auth_at).to_i > 60
|
198
|
+
authenticate!
|
199
|
+
retry
|
200
|
+
rescue ServerError, Errno::EPIPE, Timeout::Error, Errno::EINVAL, EOFError
|
201
|
+
# Server closed the connection, retry
|
202
|
+
sleep 5
|
203
|
+
retry unless (tries -= 1) <= 0
|
204
|
+
raise SwiftStorage::Errors::ServerError, "Unable to connect to OpenStack::Swift after #{retries} retries"
|
213
205
|
end
|
214
206
|
|
215
207
|
private
|
216
208
|
|
217
|
-
attr_reader
|
218
|
-
:username,
|
219
|
-
:password
|
209
|
+
attr_reader :sessions, :username, :password
|
220
210
|
|
221
211
|
def check_response!(response)
|
222
212
|
case response.code
|
@@ -232,5 +222,4 @@ class SwiftStorage::Service
|
|
232
222
|
raise ServerError, response.body
|
233
223
|
end
|
234
224
|
end
|
235
|
-
|
236
225
|
end
|
data/spec/swift/temp_url_spec.rb
CHANGED
@@ -12,7 +12,7 @@ RSpec.describe 'Temporary URL' do
|
|
12
12
|
|
13
13
|
# This has been computed manually and checked with openstack
|
14
14
|
# Only server port vary, not actual host
|
15
|
-
url = "
|
15
|
+
url = "https://127.0.0.1:#{server.port}/v1/AUTH_test/testbucket/test.html?temp_url_sig=4db4c16c859fdddca2e629a0a1e6b81c15a42cbd&temp_url_expires=50000"
|
16
16
|
expect(subject.create_temp_url('testbucket', 'test.html', 50000, 'GET')).to eq(url)
|
17
17
|
end
|
18
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swift-storage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolas Goy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
180
|
version: '0'
|
181
181
|
requirements: []
|
182
182
|
rubyforge_project:
|
183
|
-
rubygems_version: 2.4.
|
183
|
+
rubygems_version: 2.4.7
|
184
184
|
signing_key:
|
185
185
|
specification_version: 4
|
186
186
|
summary: Swift storage client.
|