use of com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus in project cloudbreak by hortonworks.
the class GcpCredentialConnectorTest method testForFailedStatusBecauseMissingCompute.
/**
* Testing the GcpContext checking mechanism. If the inner created
* GcpContext does not contains a valid Compute instance then a FAILED
* status should come back.
*/
@Test
public void testForFailedStatusBecauseMissingCompute() {
final AuthenticatedContext authContext = createAuthContext();
when(contextBuilder.contextInit(authContext.getCloudContext(), authContext, null, null, false)).thenReturn(context);
when(context.getProjectId()).thenReturn("some id");
when(context.getServiceAccountId()).thenReturn("some service id");
when(context.getCompute()).thenReturn(null);
final CloudCredentialStatus status = underTest.verify(authContext);
Assert.assertNotNull("The returned CloudCredentialStatus instance is null!", status);
Assert.assertEquals("Invalid credential status has specified!", CredentialStatus.FAILED, status.getStatus());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus in project cloudbreak by hortonworks.
the class GcpCredentialConnectorTest method testForNullExceptionOnVerifyPermissionCheck.
/**
* Test that if some exception terminates the credential check operation,
* or the checked credential is not valid. If that so, than the expected
* CredentialStatus should be FAILED.
*
* @throws IOException this exception could thrown by the credential
* checker method.
*/
@Test
public void testForNullExceptionOnVerifyPermissionCheck() throws IOException {
final AuthenticatedContext authContext = createAuthContext();
final String expectionReasonMessage = "exception message";
when(contextBuilder.contextInit(authContext.getCloudContext(), authContext, null, null, false)).thenReturn(context);
when(context.getProjectId()).thenReturn("some id");
when(context.getServiceAccountId()).thenReturn("some service id");
when(context.getCompute().regions().list(anyString()).executeUsingHead()).thenThrow(new BadRequestException(expectionReasonMessage));
final CloudCredentialStatus status = underTest.verify(authContext);
Assert.assertNotNull("The returned CloudCredentialStatus instance is null!", status);
Assert.assertEquals("Invalid credential status has specified!", CredentialStatus.FAILED, status.getStatus());
Assert.assertTrue("Not the specified exception has come with the status", status.getException() instanceof BadRequestException);
Assert.assertEquals("Not the expected exception message has come with the status", expectionReasonMessage, status.getException().getMessage());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus in project cloudbreak by hortonworks.
the class GcpCredentialConnectorTest method testPassingVerifyPermissionCheck.
/**
* Test that if the credential authentication has passed, the returned
* CredentialStatus is VERIFIED.
*
* @throws IOException this exception could thrown by the credential
* checker method.
*/
@Test
public void testPassingVerifyPermissionCheck() throws IOException {
final AuthenticatedContext authContext = createAuthContext();
when(contextBuilder.contextInit(authContext.getCloudContext(), authContext, null, null, false)).thenReturn(context);
when(context.getProjectId()).thenReturn("some id");
when(context.getServiceAccountId()).thenReturn("some service id");
final CloudCredentialStatus status = underTest.verify(authContext);
Assert.assertNotNull("The returned CloudCredentialStatus instance is null!", status);
Assert.assertEquals("Invalid credential status has specified!", CredentialStatus.VERIFIED, status.getStatus());
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus in project cloudbreak by hortonworks.
the class GcpCredentialConnector method verify.
@Override
public CloudCredentialStatus verify(@Nonnull AuthenticatedContext authenticatedContext) {
Objects.requireNonNull(authenticatedContext);
LOGGER.info("Verify credential: {}", authenticatedContext.getCloudCredential());
GcpContext gcpContext = gcpContextBuilder.contextInit(authenticatedContext.getCloudContext(), authenticatedContext, null, null, false);
try {
checkGcpContextValidity(gcpContext);
preCheckOfGooglePermission(gcpContext);
} catch (TokenResponseException te) {
return createFailedCloudCredentialStatusWithExc(te, authenticatedContext, getErrDescriptionFromTokenResponse(te));
} catch (Exception e) {
return createFailedCloudCredentialStatusWithExc(e, authenticatedContext, Optional.empty());
}
return new CloudCredentialStatus(authenticatedContext.getCloudCredential(), CredentialStatus.VERIFIED);
}
use of com.sequenceiq.cloudbreak.cloud.model.CloudCredentialStatus in project cloudbreak by hortonworks.
the class CreateCredentialHandler method accept.
@Override
public void accept(Event<CreateCredentialRequest> credentialRequestEvent) {
LOGGER.info("Received event: {}", credentialRequestEvent);
CreateCredentialRequest request = credentialRequestEvent.getData();
CloudContext cloudContext = request.getCloudContext();
try {
CloudConnector connector = cloudPlatformConnectors.get(cloudContext.getPlatformVariant());
AuthenticatedContext ac = connector.authentication().authenticate(cloudContext, request.getCloudCredential());
CloudCredentialStatus credentialStatus = connector.credentials().create(ac);
if (CredentialStatus.FAILED == credentialStatus.getStatus()) {
if (credentialStatus.getException() != null) {
throw new CloudConnectorException(credentialStatus.getException());
}
throw new CloudConnectorException(credentialStatus.getStatusReason());
}
CreateCredentialResult result = new CreateCredentialResult(request);
request.getResult().onNext(result);
eventBus.notify(result.selector(), new Event<>(credentialRequestEvent.getHeaders(), result));
LOGGER.info("Creating credential successfully finished for {}", cloudContext);
} catch (RuntimeException e) {
CreateCredentialResult failure = new CreateCredentialResult(e, request);
request.getResult().onNext(failure);
eventBus.notify(failure.selector(), new Event<>(credentialRequestEvent.getHeaders(), failure));
}
}
Aggregations