Skip to content

Commit ca627b3

Browse files
committed
Corrected KMS listCryptoKeys_printsCryptoKeys check all the keys.
1 parent 2ab3487 commit ca627b3

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

kms/src/main/java/com/example/Snippets.java

+13-8
Original file line numberDiff line numberDiff line change
@@ -522,14 +522,18 @@ public static void listCryptoKeys(String projectId, String locationId, String ke
522522
"projects/%s/locations/%s/keyRings/%s",
523523
projectId, locationId, keyRingId);
524524

525-
ListCryptoKeysResponse cryptoKeys = kms.projects().locations().keyRings()
526-
.cryptoKeys()
527-
.list(keyRingPath)
528-
.execute();
529-
530-
for (CryptoKey key : cryptoKeys.getCryptoKeys()) {
531-
System.out.println(key);
532-
}
525+
ListCryptoKeysResponse cryptoKeys = null;
526+
do { // Print every page of keys
527+
cryptoKeys = kms.projects().locations().keyRings()
528+
.cryptoKeys()
529+
.list(keyRingPath)
530+
.setPageToken(cryptoKeys != null ? cryptoKeys.getNextPageToken() : null)
531+
.execute();
532+
533+
for (CryptoKey key : cryptoKeys.getCryptoKeys()) {
534+
System.out.println(key);
535+
}
536+
} while(cryptoKeys.getNextPageToken() != null);
533537
}
534538

535539
/**
@@ -546,6 +550,7 @@ public static void listCryptoKeyVersions(
546550
"projects/%s/locations/%s/keyRings/%s/cryptoKeys/%s",
547551
projectId, locationId, keyRingId, cryptoKeyId);
548552

553+
549554
ListCryptoKeyVersionsResponse versions = kms.projects().locations().keyRings().cryptoKeys()
550555
.cryptoKeyVersions()
551556
.list(cryptoKeys)

0 commit comments

Comments
 (0)