refactor(config): move max-request-size and ecr-base-uri into sub-mappings (#2902)

floci.max-request-size and floci.ecr-base-uri sat at the config root but
belong with related settings. Relocate them:

- max-request-size -> floci.protocols.max-request-size (ProtocolsConfig)
- ecr-base-uri      -> floci.services.lambda.ecr-base-uri (LambdaServiceConfig)

A new FlociConfigRelocationsInterceptor (SmallRye ConfigSourceInterceptor,
registered via META-INF/services) keeps the old flat keys and their
FLOCI_MAX_REQUEST_SIZE / FLOCI_ECR_BASE_URI env vars working: the legacy key
is consulted when the new key is requested, and iterateNames() rewrites it so
config-mapping validation does not flag it as unknown. Future relocations are
one entry in its RELOCATIONS list.

ImageResolver, both application.yml files, the affected tests and the
configuration docs are updated to the new keys.
This commit is contained in:
Christian Franzen authored and GitHub committed 2026-09-02 18:14:55 -04:00
1 parent 4ca8c42470
commit 39b19d1c92
13 files changed
+224 -31

No files matched your search

@@ -51,12 +51,6 @@ public interface EmulatorConfig {
@WithDefault("000000000000")
String defaultAccountId();
@WithDefault("2048")
int maxRequestSize();
@WithDefault("public.ecr.aws")
String ecrBaseUri();
/**
* Path to a shared mock-response configuration file used by the fixed-stub AI services
* (Textract, Comprehend, Rekognition) to return a caller-configured response instead of
@@ -86,6 +80,17 @@ public interface EmulatorConfig {
ProtocolsConfig protocols();
interface ProtocolsConfig {
/**
* Maximum HTTP request body size, in megabytes. Feeds
* {@code quarkus.http.limits.max-body-size} in {@code application.yml}.
*
* <p>Moved here from the {@code floci} root in 2.x. The former flat key
* {@code floci.max-request-size} (env {@code FLOCI_MAX_REQUEST_SIZE}) still works
* (see {@link FlociConfigRelocationsInterceptor}), but is deprecated.
*/
@WithDefault("2048")
int maxRequestSize();
/**
* When enabled, requests carrying an RPC protocol signal that no
* supported wire protocol claims are rejected per the Smithy
@@ -584,7 +589,7 @@ public interface EmulatorConfig {
@WithDefault("5000")
long flushIntervalMs();
}
interface CodeDeployStorageConfig {
Optional<String> mode();
@@ -812,7 +817,7 @@ public interface EmulatorConfig {
@WithDefault("true")
boolean enabled();
}
interface EfsServiceConfig {
@WithDefault("true")
boolean enabled();
@@ -1792,6 +1797,18 @@ public interface EmulatorConfig {
@WithDefault("true")
boolean enabled();
/**
* Registry host (optionally with a path prefix) that Lambda runtime images are pulled
* from, e.g. {@code public.ecr.aws} produces {@code public.ecr.aws/lambda/python:3.12}.
* Point it at a private mirror to avoid depending on ECR Public.
*
* <p>Moved here from the {@code floci} root in 2.x. The former flat key
* {@code floci.ecr-base-uri} (env {@code FLOCI_ECR_BASE_URI}) still works
* (see {@link FlociConfigRelocationsInterceptor}), but is deprecated.
*/
@WithDefault("public.ecr.aws")
String ecrBaseUri();
@WithDefault("128")
int defaultMemoryMb();
@@ -0,0 +1,98 @@
package io.github.hectorvent.floci.config;
import io.smallrye.config.ConfigSourceInterceptor;
import io.smallrye.config.ConfigSourceInterceptorContext;
import io.smallrye.config.ConfigValue;
import io.smallrye.config.Priorities;
import jakarta.annotation.Priority;
import java.io.Serial;
import java.util.*;
import java.util.Map.Entry;
import static java.util.Map.entry;
import static java.util.stream.Collectors.toUnmodifiableMap;
/**
* Keeps configuration keys working after they have been moved to a new place in the
* {@code floci} config tree, typically when a flat {@code floci.*} property is pulled down
* into a sub-mapping ({@code floci.protocols.*}, {@code floci.services.lambda.*}, …).
*
* <p>A hand-rolled equivalent of SmallRye's {@code RelocateConfigSourceInterceptor}: whenever
* the <em>new</em> key is requested, the <em>legacy</em> key is consulted too, and the legacy
* value only wins when the new key was left untouched (i.e. its value is just the
* {@code @WithDefault}) or the legacy value comes from a higher-priority source.
*
* <p>{@link #iterateNames(ConfigSourceInterceptorContext)} rewrites any legacy key it sees to
* the new name, so config-mapping validation and {@code getPropertyNames()} never treat the
* legacy keys as unknown properties.
*
* <p><strong>Adding a relocation:</strong> append a {@code legacy -> current} entry to
* {@link #RELOCATIONS}. Everything else (both lookup directions, name iteration) is derived
* from that single list. Each key (legacy or current) must appear at most once.
*
* <p>Registered via {@code META-INF/services/io.smallrye.config.ConfigSourceInterceptor}. The
* priority places it inside the expression interceptor so an expression such as
* <code>${floci.protocols.max-request-size}</code> in {@code application.yml} also picks up a
* value set under the legacy key.
*/
@Priority(Priorities.LIBRARY + 200 - 5)
public class FlociConfigRelocationsInterceptor implements ConfigSourceInterceptor {
@Serial
private static final long serialVersionUID = 2446657606783245344L;
/**
* The relocations, as {@code legacy key -> current key}. This is the only place a
* relocation is declared; the lookup maps below are built from it.
*/
static final List<Entry<String, String>> RELOCATIONS = List.of(
entry("floci.max-request-size", "floci.protocols.max-request-size"),
entry("floci.ecr-base-uri", "floci.services.lambda.ecr-base-uri")
);
/**
* current key &rarr; legacy key, consulted while resolving a value.
*/
private static final Map<String, String> CURRENT_TO_LEGACY = RELOCATIONS.stream()
.collect(toUnmodifiableMap(Entry::getValue, Entry::getKey));
/**
* legacy key &rarr; current key, applied while iterating property names.
*/
private static final Map<String, String> LEGACY_TO_CURRENT = RELOCATIONS.stream()
.collect(toUnmodifiableMap(Entry::getKey, Entry::getValue));
@Override
public ConfigValue getValue(final ConfigSourceInterceptorContext context, final String name) {
final ConfigValue value = context.proceed(name);
final String legacyName = CURRENT_TO_LEGACY.get(name);
if (legacyName == null) {
return value;
}
final ConfigValue legacyValue = context.proceed(legacyName);
if (legacyValue == null || legacyValue.getValue() == null) {
return value;
}
if (value == null
|| value.getValue() == null
|| legacyValue.getConfigSourceOrdinal() > value.getConfigSourceOrdinal()) {
return legacyValue.withName(name);
}
return value;
}
@Override
public Iterator<String> iterateNames(final ConfigSourceInterceptorContext context) {
final Set<String> names = new HashSet<>();
final Iterator<String> iterator = context.iterateNames();
while (iterator.hasNext()) {
final String name = iterator.next();
names.add(LEGACY_TO_CURRENT.getOrDefault(name, name));
}
return names.iterator();
}
}
@@ -47,7 +47,7 @@ public class ImageResolver {
private final String baseUri;
public ImageResolver(EmulatorConfig config) {
this.baseUri = config.ecrBaseUri();
this.baseUri = config.services().lambda().ecrBaseUri();
}
public String resolve(String runtime) {