@Override protected IterableWithMarker<Key> fetchPageUsingOptions(ListOptions options, Optional<Object> arg0) { return api.keyApi().list(options); } }
private void createKeyPairForPublicKeyInOptionsAndAddToSet(DigitalOcean2TemplateOptions options, Set<Integer> generatedSshKeyIds) { logger.debug(">> checking if the key pair already exists..."); PublicKey userKey = sshKeyToPublicKey.apply(options.getPublicKey()); String userFingerprint = computeFingerprint(userKey); Key key = api.keyApi().get(userFingerprint); if (key == null) { logger.debug(">> key pair not found. creating a new one..."); Key newKey = api.keyApi().create(userFingerprint, options.getPublicKey()); generatedSshKeyIds.add(newKey.id()); logger.debug(">> key pair created! %s", newKey); } else { logger.debug(">> key pair found! %s", key); generatedSshKeyIds.add(key.id()); } }
private void cleanupAutoGeneratedKeyPairs(Set<Integer> generatedSshKeyIds) { logger.debug(">> cleaning up auto-generated key pairs..."); for (Integer sshKeyId : generatedSshKeyIds) { try { api.keyApi().delete(sshKeyId); } catch (Exception ex) { logger.warn(">> could not delete key pair %s: %s", sshKeyId, ex.getMessage()); } } }
@AfterClass(alwaysRun = true) public void testDeleteKey() { if (dsa != null) { api().delete(dsa.id()); FluentIterable<Key> keys = api().list().concat(); assertFalse(keys.contains(dsa), "dsa key must not be present in list"); } if (ecdsa != null) { api().delete(ecdsa.fingerprint()); FluentIterable<Key> keys = api().list().concat(); assertFalse(keys.contains(ecdsa), "dsa key must not be present in list"); } }
private void generateKeyPairAndAddKeyToSet(DigitalOcean2TemplateOptions options, Set<Integer> generatedSshKeyIds, String prefix) { logger.debug(">> creating default keypair for node..."); Map<String, String> defaultKeys = keyGenerator.get(); Key defaultKey = api.keyApi().create(prefix + "-" + System.getProperty("user.name"), defaultKeys.get("public")); generatedSshKeyIds.add(defaultKey.id()); logger.debug(">> keypair created! %s", defaultKey); // If a private key has not been explicitly set, configure the auto-generated one if (Strings.isNullOrEmpty(options.getLoginPrivateKey())) { options.overrideLoginPrivateKey(defaultKeys.get("private")); } }
public void testUpdateKey() throws InterruptedException { server.enqueue(jsonResponse("/key.json")); Key key = api.keyApi().update(1, "foo"); assertEquals(key, keyFromResource("/key.json")); assertEquals(server.getRequestCount(), 1); assertSent(server, "PUT", "/account/keys/1", "{\"name\":\"foo\"}"); }
private void generateKeyPairAndAddKeyToSet(DigitalOcean2TemplateOptions options, Set<Integer> generatedSshKeyIds, String prefix) { logger.debug(">> creating default keypair for node..."); Map<String, String> defaultKeys = keyGenerator.get(); Key defaultKey = api.keyApi().create(prefix + "-" + System.getProperty("user.name"), defaultKeys.get("public")); generatedSshKeyIds.add(defaultKey.id()); logger.debug(">> keypair created! %s", defaultKey); // If a private key has not been explicitly set, configure the auto-generated one if (Strings.isNullOrEmpty(options.getLoginPrivateKey())) { options.overrideLoginPrivateKey(defaultKeys.get("private")); } }
public void testGetKeyReturns404() throws InterruptedException { server.enqueue(response404()); Key key = api.keyApi().get(1); assertNull(key); assertEquals(server.getRequestCount(), 1); assertSent(server, "GET", "/account/keys/1"); }
public void testUpdateKeyUsingFingerprint() throws InterruptedException { server.enqueue(jsonResponse("/key.json")); Key key = api.keyApi().update("1a:cc:9b:88:c8:4f:b8:77:96:15:d2:0c:95:86:ff:90", "foo"); assertEquals(key, keyFromResource("/key.json")); assertEquals(server.getRequestCount(), 1); assertSent(server, "PUT", "/account/keys/1a:cc:9b:88:c8:4f:b8:77:96:15:d2:0c:95:86:ff:90", "{\"name\":\"foo\"}"); }
@Override protected IterableWithMarker<Key> fetchPageUsingOptions(ListOptions options, Optional<Object> arg0) { return api.keyApi().list(options); } }
private void createKeyPairForPublicKeyInOptionsAndAddToSet(DigitalOcean2TemplateOptions options, Set<Integer> generatedSshKeyIds) { logger.debug(">> checking if the key pair already exists..."); PublicKey userKey = sshKeyToPublicKey.apply(options.getPublicKey()); String userFingerprint = computeFingerprint(userKey); Key key = api.keyApi().get(userFingerprint); if (key == null) { logger.debug(">> key pair not found. creating a new one..."); Key newKey = api.keyApi().create(userFingerprint, options.getPublicKey()); generatedSshKeyIds.add(newKey.id()); logger.debug(">> key pair created! %s", newKey); } else { logger.debug(">> key pair found! %s", key); generatedSshKeyIds.add(key.id()); } }
private void cleanupAutoGeneratedKeyPairs(Set<Integer> generatedSshKeyIds) { logger.debug(">> cleaning up auto-generated key pairs..."); for (Integer sshKeyId : generatedSshKeyIds) { try { api.keyApi().delete(sshKeyId); } catch (Exception ex) { logger.warn(">> could not delete key pair %s: %s", sshKeyId, ex.getMessage()); } } }
private void generateKeyPairAndAddKeyToSet(DigitalOcean2TemplateOptions options, Set<Integer> generatedSshKeyIds, String prefix) { logger.debug(">> creating default keypair for node..."); Map<String, String> defaultKeys = keyGenerator.get(); Key defaultKey = api.keyApi().create(prefix + "-" + System.getProperty("user.name"), defaultKeys.get("public")); generatedSshKeyIds.add(defaultKey.id()); logger.debug(">> keypair created! %s", defaultKey); // If a private key has not been explicitly set, configure the auto-generated one if (Strings.isNullOrEmpty(options.getLoginPrivateKey())) { options.overrideLoginPrivateKey(defaultKeys.get("private")); } }
public void testGetKeyUsingFingerprintReturns404() throws InterruptedException { server.enqueue(response404()); Key key = api.keyApi().get("1a:cc:9b:88:c8:4f:b8:77:96:15:d2:0c:95:86:ff:90"); assertNull(key); assertEquals(server.getRequestCount(), 1); assertSent(server, "GET", "/account/keys/1a:cc:9b:88:c8:4f:b8:77:96:15:d2:0c:95:86:ff:90"); }
@Override protected IterableWithMarker<Key> fetchPageUsingOptions(ListOptions options, Optional<Object> arg0) { return api.keyApi().list(options); } }
private void createKeyPairForPublicKeyInOptionsAndAddToSet(DigitalOcean2TemplateOptions options, Set<Integer> generatedSshKeyIds) { logger.debug(">> checking if the key pair already exists..."); PublicKey userKey = sshKeyToPublicKey.apply(options.getPublicKey()); String userFingerprint = computeFingerprint(userKey); Key key = api.keyApi().get(userFingerprint); if (key == null) { logger.debug(">> key pair not found. creating a new one..."); Key newKey = api.keyApi().create(userFingerprint, options.getPublicKey()); generatedSshKeyIds.add(newKey.id()); logger.debug(">> key pair created! %s", newKey); } else { logger.debug(">> key pair found! %s", key); generatedSshKeyIds.add(key.id()); } }
private void cleanupAutoGeneratedKeyPairs(Set<Integer> generatedSshKeyIds) { logger.debug(">> cleaning up auto-generated key pairs..."); for (Integer sshKeyId : generatedSshKeyIds) { try { api.keyApi().delete(sshKeyId); } catch (Exception ex) { logger.warn(">> could not delete key pair %s: %s", sshKeyId, ex.getMessage()); } } }