Search in sources :

Example 1 with SecureServerExposer

use of org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.SecureServerExposer in project che-server by eclipse-che.

the class WsMasterModule method installDefaultSecureServerExposer.

private void installDefaultSecureServerExposer(String infrastructure) {
    if (KubernetesInfrastructure.NAME.equals(infrastructure)) {
        MapBinder<String, SecureServerExposerFactory<KubernetesEnvironment>> secureServerExposerFactories = MapBinder.newMapBinder(binder(), new TypeLiteral<>() {
        }, new TypeLiteral<>() {
        });
        install(new FactoryModuleBuilder().implement(new TypeLiteral<SecureServerExposer<KubernetesEnvironment>>() {
        }, new TypeLiteral<PassThroughProxySecureServerExposer<KubernetesEnvironment>>() {
        }).build(new TypeLiteral<PassThroughProxySecureServerExposerFactory<KubernetesEnvironment>>() {
        }));
        secureServerExposerFactories.addBinding("default").to(new TypeLiteral<PassThroughProxySecureServerExposerFactory<KubernetesEnvironment>>() {
        });
    } else {
        MapBinder<String, SecureServerExposerFactory<OpenShiftEnvironment>> secureServerExposerFactories = MapBinder.newMapBinder(binder(), new TypeLiteral<>() {
        }, new TypeLiteral<>() {
        });
        install(new FactoryModuleBuilder().implement(new TypeLiteral<SecureServerExposer<OpenShiftEnvironment>>() {
        }, new TypeLiteral<PassThroughProxySecureServerExposer<OpenShiftEnvironment>>() {
        }).build(new TypeLiteral<PassThroughProxySecureServerExposerFactory<OpenShiftEnvironment>>() {
        }));
        secureServerExposerFactories.addBinding("default").to(new TypeLiteral<PassThroughProxySecureServerExposerFactory<OpenShiftEnvironment>>() {
        });
    }
}
Also used : PassThroughProxySecureServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.PassThroughProxySecureServerExposer) SecureServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.SecureServerExposer) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) PassThroughProxySecureServerExposerFactory(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.factory.PassThroughProxySecureServerExposerFactory) OpenShiftEnvironment(org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment) TypeLiteral(com.google.inject.TypeLiteral) JwtProxySecureServerExposerFactory(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.factory.JwtProxySecureServerExposerFactory) PassThroughProxySecureServerExposerFactory(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.factory.PassThroughProxySecureServerExposerFactory) SecureServerExposerFactory(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.SecureServerExposerFactory) PassThroughProxySecureServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.PassThroughProxySecureServerExposer) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)

Example 2 with SecureServerExposer

use of org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.SecureServerExposer in project devspaces-images by redhat-developer.

the class WsMasterModule method installDefaultSecureServerExposer.

private void installDefaultSecureServerExposer(String infrastructure) {
    if (KubernetesInfrastructure.NAME.equals(infrastructure)) {
        MapBinder<String, SecureServerExposerFactory<KubernetesEnvironment>> secureServerExposerFactories = MapBinder.newMapBinder(binder(), new TypeLiteral<>() {
        }, new TypeLiteral<>() {
        });
        install(new FactoryModuleBuilder().implement(new TypeLiteral<SecureServerExposer<KubernetesEnvironment>>() {
        }, new TypeLiteral<PassThroughProxySecureServerExposer<KubernetesEnvironment>>() {
        }).build(new TypeLiteral<PassThroughProxySecureServerExposerFactory<KubernetesEnvironment>>() {
        }));
        secureServerExposerFactories.addBinding("default").to(new TypeLiteral<PassThroughProxySecureServerExposerFactory<KubernetesEnvironment>>() {
        });
    } else {
        MapBinder<String, SecureServerExposerFactory<OpenShiftEnvironment>> secureServerExposerFactories = MapBinder.newMapBinder(binder(), new TypeLiteral<>() {
        }, new TypeLiteral<>() {
        });
        install(new FactoryModuleBuilder().implement(new TypeLiteral<SecureServerExposer<OpenShiftEnvironment>>() {
        }, new TypeLiteral<PassThroughProxySecureServerExposer<OpenShiftEnvironment>>() {
        }).build(new TypeLiteral<PassThroughProxySecureServerExposerFactory<OpenShiftEnvironment>>() {
        }));
        secureServerExposerFactories.addBinding("default").to(new TypeLiteral<PassThroughProxySecureServerExposerFactory<OpenShiftEnvironment>>() {
        });
    }
}
Also used : PassThroughProxySecureServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.PassThroughProxySecureServerExposer) SecureServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.SecureServerExposer) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) PassThroughProxySecureServerExposerFactory(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.factory.PassThroughProxySecureServerExposerFactory) OpenShiftEnvironment(org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment) TypeLiteral(com.google.inject.TypeLiteral) JwtProxySecureServerExposerFactory(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.factory.JwtProxySecureServerExposerFactory) PassThroughProxySecureServerExposerFactory(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.factory.PassThroughProxySecureServerExposerFactory) SecureServerExposerFactory(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.SecureServerExposerFactory) PassThroughProxySecureServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.jwtproxy.PassThroughProxySecureServerExposer) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)

