Skip to content

Commit

Permalink
Merge pull request #97 from inspec/paginate-kms-resources
Browse files Browse the repository at this point in the history
Adding pagination for key rings and crypto keys resources.
  • Loading branch information
russellseymour authored Jan 14, 2019
2 parents cb3ae3a + 6599615 commit a815500
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
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

0 comments on commit a815500

Please sign in to comment.