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")); } }
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")); } }
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")); } }
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 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 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()); } }
@BeforeClass public void setupDroplet() { region = firstAvailableRegion(); image = ubuntuImageInRegion(region); size = cheapestSizeInRegionForImage(region, image); Map<String, String> keyPair = SshKeys.generate(); key = api.keyApi().create(prefix + "-droplet-livetest", keyPair.get("public")); }
public void testCreateKey() throws InterruptedException { server.enqueue(jsonResponse("/key.json").setStatus("HTTP/1.1 201 Created")); String dsa = stringFromResource("/ssh-dsa.pub"); Key key = api.keyApi().create("foo", dsa); assertEquals(key, keyFromResource("/key.json")); assertEquals(server.getRequestCount(), 1); assertSent(server, "POST", "/account/keys", String.format("{\"name\":\"foo\", \"public_key\":\"%s\"}", dsa)); }