feat(appintegrations): add data and event integrations (#3379)

* feat(appintegrations): add data and event integrations

Amazon AppIntegrations over REST JSON, registered under the app-integrations
signing name: event integrations on /eventIntegrations, data integrations on
/dataIntegrations, and resource tagging through the shared /tags/{resourceArn}
dispatcher. Terraform's aws_appintegrations_event_integration and
aws_appintegrations_data_integration now round-trip against Floci instead of
failing on an unimplemented signing scope.

Event integrations are keyed by name, data integrations by generated id, and
both accept their own ARN wherever the API takes an identifier. The two PATCH
operations apply only the members present in the request body, matching how AWS
treats an optional member the caller did not send. Both tag writes answer 200,
which is what the 2020-07-29 model gives them.

* test(appintegrations): add an SDK compatibility test

Adds the appintegrations AWS SDK v2 module, a TestFixtures client factory,
and an AppIntegrationsTest that drives both integration types and the tag
round trip through the real SDK client.
This commit is contained in:
lex00 authored and GitHub committed 2026-09-11 17:55:48 -04:00
1 parent 2e79f5c766
commit 137a39add3
19 files changed
+1691 -1

No files matched your search

@@ -0,0 +1,396 @@
package io.github.hectorvent.floci.services.appintegrations;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
@QuarkusTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class AppIntegrationsIntegrationTest {
private static final String EVENT_INTEGRATION_NAME = "floci-event-integration";
private static String eventIntegrationArn;
private static String dataIntegrationId;
private static String dataIntegrationArn;
@Test
@Order(1)
void createEventIntegration() {
eventIntegrationArn = given()
.contentType("application/json")
.body("""
{
"Name": "%s",
"Description": "partner events",
"EventBridgeBus": "floci-bus",
"EventFilter": {"Source": "aws.partner/example.com/1234"},
"Tags": {"team": "data"}
}
""".formatted(EVENT_INTEGRATION_NAME))
.when()
.post("/eventIntegrations")
.then()
.statusCode(200)
.body("EventIntegrationArn", containsString(":app-integrations:"))
.body("EventIntegrationArn", containsString(":event-integration/" + EVENT_INTEGRATION_NAME))
.extract().path("EventIntegrationArn");
}
@Test
@Order(2)
void getEventIntegrationEchoesTheRequest() {
given()
.when()
.get("/eventIntegrations/" + EVENT_INTEGRATION_NAME)
.then()
.statusCode(200)
.body("Name", equalTo(EVENT_INTEGRATION_NAME))
.body("Description", equalTo("partner events"))
.body("EventIntegrationArn", equalTo(eventIntegrationArn))
.body("EventBridgeBus", equalTo("floci-bus"))
.body("EventFilter.Source", equalTo("aws.partner/example.com/1234"))
.body("Tags.team", equalTo("data"));
}
@Test
@Order(3)
void listEventIntegrations() {
given()
.when()
.get("/eventIntegrations")
.then()
.statusCode(200)
.body("EventIntegrations.Name", hasItem(EVENT_INTEGRATION_NAME))
.body("EventIntegrations.find { it.Name == '" + EVENT_INTEGRATION_NAME + "' }.EventBridgeBus",
equalTo("floci-bus"));
}
@Test
@Order(4)
void listEventIntegrationAssociationsIsEmptyForANewIntegration() {
given()
.when()
.get("/eventIntegrations/" + EVENT_INTEGRATION_NAME + "/associations")
.then()
.statusCode(200)
.body("EventIntegrationAssociations.size()", equalTo(0));
}
@Test
@Order(5)
void listAssociationsForAMissingIntegrationReturnsResourceNotFound() {
given()
.when()
.get("/eventIntegrations/no-such-integration/associations")
.then()
.statusCode(404)
.body("__type", equalTo("ResourceNotFoundException"));
}
@Test
@Order(6)
void tagRoundTripOnTheEventIntegration() {
given()
.when()
.get("/tags/" + eventIntegrationArn)
.then()
.statusCode(200)
.body("tags.team", equalTo("data"));
given()
.contentType("application/json")
.body("{\"tags\": {\"env\": \"test\"}}")
.when()
.post("/tags/" + eventIntegrationArn)
.then()
.statusCode(200);
given()
.when()
.get("/tags/" + eventIntegrationArn)
.then()
.statusCode(200)
.body("tags.env", equalTo("test"));
given()
.queryParam("tagKeys", "env")
.when()
.delete("/tags/" + eventIntegrationArn)
.then()
.statusCode(200);
given()
.when()
.get("/tags/" + eventIntegrationArn)
.then()
.statusCode(200)
.body("tags.env", nullValue())
.body("tags.team", equalTo("data"));
}
@Test
@Order(7)
void updateEventIntegration() {
given()
.contentType("application/json")
.body("{\"Description\": \"partner events, revised\"}")
.when()
.patch("/eventIntegrations/" + EVENT_INTEGRATION_NAME)
.then()
.statusCode(200);
given()
.when()
.get("/eventIntegrations/" + EVENT_INTEGRATION_NAME)
.then()
.statusCode(200)
.body("Description", equalTo("partner events, revised"))
.body("EventBridgeBus", equalTo("floci-bus"))
.body("EventFilter.Source", equalTo("aws.partner/example.com/1234"));
given()
.contentType("application/json")
.body("{}")
.when()
.patch("/eventIntegrations/" + EVENT_INTEGRATION_NAME)
.then()
.statusCode(200);
given()
.when()
.get("/eventIntegrations/" + EVENT_INTEGRATION_NAME)
.then()
.statusCode(200)
.body("Description", equalTo("partner events, revised"));
}
@Test
@Order(8)
void duplicateEventIntegrationNameReturnsDuplicateResource() {
given()
.contentType("application/json")
.body("""
{
"Name": "%s",
"EventBridgeBus": "floci-bus",
"EventFilter": {"Source": "aws.partner/example.com/1234"}
}
""".formatted(EVENT_INTEGRATION_NAME))
.when()
.post("/eventIntegrations")
.then()
.statusCode(409)
.body("__type", equalTo("DuplicateResourceException"));
}
@Test
@Order(9)
void createEventIntegrationWithoutEventFilterReturnsInvalidRequest() {
given()
.contentType("application/json")
.body("{\"Name\": \"no-filter\", \"EventBridgeBus\": \"floci-bus\"}")
.when()
.post("/eventIntegrations")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidRequestException"));
}
@Test
@Order(10)
void getMissingEventIntegrationReturnsResourceNotFound() {
given()
.when()
.get("/eventIntegrations/no-such-integration")
.then()
.statusCode(404)
.body("__type", equalTo("ResourceNotFoundException"));
}
@Test
@Order(11)
void createDataIntegration() {
var response = given()
.contentType("application/json")
.body("""
{
"Name": "floci-data-integration",
"Description": "salesforce pull",
"KmsKey": "arn:aws:kms:us-east-1:000000000000:key/abc",
"SourceURI": "Salesforce://AppFlow/test",
"ScheduleConfig": {"ScheduleExpression": "rate(1 hour)", "FirstExecutionFrom": "1439788800000"},
"FileConfiguration": {"Folders": ["/home/data"]},
"Tags": {"team": "data"}
}
""")
.when()
.post("/dataIntegrations")
.then()
.statusCode(200)
.body("Id", notNullValue())
.body("Arn", containsString(":data-integration/"))
.body("Name", equalTo("floci-data-integration"))
.body("KmsKey", equalTo("arn:aws:kms:us-east-1:000000000000:key/abc"))
.body("SourceURI", equalTo("Salesforce://AppFlow/test"))
.body("ScheduleConfiguration.ScheduleExpression", equalTo("rate(1 hour)"))
.body("FileConfiguration.Folders[0]", equalTo("/home/data"))
.body("Tags.team", equalTo("data"))
.extract();
dataIntegrationId = response.path("Id");
dataIntegrationArn = response.path("Arn");
}
@Test
@Order(12)
void getDataIntegrationByIdAndByArn() {
given()
.when()
.get("/dataIntegrations/" + dataIntegrationId)
.then()
.statusCode(200)
.body("Id", equalTo(dataIntegrationId))
.body("Arn", equalTo(dataIntegrationArn))
.body("Description", equalTo("salesforce pull"))
.body("ScheduleConfiguration.FirstExecutionFrom", equalTo("1439788800000"));
String encodedArn = java.net.URLEncoder.encode(dataIntegrationArn,
java.nio.charset.StandardCharsets.UTF_8);
given()
.urlEncodingEnabled(false)
.when()
.get("/dataIntegrations/" + encodedArn)
.then()
.statusCode(200)
.body("Id", equalTo(dataIntegrationId));
}
@Test
@Order(13)
void listDataIntegrations() {
given()
.when()
.get("/dataIntegrations")
.then()
.statusCode(200)
.body("DataIntegrations.Name", hasItem("floci-data-integration"))
.body("DataIntegrations.find { it.Name == 'floci-data-integration' }.Arn",
equalTo(dataIntegrationArn))
.body("DataIntegrations.find { it.Name == 'floci-data-integration' }.SourceURI",
equalTo("Salesforce://AppFlow/test"));
}
@Test
@Order(14)
void tagRoundTripOnTheDataIntegration() {
given()
.contentType("application/json")
.body("{\"tags\": {\"tier\": \"gold\"}}")
.when()
.post("/tags/" + dataIntegrationArn)
.then()
.statusCode(200);
given()
.when()
.get("/tags/" + dataIntegrationArn)
.then()
.statusCode(200)
.body("tags.tier", equalTo("gold"))
.body("tags.team", equalTo("data"));
}
@Test
@Order(15)
void updateDataIntegration() {
given()
.contentType("application/json")
.body("{\"Description\": \"salesforce pull, revised\"}")
.when()
.patch("/dataIntegrations/" + dataIntegrationId)
.then()
.statusCode(200);
given()
.when()
.get("/dataIntegrations/" + dataIntegrationId)
.then()
.statusCode(200)
.body("Description", equalTo("salesforce pull, revised"))
.body("Name", equalTo("floci-data-integration"));
}
@Test
@Order(16)
void createDataIntegrationWithoutKmsKeyReturnsInvalidRequest() {
given()
.contentType("application/json")
.body("{\"Name\": \"no-key\"}")
.when()
.post("/dataIntegrations")
.then()
.statusCode(400)
.body("__type", equalTo("InvalidRequestException"));
}
@Test
@Order(17)
void getMissingDataIntegrationReturnsResourceNotFound() {
given()
.when()
.get("/dataIntegrations/00000000-0000-0000-0000-00000000dead")
.then()
.statusCode(404)
.body("__type", equalTo("ResourceNotFoundException"));
}
@Test
@Order(18)
void deleteDataIntegration() {
given()
.when()
.delete("/dataIntegrations/" + dataIntegrationId)
.then()
.statusCode(200);
given()
.when()
.get("/dataIntegrations/" + dataIntegrationId)
.then()
.statusCode(404)
.body("__type", equalTo("ResourceNotFoundException"));
}
@Test
@Order(19)
void deleteEventIntegration() {
given()
.when()
.delete("/eventIntegrations/" + EVENT_INTEGRATION_NAME)
.then()
.statusCode(200);
given()
.when()
.get("/eventIntegrations/" + EVENT_INTEGRATION_NAME)
.then()
.statusCode(404)
.body("__type", equalTo("ResourceNotFoundException"));
given()
.when()
.delete("/eventIntegrations/" + EVENT_INTEGRATION_NAME)
.then()
.statusCode(404)
.body("__type", equalTo("ResourceNotFoundException"));
}
}
@@ -0,0 +1,196 @@
package io.github.hectorvent.floci.services.appintegrations;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
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.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.appintegrations.model.DataIntegration;
import io.github.hectorvent.floci.services.appintegrations.model.EventIntegration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* AppIntegrations domain rules that the REST layer only passes through: required members,
* duplicate names, ARN-or-id resolution, and the partial-update semantics of the two
* PATCH operations.
*/
class AppIntegrationsServiceTest {
private static final String REGION = "us-east-1";
private static final ObjectMapper MAPPER = new ObjectMapper();
private AppIntegrationsService service;
@BeforeEach
void setUp() {
service = new AppIntegrationsService(new SharedStorageFactory(),
new RegionResolver(REGION, "000000000000"));
}
@Test
void createEventIntegrationBuildsTheAwsArnAndStoresTheFilterSource() {
EventIntegration integration = service.createEventIntegration("orders", "partner events",
eventFilter("aws.partner/example.com/1234"), "floci-bus", Map.of("team", "data"), REGION);
assertEquals("arn:aws:app-integrations:us-east-1:000000000000:event-integration/orders",
integration.getEventIntegrationArn());
assertEquals("aws.partner/example.com/1234", integration.getEventFilterSource());
assertEquals("floci-bus", integration.getEventBridgeBus());
assertEquals("data", integration.getTags().get("team"));
}
@Test
void createEventIntegrationRejectsAMissingRequiredMember() {
AwsException noName = assertThrows(AwsException.class, () -> service.createEventIntegration(
null, null, eventFilter("aws.partner/x"), "floci-bus", Map.of(), REGION));
assertEquals("InvalidRequestException", noName.getErrorCode());
AwsException noBus = assertThrows(AwsException.class, () -> service.createEventIntegration(
"orders", null, eventFilter("aws.partner/x"), null, Map.of(), REGION));
assertEquals("InvalidRequestException", noBus.getErrorCode());
AwsException noFilter = assertThrows(AwsException.class, () -> service.createEventIntegration(
"orders", null, null, "floci-bus", Map.of(), REGION));
assertEquals("InvalidRequestException", noFilter.getErrorCode());
}
@Test
void duplicateEventIntegrationNameRaisesDuplicateResource() {
service.createEventIntegration("orders", null, eventFilter("aws.partner/x"), "bus", Map.of(), REGION);
AwsException duplicate = assertThrows(AwsException.class, () -> service.createEventIntegration(
"orders", null, eventFilter("aws.partner/x"), "bus", Map.of(), REGION));
assertEquals("DuplicateResourceException", duplicate.getErrorCode());
assertEquals(409, duplicate.getHttpStatus());
}
@Test
void updateEventIntegrationLeavesAnAbsentDescriptionAlone() {
service.createEventIntegration("orders", "first", eventFilter("aws.partner/x"), "bus", Map.of(), REGION);
service.updateEventIntegration("orders", Optional.of("second"), REGION);
assertEquals("second", service.getEventIntegration("orders", REGION).getDescription());
service.updateEventIntegration("orders", Optional.empty(), REGION);
assertEquals("second", service.getEventIntegration("orders", REGION).getDescription());
}
@Test
void getMissingEventIntegrationRaisesResourceNotFound() {
AwsException missing = assertThrows(AwsException.class,
() -> service.getEventIntegration("nope", REGION));
assertEquals("ResourceNotFoundException", missing.getErrorCode());
assertEquals(404, missing.getHttpStatus());
}
@Test
void createDataIntegrationRequiresNameAndKmsKey() {
AwsException noName = assertThrows(AwsException.class, () -> service.createDataIntegration(
null, null, "arn:aws:kms:us-east-1:000000000000:key/abc", null, null, null, null,
Map.of(), REGION));
assertEquals("InvalidRequestException", noName.getErrorCode());
AwsException noKey = assertThrows(AwsException.class, () -> service.createDataIntegration(
"orders", null, null, null, null, null, null, Map.of(), REGION));
assertEquals("InvalidRequestException", noKey.getErrorCode());
}
@Test
void dataIntegrationResolvesByIdAndByItsOwnArn() {
DataIntegration created = service.createDataIntegration("orders", "pull", "key/abc",
"Salesforce://AppFlow/test", null, null, null, Map.of(), REGION);
assertEquals(created.getId(), service.getDataIntegration(created.getId(), REGION).getId());
assertEquals(created.getId(), service.getDataIntegration(created.getArn(), REGION).getId());
AwsException wrongType = assertThrows(AwsException.class, () -> service.getDataIntegration(
"arn:aws:app-integrations:us-east-1:000000000000:event-integration/orders", REGION));
assertEquals("InvalidRequestException", wrongType.getErrorCode());
}
@Test
void updateDataIntegrationAppliesOnlyThePresentMembers() {
DataIntegration created = service.createDataIntegration("orders", "pull", "key/abc",
null, null, null, null, Map.of(), REGION);
service.updateDataIntegration(created.getId(), Optional.empty(), Optional.of("revised"), REGION);
DataIntegration updated = service.getDataIntegration(created.getId(), REGION);
assertEquals("orders", updated.getName());
assertEquals("revised", updated.getDescription());
}
@Test
void tagsAreSharedAcrossBothResourceTypesByArn() {
EventIntegration event = service.createEventIntegration("orders", null,
eventFilter("aws.partner/x"), "bus", Map.of("team", "data"), REGION);
DataIntegration data = service.createDataIntegration("orders-data", null, "key/abc",
null, null, null, null, Map.of(), REGION);
service.tagResource(REGION, data.getArn(), Map.of("tier", "gold"));
assertEquals("gold", service.listTags(REGION, data.getArn()).get("tier"));
assertEquals("data", service.listTags(REGION, event.getEventIntegrationArn()).get("team"));
service.untagResource(REGION, event.getEventIntegrationArn(), List.of("team"));
assertTrue(service.listTags(REGION, event.getEventIntegrationArn()).isEmpty());
AwsException unknown = assertThrows(AwsException.class, () -> service.listTags(REGION,
"arn:aws:app-integrations:us-east-1:000000000000:data-integration/missing"));
assertEquals("ResourceNotFoundException", unknown.getErrorCode());
}
@Test
void tagWritesAnswerTwoHundredAsTheAwsModelDoes() {
assertEquals(200, service.tagResourceSuccessStatus());
assertEquals(200, service.untagResourceSuccessStatus());
assertEquals("app-integrations", service.serviceKey());
}
@Test
void deleteRemovesTheIntegrationFromItsListing() {
service.createEventIntegration("orders", null, eventFilter("aws.partner/x"), "bus", Map.of(), REGION);
DataIntegration data = service.createDataIntegration("orders-data", null, "key/abc",
null, null, null, null, Map.of(), REGION);
service.deleteEventIntegration("orders", REGION);
service.deleteDataIntegration(data.getArn(), REGION);
assertTrue(service.listEventIntegrations(REGION).isEmpty());
assertTrue(service.listDataIntegrations(REGION).isEmpty());
}
private ObjectNode eventFilter(String source) {
ObjectNode filter = MAPPER.createObjectNode();
filter.put("Source", source);
return filter;
}
private static final class SharedStorageFactory extends StorageFactory {
private final Map<String, StorageBackend<String, ?>> stores = new HashMap<>();
private SharedStorageFactory() {
super(null, null);
}
@Override
@SuppressWarnings("unchecked")
public <V> AccountAwareStorageBackend<V> create(String serviceName, String fileName,
TypeReference<Map<String, V>> typeReference) {
return (AccountAwareStorageBackend<V>) stores.computeIfAbsent(
fileName, ignored -> AccountAwareStorageBackend.inMemory("000000000000"));
}
}
}