mirror of
https://github.com/floci-io/floci.git
synced 2026-12-03 10:17:48 -05:00
refactor(docker): read the Docker host override from floci.docker.host-override (#10025)
The Docker host override every container Floci starts relies on was read from the Lambda section by core classes. floci.docker.host-override (env FLOCI_DOCKER_HOST_OVERRIDE) is now the key, read through EmulatorConfig.effectiveDockerHostOverride() by DockerHostResolver and TlsProxyServer. It wins when set and not blank; otherwise the former floci.services.lambda.docker-host-override still applies, giving every reader the value it gave before, and its first use logs a deprecation warning. The docs say which key wins and that the self-signed TLS certificate does not name the override.
This commit is contained in:
1 parent
2a2c51abe5
commit
5fffd9f3a8
19 files changed
+358
-31
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package io.floci.aws.config;
|
||||
|
||||
import io.floci.aws.core.common.docker.DockerHostOverride;
|
||||
import io.smallrye.config.ConfigMapping;
|
||||
import io.smallrye.config.WithDefault;
|
||||
|
||||
@@ -57,6 +58,17 @@ public interface EmulatorConfig {
|
||||
.orElseGet(() -> URI.create(effectiveBaseUrl()).getAuthority());
|
||||
}
|
||||
|
||||
/**
|
||||
* The address containers Floci starts use to reach it, when one is configured: {@code
|
||||
* floci.docker.host-override}, or else the deprecated {@code
|
||||
* floci.services.lambda.docker-host-override}, whose first use logs a warning. Empty when
|
||||
* neither is set; a blank value is returned as configured, and callers treat it as unset.
|
||||
*/
|
||||
default Optional<String> effectiveDockerHostOverride() {
|
||||
return DockerHostOverride.resolve(docker().hostOverride().orElse(null),
|
||||
services().lambda().dockerHostOverride().orElse(null));
|
||||
}
|
||||
|
||||
@WithDefault("us-east-1") // partition-literal: the configurable default region
|
||||
String defaultRegion();
|
||||
|
||||
@@ -3738,6 +3750,11 @@ public interface EmulatorConfig {
|
||||
@WithDefault("1")
|
||||
long durableSweepIntervalSeconds();
|
||||
|
||||
/**
|
||||
* Deprecated: use {@code floci.docker.host-override}, which wins when both are set. Still
|
||||
* honoured when that key is unset, with a warning. Read it only through
|
||||
* {@link EmulatorConfig#effectiveDockerHostOverride()}.
|
||||
*/
|
||||
Optional<String> dockerHostOverride();
|
||||
|
||||
/**
|
||||
@@ -4753,6 +4770,18 @@ public interface EmulatorConfig {
|
||||
@WithDefault("false")
|
||||
boolean allowSshHost();
|
||||
|
||||
/**
|
||||
* The address containers Floci starts use to reach it, instead of the detected one (this
|
||||
* container's IP when Floci runs in Docker, {@code host.docker.internal} on the host). The
|
||||
* self-signed TLS certificate does not name it. Env var: {@code FLOCI_DOCKER_HOST_OVERRIDE}.
|
||||
*
|
||||
* <p>Read through {@link EmulatorConfig#effectiveDockerHostOverride()}. The former key
|
||||
* {@code floci.services.lambda.docker-host-override} (env
|
||||
* {@code FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE}) still works when this one is unset, but
|
||||
* is deprecated.
|
||||
*/
|
||||
Optional<String> hostOverride();
|
||||
|
||||
/**
|
||||
* Size of the connection pool behind the shared Docker client. Every short Docker call
|
||||
* leases a connection from it; streams that stay open while a container or a command runs
|
||||
|
||||
@@ -123,7 +123,7 @@ public class TlsCertificateManager implements Resettable {
|
||||
* Whether the certificate Floci serves names {@code host}, exactly or under a one-label
|
||||
* wildcard, so a client that verifies the name accepts it: the managed leaf with every name it
|
||||
* learned, or a user-provided certificate as it is on disk. False with TLS off, for a host it
|
||||
* does not name, such as an IP from {@code docker-host-override} or the container-IP fallback,
|
||||
* does not name, such as an IP from {@code docker.host-override} or the container-IP fallback,
|
||||
* and when the certificate cannot be read.
|
||||
*/
|
||||
public boolean serves(String host) {
|
||||
|
||||
@@ -259,7 +259,7 @@ public class TlsProxyServer {
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOG.debugv(e, "TLS proxy: cannot read the hostname from floci.base-url");
|
||||
}
|
||||
config.services().lambda().dockerHostOverride().map(TlsProxyServer::normalizeHost).ifPresent(endpointHosts::add);
|
||||
config.effectiveDockerHostOverride().map(TlsProxyServer::normalizeHost).ifPresent(endpointHosts::add);
|
||||
config.services().iot().endpointAddress().filter(address -> !address.isBlank()).ifPresent(address -> {
|
||||
try {
|
||||
String iotHost = TlsConfigSource.iotEndpointHost(address);
|
||||
|
||||
@@ -97,7 +97,7 @@ public class ContainerReachableEndpoint {
|
||||
* TLS enabled, {@code TlsProxyServer} serves https beside http on {@link EmulatorConfig#port()},
|
||||
* and every container Floci launches trusts Floci's CA through {@code NODE_EXTRA_CA_CERTS} and
|
||||
* the other bundle variables, so the https URL is reachable with no shim in the handler. A host
|
||||
* the certificate does not name, an IP from {@code docker-host-override} or the container-IP
|
||||
* the certificate does not name, an IP from {@code docker.host-override} or the container-IP
|
||||
* fallback when the embedded DNS server cannot start, would fail the handler's certificate
|
||||
* check where http works, so that URL stays http.
|
||||
*/
|
||||
@@ -108,7 +108,7 @@ public class ContainerReachableEndpoint {
|
||||
/**
|
||||
* {@link #baseUrl(boolean)} over https, when Floci serves TLS under a certificate that names its host, so
|
||||
* a client that verifies the name accepts it. Empty otherwise: with TLS off, or for a host the certificate
|
||||
* does not name, such as an IP from {@code docker-host-override}, the container-IP fallback, or a
|
||||
* does not name, such as an IP from {@code docker.host-override}, the container-IP fallback, or a
|
||||
* name a user-provided certificate was not issued for.
|
||||
*/
|
||||
public Optional<String> httpsBaseUrl(boolean useEmbeddedDns) {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package io.floci.aws.core.common.docker;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* Which configured address containers Floci starts use to reach it.
|
||||
*
|
||||
* <p>{@code floci.docker.host-override} is the key. The former
|
||||
* {@code floci.services.lambda.docker-host-override} still works when that key is unset, and a
|
||||
* deprecation warning is logged the first time it is used. When both are set the new key wins.
|
||||
* The configuration reads both keys and asks this class which one applies, see
|
||||
* {@code EmulatorConfig.effectiveDockerHostOverride()}.
|
||||
*/
|
||||
public final class DockerHostOverride {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(DockerHostOverride.class);
|
||||
|
||||
static final String KEY = "floci.docker.host-override";
|
||||
static final String LEGACY_KEY = "floci.services.lambda.docker-host-override";
|
||||
|
||||
private static final AtomicBoolean LEGACY_KEY_WARNED = new AtomicBoolean();
|
||||
|
||||
private DockerHostOverride() {
|
||||
}
|
||||
|
||||
/**
|
||||
* The override that applies, given the value of each key (null when unset). A blank value is
|
||||
* returned as it was configured; callers treat it as unset.
|
||||
*/
|
||||
public static Optional<String> resolve(String override, String legacyOverride) {
|
||||
return resolve(override, legacyOverride, LEGACY_KEY_WARNED);
|
||||
}
|
||||
|
||||
static Optional<String> resolve(String override, String legacyOverride, AtomicBoolean legacyKeyWarned) {
|
||||
if (override != null && !override.isBlank()) {
|
||||
return Optional.of(override);
|
||||
}
|
||||
if (legacyOverride != null) {
|
||||
if (!legacyOverride.isBlank() && legacyKeyWarned.compareAndSet(false, true)) {
|
||||
LOG.warnv("{0} is deprecated and will be removed in a future release; set {1} "
|
||||
+ "(env FLOCI_DOCKER_HOST_OVERRIDE) instead", LEGACY_KEY, KEY);
|
||||
}
|
||||
return Optional.of(legacyOverride);
|
||||
}
|
||||
return Optional.ofNullable(override);
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class DockerHostResolver {
|
||||
}
|
||||
|
||||
public String resolve() {
|
||||
Optional<String> override = config.services().lambda().dockerHostOverride();
|
||||
Optional<String> override = config.effectiveDockerHostOverride();
|
||||
if (override.isPresent() && !override.get().isBlank()) {
|
||||
LOG.debugv("Using configured docker host override: {0}", override.get());
|
||||
return override.get();
|
||||
@@ -95,7 +95,7 @@ public class DockerHostResolver {
|
||||
* the address {@link #resolve()} gives.
|
||||
*/
|
||||
public String resolveOn(String network) {
|
||||
Optional<String> override = config.services().lambda().dockerHostOverride();
|
||||
Optional<String> override = config.effectiveDockerHostOverride();
|
||||
if ((override.isEmpty() || override.get().isBlank()) && currentContainerNetworkResolver != null
|
||||
&& containerDetector.isRunningInContainer()) {
|
||||
Optional<String> address = currentContainerNetworkResolver.resolveContainerIpOn(network);
|
||||
|
||||
@@ -481,6 +481,12 @@ floci:
|
||||
# step with the @WithDefault on EmulatorConfig.DockerConfig.logDriverPort.
|
||||
log-driver-port: 12201
|
||||
resource-namespace: "" # FLOCI_DOCKER_RESOURCE_NAMESPACE; scopes child container/volume names
|
||||
# FLOCI_DOCKER_HOST_OVERRIDE: the address containers Floci starts use to reach it, instead of the
|
||||
# detected one (this container's IP in Docker, host.docker.internal on the host). The self-signed
|
||||
# TLS certificate does not name it. Unset by default. The former floci.services.lambda.docker-host-override
|
||||
# (FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE) still works when this is unset, with a deprecation
|
||||
# warning; this key wins when both are set.
|
||||
# host-override: floci
|
||||
docker-config-path: ""
|
||||
# extra-labels: # Extra Docker labels applied to every Floci-created container and volume
|
||||
# - key: "com.example.project" # (FLOCI_DOCKER_EXTRA_LABELS_0__KEY / _0__VALUE; increment the index for more;
|
||||
|
||||
@@ -21,6 +21,8 @@ import java.net.Socket;
|
||||
import java.net.SocketException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@@ -82,6 +84,8 @@ class TlsProxyServerTest {
|
||||
when(config.services()).thenReturn(mock(EmulatorConfig.ServicesConfig.class));
|
||||
when(config.services().lambda()).thenReturn(mock(EmulatorConfig.LambdaServiceConfig.class));
|
||||
when(config.services().iot()).thenReturn(mock(EmulatorConfig.IotServiceConfig.class));
|
||||
when(config.docker()).thenReturn(mock(EmulatorConfig.DockerConfig.class));
|
||||
when(config.effectiveDockerHostOverride()).thenCallRealMethod();
|
||||
when(config.tls()).thenReturn(tls);
|
||||
when(tls.enabled()).thenReturn(tlsEnabled);
|
||||
when(tls.awsHttpsPort()).thenReturn(awsHttpsPort);
|
||||
@@ -369,6 +373,51 @@ class TlsProxyServerTest {
|
||||
}
|
||||
}
|
||||
|
||||
/** The Docker host override is a name Floci serves, read from either key, the Docker key first. */
|
||||
@Test
|
||||
@Timeout(30)
|
||||
void awsHttpsPort_servesTheDockerHostOverrideFromEitherKey() throws Exception {
|
||||
assertEquals(Set.of("docker.override.test"), overridesFlociServes("docker.override.test", null));
|
||||
assertEquals(Set.of("lambda.override.test"), overridesFlociServes(null, "lambda.override.test"));
|
||||
assertEquals(Set.of("docker.override.test"),
|
||||
overridesFlociServes("docker.override.test", "lambda.override.test"));
|
||||
}
|
||||
|
||||
private Set<String> overridesFlociServes(String dockerHostOverride, String lambdaDockerHostOverride)
|
||||
throws Exception {
|
||||
httpBackend = startMarkerBackend("PLAIN");
|
||||
httpsBackend = startMarkerBackend("TLS");
|
||||
NetServer albBackend = startMarkerBackend("ALB");
|
||||
try {
|
||||
int[] ports = FreePorts.anyInterfacePorts(2);
|
||||
int awsHttpsPort = ports[1];
|
||||
EmulatorConfig config = configWith(true, ports[0], awsHttpsPort);
|
||||
when(config.docker().hostOverride()).thenReturn(Optional.ofNullable(dockerHostOverride));
|
||||
when(config.services().lambda().dockerHostOverride())
|
||||
.thenReturn(Optional.ofNullable(lambdaDockerHostOverride));
|
||||
proxy = new TlsProxyServer(vertx, config, "127.0.0.1",
|
||||
httpBackend.actualPort(), httpsBackend.actualPort());
|
||||
proxy.routeServerNames(port -> true, (port, name, allowAliases) -> port == awsHttpsPort
|
||||
? new ServerNameTarget(albBackend.actualPort(), "listener") : null);
|
||||
|
||||
Set<String> served = new HashSet<>();
|
||||
for (String name : List.of("docker.override.test", "lambda.override.test")) {
|
||||
if ("TLS".equals(roundTrip(awsHttpsPort, TlsClientHelloTest.clientHello(name).getBytes()))) {
|
||||
served.add(name);
|
||||
}
|
||||
}
|
||||
return served;
|
||||
} finally {
|
||||
proxy.stop();
|
||||
proxy = null;
|
||||
closeBackend(albBackend);
|
||||
closeBackend(httpBackend);
|
||||
closeBackend(httpsBackend);
|
||||
httpBackend = null;
|
||||
httpsBackend = null;
|
||||
}
|
||||
}
|
||||
|
||||
private NetServer startMarkerBackend(String marker) throws Exception {
|
||||
NetServer server = vertx.createNetServer();
|
||||
server.connectHandler(sock -> sock.write(marker));
|
||||
|
||||
@@ -123,7 +123,7 @@ class ContainerReachableEndpointTest {
|
||||
@Test
|
||||
void customResourceResponseUrlStaysHttpForAnIpTheCertificateDoesNotName() {
|
||||
// The container-IP fallback when the embedded DNS server cannot start, or an IP set as
|
||||
// docker-host-override: the leaf does not name it, so a handler verifying the certificate
|
||||
// docker.host-override: the leaf does not name it, so a handler verifying the certificate
|
||||
// would refuse https where http works.
|
||||
when(tls.enabled()).thenReturn(true);
|
||||
when(config.port()).thenReturn(4566);
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package io.floci.aws.core.common.docker;
|
||||
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.testing.ParallelLocks;
|
||||
import io.smallrye.config.EnvConfigSource;
|
||||
import io.smallrye.config.SmallRyeConfig;
|
||||
import io.smallrye.config.SmallRyeConfigBuilder;
|
||||
import io.smallrye.config.source.yaml.YamlConfigSource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.parallel.ResourceLock;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/** Both environment variables bind to their keys in the shipped configuration. */
|
||||
@ResourceLock(ParallelLocks.TLS_CONFIG)
|
||||
@ResourceLock(ParallelLocks.CONFIG_MAPPING)
|
||||
class DockerHostOverrideConfigTest {
|
||||
|
||||
@Test
|
||||
void unsetByDefault() throws IOException {
|
||||
assertEquals(Optional.empty(), config(Map.of()).effectiveDockerHostOverride());
|
||||
}
|
||||
|
||||
@Test
|
||||
void theDockerVariableSetsTheDockerKey() throws IOException {
|
||||
EmulatorConfig config = config(Map.of("FLOCI_DOCKER_HOST_OVERRIDE", "floci.docker"));
|
||||
|
||||
assertEquals(Optional.of("floci.docker"), config.docker().hostOverride());
|
||||
assertEquals(Optional.of("floci.docker"), config.effectiveDockerHostOverride());
|
||||
}
|
||||
|
||||
@Test
|
||||
void theLambdaVariableStillSetsTheOverride() throws IOException {
|
||||
EmulatorConfig config = config(Map.of("FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE", "floci.lambda"));
|
||||
|
||||
assertEquals(Optional.empty(), config.docker().hostOverride());
|
||||
assertEquals(Optional.of("floci.lambda"), config.effectiveDockerHostOverride());
|
||||
}
|
||||
|
||||
@Test
|
||||
void theDockerVariableWinsOverTheLambdaVariable() throws IOException {
|
||||
EmulatorConfig config = config(Map.of(
|
||||
"FLOCI_DOCKER_HOST_OVERRIDE", "floci.docker",
|
||||
"FLOCI_SERVICES_LAMBDA_DOCKER_HOST_OVERRIDE", "floci.lambda"));
|
||||
|
||||
assertEquals(Optional.of("floci.docker"), config.effectiveDockerHostOverride());
|
||||
}
|
||||
|
||||
private static EmulatorConfig config(Map<String, String> env) throws IOException {
|
||||
SmallRyeConfig config = new SmallRyeConfigBuilder()
|
||||
.addDefaultInterceptors()
|
||||
.withMapping(EmulatorConfig.class)
|
||||
.withSources(new YamlConfigSource(Path.of("src/main/resources/application.yml").toUri().toURL()))
|
||||
.withSources(new EnvConfigSource(env, 300))
|
||||
.build();
|
||||
return config.getConfigMapping(EmulatorConfig.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package io.floci.aws.core.common.docker;
|
||||
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.testutil.LogCapture;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
class DockerHostOverrideTest {
|
||||
|
||||
@Test
|
||||
void onlyTheDockerKeyIsUsedWithoutAWarning() {
|
||||
AtomicBoolean warned = new AtomicBoolean();
|
||||
List<LogRecord> records = LogCapture.captureFromThisThread(DockerHostOverride.class,
|
||||
() -> assertEquals(Optional.of("floci.docker"),
|
||||
DockerHostOverride.resolve("floci.docker", null, warned)));
|
||||
|
||||
assertTrue(records.isEmpty(), () -> "unexpected log lines: " + records);
|
||||
}
|
||||
|
||||
@Test
|
||||
void onlyTheLambdaKeyIsStillUsedAndWarnsOnce() {
|
||||
AtomicBoolean warned = new AtomicBoolean();
|
||||
List<LogRecord> records = LogCapture.captureFromThisThread(DockerHostOverride.class, () -> {
|
||||
assertEquals(Optional.of("floci.lambda"), DockerHostOverride.resolve(null, "floci.lambda", warned));
|
||||
assertEquals(Optional.of("floci.lambda"), DockerHostOverride.resolve(null, "floci.lambda", warned));
|
||||
assertEquals(Optional.of("floci.lambda"), DockerHostOverride.resolve(" ", "floci.lambda", warned));
|
||||
});
|
||||
|
||||
assertEquals(1, records.size(), () -> "expected one deprecation warning: " + records);
|
||||
assertEquals(Level.WARNING, records.getFirst().getLevel());
|
||||
String message = LogCapture.formatted(records.getFirst());
|
||||
assertThat(message, containsString("floci.services.lambda.docker-host-override is deprecated"));
|
||||
assertThat(message, containsString("floci.docker.host-override"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theDockerKeyWinsOverTheLambdaKeyWithoutAWarning() {
|
||||
AtomicBoolean warned = new AtomicBoolean();
|
||||
List<LogRecord> records = LogCapture.captureFromThisThread(DockerHostOverride.class,
|
||||
() -> assertEquals(Optional.of("floci.docker"),
|
||||
DockerHostOverride.resolve("floci.docker", "floci.lambda", warned)));
|
||||
|
||||
assertTrue(records.isEmpty(), () -> "unexpected log lines: " + records);
|
||||
}
|
||||
|
||||
@Test
|
||||
void neitherKeyIsEmpty() {
|
||||
assertEquals(Optional.empty(), DockerHostOverride.resolve(null, null, new AtomicBoolean()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void readsBothKeysFromTheConfig() {
|
||||
assertEquals(Optional.of("floci.docker"), config("floci.docker", null).effectiveDockerHostOverride());
|
||||
assertEquals(Optional.of("floci.lambda"), config(null, "floci.lambda").effectiveDockerHostOverride());
|
||||
assertEquals(Optional.of("floci.docker"), config("floci.docker", "floci.lambda").effectiveDockerHostOverride());
|
||||
assertEquals(Optional.empty(), config(null, null).effectiveDockerHostOverride());
|
||||
}
|
||||
|
||||
private static EmulatorConfig config(String hostOverride, String lambdaDockerHostOverride) {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
EmulatorConfig.DockerConfig docker = mock(EmulatorConfig.DockerConfig.class);
|
||||
EmulatorConfig.ServicesConfig services = mock(EmulatorConfig.ServicesConfig.class);
|
||||
EmulatorConfig.LambdaServiceConfig lambda = mock(EmulatorConfig.LambdaServiceConfig.class);
|
||||
when(config.docker()).thenReturn(docker);
|
||||
when(config.services()).thenReturn(services);
|
||||
when(services.lambda()).thenReturn(lambda);
|
||||
when(docker.hostOverride()).thenReturn(Optional.ofNullable(hostOverride));
|
||||
when(lambda.dockerHostOverride()).thenReturn(Optional.ofNullable(lambdaDockerHostOverride));
|
||||
when(config.effectiveDockerHostOverride()).thenCallRealMethod();
|
||||
return config;
|
||||
}
|
||||
}
|
||||
@@ -13,16 +13,10 @@ class DockerHostResolverTest {
|
||||
|
||||
@Test
|
||||
void resolve_usesDetectedContainerNetworkIpWhenRunningInContainer() {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
EmulatorConfig config = config(null);
|
||||
ContainerDetector containerDetector = mock(ContainerDetector.class);
|
||||
CurrentContainerNetworkResolver currentContainerNetworkResolver =
|
||||
mock(CurrentContainerNetworkResolver.class);
|
||||
|
||||
EmulatorConfig.ServicesConfig services = mock(EmulatorConfig.ServicesConfig.class);
|
||||
EmulatorConfig.LambdaServiceConfig lambda = mock(EmulatorConfig.LambdaServiceConfig.class);
|
||||
when(config.services()).thenReturn(services);
|
||||
when(services.lambda()).thenReturn(lambda);
|
||||
when(lambda.dockerHostOverride()).thenReturn(Optional.empty());
|
||||
when(containerDetector.isRunningInContainer()).thenReturn(true);
|
||||
when(currentContainerNetworkResolver.resolveContainerIp()).thenReturn(Optional.of("172.24.0.2"));
|
||||
|
||||
@@ -80,13 +74,55 @@ class DockerHostResolverTest {
|
||||
currentContainerNetworkResolver).resolveOn("rds-net"));
|
||||
}
|
||||
|
||||
private static EmulatorConfig config(String dockerHostOverride) {
|
||||
@Test
|
||||
void resolve_usesTheDockerHostOverrideKey() {
|
||||
DockerHostResolver resolver = inContainerResolver(config("floci.docker", null));
|
||||
|
||||
assertEquals("floci.docker", resolver.resolve());
|
||||
assertEquals("floci.docker", resolver.resolveOn("rds-net"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolve_stillUsesTheLambdaKeyWhenTheDockerKeyIsUnset() {
|
||||
DockerHostResolver resolver = inContainerResolver(config(null, "floci.lambda"));
|
||||
|
||||
assertEquals("floci.lambda", resolver.resolve());
|
||||
assertEquals("floci.lambda", resolver.resolveOn("rds-net"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolve_prefersTheDockerKeyOverTheLambdaKey() {
|
||||
DockerHostResolver resolver = inContainerResolver(config("floci.docker", "floci.lambda"));
|
||||
|
||||
assertEquals("floci.docker", resolver.resolve());
|
||||
assertEquals("floci.docker", resolver.resolveOn("rds-net"));
|
||||
}
|
||||
|
||||
private static DockerHostResolver inContainerResolver(EmulatorConfig config) {
|
||||
ContainerDetector inContainer = mock(ContainerDetector.class);
|
||||
CurrentContainerNetworkResolver currentContainerNetworkResolver =
|
||||
mock(CurrentContainerNetworkResolver.class);
|
||||
when(inContainer.isRunningInContainer()).thenReturn(true);
|
||||
when(currentContainerNetworkResolver.resolveContainerIp()).thenReturn(Optional.of("172.24.0.2"));
|
||||
when(currentContainerNetworkResolver.resolveContainerIpOn("rds-net")).thenReturn(Optional.of("172.30.0.5"));
|
||||
return new DockerHostResolver(config, inContainer, currentContainerNetworkResolver);
|
||||
}
|
||||
|
||||
private static EmulatorConfig config(String hostOverride) {
|
||||
return config(hostOverride, null);
|
||||
}
|
||||
|
||||
private static EmulatorConfig config(String hostOverride, String lambdaDockerHostOverride) {
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
EmulatorConfig.DockerConfig docker = mock(EmulatorConfig.DockerConfig.class);
|
||||
EmulatorConfig.ServicesConfig services = mock(EmulatorConfig.ServicesConfig.class);
|
||||
EmulatorConfig.LambdaServiceConfig lambda = mock(EmulatorConfig.LambdaServiceConfig.class);
|
||||
when(config.docker()).thenReturn(docker);
|
||||
when(config.services()).thenReturn(services);
|
||||
when(services.lambda()).thenReturn(lambda);
|
||||
when(lambda.dockerHostOverride()).thenReturn(Optional.ofNullable(dockerHostOverride));
|
||||
when(docker.hostOverride()).thenReturn(Optional.ofNullable(hostOverride));
|
||||
when(lambda.dockerHostOverride()).thenReturn(Optional.ofNullable(lambdaDockerHostOverride));
|
||||
when(config.effectiveDockerHostOverride()).thenCallRealMethod();
|
||||
return config;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -184,7 +184,7 @@ class CloudFormationCustomResourceHttpsResponseUrlIntegrationTest {
|
||||
overrides.put("quarkus.http.test-port", "4510");
|
||||
overrides.put("quarkus.http.test-ssl-port", "4511");
|
||||
overrides.put("floci.port", String.valueOf(FLOCI_PORT));
|
||||
overrides.put("floci.services.lambda.docker-host-override", "localhost");
|
||||
overrides.put("floci.docker.host-override", "localhost");
|
||||
return overrides;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,11 @@ io.floci.aws.config.TlsCertificateManager io.floci.aws.services.acm.model.KeyAlg
|
||||
io.floci.aws.config.TlsConfigSource io.floci.aws.services.acm.CertificateGenerator
|
||||
io.floci.aws.config.TlsConfigSource io.floci.aws.services.acm.model.KeyAlgorithm
|
||||
io.floci.aws.config.TlsProxyServer services().iot()
|
||||
io.floci.aws.config.TlsProxyServer services().lambda()
|
||||
io.floci.aws.core.common.docker.ContainerBuilder io.floci.aws.services.lambda.launcher.ImageCacheService
|
||||
io.floci.aws.core.common.docker.ContainerLifecycleManager EcsServiceConfig
|
||||
io.floci.aws.core.common.docker.ContainerLifecycleManager io.floci.aws.services.lambda.launcher.ImageCacheService
|
||||
io.floci.aws.core.common.docker.ContainerLifecycleManager io.floci.aws.services.lambda.launcher.ImageCacheService.LaunchImage
|
||||
io.floci.aws.core.common.docker.ContainerLogStreamer io.floci.aws.services.cloudwatch.logs.CloudWatchLogsService
|
||||
io.floci.aws.core.common.docker.DockerHostResolver services().lambda()
|
||||
io.floci.aws.core.common.docker.LaunchedContainerAwsEnv io.floci.aws.services.iam.model.SessionCreds
|
||||
io.floci.aws.core.common.port.PortAllocator services().lambda()
|
||||
io.floci.aws.lifecycle.EmulatorInfoController io.floci.aws.services.dynamodb.backend.DynamoDbBackendSelector
|
||||
|
||||
|
Reference in new issue
Block a user