@Test public void testListSSHKeyPairs() { final Set<SshKeyPair> sshKeyPairs = client.getSSHKeyPairApi().listSSHKeyPairs(); for (SshKeyPair sshKeyPair : sshKeyPairs) { checkSSHKeyPair(sshKeyPair); } }
private void cleanupOrphanedKeyPairsInZone(Set<String> groups, String zoneId) { for (String group : groups) { for (SshKeyPair pair : Iterables.filter(client.getSSHKeyPairApi().listSSHKeyPairs(), nameMatches(namingConvention.create().containsGroup(group)))) { logger.debug(">> deleting keypair(%s)", pair.getName()); client.getSSHKeyPairApi().deleteSSHKeyPair(pair.getName()); // TODO: test this clear happens keyPairCache.invalidate(pair.getName()); logger.debug("<< deleted keypair(%s)", pair.getName()); } keyPairCache.invalidate(namingConvention.create().sharedNameForGroup(group)); } }
@Test public void testListAndGetSSHKeyPairsWhenResponseIs2xx() { HttpResponse response = HttpResponse.builder() .statusCode(200) .payload(payloadFromResource("/listsshkeypairsresponse.json")) .build(); SSHKeyPairApi client = requestSendsResponse(HttpRequest.builder() .method("GET") .endpoint( URI.create("http://localhost:8080/client/api?response=json&" + "command=listSSHKeyPairs&listAll=true&apiKey=identity&signature=5d2J9u%2BdKpkQsadDbl9i9OcUSLQ%3D")) .addHeader("Accept", "application/json") .build(), response); assertEquals(client.listSSHKeyPairs(), ImmutableSet.of( SshKeyPair.builder().name("jclouds-keypair") .fingerprint("1c:06:74:52:3b:99:1c:95:5c:04:c2:f4:ba:77:6e:7b").build())); client = requestSendsResponse(HttpRequest.builder() .method("GET") .endpoint( URI.create("http://localhost:8080/client/api?response=json&command=listSSHKeyPairs&listAll=true&" + "name=jclouds-keypair&apiKey=identity&signature=hJIVCFOHhdOww3aq19tFHpeD2HI%3D")) .addHeader("Accept", "application/json") .build(), response); assertEquals(client.getSSHKeyPair("jclouds-keypair"), SshKeyPair.builder().name("jclouds-keypair") .fingerprint("1c:06:74:52:3b:99:1c:95:5c:04:c2:f4:ba:77:6e:7b").build()); }