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

Adding pagination for key rings and crypto keys resources. #97

Merged
merged 2 commits into from
Jan 14, 2019
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
2 changes: 2 additions & 0 deletions libraries/google_compute_vpn_tunnel.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'gcp_backend'

module Inspec::Resources
Expand Down
19 changes: 12 additions & 7 deletions libraries/google_kms_crypto_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ def initialize(opts = {})

def fetch_data
crypto_key_rows = []
catch_gcp_errors do
@crypto_keys = @gcp.gcp_client(Google::Apis::CloudkmsV1::CloudKMSService).list_project_location_key_ring_crypto_keys("projects/#{@project}/locations/#{@location}/keyRings/#{@key_ring_name}")
end
return [] if !@crypto_keys || !@crypto_keys.crypto_keys
@crypto_keys.crypto_keys.map do |crypto_key|
crypto_key_rows+=[{ crypto_key_name: crypto_key.name.split('/').last,
crypto_key_url: crypto_key.name }]
next_page = nil
loop do
catch_gcp_errors do
@crypto_keys = @gcp.gcp_client(Google::Apis::CloudkmsV1::CloudKMSService).list_project_location_key_ring_crypto_keys("projects/#{@project}/locations/#{@location}/keyRings/#{@key_ring_name}", page_token: next_page)
end
return [] if !@crypto_keys || !@crypto_keys.crypto_keys
@crypto_keys.crypto_keys.map do |crypto_key|
crypto_key_rows += [{ crypto_key_name: crypto_key.name.split('/').last,
crypto_key_url: crypto_key.name }]
end
next_page = @crypto_keys.next_page_token
break unless next_page
end
@table = crypto_key_rows
end
Expand Down
19 changes: 12 additions & 7 deletions libraries/google_kms_key_rings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ def initialize(opts = {})

def fetch_data
key_ring_rows = []
catch_gcp_errors do
@key_rings = @gcp.gcp_client(Google::Apis::CloudkmsV1::CloudKMSService).list_project_location_key_rings("projects/#{@project}/locations/#{@location}")
end
return [] if !@key_rings || !@key_rings.key_rings
@key_rings.key_rings.map do |key_ring|
key_ring_rows+=[{ key_ring_name: key_ring.name.split('/').last,
key_ring_url: key_ring.name }]
next_page = nil
loop do
catch_gcp_errors do
@key_rings = @gcp.gcp_client(Google::Apis::CloudkmsV1::CloudKMSService).list_project_location_key_rings("projects/#{@project}/locations/#{@location}", page_token: next_page)
end
return [] if !@key_rings || !@key_rings.key_rings
@key_rings.key_rings.map do |key_ring|
key_ring_rows += [{ key_ring_name: key_ring.name.split('/').last,
key_ring_url: key_ring.name }]
end
next_page = @key_rings.next_page_token
break unless next_page
end
@table = key_ring_rows
end
Expand Down