mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
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:
1 parent
2e79f5c766
commit
137a39add3
19 files changed
+1691
-1
No files matched your search
@@ -739,6 +739,7 @@ public interface EmulatorConfig {
|
||||
ControlCatalogServiceConfig controlcatalog();
|
||||
ControlTowerServiceConfig controltower();
|
||||
ConnectServiceConfig connect();
|
||||
AppIntegrationsServiceConfig appintegrations();
|
||||
CognitoIdentityServiceConfig cognitoidentity();
|
||||
GlobalAcceleratorServiceConfig globalaccelerator();
|
||||
|
||||
@@ -755,6 +756,11 @@ public interface EmulatorConfig {
|
||||
boolean enabled();
|
||||
}
|
||||
|
||||
interface AppIntegrationsServiceConfig {
|
||||
@WithDefault("true")
|
||||
boolean enabled();
|
||||
}
|
||||
|
||||
interface CognitoIdentityServiceConfig {
|
||||
@WithDefault("true")
|
||||
boolean enabled();
|
||||
|
||||
@@ -607,6 +607,12 @@ public class ResolvedServiceCatalog {
|
||||
protocols(ServiceProtocol.REST_JSON),
|
||||
Set.of(), Set.of("connect"), Set.of(),
|
||||
Set.of(io.github.hectorvent.floci.services.connect.ConnectController.class)),
|
||||
descriptor("app-integrations", "appintegrations",
|
||||
config.services().appintegrations().enabled(), true,
|
||||
"appintegrations", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,
|
||||
protocols(ServiceProtocol.REST_JSON),
|
||||
Set.of(), Set.of("app-integrations"), Set.of(),
|
||||
Set.of(io.github.hectorvent.floci.services.appintegrations.AppIntegrationsController.class)),
|
||||
descriptor("cognito-identity", "cognitoidentity",
|
||||
config.services().cognitoidentity().enabled(), true,
|
||||
"cognitoidentity", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
|
||||
|
||||
+265
@@ -0,0 +1,265 @@
|
||||
package io.github.hectorvent.floci.services.appintegrations;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.JsonErrorResponseUtils;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.services.appintegrations.model.DataIntegration;
|
||||
import io.github.hectorvent.floci.services.appintegrations.model.EventIntegration;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
import jakarta.ws.rs.DELETE;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.PATCH;
|
||||
import jakarta.ws.rs.POST;
|
||||
import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.WebApplicationException;
|
||||
import jakarta.ws.rs.core.Context;
|
||||
import jakarta.ws.rs.core.HttpHeaders;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Amazon AppIntegrations REST-JSON controller (API version 2020-07-29).
|
||||
*
|
||||
* <p>Tag operations live on the shared {@code /tags/{resourceArn}} path and are served by
|
||||
* {@code SharedTagsController} through {@link AppIntegrationsService}'s {@code TagHandler}.
|
||||
* Only the operations declared below are served; anything else falls through to the
|
||||
* emulator's not-found handling rather than a stub success.
|
||||
*/
|
||||
@Path("/")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public class AppIntegrationsController {
|
||||
|
||||
private final AppIntegrationsService appIntegrationsService;
|
||||
private final RegionResolver regionResolver;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Inject
|
||||
public AppIntegrationsController(AppIntegrationsService appIntegrationsService,
|
||||
RegionResolver regionResolver, ObjectMapper objectMapper) {
|
||||
this.appIntegrationsService = appIntegrationsService;
|
||||
this.regionResolver = regionResolver;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/eventIntegrations")
|
||||
public Response createEventIntegration(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
JsonNode request = readTree(body);
|
||||
EventIntegration integration = appIntegrationsService.createEventIntegration(
|
||||
textOrNull(request, "Name"),
|
||||
textOrNull(request, "Description"),
|
||||
request.get("EventFilter"),
|
||||
textOrNull(request, "EventBridgeBus"),
|
||||
parseTags(request.get("Tags")),
|
||||
region);
|
||||
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("EventIntegrationArn", integration.getEventIntegrationArn());
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/eventIntegrations/{name}")
|
||||
public Response getEventIntegration(@PathParam("name") String name, @Context HttpHeaders headers) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
EventIntegration integration = appIntegrationsService.getEventIntegration(name, region);
|
||||
return Response.ok(eventIntegrationNode(integration)).build();
|
||||
}
|
||||
|
||||
@PATCH
|
||||
@Path("/eventIntegrations/{name}")
|
||||
public Response updateEventIntegration(@PathParam("name") String name,
|
||||
@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
JsonNode request = readTree(body);
|
||||
appIntegrationsService.updateEventIntegration(name, optionalText(request, "Description"), region);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/eventIntegrations/{name}")
|
||||
public Response deleteEventIntegration(@PathParam("name") String name, @Context HttpHeaders headers) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
appIntegrationsService.deleteEventIntegration(name, region);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/eventIntegrations")
|
||||
public Response listEventIntegrations(@Context HttpHeaders headers) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode integrations = response.putArray("EventIntegrations");
|
||||
for (EventIntegration integration : appIntegrationsService.listEventIntegrations(region)) {
|
||||
integrations.add(eventIntegrationNode(integration));
|
||||
}
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Associations are created by the consuming service (Amazon Connect and friends)
|
||||
* when it binds a client to the integration. Floci has no path that creates one, so
|
||||
* an existing integration always reports an empty list; a missing one still raises
|
||||
* ResourceNotFoundException.
|
||||
*/
|
||||
@GET
|
||||
@Path("/eventIntegrations/{name}/associations")
|
||||
public Response listEventIntegrationAssociations(@PathParam("name") String name,
|
||||
@Context HttpHeaders headers) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
appIntegrationsService.getEventIntegration(name, region);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.putArray("EventIntegrationAssociations");
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/dataIntegrations")
|
||||
public Response createDataIntegration(@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
JsonNode request = readTree(body);
|
||||
DataIntegration integration = appIntegrationsService.createDataIntegration(
|
||||
textOrNull(request, "Name"),
|
||||
textOrNull(request, "Description"),
|
||||
textOrNull(request, "KmsKey"),
|
||||
textOrNull(request, "SourceURI"),
|
||||
request.get("ScheduleConfig"),
|
||||
request.get("FileConfiguration"),
|
||||
request.get("ObjectConfiguration"),
|
||||
parseTags(request.get("Tags")),
|
||||
region);
|
||||
|
||||
ObjectNode response = dataIntegrationNode(integration);
|
||||
String clientToken = textOrNull(request, "ClientToken");
|
||||
if (clientToken != null) {
|
||||
response.put("ClientToken", clientToken);
|
||||
}
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/dataIntegrations/{identifier}")
|
||||
public Response getDataIntegration(@PathParam("identifier") String identifier,
|
||||
@Context HttpHeaders headers) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
DataIntegration integration = appIntegrationsService.getDataIntegration(identifier, region);
|
||||
return Response.ok(dataIntegrationNode(integration)).build();
|
||||
}
|
||||
|
||||
@PATCH
|
||||
@Path("/dataIntegrations/{identifier}")
|
||||
public Response updateDataIntegration(@PathParam("identifier") String identifier,
|
||||
@Context HttpHeaders headers, String body) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
JsonNode request = readTree(body);
|
||||
appIntegrationsService.updateDataIntegration(identifier, optionalText(request, "Name"),
|
||||
optionalText(request, "Description"), region);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("/dataIntegrations/{identifier}")
|
||||
public Response deleteDataIntegration(@PathParam("identifier") String identifier,
|
||||
@Context HttpHeaders headers) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
appIntegrationsService.deleteDataIntegration(identifier, region);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/dataIntegrations")
|
||||
public Response listDataIntegrations(@Context HttpHeaders headers) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode integrations = response.putArray("DataIntegrations");
|
||||
for (DataIntegration integration : appIntegrationsService.listDataIntegrations(region)) {
|
||||
ObjectNode summary = integrations.addObject();
|
||||
summary.put("Arn", integration.getArn());
|
||||
summary.put("Name", integration.getName());
|
||||
if (integration.getSourceUri() != null) {
|
||||
summary.put("SourceURI", integration.getSourceUri());
|
||||
}
|
||||
}
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private ObjectNode eventIntegrationNode(EventIntegration integration) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("Name", integration.getName());
|
||||
if (integration.getDescription() != null) {
|
||||
node.put("Description", integration.getDescription());
|
||||
}
|
||||
node.put("EventIntegrationArn", integration.getEventIntegrationArn());
|
||||
node.put("EventBridgeBus", integration.getEventBridgeBus());
|
||||
node.putObject("EventFilter").put("Source", integration.getEventFilterSource());
|
||||
node.set("Tags", objectMapper.valueToTree(
|
||||
integration.getTags() != null ? integration.getTags() : Map.of()));
|
||||
return node;
|
||||
}
|
||||
|
||||
private ObjectNode dataIntegrationNode(DataIntegration integration) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("Arn", integration.getArn());
|
||||
node.put("Id", integration.getId());
|
||||
node.put("Name", integration.getName());
|
||||
if (integration.getDescription() != null) {
|
||||
node.put("Description", integration.getDescription());
|
||||
}
|
||||
node.put("KmsKey", integration.getKmsKey());
|
||||
if (integration.getSourceUri() != null) {
|
||||
node.put("SourceURI", integration.getSourceUri());
|
||||
}
|
||||
setIfPresent(node, "ScheduleConfiguration", integration.getScheduleConfiguration());
|
||||
setIfPresent(node, "FileConfiguration", integration.getFileConfiguration());
|
||||
setIfPresent(node, "ObjectConfiguration", integration.getObjectConfiguration());
|
||||
node.set("Tags", objectMapper.valueToTree(
|
||||
integration.getTags() != null ? integration.getTags() : Map.of()));
|
||||
return node;
|
||||
}
|
||||
|
||||
private void setIfPresent(ObjectNode node, String field, JsonNode value) {
|
||||
if (value != null && !value.isNull()) {
|
||||
node.set(field, value);
|
||||
}
|
||||
}
|
||||
|
||||
private JsonNode readTree(String body) {
|
||||
try {
|
||||
return objectMapper.readTree(body == null || body.isBlank() ? "{}" : body);
|
||||
} catch (Exception e) {
|
||||
throw new WebApplicationException(JsonErrorResponseUtils.createSerializationErrorResponse());
|
||||
}
|
||||
}
|
||||
|
||||
private String textOrNull(JsonNode node, String field) {
|
||||
return optionalText(node, field).orElse(null);
|
||||
}
|
||||
|
||||
private Optional<String> optionalText(JsonNode node, String field) {
|
||||
JsonNode value = node.get(field);
|
||||
if (value == null || value.isNull()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(value.asText());
|
||||
}
|
||||
|
||||
private Map<String, String> parseTags(JsonNode tagsNode) {
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
if (tagsNode != null && tagsNode.isObject()) {
|
||||
tagsNode.fields().forEachRemaining(e -> tags.put(e.getKey(), e.getValue().asText()));
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
}
|
||||
+282
@@ -0,0 +1,282 @@
|
||||
package io.github.hectorvent.floci.services.appintegrations;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.TagHandler;
|
||||
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 jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Amazon AppIntegrations (signing name {@code app-integrations}, API version 2020-07-29).
|
||||
* Event integrations are addressed by name, data integrations by generated id; both accept
|
||||
* their own ARN wherever the API takes an identifier.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class AppIntegrationsService implements TagHandler {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(AppIntegrationsService.class);
|
||||
|
||||
static final String SERVICE = "app-integrations";
|
||||
private static final String EVENT_INTEGRATION_RESOURCE = "event-integration";
|
||||
private static final String DATA_INTEGRATION_RESOURCE = "data-integration";
|
||||
|
||||
private final StorageBackend<String, EventIntegration> eventIntegrations;
|
||||
private final StorageBackend<String, DataIntegration> dataIntegrations;
|
||||
private final RegionResolver regionResolver;
|
||||
|
||||
@Inject
|
||||
public AppIntegrationsService(StorageFactory storageFactory, RegionResolver regionResolver) {
|
||||
this.eventIntegrations = storageFactory.create("appintegrations",
|
||||
"appintegrations-event-integrations.json",
|
||||
new TypeReference<Map<String, EventIntegration>>() {});
|
||||
this.dataIntegrations = storageFactory.create("appintegrations",
|
||||
"appintegrations-data-integrations.json",
|
||||
new TypeReference<Map<String, DataIntegration>>() {});
|
||||
this.regionResolver = regionResolver;
|
||||
}
|
||||
|
||||
public EventIntegration createEventIntegration(String name, String description, JsonNode eventFilter,
|
||||
String eventBridgeBus, Map<String, String> tags,
|
||||
String region) {
|
||||
requireMember(name, "Name");
|
||||
requireMember(eventBridgeBus, "EventBridgeBus");
|
||||
if (eventFilter == null || !eventFilter.isObject()
|
||||
|| eventFilter.get("Source") == null || eventFilter.get("Source").isNull()) {
|
||||
throw new AwsException("InvalidRequestException", "EventFilter.Source is required", 400);
|
||||
}
|
||||
if (eventIntegrations.get(key(region, name)).isPresent()) {
|
||||
throw new AwsException("DuplicateResourceException",
|
||||
"An event integration named " + name + " already exists.", 409);
|
||||
}
|
||||
|
||||
EventIntegration integration = new EventIntegration();
|
||||
integration.setName(name);
|
||||
integration.setDescription(description);
|
||||
integration.setEventIntegrationArn(
|
||||
regionResolver.buildArn(SERVICE, region, EVENT_INTEGRATION_RESOURCE + "/" + name));
|
||||
integration.setEventBridgeBus(eventBridgeBus);
|
||||
integration.setEventFilterSource(eventFilter.get("Source").asText());
|
||||
integration.setTags(tags != null ? new LinkedHashMap<>(tags) : new LinkedHashMap<>());
|
||||
integration.setAccountId(regionResolver.getAccountId());
|
||||
|
||||
eventIntegrations.put(key(region, name), integration);
|
||||
LOG.infov("Created AppIntegrations event integration: {0}", name);
|
||||
return integration;
|
||||
}
|
||||
|
||||
public EventIntegration getEventIntegration(String name, String region) {
|
||||
String resolved = resolveIdentifier(name, EVENT_INTEGRATION_RESOURCE);
|
||||
return eventIntegrations.get(key(region, resolved))
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Event integration " + name + " does not exist.", 404));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code Description} is the only updatable member. An absent member leaves the stored
|
||||
* value alone, which is how AWS treats an optional member the caller did not send.
|
||||
*/
|
||||
public EventIntegration updateEventIntegration(String name, Optional<String> description, String region) {
|
||||
EventIntegration integration = getEventIntegration(name, region);
|
||||
description.ifPresent(integration::setDescription);
|
||||
eventIntegrations.put(key(region, integration.getName()), integration);
|
||||
return integration;
|
||||
}
|
||||
|
||||
public void deleteEventIntegration(String name, String region) {
|
||||
EventIntegration integration = getEventIntegration(name, region);
|
||||
eventIntegrations.delete(key(region, integration.getName()));
|
||||
LOG.infov("Deleted AppIntegrations event integration: {0}", integration.getName());
|
||||
}
|
||||
|
||||
public List<EventIntegration> listEventIntegrations(String region) {
|
||||
String prefix = region + "::";
|
||||
return eventIntegrations.scan(k -> k.startsWith(prefix));
|
||||
}
|
||||
|
||||
public DataIntegration createDataIntegration(String name, String description, String kmsKey,
|
||||
String sourceUri, JsonNode scheduleConfig,
|
||||
JsonNode fileConfiguration, JsonNode objectConfiguration,
|
||||
Map<String, String> tags, String region) {
|
||||
requireMember(name, "Name");
|
||||
requireMember(kmsKey, "KmsKey");
|
||||
for (DataIntegration existing : listDataIntegrations(region)) {
|
||||
if (name.equals(existing.getName())) {
|
||||
throw new AwsException("DuplicateResourceException",
|
||||
"A data integration named " + name + " already exists.", 409);
|
||||
}
|
||||
}
|
||||
|
||||
String id = UUID.randomUUID().toString();
|
||||
DataIntegration integration = new DataIntegration();
|
||||
integration.setId(id);
|
||||
integration.setArn(regionResolver.buildArn(SERVICE, region, DATA_INTEGRATION_RESOURCE + "/" + id));
|
||||
integration.setName(name);
|
||||
integration.setDescription(description);
|
||||
integration.setKmsKey(kmsKey);
|
||||
integration.setSourceUri(sourceUri);
|
||||
integration.setScheduleConfiguration(scheduleConfig);
|
||||
integration.setFileConfiguration(fileConfiguration);
|
||||
integration.setObjectConfiguration(objectConfiguration);
|
||||
integration.setTags(tags != null ? new LinkedHashMap<>(tags) : new LinkedHashMap<>());
|
||||
integration.setAccountId(regionResolver.getAccountId());
|
||||
|
||||
dataIntegrations.put(key(region, id), integration);
|
||||
LOG.infov("Created AppIntegrations data integration: {0}", id);
|
||||
return integration;
|
||||
}
|
||||
|
||||
public DataIntegration getDataIntegration(String identifier, String region) {
|
||||
String id = resolveIdentifier(identifier, DATA_INTEGRATION_RESOURCE);
|
||||
return dataIntegrations.get(key(region, id))
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
|
||||
"Data integration " + identifier + " does not exist.", 404));
|
||||
}
|
||||
|
||||
public DataIntegration updateDataIntegration(String identifier, Optional<String> name,
|
||||
Optional<String> description, String region) {
|
||||
DataIntegration integration = getDataIntegration(identifier, region);
|
||||
name.ifPresent(integration::setName);
|
||||
description.ifPresent(integration::setDescription);
|
||||
dataIntegrations.put(key(region, integration.getId()), integration);
|
||||
return integration;
|
||||
}
|
||||
|
||||
public void deleteDataIntegration(String identifier, String region) {
|
||||
DataIntegration integration = getDataIntegration(identifier, region);
|
||||
dataIntegrations.delete(key(region, integration.getId()));
|
||||
LOG.infov("Deleted AppIntegrations data integration: {0}", integration.getId());
|
||||
}
|
||||
|
||||
public List<DataIntegration> listDataIntegrations(String region) {
|
||||
String prefix = region + "::";
|
||||
return dataIntegrations.scan(k -> k.startsWith(prefix));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serviceKey() {
|
||||
return SERVICE;
|
||||
}
|
||||
|
||||
/** AppIntegrations models no {@code responseCode} on either tag write, so both answer 200. */
|
||||
@Override
|
||||
public int tagResourceSuccessStatus() {
|
||||
return 200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int untagResourceSuccessStatus() {
|
||||
return 200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> listTags(String region, String arn) {
|
||||
Map<String, String> tags = tagsOf(findByArn(arn, region));
|
||||
return tags != null ? tags : Map.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tagResource(String region, String arn, Map<String, String> tags) {
|
||||
Object resource = findByArn(arn, region);
|
||||
if (tagsOf(resource) == null) {
|
||||
setTags(resource, new LinkedHashMap<>());
|
||||
}
|
||||
tagsOf(resource).putAll(tags);
|
||||
store(region, resource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void untagResource(String region, String arn, List<String> tagKeys) {
|
||||
Object resource = findByArn(arn, region);
|
||||
Map<String, String> tags = tagsOf(resource);
|
||||
if (tags != null && tagKeys != null) {
|
||||
tagKeys.forEach(tags::remove);
|
||||
}
|
||||
store(region, resource);
|
||||
}
|
||||
|
||||
private Object findByArn(String arn, String region) {
|
||||
String prefix = region + "::";
|
||||
for (EventIntegration event : eventIntegrations.scan(k -> k.startsWith(prefix))) {
|
||||
if (arn.equals(event.getEventIntegrationArn())) {
|
||||
return event;
|
||||
}
|
||||
}
|
||||
for (DataIntegration data : dataIntegrations.scan(k -> k.startsWith(prefix))) {
|
||||
if (arn.equals(data.getArn())) {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
throw new AwsException("ResourceNotFoundException", "Resource " + arn + " does not exist.", 404);
|
||||
}
|
||||
|
||||
private Map<String, String> tagsOf(Object resource) {
|
||||
return resource instanceof EventIntegration event ? event.getTags() : ((DataIntegration) resource).getTags();
|
||||
}
|
||||
|
||||
private void setTags(Object resource, Map<String, String> tags) {
|
||||
if (resource instanceof EventIntegration event) {
|
||||
event.setTags(tags);
|
||||
} else {
|
||||
((DataIntegration) resource).setTags(tags);
|
||||
}
|
||||
}
|
||||
|
||||
private void store(String region, Object resource) {
|
||||
if (resource instanceof EventIntegration event) {
|
||||
eventIntegrations.put(key(region, event.getName()), event);
|
||||
} else {
|
||||
DataIntegration data = (DataIntegration) resource;
|
||||
dataIntegrations.put(key(region, data.getId()), data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Both the bare identifier and the resource's own ARN are accepted, as AWS does.
|
||||
* An ARN naming a different AppIntegrations resource type is rejected rather than
|
||||
* silently resolving against the wrong store.
|
||||
*/
|
||||
private String resolveIdentifier(String identifier, String expectedResourceType) {
|
||||
if (identifier == null || identifier.isBlank()) {
|
||||
throw new AwsException("InvalidRequestException", "Identifier is required", 400);
|
||||
}
|
||||
if (!identifier.startsWith("arn:")) {
|
||||
return identifier;
|
||||
}
|
||||
String resource;
|
||||
try {
|
||||
resource = AwsArnUtils.parse(identifier).resource();
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new AwsException("InvalidRequestException", "Invalid ARN: " + identifier, 400);
|
||||
}
|
||||
int slash = resource.indexOf('/');
|
||||
if (slash < 0 || slash == resource.length() - 1
|
||||
|| !expectedResourceType.equals(resource.substring(0, slash))) {
|
||||
throw new AwsException("InvalidRequestException", "Invalid ARN: " + identifier, 400);
|
||||
}
|
||||
return resource.substring(slash + 1);
|
||||
}
|
||||
|
||||
private void requireMember(String value, String member) {
|
||||
if (value == null || value.isBlank()) {
|
||||
throw new AwsException("InvalidRequestException", member + " is required", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private String key(String region, String identifier) {
|
||||
return region + "::" + identifier;
|
||||
}
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
package io.github.hectorvent.floci.services.appintegrations.model;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
public class DataIntegration {
|
||||
|
||||
private String id;
|
||||
private String arn;
|
||||
private String name;
|
||||
private String description;
|
||||
private String kmsKey;
|
||||
private String sourceUri;
|
||||
private JsonNode scheduleConfiguration;
|
||||
private JsonNode fileConfiguration;
|
||||
private JsonNode objectConfiguration;
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
private String accountId;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getArn() {
|
||||
return arn;
|
||||
}
|
||||
|
||||
public void setArn(String arn) {
|
||||
this.arn = arn;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getKmsKey() {
|
||||
return kmsKey;
|
||||
}
|
||||
|
||||
public void setKmsKey(String kmsKey) {
|
||||
this.kmsKey = kmsKey;
|
||||
}
|
||||
|
||||
public String getSourceUri() {
|
||||
return sourceUri;
|
||||
}
|
||||
|
||||
public void setSourceUri(String sourceUri) {
|
||||
this.sourceUri = sourceUri;
|
||||
}
|
||||
|
||||
public JsonNode getScheduleConfiguration() {
|
||||
return scheduleConfiguration;
|
||||
}
|
||||
|
||||
public void setScheduleConfiguration(JsonNode scheduleConfiguration) {
|
||||
this.scheduleConfiguration = scheduleConfiguration;
|
||||
}
|
||||
|
||||
public JsonNode getFileConfiguration() {
|
||||
return fileConfiguration;
|
||||
}
|
||||
|
||||
public void setFileConfiguration(JsonNode fileConfiguration) {
|
||||
this.fileConfiguration = fileConfiguration;
|
||||
}
|
||||
|
||||
public JsonNode getObjectConfiguration() {
|
||||
return objectConfiguration;
|
||||
}
|
||||
|
||||
public void setObjectConfiguration(JsonNode objectConfiguration) {
|
||||
this.objectConfiguration = objectConfiguration;
|
||||
}
|
||||
|
||||
public Map<String, String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(Map<String, String> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public String getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(String accountId) {
|
||||
this.accountId = accountId;
|
||||
}
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package io.github.hectorvent.floci.services.appintegrations.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
public class EventIntegration {
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
private String eventIntegrationArn;
|
||||
private String eventBridgeBus;
|
||||
private String eventFilterSource;
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
private String accountId;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getEventIntegrationArn() {
|
||||
return eventIntegrationArn;
|
||||
}
|
||||
|
||||
public void setEventIntegrationArn(String eventIntegrationArn) {
|
||||
this.eventIntegrationArn = eventIntegrationArn;
|
||||
}
|
||||
|
||||
public String getEventBridgeBus() {
|
||||
return eventBridgeBus;
|
||||
}
|
||||
|
||||
public void setEventBridgeBus(String eventBridgeBus) {
|
||||
this.eventBridgeBus = eventBridgeBus;
|
||||
}
|
||||
|
||||
public String getEventFilterSource() {
|
||||
return eventFilterSource;
|
||||
}
|
||||
|
||||
public void setEventFilterSource(String eventFilterSource) {
|
||||
this.eventFilterSource = eventFilterSource;
|
||||
}
|
||||
|
||||
public Map<String, String> getTags() {
|
||||
return tags;
|
||||
}
|
||||
|
||||
public void setTags(Map<String, String> tags) {
|
||||
this.tags = tags;
|
||||
}
|
||||
|
||||
public String getAccountId() {
|
||||
return accountId;
|
||||
}
|
||||
|
||||
public void setAccountId(String accountId) {
|
||||
this.accountId = accountId;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user