Search in sources :

Example 11 with ProxyConfig

use of com.sequenceiq.cloudbreak.dto.ProxyConfig in project cloudbreak by hortonworks.

the class ProxyConfigProvider method decoratePillarWithProxyDataIfNeeded.

public void decoratePillarWithProxyDataIfNeeded(Map<String, SaltPillarProperties> servicePillar, Cluster cluster) {
    Optional<ProxyConfig> proxyConfig = proxyConfigDtoService.getByCrnWithEnvironmentFallback(cluster.getProxyConfigCrn(), cluster.getEnvironmentCrn());
    proxyConfig.ifPresent(pc -> {
        Map<String, Object> proxy = new HashMap<>();
        proxy.put("host", pc.getServerHost());
        proxy.put("port", pc.getServerPort());
        proxy.put("protocol", pc.getProtocol());
        pc.getProxyAuthentication().ifPresent(auth -> {
            proxy.put("user", auth.getUserName());
            proxy.put("password", auth.getPassword());
        });
        proxy.put("noProxyHosts", pc.getNoProxyHosts());
        servicePillar.put(PROXY_KEY, new SaltPillarProperties(PROXY_SLS_PATH, singletonMap(PROXY_KEY, proxy)));
        LOGGER.info("Salt pillar properties extend with proxy config: {}", pc);
    });
}
Also used : HashMap(java.util.HashMap) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) SaltPillarProperties(com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties)

Example 12 with ProxyConfig

use of com.sequenceiq.cloudbreak.dto.ProxyConfig in project cloudbreak by hortonworks.

the class UserDataBuilderTest method testBuildUserDataAzureWithNoAuthProxy.

@Test
public void testBuildUserDataAzureWithNoAuthProxy() throws IOException {
    String expectedGwScript = FileReaderUtils.readFileFromClasspath("azure-gateway-init-noauthproxy.sh");
    String expectedCoreScript = FileReaderUtils.readFileFromClasspath("azure-core-init.sh");
    ProxyConfig proxyConfig = ProxyConfig.builder().withServerHost("proxy.host").withServerPort(1234).withNoProxyHosts("noproxy.com").withProtocol("http").build();
    Map<InstanceGroupType, String> userdata = underTest.buildUserData(Platform.platform("AZURE"), "priv-key".getBytes(), "cloudbreak", getPlatformParameters(), "pass", "cert", new CcmConnectivityParameters(), proxyConfig);
    Assert.assertEquals(expectedGwScript, userdata.get(InstanceGroupType.GATEWAY));
    Assert.assertEquals(expectedCoreScript, userdata.get(InstanceGroupType.CORE));
}
Also used : CcmConnectivityParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) Test(org.junit.Test)

Example 13 with ProxyConfig

use of com.sequenceiq.cloudbreak.dto.ProxyConfig in project cloudbreak by hortonworks.

the class UserDataBuilderTest method testBuildUserDataAzureWithAuthProxy.

@Test
public void testBuildUserDataAzureWithAuthProxy() throws IOException {
    String expectedGwScript = FileReaderUtils.readFileFromClasspath("azure-gateway-init-authproxy.sh");
    String expectedCoreScript = FileReaderUtils.readFileFromClasspath("azure-core-init.sh");
    ProxyAuthentication proxyAuthentication = ProxyAuthentication.builder().withUserName("user").withPassword("pwd").build();
    ProxyConfig proxyConfig = ProxyConfig.builder().withServerHost("proxy.host").withServerPort(1234).withProxyAuthentication(proxyAuthentication).withNoProxyHosts("noproxy.com").withProtocol("https").build();
    Map<InstanceGroupType, String> userdata = underTest.buildUserData(Platform.platform("AZURE"), "priv-key".getBytes(), "cloudbreak", getPlatformParameters(), "pass", "cert", new CcmConnectivityParameters(), proxyConfig);
    Assert.assertEquals(expectedGwScript, userdata.get(InstanceGroupType.GATEWAY));
    Assert.assertEquals(expectedCoreScript, userdata.get(InstanceGroupType.CORE));
}
Also used : CcmConnectivityParameters(com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) ProxyAuthentication(com.sequenceiq.cloudbreak.dto.ProxyAuthentication) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) Test(org.junit.Test)

