From b450ca4065a71146f7caff128d9da6e1107385c0 Mon Sep 17 00:00:00 2001 From: Stuart Paterson Date: Mon, 14 Jan 2019 11:47:08 +0000 Subject: [PATCH 1/2] Adding pagination for key rings and crypto keys resources. Signed-off-by: Stuart Paterson --- libraries/google_kms_crypto_keys.rb | 21 +++++++++++++-------- libraries/google_kms_key_rings.rb | 21 +++++++++++++-------- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/libraries/google_kms_crypto_keys.rb b/libraries/google_kms_crypto_keys.rb index 40d722d80..47cde2017 100644 --- a/libraries/google_kms_crypto_keys.rb +++ b/libraries/google_kms_crypto_keys.rb @@ -29,15 +29,20 @@ 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 end -end +end \ No newline at end of file diff --git a/libraries/google_kms_key_rings.rb b/libraries/google_kms_key_rings.rb index 96322268f..ad173b4e3 100644 --- a/libraries/google_kms_key_rings.rb +++ b/libraries/google_kms_key_rings.rb @@ -29,15 +29,20 @@ 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 end -end +end \ No newline at end of file From 6599615d6e1bdd11cad091ae14cfa1153af1da70 Mon Sep 17 00:00:00 2001 From: Stuart Paterson Date: Mon, 14 Jan 2019 11:49:15 +0000 Subject: [PATCH 2/2] Rubocoppppping. Signed-off-by: Stuart Paterson --- libraries/google_compute_vpn_tunnel.rb | 2 ++ libraries/google_kms_crypto_keys.rb | 2 +- libraries/google_kms_key_rings.rb | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/google_compute_vpn_tunnel.rb b/libraries/google_compute_vpn_tunnel.rb index 6e0113e5d..a6813d618 100644 --- a/libraries/google_compute_vpn_tunnel.rb +++ b/libraries/google_compute_vpn_tunnel.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'gcp_backend' module Inspec::Resources diff --git a/libraries/google_kms_crypto_keys.rb b/libraries/google_kms_crypto_keys.rb index 47cde2017..3d84b7037 100644 --- a/libraries/google_kms_crypto_keys.rb +++ b/libraries/google_kms_crypto_keys.rb @@ -45,4 +45,4 @@ def fetch_data @table = crypto_key_rows end end -end \ No newline at end of file +end diff --git a/libraries/google_kms_key_rings.rb b/libraries/google_kms_key_rings.rb index ad173b4e3..f3e32d870 100644 --- a/libraries/google_kms_key_rings.rb +++ b/libraries/google_kms_key_rings.rb @@ -45,4 +45,4 @@ def fetch_data @table = key_ring_rows end end -end \ No newline at end of file +end