Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing paging on all models #609

Merged
merged 2 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions lib/fog/compute/google/models/addresses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,25 @@ def all(region: nil, filter: nil, max_results: nil, order_by: nil, page_token: n
:order_by => order_by,
:page_token => page_token
}

if region
data = service.list_addresses(region, **opts).items || []
else
data = []
service.list_aggregated_addresses(**opts).items.each_value do |scoped_list|
data.concat(scoped_list.addresses) if scoped_list && scoped_list.addresses
items = []
next_page_token = nil
loop do
if region
data = service.list_addresses(region, **opts)
next_items = data.items || []
items.concat(next_items)
next_page_token = data.next_page_token
else
data = service.list_aggregated_addresses(**opts)
data.items.each_value do |scoped_list|
items.concat(scoped_list.addresses) if scoped_list && scoped_list.addresses
end
next_page_token = data.next_page_token
end
break if next_page_token.nil? || next_page_token.empty?
opts[:page_token] = next_page_token
end
load(data.map(&:to_h))
load(items.map(&:to_h))
end

def get(identity, region = nil)
Expand Down
24 changes: 17 additions & 7 deletions lib/fog/compute/google/models/disk_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@ def all(zone: nil, filter: nil, max_results: nil,
:order_by => order_by,
:page_token => page_token
}
if zone
data = service.list_disk_types(zone, **opts).items
else
data = []
service.list_aggregated_disk_types(**opts).items.each_value do |scoped_lst|
data.concat(scoped_lst.disk_types) if scoped_lst && scoped_lst.disk_types
items = []
next_page_token = nil
loop do
if zone
data = service.list_disk_types(zone, **opts)
next_items = data.items || []
items.concat(next_items)
next_page_token = data.next_page_token
else
data = service.list_aggregated_disk_types(**opts)
data.items.each_value do |scoped_lst|
items.concat(scoped_lst.disk_types) if scoped_lst && scoped_lst.disk_types
end
next_page_token = data.next_page_token
end
break if next_page_token.nil? || next_page_token.empty?
opts[:page_token] = next_page_token
end
load(data.map(&:to_h))
load(items.map(&:to_h))
end

def get(identity, zone = nil)
Expand Down
24 changes: 17 additions & 7 deletions lib/fog/compute/google/models/disks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@ def all(zone: nil, filter: nil, max_results: nil, order_by: nil,
:order_by => order_by,
:page_token => page_token
}
if zone
data = service.list_disks(zone, **opts).items || []
else
data = []
service.list_aggregated_disks(**opts).items.each_value do |scoped_list|
data.concat(scoped_list.disks) if scoped_list.disks
items = []
next_page_token = nil
loop do
if zone
data = service.list_disks(zone, **opts)
next_items = data.items || []
items.concat(next_items)
next_page_token = data.next_page_token
else
data = service.list_aggregated_disks(**opts)
data.items.each_value do |scoped_list|
items.concat(scoped_list.disks) if scoped_list && scoped_list.disks
end
next_page_token = data.next_page_token
end
break if next_page_token.nil? || next_page_token.empty?
opts[:page_token] = next_page_token
end
load(data.map(&:to_h))
load(items.map(&:to_h))
end

def get(identity, zone = nil)
Expand Down
13 changes: 11 additions & 2 deletions lib/fog/compute/google/models/firewalls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ class Firewalls < Fog::Collection
model Fog::Compute::Google::Firewall

def all(opts = {})
data = service.list_firewalls(**opts).to_h[:items]
load(data || [])
items = []
next_page_token = nil
loop do
data = service.list_firewalls(**opts)
next_items = data.to_h[:items] || []
items.concat(next_items)
next_page_token = data.next_page_token
break if next_page_token.nil? || next_page_token.empty?
opts[:page_token] = next_page_token
end
load(items)
end

def get(identity)
Expand Down
26 changes: 16 additions & 10 deletions lib/fog/compute/google/models/forwarding_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,25 @@ def all(region: nil, filter: nil, max_results: nil, order_by: nil, page_token: n
:order_by => order_by,
:page_token => page_token
}

