From 96a6fa65178bec74431cd43dc9dba9d3b45e7666 Mon Sep 17 00:00:00 2001 From: Federico Mariani <34543311+Croway@users.noreply.github.com> Date: Thu, 21 May 2026 00:15:38 +0200 Subject: [PATCH] feat(config): add AWS Config service emulation (#934) * feat(config): add AWS Config service emulation (#913) * docs: add AWS Config service page and align service counts across all docs Add docs/services/config.md with all 20 supported actions, CLI examples, and configuration reference. Add 5 services that had doc pages but were missing from the service matrix (Textract, Pricing, Cost Explorer, CUR, BCM Data Exports). Reconcile service count to 51 across README, docs/index.md, and docs/services/index.md. --- README.md | 7 +- docs/index.md | 10 +- docs/services/config.md | 110 ++++++ docs/services/index.md | 8 +- .../floci/config/EmulatorConfig.java | 6 + .../core/common/AwsJson11Controller.java | 7 +- .../core/common/ResolvedServiceCatalog.java | 4 + .../configservice/AwsConfigService.java | 316 ++++++++++++++++++ .../ConfigServiceJsonHandler.java | 242 ++++++++++++++ .../configservice/model/ConfigRule.java | 17 + .../model/ConfigRuleEvaluationStatus.java | 16 + .../configservice/model/ConfigRuleSource.java | 14 + .../ConfigSnapshotDeliveryProperties.java | 13 + .../model/ConfigurationRecorder.java | 15 + .../model/ConfigurationRecorderStatus.java | 17 + .../configservice/model/ConformancePack.java | 17 + .../model/ConformancePackStatusDetail.java | 17 + .../configservice/model/DeliveryChannel.java | 18 + .../configservice/model/RecordingGroup.java | 17 + .../ConfigRuleIntegrationTest.java | 215 ++++++++++++ .../ConfigTaggingIntegrationTest.java | 163 +++++++++ .../ConfigurationRecorderIntegrationTest.java | 219 ++++++++++++ .../ConformancePackIntegrationTest.java | 129 +++++++ 23 files changed, 1590 insertions(+), 7 deletions(-) create mode 100644 docs/services/config.md create mode 100644 src/main/java/io/github/hectorvent/floci/services/configservice/AwsConfigService.java create mode 100644 src/main/java/io/github/hectorvent/floci/services/configservice/ConfigServiceJsonHandler.java create mode 100644 src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigRule.java create mode 100644 src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigRuleEvaluationStatus.java create mode 100644 src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigRuleSource.java create mode 100644 src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigSnapshotDeliveryProperties.java create mode 100644 src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigurationRecorder.java create mode 100644 src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigurationRecorderStatus.java create mode 100644 src/main/java/io/github/hectorvent/floci/services/configservice/model/ConformancePack.java create mode 100644 src/main/java/io/github/hectorvent/floci/services/configservice/model/ConformancePackStatusDetail.java create mode 100644 src/main/java/io/github/hectorvent/floci/services/configservice/model/DeliveryChannel.java create mode 100644 src/main/java/io/github/hectorvent/floci/services/configservice/model/RecordingGroup.java create mode 100644 src/test/java/io/github/hectorvent/floci/services/configservice/ConfigRuleIntegrationTest.java create mode 100644 src/test/java/io/github/hectorvent/floci/services/configservice/ConfigTaggingIntegrationTest.java create mode 100644 src/test/java/io/github/hectorvent/floci/services/configservice/ConfigurationRecorderIntegrationTest.java create mode 100644 src/test/java/io/github/hectorvent/floci/services/configservice/ConformancePackIntegrationTest.java diff --git a/README.md b/README.md index edbeaf027d..6121ea4619 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ LocalStack's community edition [sunset in March 2026](https://blog.localstack.cl | CodeBuild | Real Docker execution | No | | Native binary | ~40 MB | No | -**47 AWS services. Broad coverage. Free forever.** +**51 AWS services. Broad coverage. Free forever.** ## Architecture Overview @@ -177,7 +177,7 @@ flowchart LR Router["HTTP Router\nJAX-RS / Vert.x"] subgraph Stateless ["Stateless Services"] - A["SSM · SQS · SNS\nIAM · STS · KMS\nSecrets Manager · SES\nCognito · Kinesis\nEventBridge · Scheduler · AppConfig\nCloudWatch · Step Functions\nCloudFormation · ACM\nAPI Gateway · ELB v2 · Auto Scaling\nCodeDeploy · Backup · Bedrock Runtime · Route53 · Transfer"] + A["SSM · SQS · SNS\nIAM · STS · KMS\nSecrets Manager · SES\nCognito · Kinesis\nEventBridge · Scheduler · AppConfig\nCloudWatch · Step Functions\nCloudFormation · ACM · Config\nAPI Gateway · ELB v2 · Auto Scaling\nCodeDeploy · Backup · Bedrock Runtime · Route53 · Transfer"] end subgraph Stateful ["Stateful Services"] @@ -213,7 +213,7 @@ Floci supports local emulation for application services, data services, eventing | Data and analytics | Athena, Glue, Firehose, OpenSearch, Textract | | Messaging and transfer | SES, SES v2, Kinesis, Transfer Family | | Cost and billing | Pricing, Cost Explorer, Cost and Usage Reports, BCM Data Exports | -| Backup and config | AWS Backup, AppConfig, AppConfigData, CloudFormation | +| Backup and config | AWS Backup, AWS Config, AppConfig, AppConfigData, CloudFormation | For operation-level compatibility, see the [Services Overview](https://floci.io/floci/services/). @@ -266,6 +266,7 @@ For operation-level compatibility, see the [Services Overview](https://floci.io/ | CodeDeploy | In-process with Lambda traffic shifting | Deployment groups, configs, lifecycle hooks, auto-rollback | | Auto Scaling | In-process with reconciler | Launch configs, ASGs, desired capacity reconciliation, lifecycle hooks | | AWS Backup | In-process | Vaults, backup plans, selections, simulated job lifecycle, recovery points | +| AWS Config | In-process | Config rules, configuration recorders, delivery channels, conformance packs, tagging | | Route53 | In-process | Hosted zones, SOA and NS records, resource record sets, change tracking, tagging | | Transfer Family | In-process | Server lifecycle, user management, SSH key import, tagging | | Textract | In-process stub | API-compatible stubs, dummy block data, async job simulation | diff --git a/docs/index.md b/docs/index.md index 7f3fc760f8..7884c35968 100644 --- a/docs/index.md +++ b/docs/index.md @@ -12,7 +12,7 @@ Floci is a fast, free, and open-source local AWS service emulator built for deve ## Supported Services -Floci emulates 45 AWS services. See the [Services Overview](services/index.md) for per-service operation counts, endpoints, and full protocol details. +Floci emulates 51 AWS services. See the [Services Overview](services/index.md) for per-service operation counts, endpoints, and full protocol details. | Service | Protocol | |---|---| @@ -56,6 +56,12 @@ Floci emulates 45 AWS services. See the [Services Overview](services/index.md) f | CodeDeploy | JSON 1.1 | | AWS Backup | REST JSON | | Route53 | REST XML | +| AWS Config | JSON 1.1 | +| Textract | JSON 1.1 | +| Pricing | JSON 1.1 | +| Cost Explorer | JSON 1.1 | +| Cost and Usage Reports | JSON 1.1 | +| BCM Data Exports | JSON 1.1 | | Transfer Family | JSON 1.1 | ## Why Floci? @@ -92,7 +98,7 @@ docker compose up -d aws --endpoint-url http://localhost:4566 s3 mb s3://my-bucket ``` -All 45 AWS services are immediately available at `http://localhost:4566`. +All 51 AWS services are immediately available at `http://localhost:4566`. [Get started →](getting-started/quick-start.md){ .md-button .md-button--primary } [View services →](services/index.md){ .md-button } diff --git a/docs/services/config.md b/docs/services/config.md new file mode 100644 index 0000000000..b26a87bc89 --- /dev/null +++ b/docs/services/config.md @@ -0,0 +1,110 @@ +# AWS Config + +**Protocol:** JSON 1.1 (`X-Amz-Target: StarlingDoveService.*`) +**Endpoint:** `POST http://localhost:4566/` + +## Supported Actions + +### Config Rules + +| Action | Description | +|---|---| +| `PutConfigRule` | Create or update a config rule | +| `DeleteConfigRule` | Delete a config rule | +| `DescribeConfigRules` | List config rules, optionally filtered by name | +| `DescribeComplianceByConfigRule` | Get compliance summary for config rules | +| `DescribeConfigRuleEvaluationStatus` | Get evaluation status for config rules | +| `StartConfigRulesEvaluation` | Trigger evaluation for config rules | + +### Configuration Recorder + +| Action | Description | +|---|---| +| `PutConfigurationRecorder` | Create or update a configuration recorder | +| `DescribeConfigurationRecorders` | List configuration recorders | +| `StartConfigurationRecorder` | Start recording configuration changes | +| `StopConfigurationRecorder` | Stop recording configuration changes | +| `DescribeConfigurationRecorderStatus` | Get the status of configuration recorders | + +### Delivery Channel + +| Action | Description | +|---|---| +| `PutDeliveryChannel` | Create or update a delivery channel | +| `DescribeDeliveryChannels` | List delivery channels | + +### Conformance Packs + +| Action | Description | +|---|---| +| `PutConformancePack` | Create or update a conformance pack | +| `DeleteConformancePack` | Delete a conformance pack | +| `DescribeConformancePacks` | List conformance packs | +| `DescribeConformancePackStatus` | Get the deployment status of conformance packs | + +### Tagging + +| Action | Description | +|---|---| +| `TagResource` | Add tags to a Config resource | +| `UntagResource` | Remove tags from a Config resource | +| `ListTagsForResource` | List tags on a Config resource | + +## Configuration + +| Variable | Default | Description | +|---|---|---| +| `FLOCI_SERVICES_CONFIGSERVICE_ENABLED` | `true` | Enable or disable the service | + +## Examples + +```bash +export AWS_ENDPOINT_URL=http://localhost:4566 + +# Create a config rule +aws configservice put-config-rule --config-rule '{ + "ConfigRuleName": "s3-bucket-versioning", + "Source": { + "Owner": "AWS", + "SourceIdentifier": "S3_BUCKET_VERSIONING_ENABLED" + } +}' + +# List config rules +aws configservice describe-config-rules + +# Create a configuration recorder +aws configservice put-configuration-recorder --configuration-recorder '{ + "name": "default", + "roleARN": "arn:aws:iam::012345678901:role/config-role", + "recordingGroup": { + "allSupported": true, + "includeGlobalResourceTypes": true + } +}' + +# Start recording +aws configservice start-configuration-recorder --configuration-recorder-name default + +# Check recorder status +aws configservice describe-configuration-recorder-status + +# Create a conformance pack +aws configservice put-conformance-pack \ + --conformance-pack-name my-pack \ + --template-body "Resources: {}" + +# List conformance packs +aws configservice describe-conformance-packs + +# Tag a resource +aws configservice tag-resource \ + --resource-arn arn:aws:config:us-east-1:000000000000:config-rule/config-rule-abc123 \ + --tags Key=env,Value=dev + +# Delete a config rule +aws configservice delete-config-rule --config-rule-name s3-bucket-versioning +``` + +!!! note + Compliance status always returns `INSUFFICIENT_DATA` since Floci does not perform actual resource evaluation. Config rules, recorders, and conformance packs are stored and returned correctly, but no real configuration recording or compliance checking takes place. diff --git a/docs/services/index.md b/docs/services/index.md index 9833f63aca..72aa5b2cb6 100644 --- a/docs/services/index.md +++ b/docs/services/index.md @@ -1,6 +1,6 @@ # Services Overview -Floci emulates 45 AWS services on a single port (`4566`). All services use the real AWS wire protocol, your existing AWS CLI commands and SDK clients work without modification. +Floci emulates 51 AWS services on a single port (`4566`). All services use the real AWS wire protocol, your existing AWS CLI commands and SDK clients work without modification. This page is the canonical reference for supported service and operation counts. Some services expose separate control-plane and data-plane rows below. Other docs (and the README) should link here rather than duplicating the table. @@ -54,6 +54,12 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac | [CodeDeploy](codedeploy.md) | `POST /` + `X-Amz-Target: CodeDeploy_20141006.*` | JSON 1.1 | 30 | | [AWS Backup](backup.md) | `/backup-vaults/*`, `/backup/plans/*`, `/backup-jobs/*`, `/supported-resource-types` | REST JSON | 20 | | [Route53](route53.md) | `/2013-04-01/hostedzone/*`, `/2013-04-01/healthcheck/*`, `/2013-04-01/change/*` | REST XML | 17 | +| [AWS Config](config.md) | `POST /` + `X-Amz-Target: StarlingDoveService.*` | JSON 1.1 | 20 | +| [Textract](textract.md) | `POST /` + `X-Amz-Target: Textract.*` | JSON 1.1 | 6 | +| [Pricing](pricing.md) | `POST /` + `X-Amz-Target: AWSPriceListService.*` | JSON 1.1 | 5 | +| [Cost Explorer](ce.md) | `POST /` + `X-Amz-Target: AWSInsightsIndexService.*` | JSON 1.1 | 9 | +| [Cost and Usage Reports](cur.md) | `POST /` + `X-Amz-Target: AWSOrigamiServiceGatewayService.*` | JSON 1.1 | 6 | +| [BCM Data Exports](bcm-data-exports.md) | `POST /` + `X-Amz-Target: AWSBillingAndCostManagementDataExports.*` | JSON 1.1 | 7 | | [Transfer Family](transfer.md) | `POST /` + `X-Amz-Target: TransferService.*` | JSON 1.1 | 17 | **Lambda, ElastiCache, RDS, MSK, ECS, EKS, and OpenSearch** spin up real Docker containers and support IAM authentication and SigV4 request signing, the same auth flow as production AWS. diff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java index 5e42bfb8a1..87195fd4d4 100644 --- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java +++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java @@ -312,6 +312,7 @@ public interface EmulatorConfig { CostExplorerServiceConfig ce(); CurServiceConfig cur(); BcmDataExportsServiceConfig bcmDataExports(); + ConfigServiceConfig configservice(); } interface TransferServiceConfig { @@ -344,6 +345,11 @@ public interface EmulatorConfig { String defaultNameserver4(); } + interface ConfigServiceConfig { + @WithDefault("true") + boolean enabled(); + } + interface AutoScalingServiceConfig { @WithDefault("true") boolean enabled(); diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java index cf873d6cae..f01017d1a7 100644 --- a/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java +++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsJson11Controller.java @@ -14,6 +14,7 @@ import io.github.hectorvent.floci.services.glue.GlueJsonHandler; import io.github.hectorvent.floci.services.resourcegroupstagging.ResourceGroupsTaggingJsonHandler; import io.github.hectorvent.floci.services.bcmdataexports.BcmDataExportsJsonHandler; import io.github.hectorvent.floci.services.ce.CostExplorerJsonHandler; +import io.github.hectorvent.floci.services.configservice.ConfigServiceJsonHandler; import io.github.hectorvent.floci.services.cur.CurJsonHandler; import io.github.hectorvent.floci.services.pricing.PricingJsonHandler; import io.github.hectorvent.floci.services.textract.TextractJsonHandler; @@ -76,6 +77,7 @@ public class AwsJson11Controller { private final CostExplorerJsonHandler costExplorerJsonHandler; private final CurJsonHandler curJsonHandler; private final BcmDataExportsJsonHandler bcmDataExportsJsonHandler; + private final ConfigServiceJsonHandler configServiceJsonHandler; @Inject public AwsJson11Controller(ObjectMapper objectMapper, ResolvedServiceCatalog catalog, @@ -100,7 +102,8 @@ public class AwsJson11Controller { TranscribeJsonHandler transcribeJsonHandler, CostExplorerJsonHandler costExplorerJsonHandler, CurJsonHandler curJsonHandler, - BcmDataExportsJsonHandler bcmDataExportsJsonHandler) { + BcmDataExportsJsonHandler bcmDataExportsJsonHandler, + ConfigServiceJsonHandler configServiceJsonHandler) { this.objectMapper = objectMapper; this.catalog = catalog; this.regionResolver = regionResolver; @@ -129,6 +132,7 @@ public class AwsJson11Controller { this.costExplorerJsonHandler = costExplorerJsonHandler; this.curJsonHandler = curJsonHandler; this.bcmDataExportsJsonHandler = bcmDataExportsJsonHandler; + this.configServiceJsonHandler = configServiceJsonHandler; } @POST @@ -182,6 +186,7 @@ public class AwsJson11Controller { case "ce" -> costExplorerJsonHandler.handle(action, request, region); case "cur" -> curJsonHandler.handle(action, request, region); case "bcm-data-exports" -> bcmDataExportsJsonHandler.handle(action, request, region); + case "config" -> configServiceJsonHandler.handle(action, request, region); default -> null; }; // catalog.matchTarget is protocol-agnostic: a JSON 1.0 target 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.java index c246a23794..d873b43b07 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 @@ -224,6 +224,10 @@ public class ResolvedServiceCatalog { null, null, 5000L, null, ServiceProtocol.JSON, protocols(ServiceProtocol.JSON), Set.of("CodeDeploy_20141006."), Set.of("codedeploy"), Set.of(), Set.of()), + descriptor("config", "configservice", config.services().configservice().enabled(), true, + null, null, 5000L, null, ServiceProtocol.JSON, + protocols(ServiceProtocol.JSON), + Set.of("StarlingDoveService."), Set.of("config"), Set.of(), Set.of()), descriptor("autoscaling", "autoscaling", config.services().autoscaling().enabled(), true, "autoscaling", config.storage().mode(), 5000L, AwsNamespaces.AUTOSCALING, ServiceProtocol.QUERY, protocols(ServiceProtocol.QUERY), diff --git a/src/main/java/io/github/hectorvent/floci/services/configservice/AwsConfigService.java b/src/main/java/io/github/hectorvent/floci/services/configservice/AwsConfigService.java new file mode 100644 index 0000000000..8bbd968937 --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/configservice/AwsConfigService.java @@ -0,0 +1,316 @@ +package io.github.hectorvent.floci.services.configservice; + +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.services.configservice.model.ConfigRule; +import io.github.hectorvent.floci.services.configservice.model.ConfigRuleEvaluationStatus; +import io.github.hectorvent.floci.services.configservice.model.ConfigRuleSource; +import io.github.hectorvent.floci.services.configservice.model.ConfigurationRecorder; +import io.github.hectorvent.floci.services.configservice.model.ConfigurationRecorderStatus; +import io.github.hectorvent.floci.services.configservice.model.ConformancePack; +import io.github.hectorvent.floci.services.configservice.model.ConformancePackStatusDetail; +import io.github.hectorvent.floci.services.configservice.model.DeliveryChannel; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + +@ApplicationScoped +public class AwsConfigService { + + private final RegionResolver regionResolver; + + private final ConcurrentHashMap> configRules = new ConcurrentHashMap<>(); + private final ConcurrentHashMap> conformancePacks = new ConcurrentHashMap<>(); + + private final ConcurrentHashMap configurationRecorders = new ConcurrentHashMap<>(); + private final ConcurrentHashMap recorderRunning = new ConcurrentHashMap<>(); + private final ConcurrentHashMap recorderLastStartTime = new ConcurrentHashMap<>(); + private final ConcurrentHashMap recorderLastStopTime = new ConcurrentHashMap<>(); + + private final ConcurrentHashMap deliveryChannels = new ConcurrentHashMap<>(); + + private final ConcurrentHashMap> tags = new ConcurrentHashMap<>(); + + @Inject + public AwsConfigService(RegionResolver regionResolver) { + this.regionResolver = regionResolver; + } + + // --- Config Rules --- + + public ConfigRule putConfigRule(String region, String ruleName, ConfigRuleSource source) { + ConcurrentHashMap store = rulesFor(region); + ConfigRule existing = store.get(ruleName); + if (existing != null) { + ConfigRule updated = new ConfigRule(existing.configRuleName(), existing.configRuleArn(), + existing.configRuleId(), existing.configRuleState(), source); + store.put(ruleName, updated); + return updated; + } + String ruleId = "config-rule-" + shortId(); + String ruleArn = AwsArnUtils.Arn.of("config", region, regionResolver.getAccountId(), + "config-rule/" + ruleId).toString(); + ConfigRule rule = new ConfigRule(ruleName, ruleArn, ruleId, "ACTIVE", source); + store.put(ruleName, rule); + return rule; + } + + public void deleteConfigRule(String region, String ruleName) { + ConcurrentHashMap store = rulesFor(region); + if (store.remove(ruleName) == null) { + throw new AwsException("NoSuchConfigRuleException", + "The ConfigRule provided in the request is invalid. " + + "Please check the configRule name.", 400); + } + } + + public List describeConfigRules(String region, List ruleNames) { + ConcurrentHashMap store = rulesFor(region); + if (ruleNames == null || ruleNames.isEmpty()) { + return new ArrayList<>(store.values()); + } + List result = new ArrayList<>(); + for (String name : ruleNames) { + ConfigRule rule = store.get(name); + if (rule != null) { + result.add(rule); + } + } + return result; + } + + public List describeConfigRuleEvaluationStatus(String region, List ruleNames) { + List rules = describeConfigRules(region, ruleNames); + List result = new ArrayList<>(); + for (ConfigRule rule : rules) { + result.add(new ConfigRuleEvaluationStatus( + rule.configRuleName(), + rule.configRuleArn(), + rule.configRuleId(), + true)); + } + return result; + } + + public void startConfigRulesEvaluation(String region, List ruleNames) { + ConcurrentHashMap store = rulesFor(region); + for (String name : ruleNames) { + if (!store.containsKey(name)) { + throw new AwsException("NoSuchConfigRuleException", + "The ConfigRule provided in the request is invalid. " + + "Please check the configRule name.", 400); + } + } + } + + // --- Configuration Recorder --- + + public void putConfigurationRecorder(String region, ConfigurationRecorder recorder) { + String name = (recorder.name() == null || recorder.name().isEmpty()) ? "default" : recorder.name(); + ConfigurationRecorder stored = new ConfigurationRecorder(name, recorder.roleARN(), recorder.recordingGroup()); + configurationRecorders.put(region, stored); + } + + public List describeConfigurationRecorders(String region, List names) { + ConfigurationRecorder recorder = configurationRecorders.get(region); + if (recorder == null) { + if (names != null && !names.isEmpty()) { + throw new AwsException("NoSuchConfigurationRecorderException", + "Cannot find configuration recorder with the specified name.", 400); + } + return Collections.emptyList(); + } + if (names != null && !names.isEmpty()) { + for (String name : names) { + if (!name.equals(recorder.name())) { + throw new AwsException("NoSuchConfigurationRecorderException", + "Cannot find configuration recorder with the specified name.", 400); + } + } + } + return List.of(recorder); + } + + public void startConfigurationRecorder(String region, String name) { + ConfigurationRecorder recorder = configurationRecorders.get(region); + if (recorder == null || !recorder.name().equals(name)) { + throw new AwsException("NoSuchConfigurationRecorderException", + "Cannot find configuration recorder with the specified name.", 400); + } + recorderRunning.put(region, true); + recorderLastStartTime.put(region, System.currentTimeMillis() / 1000); + } + + public void stopConfigurationRecorder(String region, String name) { + ConfigurationRecorder recorder = configurationRecorders.get(region); + if (recorder == null || !recorder.name().equals(name)) { + throw new AwsException("NoSuchConfigurationRecorderException", + "Cannot find configuration recorder with the specified name.", 400); + } + recorderRunning.put(region, false); + recorderLastStopTime.put(region, System.currentTimeMillis() / 1000); + } + + public List describeConfigurationRecorderStatus(String region, List names) { + ConfigurationRecorder recorder = configurationRecorders.get(region); + if (recorder == null) { + if (names != null && !names.isEmpty()) { + throw new AwsException("NoSuchConfigurationRecorderException", + "Cannot find configuration recorder with the specified name.", 400); + } + return Collections.emptyList(); + } + if (names != null && !names.isEmpty()) { + for (String name : names) { + if (!name.equals(recorder.name())) { + throw new AwsException("NoSuchConfigurationRecorderException", + "Cannot find configuration recorder with the specified name.", 400); + } + } + } + ConfigurationRecorderStatus status = new ConfigurationRecorderStatus( + recorder.name(), + recorderRunning.getOrDefault(region, false), + recorderLastStartTime.containsKey(region) ? "SUCCESS" : "Pending", + recorderLastStartTime.get(region), + recorderLastStopTime.get(region)); + return List.of(status); + } + + // --- Delivery Channel --- + + public void putDeliveryChannel(String region, DeliveryChannel channel) { + if (!configurationRecorders.containsKey(region)) { + throw new AwsException("NoAvailableConfigurationRecorderException", + "There are no configuration recorders available to provide the resource count.", 400); + } + String name = (channel.name() == null || channel.name().isEmpty()) ? "default" : channel.name(); + DeliveryChannel stored = new DeliveryChannel(name, channel.s3BucketName(), channel.s3KeyPrefix(), + channel.s3KmsKeyArn(), channel.snsTopicARN(), channel.configSnapshotDeliveryProperties()); + deliveryChannels.put(region, stored); + } + + public List describeDeliveryChannels(String region, List names) { + DeliveryChannel channel = deliveryChannels.get(region); + if (channel == null) { + if (names != null && !names.isEmpty()) { + throw new AwsException("NoSuchDeliveryChannelException", + "Cannot find delivery channel with the specified name.", 400); + } + return Collections.emptyList(); + } + if (names != null && !names.isEmpty()) { + for (String name : names) { + if (!name.equals(channel.name())) { + throw new AwsException("NoSuchDeliveryChannelException", + "Cannot find delivery channel with the specified name.", 400); + } + } + } + return List.of(channel); + } + + // --- Conformance Packs --- + + public ConformancePack putConformancePack(String region, String packName, + String templateS3Uri, String templateBody) { + ConcurrentHashMap store = packsFor(region); + ConformancePack existing = store.get(packName); + if (existing != null) { + ConformancePack updated = new ConformancePack(existing.conformancePackName(), existing.conformancePackArn(), + existing.conformancePackId(), templateS3Uri, templateBody); + store.put(packName, updated); + return updated; + } + String packId = "conformance-pack-" + shortId(); + String packArn = AwsArnUtils.Arn.of("config", region, regionResolver.getAccountId(), + "conformance-pack/" + packName + "/" + packId).toString(); + ConformancePack pack = new ConformancePack(packName, packArn, packId, templateS3Uri, templateBody); + store.put(packName, pack); + return pack; + } + + public void deleteConformancePack(String region, String packName) { + ConcurrentHashMap store = packsFor(region); + if (store.remove(packName) == null) { + throw new AwsException("NoSuchConformancePackException", + "Conformance pack '" + packName + "' does not exist.", 400); + } + } + + public List describeConformancePacks(String region, List names) { + ConcurrentHashMap store = packsFor(region); + if (names == null || names.isEmpty()) { + return new ArrayList<>(store.values()); + } + List result = new ArrayList<>(); + for (String name : names) { + ConformancePack pack = store.get(name); + if (pack == null) { + throw new AwsException("NoSuchConformancePackException", + "Conformance pack '" + name + "' does not exist.", 400); + } + result.add(pack); + } + return result; + } + + public List describeConformancePackStatus(String region, List names) { + List packs = describeConformancePacks(region, names); + List result = new ArrayList<>(); + for (ConformancePack pack : packs) { + result.add(new ConformancePackStatusDetail( + pack.conformancePackName(), + pack.conformancePackId(), + pack.conformancePackArn(), + "CREATE_SUCCESSFUL", + System.currentTimeMillis() / 1000)); + } + return result; + } + + // --- Tagging --- + + public void tagResource(String arn, List> tagList) { + Map tagMap = tags.computeIfAbsent(arn, k -> new ConcurrentHashMap<>()); + for (Map t : tagList) { + tagMap.put(t.get("Key"), t.get("Value")); + } + } + + public void untagResource(String arn, List tagKeys) { + Map tagMap = tags.get(arn); + if (tagMap != null) { + tagKeys.forEach(tagMap::remove); + } + } + + public List> listTagsForResource(String arn) { + Map tagMap = tags.getOrDefault(arn, Map.of()); + return tagMap.entrySet().stream() + .map(e -> Map.of("Key", e.getKey(), "Value", e.getValue())) + .collect(Collectors.toList()); + } + + // --- Helpers --- + + private ConcurrentHashMap rulesFor(String region) { + return configRules.computeIfAbsent(region, r -> new ConcurrentHashMap<>()); + } + + private ConcurrentHashMap packsFor(String region) { + return conformancePacks.computeIfAbsent(region, r -> new ConcurrentHashMap<>()); + } + + private static String shortId() { + return UUID.randomUUID().toString().replace("-", "").substring(0, 12); + } +} diff --git a/src/main/java/io/github/hectorvent/floci/services/configservice/ConfigServiceJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/configservice/ConfigServiceJsonHandler.java new file mode 100644 index 0000000000..7b590552a0 --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/configservice/ConfigServiceJsonHandler.java @@ -0,0 +1,242 @@ +package io.github.hectorvent.floci.services.configservice; + +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.services.configservice.model.ConfigRule; +import io.github.hectorvent.floci.services.configservice.model.ConfigRuleEvaluationStatus; +import io.github.hectorvent.floci.services.configservice.model.ConfigRuleSource; +import io.github.hectorvent.floci.services.configservice.model.ConfigurationRecorder; +import io.github.hectorvent.floci.services.configservice.model.ConfigurationRecorderStatus; +import io.github.hectorvent.floci.services.configservice.model.ConformancePack; +import io.github.hectorvent.floci.services.configservice.model.ConformancePackStatusDetail; +import io.github.hectorvent.floci.services.configservice.model.DeliveryChannel; +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.ws.rs.core.Response; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +@ApplicationScoped +public class ConfigServiceJsonHandler { + + private final AwsConfigService service; + private final ObjectMapper mapper; + + @Inject + public ConfigServiceJsonHandler(AwsConfigService service, ObjectMapper mapper) { + this.service = service; + this.mapper = mapper; + } + + public Response handle(String action, JsonNode request, String region) throws Exception { + return switch (action) { + case "PutConfigRule" -> putConfigRule(request, region); + case "DeleteConfigRule" -> deleteConfigRule(request, region); + case "DescribeConfigRules" -> describeConfigRules(request, region); + case "DescribeComplianceByConfigRule" -> describeComplianceByConfigRule(request, region); + case "DescribeConfigRuleEvaluationStatus" -> describeConfigRuleEvaluationStatus(request, region); + case "StartConfigRulesEvaluation" -> startConfigRulesEvaluation(request, region); + case "PutConformancePack" -> putConformancePack(request, region); + case "DeleteConformancePack" -> deleteConformancePack(request, region); + case "DescribeConformancePacks" -> describeConformancePacks(request, region); + case "DescribeConformancePackStatus" -> describeConformancePackStatus(request, region); + case "PutConfigurationRecorder" -> putConfigurationRecorder(request, region); + case "DescribeConfigurationRecorders" -> describeConfigurationRecorders(request, region); + case "StartConfigurationRecorder" -> startConfigurationRecorder(request, region); + case "StopConfigurationRecorder" -> stopConfigurationRecorder(request, region); + case "DescribeConfigurationRecorderStatus" -> describeConfigurationRecorderStatus(request, region); + case "PutDeliveryChannel" -> putDeliveryChannel(request, region); + case "DescribeDeliveryChannels" -> describeDeliveryChannels(request, region); + case "TagResource" -> tagResource(request); + case "UntagResource" -> untagResource(request); + case "ListTagsForResource" -> listTagsForResource(request); + default -> throw new io.github.hectorvent.floci.core.common.AwsException( + "InvalidAction", "Could not find operation " + action, 400); + }; + } + + // --- Config Rules --- + + private Response putConfigRule(JsonNode req, String region) { + JsonNode ruleNode = req.path("ConfigRule"); + String ruleName = ruleNode.path("ConfigRuleName").asText(null); + JsonNode sourceNode = ruleNode.path("Source"); + ConfigRuleSource source = new ConfigRuleSource( + sourceNode.path("Owner").asText(null), + sourceNode.path("SourceIdentifier").asText(null)); + service.putConfigRule(region, ruleName, source); + return Response.ok(mapper.createObjectNode()).build(); + } + + private Response deleteConfigRule(JsonNode req, String region) { + String ruleName = req.path("ConfigRuleName").asText(null); + service.deleteConfigRule(region, ruleName); + return Response.ok(mapper.createObjectNode()).build(); + } + + private Response describeConfigRules(JsonNode req, String region) { + List ruleNames = extractStringList(req, "ConfigRuleNames"); + List rules = service.describeConfigRules(region, ruleNames); + ObjectNode resp = mapper.createObjectNode(); + resp.set("ConfigRules", mapper.valueToTree(rules)); + return Response.ok(resp).build(); + } + + private Response describeComplianceByConfigRule(JsonNode req, String region) { + List ruleNames = extractStringList(req, "ConfigRuleNames"); + List rules = service.describeConfigRules(region, ruleNames); + ObjectNode resp = mapper.createObjectNode(); + ArrayNode arr = resp.putArray("ComplianceByConfigRules"); + for (ConfigRule rule : rules) { + ObjectNode entry = mapper.createObjectNode(); + entry.put("ConfigRuleName", rule.configRuleName()); + ObjectNode compliance = mapper.createObjectNode(); + compliance.put("ComplianceType", "INSUFFICIENT_DATA"); + entry.set("Compliance", compliance); + arr.add(entry); + } + return Response.ok(resp).build(); + } + + private Response describeConfigRuleEvaluationStatus(JsonNode req, String region) { + List ruleNames = extractStringList(req, "ConfigRuleNames"); + List statuses = service.describeConfigRuleEvaluationStatus(region, ruleNames); + ObjectNode resp = mapper.createObjectNode(); + resp.set("ConfigRulesEvaluationStatus", mapper.valueToTree(statuses)); + return Response.ok(resp).build(); + } + + private Response startConfigRulesEvaluation(JsonNode req, String region) { + List ruleNames = extractStringList(req, "ConfigRuleNames"); + service.startConfigRulesEvaluation(region, ruleNames); + return Response.ok(mapper.createObjectNode()).build(); + } + + // --- Configuration Recorder --- + + private Response putConfigurationRecorder(JsonNode req, String region) throws Exception { + ConfigurationRecorder recorder = mapper.treeToValue(req.path("ConfigurationRecorder"), ConfigurationRecorder.class); + service.putConfigurationRecorder(region, recorder); + return Response.ok(mapper.createObjectNode()).build(); + } + + private Response describeConfigurationRecorders(JsonNode req, String region) { + List names = extractStringList(req, "ConfigurationRecorderNames"); + List recorders = service.describeConfigurationRecorders(region, names); + ObjectNode resp = mapper.createObjectNode(); + resp.set("ConfigurationRecorders", mapper.valueToTree(recorders)); + return Response.ok(resp).build(); + } + + private Response startConfigurationRecorder(JsonNode req, String region) { + String name = req.path("ConfigurationRecorderName").asText(null); + service.startConfigurationRecorder(region, name); + return Response.ok(mapper.createObjectNode()).build(); + } + + private Response stopConfigurationRecorder(JsonNode req, String region) { + String name = req.path("ConfigurationRecorderName").asText(null); + service.stopConfigurationRecorder(region, name); + return Response.ok(mapper.createObjectNode()).build(); + } + + private Response describeConfigurationRecorderStatus(JsonNode req, String region) { + List names = extractStringList(req, "ConfigurationRecorderNames"); + List statuses = service.describeConfigurationRecorderStatus(region, names); + ObjectNode resp = mapper.createObjectNode(); + resp.set("ConfigurationRecordersStatus", mapper.valueToTree(statuses)); + return Response.ok(resp).build(); + } + + // --- Delivery Channel --- + + private Response putDeliveryChannel(JsonNode req, String region) throws Exception { + DeliveryChannel channel = mapper.treeToValue(req.path("DeliveryChannel"), DeliveryChannel.class); + service.putDeliveryChannel(region, channel); + return Response.ok(mapper.createObjectNode()).build(); + } + + private Response describeDeliveryChannels(JsonNode req, String region) { + List names = extractStringList(req, "DeliveryChannelNames"); + List channels = service.describeDeliveryChannels(region, names); + ObjectNode resp = mapper.createObjectNode(); + resp.set("DeliveryChannels", mapper.valueToTree(channels)); + return Response.ok(resp).build(); + } + + // --- Conformance Packs --- + + private Response putConformancePack(JsonNode req, String region) { + String packName = req.path("ConformancePackName").asText(null); + String templateS3Uri = req.has("TemplateS3Uri") ? req.path("TemplateS3Uri").asText(null) : null; + String templateBody = req.has("TemplateBody") ? req.path("TemplateBody").asText(null) : null; + ConformancePack pack = service.putConformancePack(region, packName, templateS3Uri, templateBody); + ObjectNode resp = mapper.createObjectNode(); + resp.put("ConformancePackArn", pack.conformancePackArn()); + return Response.ok(resp).build(); + } + + private Response deleteConformancePack(JsonNode req, String region) { + String packName = req.path("ConformancePackName").asText(null); + service.deleteConformancePack(region, packName); + return Response.ok(mapper.createObjectNode()).build(); + } + + private Response describeConformancePacks(JsonNode req, String region) { + List names = extractStringList(req, "ConformancePackNames"); + List packs = service.describeConformancePacks(region, names); + ObjectNode resp = mapper.createObjectNode(); + resp.set("ConformancePackDetails", mapper.valueToTree(packs)); + return Response.ok(resp).build(); + } + + private Response describeConformancePackStatus(JsonNode req, String region) { + List names = extractStringList(req, "ConformancePackNames"); + List statuses = service.describeConformancePackStatus(region, names); + ObjectNode resp = mapper.createObjectNode(); + resp.set("ConformancePackStatusDetails", mapper.valueToTree(statuses)); + return Response.ok(resp).build(); + } + + // --- Tagging --- + + private Response tagResource(JsonNode req) { + String arn = req.path("ResourceArn").asText(null); + List> tagList = new ArrayList<>(); + req.path("Tags").forEach(t -> tagList.add(Map.of( + "Key", t.path("Key").asText(), + "Value", t.path("Value").asText()))); + service.tagResource(arn, tagList); + return Response.ok(mapper.createObjectNode()).build(); + } + + private Response untagResource(JsonNode req) { + String arn = req.path("ResourceArn").asText(null); + List tagKeys = new ArrayList<>(); + req.path("TagKeys").forEach(k -> tagKeys.add(k.asText())); + service.untagResource(arn, tagKeys); + return Response.ok(mapper.createObjectNode()).build(); + } + + private Response listTagsForResource(JsonNode req) { + String arn = req.path("ResourceArn").asText(null); + List> tagList = service.listTagsForResource(arn); + ObjectNode resp = mapper.createObjectNode(); + resp.set("Tags", mapper.valueToTree(tagList)); + return Response.ok(resp).build(); + } + + // --- Helpers --- + + private List extractStringList(JsonNode req, String fieldName) { + List result = new ArrayList<>(); + if (req.has(fieldName)) { + req.path(fieldName).forEach(n -> result.add(n.asText())); + } + return result; + } +} diff --git a/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigRule.java b/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigRule.java new file mode 100644 index 0000000000..4e8f6ee649 --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigRule.java @@ -0,0 +1,17 @@ +package io.github.hectorvent.floci.services.configservice.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record ConfigRule( + @JsonProperty("ConfigRuleName") String configRuleName, + @JsonProperty("ConfigRuleArn") String configRuleArn, + @JsonProperty("ConfigRuleId") String configRuleId, + @JsonProperty("ConfigRuleState") String configRuleState, + @JsonProperty("Source") ConfigRuleSource source) { +} diff --git a/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigRuleEvaluationStatus.java b/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigRuleEvaluationStatus.java new file mode 100644 index 0000000000..6c2ca599f4 --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigRuleEvaluationStatus.java @@ -0,0 +1,16 @@ +package io.github.hectorvent.floci.services.configservice.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record ConfigRuleEvaluationStatus( + @JsonProperty("ConfigRuleName") String configRuleName, + @JsonProperty("ConfigRuleArn") String configRuleArn, + @JsonProperty("ConfigRuleId") String configRuleId, + @JsonProperty("FirstEvaluationStarted") Boolean firstEvaluationStarted) { +} diff --git a/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigRuleSource.java b/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigRuleSource.java new file mode 100644 index 0000000000..52586c8ae4 --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigRuleSource.java @@ -0,0 +1,14 @@ +package io.github.hectorvent.floci.services.configservice.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record ConfigRuleSource( + @JsonProperty("Owner") String owner, + @JsonProperty("SourceIdentifier") String sourceIdentifier) { +} diff --git a/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigSnapshotDeliveryProperties.java b/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigSnapshotDeliveryProperties.java new file mode 100644 index 0000000000..962a3809fa --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigSnapshotDeliveryProperties.java @@ -0,0 +1,13 @@ +package io.github.hectorvent.floci.services.configservice.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record ConfigSnapshotDeliveryProperties( + @JsonProperty("deliveryFrequency") String deliveryFrequency) { +} diff --git a/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigurationRecorder.java b/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigurationRecorder.java new file mode 100644 index 0000000000..c66f5b3584 --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigurationRecorder.java @@ -0,0 +1,15 @@ +package io.github.hectorvent.floci.services.configservice.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record ConfigurationRecorder( + @JsonProperty("name") String name, + @JsonProperty("roleARN") String roleARN, + @JsonProperty("recordingGroup") RecordingGroup recordingGroup) { +} diff --git a/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigurationRecorderStatus.java b/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigurationRecorderStatus.java new file mode 100644 index 0000000000..02a7424a86 --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConfigurationRecorderStatus.java @@ -0,0 +1,17 @@ +package io.github.hectorvent.floci.services.configservice.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record ConfigurationRecorderStatus( + @JsonProperty("name") String name, + @JsonProperty("recording") Boolean recording, + @JsonProperty("lastStatus") String lastStatus, + @JsonProperty("lastStartTime") Long lastStartTime, + @JsonProperty("lastStopTime") Long lastStopTime) { +} diff --git a/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConformancePack.java b/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConformancePack.java new file mode 100644 index 0000000000..487a26827b --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConformancePack.java @@ -0,0 +1,17 @@ +package io.github.hectorvent.floci.services.configservice.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record ConformancePack( + @JsonProperty("ConformancePackName") String conformancePackName, + @JsonProperty("ConformancePackArn") String conformancePackArn, + @JsonProperty("ConformancePackId") String conformancePackId, + @JsonProperty("TemplateS3Uri") String templateS3Uri, + @JsonProperty("TemplateBody") String templateBody) { +} diff --git a/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConformancePackStatusDetail.java b/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConformancePackStatusDetail.java new file mode 100644 index 0000000000..a984665e13 --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/configservice/model/ConformancePackStatusDetail.java @@ -0,0 +1,17 @@ +package io.github.hectorvent.floci.services.configservice.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record ConformancePackStatusDetail( + @JsonProperty("ConformancePackName") String conformancePackName, + @JsonProperty("ConformancePackId") String conformancePackId, + @JsonProperty("ConformancePackArn") String conformancePackArn, + @JsonProperty("ConformancePackState") String conformancePackState, + @JsonProperty("LastUpdateRequestedTime") Long lastUpdateRequestedTime) { +} diff --git a/src/main/java/io/github/hectorvent/floci/services/configservice/model/DeliveryChannel.java b/src/main/java/io/github/hectorvent/floci/services/configservice/model/DeliveryChannel.java new file mode 100644 index 0000000000..e7262f7b49 --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/configservice/model/DeliveryChannel.java @@ -0,0 +1,18 @@ +package io.github.hectorvent.floci.services.configservice.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.quarkus.runtime.annotations.RegisterForReflection; + +@RegisterForReflection +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record DeliveryChannel( + @JsonProperty("name") String name, + @JsonProperty("s3BucketName") String s3BucketName, + @JsonProperty("s3KeyPrefix") String s3KeyPrefix, + @JsonProperty("s3KmsKeyArn") String s3KmsKeyArn, + @JsonProperty("snsTopicARN") String snsTopicARN, + @JsonProperty("configSnapshotDeliveryProperties") ConfigSnapshotDeliveryProperties configSnapshotDeliveryProperties) { +} diff --git a/src/main/java/io/github/hectorvent/floci/services/configservice/model/RecordingGroup.java b/src/main/java/io/github/hectorvent/floci/services/configservice/model/RecordingGroup.java new file mode 100644 index 0000000000..f4e46f2005 --- /dev/null +++ b/src/main/java/io/github/hectorvent/floci/services/configservice/model/RecordingGroup.java @@ -0,0 +1,17 @@ +package io.github.hectorvent.floci.services.configservice.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import io.quarkus.runtime.annotations.RegisterForReflection; + +import java.util.List; + +@RegisterForReflection +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonIgnoreProperties(ignoreUnknown = true) +public record RecordingGroup( + @JsonProperty("allSupported") Boolean allSupported, + @JsonProperty("includeGlobalResourceTypes") Boolean includeGlobalResourceTypes, + @JsonProperty("resourceTypes") List resourceTypes) { +} diff --git a/src/test/java/io/github/hectorvent/floci/services/configservice/ConfigRuleIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/configservice/ConfigRuleIntegrationTest.java new file mode 100644 index 0000000000..36e921742d --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/configservice/ConfigRuleIntegrationTest.java @@ -0,0 +1,215 @@ +package io.github.hectorvent.floci.services.configservice; + +import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.BeforeAll; +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.*; + +@QuarkusTest +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +class ConfigRuleIntegrationTest { + + private static final String CONTENT_TYPE = "application/x-amz-json-1.1"; + private static final String TARGET_PREFIX = "StarlingDoveService."; + + @BeforeAll + static void configureRestAssured() { + RestAssuredJsonUtils.configureAwsContentTypes(); + } + + @Test + @Order(1) + void putConfigRule() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "PutConfigRule") + .contentType(CONTENT_TYPE) + .body(""" + { + "ConfigRule": { + "ConfigRuleName": "rule-crud-test", + "Source": { + "Owner": "AWS", + "SourceIdentifier": "S3_ACCESS_POINT_PUBLIC_ACCESS_BLOCKS" + } + } + } + """) + .when() + .post("/") + .then() + .statusCode(200); + } + + @Test + @Order(2) + void describeConfigRules() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "DescribeConfigRules") + .contentType(CONTENT_TYPE) + .body(""" + {"ConfigRuleNames": ["rule-crud-test"]} + """) + .when() + .post("/") + .then() + .statusCode(200) + .body("ConfigRules", hasSize(1)) + .body("ConfigRules[0].ConfigRuleName", equalTo("rule-crud-test")) + .body("ConfigRules[0].ConfigRuleArn", notNullValue()) + .body("ConfigRules[0].ConfigRuleId", notNullValue()) + .body("ConfigRules[0].ConfigRuleState", equalTo("ACTIVE")) + .body("ConfigRules[0].Source.Owner", equalTo("AWS")) + .body("ConfigRules[0].Source.SourceIdentifier", equalTo("S3_ACCESS_POINT_PUBLIC_ACCESS_BLOCKS")); + + given() + .header("X-Amz-Target", TARGET_PREFIX + "DescribeConfigRules") + .contentType(CONTENT_TYPE) + .body("{}") + .when() + .post("/") + .then() + .statusCode(200) + .body("ConfigRules", hasSize(greaterThanOrEqualTo(1))); + } + + @Test + @Order(3) + void describeComplianceByConfigRule() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "DescribeComplianceByConfigRule") + .contentType(CONTENT_TYPE) + .body(""" + {"ConfigRuleNames": ["rule-crud-test"]} + """) + .when() + .post("/") + .then() + .statusCode(200) + .body("ComplianceByConfigRules", hasSize(1)) + .body("ComplianceByConfigRules[0].ConfigRuleName", equalTo("rule-crud-test")) + .body("ComplianceByConfigRules[0].Compliance.ComplianceType", equalTo("INSUFFICIENT_DATA")); + } + + @Test + @Order(4) + void putConfigRuleUpdate() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "PutConfigRule") + .contentType(CONTENT_TYPE) + .body(""" + { + "ConfigRule": { + "ConfigRuleName": "rule-crud-test", + "Source": { + "Owner": "CUSTOM_LAMBDA", + "SourceIdentifier": "arn:aws:lambda:us-east-1:123456789012:function:my-rule" + } + } + } + """) + .when() + .post("/") + .then() + .statusCode(200); + + given() + .header("X-Amz-Target", TARGET_PREFIX + "DescribeConfigRules") + .contentType(CONTENT_TYPE) + .body(""" + {"ConfigRuleNames": ["rule-crud-test"]} + """) + .when() + .post("/") + .then() + .statusCode(200) + .body("ConfigRules[0].Source.Owner", equalTo("CUSTOM_LAMBDA")); + } + + @Test + @Order(5) + void describeConfigRuleEvaluationStatus() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "DescribeConfigRuleEvaluationStatus") + .contentType(CONTENT_TYPE) + .body(""" + {"ConfigRuleNames": ["rule-crud-test"]} + """) + .when() + .post("/") + .then() + .statusCode(200) + .body("ConfigRulesEvaluationStatus", hasSize(1)) + .body("ConfigRulesEvaluationStatus[0].ConfigRuleName", equalTo("rule-crud-test")) + .body("ConfigRulesEvaluationStatus[0].ConfigRuleArn", notNullValue()) + .body("ConfigRulesEvaluationStatus[0].ConfigRuleId", notNullValue()) + .body("ConfigRulesEvaluationStatus[0].FirstEvaluationStarted", equalTo(true)); + } + + @Test + @Order(6) + void startConfigRulesEvaluation() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "StartConfigRulesEvaluation") + .contentType(CONTENT_TYPE) + .body(""" + {"ConfigRuleNames": ["rule-crud-test"]} + """) + .when() + .post("/") + .then() + .statusCode(200); + } + + @Test + @Order(7) + void startConfigRulesEvaluationNonexistent() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "StartConfigRulesEvaluation") + .contentType(CONTENT_TYPE) + .body(""" + {"ConfigRuleNames": ["no-such-rule"]} + """) + .when() + .post("/") + .then() + .statusCode(400) + .body("__type", equalTo("NoSuchConfigRuleException")); + } + + @Test + @Order(8) + void deleteConfigRule() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "DeleteConfigRule") + .contentType(CONTENT_TYPE) + .body(""" + {"ConfigRuleName": "rule-crud-test"} + """) + .when() + .post("/") + .then() + .statusCode(200); + } + + @Test + @Order(9) + void deleteNonexistentConfigRule() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "DeleteConfigRule") + .contentType(CONTENT_TYPE) + .body(""" + {"ConfigRuleName": "no-such-rule"} + """) + .when() + .post("/") + .then() + .statusCode(400) + .body("__type", equalTo("NoSuchConfigRuleException")); + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/configservice/ConfigTaggingIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/configservice/ConfigTaggingIntegrationTest.java new file mode 100644 index 0000000000..47cf4ae5b8 --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/configservice/ConfigTaggingIntegrationTest.java @@ -0,0 +1,163 @@ +package io.github.hectorvent.floci.services.configservice; + +import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.BeforeAll; +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.*; + +@QuarkusTest +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +class ConfigTaggingIntegrationTest { + + private static final String CONTENT_TYPE = "application/x-amz-json-1.1"; + private static final String TARGET_PREFIX = "StarlingDoveService."; + + @BeforeAll + static void configureRestAssured() { + RestAssuredJsonUtils.configureAwsContentTypes(); + } + + @Test + @Order(1) + void putConfigRuleForTagging() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "PutConfigRule") + .contentType(CONTENT_TYPE) + .body(""" + { + "ConfigRule": { + "ConfigRuleName": "tag-test-rule", + "Source": { + "Owner": "AWS", + "SourceIdentifier": "S3_BUCKET_VERSIONING_ENABLED" + } + } + } + """) + .when() + .post("/") + .then() + .statusCode(200); + } + + @Test + @Order(2) + void tagResource() { + String arn = getConfigRuleArn("tag-test-rule"); + given() + .header("X-Amz-Target", TARGET_PREFIX + "TagResource") + .contentType(CONTENT_TYPE) + .body(""" + { + "ResourceArn": "%s", + "Tags": [ + {"Key": "Environment", "Value": "test"}, + {"Key": "Team", "Value": "platform"} + ] + } + """.formatted(arn)) + .when() + .post("/") + .then() + .statusCode(200); + } + + @Test + @Order(3) + void tagResourceAddTag() { + String arn = getConfigRuleArn("tag-test-rule"); + given() + .header("X-Amz-Target", TARGET_PREFIX + "TagResource") + .contentType(CONTENT_TYPE) + .body(""" + { + "ResourceArn": "%s", + "Tags": [{"Key": "CostCenter", "Value": "12345"}] + } + """.formatted(arn)) + .when() + .post("/") + .then() + .statusCode(200); + + given() + .header("X-Amz-Target", TARGET_PREFIX + "ListTagsForResource") + .contentType(CONTENT_TYPE) + .body(""" + {"ResourceArn": "%s"} + """.formatted(arn)) + .when() + .post("/") + .then() + .statusCode(200) + .body("Tags", hasSize(3)); + } + + @Test + @Order(4) + void untagResource() { + String arn = getConfigRuleArn("tag-test-rule"); + given() + .header("X-Amz-Target", TARGET_PREFIX + "UntagResource") + .contentType(CONTENT_TYPE) + .body(""" + { + "ResourceArn": "%s", + "TagKeys": ["CostCenter"] + } + """.formatted(arn)) + .when() + .post("/") + .then() + .statusCode(200); + + given() + .header("X-Amz-Target", TARGET_PREFIX + "ListTagsForResource") + .contentType(CONTENT_TYPE) + .body(""" + {"ResourceArn": "%s"} + """.formatted(arn)) + .when() + .post("/") + .then() + .statusCode(200) + .body("Tags", hasSize(2)); + } + + @Test + @Order(5) + void listTagsForResourceNoTags() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "ListTagsForResource") + .contentType(CONTENT_TYPE) + .body(""" + {"ResourceArn": "arn:aws:config:us-east-1:123456789012:config-rule/nonexistent"} + """) + .when() + .post("/") + .then() + .statusCode(200) + .body("Tags", hasSize(0)); + } + + private String getConfigRuleArn(String ruleName) { + return given() + .header("X-Amz-Target", TARGET_PREFIX + "DescribeConfigRules") + .contentType(CONTENT_TYPE) + .body(""" + {"ConfigRuleNames": ["%s"]} + """.formatted(ruleName)) + .when() + .post("/") + .then() + .statusCode(200) + .extract() + .path("ConfigRules[0].ConfigRuleArn"); + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/configservice/ConfigurationRecorderIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/configservice/ConfigurationRecorderIntegrationTest.java new file mode 100644 index 0000000000..dba4a923d8 --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/configservice/ConfigurationRecorderIntegrationTest.java @@ -0,0 +1,219 @@ +package io.github.hectorvent.floci.services.configservice; + +import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.BeforeAll; +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.*; + +@QuarkusTest +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +class ConfigurationRecorderIntegrationTest { + + private static final String CONTENT_TYPE = "application/x-amz-json-1.1"; + private static final String TARGET_PREFIX = "StarlingDoveService."; + + @BeforeAll + static void configureRestAssured() { + RestAssuredJsonUtils.configureAwsContentTypes(); + } + + // --- Configuration Recorder --- + + @Test + @Order(1) + void putConfigurationRecorder() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "PutConfigurationRecorder") + .contentType(CONTENT_TYPE) + .body(""" + { + "ConfigurationRecorder": { + "name": "default", + "roleARN": "arn:aws:iam::123456789012:role/config-role", + "recordingGroup": { + "allSupported": true, + "includeGlobalResourceTypes": false + } + } + } + """) + .when() + .post("/") + .then() + .statusCode(200); + } + + @Test + @Order(2) + void describeConfigurationRecorders() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "DescribeConfigurationRecorders") + .contentType(CONTENT_TYPE) + .body(""" + {"ConfigurationRecorderNames": ["default"]} + """) + .when() + .post("/") + .then() + .statusCode(200) + .body("ConfigurationRecorders", hasSize(1)) + .body("ConfigurationRecorders[0].name", equalTo("default")) + .body("ConfigurationRecorders[0].roleARN", equalTo("arn:aws:iam::123456789012:role/config-role")) + .body("ConfigurationRecorders[0].recordingGroup.allSupported", equalTo(true)); + + given() + .header("X-Amz-Target", TARGET_PREFIX + "DescribeConfigurationRecorders") + .contentType(CONTENT_TYPE) + .body("{}") + .when() + .post("/") + .then() + .statusCode(200) + .body("ConfigurationRecorders", hasSize(1)); + } + + @Test + @Order(3) + void startConfigurationRecorder() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "StartConfigurationRecorder") + .contentType(CONTENT_TYPE) + .body(""" + {"ConfigurationRecorderName": "default"} + """) + .when() + .post("/") + .then() + .statusCode(200); + } + + @Test + @Order(4) + void describeConfigurationRecorderStatusAfterStart() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "DescribeConfigurationRecorderStatus") + .contentType(CONTENT_TYPE) + .body(""" + {"ConfigurationRecorderNames": ["default"]} + """) + .when() + .post("/") + .then() + .statusCode(200) + .body("ConfigurationRecordersStatus", hasSize(1)) + .body("ConfigurationRecordersStatus[0].name", equalTo("default")) + .body("ConfigurationRecordersStatus[0].recording", equalTo(true)) + .body("ConfigurationRecordersStatus[0].lastStatus", equalTo("SUCCESS")) + .body("ConfigurationRecordersStatus[0].lastStartTime", notNullValue()); + } + + @Test + @Order(5) + void stopConfigurationRecorder() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "StopConfigurationRecorder") + .contentType(CONTENT_TYPE) + .body(""" + {"ConfigurationRecorderName": "default"} + """) + .when() + .post("/") + .then() + .statusCode(200); + } + + @Test + @Order(6) + void describeConfigurationRecorderStatusAfterStop() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "DescribeConfigurationRecorderStatus") + .contentType(CONTENT_TYPE) + .body(""" + {"ConfigurationRecorderNames": ["default"]} + """) + .when() + .post("/") + .then() + .statusCode(200) + .body("ConfigurationRecordersStatus[0].recording", equalTo(false)) + .body("ConfigurationRecordersStatus[0].lastStopTime", notNullValue()); + } + + @Test + @Order(7) + void startNonexistentConfigurationRecorder() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "StartConfigurationRecorder") + .contentType(CONTENT_TYPE) + .body(""" + {"ConfigurationRecorderName": "no-such-recorder"} + """) + .when() + .post("/") + .then() + .statusCode(400) + .body("__type", equalTo("NoSuchConfigurationRecorderException")); + } + + // --- Delivery Channel --- + + @Test + @Order(8) + void putDeliveryChannel() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "PutDeliveryChannel") + .contentType(CONTENT_TYPE) + .body(""" + { + "DeliveryChannel": { + "name": "default", + "s3BucketName": "my-config-bucket", + "s3KeyPrefix": "config-snapshots", + "configSnapshotDeliveryProperties": { + "deliveryFrequency": "Twelve_Hours" + } + } + } + """) + .when() + .post("/") + .then() + .statusCode(200); + } + + @Test + @Order(9) + void describeDeliveryChannels() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "DescribeDeliveryChannels") + .contentType(CONTENT_TYPE) + .body(""" + {"DeliveryChannelNames": ["default"]} + """) + .when() + .post("/") + .then() + .statusCode(200) + .body("DeliveryChannels", hasSize(1)) + .body("DeliveryChannels[0].name", equalTo("default")) + .body("DeliveryChannels[0].s3BucketName", equalTo("my-config-bucket")) + .body("DeliveryChannels[0].s3KeyPrefix", equalTo("config-snapshots")) + .body("DeliveryChannels[0].configSnapshotDeliveryProperties.deliveryFrequency", equalTo("Twelve_Hours")); + + given() + .header("X-Amz-Target", TARGET_PREFIX + "DescribeDeliveryChannels") + .contentType(CONTENT_TYPE) + .body("{}") + .when() + .post("/") + .then() + .statusCode(200) + .body("DeliveryChannels", hasSize(1)); + } +} diff --git a/src/test/java/io/github/hectorvent/floci/services/configservice/ConformancePackIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/configservice/ConformancePackIntegrationTest.java new file mode 100644 index 0000000000..213c77abf9 --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/configservice/ConformancePackIntegrationTest.java @@ -0,0 +1,129 @@ +package io.github.hectorvent.floci.services.configservice; + +import io.github.hectorvent.floci.testing.RestAssuredJsonUtils; +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.BeforeAll; +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.*; + +@QuarkusTest +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +class ConformancePackIntegrationTest { + + private static final String CONTENT_TYPE = "application/x-amz-json-1.1"; + private static final String TARGET_PREFIX = "StarlingDoveService."; + + @BeforeAll + static void configureRestAssured() { + RestAssuredJsonUtils.configureAwsContentTypes(); + } + + @Test + @Order(1) + void putConformancePack() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "PutConformancePack") + .contentType(CONTENT_TYPE) + .body(""" + { + "ConformancePackName": "pack-crud-test", + "TemplateS3Uri": "s3://my-bucket/template.yaml" + } + """) + .when() + .post("/") + .then() + .statusCode(200) + .body("ConformancePackArn", notNullValue()); + } + + @Test + @Order(2) + void describeConformancePacks() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "DescribeConformancePacks") + .contentType(CONTENT_TYPE) + .body(""" + {"ConformancePackNames": ["pack-crud-test"]} + """) + .when() + .post("/") + .then() + .statusCode(200) + .body("ConformancePackDetails", hasSize(1)) + .body("ConformancePackDetails[0].ConformancePackName", equalTo("pack-crud-test")) + .body("ConformancePackDetails[0].ConformancePackArn", notNullValue()) + .body("ConformancePackDetails[0].ConformancePackId", notNullValue()); + } + + @Test + @Order(3) + void describeConformancePackStatus() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "DescribeConformancePackStatus") + .contentType(CONTENT_TYPE) + .body(""" + {"ConformancePackNames": ["pack-crud-test"]} + """) + .when() + .post("/") + .then() + .statusCode(200) + .body("ConformancePackStatusDetails", hasSize(1)) + .body("ConformancePackStatusDetails[0].ConformancePackName", equalTo("pack-crud-test")) + .body("ConformancePackStatusDetails[0].ConformancePackState", equalTo("CREATE_SUCCESSFUL")) + .body("ConformancePackStatusDetails[0].LastUpdateRequestedTime", notNullValue()); + } + + @Test + @Order(4) + void deleteConformancePack() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "DeleteConformancePack") + .contentType(CONTENT_TYPE) + .body(""" + {"ConformancePackName": "pack-crud-test"} + """) + .when() + .post("/") + .then() + .statusCode(200); + } + + @Test + @Order(5) + void deleteNonexistentConformancePack() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "DeleteConformancePack") + .contentType(CONTENT_TYPE) + .body(""" + {"ConformancePackName": "no-such-pack"} + """) + .when() + .post("/") + .then() + .statusCode(400) + .body("__type", equalTo("NoSuchConformancePackException")); + } + + @Test + @Order(6) + void describeConformancePacksNonexistent() { + given() + .header("X-Amz-Target", TARGET_PREFIX + "DescribeConformancePacks") + .contentType(CONTENT_TYPE) + .body(""" + {"ConformancePackNames": ["no-such-pack"]} + """) + .when() + .post("/") + .then() + .statusCode(400) + .body("__type", equalTo("NoSuchConformancePackException")); + } +}