swift_client 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +25 -23
- data/lib/swift_client.rb +8 -1
- data/lib/swift_client/version.rb +1 -1
- data/test/swift_client_test.rb +15 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 49eedca7f2dcfc8e50c6d43042dd3783d756e310ceb57a3a186437f4069dab1f
|
4
|
+
data.tar.gz: 11e6e5fa5e5526aa27534f83fe775d223a3af101aa9a25df1101513e6f388faa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc9489387e34d0f90f0e3af89dd52fe542b2af932bca75cf4144216f881d390e7856287d78c261860396c5df3fdad32d9f076a48b259a1d0c2f1e18e612093ed
|
7
|
+
data.tar.gz: 5385bdf725dd8979ae20d2b4a0018a62099c5991b60b5101b1e86d693779c426491f997268379630a80f9447adec03f72168e23ff782e1c7299fd315b5b2d9d9
|
data/README.md
CHANGED
@@ -101,7 +101,8 @@ swift_client = SwiftClient.new(
|
|
101
101
|
:auth_url => "https://auth.example.com/v3",
|
102
102
|
:storage_url => "https://storage.example.com/v1/AUTH_account",
|
103
103
|
:user_id => "user id",
|
104
|
-
:password => "password"
|
104
|
+
:password => "password",
|
105
|
+
:interface => "internal"
|
105
106
|
)
|
106
107
|
|
107
108
|
# OR
|
@@ -126,28 +127,29 @@ access the response body and JSON response. Checkout the
|
|
126
127
|
|
127
128
|
SwiftClient offers the following requests:
|
128
129
|
|
129
|
-
* head_account(options = {})
|
130
|
-
* post_account(headers = {}, options = {})
|
131
|
-
* head_containers(options = {})
|
132
|
-
* get_containers(query = {}, options = {})
|
133
|
-
* paginate_containers(query = {}, options = {})
|
134
|
-
* get_container(container_name, query = {}, options = {})
|
135
|
-
* paginate_container(container_name, query = {}, options = {})
|
136
|
-
* head_container(container_name, options = {})
|
137
|
-
* put_container(container_name, headers = {}, options = {})
|
138
|
-
* post_container(container_name, headers = {}, options = {})
|
139
|
-
* delete_container(container_name, options = {})
|
140
|
-
* put_object(object_name, data_or_io, container_name, headers = {}, options = {})
|
141
|
-
* post_object(object_name, container_name, headers = {}, options = {})
|
142
|
-
* get_object(object_name, container_name, options = {}) -> HTTParty::Response
|
143
|
-
* get_object(object_name, container_name, options = {}) { |chunk| save chunk }
|
144
|
-
* head_object(object_name, container_name, options = {})
|
145
|
-
* delete_object(object_name, container_name, options = {})
|
146
|
-
* get_objects(container_name, query = {}, options = {})
|
147
|
-
* paginate_objects(container_name, query = {}, options = {})
|
148
|
-
* public_url(object_name, container_name)
|
149
|
-
* temp_url(object_name, container_name, options = {})
|
150
|
-
* bulk_delete(entries, options = {})
|
130
|
+
* `head_account(options = {}) # => HTTParty::Response`
|
131
|
+
* `post_account(headers = {}, options = {}) # => HTTParty::Response`
|
132
|
+
* `head_containers(options = {}) # => HTTParty::Response`
|
133
|
+
* `get_containers(query = {}, options = {}) # => HTTParty::Response`
|
134
|
+
* `paginate_containers(query = {}, options = {}) # => Enumerator`
|
135
|
+
* `get_container(container_name, query = {}, options = {}) # => HTTParty::Response`
|
136
|
+
* `paginate_container(container_name, query = {}, options = {}) # => Enumerator`
|
137
|
+
* `head_container(container_name, options = {}) # => HTTParty::Response`
|
138
|
+
* `put_container(container_name, headers = {}, options = {}) # => HTTParty::Response`
|
139
|
+
* `post_container(container_name, headers = {}, options = {}) # => HTTParty::Response`
|
140
|
+
* `delete_container(container_name, options = {}) # => HTTParty::Response`
|
141
|
+
* `put_object(object_name, data_or_io, container_name, headers = {}, options = {}) # => HTTParty::Response`
|
142
|
+
* `post_object(object_name, container_name, headers = {}, options = {}) # => HTTParty::Response`
|
143
|
+
* `get_object(object_name, container_name, options = {}) -> HTTParty::Response`
|
144
|
+
* `get_object(object_name, container_name, options = {}) { |chunk| save chunk } # => HTTParty::Response`
|
145
|
+
* `head_object(object_name, container_name, options = {}) # => HTTParty::Response`
|
146
|
+
* `delete_object(object_name, container_name, options = {}) # => HTTParty::Response`
|
147
|
+
* `get_objects(container_name, query = {}, options = {}) # => HTTParty::Response`
|
148
|
+
* `paginate_objects(container_name, query = {}, options = {}) # => Enumerator`
|
149
|
+
* `public_url(object_name, container_name) # => HTTParty::Response`
|
150
|
+
* `temp_url(object_name, container_name, options = {}) # => HTTParty::Response`
|
151
|
+
* `bulk_delete(entries, options = {}) # => entries`
|
152
|
+
* `post_head(object_name, container_name, _headers = {}, options = {}) # => HTTParty::Response`
|
151
153
|
|
152
154
|
### Getting large objects
|
153
155
|
The `get_object` method with out a block is suitable for small objects that easily fit in memory. For larger objects, specify a block to process chunked data as it comes in.
|
data/lib/swift_client.rb
CHANGED
@@ -126,6 +126,12 @@ class SwiftClient
|
|
126
126
|
request :head, "/#{container_name}/#{object_name}", options
|
127
127
|
end
|
128
128
|
|
129
|
+
def post_head(object_name, container_name, _headers = {}, options = {})
|
130
|
+
raise(EmptyNameError) if object_name.empty? || container_name.empty?
|
131
|
+
|
132
|
+
request :post, "/#{container_name}/#{object_name}", options.merge(headers: _headers)
|
133
|
+
end
|
134
|
+
|
129
135
|
def delete_object(object_name, container_name, options = {})
|
130
136
|
raise(EmptyNameError) if object_name.empty? || container_name.empty?
|
131
137
|
|
@@ -333,7 +339,8 @@ class SwiftClient
|
|
333
339
|
|
334
340
|
return unless swift_services.size == 1
|
335
341
|
|
336
|
-
|
342
|
+
interface = options[:interface] || "public"
|
343
|
+
swift_endpoints = swift_service["endpoints"].select { |endpoint| endpoint["interface"] == interface }
|
337
344
|
swift_endpoint = swift_endpoints.first
|
338
345
|
|
339
346
|
return unless swift_endpoints.size == 1
|
data/lib/swift_client/version.rb
CHANGED
data/test/swift_client_test.rb
CHANGED
@@ -77,6 +77,15 @@ class SwiftClientTest < MiniTest::Test
|
|
77
77
|
assert_equal "https://example.com/v1/AUTH_account", @swift_client.storage_url
|
78
78
|
end
|
79
79
|
|
80
|
+
def test_v3_authentication_storage_url_from_catalog_with_multiple_endpoints
|
81
|
+
stub_request(:post, "https://auth.example.com/v3/auth/tokens").with(:body => JSON.dump("auth" => { "identity" => { "methods" => ["password"], "password" => { "user" => { "name" => "username", "password" => "secret", "domain" => { "name" => "example.com" }}}}})).to_return(:status => 200, :body => JSON.dump("token" => { "catalog"=> [{ "type" => "object-store", "endpoints" => [{ "interface"=>"public", "url"=> "https://example.com/v1/AUTH_account" }, { "interface"=>"internal", "url"=> "https://example.com/v2/AUTH_account" }] }] }), :headers => { "X-Subject-Token" => "Token", "Content-Type" => "application/json" })
|
82
|
+
|
83
|
+
@swift_client = SwiftClient.new(:auth_url => "https://auth.example.com/v3", :username => "username", :user_domain => "example.com", :password => "secret", :interface => "internal")
|
84
|
+
|
85
|
+
assert_equal "Token", @swift_client.auth_token
|
86
|
+
assert_equal "https://example.com/v2/AUTH_account", @swift_client.storage_url
|
87
|
+
end
|
88
|
+
|
80
89
|
def test_v3_authentication_without_storage_url_and_multiple_swifts
|
81
90
|
stub_request(:post, "https://auth.example.com/v3/auth/tokens").with(:body => JSON.dump("auth" => { "identity" => { "methods" => ["password"], "password" => { "user" => { "name" => "username", "password" => "secret", "domain" => { "name" => "example.com" }}}}})).to_return(:status => 200, :body => JSON.dump("token" => { "catalog"=> [{ "type" => "object-store", "endpoints" => [{ "interface"=>"public", "url"=> "https://example.com/v1/AUTH_account" }] }, { "type" => "object-store", "endpoints" => [{ "interface"=>"public", "url"=> "https://example.com/v1/AUTH_account" }] }] }), :headers => { "X-Subject-Token" => "Token", "Content-Type" => "application/json" })
|
82
91
|
|
@@ -275,6 +284,12 @@ class SwiftClientTest < MiniTest::Test
|
|
275
284
|
assert_equal 201, @swift_client.post_object("object", "container", "X-Object-Meta-Test" => "Test").code
|
276
285
|
end
|
277
286
|
|
287
|
+
def test_post_head
|
288
|
+
stub_request(:post, 'https://example.com/v1/AUTH_account/container/object').with(headers: { 'Accept' => 'application/json', 'X-Auth-Token' => 'Token', 'X-Delete-At' => '1553524860' }).to_return(status: 201, body: '', headers: {})
|
289
|
+
|
290
|
+
assert_equal 201, @swift_client.post_head('object', 'container', 'X-Delete-At' => '1553524860').code
|
291
|
+
end
|
292
|
+
|
278
293
|
def test_get_object
|
279
294
|
stub_request(:get, "https://example.com/v1/AUTH_account/container/object").with(:headers => { "Accept" => "application/json", "X-Auth-Token" => "Token" }).to_return(:status => 200, :body => "Body", :headers => {})
|
280
295
|
block_res = 0
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swift_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Vetter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
147
|
version: '0'
|
148
148
|
requirements: []
|
149
149
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.
|
150
|
+
rubygems_version: 2.7.3
|
151
151
|
signing_key:
|
152
152
|
specification_version: 4
|
153
153
|
summary: Small but powerful client to interact with OpenStack Swift
|