CreateDropletOptions.Builder options = CreateDropletOptions.builder();
// Create a default keypair for the node so it has a known private key
Map<String, String> defaultKeys = keyGenerator.get();
logger.debug(">> creating default keypair for node...");
SshKey defaultKey = api.getKeyPairApi().create(name, defaultKeys.get("public"));
logger.debug(">> keypair created! %s", defaultKey);
options.addSshKeyId(defaultKey.getId());
// Check if there is a key to authorize in the portable options
if (!Strings.isNullOrEmpty(template.getOptions().getPublicKey())) {
logger.debug(">> creating user keypair for node...");
// The DigitalOcean API accepts multiple key pairs with the same name. It will be useful to identify all
// keypairs associated with the node when it comes to destroy it
SshKey key = api.getKeyPairApi().create(name, template.getOptions().getPublicKey());
logger.debug(">> keypair created! %s", key);
options.addSshKeyId(key.getId());
}
// DigitalOcean specific options
if (!templateOptions.getSshKeyIds().isEmpty()) {
options.addSshKeyIds(templateOptions.getSshKeyIds());