Example 3 with SecureServerExposer

use of org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.SecureServerExposer in project che-server by eclipse-che.

the class KubernetesServerExposerTest method assertThatSecureServerIsExposed.

@SuppressWarnings("SameParameterValue")
private void assertThatSecureServerIsExposed(String machineName, String portProtocol, Integer port, String serverName, ServerConfig serverConfig) throws Exception {
    // then
    assertThatContainerPortIsExposed(portProtocol, port);
    // ensure that service is created
    Service service = findContainerRelatedService();
    assertNotNull(service);
    // ensure that no service port is exposed
    assertTrue(service.getSpec().getPorts().stream().noneMatch(p -> p.getTargetPort().getIntVal().equals(port)));
    ServicePort servicePort = new ServicePortBuilder().withName("server-" + port).withPort(port).withProtocol(portProtocol.toUpperCase()).withNewTargetPort(port).build();
    verify(secureServerExposer).expose(eq(kubernetesEnvironment), any(), eq(machineName), // no service exists for the backed server
    isNull(), // a non-unique server
    isNull(), eq(servicePort), eq(ImmutableMap.of(serverName, serverConfig)));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Listeners(org.testng.annotations.Listeners) Container(io.fabric8.kubernetes.api.model.Container) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Assert.assertEquals(org.testng.Assert.assertEquals) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) Test(org.testng.annotations.Test) SERVER_NAME_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.ServerConfig.SERVER_NAME_ATTRIBUTE) IngressServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.IngressServerExposer) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) ArgumentCaptor(org.mockito.ArgumentCaptor) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Map(java.util.Map) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) Collections.singletonMap(java.util.Collections.singletonMap) Service(io.fabric8.kubernetes.api.model.Service) Assert.assertFalse(org.testng.Assert.assertFalse) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) ArgumentMatchers.isNull(org.mockito.ArgumentMatchers.isNull) DISCOVERABLE_SERVER_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.ServerConfig.DISCOVERABLE_SERVER_ATTRIBUTE) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeMethod(org.testng.annotations.BeforeMethod) Pod(io.fabric8.kubernetes.api.model.Pod) Mockito.times(org.mockito.Mockito.times) SecureServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.SecureServerExposer) Assert.assertNotNull(org.testng.Assert.assertNotNull) Mockito.verify(org.mockito.Mockito.verify) ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) SERVER_UNIQUE_PART_SIZE(org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer.SERVER_UNIQUE_PART_SIZE) Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) SERVER_PREFIX(org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer.SERVER_PREFIX) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) Entry(java.util.Map.Entry) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) Assert.assertTrue(org.testng.Assert.assertTrue) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) Service(io.fabric8.kubernetes.api.model.Service)

Example 4 with SecureServerExposer

use of org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.SecureServerExposer in project devspaces-images by redhat-developer.

the class KubernetesServerExposerTest method assertThatSecureServerIsExposed.

