Light, fluffy, and always free - The AWS Local Emulator alternative
feat(connect): instance management (CreateInstance family, attributes, storage configs, tags) (#2740)
lex007b6266e902a9
diff --git a/docs/services/connect.md b/docs/services/connect.mdnew file mode 100644index 0000000000..ac28642940--- /dev/null+++ b/docs/services/connect.md@@ -0,0 +1,87 @@+# Amazon Connect++**Protocol:** REST-JSON+**Endpoint:** `http://localhost:4566/instance` (SigV4 service `connect`)++## Supported Actions++<!-- floci:actions:start -->+| Action | Description |+| --- | --- |+| `CreateInstance` | Create an instance; returns `Id` and `Arn`, ACTIVE immediately |+| `DescribeInstance` | Get the full instance including tags |+| `DeleteInstance` | Delete an instance and its storage config associations |+| `ListInstances` | List instance summaries |+| `UpdateInstanceAttribute` | Set one `InstanceAttributeType` |+| `DescribeInstanceAttribute` | Read one `InstanceAttributeType` |+| `ListInstanceAttributes` | List every attribute on an instance |+| `AssociateInstanceStorageConfig` | Attach a storage config for a resource type |+| `DescribeInstanceStorageConfig` | Read a storage config by association id |+| `UpdateInstanceStorageConfig` | Replace a storage config |+| `DisassociateInstanceStorageConfig` | Remove a storage config |+| `ListInstanceStorageConfigs` | List storage configs for one resource type |+| `ListTagsForResource` | List instance tags (`GET /tags/{resourceArn}`) |+| `TagResource` | Tag an instance (`POST /tags/{resourceArn}`) |+| `UntagResource` | Remove instance tags (`DELETE /tags/{resourceArn}?tagKeys=`) |+<!-- floci:actions:end -->++`InstanceStatus` is `ACTIVE` from the first read, so `aws_connect_instance`'s status+poll completes without a transition. `CreateInstance` returns only `Id` and `Arn` —+the full `Instance` shape, tags included, comes back from `DescribeInstance`.+`InstanceSummary` has no `Tags` member in the AWS model, so `ListInstances` omits it.++Every `InstanceAttributeType` in the AWS model is seeded when an instance is created:+`INBOUND_CALLS` and `OUTBOUND_CALLS` take their values from the create request, the+rest default to `false`. This keeps `DescribeInstanceAttribute` from returning a+404 for a valid attribute type, which `aws_connect_instance` reads on every refresh.++Storage configs are keyed by instance, resource type and association id, so the same+instance can hold separate configurations for `CHAT_TRANSCRIPTS`, `CALL_RECORDINGS`+and the rest. `ResourceType` is required on every read and write, as AWS requires it.++Both a bare instance id and a full instance ARN are accepted wherever the API takes+an `InstanceId`.++## Not implemented++These return a clean `UnknownOperationException` rather than a stub success. The+telephony and contact surfaces of Connect depend on real voice, chat and agent+traffic, which the emulator has no way to model:++- Phone numbers (`ClaimPhoneNumber`, `SearchAvailablePhoneNumbers`, ...) — these+ allocate real numbers from carrier inventory.+- Contacts (`StartOutboundVoiceContact`, `StopContact`, `GetContactAttributes`, ...)+ — these require a live contact.+- Agent status, user hierarchy and routing profiles bound to live agents.+- Real-time and historical metrics (`GetCurrentMetricData`, `GetMetricDataV2`, ...) —+ these aggregate real traffic.+- Queues, hours of operation, contact flows and quick connects — not yet modelled.++## Configuration++| Variable | Default | Description |+|---|---|---|+| `FLOCI_SERVICES_CONNECT_ENABLED` | `true` | Enable or disable the service |++## Examples++```bash+export AWS_ENDPOINT_URL=http://localhost:4566++aws connect create-instance \+ --identity-management-type CONNECT_MANAGED \+ --instance-alias my-contact-center \+ --no-inbound-calls-enabled \+ --outbound-calls-enabled++aws connect describe-instance --instance-id <id>++aws connect update-instance-attribute \+ --instance-id <id> --attribute-type CONTACTFLOW_LOGS --value true++aws connect associate-instance-storage-config \+ --instance-id <id> --resource-type CHAT_TRANSCRIPTS \+ --storage-config '{"StorageType":"S3","S3Config":{"BucketName":"b","BucketPrefix":"chat/"}}'++aws connect delete-instance --instance-id <id>+```diff --git a/docs/services/index.md b/docs/services/index.mdindex e78807c20e..9ae88ab7b8 100644--- a/docs/services/index.md+++ b/docs/services/index.md@@ -43,6 +43,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac| [CloudWatch Metrics](cloudwatch.md#metrics) | `POST /` with `Action=` or JSON 1.1 | Query / JSON | 11 || [CloudWatch RUM](rum.md) | `/appmonitor`, `/appmonitor/{name}`, `/appmonitors` | REST JSON | 5 || [GuardDuty](guardduty.md) | `/detector`, `/detector/{detectorId}`, `/detector/{detectorId}/admin`, `/admin/*`, `/tags/*` | REST JSON | 13 |+| [Amazon Connect](connect.md) | `/instance`, `/instance/{instanceId}/*`, `/tags/*` | REST JSON | 15 || [ElastiCache](elasticache.md) | `POST /` with `Action=` param + TCP proxy | Query + RESP | 8 || [MemoryDB](memorydb.md) | `POST /` + `X-Amz-Target: AmazonMemoryDB.*` + TCP proxy | JSON 1.1 + RESP | 7 || [RDS](rds.md) | `POST /` with `Action=` param + TCP proxy | Query + wire | 14 |diff --git a/mkdocs.yml b/mkdocs.ymlindex 594261d641..a7e0f6617f 100644--- a/mkdocs.yml+++ b/mkdocs.yml@@ -116,6 +116,7 @@ nav:- CloudWatch: services/cloudwatch.md- CloudWatch RUM: services/rum.md- GuardDuty: services/guardduty.md+ - Connect: services/connect.md- ACM: services/acm.md- ECS: services/ecs.md- ECR: services/ecr.mddiff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.javaindex 302a4d49de..475cd414bf 100644--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java@@ -696,6 +696,7 @@ public interface EmulatorConfig {ServiceQuotasServiceConfig servicequotas();RamServiceConfig ram();ControlTowerServiceConfig controltower();+ ConnectServiceConfig connect();ApsServiceConfig aps();@@ -703,6 +704,11 @@ public interface EmulatorConfig {EfsServiceConfig efs();}+ interface ConnectServiceConfig {+ @WithDefault("true")+ boolean enabled();+ }+interface SsoAdminServiceConfig {@WithDefault("true")boolean enabled();diff --git a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.javaindex 707d6cb6c3..811fe02512 100644--- a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java+++ b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java@@ -537,6 +537,11 @@ public class ResolvedServiceCatalog {"route53resolver", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,protocols(ServiceProtocol.JSON),Set.of("Route53Resolver."), Set.of("route53resolver"), Set.of(), Set.of()),+ descriptor("connect", "connect", config.services().connect().enabled(), true,+ "connect", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,+ protocols(ServiceProtocol.REST_JSON),+ Set.of(), Set.of("connect"), Set.of(),+ Set.of(io.github.hectorvent.floci.services.connect.ConnectController.class)),descriptor("network-firewall", "networkfirewall", config.services().networkfirewall().enabled(), true,"networkfirewall", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,protocols(ServiceProtocol.JSON),diff --git a/src/main/java/io/github/hectorvent/floci/services/connect/ConnectController.java b/src/main/java/io/github/hectorvent/floci/services/connect/ConnectController.javanew file mode 100644index 0000000000..b41a31b36a--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/connect/ConnectController.java@@ -0,0 +1,293 @@+package io.github.hectorvent.floci.services.connect;++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.connect.model.ConnectInstance;+import io.github.hectorvent.floci.services.connect.model.ConnectStorageConfig;+import jakarta.inject.Inject;+import jakarta.ws.rs.Consumes;+import jakarta.ws.rs.DELETE;+import jakarta.ws.rs.GET;+import jakarta.ws.rs.POST;+import jakarta.ws.rs.PUT;+import jakarta.ws.rs.Path;+import jakarta.ws.rs.PathParam;+import jakarta.ws.rs.Produces;+import jakarta.ws.rs.QueryParam;+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;++/**+ * Amazon Connect instance control plane REST-JSON controller.+ *+ * <p>Tag operations live on the shared {@code /tags/{resourceArn}} path and are served by+ * {@code SharedTagsController} through {@link ConnectService}'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("/instance")+@Produces(MediaType.APPLICATION_JSON)+@Consumes(MediaType.APPLICATION_JSON)+public class ConnectController {++ private final ConnectService connectService;+ private final RegionResolver regionResolver;+ private final ObjectMapper objectMapper;++ @Inject+ public ConnectController(ConnectService connectService, RegionResolver regionResolver,+ ObjectMapper objectMapper) {+ this.connectService = connectService;+ this.regionResolver = regionResolver;+ this.objectMapper = objectMapper;+ }++ // ──────────────────────────── Instances ────────────────────────────++ @PUT+ public Response createInstance(@Context HttpHeaders headers, String body) {+ String region = regionResolver.resolveRegion(headers);+ JsonNode request = readTree(body);+ ConnectInstance instance = connectService.createInstance(+ textOrNull(request, "IdentityManagementType"),+ textOrNull(request, "InstanceAlias"),+ textOrNull(request, "DirectoryId"),+ booleanOrNull(request, "InboundCallsEnabled"),+ booleanOrNull(request, "OutboundCallsEnabled"),+ parseTags(request.get("Tags")),+ region);++ ObjectNode response = objectMapper.createObjectNode();+ response.put("Id", instance.getId());+ response.put("Arn", instance.getArn());+ return Response.ok(response).build();+ }++ @GET+ @Path("/{instanceId}")+ public Response describeInstance(@PathParam("instanceId") String instanceId,+ @Context HttpHeaders headers) {+ String region = regionResolver.resolveRegion(headers);+ ConnectInstance instance = connectService.describeInstance(instanceId, region);+ ObjectNode response = objectMapper.createObjectNode();+ response.set("Instance", instanceNode(instance, true));+ return Response.ok(response).build();+ }++ @DELETE+ @Path("/{instanceId}")+ public Response deleteInstance(@PathParam("instanceId") String instanceId,+ @Context HttpHeaders headers) {+ String region = regionResolver.resolveRegion(headers);+ connectService.deleteInstance(instanceId, region);+ return Response.ok().build();+ }++ @GET+ public Response listInstances(@Context HttpHeaders headers) {+ String region = regionResolver.resolveRegion(headers);+ ObjectNode response = objectMapper.createObjectNode();+ ArrayNode summaries = response.putArray("InstanceSummaryList");+ for (ConnectInstance instance : connectService.listInstances(region)) {+ summaries.add(instanceNode(instance, false));+ }+ return Response.ok(response).build();+ }++ // ──────────────────────────── Attributes ────────────────────────────++ @POST+ @Path("/{instanceId}/attribute/{attributeType}")+ public Response updateInstanceAttribute(@PathParam("instanceId") String instanceId,+ @PathParam("attributeType") String attributeType,+ @Context HttpHeaders headers, String body) {+ String region = regionResolver.resolveRegion(headers);+ JsonNode request = readTree(body);+ connectService.updateInstanceAttribute(instanceId, attributeType,+ textOrNull(request, "Value"), region);+ return Response.ok(objectMapper.createObjectNode()).build();+ }++ @GET+ @Path("/{instanceId}/attribute/{attributeType}")+ public Response describeInstanceAttribute(@PathParam("instanceId") String instanceId,+ @PathParam("attributeType") String attributeType,+ @Context HttpHeaders headers) {+ String region = regionResolver.resolveRegion(headers);+ String value = connectService.describeInstanceAttribute(instanceId, attributeType, region);+ ObjectNode response = objectMapper.createObjectNode();+ response.set("Attribute", attributeNode(attributeType, value));+ return Response.ok(response).build();+ }++ @GET+ @Path("/{instanceId}/attributes")+ public Response listInstanceAttributes(@PathParam("instanceId") String instanceId,+ @Context HttpHeaders headers) {+ String region = regionResolver.resolveRegion(headers);+ ObjectNode response = objectMapper.createObjectNode();+ ArrayNode attributes = response.putArray("Attributes");+ connectService.listInstanceAttributes(instanceId, region)+ .forEach((type, value) -> attributes.add(attributeNode(type, value)));+ return Response.ok(response).build();+ }++ // ──────────────────────── Instance storage configs ────────────────────────++ @PUT+ @Path("/{instanceId}/storage-config")+ public Response associateInstanceStorageConfig(@PathParam("instanceId") String instanceId,+ @Context HttpHeaders headers, String body) {+ String region = regionResolver.resolveRegion(headers);+ JsonNode request = readTree(body);+ ConnectStorageConfig config = connectService.associateInstanceStorageConfig(instanceId,+ textOrNull(request, "ResourceType"), request.get("StorageConfig"), region);++ ObjectNode response = objectMapper.createObjectNode();+ response.put("AssociationId", config.getAssociationId());+ return Response.ok(response).build();+ }++ @GET+ @Path("/{instanceId}/storage-config/{associationId}")+ public Response describeInstanceStorageConfig(@PathParam("instanceId") String instanceId,+ @PathParam("associationId") String associationId,+ @QueryParam("resourceType") String resourceType,+ @Context HttpHeaders headers) {+ String region = regionResolver.resolveRegion(headers);+ ConnectStorageConfig config = connectService.describeInstanceStorageConfig(instanceId,+ associationId, resourceType, region);+ ObjectNode response = objectMapper.createObjectNode();+ response.set("StorageConfig", storageConfigNode(config));+ return Response.ok(response).build();+ }++ @POST+ @Path("/{instanceId}/storage-config/{associationId}")+ public Response updateInstanceStorageConfig(@PathParam("instanceId") String instanceId,+ @PathParam("associationId") String associationId,+ @QueryParam("resourceType") String resourceType,+ @Context HttpHeaders headers, String body) {+ String region = regionResolver.resolveRegion(headers);+ JsonNode request = readTree(body);+ connectService.updateInstanceStorageConfig(instanceId, associationId, resourceType,+ request.get("StorageConfig"), region);+ return Response.ok(objectMapper.createObjectNode()).build();+ }++ @DELETE+ @Path("/{instanceId}/storage-config/{associationId}")+ public Response disassociateInstanceStorageConfig(@PathParam("instanceId") String instanceId,+ @PathParam("associationId") String associationId,+ @QueryParam("resourceType") String resourceType,+ @Context HttpHeaders headers) {+ String region = regionResolver.resolveRegion(headers);+ connectService.disassociateInstanceStorageConfig(instanceId, associationId, resourceType, region);+ return Response.ok().build();+ }++ @GET+ @Path("/{instanceId}/storage-configs")+ public Response listInstanceStorageConfigs(@PathParam("instanceId") String instanceId,+ @QueryParam("resourceType") String resourceType,+ @Context HttpHeaders headers) {+ String region = regionResolver.resolveRegion(headers);+ ObjectNode response = objectMapper.createObjectNode();+ ArrayNode configs = response.putArray("StorageConfigs");+ for (ConnectStorageConfig config+ : connectService.listInstanceStorageConfigs(instanceId, resourceType, region)) {+ configs.add(storageConfigNode(config));+ }+ return Response.ok(response).build();+ }++ // ──────────────────────────── Helpers ────────────────────────────++ /**+ * {@code Instance} carries {@code Tags}; {@code InstanceSummary} does not — see the+ * AWS model. Everything else is shared between the two shapes.+ */+ private ObjectNode instanceNode(ConnectInstance instance, boolean includeTags) {+ ObjectNode node = objectMapper.createObjectNode();+ node.put("Id", instance.getId());+ node.put("Arn", instance.getArn());+ node.put("IdentityManagementType", instance.getIdentityManagementType());+ if (instance.getInstanceAlias() != null) {+ node.put("InstanceAlias", instance.getInstanceAlias());+ }+ node.put("CreatedTime", instance.getCreatedTime().getEpochSecond());+ node.put("ServiceRole", instance.getServiceRole());+ node.put("InstanceStatus", ConnectService.ACTIVE);+ node.put("InboundCallsEnabled", instance.isInboundCallsEnabled());+ node.put("OutboundCallsEnabled", instance.isOutboundCallsEnabled());+ if (instance.getInstanceAccessUrl() != null) {+ node.put("InstanceAccessUrl", instance.getInstanceAccessUrl());+ }+ if (includeTags) {+ node.set("Tags", objectMapper.valueToTree(+ instance.getTags() != null ? instance.getTags() : Map.of()));+ }+ return node;+ }++ private ObjectNode attributeNode(String attributeType, String value) {+ ObjectNode node = objectMapper.createObjectNode();+ node.put("AttributeType", attributeType);+ node.put("Value", value);+ return node;+ }++ private ObjectNode storageConfigNode(ConnectStorageConfig config) {+ ObjectNode node = objectMapper.createObjectNode();+ node.put("AssociationId", config.getAssociationId());+ node.put("StorageType", config.getStorageType());+ config.getStorageConfig().fields().forEachRemaining(entry -> {+ if (!"AssociationId".equals(entry.getKey()) && !"StorageType".equals(entry.getKey())) {+ node.set(entry.getKey(), entry.getValue());+ }+ });+ return node;+ }++ 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) {+ JsonNode value = node.get(field);+ if (value == null || value.isNull()) {+ return null;+ }+ return value.asText();+ }++ private Boolean booleanOrNull(JsonNode node, String field) {+ JsonNode value = node.get(field);+ if (value == null || value.isNull()) {+ return null;+ }+ return value.asBoolean();+ }++ 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;+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/connect/ConnectService.java b/src/main/java/io/github/hectorvent/floci/services/connect/ConnectService.javanew file mode 100644index 0000000000..1be4735a94--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/connect/ConnectService.java@@ -0,0 +1,389 @@+package io.github.hectorvent.floci.services.connect;++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.connect.model.ConnectInstance;+import io.github.hectorvent.floci.services.connect.model.ConnectStorageConfig;+import jakarta.enterprise.context.ApplicationScoped;+import jakarta.inject.Inject;+import org.jboss.logging.Logger;++import java.time.Instant;+import java.util.LinkedHashMap;+import java.util.List;+import java.util.Map;+import java.util.Set;+import java.util.UUID;++/**+ * Amazon Connect instance control plane (signing name {@code connect}). Instances+ * are ACTIVE the moment {@code CreateInstance} returns, so {@code aws_connect_instance}'s+ * status poll completes on its first read.+ */+@ApplicationScoped+public class ConnectService implements TagHandler {++ public static final String ACTIVE = "ACTIVE";++ private static final Logger LOG = Logger.getLogger(ConnectService.class);++ /** {@code InstanceAttributeType} from the AWS model. */+ private static final List<String> ATTRIBUTE_TYPES = List.of(+ "INBOUND_CALLS",+ "OUTBOUND_CALLS",+ "CONTACTFLOW_LOGS",+ "CONTACT_LENS",+ "AUTO_RESOLVE_BEST_VOICES",+ "USE_CUSTOM_TTS_VOICES",+ "EARLY_MEDIA",+ "MULTI_PARTY_CONFERENCE",+ "HIGH_VOLUME_OUTBOUND",+ "ENHANCED_CONTACT_MONITORING",+ "ENHANCED_CHAT_MONITORING",+ "MULTI_PARTY_CHAT_CONFERENCE",+ "MESSAGE_STREAMING");++ /** {@code DirectoryType} from the AWS model. */+ private static final Set<String> IDENTITY_MANAGEMENT_TYPES =+ Set.of("SAML", "CONNECT_MANAGED", "EXISTING_DIRECTORY");++ /** {@code InstanceStorageResourceType} from the AWS model. */+ private static final Set<String> STORAGE_RESOURCE_TYPES = Set.of(+ "CHAT_TRANSCRIPTS",+ "CALL_RECORDINGS",+ "SCHEDULED_REPORTS",+ "MEDIA_STREAMS",+ "CONTACT_TRACE_RECORDS",+ "AGENT_EVENTS",+ "REAL_TIME_CONTACT_ANALYSIS_SEGMENTS",+ "ATTACHMENTS",+ "CONTACT_EVALUATIONS",+ "SCREEN_RECORDINGS",+ "REAL_TIME_CONTACT_ANALYSIS_CHAT_SEGMENTS",+ "REAL_TIME_CONTACT_ANALYSIS_VOICE_SEGMENTS",+ "EMAIL_MESSAGES");++ /** {@code StorageType} from the AWS model, mapped to the member carrying its configuration. */+ private static final Map<String, String> STORAGE_TYPE_MEMBERS = Map.of(+ "S3", "S3Config",+ "KINESIS_VIDEO_STREAM", "KinesisVideoStreamConfig",+ "KINESIS_STREAM", "KinesisStreamConfig",+ "KINESIS_FIREHOSE", "KinesisFirehoseConfig");++ private final StorageBackend<String, ConnectInstance> instances;+ private final StorageBackend<String, ConnectStorageConfig> storageConfigs;+ private final RegionResolver regionResolver;++ @Inject+ public ConnectService(StorageFactory storageFactory, RegionResolver regionResolver) {+ this.instances = storageFactory.create("connect", "connect-instances.json",+ new TypeReference<Map<String, ConnectInstance>>() {});+ this.storageConfigs = storageFactory.create("connect", "connect-storage-configs.json",+ new TypeReference<Map<String, ConnectStorageConfig>>() {});+ this.regionResolver = regionResolver;+ }++ // ──────────────────────────── Instances ────────────────────────────++ public ConnectInstance createInstance(String identityManagementType, String instanceAlias,+ String directoryId, Boolean inboundCallsEnabled,+ Boolean outboundCallsEnabled, Map<String, String> tags,+ String region) {+ if (identityManagementType == null || identityManagementType.isBlank()) {+ throw new AwsException("InvalidRequestException", "IdentityManagementType is required", 400);+ }+ if (!IDENTITY_MANAGEMENT_TYPES.contains(identityManagementType)) {+ throw new AwsException("InvalidParameterException",+ "IdentityManagementType " + identityManagementType + " is not supported.", 400);+ }+ if (inboundCallsEnabled == null) {+ throw new AwsException("InvalidRequestException", "InboundCallsEnabled is required", 400);+ }+ if (outboundCallsEnabled == null) {+ throw new AwsException("InvalidRequestException", "OutboundCallsEnabled is required", 400);+ }+ if ("EXISTING_DIRECTORY".equals(identityManagementType)+ && (directoryId == null || directoryId.isBlank())) {+ throw new AwsException("InvalidRequestException",+ "DirectoryId is required when IdentityManagementType is EXISTING_DIRECTORY", 400);+ }+ if (instanceAlias != null) {+ for (ConnectInstance existing : listInstances(region)) {+ if (instanceAlias.equals(existing.getInstanceAlias())) {+ throw new AwsException("ResourceConflictException",+ "An instance with alias " + instanceAlias + " already exists.", 409);+ }+ }+ }++ String instanceId = UUID.randomUUID().toString();+ ConnectInstance instance = new ConnectInstance();+ instance.setId(instanceId);+ instance.setArn(regionResolver.buildArn("connect", region, "instance/" + instanceId));+ instance.setIdentityManagementType(identityManagementType);+ instance.setInstanceAlias(instanceAlias);+ instance.setDirectoryId(directoryId);+ instance.setCreatedTime(Instant.now());+ instance.setServiceRole("arn:aws:iam::" + regionResolver.getAccountId()+ + ":role/aws-service-role/connect.amazonaws.com/AWSServiceRoleForAmazonConnect_" + instanceId);+ instance.setInboundCallsEnabled(inboundCallsEnabled);+ instance.setOutboundCallsEnabled(outboundCallsEnabled);+ if (instanceAlias != null) {+ instance.setInstanceAccessUrl("https://" + instanceAlias + ".my.connect.aws/");+ }+ instance.setTags(tags != null ? new LinkedHashMap<>(tags) : new LinkedHashMap<>());+ instance.setAccountId(regionResolver.getAccountId());++ // Every attribute type is seeded so DescribeInstanceAttribute never 404s on a+ // valid enum value: aws_connect_instance reads them all on every refresh.+ Map<String, String> attributes = new LinkedHashMap<>();+ for (String attributeType : ATTRIBUTE_TYPES) {+ attributes.put(attributeType, "false");+ }+ attributes.put("INBOUND_CALLS", String.valueOf(inboundCallsEnabled));+ attributes.put("OUTBOUND_CALLS", String.valueOf(outboundCallsEnabled));+ instance.setAttributes(attributes);++ instances.put(key(region, instanceId), instance);+ LOG.infov("Created Connect instance: {0}", instanceId);+ return instance;+ }++ public ConnectInstance describeInstance(String instanceId, String region) {+ return instances.get(key(region, resolveInstanceId(instanceId)))+ .orElseThrow(() -> new AwsException("ResourceNotFoundException",+ "Instance " + instanceId + " does not exist.", 404));+ }++ public void deleteInstance(String instanceId, String region) {+ ConnectInstance instance = describeInstance(instanceId, region);+ String prefix = key(region, instance.getId()) + "::";+ for (ConnectStorageConfig config : storageConfigs.scan(k -> k.startsWith(prefix))) {+ storageConfigs.delete(storageKey(region, instance.getId(), config.getResourceType(),+ config.getAssociationId()));+ }+ instances.delete(key(region, instance.getId()));+ LOG.infov("Deleted Connect instance: {0}", instance.getId());+ }++ public List<ConnectInstance> listInstances(String region) {+ String prefix = region + "::";+ return instances.scan(k -> k.startsWith(prefix));+ }++ // ──────────────────────────── Attributes ────────────────────────────++ public ConnectInstance updateInstanceAttribute(String instanceId, String attributeType, String value,+ String region) {+ validateAttributeType(attributeType);+ if (value == null || value.isBlank()) {+ throw new AwsException("InvalidRequestException", "Value is required", 400);+ }+ // Instance attributes are boolean-valued; storing the canonical form keeps the+ // attributes map and the inbound/outbound flags from diverging on read.+ if (!"true".equalsIgnoreCase(value) && !"false".equalsIgnoreCase(value)) {+ throw new AwsException("InvalidParameterException",+ "Value must be 'true' or 'false' for attribute " + attributeType, 400);+ }+ String canonical = value.toLowerCase(java.util.Locale.ROOT);+ ConnectInstance instance = describeInstance(instanceId, region);+ instance.getAttributes().put(attributeType, canonical);+ if ("INBOUND_CALLS".equals(attributeType)) {+ instance.setInboundCallsEnabled(Boolean.parseBoolean(canonical));+ } else if ("OUTBOUND_CALLS".equals(attributeType)) {+ instance.setOutboundCallsEnabled(Boolean.parseBoolean(canonical));+ }+ instances.put(key(region, instance.getId()), instance);+ return instance;+ }++ public String describeInstanceAttribute(String instanceId, String attributeType, String region) {+ validateAttributeType(attributeType);+ ConnectInstance instance = describeInstance(instanceId, region);+ String value = instance.getAttributes().get(attributeType);+ if (value == null) {+ throw new AwsException("ResourceNotFoundException",+ "Attribute " + attributeType + " is not set on instance " + instanceId + ".", 404);+ }+ return value;+ }++ public Map<String, String> listInstanceAttributes(String instanceId, String region) {+ return describeInstance(instanceId, region).getAttributes();+ }++ // ──────────────────────── Instance storage configs ────────────────────────++ public ConnectStorageConfig associateInstanceStorageConfig(String instanceId, String resourceType,+ JsonNode storageConfig, String region) {+ validateResourceType(resourceType);+ String storageType = validateStorageConfig(storageConfig);+ ConnectInstance instance = describeInstance(instanceId, region);++ String associationId = UUID.randomUUID().toString();+ ConnectStorageConfig config = new ConnectStorageConfig();+ config.setAssociationId(associationId);+ config.setInstanceId(instance.getId());+ config.setResourceType(resourceType);+ config.setStorageType(storageType);+ config.setStorageConfig(storageConfig);++ storageConfigs.put(storageKey(region, instance.getId(), resourceType, associationId), config);+ LOG.infov("Associated Connect storage config {0} ({1}) on instance {2}",+ associationId, resourceType, instance.getId());+ return config;+ }++ public ConnectStorageConfig describeInstanceStorageConfig(String instanceId, String associationId,+ String resourceType, String region) {+ validateResourceType(resourceType);+ ConnectInstance instance = describeInstance(instanceId, region);+ return storageConfigs.get(storageKey(region, instance.getId(), resourceType, associationId))+ .orElseThrow(() -> new AwsException("ResourceNotFoundException",+ "Storage config " + associationId + " does not exist on instance "+ + instance.getId() + ".", 404));+ }++ public ConnectStorageConfig updateInstanceStorageConfig(String instanceId, String associationId,+ String resourceType, JsonNode storageConfig,+ String region) {+ String storageType = validateStorageConfig(storageConfig);+ ConnectStorageConfig config =+ describeInstanceStorageConfig(instanceId, associationId, resourceType, region);+ config.setStorageType(storageType);+ config.setStorageConfig(storageConfig);+ storageConfigs.put(storageKey(region, config.getInstanceId(), resourceType, associationId), config);+ return config;+ }++ public void disassociateInstanceStorageConfig(String instanceId, String associationId,+ String resourceType, String region) {+ ConnectStorageConfig config =+ describeInstanceStorageConfig(instanceId, associationId, resourceType, region);+ storageConfigs.delete(storageKey(region, config.getInstanceId(), resourceType, associationId));+ LOG.infov("Disassociated Connect storage config {0} from instance {1}",+ associationId, config.getInstanceId());+ }++ public List<ConnectStorageConfig> listInstanceStorageConfigs(String instanceId, String resourceType,+ String region) {+ validateResourceType(resourceType);+ ConnectInstance instance = describeInstance(instanceId, region);+ String prefix = key(region, instance.getId()) + "::" + resourceType + "::";+ return storageConfigs.scan(k -> k.startsWith(prefix));+ }++ // ──────────────────────────── Tags ────────────────────────────++ @Override+ public String serviceKey() {+ return "connect";+ }++ @Override+ public Map<String, String> listTags(String region, String arn) {+ ConnectInstance instance = findByArn(arn, region);+ return instance.getTags() != null ? instance.getTags() : Map.of();+ }++ @Override+ public void tagResource(String region, String arn, Map<String, String> tags) {+ ConnectInstance instance = findByArn(arn, region);+ if (instance.getTags() == null) {+ instance.setTags(new LinkedHashMap<>());+ }+ instance.getTags().putAll(tags);+ instances.put(key(region, instance.getId()), instance);+ }++ @Override+ public void untagResource(String region, String arn, List<String> tagKeys) {+ ConnectInstance instance = findByArn(arn, region);+ if (instance.getTags() != null && tagKeys != null) {+ tagKeys.forEach(instance.getTags()::remove);+ }+ instances.put(key(region, instance.getId()), instance);+ }++ // ──────────────────────────── Helpers ────────────────────────────++ private ConnectInstance findByArn(String arn, String region) {+ String prefix = region + "::";+ for (ConnectInstance instance : instances.scan(k -> k.startsWith(prefix))) {+ if (arn.equals(instance.getArn())) {+ return instance;+ }+ }+ throw new AwsException("ResourceNotFoundException", "Resource " + arn + " does not exist.", 404);+ }++ /** Both a bare instance id and a full instance ARN are accepted, as AWS does. */+ private String resolveInstanceId(String instanceId) {+ if (instanceId == null || instanceId.isBlank()) {+ throw new AwsException("InvalidRequestException", "InstanceId is required", 400);+ }+ if (!instanceId.startsWith("arn:")) {+ return instanceId;+ }+ String resource;+ try {+ resource = AwsArnUtils.parse(instanceId).resource();+ } catch (IllegalArgumentException e) {+ throw new AwsException("InvalidParameterException", "Invalid instance ARN: " + instanceId, 400);+ }+ int slash = resource.indexOf('/');+ if (slash < 0 || slash == resource.length() - 1) {+ throw new AwsException("InvalidParameterException", "Invalid instance ARN: " + instanceId, 400);+ }+ return resource.substring(slash + 1);+ }++ private void validateAttributeType(String attributeType) {+ if (attributeType == null || !ATTRIBUTE_TYPES.contains(attributeType)) {+ throw new AwsException("InvalidParameterException",+ "AttributeType " + attributeType + " is not supported.", 400);+ }+ }++ private void validateResourceType(String resourceType) {+ if (resourceType == null || !STORAGE_RESOURCE_TYPES.contains(resourceType)) {+ throw new AwsException("InvalidParameterException",+ "ResourceType " + resourceType + " is not supported.", 400);+ }+ }++ private String validateStorageConfig(JsonNode storageConfig) {+ if (storageConfig == null || !storageConfig.isObject()) {+ throw new AwsException("InvalidRequestException", "StorageConfig is required", 400);+ }+ JsonNode storageTypeNode = storageConfig.get("StorageType");+ if (storageTypeNode == null || storageTypeNode.isNull()) {+ throw new AwsException("InvalidRequestException", "StorageConfig.StorageType is required", 400);+ }+ String storageType = storageTypeNode.asText();+ String member = STORAGE_TYPE_MEMBERS.get(storageType);+ if (member == null) {+ throw new AwsException("InvalidParameterException",+ "StorageType " + storageType + " is not supported.", 400);+ }+ if (storageConfig.get(member) == null || storageConfig.get(member).isNull()) {+ throw new AwsException("InvalidRequestException",+ "StorageConfig." + member + " is required when StorageType is " + storageType, 400);+ }+ return storageType;+ }++ private String key(String region, String instanceId) {+ return region + "::" + instanceId;+ }++ private String storageKey(String region, String instanceId, String resourceType, String associationId) {+ return key(region, instanceId) + "::" + resourceType + "::" + associationId;+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/connect/model/ConnectInstance.java b/src/main/java/io/github/hectorvent/floci/services/connect/model/ConnectInstance.javanew file mode 100644index 0000000000..472324eb29--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/connect/model/ConnectInstance.java@@ -0,0 +1,129 @@+package io.github.hectorvent.floci.services.connect.model;++import io.quarkus.runtime.annotations.RegisterForReflection;++import java.time.Instant;+import java.util.LinkedHashMap;+import java.util.Map;++@RegisterForReflection+public class ConnectInstance {++ private String id;+ private String arn;+ private String identityManagementType;+ private String instanceAlias;+ private String directoryId;+ private Instant createdTime;+ private String serviceRole;+ private boolean inboundCallsEnabled;+ private boolean outboundCallsEnabled;+ private String instanceAccessUrl;+ private Map<String, String> tags = new LinkedHashMap<>();+ private Map<String, String> attributes = 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 getIdentityManagementType() {+ return identityManagementType;+ }++ public void setIdentityManagementType(String identityManagementType) {+ this.identityManagementType = identityManagementType;+ }++ public String getInstanceAlias() {+ return instanceAlias;+ }++ public void setInstanceAlias(String instanceAlias) {+ this.instanceAlias = instanceAlias;+ }++ public String getDirectoryId() {+ return directoryId;+ }++ public void setDirectoryId(String directoryId) {+ this.directoryId = directoryId;+ }++ public Instant getCreatedTime() {+ return createdTime;+ }++ public void setCreatedTime(Instant createdTime) {+ this.createdTime = createdTime;+ }++ public String getServiceRole() {+ return serviceRole;+ }++ public void setServiceRole(String serviceRole) {+ this.serviceRole = serviceRole;+ }++ public boolean isInboundCallsEnabled() {+ return inboundCallsEnabled;+ }++ public void setInboundCallsEnabled(boolean inboundCallsEnabled) {+ this.inboundCallsEnabled = inboundCallsEnabled;+ }++ public boolean isOutboundCallsEnabled() {+ return outboundCallsEnabled;+ }++ public void setOutboundCallsEnabled(boolean outboundCallsEnabled) {+ this.outboundCallsEnabled = outboundCallsEnabled;+ }++ public String getInstanceAccessUrl() {+ return instanceAccessUrl;+ }++ public void setInstanceAccessUrl(String instanceAccessUrl) {+ this.instanceAccessUrl = instanceAccessUrl;+ }++ public Map<String, String> getTags() {+ return tags;+ }++ public void setTags(Map<String, String> tags) {+ this.tags = tags;+ }++ public Map<String, String> getAttributes() {+ return attributes;+ }++ public void setAttributes(Map<String, String> attributes) {+ this.attributes = attributes;+ }++ public String getAccountId() {+ return accountId;+ }++ public void setAccountId(String accountId) {+ this.accountId = accountId;+ }+}diff --git a/src/main/java/io/github/hectorvent/floci/services/connect/model/ConnectStorageConfig.java b/src/main/java/io/github/hectorvent/floci/services/connect/model/ConnectStorageConfig.javanew file mode 100644index 0000000000..403ddf546e--- /dev/null+++ b/src/main/java/io/github/hectorvent/floci/services/connect/model/ConnectStorageConfig.java@@ -0,0 +1,54 @@+package io.github.hectorvent.floci.services.connect.model;++import com.fasterxml.jackson.databind.JsonNode;+import io.quarkus.runtime.annotations.RegisterForReflection;++@RegisterForReflection+public class ConnectStorageConfig {++ private String associationId;+ private String instanceId;+ private String resourceType;+ private String storageType;+ private JsonNode storageConfig;++ public String getAssociationId() {+ return associationId;+ }++ public void setAssociationId(String associationId) {+ this.associationId = associationId;+ }++ public String getInstanceId() {+ return instanceId;+ }++ public void setInstanceId(String instanceId) {+ this.instanceId = instanceId;+ }++ public String getResourceType() {+ return resourceType;+ }++ public void setResourceType(String resourceType) {+ this.resourceType = resourceType;+ }++ public String getStorageType() {+ return storageType;+ }++ public void setStorageType(String storageType) {+ this.storageType = storageType;+ }++ public JsonNode getStorageConfig() {+ return storageConfig;+ }++ public void setStorageConfig(JsonNode storageConfig) {+ this.storageConfig = storageConfig;+ }+}diff --git a/src/main/resources/application.yml b/src/main/resources/application.ymlindex 251b646399..b2fb33b1bb 100644--- a/src/main/resources/application.yml+++ b/src/main/resources/application.yml@@ -579,6 +579,8 @@ floci:enabled: trueroute53resolver:enabled: true+ connect:+ enabled: trueaps:enabled: truelakeformation:diff --git a/src/test/java/io/github/hectorvent/floci/services/connect/ConnectIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/connect/ConnectIntegrationTest.javanew file mode 100644index 0000000000..5cdffd5f04--- /dev/null+++ b/src/test/java/io/github/hectorvent/floci/services/connect/ConnectIntegrationTest.java@@ -0,0 +1,410 @@+package io.github.hectorvent.floci.services.connect;++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 ConnectIntegrationTest {++ private static String instanceId;+ private static String instanceArn;+ private static String associationId;++ @Test+ @Order(1)+ void createInstance() {+ var response = given()+ .contentType("application/json")+ .body("""+ {+ "IdentityManagementType": "CONNECT_MANAGED",+ "InstanceAlias": "floci-integration",+ "InboundCallsEnabled": true,+ "OutboundCallsEnabled": false,+ "Tags": {"team": "cx"}+ }+ """)+ .when()+ .put("/instance")+ .then()+ .statusCode(200)+ .body("Id", notNullValue())+ .body("Arn", containsString(":connect:"))+ .body("Arn", containsString(":instance/"))+ .extract();+ instanceId = response.path("Id");+ instanceArn = response.path("Arn");+ }++ @Test+ @Order(2)+ void describeInstanceReturnsActiveAndEchoesRequest() {+ given()+ .when()+ .get("/instance/" + instanceId)+ .then()+ .statusCode(200)+ .body("Instance.Id", equalTo(instanceId))+ .body("Instance.Arn", equalTo(instanceArn))+ .body("Instance.InstanceStatus", equalTo("ACTIVE"))+ .body("Instance.IdentityManagementType", equalTo("CONNECT_MANAGED"))+ .body("Instance.InstanceAlias", equalTo("floci-integration"))+ .body("Instance.InboundCallsEnabled", equalTo(true))+ .body("Instance.OutboundCallsEnabled", equalTo(false))+ .body("Instance.ServiceRole", containsString(":role/"))+ .body("Instance.InstanceAccessUrl", containsString("floci-integration"))+ .body("Instance.CreatedTime", notNullValue())+ .body("Instance.Tags.team", equalTo("cx"));+ }++ @Test+ @Order(3)+ void listInstancesIncludesTheNewInstance() {+ given()+ .when()+ .get("/instance")+ .then()+ .statusCode(200)+ .body("InstanceSummaryList.Id", hasItem(instanceId))+ .body("InstanceSummaryList.find { it.Id == '" + instanceId + "' }.InstanceStatus",+ equalTo("ACTIVE"))+ .body("InstanceSummaryList.find { it.Id == '" + instanceId + "' }.InstanceAlias",+ equalTo("floci-integration"));+ }++ @Test+ @Order(4)+ void describeMissingInstanceReturnsResourceNotFound() {+ given()+ .when()+ .get("/instance/00000000-0000-0000-0000-00000000dead")+ .then()+ .statusCode(404)+ .body("__type", equalTo("ResourceNotFoundException"));+ }++ @Test+ @Order(5)+ void duplicateAliasReturnsResourceConflict() {+ given()+ .contentType("application/json")+ .body("""+ {+ "IdentityManagementType": "CONNECT_MANAGED",+ "InstanceAlias": "floci-integration",+ "InboundCallsEnabled": true,+ "OutboundCallsEnabled": true+ }+ """)+ .when()+ .put("/instance")+ .then()+ .statusCode(409)+ .body("__type", equalTo("ResourceConflictException"));+ }++ @Test+ @Order(6)+ void createWithoutIdentityManagementTypeReturnsInvalidRequest() {+ given()+ .contentType("application/json")+ .body("{\"InboundCallsEnabled\": true, \"OutboundCallsEnabled\": true}")+ .when()+ .put("/instance")+ .then()+ .statusCode(400)+ .body("__type", equalTo("InvalidRequestException"));+ }++ @Test+ @Order(7)+ void instanceAttributesAreSeededAndUpdatable() {+ given()+ .when()+ .get("/instance/" + instanceId + "/attribute/INBOUND_CALLS")+ .then()+ .statusCode(200)+ .body("Attribute.AttributeType", equalTo("INBOUND_CALLS"))+ .body("Attribute.Value", equalTo("true"));++ given()+ .when()+ .get("/instance/" + instanceId + "/attribute/CONTACTFLOW_LOGS")+ .then()+ .statusCode(200)+ .body("Attribute.Value", equalTo("false"));++ given()+ .contentType("application/json")+ .body("{\"Value\": \"true\"}")+ .when()+ .post("/instance/" + instanceId + "/attribute/CONTACTFLOW_LOGS")+ .then()+ .statusCode(200);++ given()+ .when()+ .get("/instance/" + instanceId + "/attribute/CONTACTFLOW_LOGS")+ .then()+ .statusCode(200)+ .body("Attribute.Value", equalTo("true"));+ }++ @Test+ @Order(7)+ void attributeValueIsValidatedAndCanonicalized() {+ given()+ .contentType("application/json")+ .body("{\"Value\": \"yes\"}")+ .when()+ .post("/instance/" + instanceId + "/attribute/AUTO_RESOLVE_BEST_VOICES")+ .then()+ .statusCode(400)+ .body("__type", equalTo("InvalidParameterException"));++ given()+ .contentType("application/json")+ .body("{\"Value\": \"TRUE\"}")+ .when()+ .post("/instance/" + instanceId + "/attribute/AUTO_RESOLVE_BEST_VOICES")+ .then()+ .statusCode(200);++ given()+ .when()+ .get("/instance/" + instanceId + "/attribute/AUTO_RESOLVE_BEST_VOICES")+ .then()+ .statusCode(200)+ .body("Attribute.Value", equalTo("true"));+ }++ @Test+ @Order(8)+ void listInstanceAttributes() {+ given()+ .when()+ .get("/instance/" + instanceId + "/attributes")+ .then()+ .statusCode(200)+ .body("Attributes.AttributeType", hasItem("CONTACT_LENS"))+ .body("Attributes.find { it.AttributeType == 'CONTACTFLOW_LOGS' }.Value", equalTo("true"))+ .body("Attributes.find { it.AttributeType == 'OUTBOUND_CALLS' }.Value", equalTo("false"));+ }++ @Test+ @Order(9)+ void unknownAttributeTypeReturnsInvalidParameter() {+ given()+ .when()+ .get("/instance/" + instanceId + "/attribute/NOT_A_REAL_ATTRIBUTE")+ .then()+ .statusCode(400)+ .body("__type", equalTo("InvalidParameterException"));+ }++ @Test+ @Order(10)+ void associateAndDescribeInstanceStorageConfig() {+ associationId = given()+ .contentType("application/json")+ .body("""+ {+ "ResourceType": "CHAT_TRANSCRIPTS",+ "StorageConfig": {+ "StorageType": "S3",+ "S3Config": {+ "BucketName": "floci-transcripts",+ "BucketPrefix": "chat/",+ "EncryptionConfig": {+ "EncryptionType": "KMS",+ "KeyId": "arn:aws:kms:us-east-1:000000000000:key/abc"+ }+ }+ }+ }+ """)+ .when()+ .put("/instance/" + instanceId + "/storage-config")+ .then()+ .statusCode(200)+ .body("AssociationId", notNullValue())+ .extract().path("AssociationId");++ given()+ .queryParam("resourceType", "CHAT_TRANSCRIPTS")+ .when()+ .get("/instance/" + instanceId + "/storage-config/" + associationId)+ .then()+ .statusCode(200)+ .body("StorageConfig.AssociationId", equalTo(associationId))+ .body("StorageConfig.StorageType", equalTo("S3"))+ .body("StorageConfig.S3Config.BucketName", equalTo("floci-transcripts"))+ .body("StorageConfig.S3Config.BucketPrefix", equalTo("chat/"))+ .body("StorageConfig.S3Config.EncryptionConfig.EncryptionType", equalTo("KMS"));+ }++ @Test+ @Order(11)+ void listInstanceStorageConfigs() {+ given()+ .queryParam("resourceType", "CHAT_TRANSCRIPTS")+ .when()+ .get("/instance/" + instanceId + "/storage-configs")+ .then()+ .statusCode(200)+ .body("StorageConfigs.AssociationId", hasItem(associationId))+ .body("StorageConfigs[0].S3Config.BucketName", equalTo("floci-transcripts"));++ given()+ .queryParam("resourceType", "CALL_RECORDINGS")+ .when()+ .get("/instance/" + instanceId + "/storage-configs")+ .then()+ .statusCode(200)+ .body("StorageConfigs.size()", equalTo(0));+ }++ @Test+ @Order(12)+ void updateInstanceStorageConfig() {+ given()+ .contentType("application/json")+ .queryParam("resourceType", "CHAT_TRANSCRIPTS")+ .body("""+ {+ "StorageConfig": {+ "StorageType": "S3",+ "S3Config": {"BucketName": "floci-transcripts-v2", "BucketPrefix": "chat/"}+ }+ }+ """)+ .when()+ .post("/instance/" + instanceId + "/storage-config/" + associationId)+ .then()+ .statusCode(200);++ given()+ .queryParam("resourceType", "CHAT_TRANSCRIPTS")+ .when()+ .get("/instance/" + instanceId + "/storage-config/" + associationId)+ .then()+ .statusCode(200)+ .body("StorageConfig.S3Config.BucketName", equalTo("floci-transcripts-v2"))+ .body("StorageConfig.S3Config.EncryptionConfig", nullValue());+ }++ @Test+ @Order(13)+ void storageConfigWithoutMatchingMemberIsRejected() {+ given()+ .contentType("application/json")+ .body("""+ {"ResourceType": "CALL_RECORDINGS", "StorageConfig": {"StorageType": "S3"}}+ """)+ .when()+ .put("/instance/" + instanceId + "/storage-config")+ .then()+ .statusCode(400)+ .body("__type", equalTo("InvalidRequestException"));+ }++ @Test+ @Order(14)+ void tagRoundTripOnTheSharedTagsPath() {+ given()+ .when()+ .get("/tags/" + instanceArn)+ .then()+ .statusCode(200)+ .body("tags.team", equalTo("cx"));++ given()+ .contentType("application/json")+ .body("{\"tags\": {\"env\": \"test\"}}")+ .when()+ .post("/tags/" + instanceArn)+ .then()+ .statusCode(204);++ given()+ .when()+ .get("/tags/" + instanceArn)+ .then()+ .statusCode(200)+ .body("tags.env", equalTo("test"))+ .body("tags.team", equalTo("cx"));++ given()+ .queryParam("tagKeys", "env")+ .when()+ .delete("/tags/" + instanceArn)+ .then()+ .statusCode(204);++ given()+ .when()+ .get("/tags/" + instanceArn)+ .then()+ .statusCode(200)+ .body("tags.env", nullValue())+ .body("tags.team", equalTo("cx"));+ }++ @Test+ @Order(15)+ void disassociateInstanceStorageConfig() {+ given()+ .queryParam("resourceType", "CHAT_TRANSCRIPTS")+ .when()+ .delete("/instance/" + instanceId + "/storage-config/" + associationId)+ .then()+ .statusCode(200);++ given()+ .queryParam("resourceType", "CHAT_TRANSCRIPTS")+ .when()+ .get("/instance/" + instanceId + "/storage-config/" + associationId)+ .then()+ .statusCode(404)+ .body("__type", equalTo("ResourceNotFoundException"));+ }++ @Test+ @Order(16)+ void deleteInstance() {+ given()+ .when()+ .delete("/instance/" + instanceId)+ .then()+ .statusCode(200);++ given()+ .when()+ .get("/instance/" + instanceId)+ .then()+ .statusCode(404)+ .body("__type", equalTo("ResourceNotFoundException"));+ }++ @Test+ @Order(17)+ void deleteMissingInstanceReturnsResourceNotFound() {+ given()+ .when()+ .delete("/instance/" + instanceId)+ .then()+ .statusCode(404)+ .body("__type", equalTo("ResourceNotFoundException"));+ }+}diff --git a/src/test/resources/application.yml b/src/test/resources/application.ymlindex 254d7a8995..ff78af4dcf 100644--- a/src/test/resources/application.yml+++ b/src/test/resources/application.yml@@ -364,6 +364,8 @@ floci:enabled: trueroute53resolver:enabled: true+ connect:+ enabled: trueaps:enabled: truelakeformation:diff --git a/tools/docs/services.yaml b/tools/docs/services.yamlindex ea8835d9d5..50b38802f5 100644--- a/tools/docs/services.yaml+++ b/tools/docs/services.yaml@@ -38,6 +38,19 @@ services:doc: docs/services/comprehend.mdsources:- { path: src/main/java/io/github/hectorvent/floci/services/comprehend/ComprehendJsonHandler.java, mode: switch }+ - service: connect+ doc: docs/services/connect.md+ sources:+ - { path: src/main/java/io/github/hectorvent/floci/services/connect/ConnectController.java, mode: rest }+ - { path: src/main/java/io/github/hectorvent/floci/core/common/SharedTagsController.java, mode: rest }+ rename_actions:+ ListTags: ListTagsForResource+ TagResourcePost: TagResource+ exclude_actions:+ - ListTagsByQuery+ - TagResourceByBody+ - TagResourcePut+ - UntagResourceByQuery- service: rekognitiondoc: docs/services/rekognition.mdsources: