use of com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse 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()));
}
}
use of com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse in project cloudbreak by hortonworks.
the class CredentialToCredentialV1ResponseConverter method convert.
public CredentialResponse convert(Credential source) {
CredentialResponse response = new CredentialResponse();
credentialValidator.validateCredentialCloudPlatform(source.getCloudPlatform(), source.getCreator(), source.getType());
response.setCloudPlatform(source.getCloudPlatform());
response.setName(source.getName());
response.setVerifyPermissions(source.isVerifyPermissions());
response.setVerificationStatusText(source.getVerificationStatusText());
if (source.getAttributes() != null) {
convertAttributes(source, response);
if (response.getAws() != null) {
response.getAws().setGovCloud(source.getGovCloud());
}
response.setAttributes(secretConverter.convert(source.getAttributesSecret()));
}
response.setCrn(source.getResourceCrn());
response.setCreator(source.getCreator());
response.setCreated(source.getCreated());
response.setDescription(source.getDescription() == null ? "" : source.getDescription());
response.setType(source.getType());
response.setGovCloud(source.getGovCloud());
response.setAccountId(source.getAccountId());
return response;
}
use of com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse in project cloudbreak by hortonworks.
the class SdxRecommendationServiceTest method createEnvironment.
private DetailedEnvironmentResponse createEnvironment(String cloudPlatform) {
DetailedEnvironmentResponse environment = new DetailedEnvironmentResponse();
CredentialResponse credential = new CredentialResponse();
credential.setCrn("cred");
environment.setCredential(credential);
CompactRegionResponse regions = new CompactRegionResponse();
regions.setNames(List.of("eu-central-1"));
environment.setRegions(regions);
environment.setCloudPlatform(cloudPlatform);
return environment;
}
use of com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse in project cloudbreak by hortonworks.
the class StorageValidationService method validateObjectStorage.
public ObjectStorageValidateResponse validateObjectStorage(String credentialCrn, SdxCloudStorageRequest sdxCloudStorageRequest, String blueprintName, String clusterName, String dataAccessRole, String rangerAuditRole) {
CredentialResponse credentialResponse = environmentClientService.getCredentialByCrn(credentialCrn);
String attributes = secretService.getByResponse(credentialResponse.getAttributes());
CloudCredential cloudCredential = new CloudCredential(credentialResponse.getCrn(), credentialResponse.getName(), new Json(attributes).getMap(), credentialResponse.getAccountId(), credentialResponse.isVerifyPermissions());
CloudStorageRequest cloudStorageRequest = cloudStorageManifester.initSdxCloudStorageRequest(credentialResponse.getCloudPlatform(), blueprintName, clusterName, sdxCloudStorageRequest);
AccountMappingBase accountMapping = new AccountMappingBase();
Map<String, String> userMapping = getUserMapping(dataAccessRole, rangerAuditRole);
accountMapping.setUserMappings(userMapping);
cloudStorageRequest.setAccountMapping(accountMapping);
ObjectStorageValidateRequest objectStorageValidateRequest = ObjectStorageValidateRequest.builder().withCloudPlatform(credentialResponse.getCloudPlatform()).withCredential(cloudCredential).withCloudStorageRequest(cloudStorageRequest).build();
return ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> cloudProviderServicesV4Endpoint.validateObjectStorage(objectStorageValidateRequest));
}
use of com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse in project cloudbreak by hortonworks.
the class EnvironmentServiceIntegrationTest method testCredentialDeleteByName.
@Test
public void testCredentialDeleteByName() {
credentialRepository.save(credential);
CredentialResponse results = client.credentialV1Endpoint().deleteByName(credential.getName());
assertTrue(results.getName().startsWith(credential.getName()), String.format("Result should have credential with name: %s", credential.getName()));
}
Aggregations