@SuppressWarnings("SameParameterValue")
private void assertThatSecureServerIsExposed(String machineName, String portProtocol, Integer port, String serverName, ServerConfig serverConfig) throws Exception {
    // then
    assertThatContainerPortIsExposed(portProtocol, port);
    // ensure that service is created
    Service service = findContainerRelatedService();
    assertNotNull(service);
    // ensure that no service port is exposed
    assertTrue(service.getSpec().getPorts().stream().noneMatch(p -> p.getTargetPort().getIntVal().equals(port)));
    ServicePort servicePort = new ServicePortBuilder().withName("server-" + port).withPort(port).withProtocol(portProtocol.toUpperCase()).withNewTargetPort(port).build();
    verify(secureServerExposer).expose(eq(kubernetesEnvironment), any(), eq(machineName), // no service exists for the backed server
    isNull(), // a non-unique server
    isNull(), eq(servicePort), eq(ImmutableMap.of(serverName, serverConfig)));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Listeners(org.testng.annotations.Listeners) Container(io.fabric8.kubernetes.api.model.Container) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Assert.assertEquals(org.testng.Assert.assertEquals) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) KubernetesEnvironment(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) Test(org.testng.annotations.Test) SERVER_NAME_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.ServerConfig.SERVER_NAME_ATTRIBUTE) IngressServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.external.IngressServerExposer) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) ArgumentCaptor(org.mockito.ArgumentCaptor) PodBuilder(io.fabric8.kubernetes.api.model.PodBuilder) Map(java.util.Map) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) Collections.singletonMap(java.util.Collections.singletonMap) Service(io.fabric8.kubernetes.api.model.Service) Assert.assertFalse(org.testng.Assert.assertFalse) ServerConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ServerConfigImpl) ArgumentMatchers.isNull(org.mockito.ArgumentMatchers.isNull) DISCOVERABLE_SERVER_ATTRIBUTE(org.eclipse.che.api.core.model.workspace.config.ServerConfig.DISCOVERABLE_SERVER_ATTRIBUTE) MockitoTestNGListener(org.mockito.testng.MockitoTestNGListener) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeMethod(org.testng.annotations.BeforeMethod) Pod(io.fabric8.kubernetes.api.model.Pod) Mockito.times(org.mockito.Mockito.times) SecureServerExposer(org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.SecureServerExposer) Assert.assertNotNull(org.testng.Assert.assertNotNull) Mockito.verify(org.mockito.Mockito.verify) ServerConfig(org.eclipse.che.api.core.model.workspace.config.ServerConfig) SERVER_UNIQUE_PART_SIZE(org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer.SERVER_UNIQUE_PART_SIZE) Annotations(org.eclipse.che.workspace.infrastructure.kubernetes.Annotations) SERVER_PREFIX(org.eclipse.che.workspace.infrastructure.kubernetes.server.KubernetesServerExposer.SERVER_PREFIX) InfrastructureException(org.eclipse.che.api.workspace.server.spi.InfrastructureException) Entry(java.util.Map.Entry) PodData(org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment.PodData) Assert.assertTrue(org.testng.Assert.assertTrue) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) ServicePort(io.fabric8.kubernetes.api.model.ServicePort) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) Service(io.fabric8.kubernetes.api.model.Service)

Aggregations

KubernetesEnvironment (org.eclipse.che.workspace.infrastructure.kubernetes.environment.KubernetesEnvironment)4 SecureServerExposer (org.eclipse.che.workspace.infrastructure.kubernetes.server.secure.SecureServerExposer)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 TypeLiteral (com.google.inject.TypeLiteral)2 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)2 Container (io.fabric8.kubernetes.api.model.Container)2 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)2 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)2 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)2 Pod (io.fabric8.kubernetes.api.model.Pod)2 PodBuilder (io.fabric8.kubernetes.api.model.PodBuilder)2 Service (io.fabric8.kubernetes.api.model.Service)2 ServicePort (io.fabric8.kubernetes.api.model.ServicePort)2 ServicePortBuilder (io.fabric8.kubernetes.api.model.ServicePortBuilder)2 ArrayList (java.util.ArrayList)2 Collections.singletonList (java.util.Collections.singletonList)2 Collections.singletonMap (java.util.Collections.singletonMap)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Optional (java.util.Optional)2