@Test void unregister() { PublicKeyUnregisterRequest request = generateUnregisterRequest(); underTest.unregister(request); ArgumentCaptor<DeleteKeyPairRequest> captor = ArgumentCaptor.forClass(DeleteKeyPairRequest.class); verify(ec2client).deleteKeyPair(captor.capture()); DeleteKeyPairRequest result = captor.getValue(); assertThat(result.getKeyName()).isEqualTo(PUBLIC_KEY_ID); verifyNoMoreInteractions(ec2client); }
@Override public void unregister(PublicKeyUnregisterRequest request) { LOGGER.debug("Deleting public key {} in {} region on AWS", request.getPublicKeyId(), request.getRegion()); AwsCredentialView awsCredential = new AwsCredentialView(request.getCredential()); try { AmazonEC2Client client = awsClient.createAccess(awsCredential, request.getRegion()); DeleteKeyPairRequest deleteKeyPairRequest = new DeleteKeyPairRequest(request.getPublicKeyId()); client.deleteKeyPair(deleteKeyPairRequest); } catch (Exception e) { String errorMessage = String.format("Failed to delete public key [%s: '%s', region: '%s'], detailed message: %s", getType(awsCredential), getAwsId(awsCredential), request.getRegion(), e.getMessage()); LOGGER.error(errorMessage, e); } }
AwsPublicKeyConnector implements PublicKeyConnector { @Override public void unregister(PublicKeyUnregisterRequest request) { LOGGER.debug("Deleting public key {} in {} region on AWS", request.getPublicKeyId(), request.getRegion()); AwsCredentialView awsCredential = new AwsCredentialView(request.getCredential()); try { AmazonEC2Client client = awsClient.createAccess(awsCredential, request.getRegion()); DeleteKeyPairRequest deleteKeyPairRequest = new DeleteKeyPairRequest(request.getPublicKeyId()); client.deleteKeyPair(deleteKeyPairRequest); } catch (Exception e) { String errorMessage = String.format("Failed to delete public key [%s: '%s', region: '%s'], detailed message: %s", getType(awsCredential), getAwsId(awsCredential), request.getRegion(), e.getMessage()); LOGGER.error(errorMessage, e); } } }
AwsPublicKeyConnector implements PublicKeyConnector { @Override public void unregister(PublicKeyUnregisterRequest request) { LOGGER.debug("Deleting public key {} in {} region on AWS", request.getPublicKeyId(), request.getRegion()); AwsCredentialView awsCredential = new AwsCredentialView(request.getCredential()); try { AmazonEC2Client client = awsClient.createAccess(awsCredential, request.getRegion()); DeleteKeyPairRequest deleteKeyPairRequest = new DeleteKeyPairRequest(request.getPublicKeyId()); client.deleteKeyPair(deleteKeyPairRequest); } catch (Exception e) { String errorMessage = String.format("Failed to delete public key [%s: '%s', region: '%s'], detailed message: %s", getType(awsCredential), getAwsId(awsCredential), request.getRegion(), e.getMessage()); LOGGER.error(errorMessage, e); } } AwsPublicKeyConnector(AwsClient awsClient); }
AwsPublicKeyConnector implements PublicKeyConnector { @Override public void unregister(PublicKeyUnregisterRequest request) { LOGGER.debug("Deleting public key {} in {} region on AWS", request.getPublicKeyId(), request.getRegion()); AwsCredentialView awsCredential = new AwsCredentialView(request.getCredential()); try { AmazonEC2Client client = awsClient.createAccess(awsCredential, request.getRegion()); DeleteKeyPairRequest deleteKeyPairRequest = new DeleteKeyPairRequest(request.getPublicKeyId()); client.deleteKeyPair(deleteKeyPairRequest); } catch (Exception e) { String errorMessage = String.format("Failed to delete public key [%s: '%s', region: '%s'], detailed message: %s", getType(awsCredential), getAwsId(awsCredential), request.getRegion(), e.getMessage()); LOGGER.error(errorMessage, 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 unregister(PublicKeyUnregisterRequest request) { LOGGER.debug("Deleting public key {} in {} region on AWS", request.getPublicKeyId(), request.getRegion()); AwsCredentialView awsCredential = new AwsCredentialView(request.getCredential()); try { AmazonEC2Client client = awsClient.createAccess(awsCredential, request.getRegion()); DeleteKeyPairRequest deleteKeyPairRequest = new DeleteKeyPairRequest(request.getPublicKeyId()); client.deleteKeyPair(deleteKeyPairRequest); } catch (Exception e) { String errorMessage = String.format("Failed to delete public key [%s: '%s', region: '%s'], detailed message: %s", getType(awsCredential), getAwsId(awsCredential), request.getRegion(), e.getMessage()); LOGGER.error(errorMessage, 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();  }