Search in sources :

Example 6 with ObjectStorageValidateRequest

use of com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateRequest in project cloudbreak by hortonworks.

the class CloudStorageValidator method validate.

public void validate(CloudStorageRequest cloudStorageRequest, DetailedEnvironmentResponse environment, ValidationResult.ValidationResultBuilder validationResultBuilder) {
    if (CloudStorageValidation.DISABLED.equals(environment.getCloudStorageValidation())) {
        LOGGER.info("Due to cloud storage validation not being enabled, not validating cloudStorageRequest: {}", JsonUtil.writeValueAsStringSilent(cloudStorageRequest));
        return;
    }
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    if (!entitlementService.cloudStorageValidationEnabled(accountId)) {
        LOGGER.info("Cloud storage validation entitlement is missing, not validating cloudStorageRequest: {}", JsonUtil.writeValueAsStringSilent(cloudStorageRequest));
        return;
    }
    LOGGER.info("Validating cloudStorageRequest: {}", JsonUtil.writeValueAsStringSilent(cloudStorageRequest));
    if (cloudStorageRequest != null) {
        Credential credential = getCredential(environment);
        CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(credential);
        ObjectStorageValidateRequest request = createObjectStorageValidateRequest(cloudCredential, cloudStorageRequest, environment);
        ObjectStorageValidateResponse response = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> cloudProviderServicesV4Endpoint.validateObjectStorage(request));
        LOGGER.info("ValidateObjectStorage: request: {}, response: {}", AnonymizerUtil.anonymize(JsonUtil.writeValueAsStringSilent(request)), JsonUtil.writeValueAsStringSilent(response));
        if (ResponseStatus.ERROR.equals(response.getStatus())) {
            validationResultBuilder.error(response.getError());
        } else if (StringUtils.isNotBlank(response.getError())) {
            validationResultBuilder.warning(response.getError());
        }
    }
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.datalake.entity.Credential) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) ObjectStorageValidateResponse(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateResponse) ObjectStorageValidateRequest(com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateRequest)

Aggregations

ObjectStorageValidateRequest (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateRequest)6 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)4 ObjectStorageValidateResponse (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageValidateResponse)3 Credential (com.sequenceiq.environment.credential.domain.Credential)3 Json (com.sequenceiq.cloudbreak.common.json.Json)2 CloudStorageRequest (com.sequenceiq.common.api.cloudstorage.CloudStorageRequest)2 TelemetryRequest (com.sequenceiq.common.api.telemetry.request.TelemetryRequest)2 EnvironmentCloudStorageValidationRequest (com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentCloudStorageValidationRequest)2 Test (org.junit.jupiter.api.Test)2 AccountMappingBase (com.sequenceiq.common.api.cloudstorage.AccountMappingBase)1 StorageIdentityBase (com.sequenceiq.common.api.cloudstorage.StorageIdentityBase)1 S3CloudStorageV1Parameters (com.sequenceiq.common.api.cloudstorage.old.S3CloudStorageV1Parameters)1 LoggingRequest (com.sequenceiq.common.api.telemetry.request.LoggingRequest)1 Credential (com.sequenceiq.datalake.entity.Credential)1 CredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)1 SdxCloudStorageRequest (com.sequenceiq.sdx.api.model.SdxCloudStorageRequest)1