use of com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse in project cloudbreak by hortonworks.
the class ProxyConfigDtoServiceTest method testGetWhenSecretCouldNotBeFetchedFromVault.
@Test
void testGetWhenSecretCouldNotBeFetchedFromVault() {
String name = "aProxyConfig";
String host = "https://test.cloudera.com";
Integer port = 8443;
SecretResponse secretResponse = new SecretResponse();
ProxyResponse proxyResponse = new ProxyResponse();
proxyResponse.setName(name);
proxyResponse.setHost(host);
proxyResponse.setPort(port);
proxyResponse.setUserName(secretResponse);
proxyResponse.setPassword(secretResponse);
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
when(environmentServiceCrnClient.withCrn(anyString()).proxyV1Endpoint()).thenReturn(proxyEndpoint);
when(proxyEndpoint.getByResourceCrn(anyString())).thenReturn(proxyResponse);
when(secretService.getByResponse(any(SecretResponse.class))).thenThrow(new VaultException("Vault token is invalid!"));
CloudbreakServiceException exception = assertThrows(CloudbreakServiceException.class, () -> underTest.getByCrn("crn:cdp:environments:us-west-1:cloudera:proxyconfig:a2f0bee2-059e-433f-a9d0-2893c53419ad"));
assertEquals("Failed to get Proxy config related secret due to: 'Vault token is invalid!' ", exception.getMessage());
}
use of com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse in project cloudbreak by hortonworks.
the class ProxyConfigDtoServiceTest method testGetWhenProxyConfigCouldBeFetched.
@Test
void testGetWhenProxyConfigCouldBeFetched() {
String name = "aProxyConfig";
String host = "https://test.cloudera.com";
Integer port = 8443;
String decryptedSecretValue = "decrypted-secret-value";
String noProxyList = "noproxy.com";
SecretResponse secretResponse = new SecretResponse();
ProxyResponse proxyResponse = new ProxyResponse();
proxyResponse.setName(name);
proxyResponse.setHost(host);
proxyResponse.setPort(port);
proxyResponse.setUserName(secretResponse);
proxyResponse.setPassword(secretResponse);
proxyResponse.setNoProxyHosts(noProxyList);
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
when(environmentServiceCrnClient.withCrn(anyString()).proxyV1Endpoint()).thenReturn(proxyEndpoint);
when(proxyEndpoint.getByResourceCrn(anyString())).thenReturn(proxyResponse);
when(secretService.getByResponse(any(SecretResponse.class))).thenReturn(decryptedSecretValue);
ProxyConfig proxyConfig = underTest.getByCrn("crn:cdp:environments:us-west-1:cloudera:proxyconfig:a2f0bee2-059e-433f-a9d0-2893c53419ad");
verify(secretService, times(2)).getByResponse(secretResponse);
assertEquals(proxyConfig.getName(), name);
assertEquals(proxyConfig.getServerHost(), host);
assertEquals(proxyConfig.getServerPort(), port);
assertTrue(proxyConfig.getProxyAuthentication().isPresent());
assertEquals(proxyConfig.getProxyAuthentication().get().getUserName(), decryptedSecretValue);
assertEquals(proxyConfig.getProxyAuthentication().get().getPassword(), decryptedSecretValue);
assertEquals(proxyConfig.getNoProxyHosts(), noProxyList);
}
use of com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse in project cloudbreak by hortonworks.
the class EnvironmentResponseConverterTest method testDtoToDetailedResponse.
@ParameterizedTest
@EnumSource(value = CloudPlatform.class, names = { "AWS", "AZURE", "GCP" })
void testDtoToDetailedResponse(CloudPlatform cloudPlatform) {
EnvironmentDto environment = createEnvironmentDto(cloudPlatform);
CredentialResponse credentialResponse = mock(CredentialResponse.class);
FreeIpaResponse freeIpaResponse = mock(FreeIpaResponse.class);
CompactRegionResponse compactRegionResponse = mock(CompactRegionResponse.class);
TelemetryResponse telemetryResponse = mock(TelemetryResponse.class);
BackupResponse backupResponse = mock(BackupResponse.class);
ProxyResponse proxyResponse = mock(ProxyResponse.class);
EnvironmentNetworkResponse environmentNetworkResponse = mock(EnvironmentNetworkResponse.class);
when(credentialConverter.convert(environment.getCredential())).thenReturn(credentialResponse);
when(freeIpaConverter.convert(environment.getFreeIpaCreation())).thenReturn(freeIpaResponse);
when(regionConverter.convertRegions(environment.getRegions())).thenReturn(compactRegionResponse);
when(telemetryApiConverter.convert(environment.getTelemetry())).thenReturn(telemetryResponse);
when(backupConverter.convert(environment.getBackup())).thenReturn(backupResponse);
when(proxyConfigToProxyResponseConverter.convert((ProxyConfig) environment.getProxyConfig())).thenReturn(proxyResponse);
when(networkDtoToResponseConverter.convert(environment.getNetwork(), environment.getExperimentalFeatures().getTunnel(), true)).thenReturn(environmentNetworkResponse);
DetailedEnvironmentResponse actual = underTest.dtoToDetailedResponse(environment);
assertEquals(environment.getResourceCrn(), actual.getCrn());
assertEquals(environment.getName(), actual.getName());
assertEquals(environment.getOriginalName(), actual.getOriginalName());
assertEquals(environment.getDescription(), actual.getDescription());
assertEquals(environment.getCloudPlatform(), actual.getCloudPlatform());
assertEquals(credentialResponse, actual.getCredential());
assertEquals(environment.getStatus().getResponseStatus(), actual.getEnvironmentStatus());
assertLocation(environment.getLocation(), actual.getLocation());
assertTrue(actual.getCreateFreeIpa());
assertEquals(freeIpaResponse, actual.getFreeIpa());
assertEquals(compactRegionResponse, actual.getRegions());
assertEquals(environment.getCreator(), actual.getCreator());
assertAuthentication(environment.getAuthentication(), actual.getAuthentication());
assertEquals(environment.getStatusReason(), actual.getStatusReason());
assertEquals(environment.getCreated(), actual.getCreated());
assertEquals(environment.getTags().getUserDefinedTags(), actual.getTags().getUserDefined());
assertEquals(environment.getTags().getDefaultTags(), actual.getTags().getDefaults());
assertEquals(telemetryResponse, actual.getTelemetry());
assertEquals(environment.getExperimentalFeatures().getTunnel(), actual.getTunnel());
assertEquals(environment.getExperimentalFeatures().getIdBrokerMappingSource(), actual.getIdBrokerMappingSource());
assertEquals(environment.getExperimentalFeatures().getCloudStorageValidation(), actual.getCloudStorageValidation());
assertEquals(environment.getExperimentalFeatures().getCcmV2TlsType(), actual.getCcmV2TlsType());
assertEquals(environment.getAdminGroupName(), actual.getAdminGroupName());
assertParameters(environment, actual, cloudPlatform);
assertEquals(environment.getParentEnvironmentCrn(), actual.getParentEnvironmentCrn());
assertEquals(environment.getParentEnvironmentName(), actual.getParentEnvironmentName());
assertEquals(environment.getParentEnvironmentCloudPlatform(), actual.getParentEnvironmentCloudPlatform());
assertEquals(proxyResponse, actual.getProxyConfig());
assertEquals(environmentNetworkResponse, actual.getNetwork());
assertSecurityAccess(environment.getSecurityAccess(), actual.getSecurityAccess());
verify(credentialConverter).convert(environment.getCredential());
verify(freeIpaConverter).convert(environment.getFreeIpaCreation());
verify(regionConverter).convertRegions(environment.getRegions());
verify(telemetryApiConverter).convert(environment.getTelemetry());
verify(proxyConfigToProxyResponseConverter).convert(environment.getProxyConfig());
verify(networkDtoToResponseConverter).convert(environment.getNetwork(), environment.getExperimentalFeatures().getTunnel(), true);
}
use of com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse in project cloudbreak by hortonworks.
the class EnvironmentResponseConverterTest method testDtoToSimpleResponse.
@ParameterizedTest
@EnumSource(value = CloudPlatform.class, names = { "AWS", "AZURE" })
void testDtoToSimpleResponse(CloudPlatform cloudPlatform) {
EnvironmentDto environmentDto = createEnvironmentDto(cloudPlatform);
CredentialViewResponse credentialResponse = mock(CredentialViewResponse.class);
FreeIpaResponse freeIpaResponse = mock(FreeIpaResponse.class);
CompactRegionResponse compactRegionResponse = mock(CompactRegionResponse.class);
TelemetryResponse telemetryResponse = mock(TelemetryResponse.class);
ProxyViewResponse proxyResponse = mock(ProxyViewResponse.class);
EnvironmentNetworkResponse environmentNetworkResponse = mock(EnvironmentNetworkResponse.class);
when(credentialViewConverter.convertResponse(environmentDto.getCredential())).thenReturn(credentialResponse);
when(freeIpaConverter.convert(environmentDto.getFreeIpaCreation())).thenReturn(freeIpaResponse);
when(regionConverter.convertRegions(environmentDto.getRegions())).thenReturn(compactRegionResponse);
when(telemetryApiConverter.convert(environmentDto.getTelemetry())).thenReturn(telemetryResponse);
when(proxyConfigToProxyResponseConverter.convertToView(environmentDto.getProxyConfig())).thenReturn(proxyResponse);
when(networkDtoToResponseConverter.convert(environmentDto.getNetwork(), environmentDto.getExperimentalFeatures().getTunnel(), false)).thenReturn(environmentNetworkResponse);
SimpleEnvironmentResponse actual = underTest.dtoToSimpleResponse(environmentDto, true, true);
assertEquals(environmentDto.getResourceCrn(), actual.getCrn());
assertEquals(environmentDto.getName(), actual.getName());
assertEquals(environmentDto.getOriginalName(), actual.getOriginalName());
assertEquals(environmentDto.getDescription(), actual.getDescription());
assertEquals(environmentDto.getCloudPlatform(), actual.getCloudPlatform());
assertEquals(credentialResponse, actual.getCredential());
assertEquals(environmentDto.getStatus().getResponseStatus(), actual.getEnvironmentStatus());
assertEquals(environmentDto.getCreator(), actual.getCreator());
assertLocation(environmentDto.getLocation(), actual.getLocation());
assertTrue(actual.getCreateFreeIpa());
assertEquals(freeIpaResponse, actual.getFreeIpa());
assertEquals(environmentDto.getStatusReason(), actual.getStatusReason());
assertEquals(environmentDto.getCreated(), actual.getCreated());
assertEquals(environmentDto.getExperimentalFeatures().getTunnel(), actual.getTunnel());
assertEquals(environmentDto.getExperimentalFeatures().getCcmV2TlsType(), actual.getCcmV2TlsType());
assertEquals(environmentDto.getAdminGroupName(), actual.getAdminGroupName());
assertEquals(environmentDto.getTags().getUserDefinedTags(), actual.getTags().getUserDefined());
assertEquals(environmentDto.getTags().getDefaultTags(), actual.getTags().getDefaults());
assertEquals(telemetryResponse, actual.getTelemetry());
assertEquals(compactRegionResponse, actual.getRegions());
assertParameters(environmentDto, actual, cloudPlatform);
assertEquals(environmentDto.getParentEnvironmentName(), actual.getParentEnvironmentName());
assertEquals(proxyResponse, actual.getProxyConfig());
assertEquals(environmentNetworkResponse, actual.getNetwork());
verify(credentialViewConverter).convertResponse(environmentDto.getCredential());
verify(freeIpaConverter).convert(environmentDto.getFreeIpaCreation());
verify(regionConverter).convertRegions(environmentDto.getRegions());
verify(telemetryApiConverter).convert(environmentDto.getTelemetry());
verify(proxyConfigToProxyResponseConverter).convertToView(environmentDto.getProxyConfig());
verify(networkDtoToResponseConverter).convert(environmentDto.getNetwork(), environmentDto.getExperimentalFeatures().getTunnel(), false);
}
use of com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse in project cloudbreak by hortonworks.
the class ProxyController method deleteByName.
@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.POWERUSER_ONLY)
public ProxyResponse deleteByName(String name) {
ProxyResponse proxyResponse = proxyConfigToProxyResponseConverter.convert(proxyConfigService.deleteByNameInAccount(name, ThreadBasedUserCrnProvider.getAccountId()));
notify(ResourceEvent.PROXY_CONFIG_DELETED);
return proxyResponse;
}
Aggregations