lib/vra/client.rb in vmware-vra-1.1.0 vs lib/vra/client.rb in vmware-vra-1.2.0
- old
+ new
@@ -21,19 +21,20 @@
require 'passwordmasker'
module Vra
# rubocop:disable ClassLength
class Client
- attr_accessor :bearer_token
+ attr_accessor :bearer_token, :page_size
def initialize(opts)
@base_url = opts[:base_url]
@username = opts[:username]
@password = PasswordMasker.new(opts[:password])
@tenant = opts[:tenant]
@verify_ssl = opts.fetch(:verify_ssl, true)
@bearer_token = PasswordMasker.new(nil)
+ @page_size = opts.fetch(:page_size, 20)
validate_client_options!
end
#########################
@@ -136,21 +137,27 @@
def http_get!(path)
response = http_get(path)
response.body
end
- def http_get_paginated_array!(path, limit=20)
+ def http_get_paginated_array!(path)
items = []
page = 1
- base_path = path + "?limit=#{limit}"
+ base_path = path + "?limit=#{page_size}"
loop do
response = FFI_Yajl::Parser.parse(http_get!("#{base_path}&page=#{page}"))
items += response['content']
break if page >= response['metadata']['totalPages']
page += 1
end
+
+ raise Vra::Exception::DuplicateItemsDetected,
+ 'Duplicate items were returned by the vRA API. ' \
+ 'Increase your page size to avoid this vRA API bug. ' \
+ 'See https://github.com/chef-partners/vmware-vra-gem#pagination ' \
+ 'for more information.' if items.uniq!
items
end
def http_post(path, payload, skip_auth=nil)