if region
data = service.list_forwarding_rules(region, **opts).items || []
else
data = []
service.list_aggregated_forwarding_rules(**opts).items
.each_value do |scoped_list|
if scoped_list && scoped_list.forwarding_rules
data.concat(scoped_list.forwarding_rules)
items = []
next_page_token = nil
loop do
if region
data = service.list_forwarding_rules(region, **opts)
next_items = data.items || []
items.concat(next_items)
next_page_token = data.next_page_token
else
data = service.list_aggregated_forwarding_rules(**opts)
data.items.each_value do |scoped_list|
items.concat(scoped_list.forwarding_rules) if scoped_list && scoped_list.forwarding_rules
end
next_page_token = data.next_page_token
end
break if next_page_token.nil? || next_page_token.empty?
opts[:page_token] = next_page_token
end
load(data.map(&:to_h))
load(items.map(&:to_h))
end

def get(identity, region = nil)
Expand Down
13 changes: 11 additions & 2 deletions lib/fog/compute/google/models/global_addresses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ class GlobalAddresses < Fog::Collection
model Fog::Compute::Google::GlobalAddress

def all(options = {})
data = service.list_global_addresses(**options).to_h[:items] || []
load(data)
items = []
next_page_token = nil
loop do
data = service.list_global_addresses(**options)
next_items = data.to_h[:items] || []
items.concat(next_items)
next_page_token = data.next_page_token
break if next_page_token.nil? || next_page_token.empty?
options[:page_token] = next_page_token
end
load(items)
end

def get(identity)
Expand Down
13 changes: 11 additions & 2 deletions lib/fog/compute/google/models/global_forwarding_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ class GlobalForwardingRules < Fog::Collection
model Fog::Compute::Google::GlobalForwardingRule

def all(opts = {})
data = service.list_global_forwarding_rules(**opts).to_h[:items] || []
load(data)
items = []
next_page_token = nil
loop do
data = service.list_global_forwarding_rules(**opts)
next_items = data.to_h[:items] || []
items.concat(next_items)
next_page_token = data.next_page_token
break if next_page_token.nil? || next_page_token.empty?
opts[:page_token] = next_page_token
end
load(items)
end

def get(identity)
Expand Down
15 changes: 12 additions & 3 deletions lib/fog/compute/google/models/http_health_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ class Google
class HttpHealthChecks < Fog::Collection
model Fog::Compute::Google::HttpHealthCheck

def all(_filters = {})
data = service.list_http_health_checks.to_h[:items] || []
load(data)
def all(opts = {})
items = []
next_page_token = nil
loop do
data = service.list_http_health_checks(**opts)
next_items = data.to_h[:items] || []
items.concat(next_items)
next_page_token = data.next_page_token
break if next_page_token.nil? || next_page_token.empty?
opts[:page_token] = next_page_token
end
load(items)
end

def get(identity)
Expand Down
23 changes: 15 additions & 8 deletions lib/fog/compute/google/models/images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,29 @@ class Images < Fog::Collection
windows-sql-cloud
).freeze

def all
data = all_projects.map do |project|
def all(opts = {})
items = []
all_projects.each do |project|
begin
images = service.list_images(project).items || []
# Keep track of the project in which we found the image(s)
images.map { |img| img.to_h.merge(:project => project) }
next_page_token = nil
loop do
opts[:page_token] = next_page_token
data = service.list_images(project, **opts)
images = data.items&.map(&:to_h) || []
# Keep track of the project in which we found the image(s)
images.each { |img| img.merge!(:project => project) }
items.concat(images)
next_page_token = data.next_page_token
break if next_page_token.nil? || next_page_token.empty?
end
rescue ::Google::Apis::ClientError => e
raise e unless e.status_code == 404
# Not everyone has access to every Global Project. Requests
# return 404 if you don't have access.
next
end
end
data = data.flatten

load(data)
load(items)
end

# Only return the non-deprecated list of images
Expand Down
26 changes: 17 additions & 9 deletions lib/fog/compute/google/models/instance_group_managers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,25 @@ def all(zone: nil, filter: nil, max_results: nil,
:order_by => order_by,
:page_token => page_token
}

if zone
data = service.list_instance_group_managers(zone, **opts).items || []
else
data = []
service.list_aggregated_instance_group_managers(**opts).items.each_value do |group|
data.concat(group.instance_group_managers) if group.instance_group_managers
items = []
next_page_token = nil
loop do
if zone
data = service.list_instance_group_managers(zone, **opts)
next_items = data.items || []
items.concat(next_items)
next_page_token = data.next_page_token
else
data = service.list_aggregated_instance_group_managers(**opts)
data.items.each_value do |group|
items.concat(group.instance_group_managers) if group && group.instance_group_managers
end
next_page_token = data.next_page_token
end
break if next_page_token.nil? || next_page_token.empty?
opts[:page_token] = next_page_token
end

load(data.map(&:to_h))
load(items.map(&:to_h))
end

def get(identity, zone = nil)
Expand Down
24 changes: 16 additions & 8 deletions lib/fog/compute/google/models/instance_groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,25 @@ def all(zone: nil, filter: nil, max_results: nil, order_by: nil, page_token: nil
:order_by => order_by,
:page_token => page_token
}

if zone
data = service.list_instance_groups(zone).items || []
else
data = []
service.list_aggregated_instance_groups(opts).items.each_value do |group|
data.concat(group.instance_groups) if group && group.instance_groups
items = []
next_page_token = nil
loop do
if zone
data = service.list_instance_groups(zone)
next_items = data.items || []
items.concat(next_items)
else
data = service.list_aggregated_instance_groups(opts)
data.items.each_value do |group|
items.concat(group.instance_groups) if group && group.instance_groups
end
next_page_token = data.next_page_token
end
break if next_page_token.nil? || next_page_token.empty?
opts[:page_token] = next_page_token
end

load(data.map(&:to_h))
load(items.map(&:to_h))
end

def get(identity, zone = nil)
Expand Down
15 changes: 12 additions & 3 deletions lib/fog/compute/google/models/instance_templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ class Google
class InstanceTemplates < Fog::Collection
model Fog::Compute::Google::InstanceTemplate

def all
data = service.list_instance_templates.items || []
load(data.map(&:to_h))
def all(opts = {})
items = []
next_page_token = nil
loop do
data = service.list_instance_templates(**opts)
next_items = data.items || []
items.concat(next_items)
next_page_token = data.next_page_token
break if next_page_token.nil? || next_page_token.empty?
opts[:page_token] = next_page_token
end
load(items.map(&:to_h))
end

def get(identity)
Expand Down
25 changes: 17 additions & 8 deletions lib/fog/compute/google/models/machine_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,25 @@ def all(zone: nil, filter: nil, max_results: nil, order_by: nil, page_token: nil
:order_by => order_by,
:page_token => page_token
}

if zone
data = service.list_machine_types(zone, **opts).items
else
data = []
service.list_aggregated_machine_types(**opts).items.each_value do |scoped_list|
data.concat(scoped_list.machine_types) if scoped_list && scoped_list.machine_types
items = []
next_page_token = nil
loop do
if zone
data = service.list_machine_types(zone, **opts)
next_items = data.items || []
items.concat(next_items)
next_page_token = data.next_page_token
else
data = service.list_aggregated_machine_types(**opts)
data.items.each_value do |scoped_list|
items.concat(scoped_list.machine_types) if scoped_list && scoped_list.machine_types
end
next_page_token = data.next_page_token
end
break if next_page_token.nil? || next_page_token.empty?
opts[:page_token] = next_page_token
end
load(data.map(&:to_h) || [])
load(items.map(&:to_h) || [])
end

def get(identity, zone = nil)
Expand Down
Loading