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)));
}
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));
}
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");
}
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());
}
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));
}
}
Aggregations