@Test void testValidateAwsEnvironmentRequestValid() { when(credentialService.getCloudPlatformByCredential(anyString(), anyString(), any())).thenReturn("AWS"); EnvironmentRequest request = new EnvironmentRequest(); request.setCredentialName("aws-credential"); AwsEnvironmentParameters aws = new AwsEnvironmentParameters(); S3GuardRequestParameters s3GuardRequestParameters = new S3GuardRequestParameters(); s3GuardRequestParameters.setDynamoDbTableName("table"); aws.setS3guard(s3GuardRequestParameters); request.setAws(aws); ValidationResult result = ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.validateAwsEnvironmentRequest(request)); assertFalse(result.hasError()); }
public ValidationResult validateAwsEnvironmentRequest(EnvironmentRequest environmentRequest) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); String cloudPlatform = credentialService.getCloudPlatformByCredential(environmentRequest.getCredentialName(), accountId, ENVIRONMENT); resultBuilder.ifError(() -> !AWS.name().equalsIgnoreCase(cloudPlatform), "Environment request is not for cloud platform AWS."); resultBuilder.ifError(() -> StringUtils.isBlank(Optional.ofNullable(environmentRequest.getAws()) .map(AwsEnvironmentParameters::getS3guard) .map(S3GuardRequestParameters::getDynamoDbTableName) .orElse(null)), "S3Guard Dynamo DB table name is not found in environment request."); return resultBuilder.build(); }
EnvironmentValidatorService { public ValidationResult validateAwsEnvironmentRequest(EnvironmentRequest environmentRequest) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); String cloudPlatform = credentialService.getCloudPlatformByCredential(environmentRequest.getCredentialName(), accountId, ENVIRONMENT); resultBuilder.ifError(() -> !AWS.name().equalsIgnoreCase(cloudPlatform), "Environment request is not for cloud platform AWS."); resultBuilder.ifError(() -> StringUtils.isBlank(Optional.ofNullable(environmentRequest.getAws()) .map(AwsEnvironmentParameters::getS3guard) .map(S3GuardRequestParameters::getDynamoDbTableName) .orElse(null)), "S3Guard Dynamo DB table name is not found in environment request."); return resultBuilder.build(); } }
EnvironmentValidatorService { public ValidationResult validateAwsEnvironmentRequest(EnvironmentRequest environmentRequest) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); String cloudPlatform = credentialService.getCloudPlatformByCredential(environmentRequest.getCredentialName(), accountId, ENVIRONMENT); resultBuilder.ifError(() -> !AWS.name().equalsIgnoreCase(cloudPlatform), "Environment request is not for cloud platform AWS."); resultBuilder.ifError(() -> StringUtils.isBlank(Optional.ofNullable(environmentRequest.getAws()) .map(AwsEnvironmentParameters::getS3guard) .map(S3GuardRequestParameters::getDynamoDbTableName) .orElse(null)), "S3Guard Dynamo DB table name is not found in environment request."); return resultBuilder.build(); } EnvironmentValidatorService(NetworkCreationValidator networkCreationValidator,
            PlatformParameterService platformParameterService,
            EnvironmentResourceService environmentResourceService,
            CredentialService credentialService,
            @Value("${environment.enabledParentPlatforms}") Set<String> enabledParentPlatforms,
            @Value("${environment.enabledChildPlatforms}") Set<String> enabledChildPlatforms); }
EnvironmentValidatorService { public ValidationResult validateAwsEnvironmentRequest(EnvironmentRequest environmentRequest) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); String cloudPlatform = credentialService.getCloudPlatformByCredential(environmentRequest.getCredentialName(), accountId, ENVIRONMENT); resultBuilder.ifError(() -> !AWS.name().equalsIgnoreCase(cloudPlatform), "Environment request is not for cloud platform AWS."); resultBuilder.ifError(() -> StringUtils.isBlank(Optional.ofNullable(environmentRequest.getAws()) .map(AwsEnvironmentParameters::getS3guard) .map(S3GuardRequestParameters::getDynamoDbTableName) .orElse(null)), "S3Guard Dynamo DB table name is not found in environment request."); return resultBuilder.build(); } EnvironmentValidatorService(NetworkCreationValidator networkCreationValidator,
            PlatformParameterService platformParameterService,
            EnvironmentResourceService environmentResourceService,
            CredentialService credentialService,
            @Value("${environment.enabledParentPlatforms}") Set<String> enabledParentPlatforms,
            @Value("${environment.enabledChildPlatforms}") Set<String> enabledChildPlatforms); ValidationResultBuilder validateNetworkCreation(Environment environment, NetworkDto network); ValidationResult validateParentChildRelation(Environment environment, String parentEnvironmentName); ValidationResult validateAwsEnvironmentRequest(EnvironmentRequest environmentRequest); ValidationResult validateSecurityAccessModification(SecurityAccessDto securityAccessDto, Environment environment); ValidationResult validateSecurityGroups(EnvironmentEditDto editDto, Environment environment); ValidationResult validateAuthenticationModification(EnvironmentEditDto editDto, Environment environment); ValidationResult validateFreeIpaCreation(FreeIpaCreationDto freeIpaCreation); }
EnvironmentValidatorService { public ValidationResult validateAwsEnvironmentRequest(EnvironmentRequest environmentRequest) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); String accountId = ThreadBasedUserCrnProvider.getAccountId(); String cloudPlatform = credentialService.getCloudPlatformByCredential(environmentRequest.getCredentialName(), accountId, ENVIRONMENT); resultBuilder.ifError(() -> !AWS.name().equalsIgnoreCase(cloudPlatform), "Environment request is not for cloud platform AWS."); resultBuilder.ifError(() -> StringUtils.isBlank(Optional.ofNullable(environmentRequest.getAws()) .map(AwsEnvironmentParameters::getS3guard) .map(S3GuardRequestParameters::getDynamoDbTableName) .orElse(null)), "S3Guard Dynamo DB table name is not found in environment request."); return resultBuilder.build(); } EnvironmentValidatorService(NetworkCreationValidator networkCreationValidator,
            PlatformParameterService platformParameterService,
            EnvironmentResourceService environmentResourceService,
            CredentialService credentialService,
            @Value("${environment.enabledParentPlatforms}") Set<String> enabledParentPlatforms,
            @Value("${environment.enabledChildPlatforms}") Set<String> enabledChildPlatforms); ValidationResultBuilder validateNetworkCreation(Environment environment, NetworkDto network); ValidationResult validateParentChildRelation(Environment environment, String parentEnvironmentName); ValidationResult validateAwsEnvironmentRequest(EnvironmentRequest environmentRequest); ValidationResult validateSecurityAccessModification(SecurityAccessDto securityAccessDto, Environment environment); ValidationResult validateSecurityGroups(EnvironmentEditDto editDto, Environment environment); ValidationResult validateAuthenticationModification(EnvironmentEditDto editDto, Environment environment); ValidationResult validateFreeIpaCreation(FreeIpaCreationDto freeIpaCreation);  }