use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class CredentialService method getCredentialAndValidateUpdate.
private Credential getCredentialAndValidateUpdate(Credential credential, String accountId, CredentialType type) {
Credential original = repository.findByNameAndAccountId(credential.getName(), accountId, getEnabledPlatforms(), type).orElseThrow(notFound(NOT_FOUND_FORMAT_MESS_NAME, credential.getName()));
ValidationResult validationResult = credentialValidator.validateCredentialUpdate(original, credential, type);
if (validationResult.hasError()) {
throw new BadRequestException(validationResult.getFormattedErrors());
}
return original;
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class CredentialService method initCodeGrantFlow.
public String initCodeGrantFlow(String accountId, String name) {
Credential original = repository.findByNameAndAccountId(name, accountId, getEnabledPlatforms(), ENVIRONMENT).orElseThrow(notFound(NOT_FOUND_FORMAT_MESS_NAME, name));
String originalAttributes = original.getAttributes();
if (getAzureCodeGrantFlowAttributes(original) == null) {
throw new UnsupportedOperationException("This operation is only allowed on Authorization Code Grant flow based credentails.");
}
Credential updated = credentialAdapter.initCodeGrantFlow(original, accountId);
updated = repository.save(updated);
secretService.delete(originalAttributes);
return getCodeGrantFlowAppLoginUrl(updated);
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class CredentialService method create.
public Credential create(Credential credential, @Nonnull String accountId, @Nonnull String creatorUserCrn, CredentialType type) {
repository.findByNameAndAccountId(credential.getName(), accountId, getEnabledPlatforms(), type).map(Credential::getName).ifPresent(name -> {
throw new BadRequestException("Credential already exists with name: " + name);
});
LOGGER.debug("Validating credential for cloudPlatform {} and creator {}.", credential.getCloudPlatform(), creatorUserCrn);
credentialValidator.validateCredentialCloudPlatform(credential.getCloudPlatform(), creatorUserCrn, type);
LOGGER.debug("Validating credential parameters for cloudPlatform {} and creator {}.", credential.getCloudPlatform(), creatorUserCrn);
credentialValidator.validateParameters(Platform.platform(credential.getCloudPlatform()), new Json(credential.getAttributes()));
String credentialCrn = createCRN(accountId);
credential.setResourceCrn(credentialCrn);
credential.setCreator(creatorUserCrn);
credential.setAccountId(accountId);
Credential verifiedCredential = credentialAdapter.verify(credential, accountId, Boolean.TRUE).getCredential();
if (verifiedCredential.getVerificationStatusText() != null) {
throw new BadRequestException(verifiedCredential.getVerificationStatusText());
}
try {
Credential createdCredential = transactionService.required(() -> {
Credential created = repository.save(verifiedCredential);
ownerAssignmentService.assignResourceOwnerRoleIfEntitled(creatorUserCrn, credentialCrn, accountId);
return created;
});
sendCredentialNotification(createdCredential, ResourceEvent.CREDENTIAL_CREATED);
return createdCredential;
} catch (TransactionService.TransactionExecutionException e) {
LOGGER.error("Error happened during credential creation: ", e);
throw new InternalServerErrorException(e);
}
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method changeCredentialByEnvironmentCrn.
@Test
void changeCredentialByEnvironmentCrn() {
String credentialName = "credentialName";
final Credential value = new Credential();
EnvironmentChangeCredentialDto environmentChangeDto = EnvironmentChangeCredentialDto.EnvironmentChangeCredentialDtoBuilder.anEnvironmentChangeCredentialDto().withCredentialName(credentialName).build();
when(environmentService.findByResourceCrnAndAccountIdAndArchivedIsFalse(eq(CRN), eq(ACCOUNT_ID))).thenReturn(Optional.of(new Environment()));
when(credentialService.getByNameForAccountId(eq(credentialName), eq(ACCOUNT_ID), eq(ENVIRONMENT))).thenReturn(value);
environmentModificationServiceUnderTest.changeCredentialByEnvironmentCrn(ACCOUNT_ID, CRN, environmentChangeDto);
ArgumentCaptor<Environment> environmentArgumentCaptor = ArgumentCaptor.forClass(Environment.class);
verify(environmentService).save(environmentArgumentCaptor.capture());
assertEquals(value, environmentArgumentCaptor.getValue().getCredential());
}
use of com.sequenceiq.environment.credential.domain.Credential in project cloudbreak by hortonworks.
the class EnvironmentTestData method newCredential.
private static Credential newCredential() {
Credential credential = new Credential();
credential.setResourceCrn(CREDENTIAL_CRN);
return credential;
}
Aggregations