Example 14 with ProxyConfig

use of com.sequenceiq.cloudbreak.dto.ProxyConfig in project cloudbreak by hortonworks.

the class ProxyConfigDtoServiceTest method testGetWhenProxyConfigUserPasswordEmpty.

@ParameterizedTest
@MethodSource("invalidUserPasswords")
void testGetWhenProxyConfigUserPasswordEmpty(String user, String password) {
    String name = "aProxyConfig";
    String host = "https://test.cloudera.com";
    Integer port = 8443;
    String decryptedSecretValue = "decrypted-secret-value";
    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))).thenReturn(user).thenReturn(password);
    ProxyConfig proxyConfig = underTest.getByCrn("crn:cdp:environments:us-west-1:cloudera:proxyconfig:a2f0bee2-059e-433f-a9d0-2893c53419ad");
    assertFalse(proxyConfig.getProxyAuthentication().isPresent());
}
Also used : SecretResponse(com.sequenceiq.cloudbreak.service.secret.model.SecretResponse) ProxyResponse(com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 15 with ProxyConfig

use of com.sequenceiq.cloudbreak.dto.ProxyConfig in project cloudbreak by hortonworks.

the class ProxyConfigDtoServiceTest method testGetWhenProxyConfigUserPasswordSecretsAreEmpty.

@ParameterizedTest
@MethodSource("invalidUserPasswordSecrets")
void testGetWhenProxyConfigUserPasswordSecretsAreEmpty(SecretResponse user, SecretResponse password) {
    String name = "aProxyConfig";
    String host = "https://test.cloudera.com";
    Integer port = 8443;
    ProxyResponse proxyResponse = new ProxyResponse();
    proxyResponse.setName(name);
    proxyResponse.setHost(host);
    proxyResponse.setPort(port);
    proxyResponse.setUserName(user);
    proxyResponse.setPassword(password);
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(environmentServiceCrnClient.withCrn(anyString()).proxyV1Endpoint()).thenReturn(proxyEndpoint);
    when(proxyEndpoint.getByResourceCrn(anyString())).thenReturn(proxyResponse);
    ProxyConfig proxyConfig = underTest.getByCrn("crn:cdp:environments:us-west-1:cloudera:proxyconfig:a2f0bee2-059e-433f-a9d0-2893c53419ad");
    assertFalse(proxyConfig.getProxyAuthentication().isPresent());
}
Also used : ProxyResponse(com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ProxyConfig(com.sequenceiq.cloudbreak.dto.ProxyConfig) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ProxyConfig (com.sequenceiq.cloudbreak.dto.ProxyConfig)18 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 Test (org.junit.jupiter.api.Test)6 CcmConnectivityParameters (com.sequenceiq.cloudbreak.ccm.cloudinit.CcmConnectivityParameters)5 CdpResourceApi (com.cloudera.api.swagger.CdpResourceApi)4 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)4 ApiClient (com.cloudera.api.swagger.client.ApiClient)4 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)4 ApiHostRef (com.cloudera.api.swagger.model.ApiHostRef)4 ApiRemoteDataContext (com.cloudera.api.swagger.model.ApiRemoteDataContext)4 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)4 TemplatePreparationObject (com.sequenceiq.cloudbreak.template.TemplatePreparationObject)4 GeneralClusterConfigs (com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs)4 Telemetry (com.sequenceiq.common.api.telemetry.model.Telemetry)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 PlatformParameters (com.sequenceiq.cloudbreak.cloud.PlatformParameters)3 InstanceGroupType (com.sequenceiq.common.api.type.InstanceGroupType)3 ProxyResponse (com.sequenceiq.environment.api.v1.proxy.model.response.ProxyResponse)3 Test (org.junit.Test)3