@Test public void validateEnvironmentRequestCloudStorageValidationNoEntitlement() { CloudStorageRequest cloudStorageRequest = new CloudStorageRequest(); when(environment.getCloudStorageValidation()).thenReturn(CloudStorageValidation.ENABLED); when(entitlementService.cloudStorageValidationEnabled(any(), any())).thenReturn(false); ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder(); underTest.validate(cloudStorageRequest, environment, validationResultBuilder); assertFalse(validationResultBuilder.build().hasError()); }
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(INTERNAL_ACTOR_CRN, 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( environment.getCloudPlatform(), cloudCredential, cloudStorageRequest); ObjectStorageValidateResponse response = ThreadBasedUserCrnProvider.doAsInternalActor(() -> cloudProviderServicesV4Endpoint.validateObjectStorage(request)); LOGGER.info("ValidateObjectStorage: request: {}, response: {}", JsonUtil.writeValueAsStringSilent(request), JsonUtil.writeValueAsStringSilent(response)); if (ResponseStatus.ERROR.equals(response.getStatus())) { validationResultBuilder.error(response.getError()); throw new BadRequestException(response.getError()); } } }
CloudStorageValidator { 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(INTERNAL_ACTOR_CRN, 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( environment.getCloudPlatform(), cloudCredential, cloudStorageRequest); ObjectStorageValidateResponse response = ThreadBasedUserCrnProvider.doAsInternalActor(() -> cloudProviderServicesV4Endpoint.validateObjectStorage(request)); LOGGER.info("ValidateObjectStorage: request: {}, response: {}", JsonUtil.writeValueAsStringSilent(request), JsonUtil.writeValueAsStringSilent(response)); if (ResponseStatus.ERROR.equals(response.getStatus())) { validationResultBuilder.error(response.getError()); throw new BadRequestException(response.getError()); } } } }
CloudStorageValidator { 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(INTERNAL_ACTOR_CRN, 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( environment.getCloudPlatform(), cloudCredential, cloudStorageRequest); ObjectStorageValidateResponse response = ThreadBasedUserCrnProvider.doAsInternalActor(() -> cloudProviderServicesV4Endpoint.validateObjectStorage(request)); LOGGER.info("ValidateObjectStorage: request: {}, response: {}", JsonUtil.writeValueAsStringSilent(request), JsonUtil.writeValueAsStringSilent(response)); if (ResponseStatus.ERROR.equals(response.getStatus())) { validationResultBuilder.error(response.getError()); throw new BadRequestException(response.getError()); } } } CloudStorageValidator(CredentialToCloudCredentialConverter credentialToCloudCredentialConverter,
            EntitlementService entitlementService, SecretService secretService,
            CloudProviderServicesV4Endopint cloudProviderServicesV4Endpoint); }
CloudStorageValidator { 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(INTERNAL_ACTOR_CRN, 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( environment.getCloudPlatform(), cloudCredential, cloudStorageRequest); ObjectStorageValidateResponse response = ThreadBasedUserCrnProvider.doAsInternalActor(() -> cloudProviderServicesV4Endpoint.validateObjectStorage(request)); LOGGER.info("ValidateObjectStorage: request: {}, response: {}", JsonUtil.writeValueAsStringSilent(request), JsonUtil.writeValueAsStringSilent(response)); if (ResponseStatus.ERROR.equals(response.getStatus())) { validationResultBuilder.error(response.getError()); throw new BadRequestException(response.getError()); } } } CloudStorageValidator(CredentialToCloudCredentialConverter credentialToCloudCredentialConverter,
            EntitlementService entitlementService, SecretService secretService,
            CloudProviderServicesV4Endopint cloudProviderServicesV4Endpoint); void validate(CloudStorageRequest cloudStorageRequest, DetailedEnvironmentResponse environment,
            ValidationResult.ValidationResultBuilder validationResultBuilder); }
CloudStorageValidator { 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(INTERNAL_ACTOR_CRN, 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( environment.getCloudPlatform(), cloudCredential, cloudStorageRequest); ObjectStorageValidateResponse response = ThreadBasedUserCrnProvider.doAsInternalActor(() -> cloudProviderServicesV4Endpoint.validateObjectStorage(request)); LOGGER.info("ValidateObjectStorage: request: {}, response: {}", JsonUtil.writeValueAsStringSilent(request), JsonUtil.writeValueAsStringSilent(response)); if (ResponseStatus.ERROR.equals(response.getStatus())) { validationResultBuilder.error(response.getError()); throw new BadRequestException(response.getError()); } } } CloudStorageValidator(CredentialToCloudCredentialConverter credentialToCloudCredentialConverter,
            EntitlementService entitlementService, SecretService secretService,
            CloudProviderServicesV4Endopint cloudProviderServicesV4Endpoint); void validate(CloudStorageRequest cloudStorageRequest, DetailedEnvironmentResponse environment,
            ValidationResult.ValidationResultBuilder validationResultBuilder);  }