com.amazonaws.services.ec2.model.DeleteKeyPairRequest Java Examples

The following examples show how to use com.amazonaws.services.ec2.model.DeleteKeyPairRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeleteKeyPair.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args)
{
    final String USAGE =
        "To run this example, supply a key pair name\n" +
        "Ex: DeleteKeyPair <key-pair-name>\n";

    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String key_name = args[0];

    final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();

    DeleteKeyPairRequest request = new DeleteKeyPairRequest()
        .withKeyName(key_name);

    DeleteKeyPairResult response = ec2.deleteKeyPair(request);

    System.out.printf(
        "Successfully deleted key pair named %s", key_name);
}
 
Example #2
Source File: TearDownCloudFormationTestsTask.java    From aws-ant-tasks with Apache License 2.0 5 votes vote down vote up
public void execute() {
    checkParams();
    AmazonEC2Client ec2Client = getOrCreateClient(AmazonEC2Client.class);
    ec2Client
            .deleteKeyPair(new DeleteKeyPairRequest().withKeyName(keyName));
    AmazonCloudFormationClient cloudFormationClient = getOrCreateClient(AmazonCloudFormationClient.class);
    cloudFormationClient.deleteStack(new DeleteStackRequest()
            .withStackName(stackName));
}
 
Example #3
Source File: AwsTerminateService.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
private void deleteKeyPair(AuthenticatedContext ac, CloudStack stack, AmazonEC2Client amazonEC2Client, AwsCredentialView credentialView, String regionName) {
    LOGGER.debug("Deleting keypairs");
    if (!awsClient.existingKeyPairNameSpecified(stack.getInstanceAuthentication())) {
        try {
            DeleteKeyPairRequest deleteKeyPairRequest = new DeleteKeyPairRequest(awsClient.getKeyPairName(ac));
            amazonEC2Client.deleteKeyPair(deleteKeyPairRequest);
        } catch (Exception e) {
            String errorMessage = String.format("Failed to delete public key [roleArn:'%s', region: '%s'], detailed message: %s",
                    credentialView.getRoleArn(), regionName, e.getMessage());
            LOGGER.warn(errorMessage, e);
        }
    }
}
 
Example #4
Source File: AwsPublicKeyConnector.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #5
Source File: AwsPublicKeyConnectorTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #6
Source File: AwsPublicKeyConnectorTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
void unregisterNotFoundDoesNotThrow() {
    PublicKeyUnregisterRequest request = generateUnregisterRequest();
    when(ec2client.deleteKeyPair(any())).thenThrow(new AmazonServiceException("no such key"));
    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);
}
 
Example #7
Source File: KeyPairImpl.java    From aws-sdk-java-resources with Apache License 2.0 4 votes vote down vote up
@Override
public void delete(DeleteKeyPairRequest request) {
    delete(request, null);
}
 
Example #8
Source File: KeyPairImpl.java    From aws-sdk-java-resources with Apache License 2.0 4 votes vote down vote up
@Override
public void delete(DeleteKeyPairRequest request, ResultCapture<Void>
        extractor) {

    resource.performAction("Delete", request, extractor);
}
 
Example #9
Source File: KeyPairImpl.java    From aws-sdk-java-resources with Apache License 2.0 4 votes vote down vote up
@Override
public void delete(ResultCapture<Void> extractor) {
    DeleteKeyPairRequest request = new DeleteKeyPairRequest();
    delete(request, extractor);
}
 
Example #10
Source File: KeyPair.java    From aws-sdk-java-resources with Apache License 2.0 2 votes vote down vote up
/**
 * Performs the <code>Delete</code> action.
 *
 * <p>
 * The following request parameters will be populated from the data of this
 * <code>KeyPair</code> resource, and any conflicting parameter value set in
 * the request will be overridden:
 * <ul>
 *   <li>
 *     <b><code>KeyName</code></b>
 *         - mapped from the <code>Name</code> identifier.
 *   </li>
 * </ul>
 *
 * <p>
 *
 * @see DeleteKeyPairRequest
 */
void delete(DeleteKeyPairRequest request);
 
Example #11
Source File: KeyPair.java    From aws-sdk-java-resources with Apache License 2.0 2 votes vote down vote up
/**
 * Performs the <code>Delete</code> action and use a ResultCapture to
 * retrieve the low-level client response.
 *
 * <p>
 * The following request parameters will be populated from the data of this
 * <code>KeyPair</code> resource, and any conflicting parameter value set in
 * the request will be overridden:
 * <ul>
 *   <li>
 *     <b><code>KeyName</code></b>
 *         - mapped from the <code>Name</code> identifier.
 *   </li>
 * </ul>
 *
 * <p>
 *
 * @see DeleteKeyPairRequest
 */
void delete(DeleteKeyPairRequest request, ResultCapture<Void> extractor);