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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5214a04deae33d3dbf3aca86c230704bc43e962f
4
- data.tar.gz: 63f1fa27f094b28c77823586d3e41b65d5d5a593
3
+ metadata.gz: dfaa8fed53218d5e2fc4f8831c66c2fcd7482b15
4
+ data.tar.gz: 8dddffef4fb16dcf22ab1d5f7792612ad5543273
5
5
  SHA512:
6
- metadata.gz: 6944561cf922724734d358474d0040606f3950ee3dda0f7a2189354f08bbdb8a17de64313ebe7750ec135665595eb465e58e863a78cbcc9883465965fed312f3
7
- data.tar.gz: 12b174c2963ee0f4384e7a6b119c1e4aa05b4a372b0646678bc58100df8aca59dd9c8c03df5c5a657878ed3a84c9e70f579958446db316fa7b8a307b5f877c55
6
+ metadata.gz: d1e7aae8738d039ac4fd7bd31d7cacbf90868fe8d936ed33abc9fad4d635f71e24cc8588ab445322282940f3b1df0a919a6543dbe347617e5fb936494b598934
7
+ data.tar.gz: 182155ff6e2e5ff8a80e6761f704dd43bd361e595e0be87b33faff6d947a0e6beaf035d5f33373f6efa4c0369913bf35995f380afb7a850a6d9dc90fa1de1ba5
@@ -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.
@@ -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
- # @option opts [String] :sso_url A string containing the base URL of the authentication service. This needs to be
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 \"url\" parameter is mandatory.")
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 !ca_file.nil?
205
- raise ArgumentError.new("The CA file \"#{ca_file}\" doesn't exist.") unless ::File.file?(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 Bearer authentication.
269
+ # Obtains the access token from SSO to be used for bearer authentication.
318
270
  #
319
- # @return [String] The URL.
271
+ # @return [String] The access token.
320
272
  #
321
273
  # @api private
322
274
  #
323
275
  def get_access_token
324
- # If SSO url is not supplied build default one:
325
- if @sso_url.nil?
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
- sso_response = get_sso_response(@sso_url)
279
+ # Send the response and wait for the request:
280
+ response = get_sso_response(url, parameters)
332
281
 
333
- if sso_response.is_a?(Array)
334
- sso_response = sso_response[0]
282
+ if response.is_a?(Array)
283
+ response = response[0]
335
284
  end
336
285
 
337
- if !sso_response["error"].nil?
338
- raise Error.new("Error during SSO authentication #{sso_response['error_code']} : #{sso_response['error']}")
286
+ unless response['error'].nil?
287
+ raise Error.new("Error during SSO authentication #{response['error_code']}: #{response['error']}")
339
288
  end
340
289
 
341
- return sso_response[@sso_token_name]
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
- # If SSO revoke url is not supplied build default one:
351
- if @sso_revoke_url.nil?
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
- sso_response = get_sso_response(@sso_revoke_url)
302
+ response = get_sso_response(url, parameters)
358
303
 
359
- if sso_response.is_a?(Array)
360
- sso_response = sso_response[0]
304
+ if response.is_a?(Array)
305
+ response = response[0]
361
306
  end
362
307
 
363
- if !sso_response["error"].nil?
364
- raise Error.new("Error during SSO revoke #{sso_response['error_code']} : #{sso_response['error']}")
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(sso_base_url)
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 = @sso_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 sso_base_url.scheme == 'https'
396
- if @sso_insecure
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 !@sso_ca_file.nil?
400
- raise ArgumentError.new("The CA file \"#{@sso_ca_file}\" doesn't exist.") unless ::File.file?(@sso_ca_file)
401
- sso_curl.cacert = @sso_ca_file
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
- if @kerberos
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 = sso_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
- sso_curl.http_get
366
+ body = URI.encode_www_form(parameters)
367
+ sso_curl.http_post(body)
437
368
 
438
369
  # Parse and return the JSON response:
439
- return JSON.parse(sso_curl.body_str)
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 request URL to acquire the access token from SSO. The URLS are different for basic auth and Kerberos,
447
- # @return [String] The URL.
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 build_sso_auth_url
452
- # The SSO access scope:
453
- scope = 'ovirt-app-api'
454
-
455
- # Set the grant type and entry point to request from SSO:
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
- # Copy the base URL and modify it to point to the SSO authentication service:
404
+ # Compute the URL:
465
405
  url = URI(@url.to_s)
466
406
  url.path = "/ovirt-engine/sso/oauth/#{entry_point}"
467
- url.query = URI.encode_www_form(
468
- :grant_type => grant_type,
469
- :scope => scope,
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 request URL to revoke the SSO access token.
476
- # @return [String] The URL.
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 build_sso_revoke_url
481
- # Copy the base URL and modify it to point to the SSO logout service:
482
- url = URI(@url.to_s)
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
- url.to_s
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
@@ -16,5 +16,5 @@
16
16
 
17
17
 
18
18
  module OvirtSDK4
19
- VERSION = '4.0.0.alpha20'
19
+ VERSION = '4.0.0.alpha21'
20
20
  end
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.alpha20
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-18 00:00:00.000000000 Z
11
+ date: 2016-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curb