use of com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem in project cloudbreak by hortonworks.
the class AzureIDBrokerObjectStorageValidatorTest method testValidateObjectStorageNonExistingMapperIdentity.
@Test
public void testValidateObjectStorageNonExistingMapperIdentity() {
SpiFileSystem fileSystem = setupSpiFileSystem(true);
PagedList<Identity> identityPagedList = Mockito.spy(PagedList.class);
identityPagedList.add(assumer);
identityPagedList.add(logger);
when(client.listIdentities()).thenReturn(identityPagedList);
new RoleASsignmentBuilder(client).withAssignment(ASSUMER_IDENTITY_PRINCIPAL_ID, SUBSCRIPTION_FULL_ID).withAssignment(LOG_IDENTITY_PRINCIPAL_ID, STORAGE_RESOURCE_GROUP_NAME);
ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
underTest.validateObjectStorage(client, fileSystem, STORAGE_LOCATION_RANGER, null, null, resultBuilder);
ValidationResult validationResult = resultBuilder.build();
assertTrue(validationResult.hasError());
assertEquals(2, validationResult.getErrors().size());
List<String> actual = validationResult.getErrors();
assertTrue(actual.stream().anyMatch(item -> item.contains(String.format("Identity with id %s does not exist in the given Azure subscription.", USER_IDENTITY_1))));
assertTrue(actual.stream().anyMatch(item -> item.contains(String.format("Identity with id %s does not exist in the given Azure subscription.", GROUP_IDENTITY_1))));
}
use of com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem in project cloudbreak by hortonworks.
the class AzureIDBrokerObjectStorageValidatorTest method testValidateObjectStorageWithoutFileSystems.
@Test
public void testValidateObjectStorageWithoutFileSystems() {
SpiFileSystem fileSystem = new SpiFileSystem("test", FileSystemType.ADLS_GEN_2, null);
ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
underTest.validateObjectStorage(client, fileSystem, "", null, null, resultBuilder);
assertFalse(resultBuilder.build().hasError());
}
use of com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem in project cloudbreak by hortonworks.
the class AzureIDBrokerObjectStorageValidatorTest method testValidateObjectStorageWithNoStorageAccount.
@Test
public void testValidateObjectStorageWithNoStorageAccount() {
SpiFileSystem fileSystem = setupSpiFileSystem(false);
new RoleASsignmentBuilder(client).withAssignment(ASSUMER_IDENTITY_PRINCIPAL_ID, SUBSCRIPTION_FULL_ID).withAssignment(LOG_IDENTITY_PRINCIPAL_ID, STORAGE_RESOURCE_GROUP_NAME);
when(azureStorage.findStorageAccountIdInVisibleSubscriptions(any(), anyString())).thenReturn(Optional.empty());
ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
underTest.validateObjectStorage(client, fileSystem, "", null, null, resultBuilder);
ValidationResult validationResult = resultBuilder.build();
assertTrue(validationResult.hasError());
assertEquals(1, validationResult.getErrors().size());
String actual = validationResult.getErrors().get(0);
assertEquals(actual, String.format("Storage account with name %s not found in the given Azure subscription. " + "Please check if you've used the correct Storage Location when setting up Data Access.", ABFS_STORAGE_ACCOUNT_NAME));
}
use of com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem in project cloudbreak by hortonworks.
the class AzureIDBrokerObjectStorageValidatorTest method testValidateObjectStorageWithNoSubscriptionScopeRoleAssignment.
@Test
public void testValidateObjectStorageWithNoSubscriptionScopeRoleAssignment() {
SpiFileSystem fileSystem = setupSpiFileSystem(false);
new RoleASsignmentBuilder(client).withAssignment(LOG_IDENTITY_PRINCIPAL_ID, STORAGE_RESOURCE_GROUP_NAME);
ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
underTest.validateObjectStorage(client, fileSystem, "", null, null, resultBuilder);
ValidationResult validationResult = resultBuilder.build();
assertTrue(validationResult.hasError());
assertEquals(2, validationResult.getErrors().size());
assertEquals(validationResult.getErrors().get(1), String.format("Identity with id %s has no role assignment. " + "Please check if you've used the correct Identity when setting up Data Access.", ASSUMER_IDENTITY));
assertEquals(validationResult.getErrors().get(0), String.format("Identity with id %s has no role assignment on scope(s) [/subscriptions/%s]. " + "Please check if you've used the correct Identity when setting up Data Access.", ASSUMER_IDENTITY, SUBSCRIPTION_ID));
}
use of com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem 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();
}
Aggregations