fix(appconfig): isolate resources and sessions by region (#7621)

Scope AppConfig stores, sessions and deployment cursors to the request's
account and region. Keep legacy keys in the configured default region.
Adapt the source change to current deployment and CloudFormation behavior,
and cover storage reloads and SDK routing.

Signed-off-by: Andre Kurait <akurait@amazon.com>
Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
Co-authored-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
Jackson PriceandAndre Kurait authored and GitHub committed 2026-11-05 16:13:12 -04:00
1 parent 36fbc33a2f
commit a884257311
17 files changed
+587 -42

No files matched your search

@@ -3,7 +3,8 @@ package io.github.hectorvent.floci.services.appconfig;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.services.appconfig.model.ConfigurationSession;
import io.github.hectorvent.floci.testing.InMemoryStorageFactory;
import org.junit.jupiter.api.Test;
@@ -36,8 +37,9 @@ class AppConfigDataServiceTest {
void concurrentPollsConsumeAConfigurationTokenOnlyOnce() throws Exception {
InMemoryStorageFactory factory = new InMemoryStorageFactory("000000000000");
AppConfigService appConfig = mock(AppConfigService.class);
AppConfigDataService service = new AppConfigDataService(factory, appConfig, MAPPER);
AccountAwareStorageBackend<ConfigurationSession> sessions = factory.create("appconfigdata",
RegionResolver regions = new RegionResolver("us-east-1", "000000000000");
AppConfigDataService service = new AppConfigDataService(factory, appConfig, MAPPER, regions);
StorageBackend<String, ConfigurationSession> sessions = new AppConfigStorage<>(factory, regions, "appconfigdata",
"appconfigdata-sessions.json", new TypeReference<Map<String, ConfigurationSession>>() {});
ConfigurationSession session = new ConfigurationSession();
session.setApplicationId("app");
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.appconfig;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.ServiceConfigAccess;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.appconfig.model.Deployment;
@@ -162,7 +163,8 @@ class AppConfigDeploymentLifecycleTest {
StorageFactory storage = factory();
Clock clock = mock(Clock.class);
when(clock.instant()).thenReturn(START);
AppConfigService service = new AppConfigService(storage, mock(EmulatorConfig.class), clock);
AppConfigService service = new AppConfigService(
storage, new RegionResolver("us-east-1", "000000000000"), clock);
Scope scope = scope(service);
Deployment baking = deploy(service, scope, "1", scope.bake());
Deployment response = service.getDeployment(scope.app(), scope.env(), baking.getDeploymentNumber());
@@ -238,7 +240,8 @@ class AppConfigDeploymentLifecycleTest {
}
private AppConfigService service(StorageFactory storage, Instant time) {
return new AppConfigService(storage, mock(EmulatorConfig.class), Clock.fixed(time, ZoneOffset.UTC));
return new AppConfigService(storage, new RegionResolver("us-east-1", "000000000000"),
Clock.fixed(time, ZoneOffset.UTC));
}
private StorageFactory factory() {
@@ -0,0 +1,82 @@
package io.github.hectorvent.floci.services.appconfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.RequestScopes;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
@QuarkusTest
class AppConfigRegionIntegrationTest {
@Inject
AppConfigService service;
@Inject
AppConfigDataService data;
@Inject
RegionResolver regions;
@Test
void identicalNamesResolveOnlyWithinTheirAccountAndRegion() {
String name = "regional-" + UUID.randomUUID();
Map<Scope, String> applications = new LinkedHashMap<>();
try {
for (Scope scope : List.of(
new Scope("111111111111", regions.getDefaultRegion()),
new Scope("111111111111", "us-west-2"),
new Scope("222222222222", regions.getDefaultRegion()),
new Scope("111111111111", "cn-north-1"))) {
applications.put(scope, RequestScopes.callAs(scope.account(), scope.region(),
() -> service.createApplication(Map.of("Name", name)).getId()));
}
applications.forEach((scope, id) -> RequestScopes.runAs(scope.account(), scope.region(), () -> {
assertEquals(id, service.resolveApplication(name).getId());
assertEquals(List.of(id), service.listApplications().stream()
.filter(application -> name.equals(application.getName()))
.map(application -> application.getId()).toList());
applications.values().stream().filter(other -> !other.equals(id)).forEach(other ->
assertEquals("ResourceNotFoundException",
assertThrows(AwsException.class, () -> service.getApplication(other)).getErrorCode()));
}));
} finally {
applications.forEach((scope, id) -> RequestScopes.runAs(scope.account(), scope.region(),
() -> service.deleteApplication(id)));
}
}
@Test
void foreignRegionCannotConsumeAConfigurationSession() {
String account = "333333333333";
String region = regions.getDefaultRegion();
RequestScopes.runAs(account, region, () -> {
String app = service.createApplication(Map.of("Name", "session-" + UUID.randomUUID())).getId();
String env = service.createEnvironment(app, Map.of("Name", "environment")).getId();
String profile = service.createConfigurationProfile(app,
Map.of("Name", "profile", "LocationUri", "hosted")).getId();
try {
String token = data.startConfigurationSession(Map.of(
"ApplicationIdentifier", app, "EnvironmentIdentifier", env,
"ConfigurationProfileIdentifier", profile));
RequestScopes.runAs(account, "us-west-2", () -> assertEquals("BadRequestException",
assertThrows(AwsException.class, () -> data.getLatestConfiguration(token)).getErrorCode()));
assertEquals(0, data.getLatestConfiguration(token).content().length);
} finally {
service.deleteEnvironment(app, env);
service.deleteConfigurationProfile(app, profile);
service.deleteApplication(app);
}
});
}
private record Scope(String account, String region) {}
}
@@ -0,0 +1,104 @@
package io.github.hectorvent.floci.services.appconfig;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.testing.StorageFactories;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class AppConfigRegionPersistenceTest {
@TempDir
Path directory;
@ParameterizedTest
@ValueSource(strings = {"persistent", "hybrid", "wal"})
void deploymentsAndUnconsumedSessionsKeepTheirRegionAfterRestart(String mode) {
AtomicReference<String> current = new AtomicReference<>("us-east-1");
RegionResolver regions = mock(RegionResolver.class);
when(regions.getDefaultRegion()).thenReturn("us-east-1");
when(regions.getRegion()).thenAnswer(invocation -> current.get());
when(regions.getAccountId()).thenReturn("000000000000");
Map<String, Selection> selections = new LinkedHashMap<>();
StorageFactory first = StorageFactories.open(directory, mode, "000000000000");
try {
AppConfigService service = new AppConfigService(first, regions);
AppConfigDataService data = new AppConfigDataService(first, service, new ObjectMapper(), regions);
for (String region : List.of("us-east-1", "us-west-2", "cn-north-1")) {
current.set(region);
String app = service.createApplication(Map.of("Name", "same-application")).getId();
String env = service.createEnvironment(app, Map.of("Name", "same-environment")).getId();
String profile = service.createConfigurationProfile(app,
Map.of("Name", "same-profile", "LocationUri", "hosted")).getId();
int version = service.createHostedConfigurationVersion(
app, profile, content(region), "text/plain", null).getVersionNumber();
String strategy = service.createDeploymentStrategy(Map.of(
"Name", "same-strategy", "FinalBakeTimeInMinutes", 0)).getId();
int deployment = service.startDeployment(app, env, Map.of(
"ConfigurationProfileId", profile, "ConfigurationVersion", String.valueOf(version),
"DeploymentStrategyId", strategy)).getDeploymentNumber();
String token = data.startConfigurationSession(Map.of(
"ApplicationIdentifier", app, "EnvironmentIdentifier", env,
"ConfigurationProfileIdentifier", profile));
selections.put(region, new Selection(app, env, profile, strategy, deployment, token));
}
} finally {
first.shutdownAll();
}
StorageFactory restarted = StorageFactories.open(directory, mode, "000000000000");
try {
AppConfigService service = new AppConfigService(restarted, regions);
AppConfigDataService data = new AppConfigDataService(restarted, service, new ObjectMapper(), regions);
selections.forEach((region, selection) -> {
current.set(region);
assertEquals(selection.app(), service.resolveApplication("same-application").getId());
assertEquals(selection.env(), service.resolveEnvironment(selection.app(), "same-environment").getId());
assertEquals(selection.profile(),
service.resolveConfigurationProfile(selection.app(), "same-profile").getId());
assertEquals("same-strategy", service.getDeploymentStrategy(selection.strategy()).getName());
assertEquals("COMPLETE", service.getDeployment(
selection.app(), selection.env(), selection.deployment()).getState());
assertArrayEquals(content(region), data.getConfiguration(
"same-application", "same-environment", "same-profile", "client", null, null).content());
selections.forEach((otherRegion, other) -> {
if (!region.equals(otherRegion)) {
assertEquals("ResourceNotFoundException", assertThrows(AwsException.class,
() -> service.getDeploymentStrategy(other.strategy())).getErrorCode());
assertEquals("BadRequestException", assertThrows(AwsException.class,
() -> data.getLatestConfiguration(other.token())).getErrorCode());
}
});
assertArrayEquals(content(region), data.getLatestConfiguration(selection.token()).content());
service.deleteEnvironment(selection.app(), selection.env());
service.deleteConfigurationProfile(selection.app(), selection.profile());
service.deleteDeploymentStrategy(selection.strategy());
service.deleteApplication(selection.app());
assertEquals(List.of(), service.listApplications());
});
} finally {
restarted.shutdownAll();
}
}
private static byte[] content(String region) {
return region.getBytes(StandardCharsets.UTF_8);
}
private record Selection(String app, String env, String profile, String strategy, int deployment, String token) {}
}
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.appconfig;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.ServiceConfigAccess;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.appconfig.model.Deployment;
@@ -57,7 +58,7 @@ class AppConfigServicePersistenceTest {
"State": "COMPLETE", "Description": null}}
""");
AppConfigService service = new AppConfigService(newFactory(), mock(EmulatorConfig.class));
AppConfigService service = new AppConfigService(newFactory(), new RegionResolver("us-east-1", "000000000000"));
Environment environment = service.getEnvironment("app1", "env1");
assertEquals("stored-env", environment.getName());
@@ -87,7 +88,7 @@ class AppConfigServicePersistenceTest {
@Test
void deploymentStrategySettingsSurviveARestart() {
StorageFactory first = newFactory();
AppConfigService service = new AppConfigService(first, mock(EmulatorConfig.class));
AppConfigService service = new AppConfigService(first, new RegionResolver("us-east-1", "000000000000"));
String appId = service.createApplication(Map.of("Name", "restarted-app")).getId();
String environmentId = service.createEnvironment(appId, Map.of("Name", "restarted-env")).getId();
String profileId = service.createConfigurationProfile(appId, Map.of(
@@ -101,7 +102,7 @@ class AppConfigServicePersistenceTest {
"DeploymentStrategyId", strategyId));
first.shutdownAll();
AppConfigService restarted = new AppConfigService(newFactory(), mock(EmulatorConfig.class));
AppConfigService restarted = new AppConfigService(newFactory(), new RegionResolver("us-east-1", "000000000000"));
// With the strategy gone, the settings can only come from the stored deployment.
restarted.deleteDeploymentStrategy(strategyId);
@@ -115,7 +116,7 @@ class AppConfigServicePersistenceTest {
@Test
void monitorsAndDeploymentLocationsSurviveARestart() {
StorageFactory first = newFactory();
AppConfigService service = new AppConfigService(first, mock(EmulatorConfig.class));
AppConfigService service = new AppConfigService(first, new RegionResolver("us-east-1", "000000000000"));
String appId = service.createApplication(Map.of("Name", "restarted-app")).getId();
String monitoredId = service.createEnvironment(appId, Map.of("Name", "monitored", "Monitors", List.of(
Map.of("AlarmArn", ALARM_ARN, "AlarmRoleArn", ALARM_ROLE_ARN),
@@ -129,7 +130,7 @@ class AppConfigServicePersistenceTest {
"DeploymentStrategyId", "AppConfig.AllAtOnce")).getDeploymentNumber();
first.shutdownAll();
AppConfigService restarted = new AppConfigService(newFactory(), mock(EmulatorConfig.class));
AppConfigService restarted = new AppConfigService(newFactory(), new RegionResolver("us-east-1", "000000000000"));
assertEquals(List.of(new Monitor(ALARM_ARN, ALARM_ROLE_ARN), new Monitor(SECOND_ALARM_ARN, null)),
restarted.getEnvironment(appId, monitoredId).getMonitors());
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.appconfig;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.services.appconfig.model.Application;
import io.github.hectorvent.floci.testing.InMemoryStorageFactory;
@@ -33,7 +34,8 @@ class AppConfigServiceTaggingTest {
@Test
void anApplicationReadBeforeATagOrUntagKeepsItsPriorTags() {
AppConfigService service = new AppConfigService(new InMemoryStorageFactory(ACCOUNT), null);
AppConfigService service = new AppConfigService(
new InMemoryStorageFactory(ACCOUNT), new RegionResolver("us-east-1", ACCOUNT));
Application created = service.createApplication(Map.of("Name", "orders"));
service.tagApplication(created.getId(), Map.of("team", "payments"));
Application beforeTag = service.getApplication(created.getId());
@@ -90,6 +92,7 @@ class AppConfigServiceTaggingTest {
/** An AppConfig service whose application store is {@code store} and every other store in memory. */
private static AppConfigService serviceWithApplicationStore(StorageBackend<String, Application> store) {
return new AppConfigService(new InMemoryStorageFactory(ACCOUNT).withStore(APPLICATIONS, store), null);
return new AppConfigService(new InMemoryStorageFactory(ACCOUNT).withStore(APPLICATIONS, store),
new RegionResolver("us-east-1", ACCOUNT));
}
}
@@ -1,8 +1,8 @@
package io.github.hectorvent.floci.services.appconfig;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.appconfig.model.Application;
@@ -51,6 +51,7 @@ class AppConfigServiceTest {
private AccountAwareStorageBackend<Environment> environmentStore;
private AccountAwareStorageBackend<Deployment> deploymentStore;
private AccountAwareStorageBackend<String> activeConfigStore;
private RegionResolver regions;
private AppConfigService service;
@BeforeEach
@@ -65,7 +66,8 @@ class AppConfigServiceTest {
deployments.put(invocation.getArgument(0, String.class), invocation.getArgument(1, Deployment.class));
return null;
}).when(deploymentStore).put(anyString(), any(Deployment.class));
when(deploymentStore.scan(any())).thenAnswer(invocation -> List.copyOf(deployments.values()));
when(deploymentStore.get(anyString())).thenAnswer(invocation ->
Optional.ofNullable(deployments.get(invocation.getArgument(0, String.class))));
when(deploymentStore.keys()).thenAnswer(invocation -> Set.copyOf(deployments.keySet()));
doAnswer(invocation -> deployments.remove(invocation.getArgument(0, String.class)))
.when(deploymentStore).delete(anyString());
@@ -106,7 +108,11 @@ class AppConfigServiceTest {
profile.setId("profile");
profile.setApplicationId("app");
when(profileStore.get("profile")).thenReturn(Optional.of(profile));
service = new AppConfigService(storageFactory, mock(EmulatorConfig.class));
regions = mock(RegionResolver.class);
when(regions.getDefaultRegion()).thenReturn("us-east-1");
when(regions.getRegion()).thenReturn("us-east-1");
when(regions.getAccountId()).thenReturn("000000000000");
service = new AppConfigService(storageFactory, regions);
}
@Test
@@ -115,7 +121,7 @@ class AppConfigServiceTest {
assertEquals("orders-v2", updated.getName());
assertEquals("Order processing", updated.getDescription());
verify(applicationStore).put("app", updated);
verify(applicationStore).put("us-east-1/app", updated);
}
@Test
@@ -205,6 +211,37 @@ class AppConfigServiceTest {
assertThrows(RuntimeException.class, () -> service.listDeployments("app", "env", 1, "unknown"));
}
@Test
void listDeploymentsTokensCannotCrossRegionOrAccount() {
deploymentStore.put("app::env::1", deployment("app", "env", 1));
deploymentStore.put("app::env::2", deployment("app", "env", 2));
String token = service.listDeployments("app", "env", 1, null).nextToken();
assertNotNull(token);
// The same resource IDs exist in both regions, so rejection must come from token scope.
Application app = applicationStore.get("app").orElseThrow();
Environment env = environmentStore.get("env").orElseThrow();
when(applicationStore.get("us-west-2/app")).thenReturn(Optional.of(app));
when(environmentStore.get("us-west-2/env")).thenReturn(Optional.of(env));
when(regions.getRegion()).thenReturn("us-west-2");
AwsException regionError = assertThrows(AwsException.class,
() -> service.listDeployments("app", "env", 1, token));
assertEquals("BadRequestException", regionError.getErrorCode());
assertEquals("Invalid next_token", regionError.getMessage());
when(regions.getRegion()).thenReturn("us-east-1");
when(regions.getAccountId()).thenReturn("222222222222");
AwsException accountError = assertThrows(AwsException.class,
() -> service.listDeployments("app", "env", 1, token));
assertEquals("BadRequestException", accountError.getErrorCode());
assertEquals("Invalid next_token", accountError.getMessage());
when(regions.getAccountId()).thenReturn("000000000000");
AppConfigService.DeploymentPage secondPage = service.listDeployments("app", "env", 1, token);
assertEquals(List.of(1), secondPage.items().stream().map(DeploymentSummary::getDeploymentNumber).toList());
assertNull(secondPage.nextToken());
}
@Test
void listDeploymentsStillReportsADeploymentWhoseStrategyWasDeleted() {
String strategyId = createGradualStrategy().getId();
@@ -392,7 +429,7 @@ class AppConfigServiceTest {
"DeploymentStrategyId", "AppConfig.AllAtOnce"));
assertEquals(4, deployment.getDeploymentNumber());
assertEquals(Set.of("app::env::1", "app::env::3", "app::env::4"), deploymentStore.keys());
assertEquals(Set.of("app::env::1", "app::env::3", "us-east-1/app::env::4"), deploymentStore.keys());
}
@Test
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.appconfig;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.services.appconfig.model.Application;
import io.github.hectorvent.floci.services.appconfig.model.ConfigurationProfile;
import io.github.hectorvent.floci.services.appconfig.model.DeploymentStrategy;
@@ -24,7 +25,8 @@ class AppConfigServiceUpdateIsolationTest {
private static final String ALARM = "arn:aws:cloudwatch:us-east-1:000000000000:alarm:configuration-errors";
private final AppConfigService service = new AppConfigService(new InMemoryStorageFactory("000000000000"), null);
private final AppConfigService service = new AppConfigService(new InMemoryStorageFactory("000000000000"),
new RegionResolver("us-east-1", "000000000000"));
@Test
void aStrategyReadBeforeAnUpdateKeepsItsPriorSettings() {
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.appconfig;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.services.appconfig.model.Application;
import io.github.hectorvent.floci.services.appconfig.model.ConfigurationProfile;
@@ -129,6 +130,7 @@ class AppConfigServiceUpdateRaceTest {
/** An AppConfig service whose {@code fileName} store is {@code store} and every other store in memory. */
private static AppConfigService serviceWithStore(String fileName, StorageBackend<String, ?> store) {
return new AppConfigService(new InMemoryStorageFactory(ACCOUNT).withStore(fileName, store), null);
return new AppConfigService(new InMemoryStorageFactory(ACCOUNT).withStore(fileName, store),
new RegionResolver("us-east-1", ACCOUNT));
}
}
@@ -0,0 +1,71 @@
package io.github.hectorvent.floci.services.appconfig;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.testing.StorageFactories;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
class AppConfigStorageTest {
@TempDir
Path directory;
@ParameterizedTest
@ValueSource(strings = {"memory", "persistent", "hybrid", "wal"})
void legacyKeysAndScopedKeysCannotEscapeTheirRegion(String mode) {
StorageFactory factory = StorageFactories.open(directory, mode, "000000000000");
try {
StorageBackend<String, String> legacy = factory.create(
"appconfig", "records.json", new TypeReference<>() {});
legacy.put("existing", "legacy");
AppConfigStorage<String> east = store(factory, "us-east-1");
AppConfigStorage<String> west = store(factory, "us-west-2");
assertEquals(Optional.of("legacy"), east.get("existing"));
assertEquals(Optional.empty(), west.get("existing"));
east.put("existing", "east");
west.put("existing", "west");
legacy.put("untouched", "older-record");
assertEquals(Optional.empty(), legacy.get("existing"));
assertEquals(Optional.of("east"), east.get("existing"));
assertEquals(Optional.of("west"), west.get("existing"));
assertEquals(Set.of("existing", "untouched"), east.keys());
assertEquals(Set.of("existing"), west.keys());
assertEquals(List.of("west"), west.scan(key -> key.equals("existing")));
List<String> selected = west.scan(key -> true);
selected.clear();
assertEquals(List.of("west"), west.scan(key -> true));
assertEquals(Optional.empty(), east.get("us-west-2/existing"));
east.delete("us-west-2/existing");
assertThrows(IllegalArgumentException.class, () -> east.put("us-west-2/existing", "wrong"));
assertEquals(Optional.of("west"), west.get("existing"));
east.clear();
assertEquals(Set.of(), east.keys());
assertEquals(Optional.of("west"), west.get("existing"));
} finally {
factory.shutdownAll();
}
}
private static AppConfigStorage<String> store(StorageFactory factory, String region) {
RegionResolver regions = mock(RegionResolver.class);
when(regions.getDefaultRegion()).thenReturn("us-east-1");
when(regions.getRegion()).thenReturn(region);
return new AppConfigStorage<>(factory, regions, "appconfig", "records.json", new TypeReference<>() {});
}
}
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.services.appconfig.AppConfigService;
import io.github.hectorvent.floci.services.appconfig.model.Application;
@@ -53,7 +54,7 @@ class CloudFormationAppConfigLifecycleTest {
@BeforeEach
void setUp() {
storage = new InMemoryStorageFactory(ACCOUNT);
appConfig = spy(new AppConfigService(storage, null));
appConfig = spy(new AppConfigService(storage, new RegionResolver(REGION, ACCOUNT)));
CfnResourceDispatcher dispatcher = new CfnResourceDispatcher(MAPPER,
new CloudFormationResourceRegistry(List.of(new AppConfigCfnProvisioner(appConfig))), null, null);
cfn = CloudFormationServiceFixture.create(dispatcher);
@@ -80,6 +81,12 @@ class CloudFormationAppConfigLifecycleTest {
"application/json", null);
appConfig.startDeployment(oldApp, oldEnv, Map.of("ConfigurationProfileId", oldProfile,
"ConfigurationVersion", "1", "DeploymentStrategyId", "AppConfig.AllAtOnce"));
StorageBackend<String, Deployment> deployments = store("appconfig-deployments.json", new TypeReference<>() {});
StorageBackend<String, HostedConfigurationVersion> versions = store(
"appconfig-versions.json", new TypeReference<>() {});
String oldPrefix = REGION + "/" + oldApp + "::";
assertEquals(1, deployments.scan(key -> key.startsWith(oldPrefix)).size());
assertEquals(1, versions.scan(key -> key.startsWith(oldPrefix)).size());
deploy("moved", "UPDATE", "{\"Resources\":{\"AppB\":{\"Type\":\"AWS::AppConfig::Application\","
+ "\"Properties\":{\"Name\":\"orders\"}}," + children.formatted("AppB") + "}}");
@@ -90,10 +97,8 @@ class CloudFormationAppConfigLifecycleTest {
assertTrue(appConfig.listApplications().stream().noneMatch(app -> app.getId().equals(oldApp)));
assertTrue(appConfig.findEnvironment(oldEnv).isEmpty(), "the displaced environment is deleted");
assertTrue(appConfig.findConfigurationProfile(oldProfile).isEmpty(), "the displaced profile is deleted");
assertTrue(store("appconfig-deployments.json", new TypeReference<Map<String, Deployment>>() {})
.scan(key -> key.startsWith(oldApp + "::")).isEmpty(), "with its deployments");
assertTrue(store("appconfig-versions.json", new TypeReference<Map<String, HostedConfigurationVersion>>() {})
.scan(key -> key.startsWith(oldApp + "::")).isEmpty(), "and its hosted configuration versions");
assertTrue(deployments.scan(key -> key.startsWith(oldPrefix)).isEmpty(), "with its deployments");
assertTrue(versions.scan(key -> key.startsWith(oldPrefix)).isEmpty(), "and its hosted configuration versions");
}
/**
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation.provisioners;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.services.appconfig.AppConfigService;
import io.github.hectorvent.floci.services.appconfig.model.Application;
import io.github.hectorvent.floci.services.appconfig.model.ConfigurationProfile;
@@ -64,7 +65,7 @@ class AppConfigCfnProvisionerTest {
@BeforeEach
void setUp() {
storage = new InMemoryStorageFactory(ACCOUNT);
service = spy(new AppConfigService(storage, null));
service = spy(new AppConfigService(storage, new RegionResolver(REGION, ACCOUNT)));
provisioner = new AppConfigCfnProvisioner(service);
engine = CloudFormationTemplateEngine.standalone(ACCOUNT, REGION, STACK, MAPPER, value -> value);
}
@@ -576,6 +577,12 @@ class AppConfigCfnProvisionerTest {
null);
service.startDeployment(appId, env.getPhysicalId(), Map.of("ConfigurationProfileId", profile.getPhysicalId(),
"ConfigurationVersion", "1", "DeploymentStrategyId", "AppConfig.AllAtOnce"));
String prefix = REGION + "/" + appId + "::";
assertEquals(1, storage.create("appconfig", "appconfig-deployments.json",
new TypeReference<Map<String, Deployment>>() {}).scan(key -> key.startsWith(prefix)).size());
assertEquals(1, storage.create("appconfig", "appconfig-versions.json",
new TypeReference<Map<String, HostedConfigurationVersion>>() {})
.scan(key -> key.startsWith(prefix)).size());
service.deleteApplication(appId);
provisioner.delete(ENVIRONMENT, env.getPhysicalId(), REGION);
@@ -584,10 +591,10 @@ class AppConfigCfnProvisionerTest {
assertTrue(service.findEnvironment(env.getPhysicalId()).isEmpty());
assertTrue(service.findConfigurationProfile(profile.getPhysicalId()).isEmpty());
assertTrue(storage.create("appconfig", "appconfig-deployments.json",
new TypeReference<Map<String, Deployment>>() {}).scan(key -> key.startsWith(appId + "::")).isEmpty());
new TypeReference<Map<String, Deployment>>() {}).scan(key -> key.startsWith(prefix)).isEmpty());
assertTrue(storage.create("appconfig", "appconfig-versions.json",
new TypeReference<Map<String, HostedConfigurationVersion>>() {})
.scan(key -> key.startsWith(appId + "::")).isEmpty());
.scan(key -> key.startsWith(prefix)).isEmpty());
}
@Test