GatewayTlsProvisioner implements ConfigurationProvisioner<T>, TlsProvisioner<T> { @Override public void provision(T k8sEnv, RuntimeIdentity identity) throws InfrastructureException { if (!isTlsEnabled) { return; } for (ConfigMap configMap : k8sEnv.getConfigMaps().values()) { if (configmapLabels.isGatewayConfig(configMap)) { useSecureProtocolForGatewayConfigMap(configMap); } } } @Inject  GatewayTlsProvisioner(
      @Named("che.infra.kubernetes.tls_enabled") boolean isTlsEnabled,
      GatewayConfigmapLabels configmapLabels); @Override void provision(T k8sEnv, RuntimeIdentity identity);  }
@Test(dataProvider = "tlsProvisionData") public void provisionTlsForGatewayRouteConfigmaps( ServerConfigImpl server, boolean tlsEnabled, String expectedProtocol) throws Exception { Map<String, String> composedAnnotations = new HashMap<>(annotations); composedAnnotations.putAll( Annotations.newSerializer().server("server", server).machineName(machine).annotations()); ConfigMap routeConfigMap = new ConfigMapBuilder() .withNewMetadata() .withName("route") .withAnnotations(composedAnnotations) .endMetadata() .build(); GatewayTlsProvisioner<KubernetesEnvironment> gatewayTlsProvisioner = new GatewayTlsProvisioner<>(tlsEnabled, gatewayConfigmapLabels); when(k8sEnv.getConfigMaps()).thenReturn(singletonMap("route", routeConfigMap)); gatewayTlsProvisioner.provision(k8sEnv, runtimeIdentity); Map<String, ServerConfigImpl> servers = Annotations.newDeserializer(routeConfigMap.getMetadata().getAnnotations()).servers(); assertEquals(servers.get("server").getProtocol(), expectedProtocol); }
@Test(expectedExceptions = InfrastructureException.class) public void throwExceptionWhenMultipleServersInGatewayRouteConfigAnnotations() throws InfrastructureException { Map<String, String> composedAnnotations = new HashMap<>(annotations); composedAnnotations.putAll( Annotations.newSerializer() .server("server1", httpServer) .server("server2", wsServer) .machineName(machine) .annotations()); ConfigMap routeConfigMap = new ConfigMapBuilder() .withNewMetadata() .withName("route") .withAnnotations(composedAnnotations) .endMetadata() .build(); when(k8sEnv.getConfigMaps()).thenReturn(singletonMap("route", routeConfigMap)); GatewayTlsProvisioner<KubernetesEnvironment> gatewayTlsProvisioner = new GatewayTlsProvisioner<>(true, gatewayConfigmapLabels); gatewayTlsProvisioner.provision(k8sEnv, runtimeIdentity); }