mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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:
1 parent
4ca8c42470
commit
39b19d1c92
13 files changed
+224
-31
No files matched your search
@@ -35,7 +35,7 @@ class ApplicationDefaultsTest {
|
||||
JsonNode config = new YAMLMapper().readTree(Path.of("src/main/resources/application.yml").toFile());
|
||||
|
||||
assertEquals(2048,
|
||||
config.path("floci").path("max-request-size").asInt(),
|
||||
config.path("floci").path("protocols").path("max-request-size").asInt(),
|
||||
"production application.yml should allow 2048 MB request bodies by default");
|
||||
}
|
||||
|
||||
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package io.github.hectorvent.floci.config;
|
||||
|
||||
import io.smallrye.config.PropertiesConfigSource;
|
||||
import io.smallrye.config.SmallRyeConfig;
|
||||
import io.smallrye.config.SmallRyeConfigBuilder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static java.util.stream.StreamSupport.stream;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class FlociConfigRelocationsInterceptorTest {
|
||||
|
||||
private static SmallRyeConfig config(Map<String, String> properties) {
|
||||
return new SmallRyeConfigBuilder()
|
||||
.addDefaultInterceptors()
|
||||
.withInterceptors(new FlociConfigRelocationsInterceptor())
|
||||
.withSources(new PropertiesConfigSource(properties, "test", 250))
|
||||
.withDefaultValue("floci.protocols.max-request-size", "2048")
|
||||
.withDefaultValue("floci.services.lambda.ecr-base-uri", "public.ecr.aws")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyMaxRequestSizeKeyResolvesToTheRelocatedKey() {
|
||||
SmallRyeConfig config = config(Map.of("floci.max-request-size", "4096"));
|
||||
|
||||
assertEquals(4096, config.getValue("floci.protocols.max-request-size", Integer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void legacyEcrBaseUriKeyResolvesToTheRelocatedKey() {
|
||||
SmallRyeConfig config = config(Map.of("floci.ecr-base-uri", "my.registry.example/mirror"));
|
||||
|
||||
assertEquals("my.registry.example/mirror",
|
||||
config.getValue("floci.services.lambda.ecr-base-uri", String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theRelocatedKeyWinsOverTheLegacyKeyFromTheSameSource() {
|
||||
SmallRyeConfig config = config(Map.of(
|
||||
"floci.max-request-size", "4096",
|
||||
"floci.protocols.max-request-size", "8192"));
|
||||
|
||||
assertEquals(8192, config.getValue("floci.protocols.max-request-size", Integer.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theWithDefaultValueAppliesWhenNeitherKeyIsSet() {
|
||||
SmallRyeConfig config = config(Map.of());
|
||||
|
||||
assertEquals(2048, config.getValue("floci.protocols.max-request-size", Integer.class));
|
||||
assertEquals("public.ecr.aws",
|
||||
config.getValue("floci.services.lambda.ecr-base-uri", String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void nameIterationPresentsOnlyTheRelocatedKey() {
|
||||
SmallRyeConfig config = config(Map.of("floci.max-request-size", "4096"));
|
||||
|
||||
var names = stream(config.getPropertyNames().spliterator(), false).toList();
|
||||
assertTrue(names.contains("floci.protocols.max-request-size"));
|
||||
assertFalse(names.contains("floci.max-request-size"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void expressionExpansionSeesTheLegacyKeyWhenResolvingTheRelocatedKey() {
|
||||
SmallRyeConfig config = config(Map.of(
|
||||
"quarkus.http.limits.max-body-size", "${floci.protocols.max-request-size}M",
|
||||
"floci.max-request-size", "4096"));
|
||||
assertEquals("4096M", config.getValue("quarkus.http.limits.max-body-size", String.class));
|
||||
}
|
||||
}
|
||||
+1
-4
@@ -296,10 +296,6 @@ class EventBridgeSchedulerIntegrationTest {
|
||||
@Override
|
||||
public String defaultAccountId() { return ACCOUNT; }
|
||||
@Override
|
||||
public int maxRequestSize() { return 512; }
|
||||
@Override
|
||||
public String ecrBaseUri() { return ""; }
|
||||
@Override
|
||||
public Optional<String> aiMockConfigFile() { return Optional.empty(); }
|
||||
@Override
|
||||
public StorageConfig storage() { return null; }
|
||||
@@ -327,6 +323,7 @@ class EventBridgeSchedulerIntegrationTest {
|
||||
@Override
|
||||
public ProtocolsConfig protocols() {
|
||||
return new ProtocolsConfig() {
|
||||
@Override public int maxRequestSize() { return 512; }
|
||||
@Override public boolean strictClaiming() { return false; }
|
||||
@Override public boolean rejectUnknownServiceScope() { return true; }
|
||||
};
|
||||
|
||||
+6
-6
@@ -11,11 +11,11 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
class ImageResolverTest {
|
||||
|
||||
private final EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
private final EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
|
||||
private final ImageResolver resolver;
|
||||
|
||||
ImageResolverTest() {
|
||||
when(config.ecrBaseUri()).thenReturn("public.ecr.aws");
|
||||
when(config.services().lambda().ecrBaseUri()).thenReturn("public.ecr.aws");
|
||||
this.resolver = new ImageResolver(config);
|
||||
}
|
||||
|
||||
@@ -86,8 +86,8 @@ class ImageResolverTest {
|
||||
"provided, my.custom.host/lambda/provided:latest"
|
||||
})
|
||||
void resolvesKnownRuntimesWithHostOverride(String runtime, String expectedImage) {
|
||||
EmulatorConfig customConfig = mock(EmulatorConfig.class);
|
||||
when(customConfig.ecrBaseUri()).thenReturn("my.custom.host");
|
||||
EmulatorConfig customConfig = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
|
||||
when(customConfig.services().lambda().ecrBaseUri()).thenReturn("my.custom.host");
|
||||
ImageResolver customResolver = new ImageResolver(customConfig);
|
||||
assertEquals(expectedImage, customResolver.resolve(runtime));
|
||||
}
|
||||
@@ -124,8 +124,8 @@ class ImageResolverTest {
|
||||
"provided, my.custom.host/path/lambda/provided:latest"
|
||||
})
|
||||
void resolvesKnownRuntimesWithHostAndPathOverride(String runtime, String expectedImage) {
|
||||
EmulatorConfig customConfig = mock(EmulatorConfig.class);
|
||||
when(customConfig.ecrBaseUri()).thenReturn("my.custom.host/path");
|
||||
EmulatorConfig customConfig = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
|
||||
when(customConfig.services().lambda().ecrBaseUri()).thenReturn("my.custom.host/path");
|
||||
ImageResolver customResolver = new ImageResolver(customConfig);
|
||||
assertEquals(expectedImage, customResolver.resolve(runtime));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user