swift_client 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 44973422875ba91bde545267d984f7ad5ce67f5f
4
+ data.tar.gz: 044594bc8d651dde398221808252ba417a1292bf
5
+ SHA512:
6
+ metadata.gz: 51f7033388ebd75a8f83d62900880cd5de518ad08e94fd9c64e8420a8ca0d24eb3e41fc29fa96d4dff4001c2b88ed79831f733fb2b1da80245cc01ceb446c5a1
7
+ data.tar.gz: 5a5199435b62f2b318aacf1728150894d0a242adc8030a167d22b25656c5a925a5472242768b633164359133a346de9d26852b6f221bc551ab4e402d0f259e6c
data/README.md CHANGED
@@ -28,17 +28,64 @@ Or install it yourself as:
28
28
  First, connect to a Swift cluster:
29
29
 
30
30
  ```ruby
31
- swift_client = SwiftClient.new(:auth_url => "https://example.com/auth/v1.0", :username => "account:username", :api_key => "api key", :temp_url_key => "temp url key", :storage_url => "https://example.com/v1/AUTH_account")
31
+ swift_client = SwiftClient.new(
32
+ :auth_url => "https://example.com/auth/v1.0",
33
+ :username => "account:username",
34
+ :api_key => "api key",
35
+ :temp_url_key => "temp url key",
36
+ :storage_url => "https://example.com/v1/AUTH_account"
37
+ )
32
38
  ```
33
39
 
34
40
  To connect via v2 you have to add version and method specific details:
35
41
 
36
42
  ```ruby
37
- swift_client = SwiftClient.new(:auth_url => "https://auth.example.com/v2.0", :storage_url => "https://storage.example.com/v1/AUTH_account", :tenant_name => "tenant", :username => "username", :password => "password")
43
+ swift_client = SwiftClient.new(
44
+ :auth_url => "https://auth.example.com/v2.0",
45
+ :storage_url => "https://storage.example.com/v1/AUTH_account",
46
+ :tenant_name => "tenant",
47
+ :username => "username",
48
+ :password => "password"
49
+ )
38
50
 
39
51
  # OR
40
52
 
41
- swift_client = SwiftClient.new(:auth_url => "https://auth.example.com/v2.0", :storage_url => "https://storage.example.com/v1/AUTH_account", :tenant_name => "tenant", :access_key => "access key", :secret_key => "secret key")
53
+ swift_client = SwiftClient.new(
54
+ :auth_url => "https://auth.example.com/v2.0",
55
+ :storage_url => "https://storage.example.com/v1/AUTH_account",
56
+ :tenant_name => "tenant",
57
+ :access_key => "access key",
58
+ :secret_key => "secret key"
59
+ )
60
+ ```
61
+
62
+ To connect via v3:
63
+
64
+ ```ruby
65
+ swift_client = SwiftClient.new(
66
+ :auth_url => "https://auth.example.com/v3",
67
+ :storage_url => "https://storage.example.com/v1/AUTH_account",
68
+ :username => "username",
69
+ :password => "password",
70
+ :domain => "example.com" # :domain_id => "..." is valid as well
71
+ )
72
+
73
+ # OR
74
+
75
+ swift_client = SwiftClient.new(
76
+ :auth_url => "https://auth.example.com/v3",
77
+ :storage_url => "https://storage.example.com/v1/AUTH_account",
78
+ :user_id => "user id",
79
+ :password => "password"
80
+ )
81
+
82
+ # OR
83
+
84
+ swift_client = SwiftClient.new(
85
+ :auth_url => "https://auth.example.com/v3",
86
+ :storage_url => "https://storage.example.com/v1/AUTH_account",
87
+ :token => "token"
88
+ )
42
89
  ```
43
90
 
44
91
  where `temp_url_key` and `storage_url` are optional.
data/lib/swift_client.rb CHANGED
@@ -185,7 +185,10 @@ class SwiftClient
185
185
  end
186
186
 
187
187
  def authenticate
188
- options[:auth_url] =~ /v2/ ? authenticate_v2 : authenticate_v1
188
+ return authenticate_v3 if options[:auth_url] =~ /v3/
189
+ return authenticate_v2 if options[:auth_url] =~ /v2/
190
+
191
+ authenticate_v1
189
192
  end
190
193
 
191
194
  def authenticate_v1
@@ -230,6 +233,35 @@ class SwiftClient
230
233
  self.storage_url = options[:storage_url]
231
234
  end
232
235
 
