Search in sources :

Example 31 with StorageLocationBase

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);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudS3View(com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudS3View) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase) Test(org.junit.jupiter.api.Test)

Example 32 with StorageLocationBase

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();
}
Also used : StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase) Test(org.junit.jupiter.api.Test)

Example 33 with StorageLocationBase

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();
}
Also used : Storage(com.google.api.services.storage.Storage) SpiFileSystem(com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase)

Example 34 with StorageLocationBase

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;
}
Also used : CloudStorageRequest(com.sequenceiq.common.api.cloudstorage.CloudStorageRequest) AdlsGen2CloudStorageV1Parameters(com.sequenceiq.common.api.cloudstorage.old.AdlsGen2CloudStorageV1Parameters) StorageLocationBase(com.sequenceiq.common.api.cloudstorage.StorageLocationBase) StorageIdentityBase(com.sequenceiq.common.api.cloudstorage.StorageIdentityBase)

Aggregations

StorageLocationBase (com.sequenceiq.common.api.cloudstorage.StorageLocationBase)34 CloudStorageRequest (com.sequenceiq.common.api.cloudstorage.CloudStorageRequest)19 Test (org.junit.jupiter.api.Test)19 CloudStorageCdpService (com.sequenceiq.common.model.CloudStorageCdpService)10 StorageIdentityBase (com.sequenceiq.common.api.cloudstorage.StorageIdentityBase)9 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)9 ArrayList (java.util.ArrayList)9 CloudS3View (com.sequenceiq.cloudbreak.cloud.model.filesystem.CloudS3View)7 LoggingResponse (com.sequenceiq.common.api.telemetry.response.LoggingResponse)7 FileSystemType (com.sequenceiq.common.model.FileSystemType)7 List (java.util.List)7 ConfigQueryEntry (com.sequenceiq.common.api.cloudstorage.query.ConfigQueryEntry)6 TelemetryResponse (com.sequenceiq.common.api.telemetry.response.TelemetryResponse)6 CloudIdentityType (com.sequenceiq.common.model.CloudIdentityType)6 LinkedHashSet (java.util.LinkedHashSet)6 ClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request)5 S3CloudStorageV1Parameters (com.sequenceiq.common.api.cloudstorage.old.S3CloudStorageV1Parameters)5 SdxCloudStorageRequest (com.sequenceiq.sdx.api.model.SdxCloudStorageRequest)5 SdxClusterRequest (com.sequenceiq.sdx.api.model.SdxClusterRequest)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)5