@Test void registerExisting() { PublicKeyRegisterRequest request = generateRegisterRequest(); when(ec2client.describeKeyPairs(any())).thenReturn(new DescribeKeyPairsResult()); underTest.register(request); verifyNoMoreInteractions(ec2client); }
@Override public void register(PublicKeyRegisterRequest request) { LOGGER.debug("Importing public key {} to {} region on AWS", request.getPublicKeyId(), request.getRegion()); AwsCredentialView awsCredential = new AwsCredentialView(request.getCredential()); try { AmazonEC2Client client = awsClient.createAccess(awsCredential, request.getRegion()); if (!exists(client, request.getPublicKeyId())) { ImportKeyPairRequest importKeyPairRequest = new ImportKeyPairRequest(request.getPublicKeyId(), request.getPublicKey()); client.importKeyPair(importKeyPairRequest); } } catch (Exception e) { String errorMessage = String.format("Failed to import public key [%s:'%s', region: '%s'], detailed message: %s", getType(awsCredential), getAwsId(awsCredential), request.getRegion(), e.getMessage()); LOGGER.error(errorMessage, e); throw new CloudConnectorException(e.getMessage(), e); } }
AwsPublicKeyConnector implements PublicKeyConnector { @Override public void register(PublicKeyRegisterRequest request) { LOGGER.debug("Importing public key {} to {} region on AWS", request.getPublicKeyId(), request.getRegion()); AwsCredentialView awsCredential = new AwsCredentialView(request.getCredential()); try { AmazonEC2Client client = awsClient.createAccess(awsCredential, request.getRegion()); if (!exists(client, request.getPublicKeyId())) { ImportKeyPairRequest importKeyPairRequest = new ImportKeyPairRequest(request.getPublicKeyId(), request.getPublicKey()); client.importKeyPair(importKeyPairRequest); } } catch (Exception e) { String errorMessage = String.format("Failed to import public key [%s:'%s', region: '%s'], detailed message: %s", getType(awsCredential), getAwsId(awsCredential), request.getRegion(), e.getMessage()); LOGGER.error(errorMessage, e); throw new CloudConnectorException(e.getMessage(), e); } } }
AwsPublicKeyConnector implements PublicKeyConnector { @Override public void register(PublicKeyRegisterRequest request) { LOGGER.debug("Importing public key {} to {} region on AWS", request.getPublicKeyId(), request.getRegion()); AwsCredentialView awsCredential = new AwsCredentialView(request.getCredential()); try { AmazonEC2Client client = awsClient.createAccess(awsCredential, request.getRegion()); if (!exists(client, request.getPublicKeyId())) { ImportKeyPairRequest importKeyPairRequest = new ImportKeyPairRequest(request.getPublicKeyId(), request.getPublicKey()); client.importKeyPair(importKeyPairRequest); } } catch (Exception e) { String errorMessage = String.format("Failed to import public key [%s:'%s', region: '%s'], detailed message: %s", getType(awsCredential), getAwsId(awsCredential), request.getRegion(), e.getMessage()); LOGGER.error(errorMessage, e); throw new CloudConnectorException(e.getMessage(), e); } } AwsPublicKeyConnector(AwsClient awsClient); }
AwsPublicKeyConnector implements PublicKeyConnector { @Override public void register(PublicKeyRegisterRequest request) { LOGGER.debug("Importing public key {} to {} region on AWS", request.getPublicKeyId(), request.getRegion()); AwsCredentialView awsCredential = new AwsCredentialView(request.getCredential()); try { AmazonEC2Client client = awsClient.createAccess(awsCredential, request.getRegion()); if (!exists(client, request.getPublicKeyId())) { ImportKeyPairRequest importKeyPairRequest = new ImportKeyPairRequest(request.getPublicKeyId(), request.getPublicKey()); client.importKeyPair(importKeyPairRequest); } } catch (Exception e) { String errorMessage = String.format("Failed to import public key [%s:'%s', region: '%s'], detailed message: %s", getType(awsCredential), getAwsId(awsCredential), request.getRegion(), e.getMessage()); LOGGER.error(errorMessage, e); throw new CloudConnectorException(e.getMessage(), e); } } AwsPublicKeyConnector(AwsClient awsClient); @Override void register(PublicKeyRegisterRequest request); @Override void unregister(PublicKeyUnregisterRequest request); @Override boolean exists(PublicKeyDescribeRequest request); @Override Platform platform(); @Override Variant variant(); }
AwsPublicKeyConnector implements PublicKeyConnector { @Override public void register(PublicKeyRegisterRequest request) { LOGGER.debug("Importing public key {} to {} region on AWS", request.getPublicKeyId(), request.getRegion()); AwsCredentialView awsCredential = new AwsCredentialView(request.getCredential()); try { AmazonEC2Client client = awsClient.createAccess(awsCredential, request.getRegion()); if (!exists(client, request.getPublicKeyId())) { ImportKeyPairRequest importKeyPairRequest = new ImportKeyPairRequest(request.getPublicKeyId(), request.getPublicKey()); client.importKeyPair(importKeyPairRequest); } } catch (Exception e) { String errorMessage = String.format("Failed to import public key [%s:'%s', region: '%s'], detailed message: %s", getType(awsCredential), getAwsId(awsCredential), request.getRegion(), e.getMessage()); LOGGER.error(errorMessage, e); throw new CloudConnectorException(e.getMessage(), e); } } AwsPublicKeyConnector(AwsClient awsClient); @Override void register(PublicKeyRegisterRequest request); @Override void unregister(PublicKeyUnregisterRequest request); @Override boolean exists(PublicKeyDescribeRequest request); @Override Platform platform(); @Override Variant variant();  }