use of com.sequenceiq.common.model.CredentialType.AUDIT in project cloudbreak by hortonworks.
the class AuditCredentialV1Controller method post.
@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.CREATE_AUDIT_CREDENTIAL)
public CredentialResponse post(@Valid CredentialRequest request) {
String accountId = ThreadBasedUserCrnProvider.getAccountId();
String creator = ThreadBasedUserCrnProvider.getUserCrn();
Credential credential = credentialConverter.convert(request);
credential.setType(AUDIT);
credential.setVerifyPermissions(false);
notify(ResourceEvent.CREDENTIAL_CREATED);
Set<Credential> auditCredentialsByPlatfom = credentialService.listAvailablesByAccountId(accountId, AUDIT).stream().filter(c -> c.getCloudPlatform().equals(credential.getCloudPlatform())).collect(Collectors.toSet());
if (auditCredentialsByPlatfom.isEmpty()) {
return credentialConverter.convert(credentialService.create(credential, accountId, creator, AUDIT));
} else {
throw new BadRequestException(String.format("Audit credential already exist for %s cloud.", credential.getCloudPlatform()));
}
}
Aggregations