Search in sources :

Example 1 with Credential

use of com.sequenceiq.redbeams.dto.Credential in project cloudbreak by hortonworks.

the class SubnetListerServiceTest method testListSubnetsAzure.

@Test
public void testListSubnetsAzure() {
    when(environmentNetworkResponse.getSubnetMetas()).thenReturn(subnets);
    when(environmentNetworkResponse.getAzure().getResourceGroupName()).thenReturn(RESOURCE_GROUP);
    when(environmentNetworkResponse.getAzure().getNetworkId()).thenReturn(NETWORK_ID);
    Credential.AzureParameters azure = new Credential.AzureParameters(SUBSCRIPTION_ID);
    credential = new Credential(CREDENTIAL_CRN, CREDENTIAL_NAME, CREDENTIAL_ATTRIBUTES, azure, "acc");
    when(credentialService.getCredentialByEnvCrn(ENVIRONMENT_CRN)).thenReturn(credential);
    List<CloudSubnet> subnets = underTest.listSubnets(detailedEnvironmentResponse, CloudPlatform.AZURE);
    assertEquals(2, subnets.size());
    Set<String> ids = subnets.stream().map(CloudSubnet::getId).collect(Collectors.toSet());
    assertTrue(ids.contains(formatAzureResourceId(SUBSCRIPTION_ID, RESOURCE_GROUP, NETWORK_ID, SUBNET_ID_1)));
    assertTrue(ids.contains(formatAzureResourceId(SUBSCRIPTION_ID, RESOURCE_GROUP, NETWORK_ID, SUBNET_ID_2)));
}
Also used : Credential(com.sequenceiq.redbeams.dto.Credential) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.Test)

Example 2 with Credential

use of com.sequenceiq.redbeams.dto.Credential in project cloudbreak by hortonworks.

the class SubnetListerServiceTest method testListSubnetsAws.

@Test
public void testListSubnetsAws() {
    when(environmentNetworkResponse.getSubnetMetas()).thenReturn(subnets);
    when(environmentNetworkResponse.getCbSubnets()).thenReturn(subnets);
    credential = new Credential(CREDENTIAL_CRN, CREDENTIAL_NAME, CREDENTIAL_ATTRIBUTES, "acc");
    when(credentialService.getCredentialByEnvCrn(ENVIRONMENT_CRN)).thenReturn(credential);
    List<CloudSubnet> subnets = underTest.listSubnets(detailedEnvironmentResponse, CloudPlatform.AWS);
    assertEquals(2, subnets.size());
    assertTrue(subnets.contains(subnet1));
    assertTrue(subnets.contains(subnet2));
}
Also used : Credential(com.sequenceiq.redbeams.dto.Credential) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.Test)

Example 3 with Credential

use of com.sequenceiq.redbeams.dto.Credential in project cloudbreak by hortonworks.

the class AbstractRedbeamsTerminationActionTest method setUp.

@Before
public void setUp() throws Exception {
    initMocks(this);
    dbStack = new DBStack();
    dbStack.setId(101L);
    dbStack.setName("mystack");
    dbStack.setRegion("us-east-1");
    dbStack.setAvailabilityZone("us-east-1b");
    dbStack.setCloudPlatform("AWS");
    dbStack.setPlatformVariant("GovCloud");
    dbStack.setEnvironmentId("myenv");
    dbStack.setOwnerCrn(Crn.safeFromString("crn:cdp:iam:us-west-1:cloudera:user:bob@cloudera.com"));
    dbStack.setResourceCrn(CrnTestUtil.getDatabaseCrnBuilder().setAccountId("acc").setResource("resource").build().toString());
    credential = new Credential("userId", null, "userCrn", "account");
    cloudCredential = new CloudCredential("userId", "userName", "account");
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.redbeams.dto.Credential) DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Before(org.junit.Before)

Example 4 with Credential

use of com.sequenceiq.redbeams.dto.Credential in project cloudbreak by hortonworks.

the class CredentialServiceTest method testAzureCredential.

@Test
public void testAzureCredential() {
    CredentialResponse credentialResponse = new CredentialResponse();
    credentialResponse.setCrn(CRN);
    credentialResponse.setName(NAME);
    credentialResponse.setAttributes(secretResponse);
    AzureCredentialResponseParameters azureResponse = new AzureCredentialResponseParameters();
    azureResponse.setSubscriptionId(SUBSCRIPTION_ID);
    credentialResponse.setAzure(azureResponse);
    when(credentialEndpoint.getByEnvironmentCrn(ENVIRONMENT_CRN)).thenReturn(credentialResponse);
    Credential credential = underTest.getCredentialByEnvCrn(ENVIRONMENT_CRN);
    assertEquals(CRN, credential.getCrn());
    assertEquals(NAME, credential.getName());
    assertEquals(ATTRIBUTES, credential.getAttributes());
    assertTrue(credential.getAzure().isPresent());
    assertEquals(SUBSCRIPTION_ID, credential.getAzure().get().getSubscriptionId());
}
Also used : Credential(com.sequenceiq.redbeams.dto.Credential) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) AzureCredentialResponseParameters(com.sequenceiq.environment.api.v1.credential.model.parameters.azure.AzureCredentialResponseParameters) Test(org.junit.Test)

Example 5 with Credential

use of com.sequenceiq.redbeams.dto.Credential in project cloudbreak by hortonworks.

the class SubnetListerService method getAzureSubscriptionId.

String getAzureSubscriptionId(String environmentCrn) {
    Credential credential = credentialService.getCredentialByEnvCrn(environmentCrn);
    LOGGER.info("Found credential {} for environment {}", credential.getName(), environmentCrn);
    if (credential.getAzure().isPresent()) {
        return credential.getAzure().get().getSubscriptionId();
    } else {
        throw new RedbeamsException(String.format("Retrieved credential %s for Azure environment %s which lacks subscription ID", credential.getName(), environmentCrn));
    }
}
Also used : Credential(com.sequenceiq.redbeams.dto.Credential) RedbeamsException(com.sequenceiq.redbeams.exception.RedbeamsException)

Aggregations

Credential (com.sequenceiq.redbeams.dto.Credential)15 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)9 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)6 Test (org.junit.Test)6 CloudContext (com.sequenceiq.cloudbreak.cloud.context.CloudContext)5 DatabaseStack (com.sequenceiq.cloudbreak.cloud.model.DatabaseStack)5 Location (com.sequenceiq.cloudbreak.cloud.model.Location)5 CredentialResponse (com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse)3 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)2 RedbeamsException (com.sequenceiq.redbeams.exception.RedbeamsException)2 RedbeamsContext (com.sequenceiq.redbeams.flow.redbeams.common.RedbeamsContext)2 AuthenticatedContext (com.sequenceiq.cloudbreak.cloud.context.AuthenticatedContext)1 SecretResponse (com.sequenceiq.cloudbreak.service.secret.model.SecretResponse)1 AzureCredentialResponseParameters (com.sequenceiq.environment.api.v1.credential.model.parameters.azure.AzureCredentialResponseParameters)1 RedbeamsStartContext (com.sequenceiq.redbeams.flow.redbeams.start.RedbeamsStartContext)1 RedbeamsStopContext (com.sequenceiq.redbeams.flow.redbeams.stop.RedbeamsStopContext)1 Before (org.junit.Before)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1