use of com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest in project cloudbreak by hortonworks.
the class CredentialValidatorTest method testValidateAwsCredentialRequestNotAWS.
@Test
void testValidateAwsCredentialRequestNotAWS() {
CredentialRequest request = new CredentialRequest();
request.setCloudPlatform("AZURE");
ValidationResult result = underTest.validateAwsCredentialRequest(request);
assertTrue(result.hasError());
assertEquals("Credential request is not for AWS.", result.getErrors().get(0));
}
use of com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest in project cloudbreak by hortonworks.
the class CredentialValidatorTest method testValidateAwsCredentialRequestValid.
@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());
}
use of com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest in project cloudbreak by hortonworks.
the class CredentialValidatorTest method testValidateAwsCredentialRequestNoArn.
@Test
void testValidateAwsCredentialRequestNoArn() {
CredentialRequest request = new CredentialRequest();
request.setCloudPlatform("AWS");
AwsCredentialParameters aws = new AwsCredentialParameters();
aws.setRoleBased(new RoleBasedParameters());
request.setAws(aws);
ValidationResult result = underTest.validateAwsCredentialRequest(request);
assertTrue(result.hasError());
assertEquals("Role ARN is not found in credential request.", result.getErrors().get(0));
}
use of com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest in project cloudbreak by hortonworks.
the class EnvironmentServiceIntegrationTest method setup.
@BeforeEach
public void setup() {
client = new EnvironmentServiceClientBuilder(String.format(SERVICE_ADDRESS, port)).withCertificateValidation(false).withDebug(true).withIgnorePreValidation(true).build().withCrn(TEST_USER_CRN);
credential = new Credential();
credential.setName("credential_test");
credential.setResourceCrn(TEST_RESOURCE_CRN);
credential.setAccountId(TEST_ACCOUNT_ID);
credential.setCloudPlatform("AWS");
credential.setCreator(TEST_USER_CRN);
credential.setDescription("description");
credential.setGovCloud(false);
credential.setArchived(false);
credential.setType(ENVIRONMENT);
credentialRequest = new CredentialRequest();
when(entitlementService.azureEnabled(any())).thenReturn(true);
doNothing().when(grpcUmsClient).assignResourceRole(anyString(), anyString(), anyString(), any(), any());
lenient().when(grpcUmsClient.hasRights(anyString(), anyList(), any(), any())).then(i -> {
List<RightCheck> rightChecks = i.getArgument(1);
return rightChecks.stream().map(r -> Boolean.TRUE).collect(toList());
});
lenient().when(grpcUmsClient.checkAccountRight(anyString(), anyString(), any(), any())).thenReturn(true);
Map<String, Boolean> rightCheckMap = Maps.newHashMap();
rightCheckMap.put(credential.getResourceCrn(), true);
when(umsResourceAuthorizationService.getRightOfUserOnResources(anyString(), any(), anyList())).thenReturn(rightCheckMap);
when(grpcUmsClient.getResourceRoles(any(), any())).thenReturn(Set.of("crn:altus:iam:us-west-1:altus:resourceRole:Owner", "crn:altus:iam:us-west-1:altus:resourceRole:EnvironmentAdmin"));
}
use of com.sequenceiq.environment.api.v1.credential.model.request.CredentialRequest in project cloudbreak by hortonworks.
the class CredentialValidator method validateAwsCredentialRequest.
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();
}
Aggregations