Search in sources :

Example 1 with PublicKeyUnregisterRequest

use of com.sequenceiq.cloudbreak.cloud.model.publickey.PublicKeyUnregisterRequest in project cloudbreak by hortonworks.

the class EnvironmentResourceService method deletePublicKey.

public void deletePublicKey(Environment environment, String publicKeyId) {
    try {
        LOGGER.info("Try to delete the ssh key ({}) for {}", publicKeyId, environment.getName());
        PublicKeyConnector publicKeyConnector = getPublicKeyConnector(environment.getCloudPlatform()).orElseThrow(() -> new BadRequestException("No public key connector for cloud platform: " + environment.getCloudPlatform()));
        PublicKeyUnregisterRequest request = createPublicKeyUnregisterRequest(environment, publicKeyId);
        publicKeyConnector.unregister(request);
        LOGGER.info("the ssh key ({}) deleted successfully for {}", publicKeyId, environment.getName());
    } catch (UnsupportedOperationException e) {
        LOGGER.info("Cloud platform {} does not support public key services", environment.getCloudPlatform());
    }
}
Also used : PublicKeyUnregisterRequest(com.sequenceiq.cloudbreak.cloud.model.publickey.PublicKeyUnregisterRequest) BadRequestException(javax.ws.rs.BadRequestException) PublicKeyConnector(com.sequenceiq.cloudbreak.cloud.PublicKeyConnector)

Example 2 with PublicKeyUnregisterRequest

use of com.sequenceiq.cloudbreak.cloud.model.publickey.PublicKeyUnregisterRequest in project cloudbreak by hortonworks.

the class AwsPublicKeyConnectorTest method unregisterNotFoundDoesNotThrow.

@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);
}
Also used : PublicKeyUnregisterRequest(com.sequenceiq.cloudbreak.cloud.model.publickey.PublicKeyUnregisterRequest) AmazonServiceException(com.amazonaws.AmazonServiceException) DeleteKeyPairRequest(com.amazonaws.services.ec2.model.DeleteKeyPairRequest) Test(org.junit.jupiter.api.Test)

Example 3 with PublicKeyUnregisterRequest

use of com.sequenceiq.cloudbreak.cloud.model.publickey.PublicKeyUnregisterRequest in project cloudbreak by hortonworks.

the class AwsPublicKeyConnectorTest method unregister.

@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);
}
Also used : PublicKeyUnregisterRequest(com.sequenceiq.cloudbreak.cloud.model.publickey.PublicKeyUnregisterRequest) DeleteKeyPairRequest(com.amazonaws.services.ec2.model.DeleteKeyPairRequest) Test(org.junit.jupiter.api.Test)

Aggregations

PublicKeyUnregisterRequest (com.sequenceiq.cloudbreak.cloud.model.publickey.PublicKeyUnregisterRequest)3 DeleteKeyPairRequest (com.amazonaws.services.ec2.model.DeleteKeyPairRequest)2 Test (org.junit.jupiter.api.Test)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 PublicKeyConnector (com.sequenceiq.cloudbreak.cloud.PublicKeyConnector)1 BadRequestException (javax.ws.rs.BadRequestException)1