use of com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse in project cloudbreak by hortonworks.
the class StackDecoratorTest method setUp.
@Before
public void setUp() {
String credentialName = "credentialName";
MockitoAnnotations.initMocks(this);
subject = new Stack();
subject.setEnvironmentCrn("envCrn");
Set<InstanceGroup> instanceGroups = createInstanceGroups(GATEWAY);
subject.setInstanceGroups(instanceGroups);
Cluster cluster = getCluster(instanceGroups);
subject.setCluster(cluster);
subject.setCloudPlatform("AZURE");
subject.setParameters(new HashMap<>());
when(cloudParameterCache.getPlatformParameters()).thenReturn(platformParametersMap);
when(platformParametersMap.get(any(Platform.class))).thenReturn(pps);
when(pps.specialParameters()).thenReturn(specialParameters);
when(specialParameters.getSpecialParameters()).thenReturn(specialParametersMap);
when(specialParametersMap.get(anyString())).thenReturn(false);
when(cloudParameterService.getOrchestrators()).thenReturn(platformOrchestrators);
when(platformOrchestrators.getDefaults()).thenReturn(defaultOrchestrator);
when(defaultOrchestrator.get(any(Platform.class))).thenReturn(orchestrator);
when(instanceGroupToInstanceGroupParameterRequestConverter.convert(any(InstanceGroup.class))).thenReturn(instanceGroupParameterRequest);
when(request.getCluster()).thenReturn(clusterRequest);
when(environmentSettingsRequest.getCredentialName()).thenReturn(credentialName);
when(sharedServiceValidator.checkSharedServiceStackRequirements(any(StackV4Request.class), any(Workspace.class))).thenReturn(validationResult);
DetailedEnvironmentResponse environmentResponse = new DetailedEnvironmentResponse();
environmentResponse.setCredential(credentialResponse);
CompactRegionResponse crr = new CompactRegionResponse();
crr.setNames(Lists.newArrayList("region"));
environmentResponse.setRegions(crr);
EnvironmentNetworkResponse enr = new EnvironmentNetworkResponse();
Map<String, CloudSubnet> subnetmetas = Maps.newHashMap("subnet", new CloudSubnet("id", "name", "availabilityzone", "cidr"));
enr.setSubnetMetas(subnetmetas);
environmentResponse.setNetwork(enr);
environmentResponse.setAzure(AzureEnvironmentParameters.builder().withAzureResourceGroup(AzureResourceGroup.builder().withResourceGroupUsage(ResourceGroupUsage.SINGLE).withName("resource-group").build()).build());
when(request.getCloudPlatform()).thenReturn(CloudPlatform.AZURE);
when(environmentClientService.getByName(anyString())).thenReturn(environmentResponse);
when(environmentClientService.getByCrn(anyString())).thenReturn(environmentResponse);
Credential credential = Credential.builder().cloudPlatform(CloudPlatform.MOCK.name()).build();
when(credentialClientService.getByCrn(anyString())).thenReturn(credential);
when(credentialClientService.getByName(anyString())).thenReturn(credential);
when(credentialConverter.convert(credentialResponse)).thenReturn(credential);
ExtendedCloudCredential extendedCloudCredential = mock(ExtendedCloudCredential.class);
when(extendedCloudCredentialConverter.convert(credential)).thenReturn(extendedCloudCredential);
}
use of com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse in project cloudbreak by hortonworks.
the class CredentialServiceTest method testNonAzureCredential.
@Test
public void testNonAzureCredential() {
CredentialResponse credentialResponse = new CredentialResponse();
credentialResponse.setCrn(CRN);
credentialResponse.setName(NAME);
credentialResponse.setAttributes(secretResponse);
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());
assertFalse(credential.getAzure().isPresent());
}
use of com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse in project cloudbreak by hortonworks.
the class CredentialService method getCredentialByEnvCrn.
public Credential getCredentialByEnvCrn(String envCrn) {
CredentialResponse credentialResponse = null;
try {
credentialResponse = credentialEndpoint.getByEnvironmentCrn(envCrn);
} catch (ClientErrorException e) {
try (Response response = e.getResponse()) {
if (Response.Status.NOT_FOUND.getStatusCode() == response.getStatus()) {
throw new BadRequestException(String.format("Credential not found by environment CRN: %s", envCrn), e);
}
String errorMessage = webApplicationExceptionMessageExtractor.getErrorMessage(e);
throw new CloudbreakServiceException(String.format("Failed to get credential: %s", errorMessage), e);
}
}
SecretResponse secretResponse = credentialResponse.getAttributes();
String attributes = secretService.getByResponse(secretResponse);
return new Credential(credentialResponse.getCloudPlatform(), credentialResponse.getName(), attributes, credentialResponse.getCrn(), credentialResponse.getAccountId());
}
Aggregations