diff --git a/README.md b/README.md
index 41085886ea..295b76e725 100644
--- a/README.md
+++ b/README.md
@@ -238,7 +238,7 @@ Floci supports local emulation for application services, data services, eventing
| Data, analytics, and AI | Athena, Glue, Lake Formation, EMR, EMR Serverless, Redshift, Redshift Data API, Firehose, Managed Service for Apache Flink, OpenSearch, S3 Tables, S3 Vectors, Textract, Transcribe, Comprehend, Rekognition, Translate, Bedrock Runtime, Bedrock AgentCore |
| Databases and caching | RDS, RDS Data API, Neptune, DocumentDB, MemoryDB, ElastiCache |
| Messaging and transfer | SES, Kinesis, MSK, Amazon MQ, Transfer Family, IoT Core, Amazon Connect |
-| Security and governance | AWS Network Firewall, AWS RAM, Service Quotas, WAF v2, GuardDuty, CloudTrail, CloudFront, Resource Groups Tagging API, Resource Explorer 2, CloudHSM v2, Organizations, AWS Account Management, IAM Access Analyzer, IAM Identity Center (SSO Admin), Identity Store, Amazon Macie, Amazon Detective, Control Catalog, Control Tower, Service Catalog |
+| Security and governance | AWS Network Firewall, AWS RAM, Service Quotas, WAF v2, GuardDuty, Amazon Inspector, CloudTrail, CloudFront, Resource Groups Tagging API, Resource Explorer 2, CloudHSM v2, Organizations, AWS Account Management, IAM Access Analyzer, IAM Identity Center (SSO Admin), Identity Store, Amazon Macie, Amazon Detective, Control Catalog, Control Tower, Service Catalog |
| Cost and billing | AWS Budgets, Pricing, Cost Explorer, Cost and Usage Reports, BCM Data Exports |
| Resilience, backup, and config | AWS FIS, AWS Backup, AWS Config, AppConfig, AppConfigData, CloudFormation, Cloud Control API |
diff --git a/compatibility-tests/sdk-test-java/pom.xml b/compatibility-tests/sdk-test-java/pom.xml
index dc66b024f0..cbce717077 100644
--- a/compatibility-tests/sdk-test-java/pom.xml
+++ b/compatibility-tests/sdk-test-java/pom.xml
@@ -262,6 +262,11 @@
software.amazon.awssdk
detective
+
+
+ software.amazon.awssdk
+ inspector2
+
software.amazon.awssdk
diff --git a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
index cf8d32aea5..5ffaa84e0c 100644
--- a/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
+++ b/compatibility-tests/sdk-test-java/src/main/java/com/floci/test/TestFixtures.java
@@ -38,6 +38,7 @@ import software.amazon.awssdk.services.identitystore.IdentitystoreClient;
import software.amazon.awssdk.services.budgets.BudgetsClient;
import software.amazon.awssdk.services.macie2.Macie2Client;
import software.amazon.awssdk.services.controlcatalog.ControlCatalogClient;
+import software.amazon.awssdk.services.inspector2.Inspector2Client;
import software.amazon.awssdk.services.detective.DetectiveClient;
import software.amazon.awssdk.services.rum.RumClient;
import software.amazon.awssdk.services.resourceexplorer2.ResourceExplorer2Client;
@@ -364,6 +365,14 @@ public final class TestFixtures {
.build();
}
+ public static Inspector2Client inspector2Client(String accountId) {
+ return Inspector2Client.builder()
+ .endpointOverride(ENDPOINT)
+ .region(REGION)
+ .credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(accountId, "test")))
+ .build();
+ }
+
public static SsmClient ssmClient() {
return SsmClient.builder()
.endpointOverride(ENDPOINT)
diff --git a/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/Inspector2OrganizationConfigurationTest.java b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/Inspector2OrganizationConfigurationTest.java
new file mode 100644
index 0000000000..01f595f9cb
--- /dev/null
+++ b/compatibility-tests/sdk-test-java/src/test/java/com/floci/test/Inspector2OrganizationConfigurationTest.java
@@ -0,0 +1,157 @@
+package com.floci.test;
+
+import org.jboss.logging.Logger;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+import software.amazon.awssdk.services.inspector2.Inspector2Client;
+import software.amazon.awssdk.services.inspector2.model.AutoEnable;
+import software.amazon.awssdk.services.inspector2.model.ResourceScanType;
+import software.amazon.awssdk.services.organizations.OrganizationsClient;
+import software.amazon.awssdk.services.organizations.model.AlreadyInOrganizationException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.jupiter.api.Assumptions.assumeFalse;
+
+@DisplayName("Amazon Inspector organization configuration")
+class Inspector2OrganizationConfigurationTest {
+ private static final Logger LOG = Logger.getLogger(Inspector2OrganizationConfigurationTest.class);
+ private static final String MANAGEMENT_ACCOUNT = "test";
+
+ @Test
+ void organizationConfigurationUsesAwsSdk() {
+ assumeFalse(TestFixtures.isRealAws(), "Avoids changing Amazon Inspector organization settings in real AWS");
+
+ try (OrganizationsClient organizations = TestFixtures.organizationsClient()) {
+ boolean createdOrganization = ensureOrganization(organizations);
+ String adminAccount = null;
+ String memberAccount = null;
+ boolean delegatedAdminEnabled = false;
+
+ try {
+ adminAccount = createMemberAccount(organizations, "inspector-admin");
+ memberAccount = createMemberAccount(organizations, "inspector-member");
+ String delegatedAdminAccount = adminAccount;
+ String inspectedMemberAccount = memberAccount;
+
+ try (Inspector2Client management = TestFixtures.inspector2Client(MANAGEMENT_ACCOUNT);
+ Inspector2Client administrator = TestFixtures.inspector2Client(delegatedAdminAccount)) {
+ assertThat(management.listDelegatedAdminAccounts(request -> {}).delegatedAdminAccounts()).isEmpty();
+
+ var enabled = management.enableDelegatedAdminAccount(request -> request
+ .delegatedAdminAccountId(delegatedAdminAccount));
+ delegatedAdminEnabled = true;
+ assertThat(enabled.delegatedAdminAccountId()).isEqualTo(delegatedAdminAccount);
+
+ assertThat(management.listDelegatedAdminAccounts(request -> {}).delegatedAdminAccounts())
+ .singleElement()
+ .satisfies(account -> {
+ assertThat(account.accountId()).isEqualTo(delegatedAdminAccount);
+ assertThat(account.statusAsString()).isEqualTo("ENABLED");
+ });
+
+ var enableMember = administrator.enable(request -> request
+ .accountIds(inspectedMemberAccount)
+ .resourceTypes(ResourceScanType.EC2));
+ assertThat(enableMember.accounts()).singleElement().satisfies(account -> {
+ assertThat(account.accountId()).isEqualTo(inspectedMemberAccount);
+ assertThat(account.resourceStatus().ec2AsString()).isEqualTo("ENABLING");
+ assertThat(account.resourceStatus().ecrAsString()).isEqualTo("DISABLED");
+ });
+
+ var firstStatus = administrator.batchGetAccountStatus(
+ request -> request.accountIds(inspectedMemberAccount));
+ assertThat(firstStatus.accounts()).singleElement().satisfies(account -> {
+ assertThat(account.accountId()).isEqualTo(inspectedMemberAccount);
+ assertThat(account.state().statusAsString()).isEqualTo("ENABLING");
+ assertThat(account.resourceState().ec2().statusAsString()).isEqualTo("ENABLING");
+ assertThat(account.resourceState().ecr().statusAsString()).isEqualTo("DISABLED");
+ });
+ var converged = administrator.batchGetAccountStatus(
+ request -> request.accountIds(inspectedMemberAccount));
+ assertThat(converged.accounts()).singleElement().satisfies(account -> {
+ assertThat(account.state().statusAsString()).isEqualTo("ENABLED");
+ assertThat(account.resourceState().ec2().statusAsString()).isEqualTo("ENABLED");
+ assertThat(account.resourceState().ecr().statusAsString()).isEqualTo("DISABLED");
+ });
+
+ var updated = administrator.updateOrganizationConfiguration(request -> request
+ .autoEnable(AutoEnable.builder()
+ .ec2(true)
+ .ecr(true)
+ .lambda(false)
+ .lambdaCode(false)
+ .codeRepository(true)
+ .build()));
+ assertThat(updated.autoEnable().ec2()).isTrue();
+ assertThat(updated.autoEnable().ecr()).isTrue();
+ assertThat(updated.autoEnable().codeRepository()).isTrue();
+
+ var described = administrator.describeOrganizationConfiguration(request -> {});
+ assertThat(described.autoEnable().codeRepository()).isTrue();
+
+ var disabled = management.disableDelegatedAdminAccount(request -> request
+ .delegatedAdminAccountId(delegatedAdminAccount));
+ delegatedAdminEnabled = false;
+ assertThat(disabled.delegatedAdminAccountId()).isEqualTo(delegatedAdminAccount);
+ }
+ } finally {
+ if (delegatedAdminEnabled) {
+ disableDelegatedAdminBestEffort(adminAccount);
+ }
+ removeAccountBestEffort(organizations, memberAccount);
+ removeAccountBestEffort(organizations, adminAccount);
+ if (createdOrganization) {
+ deleteOrganizationBestEffort(organizations);
+ }
+ }
+ }
+ }
+
+ private static boolean ensureOrganization(OrganizationsClient organizations) {
+ try {
+ organizations.createOrganization(request -> request.featureSet("ALL"));
+ return true;
+ } catch (AlreadyInOrganizationException e) {
+ LOG.debugf(e, "Default compatibility account already belongs to an AWS organization");
+ return false;
+ }
+ }
+
+ private static void disableDelegatedAdminBestEffort(String accountId) {
+ if (accountId == null) {
+ return;
+ }
+ try (Inspector2Client management = TestFixtures.inspector2Client(MANAGEMENT_ACCOUNT)) {
+ management.disableDelegatedAdminAccount(request -> request.delegatedAdminAccountId(accountId));
+ } catch (RuntimeException e) {
+ LOG.warnf(e, "Inspector2 compatibility cleanup could not disable delegated administrator %s", accountId);
+ }
+ }
+
+ private static void removeAccountBestEffort(OrganizationsClient organizations, String accountId) {
+ if (accountId == null) {
+ return;
+ }
+ try {
+ organizations.removeAccountFromOrganization(request -> request.accountId(accountId));
+ } catch (RuntimeException e) {
+ LOG.warnf(e, "Inspector2 compatibility cleanup could not remove account %s", accountId);
+ }
+ }
+
+ private static void deleteOrganizationBestEffort(OrganizationsClient organizations) {
+ try {
+ organizations.deleteOrganization();
+ } catch (RuntimeException e) {
+ LOG.warnf(e, "Inspector2 compatibility cleanup could not delete the temporary organization");
+ }
+ }
+
+ private static String createMemberAccount(OrganizationsClient organizations, String prefix) {
+ String suffix = TestFixtures.uniqueName(prefix);
+ var response = organizations.createAccount(request -> request
+ .accountName(suffix)
+ .email(suffix + "@example.com"));
+ return response.createAccountStatus().accountId();
+ }
+}
diff --git a/docs/services/index.md b/docs/services/index.md
index aabaac0d1c..1664fedff0 100644
--- a/docs/services/index.md
+++ b/docs/services/index.md
@@ -49,6 +49,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac
| [IAM Identity Center (SSO Admin)](ssoadmin.md) | `POST /` + `X-Amz-Target: SWBExternalService.*` | JSON 1.1 | 13 |
| [Identity Store](identitystore.md) | `POST /` + `X-Amz-Target: AWSIdentityStore.*` | JSON 1.1 | 19 |
| [Amazon Macie](macie2.md) | `/admin`, `/macie`, `/admin/configuration` | REST JSON | 6 |
+| [Amazon Inspector](inspector2.md) | `/delegatedadminaccounts/*`, `/status/batch/get`, `/enable`, `/organizationconfiguration/*` | REST JSON | 7 |
| [Amazon Detective](detective.md) | `/orgs/*`, `/graphs/list`, `/graph/*` | REST JSON | 8 |
| [Amazon Connect](connect.md) | `/instance`, `/instance/{instanceId}/*`, `/tags/*` | REST JSON | 15 |
| [ElastiCache](elasticache.md) | `POST /` with `Action=` param + TCP proxy | Query + RESP | 8 |
diff --git a/docs/services/inspector2.md b/docs/services/inspector2.md
new file mode 100644
index 0000000000..e4a40419c7
--- /dev/null
+++ b/docs/services/inspector2.md
@@ -0,0 +1,43 @@
+# Amazon Inspector
+
+**Protocol:** REST JSON
+
+**Endpoint:** `http://localhost:4566`
+
+Floci implements the Amazon Inspector organization operations used by local security-governance workflows.
+
+## Supported Actions
+
+
+| Action | Description |
+| --- | --- |
+| `ListDelegatedAdminAccounts` | - |
+| `EnableDelegatedAdminAccount` | - |
+| `DisableDelegatedAdminAccount` | - |
+| `BatchGetAccountStatus` | - |
+| `Enable` | - |
+| `UpdateOrganizationConfiguration` | - |
+| `DescribeOrganizationConfiguration` | - |
+
+
+## Supported behavior
+
+The supported surface includes delegated administrator management, `BatchGetAccountStatus`, Inspector enablement, and organization auto-enable configuration. Delegation is reflected into the delegated account so organization configuration can be managed through credentials for that administrator account.
+
+`BatchGetAccountStatus` accepts an omitted or empty `accountIds` list and resolves it to the caller account. Explicit enablement supports `EC2`, `ECR`, `LAMBDA`, `LAMBDA_CODE`, and `CODE_REPOSITORY`, with the documented request-size limits. Explicit enablement uses the account-state values `ENABLING` and `ENABLED` so SDK and deployment waiters can converge.
+
+Organization auto-enable supports `ec2`, `ecr`, `lambda`, `lambdaCode`, and `codeRepository`. Only the delegated administrator account can update or describe organization configuration.
+
+## AWS-compatible failures
+
+Invalid account IDs, resource types, pagination input, and request shapes return `ValidationException`. Conflicting delegated-administrator state returns `ConflictException`. Organization configuration from a non-administrator account returns `AccessDeniedException`, and disabling an administrator that is not configured returns `ResourceNotFoundException`.
+
+AWS also models internal and throttling failures. Floci does not synthesize provider-side failures without a local triggering condition.
+
+See the [Amazon Inspector API Reference](https://docs.aws.amazon.com/inspector/v2/APIReference/Welcome.html).
+
+## Configuration
+
+| Variable | Default | Description |
+|---|---|---|
+| `FLOCI_SERVICES_INSPECTOR2_ENABLED` | `true` | Enable or disable Amazon Inspector |
diff --git a/mkdocs.yml b/mkdocs.yml
index 580fc47de8..cfdb1aec81 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -125,6 +125,7 @@ nav:
- Identity Store: services/identitystore.md
- AWS Budgets: services/budgets.md
- Amazon Macie: services/macie2.md
+ - Amazon Inspector: services/inspector2.md
- Amazon Detective: services/detective.md
- Control Catalog: services/controlcatalog.md
- Control Tower: services/controltower.md
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 b86deca7f2..9c5e862d28 100644
--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
@@ -729,6 +729,7 @@ public interface EmulatorConfig {
AccessAnalyzerServiceConfig accessanalyzer();
IdentityStoreServiceConfig identitystore();
BudgetsServiceConfig budgets();
+ Inspector2ServiceConfig inspector2();
DetectiveServiceConfig detective();
ServiceQuotasServiceConfig servicequotas();
RamServiceConfig ram();
@@ -784,6 +785,11 @@ public interface EmulatorConfig {
boolean enabled();
}
+ interface Inspector2ServiceConfig {
+ @WithDefault("true")
+ boolean enabled();
+ }
+
interface DetectiveServiceConfig {
@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.java
index 2799a51eab..238b3299d5 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
@@ -35,6 +35,7 @@ import io.github.hectorvent.floci.services.guardduty.GuardDutyController;
import io.github.hectorvent.floci.services.macie2.MacieController;
import io.github.hectorvent.floci.services.account.AccountController;
import io.github.hectorvent.floci.services.accessanalyzer.AccessAnalyzerController;
+import io.github.hectorvent.floci.services.inspector2.Inspector2Controller;
import io.github.hectorvent.floci.services.detective.DetectiveController;
import io.github.hectorvent.floci.services.aps.ApsController;
import io.github.hectorvent.floci.services.controlcatalog.ControlCatalogController;
@@ -436,6 +437,9 @@ public class ResolvedServiceCatalog {
descriptor("detective", "detective", config.services().detective().enabled(), true,
"detective", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,
protocols(ServiceProtocol.REST_JSON), Set.of(), Set.of("detective"), Set.of(), Set.of(DetectiveController.class)),
+ descriptor("inspector2", "inspector2", config.services().inspector2().enabled(), true,
+ "inspector2", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,
+ protocols(ServiceProtocol.REST_JSON), Set.of(), Set.of("inspector2"), Set.of(), Set.of(Inspector2Controller.class)),
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/inspector2/Inspector2Controller.java b/src/main/java/io/github/hectorvent/floci/services/inspector2/Inspector2Controller.java
new file mode 100644
index 0000000000..5d2d263639
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/inspector2/Inspector2Controller.java
@@ -0,0 +1,200 @@
+package io.github.hectorvent.floci.services.inspector2;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.JsonErrorResponseUtils;
+import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.common.RequestContext;
+import io.github.hectorvent.floci.services.inspector2.model.InspectorState;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.WebApplicationException;
+import jakarta.ws.rs.core.Context;
+import jakarta.ws.rs.core.HttpHeaders;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+
+@Path("/")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class Inspector2Controller {
+ private final Inspector2Service service;
+ private final RegionResolver regionResolver;
+ private final ObjectMapper objectMapper;
+ private final RequestContext requestContext;
+
+ @Inject
+ public Inspector2Controller(Inspector2Service service, RegionResolver regionResolver, ObjectMapper objectMapper,
+ RequestContext requestContext) {
+ this.service = service;
+ this.regionResolver = regionResolver;
+ this.objectMapper = objectMapper;
+ this.requestContext = requestContext;
+ }
+
+ @POST
+ @Path("/delegatedadminaccounts/list")
+ public Response listDelegatedAdminAccounts(@Context HttpHeaders headers, String body) {
+ JsonNode request = parse(body);
+ if (request.has("maxResults")) {
+ JsonNode maxResults = request.get("maxResults");
+ if (!maxResults.canConvertToInt() || maxResults.intValue() < 1 || maxResults.intValue() > 5) {
+ throw new AwsException("ValidationException", "maxResults must be between 1 and 5.", 400);
+ }
+ }
+ if (request.hasNonNull("nextToken") && !request.path("nextToken").asText().isBlank()) {
+ throw new AwsException("ValidationException", "nextToken is invalid.", 400);
+ }
+ InspectorState state = service.delegatedAdminState(region(headers), requestContext.getAccountId());
+ var response = objectMapper.createObjectNode();
+ var accounts = response.putArray("delegatedAdminAccounts");
+ if (state.getAdminAccountId() != null) {
+ accounts.addObject().put("accountId", state.getAdminAccountId()).put("status", "ENABLED");
+ }
+ return Response.ok(response).build();
+ }
+
+ @POST
+ @Path("/delegatedadminaccounts/enable")
+ public Response enableDelegatedAdminAccount(@Context HttpHeaders headers, String body) {
+ JsonNode request = parse(body);
+ String accountId = request.path("delegatedAdminAccountId").asText(null);
+ service.enableDelegatedAdmin(region(headers), requestContext.getAccountId(), accountId);
+ var response = objectMapper.createObjectNode();
+ response.put("delegatedAdminAccountId", accountId);
+ return Response.ok(response).build();
+ }
+
+ @POST
+ @Path("/delegatedadminaccounts/disable")
+ public Response disableDelegatedAdminAccount(@Context HttpHeaders headers, String body) {
+ JsonNode request = parse(body);
+ String accountId = request.path("delegatedAdminAccountId").asText(null);
+ service.disableDelegatedAdmin(region(headers), requestContext.getAccountId(), accountId);
+ var response = objectMapper.createObjectNode();
+ response.put("delegatedAdminAccountId", accountId);
+ return Response.ok(response).build();
+ }
+
+ @POST
+ @Path("/status/batch/get")
+ public Response batchGetAccountStatus(@Context HttpHeaders headers, String body) {
+ JsonNode request = parse(body);
+ JsonNode accountIds = request.get("accountIds");
+ if (accountIds != null && (!accountIds.isArray() || accountIds.size() > 100)) {
+ throw new AwsException("ValidationException",
+ "accountIds must contain at most 100 account IDs.", 400);
+ }
+ java.util.List requestedAccounts = requestedAccounts(accountIds);
+ var response = objectMapper.createObjectNode();
+ var accounts = response.putArray("accounts");
+ for (String accountId : requestedAccounts) {
+ InspectorState state = service.accountStatus(
+ region(headers), requestContext.getAccountId(), accountId);
+ var account = accounts.addObject();
+ account.put("accountId", accountId);
+ account.set("state", stateNode(state.getStatus()));
+ account.set("resourceState", resourceState(state));
+ }
+ response.putArray("failedAccounts");
+ return Response.ok(response).build();
+ }
+
+ @POST
+ @Path("/enable")
+ public Response enable(@Context HttpHeaders headers, String body) {
+ JsonNode request = parse(body);
+ var enabled = service.enable(region(headers), requestContext.getAccountId(), request);
+ var response = objectMapper.createObjectNode();
+ var accounts = response.putArray("accounts");
+ enabled.forEach((accountId, state) -> {
+ var account = accounts.addObject();
+ account.put("accountId", accountId);
+ account.put("status", state.getStatus());
+ account.set("resourceStatus", resourceStatus(state));
+ });
+ response.putArray("failedAccounts");
+ return Response.ok(response).build();
+ }
+
+ @POST
+ @Path("/organizationconfiguration/update")
+ public Response updateOrganizationConfiguration(@Context HttpHeaders headers, String body) {
+ InspectorState state = service.updateOrganizationConfiguration(
+ region(headers), requestContext.getAccountId(), parse(body));
+ return Response.ok(organizationConfigurationResponse(state)).build();
+ }
+
+ @POST
+ @Path("/organizationconfiguration/describe")
+ public Response describeOrganizationConfiguration(@Context HttpHeaders headers, String body) {
+ InspectorState state = service.organizationConfiguration(region(headers), requestContext.getAccountId());
+ return Response.ok(organizationConfigurationResponse(state)).build();
+ }
+
+ private com.fasterxml.jackson.databind.node.ObjectNode organizationConfigurationResponse(InspectorState state) {
+ var response = objectMapper.createObjectNode();
+ var autoEnable = response.putObject("autoEnable");
+ autoEnable.put("ec2", state.isAutoEnableEc2());
+ autoEnable.put("ecr", state.isAutoEnableEcr());
+ autoEnable.put("lambda", state.isAutoEnableLambda());
+ autoEnable.put("lambdaCode", state.isAutoEnableLambdaCode());
+ autoEnable.put("codeRepository", state.isAutoEnableCodeRepository());
+ response.put("maxAccountLimitReached", false);
+ return response;
+ }
+
+ private java.util.List requestedAccounts(JsonNode accountIds) {
+ if (accountIds == null || accountIds.isEmpty()) {
+ return java.util.List.of(requestContext.getAccountId());
+ }
+ java.util.List result = new java.util.ArrayList<>(accountIds.size());
+ for (JsonNode accountId : accountIds) {
+ Inspector2Service.requireAccountId(accountId.asText(null));
+ result.add(accountId.asText());
+ }
+ return result;
+ }
+
+ private com.fasterxml.jackson.databind.node.ObjectNode resourceState(InspectorState state) {
+ var resources = objectMapper.createObjectNode();
+ resources.set("ec2", stateNode(state.getEc2Status()));
+ resources.set("ecr", stateNode(state.getEcrStatus()));
+ resources.set("lambda", stateNode(state.getLambdaStatus()));
+ resources.set("lambdaCode", stateNode(state.getLambdaCodeStatus()));
+ resources.set("codeRepository", stateNode(state.getCodeRepositoryStatus()));
+ return resources;
+ }
+
+ private com.fasterxml.jackson.databind.node.ObjectNode resourceStatus(InspectorState state) {
+ var resources = objectMapper.createObjectNode();
+ resources.put("ec2", state.getEc2Status());
+ resources.put("ecr", state.getEcrStatus());
+ resources.put("lambda", state.getLambdaStatus());
+ resources.put("lambdaCode", state.getLambdaCodeStatus());
+ resources.put("codeRepository", state.getCodeRepositoryStatus());
+ return resources;
+ }
+
+ private com.fasterxml.jackson.databind.node.ObjectNode stateNode(String status) {
+ var state = objectMapper.createObjectNode();
+ state.put("status", status);
+ return state;
+ }
+
+ private String region(HttpHeaders headers) {
+ return regionResolver.resolveRegion(headers);
+ }
+
+ private JsonNode parse(String body) {
+ try {
+ return objectMapper.readTree(body == null || body.isBlank() ? "{}" : body);
+ } catch (Exception e) {
+ throw new WebApplicationException(JsonErrorResponseUtils.createSerializationErrorResponse());
+ }
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/inspector2/Inspector2Service.java b/src/main/java/io/github/hectorvent/floci/services/inspector2/Inspector2Service.java
new file mode 100644
index 0000000000..b8a6d8a8d8
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/inspector2/Inspector2Service.java
@@ -0,0 +1,313 @@
+package io.github.hectorvent.floci.services.inspector2;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonNode;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.Resettable;
+import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
+import io.github.hectorvent.floci.core.storage.StorageFactory;
+import io.github.hectorvent.floci.services.inspector2.model.InspectorState;
+import io.github.hectorvent.floci.services.organizations.OrganizationsService;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+@ApplicationScoped
+public class Inspector2Service implements Resettable {
+ private static final Set RESOURCE_TYPES = Set.of(
+ "EC2", "ECR", "LAMBDA", "LAMBDA_CODE", "CODE_REPOSITORY");
+
+ private final AccountAwareStorageBackend states;
+ private final OrganizationsService organizationsService;
+
+ @Inject
+ public Inspector2Service(StorageFactory storageFactory, OrganizationsService organizationsService) {
+ this(storageFactory.create("inspector2", "inspector2-state.json",
+ new TypeReference