@Test void testValidateAwsCredentialRequestValid() { CredentialRequest request = new CredentialRequest(); request.setCloudPlatform("AWS"); AwsCredentialParameters aws = new AwsCredentialParameters(); RoleBasedParameters roleBased = new RoleBasedParameters(); roleBased.setRoleArn("arn"); aws.setRoleBased(roleBased); request.setAws(aws); ValidationResult result = underTest.validateAwsCredentialRequest(request); assertFalse(result.hasError()); }
public ValidationResult validateAwsCredentialRequest(CredentialRequest credentialRequest) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); resultBuilder.ifError(() -> !CloudPlatform.AWS.name().equalsIgnoreCase(credentialRequest.getCloudPlatform()), "Credential request is not for AWS."); resultBuilder.ifError(() -> StringUtils.isBlank(Optional.ofNullable(credentialRequest.getAws()) .map(AwsCredentialParameters::getRoleBased) .map(RoleBasedParameters::getRoleArn) .orElse(null)), "Role ARN is not found in credential request."); return resultBuilder.build(); }
CredentialValidator { public ValidationResult validateAwsCredentialRequest(CredentialRequest credentialRequest) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); resultBuilder.ifError(() -> !CloudPlatform.AWS.name().equalsIgnoreCase(credentialRequest.getCloudPlatform()), "Credential request is not for AWS."); resultBuilder.ifError(() -> StringUtils.isBlank(Optional.ofNullable(credentialRequest.getAws()) .map(AwsCredentialParameters::getRoleBased) .map(RoleBasedParameters::getRoleArn) .orElse(null)), "Role ARN is not found in credential request."); return resultBuilder.build(); } }
CredentialValidator { public ValidationResult validateAwsCredentialRequest(CredentialRequest credentialRequest) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); resultBuilder.ifError(() -> !CloudPlatform.AWS.name().equalsIgnoreCase(credentialRequest.getCloudPlatform()), "Credential request is not for AWS."); resultBuilder.ifError(() -> StringUtils.isBlank(Optional.ofNullable(credentialRequest.getAws()) .map(AwsCredentialParameters::getRoleBased) .map(RoleBasedParameters::getRoleArn) .orElse(null)), "Role ARN is not found in credential request."); return resultBuilder.build(); } CredentialValidator(@Value("${environment.enabledplatforms}") Set<String> enabledPlatforms,
            CredentialDefinitionService credentialDefinitionService,
            List<ProviderCredentialValidator> providerCredentialValidators,
            EntitlementService entitlementService); }
CredentialValidator { public ValidationResult validateAwsCredentialRequest(CredentialRequest credentialRequest) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); resultBuilder.ifError(() -> !CloudPlatform.AWS.name().equalsIgnoreCase(credentialRequest.getCloudPlatform()), "Credential request is not for AWS."); resultBuilder.ifError(() -> StringUtils.isBlank(Optional.ofNullable(credentialRequest.getAws()) .map(AwsCredentialParameters::getRoleBased) .map(RoleBasedParameters::getRoleArn) .orElse(null)), "Role ARN is not found in credential request."); return resultBuilder.build(); } CredentialValidator(@Value("${environment.enabledplatforms}") Set<String> enabledPlatforms,
            CredentialDefinitionService credentialDefinitionService,
            List<ProviderCredentialValidator> providerCredentialValidators,
            EntitlementService entitlementService); void validateParameters(Platform platform, Json json); void validateCredentialCloudPlatform(String cloudPlatform, String userCrn); boolean isCredentialCloudPlatformValid(String cloudPlatform, String accountId); ValidationResult validateCredentialUpdate(Credential original, Credential newCred, CredentialType type); ValidationResult validateAwsCredentialRequest(CredentialRequest credentialRequest); }
CredentialValidator { public ValidationResult validateAwsCredentialRequest(CredentialRequest credentialRequest) { ValidationResultBuilder resultBuilder = new ValidationResultBuilder(); resultBuilder.ifError(() -> !CloudPlatform.AWS.name().equalsIgnoreCase(credentialRequest.getCloudPlatform()), "Credential request is not for AWS."); resultBuilder.ifError(() -> StringUtils.isBlank(Optional.ofNullable(credentialRequest.getAws()) .map(AwsCredentialParameters::getRoleBased) .map(RoleBasedParameters::getRoleArn) .orElse(null)), "Role ARN is not found in credential request."); return resultBuilder.build(); } CredentialValidator(@Value("${environment.enabledplatforms}") Set<String> enabledPlatforms,
            CredentialDefinitionService credentialDefinitionService,
            List<ProviderCredentialValidator> providerCredentialValidators,
            EntitlementService entitlementService); void validateParameters(Platform platform, Json json); void validateCredentialCloudPlatform(String cloudPlatform, String userCrn); boolean isCredentialCloudPlatformValid(String cloudPlatform, String accountId); ValidationResult validateCredentialUpdate(Credential original, Credential newCred, CredentialType type); ValidationResult validateAwsCredentialRequest(CredentialRequest credentialRequest);  }