use of com.sequenceiq.common.api.cloudstorage.StorageLocationBase in project cloudbreak by hortonworks.
the class AwsRangerAuditRolePermissionValidatorTest method testGetPolicyJsonReplacementsNoDynamodb.
@Test
@Override
public void testGetPolicyJsonReplacementsNoDynamodb() {
String storageLocationBaseStr = "bucket/cluster";
String bucket = "bucket";
Map<String, String> expectedPolicyJsonReplacements = Map.ofEntries(Map.entry("${ARN_PARTITION}", "aws"), Map.entry("${STORAGE_LOCATION_BASE}", storageLocationBaseStr), Map.entry("${DATALAKE_BUCKET}", bucket), Map.entry("${DYNAMODB_TABLE_NAME}", ""));
StorageLocationBase storageLocationBase = new StorageLocationBase();
storageLocationBase.setValue(storageLocationBaseStr);
CloudS3View cloudFileSystem = new CloudS3View(CloudIdentityType.ID_BROKER);
cloudFileSystem.setInstanceProfile("arn:aws:iam::11111111111:instance-profile/instanceprofile");
Map<String, String> policyJsonReplacements = awsRangerAuditRolePermissionValidator.getPolicyJsonReplacements(storageLocationBase, cloudFileSystem);
assertThat(policyJsonReplacements).isEqualTo(expectedPolicyJsonReplacements);
}
use of com.sequenceiq.common.api.cloudstorage.StorageLocationBase in project cloudbreak by hortonworks.
the class AwsRangerAuditRolePermissionValidatorTest method testCheckLocation.
@Test
@Override
public void testCheckLocation() {
assertThat(awsRangerAuditRolePermissionValidator.checkLocation(new StorageLocationBase())).isFalse();
StorageLocationBase nonRangerAuditLocation = new StorageLocationBase();
nonRangerAuditLocation.setType(CloudStorageCdpService.HBASE_ROOT);
assertThat(awsRangerAuditRolePermissionValidator.checkLocation(nonRangerAuditLocation)).isFalse();
StorageLocationBase rangerAuditLocation = new StorageLocationBase();
rangerAuditLocation.setType(CloudStorageCdpService.RANGER_AUDIT);
assertThat(awsRangerAuditRolePermissionValidator.checkLocation(rangerAuditLocation)).isTrue();
}
use of com.sequenceiq.common.api.cloudstorage.StorageLocationBase in project cloudbreak by hortonworks.
the class GcpObjectStorageConnector method validateObjectStorage.
@Override
public ObjectStorageValidateResponse validateObjectStorage(ObjectStorageValidateRequest request) {
String accountId = Crn.safeFromString(request.getCredential().getId()).getAccountId();
if (!entitlementService.gcpCloudStorageValidationEnabled(accountId)) {
LOGGER.info("Gcp Cloud storage validation entitlement is missing, not validating cloudStorageRequest: {}", JsonUtil.writeValueAsStringSilent(request));
return ObjectStorageValidateResponse.builder().withStatus(ResponseStatus.OK).build();
}
Storage storage = gcpStorageFactory.buildStorage(request.getCredential(), request.getCredential().getName());
ValidationResult.ValidationResultBuilder resultBuilder = new ValidationResult.ValidationResultBuilder();
for (StorageLocationBase location : request.getCloudStorageRequest().getLocations()) {
String bucketName = gcpStackUtil.getBucketName(location.getValue());
try {
storage.buckets().get(bucketName).execute();
} catch (Exception e) {
String message = String.format("The specified bucket with %s name does not exist", bucketName);
LOGGER.debug(message + ":" + e.getMessage());
resultBuilder.error(message);
}
}
SpiFileSystem spiFileSystem = request.getSpiFileSystem();
try {
resultBuilder = gcpServiceAccountObjectStorageValidator.validateObjectStorage(request.getCredential(), spiFileSystem, resultBuilder);
} catch (Exception e) {
LOGGER.debug(e.getMessage());
resultBuilder.error(e.getMessage());
}
ValidationResult validationResult = resultBuilder.build();
if (validationResult.hasError()) {
return ObjectStorageValidateResponse.builder().withStatus(ResponseStatus.ERROR).withError(validationResult.getFormattedErrors()).build();
}
return ObjectStorageValidateResponse.builder().withStatus(ResponseStatus.OK).build();
}
use of com.sequenceiq.common.api.cloudstorage.StorageLocationBase in project cloudbreak by hortonworks.
the class AzureAdlsGen2Tests method adlsGen2CloudStorageV4RequestWithoutStorageLocations.
private CloudStorageRequest adlsGen2CloudStorageV4RequestWithoutStorageLocations() {
CloudStorageRequest request = new CloudStorageRequest();
AdlsGen2CloudStorageV1Parameters adlsGen2 = new AdlsGen2CloudStorageV1Parameters();
String accountName = azureProperties.getCloudStorage().getAccountName();
String accountKey = azureProperties.getCloudStorage().getAccountKey();
adlsGen2.setAccountKey(accountKey);
adlsGen2.setAccountName(accountName);
StorageLocationBase storageLocationBase = new StorageLocationBase();
storageLocationBase.setType(CloudStorageCdpService.RANGER_AUDIT);
storageLocationBase.setValue("somePath");
request.setLocations(List.of(storageLocationBase));
StorageIdentityBase storageIdentityBase = new StorageIdentityBase();
storageIdentityBase.setAdlsGen2(adlsGen2);
request.setIdentities(List.of(storageIdentityBase));
return request;
}
Aggregations