Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fix(appconfig): resolve data sessions by name (#798)

Liam MacPherson0dcc840c4ed6
diff --git a/ministack/services/appconfig.py b/ministack/services/appconfig.py
index 74f368bb..90f4f73c 100644
--- a/ministack/services/appconfig.py
+++ b/ministack/services/appconfig.py
@@ -126,6 +126,39 @@ def _deployment_arn(app_id, env_id, deploy_num):
)
+def _resolve_application_id(identifier):
+ if identifier in _applications:
+ return identifier
+
+ for app_id, record in _applications.items():
+ if record.get("Name") == identifier:
+ return app_id
+
+ return None
+
+
+def _resolve_environment_id(app_id, identifier):
+ if f"{app_id}/{identifier}" in _environments:
+ return identifier
+
+ for record in _environments.values():
+ if record.get("ApplicationId") == app_id and record.get("Name") == identifier:
+ return record.get("Id")
+
+ return None
+
+
+def _resolve_configuration_profile_id(app_id, identifier):
+ if f"{app_id}/{identifier}" in _config_profiles:
+ return identifier
+
+ for record in _config_profiles.values():
+ if record.get("ApplicationId") == app_id and record.get("Name") == identifier:
+ return record.get("Id")
+
+ return None
+
+
# ---------------------------------------------------------------------------
# Applications
# ---------------------------------------------------------------------------
@@ -578,15 +611,27 @@ def _list_tags_for_resource(resource_arn):
def _start_configuration_session(body):
- app_id = body.get("ApplicationIdentifier", "")
- env_id = body.get("EnvironmentIdentifier", "")
- profile_id = body.get("ConfigurationProfileIdentifier", "")
+ app_identifier = body.get("ApplicationIdentifier", "")
+ env_identifier = body.get("EnvironmentIdentifier", "")
+ profile_identifier = body.get("ConfigurationProfileIdentifier", "")
- if not app_id or not env_id or not profile_id:
+ if not app_identifier or not env_identifier or not profile_identifier:
return _error(400, "BadRequestException",
"ApplicationIdentifier, EnvironmentIdentifier, and "
"ConfigurationProfileIdentifier are required")
+ app_id = _resolve_application_id(app_identifier)
+ if not app_id:
+ return _error(404, "ResourceNotFoundException", f"Application {app_identifier} not found")
+
+ env_id = _resolve_environment_id(app_id, env_identifier)
+ if not env_id:
+ return _error(404, "ResourceNotFoundException", f"Environment {env_identifier} not found")
+
+ profile_id = _resolve_configuration_profile_id(app_id, profile_identifier)
+ if not profile_id:
+ return _error(404, "ResourceNotFoundException", f"Configuration profile {profile_identifier} not found")
+
token = uuid.uuid4().hex
_sessions[token] = {
"ApplicationIdentifier": app_id,
diff --git a/tests/test_appconfig.py b/tests/test_appconfig.py
index 745381c5..9bffa1fd 100644
--- a/tests/test_appconfig.py
+++ b/tests/test_appconfig.py
@@ -528,6 +528,48 @@ def test_appconfig_data_plane_e2e(appconfig_client, appconfigdata_client):
assert latest2["NextPollConfigurationToken"]
+def test_appconfig_data_plane_e2e_with_names(appconfig_client, appconfigdata_client):
+ app = appconfig_client.create_application(Name="data-plane-app-by-name")
+ env = appconfig_client.create_environment(ApplicationId=app["Id"], Name="live")
+ profile = appconfig_client.create_configuration_profile(
+ ApplicationId=app["Id"], Name="data-profile", LocationUri="hosted",
+ )
+ config_content = json.dumps({"feature_x": True, "max_retries": 3}).encode("utf-8")
+ appconfig_client.create_hosted_configuration_version(
+ ApplicationId=app["Id"],
+ ConfigurationProfileId=profile["Id"],
+ Content=config_content,
+ ContentType="application/json",
+ )
+ strategy = appconfig_client.create_deployment_strategy(
+ Name="e2e-strategy-by-name",
+ DeploymentDurationInMinutes=0,
+ GrowthFactor=100.0,
+ ReplicateTo="NONE",
+ )
+ appconfig_client.start_deployment(
+ ApplicationId=app["Id"],
+ EnvironmentId=env["Id"],
+ DeploymentStrategyId=strategy["Id"],
+ ConfigurationProfileId=profile["Id"],
+ ConfigurationVersion="1",
+ )
+
+ session = appconfigdata_client.start_configuration_session(
+ ApplicationIdentifier=app["Name"],
+ EnvironmentIdentifier=env["Name"],
+ ConfigurationProfileIdentifier=profile["Name"],
+ )
+ token = session["InitialConfigurationToken"]
+ assert token
+
+ latest = appconfigdata_client.get_latest_configuration(ConfigurationToken=token)
+ body = latest["Configuration"].read()
+ assert json.loads(body) == {"feature_x": True, "max_retries": 3}
+ assert latest["ContentType"] == "application/json"
+ assert latest["NextPollConfigurationToken"]
+
+
# ---------------------------------------------------------------------------
# Error cases
# ---------------------------------------------------------------------------
@@ -570,3 +612,47 @@ def test_appconfig_get_nonexistent_deployment(appconfig_client):
ApplicationId=app["Id"], EnvironmentId=env["Id"], DeploymentNumber=999,
)
assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"
+
+
+def test_appconfig_start_configuration_session_rejects_missing_application(appconfigdata_client):
+ with pytest.raises(ClientError) as exc:
+ appconfigdata_client.start_configuration_session(
+ ApplicationIdentifier="missing-app",
+ EnvironmentIdentifier="live",
+ ConfigurationProfileIdentifier="data-profile",
+ )
+
+ assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"
+ assert exc.value.response["ResponseMetadata"]["HTTPStatusCode"] == 404
+
+
+def test_appconfig_start_configuration_session_rejects_missing_environment(appconfig_client, appconfigdata_client):
+ app = appconfig_client.create_application(Name="session-env-app")
+
+ with pytest.raises(ClientError) as exc:
+ appconfigdata_client.start_configuration_session(
+ ApplicationIdentifier=app["Name"],
+ EnvironmentIdentifier="missing-env",
+ ConfigurationProfileIdentifier="data-profile",
+ )
+
+ assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"
+ assert exc.value.response["ResponseMetadata"]["HTTPStatusCode"] == 404
+
+
+def test_appconfig_start_configuration_session_rejects_missing_configuration_profile(
+ appconfig_client,
+ appconfigdata_client,
+):
+ app = appconfig_client.create_application(Name="session-profile-app")
+ env = appconfig_client.create_environment(ApplicationId=app["Id"], Name="live")
+
+ with pytest.raises(ClientError) as exc:
+ appconfigdata_client.start_configuration_session(
+ ApplicationIdentifier=app["Name"],
+ EnvironmentIdentifier=env["Name"],
+ ConfigurationProfileIdentifier="missing-profile",
+ )
+
+ assert exc.value.response["Error"]["Code"] == "ResourceNotFoundException"
+ assert exc.value.response["ResponseMetadata"]["HTTPStatusCode"] == 404