ovirt-engine-sdk 4.0.0.alpha20 → 4.0.0.alpha21
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 +4 -4
- data/CHANGES.adoc +6 -0
- data/lib/ovirtsdk4/http.rb +91 -153
- data/lib/ovirtsdk4/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dfaa8fed53218d5e2fc4f8831c66c2fcd7482b15
|
4
|
+
data.tar.gz: 8dddffef4fb16dcf22ab1d5f7792612ad5543273
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1e7aae8738d039ac4fd7bd31d7cacbf90868fe8d936ed33abc9fad4d635f71e24cc8588ab445322282940f3b1df0a919a6543dbe347617e5fb936494b598934
|
7
|
+
data.tar.gz: 182155ff6e2e5ff8a80e6761f704dd43bd361e595e0be87b33faff6d947a0e6beaf035d5f33373f6efa4c0369913bf35995f380afb7a850a6d9dc90fa1de1ba5
|
data/CHANGES.adoc
CHANGED
@@ -3,6 +3,12 @@
|
|
3
3
|
This document describes the relevant changes between releases of the
|
4
4
|
API model.
|
5
5
|
|
6
|
+
== 4.0.0.alpha21 / Aug 22 2016
|
7
|
+
|
8
|
+
Bug fixes:
|
9
|
+
|
10
|
+
* Don't send SSO passwords using HTTP GET and query parameter.
|
11
|
+
|
6
12
|
== 4.0.0.alpha20 / Aug 18 2016
|
7
13
|
|
8
14
|
Update to model 4.0.32.
|
data/lib/ovirtsdk4/http.rb
CHANGED
@@ -77,11 +77,6 @@ module OvirtSDK4
|
|
77
77
|
#
|
78
78
|
# Creates a new connection to the API server.
|
79
79
|
#
|
80
|
-
# Note that all the parameters with names starting with `sso` are intended for use with external authentication
|
81
|
-
# services, using the http://oauth.net/2/[OAuth2] protocol. But the typical usage doesn't require them, as they
|
82
|
-
# are automatically calculated to use the authentication service that is part of the engine. A typical connection
|
83
|
-
# can be created specifying just the `url`, `username`, `password` and `ca_file` parameters:
|
84
|
-
#
|
85
80
|
# [source,ruby]
|
86
81
|
# ----
|
87
82
|
# connection = OvirtSDK4::Connection.new(
|
@@ -129,90 +124,48 @@ module OvirtSDK4
|
|
129
124
|
# compressed responses. Note that this is a hint for the server, and that it may return uncompressed data even
|
130
125
|
# when this parameter is set to `true`.
|
131
126
|
#
|
132
|
-
|
133
|
-
# specified only when using an external authentication service. By default this URL is automatically calculated
|
134
|
-
# from the value of the `url` parameter, so that authentication will be performed using the authentication
|
135
|
-
# service that is part of the engine.
|
136
|
-
#
|
137
|
-
# @option opts [String] :sso_revoke_url A string containing the base URL of the SSO revoke service. This needs to be
|
138
|
-
# specified only when using an external authentication service. By default this URL is automatically calculated
|
139
|
-
# from the value of the `url` parameter, so that SSO token revoke will be performed using the SSO service that
|
140
|
-
# is part of the engine.
|
141
|
-
#
|
142
|
-
# @option opts [Boolean] :sso_insecure A boolean flag that indicates if the SSO server TLS certificate and
|
143
|
-
# host name should be checked. Default is value of `insecure`.
|
144
|
-
#
|
145
|
-
# @option opts [String] :sso_ca_file The name of a PEM file containing the trusted CA certificates. The
|
146
|
-
# certificate presented by the SSO server will be verified using these CA certificates. Default is value of
|
147
|
-
# `ca_file`.
|
148
|
-
#
|
149
|
-
# @option opts [Boolean] :sso_timeout The maximun total time to wait for the SSO response, in seconds. A value
|
150
|
-
# of zero means wait for ever. If the timeout expires before the SSO response is received an exception will be
|
151
|
-
# raised. Default is value of `timeout`.
|
152
|
-
#
|
153
|
-
# @option opts [String] :sso_token_name (access_token) The token name in the JSON SSO response returned from the SSO
|
154
|
-
# server. Default value is `access_token`
|
155
|
-
#
|
156
|
-
def initialize(opts = {})
|
127
|
+
def initialize(opts = {})
|
157
128
|
# Get the values of the parameters and assign default values:
|
158
|
-
url = opts[:url]
|
159
|
-
username = opts[:username]
|
160
|
-
password = opts[:password]
|
161
|
-
token = opts[:token]
|
162
|
-
insecure = opts[:insecure] || false
|
163
|
-
ca_file = opts[:ca_file]
|
129
|
+
@url = opts[:url]
|
130
|
+
@username = opts[:username]
|
131
|
+
@password = opts[:password]
|
132
|
+
@token = opts[:token]
|
133
|
+
@insecure = opts[:insecure] || false
|
134
|
+
@ca_file = opts[:ca_file]
|
164
135
|
@debug = opts[:debug] || false
|
165
136
|
@log = opts[:log]
|
166
|
-
kerberos = opts[:kerberos] || false
|
167
|
-
timeout = opts[:timeout] || 0
|
168
|
-
compress = opts[:compress] || false
|
169
|
-
sso_url = opts[:sso_url]
|
170
|
-
sso_revoke_url = opts[:sso_revoke_url]
|
171
|
-
sso_insecure = opts[:sso_insecure] || insecure
|
172
|
-
sso_ca_file = opts[:sso_ca_file] || ca_file
|
173
|
-
sso_timeout = opts[:sso_timeout] || timeout
|
174
|
-
sso_token_name = opts[:sso_token_name] || 'access_token'
|
137
|
+
@kerberos = opts[:kerberos] || false
|
138
|
+
@timeout = opts[:timeout] || 0
|
139
|
+
@compress = opts[:compress] || false
|
175
140
|
|
176
141
|
# Check mandatory parameters:
|
177
142
|
if url.nil?
|
178
|
-
raise ArgumentError.new("The
|
143
|
+
raise ArgumentError.new("The 'url' parameter is mandatory.")
|
179
144
|
end
|
180
145
|
|
181
146
|
# Save the URL:
|
182
|
-
@url = URI(url)
|
183
|
-
|
184
|
-
# Save SSO parameters:
|
185
|
-
@sso_url = sso_url
|
186
|
-
@sso_revoke_url = sso_revoke_url
|
187
|
-
@username = username
|
188
|
-
@password = password
|
189
|
-
@token = token
|
190
|
-
@kerberos = kerberos
|
191
|
-
@sso_insecure = sso_insecure
|
192
|
-
@sso_ca_file = sso_ca_file
|
193
|
-
@sso_timeout = sso_timeout
|
194
|
-
@sso_token_name = sso_token_name
|
147
|
+
@url = URI(@url)
|
195
148
|
|
196
149
|
# Create the cURL handle:
|
197
150
|
@curl = Curl::Easy.new
|
198
151
|
|
199
152
|
# Configure TLS parameters:
|
200
153
|
if @url.scheme == 'https'
|
201
|
-
if insecure
|
154
|
+
if @insecure
|
202
155
|
@curl.ssl_verify_peer = false
|
203
156
|
@curl.ssl_verify_host = false
|
204
|
-
elsif
|
205
|
-
raise ArgumentError.new("The CA file
|
206
|
-
@curl.cacert = ca_file
|
157
|
+
elsif !@ca_file.nil?
|
158
|
+
raise ArgumentError.new("The CA file '#{@ca_file}' doesn't exist.") unless ::File.file?(@ca_file)
|
159
|
+
@curl.cacert = @ca_file
|
207
160
|
end
|
208
161
|
end
|
209
162
|
|
210
163
|
# Configure the timeout:
|
211
|
-
@curl.timeout = timeout
|
164
|
+
@curl.timeout = @timeout
|
212
165
|
|
213
166
|
# Configure compression of responses (setting the value to a zero length string means accepting all the
|
214
167
|
# compression types that libcurl supports):
|
215
|
-
if compress
|
168
|
+
if @compress
|
216
169
|
@curl.encoding = ''
|
217
170
|
end
|
218
171
|
|
@@ -270,7 +223,6 @@ module OvirtSDK4
|
|
270
223
|
# @api private
|
271
224
|
#
|
272
225
|
def send(request)
|
273
|
-
|
274
226
|
# Check if we already have an SSO access token:
|
275
227
|
@token ||= get_access_token
|
276
228
|
|
@@ -314,31 +266,28 @@ module OvirtSDK4
|
|
314
266
|
end
|
315
267
|
|
316
268
|
#
|
317
|
-
# Obtains the access token from SSO to be used for
|
269
|
+
# Obtains the access token from SSO to be used for bearer authentication.
|
318
270
|
#
|
319
|
-
# @return [String] The
|
271
|
+
# @return [String] The access token.
|
320
272
|
#
|
321
273
|
# @api private
|
322
274
|
#
|
323
275
|
def get_access_token
|
324
|
-
#
|
325
|
-
|
326
|
-
@sso_url = URI(build_sso_auth_url)
|
327
|
-
else
|
328
|
-
@sso_url = URI(@sso_url)
|
329
|
-
end
|
276
|
+
# Build the URL and parameters required for the request:
|
277
|
+
url, parameters = build_sso_auth_request
|
330
278
|
|
331
|
-
|
279
|
+
# Send the response and wait for the request:
|
280
|
+
response = get_sso_response(url, parameters)
|
332
281
|
|
333
|
-
if
|
334
|
-
|
282
|
+
if response.is_a?(Array)
|
283
|
+
response = response[0]
|
335
284
|
end
|
336
285
|
|
337
|
-
|
338
|
-
raise Error.new("Error during SSO authentication #{
|
286
|
+
unless response['error'].nil?
|
287
|
+
raise Error.new("Error during SSO authentication #{response['error_code']}: #{response['error']}")
|
339
288
|
end
|
340
289
|
|
341
|
-
|
290
|
+
response['access_token']
|
342
291
|
end
|
343
292
|
|
344
293
|
#
|
@@ -347,37 +296,37 @@ module OvirtSDK4
|
|
347
296
|
# @api private
|
348
297
|
#
|
349
298
|
def revoke_access_token
|
350
|
-
#
|
351
|
-
|
352
|
-
@sso_revoke_url = URI(build_sso_revoke_url)
|
353
|
-
else
|
354
|
-
@sso_revoke_url = URI(@sso_revoke_url)
|
355
|
-
end
|
299
|
+
# Build the URL and parameters required for the request:
|
300
|
+
url, parameters = build_sso_revoke_request
|
356
301
|
|
357
|
-
|
302
|
+
response = get_sso_response(url, parameters)
|
358
303
|
|
359
|
-
if
|
360
|
-
|
304
|
+
if response.is_a?(Array)
|
305
|
+
response = response[0]
|
361
306
|
end
|
362
307
|
|
363
|
-
|
364
|
-
raise Error.new("Error during SSO revoke #{
|
308
|
+
unless response['error'].nil?
|
309
|
+
raise Error.new("Error during SSO revoke #{response['error_code']}: #{response['error']}")
|
365
310
|
end
|
366
311
|
end
|
367
312
|
|
368
313
|
#
|
369
314
|
# Execute a get request to the SSO server and return the response.
|
370
315
|
#
|
316
|
+
# @param url [String] The URL of the SSO server.
|
317
|
+
#
|
318
|
+
# @param parameters [Hash] The parameters to send to the SSO server.
|
319
|
+
#
|
371
320
|
# @return [Hash] The JSON response.
|
372
321
|
#
|
373
322
|
# @api private
|
374
323
|
#
|
375
|
-
def get_sso_response(
|
324
|
+
def get_sso_response(url, parameters)
|
376
325
|
# Create the cURL handle for SSO:
|
377
326
|
sso_curl = Curl::Easy.new
|
378
327
|
|
379
328
|
# Configure the timeout:
|
380
|
-
sso_curl.timeout = @
|
329
|
+
sso_curl.timeout = @timeout
|
381
330
|
|
382
331
|
# Configure debug mode:
|
383
332
|
if @debug && @log
|
@@ -392,100 +341,95 @@ module OvirtSDK4
|
|
392
341
|
|
393
342
|
begin
|
394
343
|
# Configure TLS parameters:
|
395
|
-
if
|
396
|
-
if @
|
344
|
+
if url.scheme == 'https'
|
345
|
+
if @insecure
|
397
346
|
sso_curl.ssl_verify_peer = false
|
398
347
|
sso_curl.ssl_verify_host = false
|
399
|
-
elsif !@
|
400
|
-
raise ArgumentError.new("The CA file \"#{@
|
401
|
-
sso_curl.cacert = @
|
348
|
+
elsif !@ca_file.nil?
|
349
|
+
raise ArgumentError.new("The CA file \"#{@ca_file}\" doesn't exist.") unless ::File.file?(@ca_file)
|
350
|
+
sso_curl.cacert = @ca_file
|
402
351
|
end
|
403
352
|
end
|
404
353
|
|
405
|
-
# The username and password parameters:
|
406
|
-
params = {}
|
407
|
-
|
408
|
-
# The base SSO URL:
|
409
|
-
sso_url = sso_base_url.to_s
|
410
|
-
|
411
354
|
# Configure authentication:
|
412
|
-
|
413
|
-
sso_curl.http_auth_types = :gssnegotiate
|
414
|
-
sso_curl.username = ''
|
415
|
-
sso_curl.password = ''
|
416
|
-
else
|
417
|
-
sso_curl.http_auth_types = :basic
|
418
|
-
sso_curl.username = @username
|
419
|
-
sso_curl.password = @password
|
420
|
-
if sso_url.index('?').nil?
|
421
|
-
sso_url += '?'
|
422
|
-
end
|
423
|
-
params['username'] = @username
|
424
|
-
params['password'] = @password
|
425
|
-
sso_url = sso_url + '&' + URI.encode_www_form(params)
|
426
|
-
end
|
355
|
+
sso_curl.http_auth_types = @kerberos ? :gssnegotiate : 0
|
427
356
|
|
428
357
|
# Build the SSO access_token request url:
|
429
|
-
sso_curl.url =
|
358
|
+
sso_curl.url = url.to_s
|
430
359
|
|
431
360
|
# Add headers:
|
432
361
|
sso_curl.headers['User-Agent'] = "RubySDK/#{VERSION}"
|
362
|
+
sso_curl.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
433
363
|
sso_curl.headers['Accept'] = 'application/json'
|
434
364
|
|
435
365
|
# Request access token:
|
436
|
-
|
366
|
+
body = URI.encode_www_form(parameters)
|
367
|
+
sso_curl.http_post(body)
|
437
368
|
|
438
369
|
# Parse and return the JSON response:
|
439
|
-
|
370
|
+
body = sso_curl.body_str
|
371
|
+
return JSON.parse(body)
|
440
372
|
ensure
|
441
373
|
sso_curl.close
|
442
374
|
end
|
443
375
|
end
|
444
376
|
|
445
377
|
#
|
446
|
-
# Builds a
|
447
|
-
#
|
378
|
+
# Builds a the URL and parameters to acquire the access token from SSO.
|
379
|
+
#
|
380
|
+
# @return [Array] An array containing two elements, the first is the URL of the SSO service and the second is a hash
|
381
|
+
# containing the parameters required to perform authentication.
|
448
382
|
#
|
449
383
|
# @api private
|
450
384
|
#
|
451
|
-
def
|
452
|
-
#
|
453
|
-
|
454
|
-
|
455
|
-
|
385
|
+
def build_sso_auth_request
|
386
|
+
# Compute the entry point and the parameters:
|
387
|
+
parameters = {
|
388
|
+
:scope => 'ovirt-app-api',
|
389
|
+
}
|
456
390
|
if @kerberos
|
457
|
-
grant_type = 'urn:ovirt:params:oauth:grant-type:http'
|
458
391
|
entry_point = 'token-http-auth'
|
392
|
+
parameters.merge!(
|
393
|
+
:grant_type => 'urn:ovirt:params:oauth:grant-type:http',
|
394
|
+
)
|
459
395
|
else
|
460
|
-
grant_type = 'password'
|
461
396
|
entry_point = 'token'
|
397
|
+
parameters.merge!(
|
398
|
+
:grant_type => 'password',
|
399
|
+
:username => @username,
|
400
|
+
:password => @password,
|
401
|
+
)
|
462
402
|
end
|
463
403
|
|
464
|
-
#
|
404
|
+
# Compute the URL:
|
465
405
|
url = URI(@url.to_s)
|
466
406
|
url.path = "/ovirt-engine/sso/oauth/#{entry_point}"
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
)
|
471
|
-
url.to_s
|
407
|
+
|
408
|
+
# Return the pair containing the URL and the parameters:
|
409
|
+
[url, parameters]
|
472
410
|
end
|
473
411
|
|
474
412
|
#
|
475
|
-
# Builds a
|
476
|
-
#
|
413
|
+
# Builds a the URL and parameters to revoke the SSO access token
|
414
|
+
#
|
415
|
+
# @return [Array] An array containing two elements, the first is the URL of the SSO service and the second is a hash
|
416
|
+
# containing the parameters required to perform the revoke.
|
477
417
|
#
|
478
418
|
# @api private
|
479
419
|
#
|
480
|
-
def
|
481
|
-
#
|
482
|
-
|
483
|
-
url.path = '/ovirt-engine/services/sso-logout'
|
484
|
-
url.query = URI.encode_www_form(
|
420
|
+
def build_sso_revoke_request
|
421
|
+
# Compute the parameters:
|
422
|
+
parameters = {
|
485
423
|
:scope => '',
|
486
424
|
:token => @token,
|
487
|
-
|
488
|
-
|
425
|
+
}
|
426
|
+
|
427
|
+
# Compute the URL:
|
428
|
+
url = URI(@url.to_s)
|
429
|
+
url.path = '/ovirt-engine/services/sso-logout'
|
430
|
+
|
431
|
+
# Return the pair containing the URL and the parameters:
|
432
|
+
[url, parameters]
|
489
433
|
end
|
490
434
|
|
491
435
|
#
|
@@ -564,14 +508,8 @@ module OvirtSDK4
|
|
564
508
|
# Releases the resources used by this connection.
|
565
509
|
#
|
566
510
|
def close
|
567
|
-
# Send the last request to indicate the server that the session should be closed:
|
568
|
-
request = Request.new({
|
569
|
-
:method => :HEAD,
|
570
|
-
})
|
571
|
-
send(request)
|
572
|
-
|
573
511
|
# Revoke the SSO access token:
|
574
|
-
revoke_access_token
|
512
|
+
revoke_access_token unless @token.nil?
|
575
513
|
|
576
514
|
# Release resources used by the cURL handle:
|
577
515
|
@curl.close
|
data/lib/ovirtsdk4/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ovirt-engine-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.0.
|
4
|
+
version: 4.0.0.alpha21
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Hernandez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curb
|