236
+ def authenticate_v3
237
+ [:auth_url, :storage_url].each do |key|
238
+ raise(AuthenticationError, "#{key} missing") unless options[key]
239
+ end
240
+
241
+ auth = { "auth" => { "identity" => {} } }
242
+
243
+ if options[:username] && options[:password] && (options[:domain] || options[:domain_id])
244
+ auth["auth"]["identity"]["methods"] = ["password"]
245
+ auth["auth"]["identity"]["password"] = { "user" => { "name" => options[:username], "password" => options[:password] } }
246
+ auth["auth"]["identity"]["password"]["user"]["domain"] = options[:domain] ? { "name" => options[:domain] } : { "id" => options[:domain_id] }
247
+ elsif options[:user_id] && options[:password]
248
+ auth["auth"]["identity"]["methods"] = ["password"]
249
+ auth["auth"]["identity"]["password"] = { "user" => { "id" => options[:user_id], "password" => options[:password] } }
250
+ elsif options[:token]
251
+ auth["auth"]["identity"]["methods"] = ["token"]
252
+ auth["auth"]["identity"]["token"] = { "id" => options[:token] }
253
+ else
254
+ raise AuthenticationError, "Unknown authentication method"
255
+ end
256
+
257
+ response = HTTParty.post("#{options[:auth_url].gsub(/\/+$/, "")}/auth/tokens", :body => JSON.dump(auth), :headers => { "Content-Type" => "application/json" })
258
+
259
+ raise(AuthenticationError, "#{response.code}: #{response.message}") unless response.success?
260
+
261
+ self.auth_token = response.headers["X-Subject-Token"]
262
+ self.storage_url = options[:storage_url]
263
+ end
264
+
233
265
  def paginate(method, *args, query)
234
266
  return enum_for(:paginate, method, *args, query) unless block_given?
235
267
 
@@ -1,5 +1,5 @@
1
1
 
2
2
  class SwiftClient
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
 
@@ -11,6 +11,24 @@ class SwiftClientTest < MiniTest::Test
11
11
  assert_equal "https://example.com/v1/AUTH_account", @swift_client.storage_url
12
12
  end
13
13
 
14
+ def test_v3_authentication_with_password
15
+ 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" => "..."), :headers => { "X-Subject-Token" => "Token", "Content-Type" => "application/json" })
16
+
17
+ @swift_client = SwiftClient.new(:storage_url => "https://example.com/v1/AUTH_account", :auth_url => "https://auth.example.com/v3", :username => "username", :domain => "example.com", :password => "secret")
18
+
19
+ assert_equal "Token", @swift_client.auth_token
20
+ assert_equal "https://example.com/v1/AUTH_account", @swift_client.storage_url
21
+ end
22
+
23
+ def test_v3_authentication_with_token
24
+ stub_request(:post, "https://auth.example.com/v3/auth/tokens").with(:body => JSON.dump("auth" => { "identity" => { "methods" => ["token"], "token" => { "id" => "Token" }}})).to_return(:status => 200, :body => JSON.dump("token" => "..."), :headers => { "X-Subject-Token" => "Token", "Content-Type" => "application/json" })
25
+
26
+ @swift_client = SwiftClient.new(:storage_url => "https://example.com/v1/AUTH_account", :auth_url => "https://auth.example.com/v3", :token => "Token")
27
+
28
+ assert_equal "Token", @swift_client.auth_token
29
+ assert_equal "https://example.com/v1/AUTH_account", @swift_client.storage_url
30
+ end
31
+
14
32
  def test_v2_authentication_with_password
15
33
  stub_request(:post, "https://auth.example.com/v2.0/tokens").with(:body => JSON.dump("auth" => { "tenantName" => "Tenant", "passwordCredentials" => { "username" => "Username", :password => "Password" }})).to_return(:status => 200, :body => JSON.dump("access" => { "token" => { "id" => "Token" }}), :headers => { "Content-Type" => "application/json" })
16
34
 
metadata CHANGED
@@ -1,110 +1,97 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swift_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: 0.1.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Benjamin Vetter
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-12-08 00:00:00.000000000 Z
11
+ date: 2016-02-23 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: httparty
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: mime-types
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - <
31
+ - - "<"
36
32
  - !ruby/object:Gem::Version
37
33
  version: '3.0'
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - <
38
+ - - "<"
44
39
  - !ruby/object:Gem::Version
45
40
  version: '3.0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: bundler
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rake
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: '0'
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: '0'
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: minitest
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: webmock
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - ">="
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - ">="
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  description: Small but powerful client to interact with OpenStack Swift
@@ -114,8 +101,8 @@ executables: []
114
101
  extensions: []
115
102
  extra_rdoc_files: []
116
103
  files:
117
- - .gitignore
118
- - .travis.yml
104
+ - ".gitignore"
105
+ - ".travis.yml"
119
106
  - Gemfile
120
107
  - LICENSE.txt
121
108
  - README.md
@@ -128,27 +115,26 @@ files:
128
115
  homepage: https://github.com/mrkamel/swift_client
129
116
  licenses:
130
117
  - MIT
118
+ metadata: {}
131
119
  post_install_message:
132
120
  rdoc_options: []
133
121
  require_paths:
134
122
  - lib
135
123
  required_ruby_version: !ruby/object:Gem::Requirement
136
- none: false
137
124
  requirements:
138
- - - ! '>='
125
+ - - ">="
139
126
  - !ruby/object:Gem::Version
140
127
  version: '0'
141
128
  required_rubygems_version: !ruby/object:Gem::Requirement
142
- none: false
143
129
  requirements:
144
- - - ! '>='
130
+ - - ">="
145
131
  - !ruby/object:Gem::Version
146
132
  version: '0'
147
133
  requirements: []
148
134
  rubyforge_project:
149
- rubygems_version: 1.8.23
135
+ rubygems_version: 2.2.2
150
136
  signing_key:
151
- specification_version: 3
137
+ specification_version: 4
152
138
  summary: Small but powerful client to interact with OpenStack Swift
153
139
  test_files:
154
140
  - test/swift_client_test.rb