use of com.sequenceiq.datalake.entity.Credential 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());
}
}
}
use of com.sequenceiq.datalake.entity.Credential in project cloudbreak by hortonworks.
the class CloudStorageLocationValidator method validate.
public void validate(String storageLocation, FileSystemType fileSystemType, DetailedEnvironmentResponse environment, ValidationResultBuilder resultBuilder) {
String bucketName = getBucketName(fileSystemType, storageLocation);
Credential credential = getCredential(environment);
CloudCredential cloudCredential = credentialToCloudCredentialConverter.convert(credential);
ObjectStorageMetadataRequest request = createObjectStorageMetadataRequest(environment.getCloudPlatform(), cloudCredential, bucketName);
ObjectStorageMetadataResponse response = ThreadBasedUserCrnProvider.doAsInternalActor(regionAwareInternalCrnGeneratorFactory.iam().getInternalCrnForServiceAsString(), () -> cloudProviderServicesV4Endopint.getObjectStorageMetaData(request));
resultBuilder.ifError(() -> response.getStatus() == ResponseStatus.OK && !environment.getLocation().getName().equals(response.getRegion()), String.format("Object storage location [%s] of bucket '%s' must match environment location [%s]", response.getRegion(), bucketName, environment.getLocation().getName()));
}
Aggregations