feat(ssm): publish parameter change events (#5262)

* feat(ssm): publish parameter change events

After a successful PutParameter, DeleteParameter, DeleteParameters,
LabelParameterVersion or UnlabelParameterVersion, SsmService publishes the
AWS-shaped aws.ssm "Parameter Store Change" event to the default EventBridge
bus, with the parameter ARN in resources. A label event carries the type and
description of the labelled version; an unlabel event lists the labels it
removed. Every event is published after the service lock is released. Failed
calls publish nothing, and a delivery failure is logged without failing or
undoing the write. CloudFormation managed parameters go through SsmService and
publish the same events.

* test(cloudformation): move CfnStackWaits into testing

CfnStackWaits was package-private in the CloudFormation tests, so the SSM
event integration test polled DescribeStacks for CREATE_COMPLETE itself.
It now lives in testing with a public API, and that test waits through
CfnStackWaits.awaitStatus and builds its CloudFormation requests with
CfnRequests.cfn instead of a private copy.

* refactor(eventbridge): build service event entries in one place

The ECS, Step Functions, Redshift Data, CodePipeline, SES and SSM publishers
each built the same Source, DetailType, Detail and Resources entry.
EventBridgeService.serviceEventEntry builds it, with Resources always
present and empty for a null or blank resource ARN. Each publisher still
calls putEvents with its own region and account. The explicit default
EventBusName and the Region that repeated putEvents' region argument are
gone; putEvents fills both the same way.
This commit is contained in:
Mario Toffia authored and GitHub committed 2026-10-21 07:07:39 -04:00
1 parent 1b15299228
commit 89317831bb
108 files changed
+740 -96

No files matched your search

@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.services.apigateway.ApiGatewayService;
import io.github.hectorvent.floci.services.apigateway.model.UsagePlan;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType;
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.sun.net.httpserver.HttpServer;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.CloudFormationSettingsProfile;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.SidecarContainersProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.services.autoscaling.AutoScalingService;
import io.github.hectorvent.floci.services.autoscaling.model.ScalingPolicy;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.config.TlsCertificateManager;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.InjectMock;
import io.quarkus.test.junit.QuarkusTest;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
@@ -6,6 +6,7 @@ import io.github.hectorvent.floci.services.cloudfront.CloudFrontService;
import io.github.hectorvent.floci.services.cloudfront.model.CloudFrontFunction;
import io.github.hectorvent.floci.services.cloudfront.model.KeyGroup;
import io.github.hectorvent.floci.services.cloudfront.model.PublicKey;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.services.cloudfront.model.Distribution;
import io.github.hectorvent.floci.services.cloudfront.model.OriginAccessControl;
import io.github.hectorvent.floci.services.cloudfront.model.OriginRequestPolicy;
import io.github.hectorvent.floci.services.cloudfront.model.ResponseHeadersPolicy;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.services.cloudwatch.dashboards.CloudWatchDashboardsService;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectSpy;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.config.EncoderConfig;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.services.cloudwatch.dashboards.CloudWatchDashboardsService;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectSpy;
import io.restassured.RestAssured;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import io.restassured.config.EncoderConfig;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.Test;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.Test;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.path.json.JsonPath;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.services.dynamodb.DynamoDbService;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectSpy;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.PartitionCleanup;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.services.elbv2.ElbV2Service;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectSpy;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.path.json.JsonPath;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.EnforcementFixtures;
import io.github.hectorvent.floci.testing.IamEnforcementProfile;
import io.github.hectorvent.floci.testing.PartitionCleanup;
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.services.s3.S3Service;
import io.github.hectorvent.floci.services.ssm.SsmService;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.EnforcementFixtures;
import io.github.hectorvent.floci.testing.PartitionCleanup;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.iam.IamService;
import io.github.hectorvent.floci.services.iam.IamService.InlinePolicyChange;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectSpy;
import io.restassured.response.Response;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
import org.junit.jupiter.api.Test;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.PartitionCleanup;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.PartitionCleanup;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.EnforcementFixtures;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.services.ec2.model.Instance;
import io.github.hectorvent.floci.services.ec2.model.LaunchTemplateData;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
@@ -10,6 +10,7 @@ import io.github.hectorvent.floci.services.cloudwatch.logs.CloudWatchLogsMetricF
import io.github.hectorvent.floci.services.cloudwatch.logs.CloudWatchLogsMetricFilterService.MutationOutcome;
import io.github.hectorvent.floci.services.cloudwatch.logs.CloudWatchLogsMetricFilterService.MutationResult;
import io.github.hectorvent.floci.services.cloudwatch.logs.model.MetricFilter;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectSpy;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectSpy;
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.services.ec2.Ec2Service;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectSpy;
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.services.s3.S3Service;
import io.github.hectorvent.floci.services.ssm.SsmService;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.storage.PersistentStorage;
import io.github.hectorvent.floci.services.cloudformation.model.Stack;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.PartitionCleanup;
import io.github.hectorvent.floci.testing.PersistentStorageProfile;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.services.pipes.PipesService;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectSpy;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RdsMockProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RdsMockProfile;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.services.sqs.SqsService;
import io.github.hectorvent.floci.services.sqs.model.Message;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.http.ContentType;
import io.restassured.response.ValidatableResponse;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.path.xml.XmlPath;
@@ -12,6 +12,7 @@ import io.github.hectorvent.floci.services.scheduler.model.ScheduleRequest;
import io.github.hectorvent.floci.services.sqs.SqsService;
import io.github.hectorvent.floci.services.sqs.model.Message;
import io.github.hectorvent.floci.services.sqs.model.Queue;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectSpy;
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RdsMockProfile;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.path.xml.XmlPath;
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.services.ssm.SsmService;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectSpy;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.path.xml.XmlPath;
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.CloudFormationSettingsProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.Test;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.path.xml.XmlPath;
import io.restassured.specification.RequestSpecification;
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import com.fasterxml.jackson.databind.JsonNode;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.services.cloudformation.model.Stack;
import io.github.hectorvent.floci.services.cloudformation.provisioners.CfnRollback;
import io.github.hectorvent.floci.services.cognito.CognitoService;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectSpy;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.DockerAvailability;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.common.http.TestHTTPResource;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.github.hectorvent.floci.testing.SidecarContainersProfile;
import io.quarkus.test.common.http.TestHTTPResource;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.Test;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.specification.RequestSpecification;
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.services.redshift.model.Endpoint;
import io.github.hectorvent.floci.services.redshiftserverless.RedshiftServerlessRuntime;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.InjectMock;
import io.quarkus.test.junit.QuarkusTest;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation;
import io.github.hectorvent.floci.core.common.XmlParser;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
@@ -1556,4 +1556,17 @@ class EventBridgeServiceTest {
assertEquals("Parameter Source is not valid. Reason: Source is a required argument.",
result.entries().get(0).get("ErrorMessage"));
}
@Test
void serviceEventEntryCarriesTheResourceAndAnEmptyResourcesListWithoutOne() {
Map<String, Object> entry = EventBridgeService.serviceEventEntry("aws.ssm", "Parameter Store Change",
"{\"operation\":\"Create\"}", "arn:aws:ssm:us-east-1:000000000000:parameter/a");
assertEquals(Map.of("Source", "aws.ssm", "DetailType", "Parameter Store Change",
"Detail", "{\"operation\":\"Create\"}",
"Resources", new ObjectMapper().createArrayNode().add("arn:aws:ssm:us-east-1:000000000000:parameter/a")),
entry);
assertEquals(0, ((ArrayNode) EventBridgeService.serviceEventEntry("s", "d", "{}", null).get("Resources")).size());
assertEquals(0, ((ArrayNode) EventBridgeService.serviceEventEntry("s", "d", "{}", " ").get("Resources")).size());
}
}
@@ -1,9 +1,13 @@
package io.github.hectorvent.floci.services.ssm;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.testing.CfnStackWaits;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
import io.restassured.response.ValidatableResponse;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
@@ -14,14 +18,17 @@ import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.stream.Stream;
import static io.github.hectorvent.floci.testing.CfnRequests.cfn;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
@QuarkusTest
@@ -29,6 +36,7 @@ import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
class SsmIntegrationTest {
private static final String SSM_CONTENT_TYPE = "application/x-amz-json-1.1";
private static final ObjectMapper MAPPER = new ObjectMapper();
@BeforeAll
static void configureRestAssured() {
@@ -2315,6 +2323,138 @@ class SsmIntegrationTest {
.then();
}
@Test
void parameterChangesArePublishedToTheDefaultEventBus() throws Exception {
String suffix = Long.toString(System.nanoTime(), 36);
String base = "/events-" + suffix;
String queueUrl = given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "CreateQueue")
.formParam("QueueName", "ssm-events-" + suffix)
.when()
.post("/")
.then()
.statusCode(200)
.extract().xmlPath().getString("CreateQueueResponse.CreateQueueResult.QueueUrl");
String queueArn = given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "GetQueueAttributes")
.formParam("QueueUrl", queueUrl)
.formParam("AttributeName.1", "QueueArn")
.when()
.post("/")
.then()
.statusCode(200)
.extract().xmlPath().getString("**.find { it.Name == 'QueueArn' }.Value");
String pattern = "{\"source\":[\"aws.ssm\"],\"detail-type\":[\"Parameter Store Change\"],"
+ "\"detail\":{\"name\":[{\"prefix\":\"" + base + "/\"}]}}";
events("PutRule", MAPPER.createObjectNode().put("Name", "ssm-events-" + suffix).put("EventPattern", pattern));
events("PutTargets", MAPPER.readTree("{\"Rule\":\"ssm-events-" + suffix + "\","
+ "\"Targets\":[{\"Id\":\"1\",\"Arn\":\"" + queueArn + "\"}]}"));
ssm("PutParameter", "{\"Name\":\"" + base + "/a\",\"Value\":\"v1\",\"Type\":\"String\",\"Description\":\"d\"}")
.statusCode(200);
ssm("PutParameter", "{\"Name\":\"" + base + "/a\",\"Value\":\"v2\",\"Type\":\"String\",\"Description\":\"d\","
+ "\"Overwrite\":true}")
.statusCode(200);
ssm("LabelParameterVersion", "{\"Name\":\"" + base + "/a\",\"ParameterVersion\":2,\"Labels\":[\"stable\"]}")
.statusCode(200);
ssm("UnlabelParameterVersion", "{\"Name\":\"" + base + "/a\",\"ParameterVersion\":2,\"Labels\":[\"stable\"]}")
.statusCode(200);
ssm("PutParameter", "{\"Name\":\"" + base + "/a\",\"Value\":\"v3\",\"Type\":\"String\"}")
.statusCode(400)
.body("__type", equalTo("ParameterAlreadyExists"));
String arn = ssm("GetParameter", "{\"Name\":\"" + base + "/a\"}").statusCode(200)
.extract().path("Parameter.ARN");
ssm("DeleteParameter", "{\"Name\":\"" + base + "/a\"}").statusCode(200);
ssm("PutParameter", "{\"Name\":\"" + base + "/b\",\"Value\":\"v\",\"Type\":\"String\"}").statusCode(200);
ssm("DeleteParameters", "{\"Names\":[\"" + base + "/b\",\"" + base + "/missing\"]}").statusCode(200);
String stack = "ssm-events-" + suffix;
cfn("CreateStack", stack).formParam("TemplateBody", "{\"Resources\":{\"P\":{\"Type\":\"AWS::SSM::Parameter\","
+ "\"Properties\":{\"Name\":\"" + base + "/cfn\",\"Type\":\"String\",\"Value\":\"v\"}}}}")
.when().post("/").then().statusCode(200);
CfnStackWaits.awaitStatus(stack, "CREATE_COMPLETE");
cfn("DeleteStack", stack).when().post("/").then().statusCode(200);
List<JsonNode> received = receiveEvents(queueUrl, 9);
assertEquals(List.of("Create " + base + "/a", "Update " + base + "/a",
"LabelParameterVersion " + base + "/a", "UnlabelParameterVersion " + base + "/a",
"Delete " + base + "/a",
"Create " + base + "/b", "Delete " + base + "/b",
"Create " + base + "/cfn", "Delete " + base + "/cfn"),
received.stream().map(e -> e.at("/detail/operation").asText() + " " + e.at("/detail/name").asText())
.toList());
JsonNode created = received.getFirst();
assertEquals("aws.ssm", created.path("source").asText());
assertEquals("Parameter Store Change", created.path("detail-type").asText());
assertEquals(arn, created.at("/resources/0").asText());
assertEquals("us-east-1", created.path("region").asText());
assertFalse(created.path("account").asText().isEmpty());
assertEquals(MAPPER.readTree("{\"operation\":\"Create\",\"name\":\"" + base + "/a\",\"type\":\"String\","
+ "\"description\":\"d\"}"), created.path("detail"));
assertEquals(MAPPER.readTree("{\"operation\":\"LabelParameterVersion\",\"name\":\"" + base + "/a\","
+ "\"type\":\"String\",\"description\":\"d\",\"label\":\"stable\",\"fromVersion\":\"\",\"toVersion\":\"2\"}"),
received.get(2).path("detail"));
assertEquals(MAPPER.readTree("{\"operation\":\"UnlabelParameterVersion\",\"name\":\"" + base + "/a\","
+ "\"type\":\"String\",\"description\":\"d\",\"labels\":[\"stable\"],\"fromVersion\":\"2\",\"toVersion\":\"\"}"),
received.get(3).path("detail"));
events("RemoveTargets", MAPPER.readTree("{\"Rule\":\"ssm-events-" + suffix + "\",\"Ids\":[\"1\"]}"));
events("DeleteRule", MAPPER.createObjectNode().put("Name", "ssm-events-" + suffix));
given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DeleteQueue")
.formParam("QueueUrl", queueUrl)
.when()
.post("/")
.then()
.statusCode(200);
}
private static ValidatableResponse ssm(String action, String body) {
return given()
.header("X-Amz-Target", "AmazonSSM." + action)
.contentType(SSM_CONTENT_TYPE)
.body(body)
.when()
.post("/")
.then();
}
private static void events(String action, JsonNode body) {
given()
.header("X-Amz-Target", "AWSEvents." + action)
.contentType(SSM_CONTENT_TYPE)
.body(body.toString())
.when()
.post("/")
.then()
.statusCode(200);
}
private static List<JsonNode> receiveEvents(String queueUrl, int expected) throws Exception {
List<JsonNode> received = new ArrayList<>();
long deadline = System.currentTimeMillis() + 10_000;
while (received.size() < expected && System.currentTimeMillis() < deadline) {
List<String> bodies = given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "ReceiveMessage")
.formParam("QueueUrl", queueUrl)
.formParam("MaxNumberOfMessages", "10")
.formParam("WaitTimeSeconds", "1")
.when()
.post("/")
.then()
.statusCode(200)
.extract().xmlPath().getList("ReceiveMessageResponse.ReceiveMessageResult.Message.Body");
for (String body : bodies) {
received.add(MAPPER.readTree(body));
}
}
return received;
}
private io.restassured.response.ValidatableResponse describeParameters(String body) {
return given()
.header("X-Amz-Target", "AmazonSSM.DescribeParameters")
@@ -1,9 +1,12 @@
package io.github.hectorvent.floci.services.ssm;
import com.fasterxml.jackson.databind.JsonNode;
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.InMemoryStorage;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.services.eventbridge.EventBridgeService;
import io.github.hectorvent.floci.services.secretsmanager.SecretsManagerService;
import io.github.hectorvent.floci.services.secretsmanager.model.Secret;
import io.github.hectorvent.floci.services.secretsmanager.model.SecretVersion;
@@ -17,6 +20,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.time.Instant;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -32,11 +36,18 @@ import java.util.concurrent.TimeoutException;
import java.util.function.Predicate;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
class SsmServiceTest {
private static final ObjectMapper MAPPER = new ObjectMapper();
private final List<Map<String, Object>> events = new ArrayList<>();
private SsmService ssmService;
@BeforeEach
@@ -1693,6 +1704,184 @@ class SsmServiceTest {
assertEquals("ParameterNotFound", ex.getErrorCode());
}
@Test
void putParameterPublishesCreateWithTheDescription() throws Exception {
SsmService service = serviceRecordingEvents();
service.putParameter("/events/a", "v", "SecureString", "the db", false, "us-east-1");
assertEquals(1, events.size());
assertEvent(events.getFirst(), service.getParameter("/events/a", "us-east-1").getArn(),
Map.of("operation", "Create", "name", "/events/a", "type", "SecureString",
"description", "the db"));
}
@Test
void putParameterOverwritePublishesUpdateEvenForTheSameValue() throws Exception {
SsmService service = serviceRecordingEvents();
service.putParameter("/events/a", "v", "String", null, false, "us-east-1");
service.putParameter("/events/a", "v", "String", null, true, "us-east-1");
assertEquals(2, events.size());
assertEvent(events.get(1), service.getParameter("/events/a", "us-east-1").getArn(),
Map.of("operation", "Update", "name", "/events/a", "type", "String"));
}
@Test
void failedPutParameterPublishesNothing() {
SsmService service = serviceRecordingEvents();
service.putParameter("/events/a", "v", "String", null, false, "us-east-1");
events.clear();
assertThrows(AwsException.class, () ->
service.putParameter("/events/a", "w", "String", null, false, "us-east-1"));
assertTrue(events.isEmpty());
}
@Test
void deleteParameterPublishesDeleteWithTheDeletedParametersFields() throws Exception {
SsmService service = serviceRecordingEvents();
service.putParameter("/events/a", "x,y", "StringList", "list", false, "us-east-1");
String arn = service.getParameter("/events/a", "us-east-1").getArn();
events.clear();
service.deleteParameter("/events/a", "us-east-1");
assertThrows(AwsException.class, () -> service.deleteParameter("/events/a", "us-east-1"));
assertEquals(1, events.size());
assertEvent(events.getFirst(), arn,
Map.of("operation", "Delete", "name", "/events/a", "type", "StringList", "description", "list"));
}
@Test
void deleteParametersPublishesOneDeletePerDeletedName() throws Exception {
SsmService service = serviceRecordingEvents();
service.putParameter("/events/a", "v", "String", null, false, "us-east-1");
String arn = service.getParameter("/events/a", "us-east-1").getArn();
events.clear();
service.deleteParameters(List.of("/events/a", "/events/missing"), "us-east-1");
assertEquals(1, events.size());
assertEvent(events.getFirst(), arn, Map.of("operation", "Delete", "name", "/events/a", "type", "String"));
}
@Test
void labelParameterVersionPublishesOnlyLabelsThatAreAttachedOrMoved() throws Exception {
SsmService service = serviceRecordingEvents();
service.putParameter("/events/a", "v1", "String", null, false, "us-east-1");
service.putParameter("/events/a", "v2", "String", null, true, "us-east-1");
String arn = service.getParameter("/events/a", "us-east-1").getArn();
events.clear();
service.labelParameterVersion("/events/a", 1L, List.of("a"), "us-east-1");
service.labelParameterVersion("/events/a", 2L, List.of("a", "b", "1abc", "awsx"), "us-east-1");
service.labelParameterVersion("/events/a", 2L, List.of("a"), "us-east-1");
assertEquals(3, events.size());
assertEvent(events.get(0), arn, labelDetail("a", "", "1"));
assertEvent(events.get(1), arn, labelDetail("a", "1", "2"));
assertEvent(events.get(2), arn, labelDetail("b", "", "2"));
}
@Test
void labelParameterVersionPublishesTheLabelledVersionsTypeAndDescription() throws Exception {
SsmService service = serviceRecordingEvents();
service.putParameter("/events/a", "v", "String", "one", false, "us-east-1");
service.putParameter("/events/a", "x,y", "StringList", "two", true, "us-east-1");
String arn = service.getParameter("/events/a", "us-east-1").getArn();
events.clear();
service.labelParameterVersion("/events/a", 1L, List.of("old"), "us-east-1");
assertEquals(1, events.size());
assertEvent(events.getFirst(), arn, Map.of("operation", "LabelParameterVersion", "name", "/events/a",
"type", "String", "description", "one", "label", "old", "fromVersion", "", "toVersion", "1"));
}
@Test
void unlabelParameterVersionPublishesOneEventWithTheLabelsItRemoved() throws Exception {
SsmService service = serviceRecordingEvents();
service.putParameter("/events/a", "v", "String", "one", false, "us-east-1");
service.putParameter("/events/a", "w", "String", null, true, "us-east-1");
service.labelParameterVersion("/events/a", 1L, List.of("x", "y"), "us-east-1");
String arn = service.getParameter("/events/a", "us-east-1").getArn();
events.clear();
service.unlabelParameterVersion("/events/a", 1L, List.of("y", "missing"), "us-east-1");
service.unlabelParameterVersion("/events/a", 2L, List.of("x"), "us-east-1");
assertEquals(1, events.size());
assertEvent(events.getFirst(), arn, Map.of("operation", "UnlabelParameterVersion", "name", "/events/a",
"type", "String", "description", "one", "labels", List.of("y"), "fromVersion", "1", "toVersion", ""));
}
@Test
void writesPublishOutsideTheServiceMonitor() {
EventBridgeService eventBridge = mock(EventBridgeService.class);
SsmService service = serviceWith(eventBridge);
List<Boolean> monitorHeld = new ArrayList<>();
when(eventBridge.putEvents(anyList(), anyString())).thenAnswer(invocation -> {
monitorHeld.add(Thread.holdsLock(service));
return null;
});
service.putParameter("/events/a", "v", "String", null, false, "us-east-1");
service.putParameter("/events/b", "v", "String", null, false, "us-east-1");
service.labelParameterVersion("/events/a", 1L, List.of("a"), "us-east-1");
service.labelParameterVersion("/events/a", 1, List.of("b"), "us-east-1");
service.unlabelParameterVersion("/events/a", 1, List.of("b"), "us-east-1");
service.deleteParameter("/events/a", "us-east-1");
service.deleteParameters(List.of("/events/b"), "us-east-1");
assertEquals(List.of(false, false, false, false, false, false, false), monitorHeld);
}
@Test
void aFailingEventBusNeitherFailsNorUndoesTheWrite() {
EventBridgeService eventBridge = mock(EventBridgeService.class);
when(eventBridge.putEvents(anyList(), anyString())).thenThrow(new RuntimeException("bus down"));
SsmService service = serviceWith(eventBridge);
assertEquals(1, service.putParameter("/events/a", "v", "String", null, false, "us-east-1"));
verify(eventBridge).putEvents(anyList(), eq("us-east-1"));
assertEquals("v", service.getParameter("/events/a", "us-east-1").getValue());
}
private SsmService serviceRecordingEvents() {
EventBridgeService eventBridge = mock(EventBridgeService.class);
when(eventBridge.putEvents(anyList(), eq("us-east-1"))).thenAnswer(invocation -> {
events.addAll(invocation.getArgument(0));
return null;
});
return serviceWith(eventBridge);
}
private static SsmService serviceWith(EventBridgeService eventBridge) {
return new SsmService(new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(),
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>(), 5,
new RegionResolver("us-east-1", "000000000000"), null, null,
new SsmEventPublisher(eventBridge, MAPPER));
}
private static Map<String, String> labelDetail(String label, String fromVersion, String toVersion) {
return Map.of("operation", "LabelParameterVersion", "name", "/events/a", "type", "String",
"label", label, "fromVersion", fromVersion, "toVersion", toVersion);
}
private static void assertEvent(Map<String, Object> entry, String arn, Map<String, ?> detail)
throws Exception {
assertEquals("aws.ssm", entry.get("Source"));
assertEquals("Parameter Store Change", entry.get("DetailType"));
JsonNode expectedResources = MAPPER.valueToTree(List.of(arn));
assertEquals(expectedResources, MAPPER.valueToTree(entry.get("Resources")));
JsonNode expectedDetail = MAPPER.valueToTree(detail);
assertEquals(expectedDetail, MAPPER.readTree((String) entry.get("Detail")));
}
private List<String> describedNames(List<ParameterStringFilter> filters, String region) {
return ssmService.describeParameters(filters, region).stream().map(Parameter::getName).toList();
}
@@ -1,4 +1,4 @@
package io.github.hectorvent.floci.services.cloudformation;
package io.github.hectorvent.floci.testing;
import io.restassured.path.xml.XmlPath;
import io.restassured.path.xml.element.Node;
@@ -18,13 +18,13 @@ import static org.junit.jupiter.api.Assertions.fail;
* DeleteStack answers before the stack is gone. The deletion runs on an executor, so a test
* that looks at the stack's resources right after the answer races it.
*/
final class CfnStackWaits {
public final class CfnStackWaits {
private CfnStackWaits() {
}
/** What DescribeStacks reported: the status and, when present, the StackStatusReason. */
record StackState(String status, String reason) {
public record StackState(String status, String reason) {
}
private static final Set<String> TERMINAL = Set.of(
@@ -40,11 +40,11 @@ final class CfnStackWaits {
* stack does not exist) fails at once with the error body rather than polling the clock out;
* ten seconds without a terminal status fails too.
*/
static StackState awaitTerminal(String stackName) {
public static StackState awaitTerminal(String stackName) {
return awaitTerminal(stackName, null);
}
static StackState awaitTerminal(String stackName, String authorization) {
public static StackState awaitTerminal(String stackName, String authorization) {
long deadline = System.currentTimeMillis() + 10_000;
StackState last = new StackState(null, "");
while (System.currentTimeMillis() < deadline) {
@@ -82,7 +82,7 @@ final class CfnStackWaits {
* terminal status fails at once with its reason, as do a DescribeStacks that is not 200 and ten
* seconds without the expected status.
*/
static StackState awaitStatus(String stackName, String expectedStatus) {
public static StackState awaitStatus(String stackName, String expectedStatus) {
long deadline = System.currentTimeMillis() + 10_000;
StackState last = new StackState(null, "");
while (System.currentTimeMillis() < deadline) {
@@ -122,11 +122,11 @@ final class CfnStackWaits {
* stack's own reason only names the failed resource, as on AWS, so the failure's message is read
* here. Fails when DescribeStackEvents is not 200 or no resource failed in that operation.
*/
static String failedResourceReason(String stackName) {
public static String failedResourceReason(String stackName) {
return failedResourceReason(stackName, null);
}
static String failedResourceReason(String stackName, String authorization) {
public static String failedResourceReason(String stackName, String authorization) {
RequestSpecification request = given()
.contentType("application/x-www-form-urlencoded")
.formParam("Action", "DescribeStackEvents")
@@ -166,11 +166,11 @@ final class CfnStackWaits {
* Waits until DescribeStacks answers 400, which is how a missing stack is reported. Fails on
* DELETE_FAILED or after ten seconds.
*/
static void awaitStackDeleted(String stackName) {
public static void awaitStackDeleted(String stackName) {
awaitStackDeleted(stackName, null);
}
static void awaitStackDeleted(String stackName, String authorization) {
public static void awaitStackDeleted(String stackName, String authorization) {
long deadline = System.currentTimeMillis() + 10_000;
String body = "";
while (System.currentTimeMillis() < deadline) {