Search in sources :

Example 11 with CredentialResponse

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()));
    }
}
Also used : CredentialToCredentialV1ResponseConverter(com.sequenceiq.environment.credential.v1.converter.CredentialToCredentialV1ResponseConverter) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CredentialService(com.sequenceiq.environment.credential.service.CredentialService) Credential(com.sequenceiq.environment.credential.domain.Credential) AUDIT(com.sequenceiq.common.model.CredentialType.AUDIT) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Set(java.util.Set) CredentialDeleteService(com.sequenceiq.environment.credential.service.CredentialDeleteService) Controller(org.springframework.stereotype.Controller) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount) Collectors(java.util.stream.Collectors) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) Valid(javax.validation.Valid) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) AccountId(com.sequenceiq.cloudbreak.auth.security.internal.AccountId) CredentialRequest(com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest) CredentialPrerequisitesResponse(com.sequenceiq.cloudbreak.cloud.response.CredentialPrerequisitesResponse) NotificationController(com.sequenceiq.notification.NotificationController) EditCredentialRequest(com.sequenceiq.environment.api.v1.credential.model.request.EditCredentialRequest) AuthorizationResourceAction(com.sequenceiq.authorization.resource.AuthorizationResourceAction) TenantAwareParam(com.sequenceiq.cloudbreak.auth.security.internal.TenantAwareParam) AuditCredentialEndpoint(com.sequenceiq.environment.api.v1.credential.endpoint.AuditCredentialEndpoint) CredentialResponses(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponses) Credential(com.sequenceiq.environment.credential.domain.Credential) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount)

Example 12 with CredentialResponse

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;
}
Also used : CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)

Example 13 with CredentialResponse

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;
}
Also used : CompactRegionResponse(com.sequenceiq.environment.api.v1.environment.model.response.CompactRegionResponse) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)

Example 14 with CredentialResponse

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));
}
Also used : AccountMappingBase(com.sequenceiq.common.api.cloudstorage.AccountMappingBase) CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) SdxCloudStorageRequest(com.sequenceiq.sdx.api.model.SdxCloudStorageRequest) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) Json(com.sequenceiq.cloudbreak.common.json.Json) ObjectStorageValidateRequest(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateRequest)

Example 15 with CredentialResponse

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()));
}
Also used : CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) InteractiveCredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.InteractiveCredentialResponse) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

CredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)29 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)12 Test (org.junit.jupiter.api.Test)10 InteractiveCredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.InteractiveCredentialResponse)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)5 CompactRegionResponse (com.sequenceiq.environment.api.v1.environment.model.response.CompactRegionResponse)5 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)4 EnvironmentNetworkResponse (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse)4 BadRequestException (javax.ws.rs.BadRequestException)4 NameOrCrn (com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn)3 StackViewV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackViewV4Response)3 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)3 Before (org.junit.Before)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)2 Json (com.sequenceiq.cloudbreak.common.json.Json)2 Credential (com.sequenceiq.cloudbreak.dto.credential.Credential)2 SecretResponse (com.sequenceiq.cloudbreak.service.secret.model.SecretResponse)2 BackupResponse (com.sequenceiq.common.api.backup.response.BackupResponse)2