Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

feat(servicecatalog): emulate AWS Service Catalog with Control Tower Account Factory (#2585)

Sam Fakhreddine2e843e9f2353
diff --git a/README.md b/README.md
index 8ce3295706..726a4f23be 100644
--- a/README.md
+++ b/README.md
@@ -178,7 +178,7 @@ LocalStack's community edition [sunset in March 2026](https://blog.localstack.cl
| CodeBuild | Real Docker execution | No |
| Native binary | ~40 MB | No |
-**79 AWS services. Broad coverage. Free forever.**
+**80 AWS services. Broad coverage. Free forever.**
## Architecture Overview
diff --git a/docs/index.md b/docs/index.md
index 60e31744b3..63f7538753 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 79 AWS services. See the [Services Overview](services/index.md) for per-service operation counts, endpoints, and full protocol details.
+Floci emulates 80 AWS services. See the [Services Overview](services/index.md) for per-service operation counts, endpoints, and full protocol details.
| Service | Protocol |
|---|---|
@@ -117,7 +117,7 @@ docker compose up -d
aws --endpoint-url http://localhost:4566 s3 mb s3://my-bucket
```
-All 79 AWS services are immediately available at `http://localhost:4566`.
+All 80 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/index.md b/docs/services/index.md
index 602b3f5fa4..9282dcc602 100644
--- a/docs/services/index.md
+++ b/docs/services/index.md
@@ -1,6 +1,6 @@
# Services Overview
-Floci emulates 79 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 80 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.
@@ -85,6 +85,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac
| [AWS Batch](batch.md) | `/v1/...` | REST JSON | 10 |
| [CodeDeploy](codedeploy.md) | `POST /` + `X-Amz-Target: CodeDeploy_20141006.*` | JSON 1.1 | 30 |
| [CodePipeline](codepipeline.md) | `POST /` + `X-Amz-Target: CodePipeline_20150709.*` | JSON 1.1 | 44 |
+| [AWS Service Catalog](service-catalog.md) | `POST /` + `X-Amz-Target: AWS242ServiceCatalogService.*` | JSON 1.1 | 89 |
| [Service Quotas](servicequotas.md) | `POST /` + `X-Amz-Target: ServiceQuotasV20190624.*` | JSON 1.1 | 5 |
| [AWS RAM](ram.md) | `POST /{operationname}` (lowercase), `DELETE /deleteresourceshare` | REST JSON | 12 |
| [Control Tower](controltower.md) | `/list-landingzones`, `/get-landingzone`, `/create-landingzone`, `/*-baseline*` | REST JSON | 15 |
diff --git a/docs/services/service-catalog.md b/docs/services/service-catalog.md
new file mode 100644
index 0000000000..f12f0301cc
--- /dev/null
+++ b/docs/services/service-catalog.md
@@ -0,0 +1,215 @@
+# AWS Service Catalog
+
+**Protocol:** AWS JSON 1.1
+**Signing name:** `servicecatalog`
+
+Floci persists portfolios, products and provisioning-artifact metadata, TagOptions,
+resource associations, provisioned products, and organization/account portfolio shares.
+Portfolio-share operations complete immediately while preserving the AWS status-token
+workflow.
+
+## Supported Actions
+
+<!-- floci:actions:start -->
+| Action | Description |
+| --- | --- |
+| `CreatePortfolio` | Create a portfolio to organise products. |
+| `UpdatePortfolio` | Update a portfolio's display name, description, or provider. |
+| `DescribePortfolio` | Return a portfolio's details. |
+| `ListPortfolios` | List all portfolios in the account. |
+| `DeletePortfolio` | Delete a portfolio. |
+| `CreateProduct` | Create a product with its initial provisioning artifact. |
+| `UpdateProduct` | Update a product's metadata. |
+| `DescribeProductAsAdmin` | Return a product's details and provisioning artifacts from the admin view. |
+| `SearchProductsAsAdmin` | List every product in the account from the admin view. |
+| `SearchProducts` | Search the products available to the caller. |
+| `ListProvisioningArtifacts` | List the provisioning artifacts (versions) of a product. |
+| `ProvisionProduct` | Provision a product the catalog holds; the Control Tower Account Factory product creates a real Organizations member account and moves it to the requested OU, any other product persists a provisioned-product record only. |
+| `SearchProvisionedProducts` | Search provisioned products; only `status:` and `physicalid:` search terms are honoured and results are not paginated. |
+| `DeleteProduct` | Delete a product. |
+| `CreateTagOption` | Create a TagOption key/value pair. |
+| `UpdateTagOption` | Update a TagOption's value or active flag. |
+| `DescribeTagOption` | Return a TagOption's details. |
+| `ListTagOptions` | List all TagOptions. |
+| `DeleteTagOption` | Delete a TagOption. |
+| `AssociateProductWithPortfolio` | Associate a product with a portfolio. |
+| `DisassociateProductFromPortfolio` | Remove a product from a portfolio; the delete is unconditional, so unknown ids still succeed. |
+| `AssociateTagOptionWithResource` | Attach a TagOption to a portfolio or product. |
+| `DisassociateTagOptionFromResource` | Detach a TagOption from a resource; the delete is unconditional, so unknown ids still succeed. |
+| `UpdatePortfolioShare` | Create or overwrite a portfolio share with a fresh token; identical to `CreatePortfolioShare` and no existing share is required. |
+| `CreatePortfolioShare` | Share a portfolio with an account or organization node; completes immediately. |
+| `DescribePortfolioShareStatus` | Report the status of a share operation by its token; always terminal. |
+| `DescribeProduct` | Return a product's consumer view; omits `Budgets` and `LaunchPaths`, and a `Name` given instead of `Id` is still resolved as an id. |
+| `DescribePortfolioShares` | List a portfolio's shares; every share reports `Accepted: true` and no pagination token is emitted. |
+| `ListPortfoliosForProduct` | List the portfolios a product is associated with. |
+| `CopyProduct` | Copy a product's metadata synchronously; the returned copy token is already terminal. |
+| `DescribeProvisioningArtifact` | Return a provisioning artifact's details; omits the template `Info` map. |
+| `AcceptPortfolioShare` | Validate the shared portfolio exists; acceptance state is not persisted. |
+| `DeletePortfolioShare` | Delete the share row keyed by portfolio and resolved principal. |
+| `RejectPortfolioShare` | Validate the portfolio exists; rejection is a no-op beyond validation. |
+| `AssociateBudgetWithResource` | Record a budget-name association with a resource; no Budgets service integration exists. |
+| `AssociatePrincipalWithPortfolio` | Record an IAM principal association on a portfolio; the association is metadata only and grants no access. |
+| `AssociateServiceActionWithProvisioningArtifact` | Store a service-action/provisioning-artifact association; no list operation ever reads it back. |
+| `BatchAssociateServiceActionWithProvisioningArtifact` | Store several service-action associations in one call, reporting per-entry failures; no list operation ever reads them back. |
+| `BatchDisassociateServiceActionFromProvisioningArtifact` | Remove multiple service-action associations in one call. |
+| `CreateConstraint` | Create a constraint on a product/portfolio pair; `Parameters` is echoed back in the response but never persisted. |
+| `CreateProvisionedProductPlan` | Create a provisioned product plan record; no `ResourceChanges` preview is computed. |
+| `CreateServiceAction` | Create a self-service action definition. |
+| `DeleteConstraint` | Delete a constraint. |
+| `DeleteProvisionedProductPlan` | Delete a provisioned product plan. |
+| `DeleteProvisioningArtifact` | Delete a provisioning artifact from a product. |
+| `DeleteServiceAction` | Delete a service action. |
+| `DescribeConstraint` | Return a constraint's details; `ConstraintParameters` is never returned. |
+| `DescribeProductView` | Return a product's consumer view; product-view ids are not modelled, so `Id` must be a product or provisioning-artifact id. |
+| `DescribeProvisionedProduct` | Return a provisioned product's details. |
+| `DescribeProvisionedProductPlan` | Return a provisioned product plan's identity fields; no `Status` or `ResourceChanges` is reported. |
+| `DescribeProvisioningParameters` | Return the provisioning parameters recorded on the product at creation; the response is empty if none were supplied. |
+| `DescribeRecord` | Look up a record by id; `ProvisionProduct` and `ExecuteProvisionedProductPlan` return a `RecordId` they never persist, so those are not found. |
+| `DescribeServiceActionExecutionParameters` | Return a service action's execution parameters; always an empty list. |
+| `DisableAWSOrganizationsAccess` | Accept the disable request without persisting any state. |
+| `DisassociateBudgetFromResource` | Remove a budget-name association from a resource. |
+| `DisassociatePrincipalFromPortfolio` | Revoke a principal's access to a portfolio. |
+| `DisassociateServiceActionFromProvisioningArtifact` | Remove a service action's association with a provisioning artifact. |
+| `EnableAWSOrganizationsAccess` | Accept the enable request without persisting any state. |
+| `ExecuteProvisionedProductPlan` | Mark a plan executed with a `SUCCEEDED` record; no provisioned product is created and the record is not persisted. |
+| `ExecuteProvisionedProductServiceAction` | Persist a `SUCCEEDED` execution record against a provisioned product; the `ServiceActionId` is required but never resolved and no action runs. |
+| `GetAWSOrganizationsAccessStatus` | Report the Organizations access status; always `ENABLED`. |
+| `GetProvisionedProductOutputs` | Return a provisioned product's stack outputs; always an empty list. |
+| `ImportAsProvisionedProduct` | Register the given `PhysicalId` as an `AVAILABLE` provisioned product and persist an `IMPORT` record; no CloudFormation stack is looked up. |
+| `ListAcceptedPortfolioShares` | List portfolios; returns every portfolio, not just accepted shares. |
+| `ListBudgetsForResource` | List the budget names associated with a resource. |
+| `ListConstraintsForPortfolio` | List the constraints for a portfolio, optionally filtered by product. |
+| `ListLaunchPaths` | Synthesise one launch path per portfolio the product is associated with, keyed by the portfolio's own id. |
+| `ListOrganizationPortfolioAccess` | List the organization nodes a portfolio is shared with. |
+| `ListPortfolioAccess` | List the account IDs a portfolio is shared with; `OrganizationParentId` is accepted but ignored. |
+| `ListPrincipalsForPortfolio` | List the principals associated with a portfolio. |
+| `ListProvisionedProductPlans` | List provisioned product plans with offset-based pagination; `PageSize` is capped at 20. |
+| `ListProvisioningArtifactsForServiceAction` | List provisioning artifacts for a service action; always an empty list. |
+| `ListRecordHistory` | Synthesise one `SUCCEEDED` record per stored provisioned product; the entries carry no `RecordId` and the real record store is not consulted. |
+| `ListResourcesForTagOption` | List the resources a TagOption is attached to. |
+| `ListServiceActions` | List every service action in the account, without context scoping. |
+| `ListServiceActionsForProvisioningArtifact` | List service actions for a provisioning artifact; always an empty list. |
+| `ListStackInstancesForProvisionedProduct` | Return one synthetic stack instance derived from the provisioned product; always exactly one, always `CURRENT`. |
+| `NotifyProvisionProductEngineWorkflowResult` | Validate the workflow-result fields and return empty; nothing is recorded. |
+| `NotifyTerminateProvisionedProductEngineWorkflowResult` | Validate the workflow-result fields and return empty; nothing is recorded. |
+| `NotifyUpdateProvisionedProductEngineWorkflowResult` | Validate the workflow-result fields and return empty; nothing is recorded. |
+| `ScanProvisionedProducts` | List all provisioned products with page-token pagination. |
+| `UpdateConstraint` | Update a constraint's parameters or description. |
+| `UpdateProvisionedProduct` | Validate the provisioned product exists and persist a `SUCCEEDED` record; no field on the product itself changes. |
+| `UpdateProvisionedProductProperties` | Replace a provisioned product's properties wholesale and persist a record; property keys are not validated. |
+| `UpdateServiceAction` | Update a service action's definition. |
+| `CreateProvisioningArtifact` | Add a new provisioning artifact (version) to a product. |
+| `DescribeCopyProductStatus` | Report a product-copy status; always `SUCCEEDED` immediately. |
+| `TerminateProvisionedProduct` | Mark a provisioned product `TERMINATED` and persist a record; the row is kept and any account it created is left in the organization. |
+| `UpdateProvisioningArtifact` | Rename a provisioning artifact; only `Name` is applied and the artifact is always reported `Active`. |
+<!-- floci:actions:end -->
+
+Floci lazily creates the managed **AWS Control Tower Account Factory Portfolio** and its
+Account Factory product the first time `ListPortfolios`, `ListAcceptedPortfolioShares`,
+`SearchProducts` or `ProvisionProduct` is called. `SearchProductsAsAdmin` does not trigger
+this, so the Account Factory product is absent from the admin view until one of those
+operations has run.
+`ProvisionProduct` resolves the product named by `ProductId` or `ProductName` and rejects one the catalog does not hold with `ResourceNotFoundException`; a request naming neither is rejected with `InvalidParametersException`. A supplied `ProvisioningArtifactId` or `ProvisioningArtifactName` must belong to that product, and when neither is supplied the product's first artifact is used.
+
+When the resolved product is the Account Factory product, `ProvisionProduct` creates a real Organizations member account through the Organizations service — reusing an existing account when `AccountEmail` already matches one — moves it under the OU named by the `ManagedOrganizationalUnit` provisioning parameter, and persists an `AVAILABLE` provisioned product of type `CONTROL_TOWER_ACCOUNT`. Organizational-unit display labels such as `Infrastructure (ou-...)` are resolved to their underlying OU IDs. Any other product persists an `AVAILABLE` provisioned product of type `CFN_STACK` and never touches Organizations.
+
+## Limitations
+
+- **`ProvisionProduct` provisions nothing outside the Account Factory path.** A product created with `CreateProduct` gets an `AVAILABLE` `CFN_STACK` provisioned product record and nothing else: no CloudFormation template is rendered, no stack exists, and the record carries no `PhysicalId`. Provisioning parameters are not applied or stored, and provisioning is idempotent on `ProvisionedProductName` — a repeat call returns the existing provisioned product unchanged, whichever product it names.
+- **`TerminateProvisionedProduct` does not release anything.** It flips the provisioned
+ product's `Status` to `TERMINATED` and persists a record, but the provisioned product row is
+ kept (so it still appears in `ScanProvisionedProducts` and `SearchProvisionedProducts`) and
+ an Organizations account created for it is left in place. `RetainPhysicalResources` and
+ `IgnoreErrors` have no effect.
+- **The three `Notify*EngineWorkflowResult` operations record nothing.** Each validates its
+ fields — `Status` must be `SUCCEEDED` or `FAILED` — and returns an empty response. No
+ workflow token, record, or status is stored, so a notified result is not observable
+ afterwards through any operation.
+- **`ListStackInstancesForProvisionedProduct` returns one synthetic instance.** No stack set
+ or stack instances are modelled; the single entry is derived from the provisioned product
+ itself — `Account` from its `PhysicalId`, `Region` parsed out of its ARN, and
+ `StackInstanceStatus` always `CURRENT`.
+- **Constraint parameters are never persisted.** `CreateConstraint` requires `Parameters` and
+ echoes it back in its own response, but only the constraint's ids, type, owner and
+ description are stored — `DescribeConstraint` and `ListConstraintsForPortfolio` never return
+ `ConstraintParameters`. `UpdateConstraint` does store `Parameters`, but nothing reads them
+ back either.
+- **Service-action associations are write-only.** `AssociateServiceActionWithProvisioningArtifact`
+ and its batch form validate the product and artifact and store an association (rejecting
+ duplicates with `DuplicateResourceException`), and the disassociate operations remove it, but
+ no operation reads it back — both `ListServiceActionsForProvisioningArtifact` and
+ `ListProvisioningArtifactsForServiceAction` always return empty (see below).
+- **`CopyProduct` completes synchronously.** Real AWS returns a `CopyProductToken` for an
+ asynchronous copy whose progress is polled with `DescribeCopyProductStatus`. Floci creates
+ the copied product before returning, so the token it hands back is already terminal —
+ `DescribeCopyProductStatus` immediately reports `SUCCEEDED`. A caller that treats the token
+ as pending work will not see any intermediate state.
+- **`DescribeServiceActionExecutionParameters` always returns an empty parameter list.** No
+ parameter schema is modelled for service action definitions.
+- **`ListAcceptedPortfolioShares` returns every portfolio, not just accepted shares.** Consistent
+ with `AcceptPortfolioShare` not tracking acceptance as distinct state (see above): there is no
+ way to distinguish a portfolio the caller owns from one shared and accepted from elsewhere.
+- **`UpdateProvisionedProduct` does not apply any request fields.** It validates the
+ provisioned product exists and persists a `SUCCEEDED` record (matching this codebase's
+ validate-and-echo convention for unimplementable state transitions), but no field on
+ the provisioned product itself changes — a real re-provisioning artifact/parameter
+ change is not modelled.
+- **`CopyProduct` copies product metadata only**, including provisioning-artifact ids and
+ names. `SourceProvisioningArtifactIdentifiers` and `CopyOptions` in the request are not
+ honoured — every artifact is carried over and no `CopyOption` is applied.
+- **`DescribePortfolioShares` reports every share as `Accepted: true`.** Shares complete
+ immediately, so there is no pending or declined state to report, and `ShareTagOptions` and
+ `SharePrincipals` are always `false` because neither is modelled.
+- **`AcceptPortfolioShare` and `RejectPortfolioShare` validate the portfolio exists and return
+ successfully, but neither persists any state.** Acceptance is unconditional in this emulator —
+ every share already reads back as `Accepted: true` (see above) — so reject is likewise a no-op
+ beyond validation. There is no way to observe a rejected share through any other operation.
+- **`DeletePortfolioShare` removes the share row keyed by `PortfolioId` + the resolved principal**
+ (`ACCOUNT:<AccountId>` or `<OrganizationNode.Type>:<OrganizationNode.Value>`), the same key
+ `CreatePortfolioShare`/`UpdatePortfolioShare` write. It does not accept `PortfolioShareToken` as
+ an alternate lookup key, matching the request shape AWS documents for this operation.
+- **`DescribePortfolioShares` does not paginate.** All shares for a portfolio are returned in
+ one response and no `NextPageToken` is emitted, rather than advertising a token the emulator
+ would not honour.
+- **`DescribeProduct` omits `Budgets` and `LaunchPaths`.** Neither budgets nor launch paths are
+ modelled, so the fields are absent rather than returned empty.
+- **`DescribeProvisioningArtifact` omits `Info`.** The CloudFormation template URL map is not
+ stored, and `Verbose` in the request has no effect.
+- **`EnableAWSOrganizationsAccess` / `DisableAWSOrganizationsAccess` do not persist any state.**
+ `GetAWSOrganizationsAccessStatus` always reports `ENABLED` regardless of which was last called.
+- **Budget associations are name-only.** `AssociateBudgetWithResource` records the pairing of a
+ `BudgetName` string with a resource; no Budgets service integration exists, so any name is
+ accepted and no actual budget or cost data is checked or returned.
+- **`ListServiceActions` returns every service action in the account.** There is no portfolio,
+ product, or provisioning-artifact scoping — real AWS only lists actions associated with a
+ given context. `DefinitionType` is always reported as `SSM_AUTOMATION`, matching AWS's only
+ currently defined value for that enum.
+- **`ListProvisioningArtifactsForServiceAction` always returns an empty list.** It validates
+ that `ServiceActionId` was supplied and returns no views, even when associations for that
+ service action were stored (see above).
+- **`ExecuteProvisionedProductPlan` completes synchronously and does not create an actual
+ provisioned product.** It validates the plan exists and returns a `SUCCEEDED` record, but no
+ `ProvisionedProduct` entry is created as a side effect — `DescribeProvisionedProduct` will not
+ find anything from an executed plan.
+- **`GetProvisionedProductOutputs` always returns an empty `Outputs` list.** No CloudFormation
+ stack outputs are modelled or persisted for any provisioned product.
+- **Two operations return a `RecordId` they never persist.** `ImportAsProvisionedProduct`,
+ `ExecuteProvisionedProductServiceAction`, `UpdateProvisionedProduct`,
+ `UpdateProvisionedProductProperties` and `TerminateProvisionedProduct` all store a record
+ that `DescribeRecord` can later find. `ProvisionProduct` and `ExecuteProvisionedProductPlan`
+ mint a `RecordId` for their response only, so looking either one up afterwards raises
+ `ResourceNotFoundException`.
+- **`ListRecordHistory` does not read the record store.** It synthesises one `SUCCEEDED`
+ entry per stored provisioned product, so the entries carry no `RecordId` and cannot be fed
+ back into `DescribeRecord`, and records from operations that persisted one never appear.
+ Request filters and pagination are ignored.
+- **`ListServiceActionsForProvisioningArtifact` always returns an empty list.** It validates
+ that the product and provisioning artifact exist and then returns no summaries, even when
+ associations for that artifact were stored (the inverse case,
+ `ListProvisioningArtifactsForServiceAction`, behaves the same way).
+
+## Configuration
+
+| Variable | Default | Description |
+|---|---|---|
+| `FLOCI_SERVICES_SERVICECATALOG_ENABLED` | `true` | Enable or disable AWS Service Catalog |
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 fa1a35a935..ec70d65a20 100644
--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
@@ -672,6 +672,7 @@ public interface EmulatorConfig {
RumServiceConfig rum();
GuardDutyServiceConfig guardduty();
EmrServerlessServiceConfig emrserverless();
+ ServiceCatalogServiceConfig servicecatalog();
SsoAdminServiceConfig ssoadmin();
ServiceQuotasServiceConfig servicequotas();
RamServiceConfig ram();
@@ -731,6 +732,11 @@ public interface EmulatorConfig {
boolean enabled();
}
+ interface ServiceCatalogServiceConfig {
+ @WithDefault("true")
+ boolean enabled();
+ }
+
interface ServiceQuotasServiceConfig {
@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 d5876f4c14..3a274fa627 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
@@ -42,6 +42,7 @@ import io.github.hectorvent.floci.services.kinesisanalytics.KinesisAnalyticsV2Js
import io.github.hectorvent.floci.services.kms.KmsJsonHandler;
import io.github.hectorvent.floci.services.secretsmanager.SecretsManagerJsonHandler;
import io.github.hectorvent.floci.services.organizations.OrganizationsJsonHandler;
+import io.github.hectorvent.floci.services.servicecatalog.ServiceCatalogJsonHandler;
import io.github.hectorvent.floci.services.servicequotas.ServiceQuotasJsonHandler;
import io.github.hectorvent.floci.services.ssm.Ec2MessagesJsonHandler;
import io.github.hectorvent.floci.services.ssm.SsmJsonHandler;
@@ -105,6 +106,7 @@ public class AwsJson11Controller {
private final ConfigServiceJsonHandler configServiceJsonHandler;
private final CloudTrailJsonHandler cloudTrailJsonHandler;
private final LightsailJsonHandler lightsailJsonHandler;
+ private final ServiceCatalogJsonHandler serviceCatalogJsonHandler;
private final CloudControlJsonHandler cloudControlJsonHandler;
private final ApplicationAutoScalingJsonHandler applicationAutoScalingJsonHandler;
private final CloudHsmV2JsonHandler cloudHsmV2JsonHandler;
@@ -145,6 +147,7 @@ public class AwsJson11Controller {
ConfigServiceJsonHandler configServiceJsonHandler,
CloudTrailJsonHandler cloudTrailJsonHandler,
LightsailJsonHandler lightsailJsonHandler,
+ ServiceCatalogJsonHandler serviceCatalogJsonHandler,
CloudControlJsonHandler cloudControlJsonHandler,
ApplicationAutoScalingJsonHandler applicationAutoScalingJsonHandler,
CloudHsmV2JsonHandler cloudHsmV2JsonHandler,
@@ -189,6 +192,7 @@ public class AwsJson11Controller {
this.configServiceJsonHandler = configServiceJsonHandler;
this.cloudTrailJsonHandler = cloudTrailJsonHandler;
this.lightsailJsonHandler = lightsailJsonHandler;
+ this.serviceCatalogJsonHandler = serviceCatalogJsonHandler;
this.cloudControlJsonHandler = cloudControlJsonHandler;
this.applicationAutoScalingJsonHandler = applicationAutoScalingJsonHandler;
this.cloudHsmV2JsonHandler = cloudHsmV2JsonHandler;
@@ -265,6 +269,8 @@ public class AwsJson11Controller {
case "cloudtrail" -> cloudTrailJsonHandler.handle(action, request, region);
case "application-autoscaling" -> applicationAutoScalingJsonHandler.handle(action, request, region);
case "lightsail" -> lightsailJsonHandler.handle(action, request, region);
+ case "servicecatalog" -> serviceCatalogJsonHandler.handle(
+ action, request, region, regionResolver.getAccountId());
case "cloudcontrol" -> cloudControlJsonHandler.handle(action, request, region);
case "cloudhsmv2" -> cloudHsmV2JsonHandler.handle(action, request, region);
// Organizations is global and account-scoped rather than region-scoped: every
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 947847d847..0aab4a0c9e 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
@@ -519,12 +519,15 @@ public class ResolvedServiceCatalog {
config.storage().services().guardduty().flushIntervalMs(), null, ServiceProtocol.REST_JSON,
protocols(ServiceProtocol.REST_JSON),
Set.of(), Set.of("guardduty"), Set.of(), Set.of(GuardDutyController.class)),
+ descriptor("servicecatalog", "servicecatalog", config.services().servicecatalog().enabled(), true,
+ "servicecatalog", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
+ protocols(ServiceProtocol.JSON),
+ Set.of("AWS242ServiceCatalogService."), Set.of("servicecatalog"), Set.of(), Set.of()),
descriptor("controltower", "controltower", config.services().controltower().enabled(), true,
"controltower", storageMode(config.storage().services().controltower().mode(), config.storage().mode()),
config.storage().services().controltower().flushIntervalMs(), null, ServiceProtocol.REST_JSON,
protocols(ServiceProtocol.REST_JSON),
Set.of(), Set.of("controltower"), Set.of(), Set.of(ControlTowerController.class)),
-
descriptor("lakeformation", "lakeformation", config.services().lakeformation().enabled(), true,
"lakeformation",
storageMode(config.storage().services().lakeformation().mode(), config.storage().mode()),
diff --git a/src/main/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogJsonHandler.java
new file mode 100644
index 0000000000..58d0f51268
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogJsonHandler.java
@@ -0,0 +1,884 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.common.AwsErrorResponse;
+import io.github.hectorvent.floci.core.common.AwsException;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.core.Response;
+import org.jboss.logging.Logger;
+
+import java.util.UUID;
+import java.util.List;
+
+@ApplicationScoped
+public class ServiceCatalogJsonHandler {
+
+ private static final Logger LOG = Logger.getLogger(ServiceCatalogJsonHandler.class);
+ private final ServiceCatalogService service;
+ private final ObjectMapper objectMapper;
+
+ @Inject
+ public ServiceCatalogJsonHandler(ServiceCatalogService service, ObjectMapper objectMapper) {
+ this.service = service;
+ this.objectMapper = objectMapper;
+ }
+
+ public Response handle(String action, JsonNode request, String region, String accountId) {
+ try {
+ return switch (action) {
+ case "CreatePortfolio" -> portfolioResponse(service.createPortfolio(request, region, accountId));
+ case "UpdatePortfolio" -> portfolioResponse(service.updatePortfolio(text(request, "Id"), request));
+ case "DescribePortfolio" -> portfolioResponse(service.describePortfolio(text(request, "Id")));
+ case "ListPortfolios" -> listPortfolios(region, accountId);
+ case "DeletePortfolio" -> empty(() -> service.deletePortfolio(text(request, "Id")));
+ case "CreateProduct" -> productResponse(service.createProduct(request, region, accountId));
+ case "UpdateProduct" -> productResponse(service.updateProduct(text(request, "Id"), request));
+ case "DescribeProductAsAdmin" -> productResponse(service.describeProduct(text(request, "Id")));
+ case "SearchProductsAsAdmin" -> listProducts();
+ case "SearchProducts" -> searchProducts(request, region, accountId);
+ case "ListProvisioningArtifacts" -> provisioningArtifacts(text(request, "ProductId"));
+ case "ProvisionProduct" -> provisionProduct(request, region, accountId);
+ case "SearchProvisionedProducts" -> searchProvisionedProducts(request);
+ case "DeleteProduct" -> empty(() -> service.deleteProduct(text(request, "Id")));
+ case "CreateTagOption" -> tagOptionResponse(service.createTagOption(request));
+ case "UpdateTagOption" -> tagOptionResponse(service.updateTagOption(text(request, "Id"), request));
+ case "DescribeTagOption" -> tagOptionResponse(service.describeTagOption(text(request, "Id")));
+ case "ListTagOptions" -> listTagOptions();
+ case "DeleteTagOption" -> empty(() -> service.deleteTagOption(text(request, "Id")));
+ case "AssociateProductWithPortfolio" -> empty(() -> service.associateProduct(
+ text(request, "PortfolioId"), text(request, "ProductId")));
+ case "DisassociateProductFromPortfolio" -> empty(() -> service.disassociateProduct(
+ text(request, "PortfolioId"), text(request, "ProductId")));
+ case "AssociateTagOptionWithResource" -> empty(() -> service.associateTagOption(
+ text(request, "ResourceId"), text(request, "TagOptionId")));
+ case "DisassociateTagOptionFromResource" -> empty(() -> service.disassociateTagOption(
+ text(request, "ResourceId"), text(request, "TagOptionId")));
+ case "UpdatePortfolioShare", "CreatePortfolioShare" -> shareResponse(
+ service.updatePortfolioShare(request));
+ case "DescribePortfolioShareStatus" -> shareStatusResponse(
+ service.describePortfolioShareStatus(text(request, "PortfolioShareToken")));
+ case "DescribeProduct" -> describeProductForUser(request);
+ case "DescribePortfolioShares" -> describePortfolioShares(request);
+ case "ListPortfoliosForProduct" -> listPortfoliosForProduct(text(request, "ProductId"));
+ case "CopyProduct" -> copyProductResponse(service.copyProduct(request, region, accountId));
+ case "DescribeProvisioningArtifact" -> describeProvisioningArtifact(request);
+ case "AcceptPortfolioShare" -> empty(() -> service.acceptPortfolioShare(text(request, "PortfolioId")));
+ case "DeletePortfolioShare" -> deletePortfolioShare(request);
+ case "RejectPortfolioShare" -> empty(() -> service.rejectPortfolioShare(text(request, "PortfolioId")));
+ case "AssociateBudgetWithResource" -> empty(() -> service.associateBudgetWithResource(
+ text(request, "BudgetName"), text(request, "ResourceId")));
+ case "AssociatePrincipalWithPortfolio" -> empty(() -> service.associatePrincipal(
+ text(request, "PortfolioId"), text(request, "PrincipalARN"), text(request, "PrincipalType")));
+ case "AssociateServiceActionWithProvisioningArtifact" -> empty(() -> service.associateServiceActionWithProvisioningArtifact(
+ text(request, "ProductId"), text(request, "ProvisioningArtifactId"), text(request, "ServiceActionId")));
+ case "BatchAssociateServiceActionWithProvisioningArtifact" -> batchAssociateServiceActionWithProvisioningArtifact(request);
+ case "BatchDisassociateServiceActionFromProvisioningArtifact" -> batchDisassociateServiceActionFromProvisioningArtifact(request);
+ case "CreateConstraint" -> createConstraintResponse(request, region, accountId);
+ case "CreateProvisionedProductPlan" -> createProvisionedProductPlan(request, region, accountId);
+ case "CreateServiceAction" -> createServiceActionResponse(service.createServiceAction(request));
+ case "DeleteConstraint" -> empty(() -> service.deleteConstraint(text(request, "Id")));
+ case "DeleteProvisionedProductPlan" -> empty(() -> service.deleteProvisionedProductPlan(text(request, "PlanId")));
+ case "DeleteProvisioningArtifact" -> empty(() -> service.deleteProvisioningArtifact(
+ text(request, "ProductId"), text(request, "ProvisioningArtifactId")));
+ case "DeleteServiceAction" -> empty(() -> service.deleteServiceAction(text(request, "Id")));
+ case "DescribeConstraint" -> describeConstraint(request);
+ case "DescribeProductView" -> describeProductView(request);
+ case "DescribeProvisionedProduct" -> describeProvisionedProduct(request);
+ case "DescribeProvisionedProductPlan" -> describeProvisionedProductPlan(request);
+ case "DescribeProvisioningParameters" -> describeProvisioningParameters(request);
+ case "DescribeRecord" -> describeRecord(request);
+ case "DescribeServiceActionExecutionParameters" -> describeServiceActionExecutionParameters(request);
+ case "DisableAWSOrganizationsAccess" -> empty(() -> {});
+ case "DisassociateBudgetFromResource" -> empty(() -> service.disassociateBudgetFromResource(
+ text(request, "BudgetName"), text(request, "ResourceId")));
+ case "DisassociatePrincipalFromPortfolio" -> empty(() -> service.disassociatePrincipal(
+ text(request, "PortfolioId"), text(request, "PrincipalARN")));
+ case "DisassociateServiceActionFromProvisioningArtifact" -> empty(() -> service.disassociateServiceActionFromProvisioningArtifact(
+ text(request, "ProductId"), text(request, "ProvisioningArtifactId"), text(request, "ServiceActionId")));
+ case "EnableAWSOrganizationsAccess" -> Response.ok(objectMapper.createObjectNode()).build();
+ case "ExecuteProvisionedProductPlan" -> executeProvisionedProductPlan(request);
+ case "ExecuteProvisionedProductServiceAction" -> executeProvisionedProductServiceAction(request, region, accountId);
+ case "GetAWSOrganizationsAccessStatus" -> getAWSOrganizationsAccessStatus();
+ case "GetProvisionedProductOutputs" -> getProvisionedProductOutputs(request);
+ case "ImportAsProvisionedProduct" -> importAsProvisionedProduct(request, region, accountId);
+ case "ListAcceptedPortfolioShares" -> listPortfolios(region, accountId);
+ case "ListBudgetsForResource" -> listBudgetsForResource(text(request, "ResourceId"));
+ case "ListConstraintsForPortfolio" -> listConstraintsForPortfolio(text(request, "PortfolioId"), text(request, "ProductId"));
+ case "ListLaunchPaths" -> listLaunchPaths(request);
+ case "ListOrganizationPortfolioAccess" -> listOrganizationPortfolioAccess(request);
+ case "ListPortfolioAccess" -> listPortfolioAccess(request);
+ case "ListPrincipalsForPortfolio" -> listPrincipalsForPortfolio(text(request, "PortfolioId"));
+ case "ListProvisionedProductPlans" -> listProvisionedProductPlans(request);
+ case "ListProvisioningArtifactsForServiceAction" -> listProvisioningArtifactsForServiceAction(request);
+ case "ListRecordHistory" -> listRecordHistory();
+ case "ListResourcesForTagOption" -> listResourcesForTagOption(request);
+ case "ListServiceActions" -> listServiceActions();
+ case "ListServiceActionsForProvisioningArtifact" -> listServiceActionsForProvisioningArtifact(request);
+ case "ListStackInstancesForProvisionedProduct" -> listStackInstancesForProvisionedProduct(request);
+ case "NotifyProvisionProductEngineWorkflowResult" -> empty(() -> service.notifyProvisionProductEngineWorkflowResult(request));
+ case "NotifyTerminateProvisionedProductEngineWorkflowResult" -> empty(() ->
+ service.notifyTerminateProvisionedProductEngineWorkflowResult(request));
+ case "NotifyUpdateProvisionedProductEngineWorkflowResult" -> empty(() -> service.notifyUpdateProvisionedProductEngineWorkflowResult(request));
+ case "ScanProvisionedProducts" -> scanProvisionedProducts(request);
+ case "UpdateConstraint" -> updateConstraint(request, region, accountId);
+ case "UpdateProvisionedProduct" -> updateProvisionedProduct(request, region, accountId);
+ case "UpdateProvisionedProductProperties" -> updateProvisionedProductProperties(request);
+ case "UpdateServiceAction" -> updateServiceAction(request);
+ case "CreateProvisioningArtifact" -> createProvisioningArtifact(request, region, accountId);
+ case "DescribeCopyProductStatus" -> describeCopyProductStatus(request);
+ case "TerminateProvisionedProduct" -> terminateProvisionedProduct(request, region, accountId);
+ case "UpdateProvisioningArtifact" -> updateProvisioningArtifact(request);
+ default -> Response.status(400).entity(new AwsErrorResponse(
+ "InvalidParametersException", "Operation " + action + " is not supported.")).build();
+ };
+ } catch (AwsException e) {
+ return Response.status(e.getHttpStatus())
+ .entity(new AwsErrorResponse(e.jsonType(), e.getMessage())).build();
+ } catch (Exception e) {
+ LOG.errorf(e, "Service Catalog error processing %s", action);
+ return Response.status(500).entity(new AwsErrorResponse("InternalFailure", e.getMessage())).build();
+ }
+ }
+
+ private Response listPortfolios(String region, String accountId) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode details = response.putArray("PortfolioDetails");
+ service.listPortfolios(region, accountId).forEach(details::add);
+ return Response.ok(response).build();
+ }
+
+ private Response portfolioResponse(ObjectNode portfolio) {
+ return Response.ok(objectMapper.createObjectNode().set("PortfolioDetail", portfolio)).build();
+ }
+
+ private Response listProducts() {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode details = response.putArray("ProductViewDetails");
+ service.listProducts().forEach(product -> details.add(productView(product)));
+ return Response.ok(response).build();
+ }
+
+ private Response searchProducts(JsonNode request, String region, String accountId) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode summaries = response.putArray("ProductViewSummaries");
+ service.searchProducts(request, region, accountId).forEach(product ->
+ summaries.add(productView(product).path("ProductViewSummary")));
+ return Response.ok(response).build();
+ }
+
+ private Response provisioningArtifacts(String productId) {
+ ObjectNode product = service.describeProduct(productId);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode artifacts = response.putArray("ProvisioningArtifactDetails");
+ JsonNode ids = product.path("ProvisioningArtifactIds");
+ JsonNode names = product.path("ProvisioningArtifactNames");
+ for (int i = 0; i < ids.size(); i++) {
+ artifacts.add(objectMapper.createObjectNode().put("Id", ids.get(i).asText())
+ .put("Name", i < names.size() ? names.get(i).asText() : "")
+ .put("Active", true).put("Type", "CLOUD_FORMATION_TEMPLATE"));
+ }
+ return Response.ok(response).build();
+ }
+
+ private Response provisionProduct(JsonNode request, String region, String accountId) {
+ ObjectNode detail = service.provisionProduct(request, region, accountId);
+ ObjectNode record = objectMapper.createObjectNode();
+ record.put("RecordId", "rec-" + UUID.randomUUID().toString().replace("-", "").substring(0, 16));
+ record.put("ProvisionedProductId", detail.path("Id").asText());
+ record.put("Status", "SUCCEEDED");
+ record.put("CreatedTime", System.currentTimeMillis() / 1000.0);
+ return Response.ok(objectMapper.createObjectNode().set("RecordDetail", record)).build();
+ }
+
+ private Response searchProvisionedProducts(JsonNode request) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode products = response.putArray("ProvisionedProducts");
+ service.searchProvisionedProducts(request).forEach(products::add);
+ response.put("TotalResultsCount", products.size());
+ return Response.ok(response).build();
+ }
+
+ private Response productResponse(ObjectNode product) {
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("ProductViewDetail", productView(product));
+ ArrayNode artifacts = response.putArray("ProvisioningArtifactDetails");
+ JsonNode ids = product.path("ProvisioningArtifactIds");
+ JsonNode names = product.path("ProvisioningArtifactNames");
+ for (int i = 0; i < ids.size(); i++) {
+ artifacts.add(objectMapper.createObjectNode().put("Id", ids.get(i).asText())
+ .put("Name", i < names.size() ? names.get(i).asText() : "")
+ .put("Active", true).put("Type", "CLOUD_FORMATION_TEMPLATE"));
+ }
+ return Response.ok(response).build();
+ }
+
+ private ObjectNode productView(ObjectNode product) {
+ ObjectNode summary = product.deepCopy();
+ summary.put("ProductId", product.path("Id").asText());
+ ObjectNode view = objectMapper.createObjectNode();
+ view.set("ProductViewSummary", summary);
+ view.put("Status", "AVAILABLE");
+ return view;
+ }
+
+ private Response listTagOptions() {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode details = response.putArray("TagOptionDetails");
+ service.listTagOptions().forEach(details::add);
+ return Response.ok(response).build();
+ }
+
+ private Response tagOptionResponse(ObjectNode option) {
+ return Response.ok(objectMapper.createObjectNode().set("TagOptionDetail", option)).build();
+ }
+
+ private Response shareResponse(ObjectNode share) {
+ return Response.ok(objectMapper.createObjectNode()
+ .put("PortfolioShareToken", share.path("PortfolioShareToken").asText())
+ .put("Status", share.path("Status").asText())).build();
+ }
+
+ private Response shareStatusResponse(ObjectNode share) {
+ return Response.ok(objectMapper.createObjectNode()
+ .put("PortfolioShareToken", share.path("PortfolioShareToken").asText())
+ .put("Status", share.path("Status").asText())).build();
+ }
+
+ private Response empty(Runnable operation) {
+ operation.run();
+ return Response.ok(objectMapper.createObjectNode()).build();
+ }
+
+ private String text(JsonNode node, String field) {
+ JsonNode value = node == null ? null : node.get(field);
+ return value == null || value.isNull() ? null : value.asText();
+ }
+
+ private Response describeProductForUser(JsonNode request) {
+ String id = text(request, "Id");
+ if (id == null || id.isBlank()) {
+ id = text(request, "Name");
+ }
+ ObjectNode product = service.describeProduct(id);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("ProductViewSummary", productView(product).path("ProductViewSummary"));
+ ArrayNode artifacts = response.putArray("ProvisioningArtifacts");
+ JsonNode ids = product.path("ProvisioningArtifactIds");
+ JsonNode names = product.path("ProvisioningArtifactNames");
+ for (int i = 0; i < ids.size(); i++) {
+ artifacts.add(objectMapper.createObjectNode()
+ .put("Id", ids.get(i).asText())
+ .put("Name", i < names.size() ? names.get(i).asText() : "")
+ .put("CreatedTime", product.path("CreatedTime").asDouble(0.0)));
+ }
+ return Response.ok(response).build();
+ }
+
+ private Response describePortfolioShares(JsonNode request) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode details = response.putArray("PortfolioShareDetails");
+ String type = text(request, "Type");
+ // Validated only when supplied: botocore marks Type required, but this emulator has
+ // always treated it as an optional filter and tests pin that leniency (lesson 3's
+ // territory). What matters here is that a supplied value is a real share type
+ // rather than silently filtering everything out.
+ if (type != null) {
+ ServiceCatalogService.requireEnum(type, "Type",
+ ServiceCatalogService.DESCRIBE_PORTFOLIO_SHARE_TYPES);
+ }
+ service.describePortfolioShares(text(request, "PortfolioId"), type).forEach(details::add);
+ return Response.ok(response).build();
+ }
+
+ private Response listPortfoliosForProduct(String productId) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode details = response.putArray("PortfolioDetails");
+ service.listPortfoliosForProduct(productId).forEach(details::add);
+ return Response.ok(response).build();
+ }
+
+ private Response copyProductResponse(String token) {
+ return Response.ok(objectMapper.createObjectNode().put("CopyProductToken", token)).build();
+ }
+
+ private Response describeProvisioningArtifact(JsonNode request) {
+ String artifactId = text(request, "ProvisioningArtifactId");
+ String productId = text(request, "ProductId");
+ String artifactName = text(request, "ProvisioningArtifactName");
+ ObjectNode product = service.describeProduct(productId != null ? productId : artifactId);
+ JsonNode ids = product.path("ProvisioningArtifactIds");
+ JsonNode names = product.path("ProvisioningArtifactNames");
+ int index = -1;
+ if (artifactId != null) {
+ for (int i = 0; i < ids.size(); i++) {
+ if (artifactId.equals(ids.get(i).asText())) {
+ index = i;
+ break;
+ }
+ }
+ } else if (artifactName != null) {
+ for (int i = 0; i < names.size(); i++) {
+ if (artifactName.equals(names.get(i).asText())) {
+ index = i;
+ break;
+ }
+ }
+ }
+ if (index < 0) {
+ throw new AwsException("ResourceNotFoundException",
+ "Unknown provisioning artifact: " + (artifactId != null ? artifactId : artifactName), 400);
+ }
+ ObjectNode detail = objectMapper.createObjectNode();
+ detail.put("Id", ids.get(index).asText());
+ detail.put("Name", index < names.size() ? names.get(index).asText() : "");
+ detail.put("Type", "CLOUD_FORMATION_TEMPLATE");
+ detail.put("CreatedTime", product.path("CreatedTime").asDouble());
+ detail.put("Active", true);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("ProvisioningArtifactDetail", detail);
+ response.put("Status", "AVAILABLE");
+ return Response.ok(response).build();
+ }
+
+ private Response deletePortfolioShare(JsonNode request) {
+ String token = service.deletePortfolioShare(request);
+ ObjectNode response = objectMapper.createObjectNode();
+ if (token != null) {
+ response.put("PortfolioShareToken", token);
+ }
+ return Response.ok(response).build();
+ }
+
+ private Response batchAssociateServiceActionWithProvisioningArtifact(JsonNode request) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode failed = response.putArray("FailedServiceActionAssociations");
+ service.batchAssociateServiceActionWithProvisioningArtifact(request).forEach(failed::add);
+ return Response.ok(response).build();
+ }
+
+ private Response batchDisassociateServiceActionFromProvisioningArtifact(JsonNode request) {
+ ObjectNode response = objectMapper.createObjectNode();
+ var failures = service.batchDisassociateServiceActionFromProvisioningArtifact(request);
+ if (!failures.isEmpty()) {
+ ArrayNode failed = response.putArray("FailedServiceActionAssociations");
+ failures.forEach(failed::add);
+ }
+ return Response.ok(response).build();
+ }
+
+ private Response createConstraintResponse(JsonNode request, String region, String accountId) {
+ ObjectNode constraint = service.createConstraint(request, region, accountId);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("ConstraintDetail", constraint);
+ response.set("ConstraintParameters", request.path("Parameters"));
+ response.put("Status", "AVAILABLE");
+ return Response.ok(response).build();
+ }
+
+ private Response createProvisionedProductPlan(JsonNode request, String region, String accountId) {
+ ObjectNode plan = service.createProvisionedProductPlan(request, region, accountId);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("PlanId", plan.path("PlanId").asText());
+ response.put("PlanName", plan.path("PlanName").asText());
+ response.put("ProvisionProductId", plan.path("ProvisionProductId").asText());
+ response.put("ProvisionedProductName", plan.path("ProvisionedProductName").asText());
+ response.put("ProvisioningArtifactId", plan.path("ProvisioningArtifactId").asText());
+ return Response.ok(response).build();
+ }
+
+ private Response createServiceActionResponse(ObjectNode action) {
+ ObjectNode summary = objectMapper.createObjectNode();
+ summary.put("Id", action.path("Id").asText());
+ summary.put("Name", action.path("Name").asText());
+ summary.put("DefinitionType", action.path("DefinitionType").asText());
+ summary.put("Description", action.path("Description").asText());
+ ObjectNode detail = objectMapper.createObjectNode();
+ detail.set("Definition", action.path("Definition"));
+ detail.set("ServiceActionSummary", summary);
+ return Response.ok(objectMapper.createObjectNode().set("ServiceActionDetail", detail)).build();
+ }
+
+ private Response describeConstraint(JsonNode request) {
+ ObjectNode constraint = service.describeConstraint(text(request, "Id"));
+ ObjectNode detail = objectMapper.createObjectNode();
+ detail.put("ConstraintId", constraint.path("ConstraintId").asText());
+ detail.put("Description", constraint.path("Description").asText());
+ detail.put("Owner", constraint.path("Owner").asText());
+ detail.put("PortfolioId", constraint.path("PortfolioId").asText());
+ detail.put("ProductId", constraint.path("ProductId").asText());
+ detail.put("Type", constraint.path("Type").asText());
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("ConstraintDetail", detail);
+ response.put("Status", "AVAILABLE");
+ return Response.ok(response).build();
+ }
+
+ private Response describeProductView(JsonNode request) {
+ String id = text(request, "Id");
+ if (id == null || id.isBlank()) {
+ throw new AwsException("InvalidParametersException", "Id is required", 400);
+ }
+ ObjectNode product = service.describeProduct(id);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("ProductViewSummary", productView(product).path("ProductViewSummary"));
+ ArrayNode artifacts = response.putArray("ProvisioningArtifacts");
+ JsonNode ids = product.path("ProvisioningArtifactIds");
+ JsonNode names = product.path("ProvisioningArtifactNames");
+ for (int i = 0; i < ids.size(); i++) {
+ artifacts.add(objectMapper.createObjectNode()
+ .put("Id", ids.get(i).asText())
+ .put("Name", i < names.size() ? names.get(i).asText() : "")
+ .put("CreatedTime", product.path("CreatedTime").asDouble(0.0)));
+ }
+ return Response.ok(response).build();
+ }
+
+ private Response describeProvisionedProduct(JsonNode request) {
+ ObjectNode detail = service.describeProvisionedProduct(text(request, "Id"), text(request, "Name"));
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("ProvisionedProductDetail", detail);
+ return Response.ok(response).build();
+ }
+
+ private Response describeProvisionedProductPlan(JsonNode request) {
+ ObjectNode plan = service.describeProvisionedProductPlan(text(request, "PlanId"));
+ ObjectNode details = objectMapper.createObjectNode();
+ details.put("PlanId", plan.path("Id").asText());
+ if (plan.has("PlanName")) {
+ details.put("PlanName", plan.get("PlanName").asText());
+ }
+ if (plan.has("ProductId")) {
+ details.put("ProductId", plan.get("ProductId").asText());
+ }
+ if (plan.has("ProvisionProductId")) {
+ details.put("ProvisionProductId", plan.get("ProvisionProductId").asText());
+ }
+ if (plan.has("ProvisionedProductName")) {
+ details.put("ProvisionProductName", plan.get("ProvisionedProductName").asText());
+ }
+ if (plan.has("ProvisioningArtifactId")) {
+ details.put("ProvisioningArtifactId", plan.get("ProvisioningArtifactId").asText());
+ }
+ if (plan.has("CreatedTime")) {
+ details.put("CreatedTime", plan.get("CreatedTime").asDouble());
+ }
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("ProvisionedProductPlanDetails", details);
+ return Response.ok(response).build();
+ }
+
+ private Response describeProvisioningParameters(JsonNode request) {
+ ObjectNode product = service.describeProvisioningParameters(request);
+ ObjectNode response = objectMapper.createObjectNode();
+ JsonNode storedParams = product.path("ProvisioningArtifactParameters");
+ if (storedParams.isArray() && !storedParams.isEmpty()) {
+ ArrayNode params = response.putArray("ProvisioningArtifactParameters");
+ for (JsonNode param : storedParams) {
+ ObjectNode p = objectMapper.createObjectNode();
+ if (param.has("Name")) {
+ p.put("ParameterKey", param.get("Name").asText());
+ }
+ if (param.has("Description")) {
+ p.put("Description", param.get("Description").asText());
+ }
+ if (param.has("Type")) {
+ p.put("ParameterType", param.get("Type").asText());
+ }
+ params.add(p);
+ }
+ }
+ return Response.ok(response).build();
+ }
+
+ private Response describeRecord(JsonNode request) {
+ ObjectNode record = service.describeRecord(text(request, "Id"));
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("RecordDetail", record);
+ return Response.ok(response).build();
+ }
+
+ private Response describeServiceActionExecutionParameters(JsonNode request) {
+ service.describeServiceActionExecutionParameters(
+ text(request, "ProvisionedProductId"), text(request, "ServiceActionId"));
+ ObjectNode response = objectMapper.createObjectNode();
+ response.putArray("ServiceActionParameters");
+ return Response.ok(response).build();
+ }
+
+ private Response executeProvisionedProductPlan(JsonNode request) {
+ ObjectNode record = service.executeProvisionedProductPlan(request);
+ return Response.ok(objectMapper.createObjectNode().set("RecordDetail", record)).build();
+ }
+
+ private Response executeProvisionedProductServiceAction(JsonNode request, String region, String accountId) {
+ ObjectNode product = service.executeProvisionedProductServiceAction(request, region, accountId);
+ ObjectNode record = objectMapper.createObjectNode();
+ record.put("RecordId", product.path("RecordId").asText());
+ record.put("ProvisionedProductId", product.path("Id").asText());
+ record.put("ProvisionedProductName", product.path("Name").asText());
+ record.put("ProvisionedProductType", product.path("Type").asText());
+ record.put("ProductId", product.path("ProductId").asText());
+ record.put("ProvisioningArtifactId", product.path("ProvisioningArtifactId").asText());
+ record.put("Status", "SUCCEEDED");
+ record.put("CreatedTime", System.currentTimeMillis() / 1000.0);
+ record.put("UpdatedTime", System.currentTimeMillis() / 1000.0);
+ return Response.ok(objectMapper.createObjectNode().set("RecordDetail", record)).build();
+ }
+
+ private Response getAWSOrganizationsAccessStatus() {
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("AccessStatus", "ENABLED");
+ return Response.ok(response).build();
+ }
+
+ private Response getProvisionedProductOutputs(JsonNode request) {
+ service.getProvisionedProductOutputs(request);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.putArray("Outputs");
+ return Response.ok(response).build();
+ }
+
+ private Response importAsProvisionedProduct(JsonNode request, String region, String accountId) {
+ ObjectNode detail = service.importAsProvisionedProduct(request, region, accountId);
+ ObjectNode record = objectMapper.createObjectNode();
+ record.put("RecordId", detail.path("RecordId").asText());
+ record.put("ProvisionedProductId", detail.path("Id").asText());
+ record.put("ProvisionedProductName", detail.path("Name").asText());
+ record.put("Status", "SUCCEEDED");
+ record.put("CreatedTime", System.currentTimeMillis() / 1000.0);
+ record.put("ProductId", detail.path("ProductId").asText());
+ record.put("ProvisioningArtifactId", detail.path("ProvisioningArtifactId").asText());
+ record.put("RecordType", "IMPORT");
+ return Response.ok(objectMapper.createObjectNode().set("RecordDetail", record)).build();
+ }
+
+ private Response listBudgetsForResource(String resourceId) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode budgets = response.putArray("Budgets");
+ service.listBudgetsForResource(resourceId).forEach(assoc ->
+ budgets.add(objectMapper.createObjectNode().put("BudgetName", text(assoc, "BudgetName"))));
+ return Response.ok(response).build();
+ }
+
+ private Response listConstraintsForPortfolio(String portfolioId, String productId) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode details = response.putArray("ConstraintDetails");
+ service.listConstraintsForPortfolio(portfolioId, productId).forEach(details::add);
+ return Response.ok(response).build();
+ }
+
+ private Response listLaunchPaths(JsonNode request) {
+ String productId = text(request, "ProductId");
+ if (productId == null || productId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ProductId is required", 400);
+ }
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode summaries = response.putArray("LaunchPathSummaries");
+ service.listPortfoliosForProduct(productId).forEach(portfolio -> {
+ ObjectNode summary = objectMapper.createObjectNode();
+ summary.put("Id", portfolio.path("Id").asText());
+ summary.put("Name", portfolio.path("DisplayName").asText());
+ if (portfolio.has("Tags")) {
+ summary.set("Tags", portfolio.get("Tags").deepCopy());
+ }
+ summaries.add(summary);
+ });
+ return Response.ok(response).build();
+ }
+
+ private Response listOrganizationPortfolioAccess(JsonNode request) {
+ String nodeType = text(request, "OrganizationNodeType");
+ if (nodeType == null || nodeType.isBlank()) {
+ throw new AwsException("InvalidParametersException", "OrganizationNodeType is required", 400);
+ }
+ ServiceCatalogService.requireEnum(nodeType, "OrganizationNodeType",
+ ServiceCatalogService.ORGANIZATION_NODE_TYPES);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode nodes = response.putArray("OrganizationNodes");
+ service.describePortfolioShares(text(request, "PortfolioId"), nodeType).forEach(share -> {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("Type", share.path("Type").asText());
+ node.put("Value", share.path("PrincipalId").asText());
+ nodes.add(node);
+ });
+ return Response.ok(response).build();
+ }
+
+ private Response listPortfolioAccess(JsonNode request) {
+ String portfolioId = text(request, "PortfolioId");
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode ids = response.putArray("AccountIds");
+ service.listPortfolioAccess(portfolioId, text(request, "OrganizationParentId")).forEach(ids::add);
+ return Response.ok(response).build();
+ }
+
+ private Response listPrincipalsForPortfolio(String portfolioId) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode principals = response.putArray("Principals");
+ service.listPrincipalsForPortfolio(portfolioId).forEach(principals::add);
+ return Response.ok(response).build();
+ }
+
+ private Response listProvisionedProductPlans(JsonNode request) {
+ String provisionProductId = text(request, "ProvisionProductId");
+ int pageSize = 20;
+ JsonNode pageSizeNode = request.get("PageSize");
+ if (pageSizeNode != null && pageSizeNode.isInt()) {
+ pageSize = Math.max(0, Math.min(20, pageSizeNode.asInt()));
+ }
+ String pageToken = text(request, "PageToken");
+ int offset = 0;
+ if (pageToken != null && !pageToken.isBlank()) {
+ try {
+ offset = Integer.parseInt(pageToken);
+ } catch (NumberFormatException e) {
+ throw new AwsException("InvalidParametersException", "Invalid PageToken: " + pageToken, 400);
+ }
+ }
+
+ var all = service.listProvisionedProductPlans(provisionProductId);
+ var page = all.stream().skip(offset).limit(pageSize).toList();
+
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode plans = response.putArray("ProvisionedProductPlans");
+ for (ObjectNode product : page) {
+ ObjectNode plan = objectMapper.createObjectNode();
+ plan.put("PlanId", text(product, "Id"));
+ plan.put("PlanName", text(product, "PlanName"));
+ plan.put("PlanType", "CLOUDFORMATION");
+ plan.put("ProvisionProductId", text(product, "ProvisionProductId"));
+ plan.put("ProvisionProductName", text(product, "ProvisionedProductName"));
+ plan.put("ProvisioningArtifactId", text(product, "ProvisioningArtifactId"));
+ plans.add(plan);
+ }
+ int nextOffset = offset + page.size();
+ if (nextOffset < all.size()) {
+ response.put("NextPageToken", String.valueOf(nextOffset));
+ }
+ return Response.ok(response).build();
+ }
+
+ private Response listProvisioningArtifactsForServiceAction(JsonNode request) {
+ String serviceActionId = text(request, "ServiceActionId");
+ if (serviceActionId == null || serviceActionId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ServiceActionId is required", 400);
+ }
+ ObjectNode response = objectMapper.createObjectNode();
+ response.putArray("ProvisioningArtifactViews");
+ return Response.ok(response).build();
+ }
+
+ private Response listRecordHistory() {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode details = response.putArray("RecordDetails");
+ service.listRecordHistory().forEach(product -> {
+ ObjectNode record = objectMapper.createObjectNode();
+ record.put("ProvisionedProductId", product.path("Id").asText());
+ record.put("ProvisionedProductName", product.path("Name").asText());
+ record.put("ProvisionedProductType", product.path("Type").asText());
+ record.put("ProductId", product.path("ProductId").asText());
+ record.put("ProvisioningArtifactId", product.path("ProvisioningArtifactId").asText());
+ record.put("CreatedTime", product.path("CreatedTime").asDouble());
+ record.put("Status", "SUCCEEDED");
+ details.add(record);
+ });
+ return Response.ok(response).build();
+ }
+
+ private Response listResourcesForTagOption(JsonNode request) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode details = response.putArray("ResourceDetails");
+ service.listResourcesForTagOption(text(request, "TagOptionId"), text(request, "ResourceType")).forEach(details::add);
+ return Response.ok(response).build();
+ }
+
+ private Response listServiceActions() {
+ ObjectNode response = objectMapper.createObjectNode();
+ var summaries = response.putArray("ServiceActionSummaries");
+ service.listServiceActions().forEach(action -> {
+ ObjectNode summary = objectMapper.createObjectNode();
+ summary.put("Id", action.path("Id").asText());
+ if (action.has("Name")) {
+ summary.put("Name", action.get("Name").asText());
+ }
+ if (action.has("Description")) {
+ summary.put("Description", action.get("Description").asText());
+ }
+ summary.put("DefinitionType", "SSM_AUTOMATION");
+ summaries.add(summary);
+ });
+ return Response.ok(response).build();
+ }
+
+ private Response listServiceActionsForProvisioningArtifact(JsonNode request) {
+ String productId = text(request, "ProductId");
+ if (productId == null || productId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ProductId is required", 400);
+ }
+ String artifactId = text(request, "ProvisioningArtifactId");
+ if (artifactId == null || artifactId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ProvisioningArtifactId is required", 400);
+ }
+ ObjectNode product = service.describeProduct(productId);
+ JsonNode ids = product.path("ProvisioningArtifactIds");
+ boolean found = false;
+ for (JsonNode id : ids) {
+ if (artifactId.equals(id.asText())) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ throw new AwsException("ResourceNotFoundException",
+ "Unknown provisioning artifact: " + artifactId, 400);
+ }
+ ObjectNode response = objectMapper.createObjectNode();
+ response.putArray("ServiceActionSummaries");
+ return Response.ok(response).build();
+ }
+
+ private Response listStackInstancesForProvisionedProduct(JsonNode request) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode instances = response.putArray("StackInstances");
+ service.listStackInstancesForProvisionedProduct(text(request, "ProvisionedProductId")).forEach(instances::add);
+ return Response.ok(response).build();
+ }
+
+ private Response scanProvisionedProducts(JsonNode request) {
+ List<ObjectNode> all = service.scanProvisionedProducts();
+ int pageSize = request.path("PageSize").asInt(0);
+ int offset = 0;
+ String pageToken = text(request, "PageToken");
+ if (pageToken != null && !pageToken.isBlank()) {
+ try {
+ offset = Integer.parseInt(pageToken);
+ } catch (NumberFormatException e) {
+ throw new AwsException("InvalidParametersException", "Invalid PageToken: " + pageToken, 400);
+ }
+ }
+ int start = Math.min(offset, all.size());
+ int end = pageSize > 0 ? Math.min(start + pageSize, all.size()) : all.size();
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode products = response.putArray("ProvisionedProducts");
+ for (int i = start; i < end; i++) {
+ products.add(all.get(i));
+ }
+ if (end < all.size()) {
+ response.put("NextPageToken", String.valueOf(end));
+ }
+ return Response.ok(response).build();
+ }
+
+ private Response updateConstraint(JsonNode request, String region, String accountId) {
+ String id = text(request, "Id");
+ ObjectNode constraint = service.updateConstraint(id, request);
+ ObjectNode detail = objectMapper.createObjectNode();
+ detail.put("ConstraintId", id);
+ if (constraint.has("Description")) {
+ detail.put("Description", constraint.get("Description").asText());
+ }
+ detail.put("Owner", accountId);
+ detail.put("PortfolioId", text(constraint, "PortfolioId"));
+ detail.put("ProductId", text(constraint, "ProductId"));
+ detail.put("Type", text(constraint, "Type"));
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("ConstraintDetail", detail);
+ if (constraint.has("Parameters")) {
+ response.set("ConstraintParameters", constraint.get("Parameters"));
+ }
+ response.put("Status", "AVAILABLE");
+ return Response.ok(response).build();
+ }
+
+ private Response updateProvisionedProduct(JsonNode request, String region, String accountId) {
+ ObjectNode product = service.updateProvisionedProduct(request, region, accountId);
+ ObjectNode record = objectMapper.createObjectNode();
+ record.put("RecordId", product.path("RecordId").asText());
+ record.put("ProvisionedProductId", product.path("Id").asText());
+ record.put("ProvisionedProductName", product.path("Name").asText());
+ record.put("ProductId", product.path("ProductId").asText());
+ record.put("ProvisioningArtifactId", product.path("ProvisioningArtifactId").asText());
+ record.put("Status", "SUCCEEDED");
+ record.put("CreatedTime", product.path("CreatedTime").asDouble());
+ record.put("UpdatedTime", System.currentTimeMillis() / 1000.0);
+ return Response.ok(objectMapper.createObjectNode().set("RecordDetail", record)).build();
+ }
+
+ private Response updateProvisionedProductProperties(JsonNode request) {
+ ObjectNode result = service.updateProvisionedProductProperties(text(request, "ProvisionedProductId"), request);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("ProvisionedProductId", result.path("Id").asText());
+ response.set("ProvisionedProductProperties", result.path("ProvisionedProductProperties"));
+ response.put("RecordId", result.path("RecordId").asText());
+ response.put("Status", "SUCCEEDED");
+ return Response.ok(response).build();
+ }
+
+ private Response updateServiceAction(JsonNode request) {
+ ObjectNode action = service.updateServiceAction(text(request, "Id"), request);
+ ObjectNode summary = objectMapper.createObjectNode();
+ summary.put("Id", action.path("Id").asText());
+ if (action.has("Name")) {
+ summary.put("Name", action.get("Name").asText());
+ }
+ if (action.has("Description")) {
+ summary.put("Description", action.get("Description").asText());
+ }
+ summary.put("DefinitionType", "SSM_AUTOMATION");
+ ObjectNode detail = objectMapper.createObjectNode();
+ detail.set("ServiceActionSummary", summary);
+ if (action.has("Definition")) {
+ detail.set("Definition", action.get("Definition"));
+ }
+ return Response.ok(objectMapper.createObjectNode().set("ServiceActionDetail", detail)).build();
+ }
+
+ private Response createProvisioningArtifact(JsonNode request, String region, String accountId) {
+ ObjectNode detail = service.createProvisioningArtifact(request, region, accountId);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("ProvisioningArtifactDetail", detail);
+ response.put("Status", "AVAILABLE");
+ return Response.ok(response).build();
+ }
+
+ private Response describeCopyProductStatus(JsonNode request) {
+ String token = text(request, "CopyProductToken");
+ ObjectNode record = service.describeCopyProductStatus(token);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("CopyProductStatus", record.path("Status").asText("SUCCEEDED"));
+ String targetProductId = record.path("TargetProductId").asText("");
+ if (!targetProductId.isEmpty()) {
+ response.put("TargetProductId", targetProductId);
+ }
+ return Response.ok(response).build();
+ }
+
+ private Response terminateProvisionedProduct(JsonNode request, String region, String accountId) {
+ ObjectNode product = service.terminateProvisionedProduct(request, region, accountId);
+ ObjectNode record = objectMapper.createObjectNode();
+ record.put("RecordId", product.path("RecordId").asText());
+ record.put("ProvisionedProductId", product.path("Id").asText());
+ record.put("ProvisionedProductName", product.path("Name").asText());
+ record.put("ProductId", product.path("ProductId").asText());
+ record.put("ProvisioningArtifactId", product.path("ProvisioningArtifactId").asText());
+ record.put("Status", "SUCCEEDED");
+ record.put("CreatedTime", product.path("CreatedTime").asDouble(0.0));
+ record.put("UpdatedTime", product.path("UpdatedTime").asDouble(0.0));
+ record.put("RecordType", "TERMINATE_PROVISIONED_PRODUCT");
+ return Response.ok(objectMapper.createObjectNode().set("RecordDetail", record)).build();
+ }
+
+ private Response updateProvisioningArtifact(JsonNode request) {
+ String productId = text(request, "ProductId");
+ String artifactId = text(request, "ProvisioningArtifactId");
+ ObjectNode detail = service.updateProvisioningArtifact(productId, artifactId, request);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.set("ProvisioningArtifactDetail", detail);
+ response.put("Status", "AVAILABLE");
+ return Response.ok(response).build();
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogService.java b/src/main/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogService.java
new file mode 100644
index 0000000000..4ac0ef24ad
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogService.java
@@ -0,0 +1,1585 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.storage.StorageBackend;
+import io.github.hectorvent.floci.core.storage.StorageFactory;
+import io.github.hectorvent.floci.services.organizations.OrganizationsService;
+import io.github.hectorvent.floci.services.organizations.model.CreateAccountStatus;
+import io.github.hectorvent.floci.services.organizations.model.OrganizationAccount;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+
+import java.time.Instant;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.Optional;
+
+@ApplicationScoped
+public class ServiceCatalogService {
+
+ static final String CONTROL_TOWER_PORTFOLIO_ID = "port-flocicontrol1";
+ static final String CONTROL_TOWER_PORTFOLIO_NAME = "AWS Control Tower Account Factory Portfolio";
+ static final String CONTROL_TOWER_PROVIDER_NAME = "AWS Control Tower";
+ static final String CONTROL_TOWER_PRODUCT_ID = "prod-flocicontrol1";
+ static final String CONTROL_TOWER_PRODUCT_NAME = "AWS Control Tower Account Factory";
+ static final String CONTROL_TOWER_ARTIFACT_ID = "pa-flocicontrol1";
+
+ private final StorageBackend<String, ObjectNode> portfolioStore;
+ private final StorageBackend<String, ObjectNode> productStore;
+ private final StorageBackend<String, ObjectNode> tagOptionStore;
+ private final StorageBackend<String, ObjectNode> associationStore;
+ private final StorageBackend<String, ObjectNode> shareStore;
+ private final StorageBackend<String, ObjectNode> provisionedProductStore;
+ private final ObjectMapper objectMapper;
+ private final OrganizationsService organizationsService;
+
+ @Inject
+ public ServiceCatalogService(StorageFactory storageFactory, ObjectMapper objectMapper,
+ OrganizationsService organizationsService) {
+ this.portfolioStore = storageFactory.create("servicecatalog", "servicecatalog-portfolios.json",
+ new TypeReference<Map<String, ObjectNode>>() {});
+ this.productStore = storageFactory.create("servicecatalog", "servicecatalog-products.json",
+ new TypeReference<Map<String, ObjectNode>>() {});
+ this.tagOptionStore = storageFactory.create("servicecatalog", "servicecatalog-tag-options.json",
+ new TypeReference<Map<String, ObjectNode>>() {});
+ this.associationStore = storageFactory.create("servicecatalog", "servicecatalog-associations.json",
+ new TypeReference<Map<String, ObjectNode>>() {});
+ this.shareStore = storageFactory.create("servicecatalog", "servicecatalog-shares.json",
+ new TypeReference<Map<String, ObjectNode>>() {});
+ this.provisionedProductStore = storageFactory.create("servicecatalog", "servicecatalog-provisioned-products.json",
+ new TypeReference<Map<String, ObjectNode>>() {});
+ this.objectMapper = objectMapper;
+ this.organizationsService = organizationsService;
+ }
+
+ public ObjectNode createPortfolio(JsonNode request, String region, String accountId) {
+ requireText(request, "DisplayName");
+ requireText(request, "ProviderName");
+ String id = id("port");
+ ObjectNode portfolio = copy(request);
+ portfolio.put("Id", id);
+ portfolio.put("ARN", "arn:aws:catalog:" + region + ":" + accountId + ":portfolio/" + id);
+ portfolio.put("CreatedTime", Instant.now().toEpochMilli() / 1000.0);
+ portfolioStore.put(id, portfolio);
+ return portfolio.deepCopy();
+ }
+
+ public ObjectNode updatePortfolio(String id, JsonNode request) {
+ ObjectNode portfolio = require(portfolioStore, id, "portfolio");
+ copyIfPresent(request, portfolio, "DisplayName", "ProviderName", "Description", "Tags");
+ portfolioStore.put(id, portfolio);
+ return portfolio.deepCopy();
+ }
+
+ public ObjectNode describePortfolio(String id) {
+ return require(portfolioStore, id, "portfolio").deepCopy();
+ }
+
+ public synchronized List<ObjectNode> listPortfolios(String region, String accountId) {
+ ensureControlTowerCatalog(region, accountId);
+ return portfolioStore.scan(key -> true).stream().map(ObjectNode::deepCopy).toList();
+ }
+
+ private void ensureControlTowerCatalog(String region, String accountId) {
+ boolean exists = portfolioStore.scan(key -> true).stream()
+ .anyMatch(portfolio -> CONTROL_TOWER_PORTFOLIO_NAME.equals(text(portfolio, "DisplayName"))
+ && CONTROL_TOWER_PROVIDER_NAME.equals(text(portfolio, "ProviderName")));
+ if (!exists) {
+ ObjectNode portfolio = objectMapper.createObjectNode();
+ portfolio.put("Id", CONTROL_TOWER_PORTFOLIO_ID);
+ portfolio.put("ARN", "arn:aws:catalog:" + region + ":" + accountId
+ + ":portfolio/" + CONTROL_TOWER_PORTFOLIO_ID);
+ portfolio.put("DisplayName", CONTROL_TOWER_PORTFOLIO_NAME);
+ portfolio.put("ProviderName", CONTROL_TOWER_PROVIDER_NAME);
+ portfolio.put("Description", "AWS Control Tower Account Factory Portfolio");
+ portfolio.put("CreatedTime", Instant.now().toEpochMilli() / 1000.0);
+ portfolioStore.put(CONTROL_TOWER_PORTFOLIO_ID, portfolio);
+ }
+ if (productStore.get(CONTROL_TOWER_PRODUCT_ID).isEmpty()) {
+ ObjectNode product = objectMapper.createObjectNode();
+ product.put("Id", CONTROL_TOWER_PRODUCT_ID);
+ product.put("ARN", "arn:aws:catalog:" + region + ":" + accountId
+ + ":product/" + CONTROL_TOWER_PRODUCT_ID);
+ product.put("Name", CONTROL_TOWER_PRODUCT_NAME);
+ product.put("Owner", CONTROL_TOWER_PROVIDER_NAME);
+ product.put("Type", "CLOUD_FORMATION_TEMPLATE");
+ product.put("CreatedTime", Instant.now().toEpochMilli() / 1000.0);
+ product.putArray("ProvisioningArtifactIds").add(CONTROL_TOWER_ARTIFACT_ID);
+ product.putArray("ProvisioningArtifactNames").add("AWS Control Tower Account Factory");
+ productStore.put(CONTROL_TOWER_PRODUCT_ID, product);
+ }
+ String associationId = associationId("product", CONTROL_TOWER_PORTFOLIO_ID,
+ CONTROL_TOWER_PRODUCT_ID);
+ if (associationStore.get(associationId).isEmpty()) {
+ associationStore.put(associationId, objectMapper.createObjectNode()
+ .put("Type", "PRODUCT").put("PortfolioId", CONTROL_TOWER_PORTFOLIO_ID)
+ .put("ProductId", CONTROL_TOWER_PRODUCT_ID));
+ }
+ }
+
+ /**
+ * AWS refuses to delete a portfolio that "has associated products, users, constraints, or
+ * shared accounts" rather than cascading. Every one of those rows carries the portfolio's
+ * id in {@code PortfolioId} — products, principals and constraints alike — so a single scan
+ * covers the documented list. Tag-option associations key off {@code ResourceId} instead and
+ * are deliberately not counted: they are absent from AWS's list, and the previous cascade
+ * never removed them either, so nothing is orphaned that was not orphaned before.
+ */
+ public void deletePortfolio(String id) {
+ require(portfolioStore, id, "portfolio");
+ boolean hasAssociations = associationStore.scan(key -> true).stream()
+ .anyMatch(value -> id.equals(text(value, "PortfolioId")));
+ boolean hasShares = shareStore.keys().stream().anyMatch(key -> key.startsWith(id + "|"));
+ if (hasAssociations || hasShares) {
+ throw inUse("portfolio", id,
+ "it has associated products, users, constraints, or shared accounts");
+ }
+ portfolioStore.delete(id);
+ }
+
+ public ObjectNode createProduct(JsonNode request, String region, String accountId) {
+ requireText(request, "Name");
+ requireText(request, "Owner");
+ String id = id("prod");
+ ObjectNode product = copy(request);
+ product.put("Id", id);
+ product.put("ARN", "arn:aws:catalog:" + region + ":" + accountId + ":product/" + id);
+ product.put("CreatedTime", Instant.now().toEpochMilli() / 1000.0);
+ ArrayNode artifactIds = product.putArray("ProvisioningArtifactIds");
+ ArrayNode artifactNames = product.putArray("ProvisioningArtifactNames");
+ JsonNode artifacts = request.path("ProvisioningArtifactParameters");
+ if (artifacts.isArray()) {
+ for (JsonNode artifact : artifacts) {
+ artifactIds.add(id("pa"));
+ artifactNames.add(artifact.path("Name").asText(""));
+ }
+ }
+ if (artifactIds.isEmpty()) {
+ artifactIds.add(id("pa"));
+ artifactNames.add("v1");
+ }
+ productStore.put(id, product);
+ return product.deepCopy();
+ }
+
+ public ObjectNode updateProduct(String id, JsonNode request) {
+ ObjectNode product = requireProduct(id);
+ copyIfPresent(request, product, "Name", "Owner", "Description", "Distributor", "SupportDescription",
+ "SupportEmail", "SupportUrl", "Tags", "ProvisioningArtifactParameters");
+ productStore.put(text(product, "Id"), product);
+ return product.deepCopy();
+ }
+
+ public ObjectNode describeProduct(String id) {
+ return requireProduct(id).deepCopy();
+ }
+
+ public List<ObjectNode> listProducts() {
+ return productStore.scan(key -> true).stream().map(ObjectNode::deepCopy).toList();
+ }
+
+ public synchronized List<ObjectNode> searchProducts(JsonNode request, String region, String accountId) {
+ ensureControlTowerCatalog(region, accountId);
+ JsonNode terms = request.path("Filters").path("FullTextSearch");
+ return productStore.scan(key -> true).stream()
+ .filter(product -> !terms.isArray() || terms.isEmpty()
+ || java.util.stream.StreamSupport.stream(terms.spliterator(), false)
+ .allMatch(term -> (text(product, "Name") + " " + text(product, "Owner"))
+ .toLowerCase().contains(term.asText().toLowerCase())))
+ .map(ObjectNode::deepCopy).toList();
+ }
+
+ public ObjectNode provisionProduct(JsonNode request, String region, String accountId) {
+ ensureControlTowerCatalog(region, accountId);
+ String name = requireText(request, "ProvisionedProductName");
+ ObjectNode product = resolveProduct(request);
+ String productId = text(product, "Id");
+ String artifactId = resolveArtifactId(product, request);
+ ObjectNode existing = provisionedProductStore.scan(key -> true).stream()
+ .filter(candidate -> name.equals(text(candidate, "Name")))
+ .findFirst().orElse(null);
+ if (existing != null) {
+ return existing.deepCopy();
+ }
+ String provisionedId = id("pp");
+ ObjectNode provisioned = objectMapper.createObjectNode();
+ provisioned.put("Id", provisionedId);
+ provisioned.put("Arn", "arn:aws:servicecatalog:" + region + ":" + accountId
+ + ":provisionedproduct/" + provisionedId);
+ provisioned.put("Name", name);
+ if (CONTROL_TOWER_PRODUCT_ID.equals(productId)) {
+ provisioned.put("Type", "CONTROL_TOWER_ACCOUNT");
+ provisioned.put("PhysicalId", accountFactoryAccountId(request, name, accountId));
+ } else {
+ provisioned.put("Type", "CFN_STACK");
+ }
+ provisioned.put("Status", "AVAILABLE");
+ provisioned.put("ProductId", productId);
+ provisioned.put("ProvisioningArtifactId", artifactId);
+ provisioned.put("CreatedTime", Instant.now().toEpochMilli() / 1000.0);
+ provisionedProductStore.put(provisionedId, provisioned);
+ return provisioned.deepCopy();
+ }
+
+ /**
+ * Runs the Control Tower Account Factory side of a provision: finds or creates the
+ * Organizations member account the provisioning parameters describe, moves it to the
+ * requested OU, and returns its account id.
+ */
+ private String accountFactoryAccountId(JsonNode request, String name, String accountId) {
+ Map<String, String> parameters = new java.util.HashMap<>();
+ request.path("ProvisioningParameters").forEach(parameter ->
+ parameters.put(text(parameter, "Key"), text(parameter, "Value")));
+ String email = parameters.get("AccountEmail");
+ if (email == null || email.isBlank()) {
+ // Without this, Organizations' validateEmail raises InvalidInputException — an
+ // Organizations shape a servicecatalog client cannot deserialize. Keep every error
+ // a Service Catalog caller sees inside the Service Catalog model, the same way the
+ // createAccount failure below is translated.
+ throw new AwsException("InvalidParametersException",
+ "AccountEmail is required in ProvisioningParameters for " + CONTROL_TOWER_PRODUCT_NAME, 400);
+ }
+ String accountName = parameters.getOrDefault("AccountName", name);
+ OrganizationAccount account = organizationsService.listAccounts(accountId).stream()
+ .filter(candidate -> email != null && email.equalsIgnoreCase(candidate.getEmail()))
+ .findFirst().orElse(null);
+ if (account == null) {
+ CreateAccountStatus status = organizationsService.createAccount(
+ accountId, email, accountName, Map.of(), false);
+ if (!"SUCCEEDED".equals(status.getState())) {
+ throw new AwsException("InvalidParametersException",
+ "Control Tower account creation failed: " + status.getFailureReason(), 400);
+ }
+ account = organizationsService.describeAccount(accountId, status.getAccountId());
+ }
+ String destinationParent = organizationalUnitId(parameters.get("ManagedOrganizationalUnit"));
+ if (destinationParent != null && !destinationParent.equals(account.getParentId())) {
+ organizationsService.moveAccount(accountId, account.getId(), account.getParentId(), destinationParent);
+ }
+ return account.getId();
+ }
+
+ private ObjectNode resolveProduct(JsonNode request) {
+ String productId = text(request, "ProductId");
+ if (productId != null && !productId.isBlank()) {
+ // Strict id-only lookup: requireProduct also matches provisioning-artifact ids,
+ // which would let an artifact id in ProductId resolve its owning product.
+ return productStore.get(productId)
+ .orElseThrow(() -> notFound("product", productId));
+ }
+ String productName = text(request, "ProductName");
+ if (productName != null && !productName.isBlank()) {
+ // Names are not unique keys: an ambiguous name must fail rather than
+ // first-match into an arbitrary product (which could be, or displace,
+ // the Account Factory product).
+ List<ObjectNode> matches = productStore.scan(key -> true).stream()
+ .filter(product -> productName.equals(text(product, "Name")))
+ .toList();
+ if (matches.size() > 1) {
+ throw new AwsException("DuplicateResourceException",
+ "More than one product matches name: " + productName, 400);
+ }
+ if (matches.isEmpty()) {
+ throw notFound("product", productName);
+ }
+ return matches.get(0);
+ }
+ throw new AwsException("InvalidParametersException", "ProductId or ProductName is required", 400);
+ }
+
+ /**
+ * Resolves the provisioning artifact a request targets, rejecting one the product does
+ * not own. Neither identifier supplied means the product's first artifact.
+ */
+ private String resolveArtifactId(ObjectNode product, JsonNode request) {
+ JsonNode ids = product.path("ProvisioningArtifactIds");
+ JsonNode names = product.path("ProvisioningArtifactNames");
+ String artifactId = text(request, "ProvisioningArtifactId");
+ String artifactName = text(request, "ProvisioningArtifactName");
+ if (artifactId != null && !artifactId.isBlank()) {
+ for (JsonNode candidate : ids) {
+ if (artifactId.equals(candidate.asText())) {
+ return artifactId;
+ }
+ }
+ throw new AwsException("ResourceNotFoundException",
+ "Unknown provisioning artifact: " + artifactId, 400);
+ }
+ if (artifactName != null && !artifactName.isBlank()) {
+ for (int i = 0; i < names.size(); i++) {
+ if (artifactName.equals(names.get(i).asText())) {
+ return i < ids.size() ? ids.get(i).asText() : null;
+ }
+ }
+ throw new AwsException("ResourceNotFoundException",
+ "Unknown provisioning artifact: " + artifactName, 400);
+ }
+ return ids.isEmpty() ? null : ids.get(0).asText();
+ }
+
+ private String organizationalUnitId(String value) {
+ if (value == null) {
+ return null;
+ }
+ int open = value.lastIndexOf('(');
+ if (open >= 0 && value.endsWith(")")) {
+ String candidate = value.substring(open + 1, value.length() - 1).trim();
+ if (candidate.startsWith("ou-")) {
+ return candidate;
+ }
+ }
+ return value;
+ }
+
+ public List<ObjectNode> searchProvisionedProducts(JsonNode request) {
+ JsonNode terms = request.path("Filters").path("SearchQuery");
+ return provisionedProductStore.scan(key -> true).stream()
+ .filter(product -> matchesProvisionedProductTerms(product, terms))
+ .map(ObjectNode::deepCopy).toList();
+ }
+
+ private boolean matchesProvisionedProductTerms(ObjectNode product, JsonNode terms) {
+ if (!terms.isArray() || terms.isEmpty()) {
+ return true;
+ }
+ for (JsonNode termNode : terms) {
+ String[] parts = termNode.asText().split(":", 2);
+ if (parts.length != 2) {
+ continue;
+ }
+ String expected = parts[1].trim();
+ String actual = switch (parts[0].trim().toLowerCase()) {
+ case "status" -> text(product, "Status");
+ case "physicalid" -> text(product, "PhysicalId");
+ default -> null;
+ };
+ if (actual != null && !actual.equalsIgnoreCase(expected)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * AWS refuses to delete a product that "is associated with a portfolio". Only the portfolio
+ * association blocks — a product carrying just service-action associations or constraints is
+ * still deletable, and those rows are cleaned up below as before.
+ */
+ public void deleteProduct(String id) {
+ ObjectNode product = requireProduct(id);
+ String productId = text(product, "Id");
+ boolean inPortfolio = associationStore.scan(key -> true).stream()
+ .anyMatch(value -> "PRODUCT".equals(text(value, "Type"))
+ && productMatches(value.path("ProductId").asText(), product));
+ if (inPortfolio) {
+ throw inUse("product", productId, "it is associated with a portfolio");
+ }
+ productStore.delete(productId);
+ associationStore.keys().stream()
+ .filter(key -> associationStore.get(key)
+ .map(value -> productMatches(value.path("ProductId").asText(), product)).orElse(false))
+ .toList().forEach(associationStore::delete);
+ }
+
+ public ObjectNode createTagOption(JsonNode request) {
+ requireText(request, "Key");
+ requireText(request, "Value");
+ String id = id("tag");
+ ObjectNode option = copy(request);
+ option.put("Id", id);
+ if (!option.has("Active")) {
+ option.put("Active", true);
+ }
+ tagOptionStore.put(id, option);
+ return option.deepCopy();
+ }
+
+ public ObjectNode updateTagOption(String id, JsonNode request) {
+ ObjectNode option = require(tagOptionStore, id, "TagOption");
+ copyIfPresent(request, option, "Active", "Value");
+ tagOptionStore.put(id, option);
+ return option.deepCopy();
+ }
+
+ public ObjectNode describeTagOption(String id) {
+ return require(tagOptionStore, id, "TagOption").deepCopy();
+ }
+
+ public List<ObjectNode> listTagOptions() {
+ return tagOptionStore.scan(key -> true).stream().map(ObjectNode::deepCopy).toList();
+ }
+
+ public void deleteTagOption(String id) {
+ require(tagOptionStore, id, "TagOption");
+ tagOptionStore.delete(id);
+ associationStore.keys().stream()
+ .filter(key -> associationStore.get(key)
+ .map(value -> id.equals(text(value, "TagOptionId"))).orElse(false))
+ .toList().forEach(associationStore::delete);
+ }
+
+ public String associateProduct(String portfolioId, String productId) {
+ require(portfolioStore, portfolioId, "portfolio", "PortfolioId");
+ requireProduct(productId, "ProductId");
+ String id = associationId("product", portfolioId, productId);
+ associationStore.put(id, objectMapper.createObjectNode()
+ .put("Type", "PRODUCT").put("PortfolioId", portfolioId).put("ProductId", productId));
+ return id;
+ }
+
+ public void disassociateProduct(String portfolioId, String productId) {
+ associationStore.delete(associationId("product", portfolioId, productId));
+ }
+
+ public String associateTagOption(String resourceId, String tagOptionId) {
+ require(tagOptionStore, tagOptionId, "TagOption", "TagOptionId");
+ requireIdentifier(resourceId, "ResourceId");
+ if (portfolioStore.get(resourceId).isEmpty()) {
+ requireProduct(resourceId, "ResourceId");
+ }
+ String id = associationId("tag", resourceId, tagOptionId);
+ associationStore.put(id, objectMapper.createObjectNode()
+ .put("Type", "TAG_OPTION").put("ResourceId", resourceId).put("TagOptionId", tagOptionId));
+ return id;
+ }
+
+ public void disassociateTagOption(String resourceId, String tagOptionId) {
+ associationStore.delete(associationId("tag", resourceId, tagOptionId));
+ }
+
+ public ObjectNode updatePortfolioShare(JsonNode request) {
+ String portfolioId = requireText(request, "PortfolioId");
+ require(portfolioStore, portfolioId, "portfolio");
+ String target = shareTarget(request);
+ String token = id("share");
+ ObjectNode share = copy(request);
+ share.put("PortfolioShareToken", token);
+ share.put("Status", "COMPLETED");
+ shareStore.put(portfolioId + "|" + target, share);
+ return share.deepCopy();
+ }
+
+ public ObjectNode describePortfolioShareStatus(String token) {
+ requireIdentifier(token, "PortfolioShareToken");
+ return shareStore.scan(key -> true).stream()
+ .filter(share -> token.equals(text(share, "PortfolioShareToken")))
+ .findFirst().map(ObjectNode::deepCopy)
+ .orElseThrow(() -> notFound("portfolio share", token));
+ }
+
+ private ObjectNode requireProduct(String identifier) {
+ return requireProduct(identifier, "Id");
+ }
+
+ private ObjectNode requireProduct(String identifier, String parameter) {
+ requireIdentifier(identifier, parameter);
+ ObjectNode direct = productStore.get(identifier).orElse(null);
+ if (direct != null) {
+ return direct;
+ }
+ return productStore.scan(key -> true).stream()
+ .filter(product -> productMatches(identifier, product))
+ .findFirst().orElseThrow(() -> notFound("product", identifier));
+ }
+
+ private boolean productMatches(String identifier, ObjectNode product) {
+ if (identifier.equals(text(product, "Id"))) {
+ return true;
+ }
+ JsonNode ids = product.path("ProvisioningArtifactIds");
+ return ids.isArray() && java.util.stream.StreamSupport.stream(ids.spliterator(), false)
+ .anyMatch(id -> identifier.equals(id.asText()));
+ }
+
+ private ObjectNode require(StorageBackend<String, ObjectNode> store, String id, String type) {
+ return require(store, id, type, "Id");
+ }
+
+ private ObjectNode require(StorageBackend<String, ObjectNode> store, String id, String type,
+ String parameter) {
+ requireIdentifier(id, parameter);
+ return store.get(id).orElseThrow(() -> notFound(type, id));
+ }
+
+ private void requireIdentifier(String id, String parameter) {
+ if (id == null || id.isBlank()) {
+ throw new AwsException("InvalidParametersException", parameter + " is required", 400);
+ }
+ }
+
+ /** botocore {@code OrganizationNodeType}. */
+ static final List<String> ORGANIZATION_NODE_TYPES =
+ List.of("ORGANIZATION", "ORGANIZATIONAL_UNIT", "ACCOUNT");
+
+ /** botocore {@code DescribePortfolioShareType} — a superset of the node types above. */
+ static final List<String> DESCRIBE_PORTFOLIO_SHARE_TYPES =
+ List.of("ACCOUNT", "ORGANIZATION", "ORGANIZATIONAL_UNIT", "ORGANIZATION_MEMBER_ACCOUNT");
+
+ private static final java.util.regex.Pattern ACCOUNT_ID_PATTERN =
+ java.util.regex.Pattern.compile("[0-9]{12}");
+
+ /**
+ * Rejects a value botocore does not list in the member's enum. Accepting one leaves the
+ * emulator holding state AWS would never have created — a portfolio share keyed by an
+ * unmodelled node type is reported back by DescribePortfolioShares as though real.
+ */
+ static void requireEnum(String value, String field, List<String> allowed) {
+ if (!allowed.contains(value)) {
+ throw new AwsException("InvalidParametersException",
+ field + " must be one of " + String.join(", ", allowed) + ": " + value, 400);
+ }
+ }
+
+ /**
+ * Resolves the {@code AccountId} / {@code OrganizationNode} pair the portfolio-share
+ * operations key their store on, enforcing the constraints botocore pins on each:
+ * {@code AccountId} matches {@code ^[0-9]{12}$} and {@code OrganizationNode.Type} is an
+ * {@code OrganizationNodeType}. Both used to be concatenated into the key unchecked.
+ */
+ private String shareTarget(JsonNode request) {
+ if (request.hasNonNull("AccountId")) {
+ String accountId = request.get("AccountId").asText();
+ if (!ACCOUNT_ID_PATTERN.matcher(accountId).matches()) {
+ throw new AwsException("InvalidParametersException",
+ "AccountId must be a 12-digit AWS account id: " + accountId, 400);
+ }
+ return "ACCOUNT:" + accountId;
+ }
+ JsonNode orgNode = request.path("OrganizationNode");
+ String type = orgNode.path("Type").asText();
+ String value = orgNode.path("Value").asText();
+ if (type.isEmpty() && value.isEmpty()) {
+ throw new AwsException("InvalidParametersException",
+ "AccountId or OrganizationNode is required", 400);
+ }
+ requireEnum(type, "OrganizationNode.Type", ORGANIZATION_NODE_TYPES);
+ return type + ":" + value;
+ }
+
+ private AwsException notFound(String type, String id) {
+ return new AwsException("ResourceNotFoundException", "Unknown " + type + ": " + id, 400);
+ }
+
+ /** 400 matches every other error this service raises; the shape models no status of its own. */
+ private AwsException inUse(String type, String id, String reason) {
+ return new AwsException("ResourceInUseException",
+ "Cannot delete " + type + " " + id + " because " + reason + ".", 400);
+ }
+
+ private String requireText(JsonNode node, String field) {
+ String value = text(node, field);
+ if (value == null || value.isBlank()) {
+ throw new AwsException("InvalidParametersException", field + " is required", 400);
+ }
+ return value;
+ }
+
+ private String text(JsonNode node, String field) {
+ JsonNode value = node == null ? null : node.get(field);
+ return value == null || value.isNull() ? null : value.asText();
+ }
+
+ private ObjectNode copy(JsonNode node) {
+ return node != null && node.isObject()
+ ? ((ObjectNode) node).deepCopy() : objectMapper.createObjectNode();
+ }
+
+ private void copyIfPresent(JsonNode source, ObjectNode target, String... fields) {
+ for (String field : fields) {
+ if (source.has(field)) {
+ target.set(field, source.get(field).deepCopy());
+ }
+ }
+ }
+
+ private String associationId(String type, String left, String right) {
+ return type + "|" + left + "|" + right;
+ }
+
+ private String id(String prefix) {
+ return prefix + "-" + UUID.randomUUID().toString().replace("-", "").substring(0, 13);
+ }
+
+ public List<ObjectNode> describePortfolioShares(String portfolioId, String type) {
+ if (portfolioId == null || portfolioId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "PortfolioId is required", 400);
+ }
+ require(portfolioStore, portfolioId, "portfolio");
+ String prefix = portfolioId + "|";
+ List<ObjectNode> results = new java.util.ArrayList<>();
+ for (String key : shareStore.keys()) {
+ if (!key.startsWith(prefix)) {
+ continue;
+ }
+ shareStore.get(key).ifPresent(share -> {
+ String target = key.substring(prefix.length());
+ int colon = target.indexOf(':');
+ String shareType = colon >= 0 ? target.substring(0, colon) : target;
+ String principalId = colon >= 0 ? target.substring(colon + 1) : "";
+ if (type != null && !type.equals(shareType)) {
+ return;
+ }
+ ObjectNode result = objectMapper.createObjectNode();
+ result.put("PrincipalId", principalId);
+ result.put("Type", shareType);
+ result.put("Accepted", true);
+ result.put("ShareTagOptions", false);
+ result.put("SharePrincipals", false);
+ results.add(result);
+ });
+ }
+ return results;
+ }
+
+ public List<ObjectNode> listPortfoliosForProduct(String productId) {
+ requireProduct(productId, "ProductId");
+ return associationStore.scan(key -> true).stream()
+ .filter(assoc -> "PRODUCT".equals(text(assoc, "Type"))
+ && productId.equals(text(assoc, "ProductId")))
+ .map(assoc -> text(assoc, "PortfolioId"))
+ .distinct()
+ .map(portfolioStore::get)
+ .flatMap(Optional::stream)
+ .map(ObjectNode::deepCopy)
+ .toList();
+ }
+
+ public String copyProduct(JsonNode request, String region, String accountId) {
+ String sourceArn = requireText(request, "SourceProductArn");
+ String sourceId = sourceArn.substring(sourceArn.lastIndexOf('/') + 1);
+ ObjectNode source = requireProduct(sourceId);
+ String newId = id("prod");
+ ObjectNode product = source.deepCopy();
+ product.put("Id", newId);
+ product.put("ARN", "arn:aws:catalog:" + region + ":" + accountId + ":product/" + newId);
+ product.put("CreatedTime", Instant.now().toEpochMilli() / 1000.0);
+ String targetName = text(request, "TargetProductName");
+ if (targetName != null && !targetName.isBlank()) {
+ product.put("Name", targetName);
+ }
+ productStore.put(newId, product);
+ String token = id("copy");
+ ObjectNode status = objectMapper.createObjectNode();
+ status.put("Status", "SUCCEEDED");
+ status.put("TargetProductId", newId);
+ associationStore.put(token, status);
+ return token;
+ }
+
+ // no new service method required
+
+ public void acceptPortfolioShare(String portfolioId) {
+ if (portfolioId == null || portfolioId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "PortfolioId is required", 400);
+ }
+ require(portfolioStore, portfolioId, "portfolio");
+ }
+
+ public String deletePortfolioShare(JsonNode request) {
+ String portfolioId = requireText(request, "PortfolioId");
+ require(portfolioStore, portfolioId, "portfolio");
+ String key = portfolioId + "|" + shareTarget(request);
+ String token = shareStore.get(key).map(share -> text(share, "PortfolioShareToken")).orElse(null);
+ shareStore.delete(key);
+ return token;
+ }
+
+ public void rejectPortfolioShare(String portfolioId) {
+ if (portfolioId == null || portfolioId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "PortfolioId is required", 400);
+ }
+ require(portfolioStore, portfolioId, "portfolio");
+ }
+
+ public void associateBudgetWithResource(String budgetName, String resourceId) {
+ if (budgetName == null || budgetName.isBlank()) {
+ throw new AwsException("InvalidParametersException", "BudgetName is required", 400);
+ }
+ if (resourceId == null || resourceId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ResourceId is required", 400);
+ }
+ if (portfolioStore.get(resourceId).isEmpty()) {
+ requireProduct(resourceId);
+ }
+ String id = associationId("budget", resourceId, budgetName);
+ if (associationStore.get(id).isPresent()) {
+ throw new AwsException("DuplicateResourceException",
+ "Budget " + budgetName + " is already associated with resource " + resourceId, 400);
+ }
+ associationStore.put(id, objectMapper.createObjectNode()
+ .put("Type", "BUDGET").put("ResourceId", resourceId).put("BudgetName", budgetName));
+ }
+
+ public void associatePrincipal(String portfolioId, String principalArn, String principalType) {
+ if (portfolioId == null || portfolioId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "PortfolioId is required", 400);
+ }
+ if (principalArn == null || principalArn.isBlank()) {
+ throw new AwsException("InvalidParametersException", "PrincipalARN is required", 400);
+ }
+ if (principalType == null || principalType.isBlank()) {
+ throw new AwsException("InvalidParametersException", "PrincipalType is required", 400);
+ }
+ requireEnum(principalType, "PrincipalType", List.of("IAM", "IAM_PATTERN"));
+ require(portfolioStore, portfolioId, "portfolio");
+ String id = associationId("principal", portfolioId, principalArn);
+ associationStore.put(id, objectMapper.createObjectNode()
+ .put("Type", "PRINCIPAL").put("PortfolioId", portfolioId)
+ .put("PrincipalARN", principalArn).put("PrincipalType", principalType));
+ }
+
+ public void associateServiceActionWithProvisioningArtifact(String productId, String provisioningArtifactId, String serviceActionId) {
+ if (productId == null || productId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ProductId is required", 400);
+ }
+ if (provisioningArtifactId == null || provisioningArtifactId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ProvisioningArtifactId is required", 400);
+ }
+ if (serviceActionId == null || serviceActionId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ServiceActionId is required", 400);
+ }
+ ObjectNode product = requireProduct(productId);
+ JsonNode artifactIds = product.path("ProvisioningArtifactIds");
+ boolean found = artifactIds.isArray() && java.util.stream.StreamSupport.stream(artifactIds.spliterator(), false)
+ .anyMatch(id -> provisioningArtifactId.equals(id.asText()));
+ if (!found) {
+ throw new AwsException("ResourceNotFoundException", "Unknown provisioning artifact: " + provisioningArtifactId, 400);
+ }
+ String id = associationId("service_action", productId, provisioningArtifactId + "|" + serviceActionId);
+ if (associationStore.get(id).isPresent()) {
+ throw new AwsException("DuplicateResourceException",
+ "Service action " + serviceActionId + " is already associated with provisioning artifact " + provisioningArtifactId, 400);
+ }
+ associationStore.put(id, objectMapper.createObjectNode()
+ .put("Type", "SERVICE_ACTION")
+ .put("ProductId", productId)
+ .put("ProvisioningArtifactId", provisioningArtifactId)
+ .put("ServiceActionId", serviceActionId));
+ }
+
+ public List<ObjectNode> batchAssociateServiceActionWithProvisioningArtifact(JsonNode request) {
+ JsonNode associations = request.path("ServiceActionAssociations");
+ if (!associations.isArray() || associations.isEmpty()) {
+ throw new AwsException("InvalidParametersException", "ServiceActionAssociations is required", 400);
+ }
+ List<ObjectNode> failures = new java.util.ArrayList<>();
+ for (JsonNode assoc : associations) {
+ String productId = text(assoc, "ProductId");
+ String artifactId = text(assoc, "ProvisioningArtifactId");
+ String serviceActionId = text(assoc, "ServiceActionId");
+ if (productId == null || productId.isBlank() || artifactId == null || artifactId.isBlank()
+ || serviceActionId == null || serviceActionId.isBlank()) {
+ failures.add(serviceActionFailure(assoc, "INVALID_PARAMETER",
+ "ProductId, ProvisioningArtifactId, and ServiceActionId are required"));
+ continue;
+ }
+ ObjectNode product;
+ try {
+ product = requireProduct(productId);
+ } catch (AwsException e) {
+ failures.add(serviceActionFailure(assoc, "RESOURCE_NOT_FOUND", "Unknown product: " + productId));
+ continue;
+ }
+ JsonNode artifactIds = product.path("ProvisioningArtifactIds");
+ boolean artifactFound = artifactIds.isArray() && java.util.stream.StreamSupport
+ .stream(artifactIds.spliterator(), false)
+ .anyMatch(id -> artifactId.equals(id.asText()));
+ if (!artifactFound) {
+ failures.add(serviceActionFailure(assoc, "RESOURCE_NOT_FOUND",
+ "Unknown provisioning artifact: " + artifactId));
+ continue;
+ }
+ String id = associationId("service_action", productId, artifactId + "|" + serviceActionId);
+ associationStore.put(id, objectMapper.createObjectNode()
+ .put("Type", "SERVICE_ACTION").put("ProductId", productId)
+ .put("ProvisioningArtifactId", artifactId).put("ServiceActionId", serviceActionId));
+ }
+ return failures;
+ }
+
+ private ObjectNode serviceActionFailure(JsonNode assoc, String code, String message) {
+ ObjectNode failure = objectMapper.createObjectNode();
+ failure.put("ErrorCode", code);
+ failure.put("ErrorMessage", message);
+ if (text(assoc, "ProductId") != null) {
+ failure.put("ProductId", text(assoc, "ProductId"));
+ }
+ if (text(assoc, "ProvisioningArtifactId") != null) {
+ failure.put("ProvisioningArtifactId", text(assoc, "ProvisioningArtifactId"));
+ }
+ if (text(assoc, "ServiceActionId") != null) {
+ failure.put("ServiceActionId", text(assoc, "ServiceActionId"));
+ }
+ return failure;
+ }
+
+ public List<ObjectNode> batchDisassociateServiceActionFromProvisioningArtifact(JsonNode request) {
+ JsonNode associations = request.path("ServiceActionAssociations");
+ if (!associations.isArray() || associations.isEmpty()) {
+ throw new AwsException("InvalidParametersException", "ServiceActionAssociations is required", 400);
+ }
+ List<ObjectNode> failures = new java.util.ArrayList<>();
+ for (JsonNode assoc : associations) {
+ String productId = text(assoc, "ProductId");
+ String artifactId = text(assoc, "ProvisioningArtifactId");
+ String serviceActionId = text(assoc, "ServiceActionId");
+ if (productId == null || productId.isBlank() || artifactId == null || artifactId.isBlank()
+ || serviceActionId == null || serviceActionId.isBlank()) {
+ ObjectNode failure = objectMapper.createObjectNode();
+ failure.put("ErrorCode", "INVALID_PARAMETER");
+ failure.put("ErrorMessage", "ProductId, ProvisioningArtifactId, and ServiceActionId are required");
+ if (productId != null) failure.put("ProductId", productId);
+ if (artifactId != null) failure.put("ProvisioningArtifactId", artifactId);
+ if (serviceActionId != null) failure.put("ServiceActionId", serviceActionId);
+ failures.add(failure);
+ continue;
+ }
+ String key = associationId("service_action", productId, artifactId + "|" + serviceActionId);
+ if (associationStore.get(key).isEmpty()) {
+ ObjectNode failure = objectMapper.createObjectNode();
+ failure.put("ErrorCode", "RESOURCE_NOT_FOUND");
+ failure.put("ErrorMessage", "Service action association not found for product " + productId
+ + ", artifact " + artifactId + ", service action " + serviceActionId);
+ failure.put("ProductId", productId);
+ failure.put("ProvisioningArtifactId", artifactId);
+ failure.put("ServiceActionId", serviceActionId);
+ failures.add(failure);
+ } else {
+ associationStore.delete(key);
+ }
+ }
+ return failures;
+ }
+
+ public ObjectNode createConstraint(JsonNode request, String region, String accountId) {
+ String portfolioId = requireText(request, "PortfolioId");
+ String productId = requireText(request, "ProductId");
+ requireText(request, "Parameters");
+ requireText(request, "Type");
+ requireText(request, "IdempotencyToken");
+ require(portfolioStore, portfolioId, "portfolio");
+ requireProduct(productId);
+ String constraintId = id("con");
+ ObjectNode constraint = objectMapper.createObjectNode();
+ constraint.put("ConstraintId", constraintId);
+ constraint.put("PortfolioId", portfolioId);
+ constraint.put("ProductId", productId);
+ constraint.put("Type", text(request, "Type"));
+ constraint.put("Owner", accountId);
+ if (request.has("Description")) {
+ constraint.put("Description", text(request, "Description"));
+ }
+ associationStore.put(constraintId, constraint);
+ return constraint.deepCopy();
+ }
+
+ public ObjectNode createProvisionedProductPlan(JsonNode request, String region, String accountId) {
+ requireText(request, "PlanName");
+ // ProvisionedProductPlanType has exactly one member; the plan is always described
+ // as CLOUDFORMATION, so accepting another value would report a type never asked for.
+ requireEnum(requireText(request, "PlanType"), "PlanType", List.of("CLOUDFORMATION"));
+ String productId = requireText(request, "ProductId");
+ requireText(request, "ProvisionedProductName");
+ String artifactId = requireText(request, "ProvisioningArtifactId");
+ requireText(request, "IdempotencyToken");
+ ObjectNode product = requireProduct(productId);
+ JsonNode ids = product.path("ProvisioningArtifactIds");
+ boolean found = false;
+ for (JsonNode id : ids) {
+ if (artifactId.equals(id.asText())) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ throw new AwsException("ResourceNotFoundException",
+ "Unknown provisioning artifact: " + artifactId, 400);
+ }
+ String planId = id("plan");
+ ObjectNode plan = objectMapper.createObjectNode();
+ plan.put("Type", "PROVISIONED_PRODUCT_PLAN");
+ plan.put("Id", planId);
+ plan.put("PlanId", planId);
+ plan.put("Name", text(request, "ProvisionedProductName"));
+ plan.put("PlanName", text(request, "PlanName"));
+ plan.put("ProductId", productId);
+ plan.put("ProvisionProductId", productId);
+ plan.put("ProvisionedProductName", text(request, "ProvisionedProductName"));
+ plan.put("ProvisioningArtifactId", artifactId);
+ plan.put("CreatedTime", Instant.now().toEpochMilli() / 1000.0);
+ associationStore.put(planId, plan);
+ return plan.deepCopy();
+ }
+
+ public ObjectNode createServiceAction(JsonNode request) {
+ requireText(request, "Name");
+ // ServiceActionDefinitionType has exactly one member.
+ requireEnum(requireText(request, "DefinitionType"), "DefinitionType", List.of("SSM_AUTOMATION"));
+ requireText(request, "IdempotencyToken");
+ JsonNode definition = request.get("Definition");
+ if (definition == null || definition.isNull() || !definition.isObject()) {
+ throw new AwsException("InvalidParametersException", "Definition is required", 400);
+ }
+ String id = id("serv");
+ ObjectNode action = objectMapper.createObjectNode();
+ action.put("Id", id);
+ action.put("Name", text(request, "Name"));
+ action.put("DefinitionType", text(request, "DefinitionType"));
+ action.put("Description", text(request, "Description") != null ? text(request, "Description") : "");
+ action.set("Definition", definition.deepCopy());
+ action.put("Type", "SERVICE_ACTION");
+ associationStore.put(id, action);
+ return action.deepCopy();
+ }
+
+ public void deleteConstraint(String id) {
+ if (id == null || id.isBlank()) {
+ throw new AwsException("InvalidParametersException", "Id is required", 400);
+ }
+ require(associationStore, id, "constraint");
+ associationStore.delete(id);
+ }
+
+ public void deleteProvisionedProductPlan(String planId) {
+ if (planId == null || planId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "PlanId is required", 400);
+ }
+ require(associationStore, planId, "provisioned product plan");
+ associationStore.delete(planId);
+ }
+
+ public void deleteProvisioningArtifact(String productId, String artifactId) {
+ if (productId == null || productId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ProductId is required", 400);
+ }
+ if (artifactId == null || artifactId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ProvisioningArtifactId is required", 400);
+ }
+ ObjectNode product = requireProduct(productId);
+ JsonNode ids = product.path("ProvisioningArtifactIds");
+ JsonNode names = product.path("ProvisioningArtifactNames");
+ int index = -1;
+ for (int i = 0; i < ids.size(); i++) {
+ if (artifactId.equals(ids.get(i).asText())) {
+ index = i;
+ break;
+ }
+ }
+ if (index < 0) {
+ throw new AwsException("ResourceNotFoundException",
+ "Unknown provisioning artifact: " + artifactId, 400);
+ }
+ ((ArrayNode) ids).remove(index);
+ if (index < names.size()) {
+ ((ArrayNode) names).remove(index);
+ }
+ productStore.put(text(product, "Id"), product);
+ }
+
+ public void deleteServiceAction(String id) {
+ if (id == null || id.isBlank()) {
+ throw new AwsException("InvalidParametersException", "Id is required", 400);
+ }
+ require(associationStore, id, "service action");
+ associationStore.delete(id);
+ }
+
+ public ObjectNode describeConstraint(String id) {
+ if (id == null || id.isBlank()) {
+ throw new AwsException("InvalidParametersException", "Id is required", 400);
+ }
+ return require(associationStore, id, "constraint").deepCopy();
+ }
+
+ public ObjectNode describeProvisionedProduct(String id, String name) {
+ if (id != null && !id.isBlank()) {
+ return require(provisionedProductStore, id, "provisioned product").deepCopy();
+ }
+ if (name != null && !name.isBlank()) {
+ return provisionedProductStore.scan(key -> true).stream()
+ .filter(product -> name.equals(text(product, "Name")))
+ .findFirst().map(ObjectNode::deepCopy)
+ .orElseThrow(() -> notFound("provisioned product", name));
+ }
+ throw new AwsException("InvalidParametersException", "Id or Name is required", 400);
+ }
+
+ public ObjectNode describeProvisionedProductPlan(String planId) {
+ if (planId == null || planId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "PlanId is required", 400);
+ }
+ return require(associationStore, planId, "provisioned product plan").deepCopy();
+ }
+
+ public ObjectNode describeProvisioningParameters(JsonNode request) {
+ ObjectNode product = resolveProduct(request);
+ resolveArtifactId(product, request);
+ return product.deepCopy();
+ }
+
+ public ObjectNode describeRecord(String id) {
+ if (id == null || id.isBlank()) {
+ throw new AwsException("InvalidParametersException", "Id is required", 400);
+ }
+ return associationStore.scan(key -> true).stream()
+ .filter(record -> "RECORD".equals(text(record, "Type")) && id.equals(text(record, "RecordId")))
+ .findFirst().map(ObjectNode::deepCopy)
+ .orElseThrow(() -> notFound("record", id));
+ }
+
+ public void describeServiceActionExecutionParameters(String provisionedProductId, String serviceActionId) {
+ if (provisionedProductId == null || provisionedProductId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ProvisionedProductId is required", 400);
+ }
+ if (serviceActionId == null || serviceActionId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ServiceActionId is required", 400);
+ }
+ require(provisionedProductStore, provisionedProductId, "provisioned product");
+ }
+
+ public void disassociateBudgetFromResource(String budgetName, String resourceId) {
+ if (budgetName == null || budgetName.isBlank()) {
+ throw new AwsException("InvalidParametersException", "BudgetName is required", 400);
+ }
+ if (resourceId == null || resourceId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ResourceId is required", 400);
+ }
+ if (portfolioStore.get(resourceId).isEmpty()) {
+ requireProduct(resourceId);
+ }
+ associationStore.delete(associationId("budget", resourceId, budgetName));
+ }
+
+ public void disassociatePrincipal(String portfolioId, String principalArn) {
+ if (portfolioId == null || portfolioId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "PortfolioId is required", 400);
+ }
+ if (principalArn == null || principalArn.isBlank()) {
+ throw new AwsException("InvalidParametersException", "PrincipalARN is required", 400);
+ }
+ require(portfolioStore, portfolioId, "portfolio");
+ associationStore.delete(associationId("principal", portfolioId, principalArn));
+ }
+
+ public void disassociateServiceActionFromProvisioningArtifact(String productId, String provisioningArtifactId, String serviceActionId) {
+ if (productId == null || productId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ProductId is required", 400);
+ }
+ if (provisioningArtifactId == null || provisioningArtifactId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ProvisioningArtifactId is required", 400);
+ }
+ if (serviceActionId == null || serviceActionId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ServiceActionId is required", 400);
+ }
+ ObjectNode product = requireProduct(productId);
+ JsonNode artifactIds = product.path("ProvisioningArtifactIds");
+ boolean found = artifactIds.isArray() && java.util.stream.StreamSupport.stream(artifactIds.spliterator(), false)
+ .anyMatch(id -> provisioningArtifactId.equals(id.asText()));
+ if (!found) {
+ throw new AwsException("ResourceNotFoundException", "Unknown provisioning artifact: " + provisioningArtifactId, 400);
+ }
+ String id = associationId("service_action", productId, provisioningArtifactId + "|" + serviceActionId);
+ require(associationStore, id, "service action association");
+ associationStore.delete(id);
+ }
+
+ public ObjectNode executeProvisionedProductPlan(JsonNode request) {
+ String planId = requireText(request, "PlanId");
+ requireText(request, "IdempotencyToken");
+ require(associationStore, planId, "provisioned product plan");
+ ObjectNode record = objectMapper.createObjectNode();
+ record.put("RecordId", "rec-" + UUID.randomUUID().toString().replace("-", "").substring(0, 16));
+ record.put("Status", "SUCCEEDED");
+ record.put("CreatedTime", System.currentTimeMillis() / 1000.0);
+ return record;
+ }
+
+ public ObjectNode executeProvisionedProductServiceAction(JsonNode request, String region, String accountId) {
+ requireText(request, "ServiceActionId");
+ requireText(request, "ExecuteToken");
+ String provisionedProductId = requireText(request, "ProvisionedProductId");
+ ObjectNode product = provisionedProductStore.get(provisionedProductId)
+ .orElseThrow(() -> notFound("provisioned product", provisionedProductId));
+
+ String recordId = id("rec");
+ ObjectNode record = objectMapper.createObjectNode();
+ record.put("Type", "RECORD");
+ record.put("RecordId", recordId);
+ record.put("ProvisionedProductId", provisionedProductId);
+ record.put("ProvisionedProductName", text(product, "Name"));
+ record.put("ProvisionedProductType", text(product, "Type"));
+ record.put("ProductId", text(product, "ProductId"));
+ record.put("ProvisioningArtifactId", text(product, "ProvisioningArtifactId"));
+ record.put("RecordType", "UPDATE_PROVISIONED_PRODUCT");
+ record.put("Status", "SUCCEEDED");
+ record.put("CreatedTime", Instant.now().toEpochMilli() / 1000.0);
+ associationStore.put(recordId, record);
+
+ ObjectNode result = product.deepCopy();
+ result.put("RecordId", recordId);
+ return result;
+ }
+
+ public void getProvisionedProductOutputs(JsonNode request) {
+ String id = text(request, "ProvisionedProductId");
+ if (id != null && !id.isBlank()) {
+ require(provisionedProductStore, id, "provisioned product");
+ return;
+ }
+ String name = text(request, "ProvisionedProductName");
+ if (name != null && !name.isBlank()) {
+ provisionedProductStore.scan(key -> true).stream()
+ .filter(product -> name.equals(text(product, "Name")))
+ .findFirst().orElseThrow(() -> notFound("provisioned product", name));
+ return;
+ }
+ throw new AwsException("InvalidParametersException",
+ "ProvisionedProductId or ProvisionedProductName is required", 400);
+ }
+
+ public ObjectNode importAsProvisionedProduct(JsonNode request, String region, String accountId) {
+ String productId = requireText(request, "ProductId");
+ String provisioningArtifactId = requireText(request, "ProvisioningArtifactId");
+ String provisionedProductName = requireText(request, "ProvisionedProductName");
+ String physicalId = requireText(request, "PhysicalId");
+ requireText(request, "IdempotencyToken");
+ ObjectNode product = requireProduct(productId);
+ String provisionedId = id("pp");
+ ObjectNode provisioned = objectMapper.createObjectNode();
+ provisioned.put("Id", provisionedId);
+ provisioned.put("Arn", "arn:aws:servicecatalog:" + region + ":" + accountId
+ + ":provisionedproduct/" + provisionedId);
+ provisioned.put("Name", provisionedProductName);
+ provisioned.put("Type", "IMPORTED");
+ provisioned.put("Status", "AVAILABLE");
+ provisioned.put("PhysicalId", physicalId);
+ provisioned.put("ProductId", productId);
+ provisioned.put("ProvisioningArtifactId", provisioningArtifactId);
+ provisioned.put("CreatedTime", Instant.now().toEpochMilli() / 1000.0);
+ provisionedProductStore.put(provisionedId, provisioned);
+
+ String recordId = id("rec");
+ ObjectNode record = objectMapper.createObjectNode();
+ record.put("Type", "RECORD");
+ record.put("RecordId", recordId);
+ record.put("ProvisionedProductId", provisionedId);
+ record.put("ProvisionedProductName", provisionedProductName);
+ record.put("ProductId", productId);
+ record.put("ProvisioningArtifactId", provisioningArtifactId);
+ record.put("RecordType", "IMPORT");
+ record.put("Status", "SUCCEEDED");
+ record.put("CreatedTime", provisioned.get("CreatedTime").asDouble());
+ associationStore.put(recordId, record);
+
+ ObjectNode result = provisioned.deepCopy();
+ result.put("RecordId", recordId);
+ return result;
+ }
+
+ public List<ObjectNode> listBudgetsForResource(String resourceId) {
+ if (resourceId == null || resourceId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ResourceId is required", 400);
+ }
+ if (portfolioStore.get(resourceId).isEmpty()) {
+ requireProduct(resourceId);
+ }
+ return associationStore.scan(key -> true).stream()
+ .filter(assoc -> "BUDGET".equals(text(assoc, "Type"))
+ && resourceId.equals(text(assoc, "ResourceId")))
+ .map(ObjectNode::deepCopy)
+ .toList();
+ }
+
+ public List<ObjectNode> listConstraintsForPortfolio(String portfolioId, String productId) {
+ if (portfolioId == null || portfolioId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "PortfolioId is required", 400);
+ }
+ require(portfolioStore, portfolioId, "portfolio");
+ return associationStore.scan(key -> true).stream()
+ .filter(node -> portfolioId.equals(text(node, "PortfolioId")) && node.has("ConstraintId"))
+ .filter(node -> productId == null || productId.isBlank() || productId.equals(text(node, "ProductId")))
+ .map(ObjectNode::deepCopy)
+ .toList();
+ }
+
+ public List<String> listPortfolioAccess(String portfolioId, String organizationParentId) {
+ if (portfolioId == null || portfolioId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "PortfolioId is required", 400);
+ }
+ require(portfolioStore, portfolioId, "portfolio");
+ String prefix = portfolioId + "|";
+ List<String> accountIds = new java.util.ArrayList<>();
+ for (String key : shareStore.keys()) {
+ if (!key.startsWith(prefix)) {
+ continue;
+ }
+ String target = key.substring(prefix.length());
+ int colon = target.indexOf(':');
+ String shareType = colon >= 0 ? target.substring(0, colon) : target;
+ String principalId = colon >= 0 ? target.substring(colon + 1) : "";
+ if ("ACCOUNT".equals(shareType)) {
+ accountIds.add(principalId);
+ }
+ }
+ return accountIds;
+ }
+
+ public List<ObjectNode> listPrincipalsForPortfolio(String portfolioId) {
+ if (portfolioId == null || portfolioId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "PortfolioId is required", 400);
+ }
+ require(portfolioStore, portfolioId, "portfolio");
+ return associationStore.scan(key -> true).stream()
+ .filter(assoc -> "PRINCIPAL".equals(text(assoc, "Type"))
+ && portfolioId.equals(text(assoc, "PortfolioId")))
+ .map(assoc -> {
+ ObjectNode principal = objectMapper.createObjectNode();
+ principal.put("PrincipalARN", text(assoc, "PrincipalARN"));
+ principal.put("PrincipalType", text(assoc, "PrincipalType"));
+ return principal;
+ })
+ .toList();
+ }
+
+ public List<ObjectNode> listProvisionedProductPlans(String provisionProductId) {
+ return associationStore.scan(key -> true).stream()
+ .filter(node -> "PROVISIONED_PRODUCT_PLAN".equals(text(node, "Type")))
+ .filter(plan -> provisionProductId == null || provisionProductId.isBlank()
+ || provisionProductId.equals(text(plan, "ProvisionProductId")))
+ .map(ObjectNode::deepCopy)
+ .toList();
+ }
+
+ public List<ObjectNode> listRecordHistory() {
+ return provisionedProductStore.scan(key -> true).stream().map(ObjectNode::deepCopy).toList();
+ }
+
+ public List<ObjectNode> listResourcesForTagOption(String tagOptionId, String resourceType) {
+ if (tagOptionId == null || tagOptionId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "TagOptionId is required", 400);
+ }
+ require(tagOptionStore, tagOptionId, "TagOption");
+ List<ObjectNode> results = new java.util.ArrayList<>();
+ for (String key : associationStore.keys()) {
+ associationStore.get(key).ifPresent(assoc -> {
+ if (!"TAG_OPTION".equals(text(assoc, "Type"))) {
+ return;
+ }
+ if (!tagOptionId.equals(text(assoc, "TagOptionId"))) {
+ return;
+ }
+ String resourceId = text(assoc, "ResourceId");
+ ObjectNode resource = portfolioStore.get(resourceId).orElse(null);
+ String type = "PORTFOLIO";
+ if (resource == null) {
+ resource = productStore.get(resourceId).orElse(null);
+ type = "PRODUCT";
+ }
+ if (resource == null) {
+ return;
+ }
+ if (resourceType != null && !resourceType.isBlank() && !resourceType.equalsIgnoreCase(type)) {
+ return;
+ }
+ ObjectNode detail = objectMapper.createObjectNode();
+ detail.put("Id", resourceId);
+ detail.put("ARN", text(resource, "ARN"));
+ String name = text(resource, "DisplayName");
+ if (name == null) {
+ name = text(resource, "Name");
+ }
+ detail.put("Name", name);
+ detail.put("CreatedTime", resource.path("CreatedTime").asDouble(0.0));
+ String description = text(resource, "Description");
+ if (description != null) {
+ detail.put("Description", description);
+ }
+ results.add(detail);
+ });
+ }
+ return results;
+ }
+
+ public List<ObjectNode> listStackInstancesForProvisionedProduct(String provisionedProductId) {
+ if (provisionedProductId == null || provisionedProductId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ProvisionedProductId is required", 400);
+ }
+ ObjectNode product = require(provisionedProductStore, provisionedProductId, "provisioned product");
+ ObjectNode instance = objectMapper.createObjectNode();
+ instance.put("Account", text(product, "PhysicalId"));
+ String arn = text(product, "Arn");
+ if (arn != null) {
+ String[] parts = arn.split(":");
+ if (parts.length >= 4) {
+ instance.put("Region", parts[3]);
+ }
+ }
+ instance.put("StackInstanceStatus", "CURRENT");
+ return List.of(instance);
+ }
+
+ public void notifyProvisionProductEngineWorkflowResult(JsonNode request) {
+ requireText(request, "WorkflowToken");
+ requireText(request, "RecordId");
+ String status = requireText(request, "Status");
+ if (!"SUCCEEDED".equals(status) && !"FAILED".equals(status)) {
+ throw new AwsException("InvalidParametersException",
+ "Status must be SUCCEEDED or FAILED", 400);
+ }
+ requireText(request, "IdempotencyToken");
+ }
+
+ public void notifyTerminateProvisionedProductEngineWorkflowResult(JsonNode request) {
+ requireText(request, "WorkflowToken");
+ requireText(request, "RecordId");
+ String status = requireText(request, "Status");
+ if (!"SUCCEEDED".equals(status) && !"FAILED".equals(status)) {
+ throw new AwsException("InvalidParametersException",
+ "Status must be SUCCEEDED or FAILED", 400);
+ }
+ requireText(request, "IdempotencyToken");
+ }
+
+ public void notifyUpdateProvisionedProductEngineWorkflowResult(JsonNode request) {
+ requireText(request, "WorkflowToken");
+ requireText(request, "RecordId");
+ String status = requireText(request, "Status");
+ if (!"SUCCEEDED".equals(status) && !"FAILED".equals(status)) {
+ throw new AwsException("InvalidParametersException",
+ "Status must be SUCCEEDED or FAILED", 400);
+ }
+ requireText(request, "IdempotencyToken");
+ }
+
+ public List<ObjectNode> scanProvisionedProducts() {
+ return provisionedProductStore.scan(key -> true).stream().map(ObjectNode::deepCopy).toList();
+ }
+
+ public ObjectNode updateConstraint(String id, JsonNode request) {
+ if (id == null || id.isBlank()) {
+ throw new AwsException("InvalidParametersException", "Id is required", 400);
+ }
+ ObjectNode constraint = require(associationStore, id, "constraint");
+ if (request.has("Description")) {
+ constraint.put("Description", request.get("Description").asText());
+ }
+ if (request.has("Parameters")) {
+ constraint.set("Parameters", request.get("Parameters").deepCopy());
+ }
+ associationStore.put(id, constraint);
+ return constraint.deepCopy();
+ }
+
+ public ObjectNode updateProvisionedProduct(JsonNode request, String region, String accountId) {
+ requireText(request, "UpdateToken");
+ String productId = text(request, "ProvisionedProductId");
+ String productName = text(request, "ProvisionedProductName");
+ ObjectNode product;
+ if (productId == null || productId.isBlank()) {
+ if (productName == null || productName.isBlank()) {
+ throw new AwsException("InvalidParametersException",
+ "ProvisionedProductId or ProvisionedProductName is required", 400);
+ }
+ product = provisionedProductStore.scan(key -> true).stream()
+ .filter(p -> productName.equals(text(p, "Name")))
+ .findFirst().orElseThrow(() -> notFound("provisioned product", productName));
+ } else {
+ product = require(provisionedProductStore, productId, "provisioned product");
+ }
+
+ String recordId = id("rec");
+ ObjectNode record = objectMapper.createObjectNode();
+ record.put("Type", "RECORD");
+ record.put("RecordId", recordId);
+ record.put("ProvisionedProductId", text(product, "Id"));
+ record.put("ProvisionedProductName", text(product, "Name"));
+ record.put("ProductId", text(product, "ProductId"));
+ record.put("ProvisioningArtifactId", text(product, "ProvisioningArtifactId"));
+ record.put("RecordType", "UPDATE_PROVISIONED_PRODUCT");
+ record.put("Status", "SUCCEEDED");
+ record.put("CreatedTime", Instant.now().toEpochMilli() / 1000.0);
+ associationStore.put(recordId, record);
+
+ ObjectNode result = product.deepCopy();
+ result.put("RecordId", recordId);
+ return result;
+ }
+
+ public ObjectNode updateProvisionedProductProperties(String provisionedProductId, JsonNode request) {
+ if (provisionedProductId == null || provisionedProductId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ProvisionedProductId is required", 400);
+ }
+ requireText(request, "IdempotencyToken");
+ JsonNode properties = request.path("ProvisionedProductProperties");
+ if (!properties.isObject() || properties.isEmpty()) {
+ throw new AwsException("InvalidParametersException", "ProvisionedProductProperties is required", 400);
+ }
+ ObjectNode product = require(provisionedProductStore, provisionedProductId, "provisioned product");
+ product.set("ProvisionedProductProperties", properties.deepCopy());
+ provisionedProductStore.put(provisionedProductId, product);
+
+ String recordId = id("rec");
+ ObjectNode record = objectMapper.createObjectNode();
+ record.put("Type", "RECORD");
+ record.put("RecordId", recordId);
+ record.put("ProvisionedProductId", provisionedProductId);
+ record.put("ProvisionedProductName", text(product, "Name"));
+ record.put("ProductId", text(product, "ProductId"));
+ record.put("ProvisioningArtifactId", text(product, "ProvisioningArtifactId"));
+ record.put("RecordType", "UPDATE_PROVISIONED_PRODUCT");
+ record.put("Status", "SUCCEEDED");
+ record.put("CreatedTime", Instant.now().toEpochMilli() / 1000.0);
+ associationStore.put(recordId, record);
+
+ ObjectNode result = product.deepCopy();
+ result.put("RecordId", recordId);
+ return result;
+ }
+
+ public List<ObjectNode> listServiceActions() {
+ return associationStore.scan(key -> true).stream()
+ .filter(node -> "SERVICE_ACTION".equals(text(node, "Type")) && node.has("Id"))
+ .map(ObjectNode::deepCopy)
+ .toList();
+ }
+
+ public ObjectNode updateServiceAction(String id, JsonNode request) {
+ if (id == null || id.isBlank()) {
+ throw new AwsException("InvalidParametersException", "Id is required", 400);
+ }
+ ObjectNode action = associationStore.scan(key -> true).stream()
+ .filter(node -> "SERVICE_ACTION".equals(text(node, "Type")) && id.equals(text(node, "Id")))
+ .findFirst().orElseThrow(() -> notFound("service action", id));
+ copyIfPresent(request, action, "Name", "Description", "Definition");
+ associationStore.put(id, action);
+ return action.deepCopy();
+ }
+
+ public ObjectNode createProvisioningArtifact(JsonNode request, String region, String accountId) {
+ String productId = requireText(request, "ProductId");
+ requireText(request, "IdempotencyToken");
+ JsonNode parameters = request.path("Parameters");
+ if (!parameters.isObject() || parameters.isEmpty()) {
+ throw new AwsException("InvalidParametersException", "Parameters is required", 400);
+ }
+ ObjectNode product = requireProduct(productId);
+ String name = text(parameters, "Name");
+ if (name == null || name.isBlank()) {
+ name = "v" + (product.path("ProvisioningArtifactIds").size() + 1);
+ }
+ String type = text(parameters, "Type");
+ if (type == null || type.isBlank()) {
+ type = "CLOUD_FORMATION_TEMPLATE";
+ }
+ String artifactId = id("pa");
+ ((ArrayNode) product.path("ProvisioningArtifactIds")).add(artifactId);
+ ((ArrayNode) product.path("ProvisioningArtifactNames")).add(name);
+ productStore.put(text(product, "Id"), product);
+ ObjectNode detail = objectMapper.createObjectNode();
+ detail.put("Id", artifactId);
+ detail.put("Name", name);
+ detail.put("Type", type);
+ detail.put("CreatedTime", Instant.now().toEpochMilli() / 1000.0);
+ detail.put("Active", true);
+ String description = text(parameters, "Description");
+ if (description != null && !description.isBlank()) {
+ detail.put("Description", description);
+ }
+ return detail;
+ }
+
+ public ObjectNode describeCopyProductStatus(String token) {
+ if (token == null || token.isBlank()) {
+ throw new AwsException("InvalidParametersException", "CopyProductToken is required", 400);
+ }
+ return associationStore.get(token).orElseThrow(() ->
+ new AwsException("ResourceNotFoundException", "Unknown copy product token: " + token, 400));
+ }
+
+ public ObjectNode terminateProvisionedProduct(JsonNode request, String region, String accountId) {
+ requireText(request, "TerminateToken");
+ String provisionedProductId = text(request, "ProvisionedProductId");
+ String provisionedProductName = text(request, "ProvisionedProductName");
+ ObjectNode product = null;
+ if (provisionedProductId != null && !provisionedProductId.isBlank()) {
+ product = provisionedProductStore.get(provisionedProductId).orElse(null);
+ }
+ if (product == null && provisionedProductName != null && !provisionedProductName.isBlank()) {
+ String identifier = provisionedProductName;
+ if (identifier.contains(":provisionedproduct/")) {
+ identifier = identifier.substring(identifier.lastIndexOf('/') + 1);
+ }
+ final String finalIdentifier = identifier;
+ product = provisionedProductStore.scan(key -> true).stream()
+ .filter(p -> finalIdentifier.equals(text(p, "Name")) || finalIdentifier.equals(text(p, "Id")))
+ .findFirst().orElse(null);
+ }
+ if (product == null) {
+ throw new AwsException("ResourceNotFoundException",
+ "Unknown provisioned product: " + (provisionedProductId != null ? provisionedProductId : provisionedProductName), 400);
+ }
+ String id = text(product, "Id");
+ product.put("Status", "TERMINATED");
+ product.put("UpdatedTime", Instant.now().toEpochMilli() / 1000.0);
+ provisionedProductStore.put(id, product);
+
+ String recordId = id("rec");
+ ObjectNode record = objectMapper.createObjectNode();
+ record.put("Type", "RECORD");
+ record.put("RecordId", recordId);
+ record.put("ProvisionedProductId", id);
+ record.put("ProvisionedProductName", text(product, "Name"));
+ record.put("ProductId", text(product, "ProductId"));
+ record.put("ProvisioningArtifactId", text(product, "ProvisioningArtifactId"));
+ record.put("RecordType", "TERMINATE_PROVISIONED_PRODUCT");
+ record.put("Status", "SUCCEEDED");
+ record.put("CreatedTime", product.get("CreatedTime").asDouble());
+ record.put("UpdatedTime", product.get("UpdatedTime").asDouble());
+ associationStore.put(recordId, record);
+
+ ObjectNode result = product.deepCopy();
+ result.put("RecordId", recordId);
+ return result;
+ }
+
+ public ObjectNode updateProvisioningArtifact(String productId, String artifactId, JsonNode request) {
+ if (productId == null || productId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ProductId is required", 400);
+ }
+ if (artifactId == null || artifactId.isBlank()) {
+ throw new AwsException("InvalidParametersException", "ProvisioningArtifactId is required", 400);
+ }
+ ObjectNode product = requireProduct(productId);
+ JsonNode ids = product.path("ProvisioningArtifactIds");
+ int index = -1;
+ for (int i = 0; i < ids.size(); i++) {
+ if (artifactId.equals(ids.get(i).asText())) {
+ index = i;
+ break;
+ }
+ }
+ if (index < 0) {
+ throw new AwsException("ResourceNotFoundException",
+ "Unknown provisioning artifact: " + artifactId, 400);
+ }
+ JsonNode names = product.path("ProvisioningArtifactNames");
+ String newName = text(request, "Name");
+ if (newName != null && !newName.isBlank()) {
+ ((ArrayNode) names).set(index, objectMapper.getNodeFactory().textNode(newName));
+ productStore.put(text(product, "Id"), product);
+ }
+ ObjectNode detail = objectMapper.createObjectNode();
+ detail.put("Id", artifactId);
+ detail.put("Name", index < names.size() ? names.get(index).asText() : "");
+ detail.put("Active", true);
+ detail.put("Type", "CLOUD_FORMATION_TEMPLATE");
+ detail.put("CreatedTime", product.path("CreatedTime").asDouble());
+ return detail;
+ }
+}
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 3b30d59a03..9aa7bead3a 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -543,6 +543,8 @@ floci:
enabled: true
rum:
enabled: true
+ servicecatalog:
+ enabled: true
guardduty:
enabled: true
emrserverless:
diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/IamManagedPolicyAccountScopeTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/IamManagedPolicyAccountScopeTest.java
index 77e63bf5b0..bf8f135de6 100644
--- a/src/test/java/io/github/hectorvent/floci/services/iam/IamManagedPolicyAccountScopeTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/iam/IamManagedPolicyAccountScopeTest.java
@@ -84,6 +84,7 @@ class IamManagedPolicyAccountScopeTest {
assertTrue(arns.contains(AwsManagedPolicies.ARN_PREFIX + "/AWSXRayDaemonWriteAccess"));
assertTrue(arns.contains(AwsManagedPolicies.ARN_PREFIX + "/AWSCloudFormationReadOnlyAccess"));
assertTrue(arns.contains(AwsManagedPolicies.ARN_PREFIX + "/AWSCloudFormationFullAccess"));
+ assertTrue(arns.contains(AwsManagedPolicies.ARN_PREFIX + "/AWSServiceCatalogEndUserFullAccess"));
assertTrue(arns.contains(AwsManagedPolicies.ARN_PREFIX + "/AmazonElasticFileSystemClientFullAccess"));
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogBudgetAssociationConsumerTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogBudgetAssociationConsumerTest.java
new file mode 100644
index 0000000000..f33444cec8
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogBudgetAssociationConsumerTest.java
@@ -0,0 +1,128 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItem;
+
+/**
+ * Wire-level tests for {@code AssociateBudgetWithResource},
+ * {@code DisassociateBudgetFromResource} and {@code ListBudgetsForResource}.
+ *
+ * <p>New class, not appended to an existing one, so falsifiability isolates per
+ * operation (CS-001): removing one operation's dispatch case must fail only that
+ * operation's own tests. Assertions on error paths check the exception {@code __type},
+ * not just status code, since {@code AssociateBudgetWithResource}'s duplicate-association
+ * error and the handler's unsupported-operation default arm are both 400.
+ */
+@QuarkusTest
+class ServiceCatalogBudgetAssociationConsumerTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private static Response call(String action, String body) {
+ return given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
+ .header("Authorization", AUTH_HEADER)
+ .body(body)
+ .when()
+ .post("/");
+ }
+
+ private static String createProduct(String name) {
+ return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
+ + "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
+ .then().statusCode(200)
+ .extract().path("ProductViewDetail.ProductViewSummary.Id");
+ }
+
+ // ---------- AssociateBudgetWithResource ----------
+
+ @Test
+ void associateBudgetWithResource_returnsEmptyBody() {
+ String productId = createProduct("ab-budget-associate");
+ call("AssociateBudgetWithResource", "{\"BudgetName\":\"my-budget\",\"ResourceId\":\""
+ + productId + "\"}")
+ .then()
+ .statusCode(200);
+ }
+
+ @Test
+ void associateBudgetWithResource_duplicate_returnsDuplicateResourceException() {
+ String productId = createProduct("ab-budget-dup");
+ call("AssociateBudgetWithResource", "{\"BudgetName\":\"dup-budget\",\"ResourceId\":\""
+ + productId + "\"}")
+ .then().statusCode(200);
+
+ call("AssociateBudgetWithResource", "{\"BudgetName\":\"dup-budget\",\"ResourceId\":\""
+ + productId + "\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("DuplicateResourceException"));
+ }
+
+ @Test
+ void associateBudgetWithResource_unknownResource_returnsResourceNotFound() {
+ call("AssociateBudgetWithResource", "{\"BudgetName\":\"my-budget\",\"ResourceId\":\""
+ + "prod-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- DisassociateBudgetFromResource ----------
+
+ @Test
+ void disassociateBudgetFromResource_removesAssociation() {
+ String productId = createProduct("ab-budget-disassociate");
+ call("AssociateBudgetWithResource", "{\"BudgetName\":\"remove-me\",\"ResourceId\":\""
+ + productId + "\"}")
+ .then().statusCode(200);
+
+ call("DisassociateBudgetFromResource", "{\"BudgetName\":\"remove-me\",\"ResourceId\":\""
+ + productId + "\"}")
+ .then()
+ .statusCode(200);
+
+ call("ListBudgetsForResource", "{\"ResourceId\":\"" + productId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("Budgets.BudgetName.size()", equalTo(0));
+ }
+
+ // ---------- ListBudgetsForResource ----------
+
+ @Test
+ void listBudgetsForResource_returnsAssociatedBudgets() {
+ String productId = createProduct("ab-budget-list");
+ call("AssociateBudgetWithResource", "{\"BudgetName\":\"listed-budget\",\"ResourceId\":\""
+ + productId + "\"}")
+ .then().statusCode(200);
+
+ call("ListBudgetsForResource", "{\"ResourceId\":\"" + productId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("Budgets.BudgetName", hasItem("listed-budget"));
+ }
+
+ @Test
+ void listBudgetsForResource_unknownResource_returnsResourceNotFound() {
+ call("ListBudgetsForResource", "{\"ResourceId\":\"prod-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogCatalogReadOpsConsumerTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogCatalogReadOpsConsumerTest.java
new file mode 100644
index 0000000000..2dcbfa8f27
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogCatalogReadOpsConsumerTest.java
@@ -0,0 +1,316 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.startsWith;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+/**
+ * Wire-level tests for the five Service Catalog operations added together:
+ * {@code DescribeProduct}, {@code DescribePortfolioShares},
+ * {@code ListPortfoliosForProduct}, {@code CopyProduct} and
+ * {@code DescribeProvisioningArtifact}.
+ *
+ * <p>Grouped in one new class rather than five. The convention of one class per
+ * operation exists to stop a shared, pre-existing test from having its assertions
+ * weakened; a brand-new class cannot weaken anything, and every test here targets a
+ * single operation, so removing one dispatch case still fails only that operation's
+ * tests.
+ *
+ * <p>Each operation drives the real HTTP route with the real {@code X-Amz-Target},
+ * so the dispatch case is itself under test (CS-001).
+ */
+@QuarkusTest
+class ServiceCatalogCatalogReadOpsConsumerTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private static Response call(String action, String body) {
+ return given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
+ .header("Authorization", AUTH_HEADER)
+ .body(body)
+ .when()
+ .post("/");
+ }
+
+ /** Creates a product and returns its id, so each test owns its fixture. */
+ private static String createProduct(String name) {
+ return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
+ + "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
+ .then().statusCode(200)
+ .extract().path("ProductViewDetail.ProductViewSummary.Id");
+ }
+
+ private static String createPortfolio(String displayName) {
+ return call("CreatePortfolio", "{\"DisplayName\":\"" + displayName
+ + "\",\"ProviderName\":\"floci-test\"}")
+ .then().statusCode(200)
+ .extract().path("PortfolioDetail.Id");
+ }
+
+ // ---------- DescribeProduct ----------
+
+ @Test
+ void describeProduct_returnsSummaryAndArtifacts() {
+ String productId = createProduct("ab-describe-product");
+ call("DescribeProduct", "{\"Id\":\"" + productId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("ProductViewSummary.Id", equalTo(productId))
+ .body("ProductViewSummary.Name", equalTo("ab-describe-product"))
+ .body("ProvisioningArtifacts[0].Id", startsWith("pa-"))
+ .body("ProvisioningArtifacts[0].Name", equalTo("v1"));
+ }
+
+ /** DescribeProduct must not return the admin shape; the two differ on the wire. */
+ @Test
+ void describeProduct_doesNotReturnAdminOnlyProductViewDetail() {
+ String productId = createProduct("ab-describe-product-shape");
+ call("DescribeProduct", "{\"Id\":\"" + productId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("ProductViewDetail", equalTo(null))
+ .body("ProvisioningArtifactDetails", equalTo(null));
+ }
+
+ @Test
+ void describeProduct_unknownId_returnsResourceNotFound() {
+ call("DescribeProduct", "{\"Id\":\"prod-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- DescribePortfolioShares ----------
+
+ @Test
+ void describePortfolioShares_returnsSharesCreatedForThePortfolio() {
+ String portfolioId = createPortfolio("ab-shares-portfolio");
+ call("CreatePortfolioShare", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"AccountId\":\"222222222222\"}").then().statusCode(200);
+
+ call("DescribePortfolioShares", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"Type\":\"ACCOUNT\"}")
+ .then()
+ .statusCode(200)
+ .body("PortfolioShareDetails.PrincipalId", hasItem("222222222222"))
+ .body("PortfolioShareDetails.Type", hasItem("ACCOUNT"))
+ .body("PortfolioShareDetails[0].Accepted", equalTo(true));
+ }
+
+ /** A portfolio with no shares is an empty list, not an error. */
+ @Test
+ void describePortfolioShares_noShares_returnsEmptyList() {
+ String portfolioId = createPortfolio("ab-shares-empty");
+ call("DescribePortfolioShares", "{\"PortfolioId\":\"" + portfolioId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("PortfolioShareDetails.size()", equalTo(0));
+ }
+
+ @Test
+ void describePortfolioShares_unknownPortfolio_returnsResourceNotFound() {
+ call("DescribePortfolioShares", "{\"PortfolioId\":\"port-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ /**
+ * Asserts the message, not just the type. The handler's default arm also returns
+ * InvalidParametersException at 400, so a type-only assertion would pass even with
+ * the dispatch case deleted and would prove nothing about this operation (CS-001).
+ */
+ @Test
+ void describePortfolioShares_missingPortfolioId_returnsInvalidParameters() {
+ call("DescribePortfolioShares", "{}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"))
+ .body("message", equalTo("PortfolioId is required"));
+ }
+
+ /**
+ * {@code Type} selects which share flavour to report and botocore pins it to
+ * {@code DescribePortfolioShareType}. An unmodelled value used to match nothing and
+ * return an empty list — a client filtering on a typo saw "no shares", not an error.
+ */
+ @Test
+ void describePortfolioShares_unknownType_returnsInvalidParameters() {
+ String portfolioId = createPortfolio("ab-shares-badtype");
+ call("DescribePortfolioShares", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"Type\":\"ACCOUNTS\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"))
+ .body("message", startsWith("Type must be one of"));
+ }
+
+ // ---------- CreatePortfolioShare ----------
+
+ /**
+ * The share's store key is built from {@code OrganizationNode.Type}, so an unmodelled
+ * type used to create a share DescribePortfolioShares then reported back verbatim.
+ */
+ @Test
+ void createPortfolioShare_unknownOrganizationNodeType_returnsInvalidParameters() {
+ String portfolioId = createPortfolio("ab-share-badnode");
+ call("CreatePortfolioShare", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"OrganizationNode\":{\"Type\":\"TEAM\",\"Value\":\"o-abcdefghij\"}}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"))
+ .body("message", startsWith("OrganizationNode.Type must be one of"));
+ }
+
+ /** botocore pins AccountId to ^[0-9]{12}$; a short id used to become a share key. */
+ @Test
+ void createPortfolioShare_malformedAccountId_returnsInvalidParameters() {
+ String portfolioId = createPortfolio("ab-share-badaccount");
+ call("CreatePortfolioShare", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"AccountId\":\"2222\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"))
+ .body("message", startsWith("AccountId must be a 12-digit"));
+ }
+
+ // ---------- ListPortfoliosForProduct ----------
+
+ @Test
+ void listPortfoliosForProduct_returnsAssociatedPortfolioOnly() {
+ String productId = createProduct("ab-lpfp-product");
+ String associated = createPortfolio("ab-lpfp-associated");
+ String unrelated = createPortfolio("ab-lpfp-unrelated");
+ call("AssociateProductWithPortfolio", "{\"PortfolioId\":\"" + associated
+ + "\",\"ProductId\":\"" + productId + "\"}").then().statusCode(200);
+
+ Response response = call("ListPortfoliosForProduct", "{\"ProductId\":\"" + productId + "\"}");
+ response.then()
+ .statusCode(200)
+ .body("PortfolioDetails.Id", hasItem(associated));
+
+ assertNotEquals(unrelated, response.path("PortfolioDetails[0].Id"),
+ "an unassociated portfolio must not be returned");
+ assertEquals(1, (Integer) response.path("PortfolioDetails.size()"));
+ }
+
+ @Test
+ void listPortfoliosForProduct_noAssociations_returnsEmptyList() {
+ String productId = createProduct("ab-lpfp-none");
+ call("ListPortfoliosForProduct", "{\"ProductId\":\"" + productId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("PortfolioDetails.size()", equalTo(0));
+ }
+
+ @Test
+ void listPortfoliosForProduct_unknownProduct_returnsResourceNotFound() {
+ call("ListPortfoliosForProduct", "{\"ProductId\":\"prod-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- CopyProduct ----------
+
+ @Test
+ void copyProduct_createsIndependentCopyAndReturnsToken() {
+ String sourceId = createProduct("ab-copy-source");
+ String sourceArn = call("DescribeProductAsAdmin", "{\"Id\":\"" + sourceId + "\"}")
+ .then().statusCode(200)
+ .extract().path("ProductViewDetail.ProductViewSummary.ARN");
+
+ String token = call("CopyProduct", "{\"SourceProductArn\":\"" + sourceArn
+ + "\",\"TargetProductName\":\"ab-copy-target\"}")
+ .then().statusCode(200)
+ .body("CopyProductToken", notNullValue())
+ .extract().path("CopyProductToken");
+ assertEquals(true, token.startsWith("copy-"), "token was: " + token);
+
+ // The copy is a distinct product carrying the target name.
+ Response search = call("SearchProductsAsAdmin", "{}");
+ search.then().statusCode(200)
+ .body("ProductViewDetails.ProductViewSummary.Name", hasItem("ab-copy-target"))
+ .body("ProductViewDetails.ProductViewSummary.Name", hasItem("ab-copy-source"));
+ }
+
+ @Test
+ void copyProduct_withoutTargetName_keepsSourceName() {
+ String sourceId = createProduct("ab-copy-keepname");
+ String sourceArn = call("DescribeProductAsAdmin", "{\"Id\":\"" + sourceId + "\"}")
+ .then().statusCode(200)
+ .extract().path("ProductViewDetail.ProductViewSummary.ARN");
+ call("CopyProduct", "{\"SourceProductArn\":\"" + sourceArn + "\"}")
+ .then()
+ .statusCode(200)
+ .body("CopyProductToken", startsWith("copy-"));
+ }
+
+ /** Message-level assertion for the same reason as the DescribePortfolioShares case. */
+ @Test
+ void copyProduct_missingSourceArn_returnsInvalidParameters() {
+ call("CopyProduct", "{}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"))
+ .body("message", equalTo("SourceProductArn is required"));
+ }
+
+ @Test
+ void copyProduct_unknownSourceProduct_returnsResourceNotFound() {
+ call("CopyProduct", "{\"SourceProductArn\":"
+ + "\"arn:aws:catalog:us-east-1:000000000000:product/prod-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- DescribeProvisioningArtifact ----------
+
+ @Test
+ void describeProvisioningArtifact_byProductAndArtifactId_returnsDetail() {
+ String productId = createProduct("ab-dpa-product");
+ String artifactId = call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
+ .then().statusCode(200)
+ .extract().path("ProvisioningArtifactDetails[0].Id");
+
+ call("DescribeProvisioningArtifact", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("ProvisioningArtifactDetail.Id", equalTo(artifactId))
+ .body("ProvisioningArtifactDetail.Name", equalTo("v1"))
+ .body("ProvisioningArtifactDetail.Type", equalTo("CLOUD_FORMATION_TEMPLATE"))
+ .body("ProvisioningArtifactDetail.Active", equalTo(true))
+ .body("Status", equalTo("AVAILABLE"));
+ }
+
+ @Test
+ void describeProvisioningArtifact_unknownArtifact_returnsResourceNotFound() {
+ String productId = createProduct("ab-dpa-unknown");
+ call("DescribeProvisioningArtifact", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"pa-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogConstraintConsumerTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogConstraintConsumerTest.java
new file mode 100644
index 0000000000..69b80aa8de
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogConstraintConsumerTest.java
@@ -0,0 +1,144 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+
+/**
+ * Wire-level tests for {@code CreateConstraint}, {@code DescribeConstraint},
+ * {@code UpdateConstraint} and {@code DeleteConstraint}.
+ *
+ * <p>New class, not appended to an existing one, so falsifiability isolates per
+ * operation (CS-001). {@code ConstraintId} and {@code Type} are asserted by value,
+ * not just presence, because {@code describeConstraint}'s handler originally read
+ * the stored object's fields under the wrong names ({@code Id}/{@code ConstraintType}
+ * instead of {@code ConstraintId}/{@code Type}) and always returned empty strings —
+ * a value-level assertion is what would have caught that.
+ */
+@QuarkusTest
+class ServiceCatalogConstraintConsumerTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private static Response call(String action, String body) {
+ return given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
+ .header("Authorization", AUTH_HEADER)
+ .body(body)
+ .when()
+ .post("/");
+ }
+
+ private static String createProduct(String name) {
+ return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
+ + "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
+ .then().statusCode(200)
+ .extract().path("ProductViewDetail.ProductViewSummary.Id");
+ }
+
+ private static String createPortfolio(String displayName) {
+ return call("CreatePortfolio", "{\"DisplayName\":\"" + displayName
+ + "\",\"ProviderName\":\"floci-test\"}")
+ .then().statusCode(200)
+ .extract().path("PortfolioDetail.Id");
+ }
+
+ private static String createConstraint(String portfolioId, String productId) {
+ return call("CreateConstraint", "{\"PortfolioId\":\"" + portfolioId + "\",\"ProductId\":\""
+ + productId + "\",\"Parameters\":\"{}\",\"Type\":\"LAUNCH\",\"IdempotencyToken\":\""
+ + "tok-" + portfolioId + "\"}")
+ .then().statusCode(200)
+ .extract().path("ConstraintDetail.ConstraintId");
+ }
+
+ // ---------- CreateConstraint ----------
+
+ @Test
+ void createConstraint_returnsConstraintDetailMatchingRequest() {
+ String portfolioId = createPortfolio("ab-constraint-portfolio");
+ String productId = createProduct("ab-constraint-product");
+ call("CreateConstraint", "{\"PortfolioId\":\"" + portfolioId + "\",\"ProductId\":\""
+ + productId + "\",\"Parameters\":\"{}\",\"Type\":\"LAUNCH\",\"IdempotencyToken\":\"tok-1\"}")
+ .then()
+ .statusCode(200)
+ .body("ConstraintDetail.Type", equalTo("LAUNCH"))
+ .body("ConstraintDetail.PortfolioId", equalTo(portfolioId))
+ .body("ConstraintDetail.ProductId", equalTo(productId))
+ .body("ConstraintDetail.ConstraintId", org.hamcrest.Matchers.notNullValue());
+ }
+
+ // ---------- DescribeConstraint ----------
+
+ @Test
+ void describeConstraint_returnsConstraintIdAndType() {
+ String portfolioId = createPortfolio("ab-describe-constraint-portfolio");
+ String productId = createProduct("ab-describe-constraint-product");
+ String constraintId = createConstraint(portfolioId, productId);
+
+ call("DescribeConstraint", "{\"Id\":\"" + constraintId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("ConstraintDetail.ConstraintId", equalTo(constraintId))
+ .body("ConstraintDetail.Type", equalTo("LAUNCH"))
+ .body("ConstraintDetail.PortfolioId", equalTo(portfolioId));
+ }
+
+ @Test
+ void describeConstraint_unknownId_returnsResourceNotFound() {
+ call("DescribeConstraint", "{\"Id\":\"con-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- UpdateConstraint ----------
+
+ @Test
+ void updateConstraint_changesDescription() {
+ String portfolioId = createPortfolio("ab-update-constraint-portfolio");
+ String productId = createProduct("ab-update-constraint-product");
+ String constraintId = createConstraint(portfolioId, productId);
+
+ call("UpdateConstraint", "{\"Id\":\"" + constraintId + "\",\"Description\":\"updated\"}")
+ .then()
+ .statusCode(200)
+ .body("ConstraintDetail.ConstraintId", equalTo(constraintId))
+ .body("ConstraintDetail.Description", equalTo("updated"));
+
+ call("DescribeConstraint", "{\"Id\":\"" + constraintId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("ConstraintDetail.Description", equalTo("updated"));
+ }
+
+ // ---------- DeleteConstraint ----------
+
+ @Test
+ void deleteConstraint_removesConstraint() {
+ String portfolioId = createPortfolio("ab-delete-constraint-portfolio");
+ String productId = createProduct("ab-delete-constraint-product");
+ String constraintId = createConstraint(portfolioId, productId);
+
+ call("DeleteConstraint", "{\"Id\":\"" + constraintId + "\"}")
+ .then()
+ .statusCode(200);
+
+ call("DescribeConstraint", "{\"Id\":\"" + constraintId + "\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogDescribeQueryConsumerTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogDescribeQueryConsumerTest.java
new file mode 100644
index 0000000000..bc5e43b69a
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogDescribeQueryConsumerTest.java
@@ -0,0 +1,197 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItem;
+
+/**
+ * Wire-level tests for {@code DescribeCopyProductStatus}, {@code DescribeProductView},
+ * {@code DescribeProvisioningParameters} and
+ * {@code DescribeServiceActionExecutionParameters}.
+ *
+ * <p>New class, not appended to an existing one, so falsifiability isolates per
+ * operation (CS-001). {@code describeCopyProductStatus} looked up a token via
+ * {@code associationStore} that {@code copyProduct} (already {@code accepted} from
+ * earlier this session) never persisted — same shape as issues 0020/0021. Fixed by
+ * having {@code copyProduct} store a status row under the token it returns.
+ */
+@QuarkusTest
+class ServiceCatalogDescribeQueryConsumerTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private static Response call(String action, String body) {
+ return given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
+ .header("Authorization", AUTH_HEADER)
+ .body(body)
+ .when()
+ .post("/");
+ }
+
+ private static String createProduct(String name) {
+ return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
+ + "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
+ .then().statusCode(200)
+ .extract().path("ProductViewDetail.ProductViewSummary.Id");
+ }
+
+ private static String describeProductAsAdminArn(String productId) {
+ return call("DescribeProductAsAdmin", "{\"Id\":\"" + productId + "\"}")
+ .then().statusCode(200)
+ .extract().path("ProductViewDetail.ProductViewSummary.ARN");
+ }
+
+ // ---------- DescribeCopyProductStatus ----------
+
+ @Test
+ void describeCopyProductStatus_returnsSucceededWithTargetProductId() {
+ String sourceId = createProduct("ab-copy-status-source");
+ String sourceArn = describeProductAsAdminArn(sourceId);
+
+ String token = call("CopyProduct", "{\"SourceProductArn\":\"" + sourceArn
+ + "\",\"TargetProductName\":\"ab-copy-status-target\"}")
+ .then().statusCode(200)
+ .extract().path("CopyProductToken");
+
+ call("DescribeCopyProductStatus", "{\"CopyProductToken\":\"" + token + "\"}")
+ .then()
+ .statusCode(200)
+ .body("CopyProductStatus", equalTo("SUCCEEDED"))
+ .body("TargetProductId", org.hamcrest.Matchers.notNullValue());
+ }
+
+ // ---------- DescribeProductView ----------
+
+ @Test
+ void describeProductView_returnsSummaryAndArtifacts() {
+ String productId = createProduct("ab-product-view");
+
+ call("DescribeProductView", "{\"Id\":\"" + productId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("ProductViewSummary.Id", equalTo(productId))
+ .body("ProvisioningArtifacts.Name", hasItem("v1"));
+ }
+
+ @Test
+ void describeProductView_missingId_returnsInvalidParameters() {
+ call("DescribeProductView", "{}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"));
+ }
+
+ // ---------- DescribeProvisioningParameters ----------
+
+ @Test
+ void describeProvisioningParameters_returnsParameterKeys() {
+ String productId = call("CreateProduct", "{\"Name\":\"ab-provisioning-params\",\"Owner\":\""
+ + "floci-test\",\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\",\"Info\":{"
+ + "\"LoadTemplateFromURL\":\"https://example.com/template.json\"}}]}")
+ .then().statusCode(200)
+ .extract().path("ProductViewDetail.ProductViewSummary.Id");
+
+ call("DescribeProvisioningParameters", "{\"ProductId\":\"" + productId + "\"}")
+ .then()
+ .statusCode(200);
+ }
+
+ @Test
+ void describeProvisioningParameters_unknownArtifact_returnsResourceNotFound() {
+ String productId = createProduct("ab-provisioning-params-unknown-artifact");
+
+ call("DescribeProvisioningParameters", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"pa-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ @Test
+ void describeProvisioningParameters_missingProductIdAndName_returnsInvalidParameters() {
+ call("DescribeProvisioningParameters", "{}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"));
+ }
+
+ // ---------- DescribeServiceActionExecutionParameters ----------
+
+ private static String importProvisionedProduct(String productId, String name) {
+ return call("ImportAsProvisionedProduct", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"pa-anything\",\"ProvisionedProductName\":\""
+ + name + "\",\"PhysicalId\":\"phys-" + name + "\",\"IdempotencyToken\":\"tok-" + name + "\"}")
+ .then().statusCode(200)
+ .extract().path("RecordDetail.ProvisionedProductId");
+ }
+
+ @Test
+ void describeServiceActionExecutionParameters_returnsEmptyParameterList() {
+ String productId = createProduct("ab-safep-product");
+ String provisionedId = importProvisionedProduct(productId, "ab-safep-pp");
+
+ call("DescribeServiceActionExecutionParameters", "{\"ProvisionedProductId\":\"" + provisionedId
+ + "\",\"ServiceActionId\":\"sa-anything\"}")
+ .then()
+ .statusCode(200)
+ .body("ServiceActionParameters.size()", equalTo(0));
+ }
+
+ @Test
+ void describeServiceActionExecutionParameters_unknownProduct_returnsResourceNotFound() {
+ call("DescribeServiceActionExecutionParameters", "{\"ProvisionedProductId\":\"pp-doesnotexist\","
+ + "\"ServiceActionId\":\"sa-anything\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ @Test
+ void describeServiceActionExecutionParameters_missingServiceActionId_returnsInvalidParameters() {
+ call("DescribeServiceActionExecutionParameters", "{\"ProvisionedProductId\":\"pp-anything\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"));
+ }
+
+ // ---------- missing identifier parameters ----------
+
+ @Test
+ void describeProductAsAdmin_missingId_returnsInvalidParameters() {
+ call("DescribeProductAsAdmin", "{}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"));
+ }
+
+ @Test
+ void describePortfolio_missingId_returnsInvalidParameters() {
+ call("DescribePortfolio", "{}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"));
+ }
+
+ @Test
+ void describeTagOption_missingId_returnsInvalidParameters() {
+ call("DescribeTagOption", "{}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogEngineWorkflowNotifyConsumerTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogEngineWorkflowNotifyConsumerTest.java
new file mode 100644
index 0000000000..88fb2d83c5
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogEngineWorkflowNotifyConsumerTest.java
@@ -0,0 +1,101 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+
+/**
+ * Wire-level tests for {@code NotifyProvisionProductEngineWorkflowResult},
+ * {@code NotifyUpdateProvisionedProductEngineWorkflowResult} and
+ * {@code NotifyTerminateProvisionedProductEngineWorkflowResult}.
+ *
+ * <p>New class, not appended to an existing one, so falsifiability isolates per
+ * operation (CS-001). {@code NotifyTerminate...} already validated {@code Status}
+ * against {@code SUCCEEDED}/{@code FAILED}; the other two accepted any string. Made
+ * consistent across all three as part of this session's batch (they represent the
+ * same concept — an external provisioning engine reporting a workflow outcome).
+ */
+@QuarkusTest
+class ServiceCatalogEngineWorkflowNotifyConsumerTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private static Response call(String action, String body) {
+ return given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
+ .header("Authorization", AUTH_HEADER)
+ .body(body)
+ .when()
+ .post("/");
+ }
+
+ // ---------- NotifyProvisionProductEngineWorkflowResult ----------
+
+ @Test
+ void notifyProvisionProductEngineWorkflowResult_succeeded_returnsEmptyBody() {
+ call("NotifyProvisionProductEngineWorkflowResult", "{\"WorkflowToken\":\"wf-1\","
+ + "\"RecordId\":\"rec-1\",\"Status\":\"SUCCEEDED\",\"IdempotencyToken\":\"tok-1\"}")
+ .then()
+ .statusCode(200);
+ }
+
+ @Test
+ void notifyProvisionProductEngineWorkflowResult_invalidStatus_returnsInvalidParameters() {
+ call("NotifyProvisionProductEngineWorkflowResult", "{\"WorkflowToken\":\"wf-2\","
+ + "\"RecordId\":\"rec-2\",\"Status\":\"BOGUS\",\"IdempotencyToken\":\"tok-2\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"));
+ }
+
+ // ---------- NotifyUpdateProvisionedProductEngineWorkflowResult ----------
+
+ @Test
+ void notifyUpdateProvisionedProductEngineWorkflowResult_failed_returnsEmptyBody() {
+ call("NotifyUpdateProvisionedProductEngineWorkflowResult", "{\"WorkflowToken\":\"wf-3\","
+ + "\"RecordId\":\"rec-3\",\"Status\":\"FAILED\",\"IdempotencyToken\":\"tok-3\"}")
+ .then()
+ .statusCode(200);
+ }
+
+ @Test
+ void notifyUpdateProvisionedProductEngineWorkflowResult_invalidStatus_returnsInvalidParameters() {
+ call("NotifyUpdateProvisionedProductEngineWorkflowResult", "{\"WorkflowToken\":\"wf-4\","
+ + "\"RecordId\":\"rec-4\",\"Status\":\"BOGUS\",\"IdempotencyToken\":\"tok-4\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"));
+ }
+
+ // ---------- NotifyTerminateProvisionedProductEngineWorkflowResult ----------
+
+ @Test
+ void notifyTerminateProvisionedProductEngineWorkflowResult_succeeded_returnsEmptyBody() {
+ call("NotifyTerminateProvisionedProductEngineWorkflowResult", "{\"WorkflowToken\":\"wf-5\","
+ + "\"RecordId\":\"rec-5\",\"Status\":\"SUCCEEDED\",\"IdempotencyToken\":\"tok-5\"}")
+ .then()
+ .statusCode(200);
+ }
+
+ @Test
+ void notifyTerminateProvisionedProductEngineWorkflowResult_invalidStatus_returnsInvalidParameters() {
+ call("NotifyTerminateProvisionedProductEngineWorkflowResult", "{\"WorkflowToken\":\"wf-6\","
+ + "\"RecordId\":\"rec-6\",\"Status\":\"BOGUS\",\"IdempotencyToken\":\"tok-6\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogExecuteServiceActionConsumerTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogExecuteServiceActionConsumerTest.java
new file mode 100644
index 0000000000..0583a8f89c
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogExecuteServiceActionConsumerTest.java
@@ -0,0 +1,108 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+
+/**
+ * Wire-level tests for {@code ExecuteProvisionedProductServiceAction}.
+ *
+ * <p>New class, not appended to an existing one, so falsifiability isolates per
+ * operation (CS-001). Same bug shape as issue 0021 (DescribeRecord): the handler
+ * generated and discarded its own throwaway {@code RecordId} instead of persisting
+ * one. Fixed the same way — the service now persists a {@code RECORD} row and
+ * returns its id, the handler reads it back.
+ */
+@QuarkusTest
+class ServiceCatalogExecuteServiceActionConsumerTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private static Response call(String action, String body) {
+ return given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
+ .header("Authorization", AUTH_HEADER)
+ .body(body)
+ .when()
+ .post("/");
+ }
+
+ private static String createProduct(String name) {
+ return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
+ + "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
+ .then().statusCode(200)
+ .extract().path("ProductViewDetail.ProductViewSummary.Id");
+ }
+
+ private static String firstArtifactId(String productId) {
+ return call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
+ .then().statusCode(200)
+ .extract().path("ProvisioningArtifactDetails[0].Id");
+ }
+
+ private static String importProvisionedProduct(String productId, String artifactId, String name) {
+ return call("ImportAsProvisionedProduct", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ProvisionedProductName\":\""
+ + name + "\",\"PhysicalId\":\"phys-" + name + "\",\"IdempotencyToken\":\"tok-" + name + "\"}")
+ .then().statusCode(200)
+ .extract().path("RecordDetail.ProvisionedProductId");
+ }
+
+ @Test
+ void executeProvisionedProductServiceAction_returnsDescribableRecord() {
+ String productId = createProduct("ab-execute-action-product");
+ String artifactId = firstArtifactId(productId);
+ String provisionedId = importProvisionedProduct(productId, artifactId, "ab-execute-action-pp");
+
+ String recordId = call("ExecuteProvisionedProductServiceAction", "{\"ProvisionedProductId\":\""
+ + provisionedId + "\",\"ServiceActionId\":\"sa-anything\",\"ExecuteToken\":\""
+ + "tok-execute-action\"}")
+ .then()
+ .statusCode(200)
+ .body("RecordDetail.ProvisionedProductId", equalTo(provisionedId))
+ .body("RecordDetail.Status", equalTo("SUCCEEDED"))
+ .extract().path("RecordDetail.RecordId");
+
+ call("DescribeRecord", "{\"Id\":\"" + recordId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("RecordDetail.RecordId", equalTo(recordId))
+ .body("RecordDetail.ProvisionedProductId", equalTo(provisionedId))
+ .body("RecordDetail.RecordType", equalTo("UPDATE_PROVISIONED_PRODUCT"));
+ }
+
+ @Test
+ void executeProvisionedProductServiceAction_unknownProduct_returnsResourceNotFound() {
+ call("ExecuteProvisionedProductServiceAction", "{\"ProvisionedProductId\":\"pp-doesnotexist\","
+ + "\"ServiceActionId\":\"sa-anything\",\"ExecuteToken\":\"tok-unknown\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ @Test
+ void executeProvisionedProductServiceAction_missingServiceActionId_returnsInvalidParameters() {
+ String productId = createProduct("ab-execute-action-missing-sa-product");
+ String artifactId = firstArtifactId(productId);
+ String provisionedId = importProvisionedProduct(productId, artifactId, "ab-execute-action-missing-sa");
+
+ call("ExecuteProvisionedProductServiceAction", "{\"ProvisionedProductId\":\"" + provisionedId
+ + "\",\"ExecuteToken\":\"tok-missing-sa\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogIntegrationTest.java
new file mode 100644
index 0000000000..3e473ba7cf
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogIntegrationTest.java
@@ -0,0 +1,303 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.hasSize;
+
+@QuarkusTest
+class ServiceCatalogIntegrationTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String TARGET = "AWS242ServiceCatalogService.";
+ private static final String ORGANIZATIONS_TARGET = "AWSOrganizationsV20161128.";
+ private static final String AUTH =
+ "AWS4-HMAC-SHA256 Credential=723679240095/20260101/us-east-1/servicecatalog/aws4_request";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ @Test
+ void createAndListPortfolio_returnsAwsShape() {
+ String id = given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "CreatePortfolio")
+ .header("Authorization", AUTH)
+ .body("{\"DisplayName\":\"VellumGoldenWorkloads\","
+ + "\"ProviderName\":\"Vellum Cloud Platform\"}")
+ .when().post("/")
+ .then().statusCode(200)
+ .body("PortfolioDetail.DisplayName", equalTo("VellumGoldenWorkloads"))
+ .extract().path("PortfolioDetail.Id");
+
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "ListPortfolios")
+ .header("Authorization", AUTH)
+ .body("{}")
+ .when().post("/")
+ .then().statusCode(200)
+ .body("PortfolioDetails.Id", hasItem(id))
+ .body("PortfolioDetails.DisplayName", hasItem("VellumGoldenWorkloads"));
+ }
+
+ @Test
+ void listPortfolios_includesControlTowerAccountFactoryPortfolio() {
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "ListPortfolios")
+ .header("Authorization", AUTH)
+ .body("{}")
+ .when().post("/")
+ .then().statusCode(200)
+ .body("PortfolioDetails.DisplayName",
+ hasItem(ServiceCatalogService.CONTROL_TOWER_PORTFOLIO_NAME))
+ .body("PortfolioDetails.ProviderName",
+ hasItem(ServiceCatalogService.CONTROL_TOWER_PROVIDER_NAME))
+ .body("PortfolioDetails.Id",
+ hasItem(ServiceCatalogService.CONTROL_TOWER_PORTFOLIO_ID));
+ }
+
+ @Test
+ void updatePortfolioShare_isStoredAndImmediatelyComplete() {
+ String portfolioId = given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "CreatePortfolio")
+ .header("Authorization", AUTH)
+ .body("{\"DisplayName\":\"Shared\",\"ProviderName\":\"Vellum\"}")
+ .when().post("/").then().statusCode(200)
+ .extract().path("PortfolioDetail.Id");
+
+ String token = given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "UpdatePortfolioShare")
+ .header("Authorization", AUTH)
+ .body("{\"PortfolioId\":\"" + portfolioId + "\","
+ + "\"OrganizationNode\":{\"Type\":\"ORGANIZATIONAL_UNIT\","
+ + "\"Value\":\"ou-vellum-workloads\"},\"ShareTagOptions\":true}")
+ .when().post("/").then().statusCode(200)
+ .body("Status", equalTo("COMPLETED"))
+ .extract().path("PortfolioShareToken");
+
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "DescribePortfolioShareStatus")
+ .header("Authorization", AUTH)
+ .body("{\"PortfolioShareToken\":\"" + token + "\"}")
+ .when().post("/").then().statusCode(200)
+ .body("Status", equalTo("COMPLETED"));
+ }
+
+ @Test
+ void searchProvisionedProducts_returnsEmptyAwsShapeWhenNoneExist() {
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "SearchProvisionedProducts")
+ .header("Authorization", AUTH)
+ .body("{\"Filters\":{\"SearchQuery\":[\"physicalId: 723679240095\"]},"
+ + "\"AccessLevelFilter\":{\"Key\":\"Account\",\"Value\":\"self\"}}")
+ .when().post("/")
+ .then().statusCode(200)
+ .body("ProvisionedProducts", hasSize(0))
+ .body("TotalResultsCount", equalTo(0));
+ }
+
+ @Test
+ void searchProductsAndListArtifacts_includeControlTowerAccountFactory() {
+ String productId = given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "SearchProducts")
+ .header("Authorization", AUTH)
+ .body("{\"Filters\":{\"FullTextSearch\":[\"AWS Control Tower Account Factory\"]}}")
+ .when().post("/")
+ .then().statusCode(200)
+ .body("ProductViewSummaries", hasSize(1))
+ .body("ProductViewSummaries[0].Name", equalTo(ServiceCatalogService.CONTROL_TOWER_PRODUCT_NAME))
+ .extract().path("ProductViewSummaries[0].ProductId");
+
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "ListProvisioningArtifacts")
+ .header("Authorization", AUTH)
+ .body("{\"ProductId\":\"" + productId + "\"}")
+ .when().post("/")
+ .then().statusCode(200)
+ .body("ProvisioningArtifactDetails", hasSize(1))
+ .body("ProvisioningArtifactDetails[0].Id",
+ equalTo(ServiceCatalogService.CONTROL_TOWER_ARTIFACT_ID))
+ .body("ProvisioningArtifactDetails[0].Active", equalTo(true));
+ }
+
+ @Test
+ void provisionControlTowerProduct_createsAccountAndPersistsAvailableProduct() {
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", ORGANIZATIONS_TARGET + "CreateOrganization")
+ .header("Authorization", AUTH)
+ .body("{\"FeatureSet\":\"ALL\"}")
+ .when().post("/").then().statusCode(200);
+
+ String rootId = given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", ORGANIZATIONS_TARGET + "ListRoots")
+ .header("Authorization", AUTH)
+ .body("{}")
+ .when().post("/").then().statusCode(200)
+ .extract().path("Roots[0].Id");
+ String ouId = given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", ORGANIZATIONS_TARGET + "CreateOrganizationalUnit")
+ .header("Authorization", AUTH)
+ .body("{\"ParentId\":\"" + rootId + "\",\"Name\":\"Workloads\"}")
+ .when().post("/").then().statusCode(200)
+ .extract().path("OrganizationalUnit.Id");
+
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "ProvisionProduct")
+ .header("Authorization", AUTH)
+ .body("{\"ProductName\":\"AWS Control Tower Account Factory\","
+ + "\"ProvisioningArtifactId\":\"" + ServiceCatalogService.CONTROL_TOWER_ARTIFACT_ID + "\","
+ + "\"ProvisionedProductName\":\"ServiceCatalogWorkload\","
+ + "\"ProvisionToken\":\"token-1\",\"ProvisioningParameters\":["
+ + "{\"Key\":\"AccountName\",\"Value\":\"ServiceCatalogWorkload\"},"
+ + "{\"Key\":\"AccountEmail\",\"Value\":\"[email protected]\"},"
+ + "{\"Key\":\"ManagedOrganizationalUnit\","
+ + "\"Value\":\"Workloads (" + ouId + ")\"}]}")
+ .when().post("/")
+ .then().statusCode(200)
+ .body("RecordDetail.Status", equalTo("SUCCEEDED"));
+
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "SearchProvisionedProducts")
+ .header("Authorization", AUTH)
+ .body("{\"Filters\":{\"SearchQuery\":[\"status: AVAILABLE\"]},"
+ + "\"AccessLevelFilter\":{\"Key\":\"Account\",\"Value\":\"self\"}}")
+ .when().post("/")
+ .then().statusCode(200)
+ .body("ProvisionedProducts", hasSize(1))
+ .body("ProvisionedProducts[0].Type", equalTo("CONTROL_TOWER_ACCOUNT"))
+ .body("ProvisionedProducts[0].Status", equalTo("AVAILABLE"));
+ }
+
+ @Test
+ void acceptPortfolioShare_withExistingPortfolio_returnsEmptyBody() {
+ String portfolioId = given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "CreatePortfolio")
+ .header("Authorization", AUTH)
+ .body("{\"DisplayName\":\"ShareAccept\",\"ProviderName\":\"Vellum\"}")
+ .when().post("/").then().statusCode(200)
+ .extract().path("PortfolioDetail.Id");
+
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "AcceptPortfolioShare")
+ .header("Authorization", AUTH)
+ .body("{\"PortfolioId\":\"" + portfolioId + "\"}")
+ .when().post("/")
+ .then().statusCode(200);
+ }
+
+ @Test
+ void acceptPortfolioShare_withoutPortfolioId_returnsAwsError() {
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "AcceptPortfolioShare")
+ .header("Authorization", AUTH)
+ .body("{}")
+ .when().post("/")
+ .then().statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"))
+ .body("message", equalTo("PortfolioId is required"));
+ }
+
+ @Test
+ void rejectPortfolioShare_withExistingPortfolio_returnsEmptyBody() {
+ String portfolioId = given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "CreatePortfolio")
+ .header("Authorization", AUTH)
+ .body("{\"DisplayName\":\"ShareReject\",\"ProviderName\":\"Vellum\"}")
+ .when().post("/").then().statusCode(200)
+ .extract().path("PortfolioDetail.Id");
+
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "RejectPortfolioShare")
+ .header("Authorization", AUTH)
+ .body("{\"PortfolioId\":\"" + portfolioId + "\"}")
+ .when().post("/")
+ .then().statusCode(200);
+ }
+
+ @Test
+ void rejectPortfolioShare_withoutPortfolioId_returnsAwsError() {
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "RejectPortfolioShare")
+ .header("Authorization", AUTH)
+ .body("{}")
+ .when().post("/")
+ .then().statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"))
+ .body("message", equalTo("PortfolioId is required"));
+ }
+
+ @Test
+ void createDescribeAndDeletePortfolioShare_removesShare() {
+ String portfolioId = given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "CreatePortfolio")
+ .header("Authorization", AUTH)
+ .body("{\"DisplayName\":\"ShareRoundTrip\",\"ProviderName\":\"Vellum\"}")
+ .when().post("/").then().statusCode(200)
+ .extract().path("PortfolioDetail.Id");
+
+ String accountId = "123456789012";
+
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "CreatePortfolioShare")
+ .header("Authorization", AUTH)
+ .body("{\"PortfolioId\":\"" + portfolioId + "\",\"AccountId\":\"" + accountId + "\"}")
+ .when().post("/")
+ .then().statusCode(200)
+ .body("Status", equalTo("COMPLETED"));
+
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "DescribePortfolioShares")
+ .header("Authorization", AUTH)
+ .body("{\"PortfolioId\":\"" + portfolioId + "\",\"Type\":\"ACCOUNT\"}")
+ .when().post("/")
+ .then().statusCode(200)
+ .body("PortfolioShareDetails", hasSize(1))
+ .body("PortfolioShareDetails[0].PrincipalId", equalTo(accountId));
+
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "DeletePortfolioShare")
+ .header("Authorization", AUTH)
+ .body("{\"PortfolioId\":\"" + portfolioId + "\",\"AccountId\":\"" + accountId + "\"}")
+ .when().post("/")
+ .then().statusCode(200);
+
+ given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", TARGET + "DescribePortfolioShares")
+ .header("Authorization", AUTH)
+ .body("{\"PortfolioId\":\"" + portfolioId + "\",\"Type\":\"ACCOUNT\"}")
+ .when().post("/")
+ .then().statusCode(200)
+ .body("PortfolioShareDetails", hasSize(0));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogOrgAccessConsumerTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogOrgAccessConsumerTest.java
new file mode 100644
index 0000000000..f969a2df9e
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogOrgAccessConsumerTest.java
@@ -0,0 +1,63 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+
+/**
+ * Wire-level tests for {@code EnableAWSOrganizationsAccess},
+ * {@code DisableAWSOrganizationsAccess} and {@code GetAWSOrganizationsAccessStatus}.
+ *
+ * <p>New class, not appended to an existing one: the falsifiability check requires
+ * that removing one operation's dispatch case fails only that operation's own tests
+ * (CS-001). All three operations here return 200 with no error body on success; the
+ * handler's {@code default} arm returns 400, so a bare status-code assertion is
+ * already sufficient to falsify — no message-collision risk to guard against.
+ */
+@QuarkusTest
+class ServiceCatalogOrgAccessConsumerTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private static io.restassured.response.Response call(String action, String body) {
+ return given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
+ .header("Authorization", AUTH_HEADER)
+ .body(body)
+ .when()
+ .post("/");
+ }
+
+ @Test
+ void enableAwsOrganizationsAccess_returnsEmptyBody() {
+ call("EnableAWSOrganizationsAccess", "{}")
+ .then()
+ .statusCode(200);
+ }
+
+ @Test
+ void disableAwsOrganizationsAccess_returnsEmptyBody() {
+ call("DisableAWSOrganizationsAccess", "{}")
+ .then()
+ .statusCode(200);
+ }
+
+ @Test
+ void getAwsOrganizationsAccessStatus_returnsEnabled() {
+ call("GetAWSOrganizationsAccessStatus", "{}")
+ .then()
+ .statusCode(200)
+ .body("AccessStatus", org.hamcrest.Matchers.equalTo("ENABLED"));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogPortfolioQueryConsumerTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogPortfolioQueryConsumerTest.java
new file mode 100644
index 0000000000..db4b67b7aa
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogPortfolioQueryConsumerTest.java
@@ -0,0 +1,148 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItem;
+
+/**
+ * Wire-level tests for {@code ListAcceptedPortfolioShares},
+ * {@code ListConstraintsForPortfolio} and {@code ListLaunchPaths}. Last three
+ * operations in this session's servicecatalog full-parity batch (56 ops total).
+ *
+ * <p>New class, not appended to an existing one, so falsifiability isolates per
+ * operation (CS-001). {@code listConstraintsForPortfolio} was a hardcoded stub
+ * that always returned an empty list, despite {@code CreateConstraint} (already
+ * {@code accepted}) fully persisting constraints with the exact
+ * {@code PortfolioId}/{@code ProductId} fields this query needed to filter on —
+ * same shape as issue 0018 (`ListServiceActions`). Fixed to actually scan.
+ * {@code ListAcceptedPortfolioShares} reuses {@code ListPortfolios}'s handler as-is
+ * — consistent with the already-documented `AcceptPortfolioShare` limitation (no
+ * distinct acceptance state is tracked), not a new bug.
+ */
+@QuarkusTest
+class ServiceCatalogPortfolioQueryConsumerTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private static Response call(String action, String body) {
+ return given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
+ .header("Authorization", AUTH_HEADER)
+ .body(body)
+ .when()
+ .post("/");
+ }
+
+ private static String createProduct(String name) {
+ return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
+ + "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
+ .then().statusCode(200)
+ .extract().path("ProductViewDetail.ProductViewSummary.Id");
+ }
+
+ private static String createPortfolio(String displayName) {
+ return call("CreatePortfolio", "{\"DisplayName\":\"" + displayName
+ + "\",\"ProviderName\":\"floci-test\"}")
+ .then().statusCode(200)
+ .extract().path("PortfolioDetail.Id");
+ }
+
+ // ---------- ListAcceptedPortfolioShares ----------
+
+ @Test
+ void listAcceptedPortfolioShares_includesExistingPortfolio() {
+ String portfolioId = createPortfolio("ab-accepted-shares-portfolio");
+
+ call("ListAcceptedPortfolioShares", "{}")
+ .then()
+ .statusCode(200)
+ .body("PortfolioDetails.Id", hasItem(portfolioId));
+ }
+
+ // ---------- ListConstraintsForPortfolio ----------
+
+ @Test
+ void listConstraintsForPortfolio_returnsCreatedConstraint() {
+ String portfolioId = createPortfolio("ab-list-constraints-portfolio");
+ String productId = createProduct("ab-list-constraints-product");
+ String constraintId = call("CreateConstraint", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"ProductId\":\"" + productId + "\",\"Parameters\":\"{}\",\"Type\":\"LAUNCH\","
+ + "\"IdempotencyToken\":\"tok-list-constraints\"}")
+ .then().statusCode(200)
+ .extract().path("ConstraintDetail.ConstraintId");
+
+ call("ListConstraintsForPortfolio", "{\"PortfolioId\":\"" + portfolioId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("ConstraintDetails.ConstraintId", hasItem(constraintId));
+ }
+
+ @Test
+ void listConstraintsForPortfolio_scopedToProductId_excludesOtherProducts() {
+ String portfolioId = createPortfolio("ab-list-constraints-scoped-portfolio");
+ String productA = createProduct("ab-list-constraints-scoped-product-a");
+ String productB = createProduct("ab-list-constraints-scoped-product-b");
+ String constraintA = call("CreateConstraint", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"ProductId\":\"" + productA + "\",\"Parameters\":\"{}\",\"Type\":\"LAUNCH\","
+ + "\"IdempotencyToken\":\"tok-scoped-a\"}")
+ .then().statusCode(200)
+ .extract().path("ConstraintDetail.ConstraintId");
+ call("CreateConstraint", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"ProductId\":\"" + productB + "\",\"Parameters\":\"{}\",\"Type\":\"LAUNCH\","
+ + "\"IdempotencyToken\":\"tok-scoped-b\"}")
+ .then().statusCode(200);
+
+ call("ListConstraintsForPortfolio", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"ProductId\":\"" + productA + "\"}")
+ .then()
+ .statusCode(200)
+ .body("ConstraintDetails.ConstraintId", hasItem(constraintA))
+ .body("ConstraintDetails.size()", equalTo(1));
+ }
+
+ @Test
+ void listConstraintsForPortfolio_unknownPortfolio_returnsResourceNotFound() {
+ call("ListConstraintsForPortfolio", "{\"PortfolioId\":\"port-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- ListLaunchPaths ----------
+
+ @Test
+ void listLaunchPaths_returnsPortfolioContainingProduct() {
+ String portfolioId = createPortfolio("ab-launch-paths-portfolio");
+ String productId = createProduct("ab-launch-paths-product");
+ call("AssociateProductWithPortfolio", "{\"ProductId\":\"" + productId
+ + "\",\"PortfolioId\":\"" + portfolioId + "\"}")
+ .then().statusCode(200);
+
+ call("ListLaunchPaths", "{\"ProductId\":\"" + productId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("LaunchPathSummaries.Id", hasItem(portfolioId));
+ }
+
+ @Test
+ void listLaunchPaths_missingProductId_returnsInvalidParameters() {
+ call("ListLaunchPaths", "{}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogPrincipalAccessConsumerTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogPrincipalAccessConsumerTest.java
new file mode 100644
index 0000000000..25bbbf39fd
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogPrincipalAccessConsumerTest.java
@@ -0,0 +1,180 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItem;
+
+/**
+ * Wire-level tests for {@code AssociatePrincipalWithPortfolio},
+ * {@code DisassociatePrincipalFromPortfolio}, {@code ListPrincipalsForPortfolio},
+ * {@code ListPortfolioAccess} and {@code ListOrganizationPortfolioAccess}.
+ *
+ * <p>New class, not appended to an existing one, so falsifiability isolates per
+ * operation (CS-001).
+ */
+@QuarkusTest
+class ServiceCatalogPrincipalAccessConsumerTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private static Response call(String action, String body) {
+ return given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
+ .header("Authorization", AUTH_HEADER)
+ .body(body)
+ .when()
+ .post("/");
+ }
+
+ private static String createPortfolio(String displayName) {
+ return call("CreatePortfolio", "{\"DisplayName\":\"" + displayName
+ + "\",\"ProviderName\":\"floci-test\"}")
+ .then().statusCode(200)
+ .extract().path("PortfolioDetail.Id");
+ }
+
+ // ---------- AssociatePrincipalWithPortfolio ----------
+
+ @Test
+ void associatePrincipalWithPortfolio_rejectsUnknownPrincipalType() {
+ String portfolioId = createPortfolio("ab-principal-badtype");
+ call("AssociatePrincipalWithPortfolio", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"PrincipalARN\":\"arn:aws:iam::000000000000:role/my-role\","
+ + "\"PrincipalType\":\"FEDERATED\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"));
+ }
+
+ @Test
+ void associatePrincipalWithPortfolio_returnsEmptyBody() {
+ String portfolioId = createPortfolio("ab-principal-associate");
+ call("AssociatePrincipalWithPortfolio", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"PrincipalARN\":\"arn:aws:iam::000000000000:role/my-role\","
+ + "\"PrincipalType\":\"IAM\"}")
+ .then()
+ .statusCode(200);
+ }
+
+ @Test
+ void associatePrincipalWithPortfolio_unknownPortfolio_returnsResourceNotFound() {
+ call("AssociatePrincipalWithPortfolio", "{\"PortfolioId\":\"port-doesnotexist\","
+ + "\"PrincipalARN\":\"arn:aws:iam::000000000000:role/my-role\","
+ + "\"PrincipalType\":\"IAM\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- ListPrincipalsForPortfolio ----------
+
+ @Test
+ void listPrincipalsForPortfolio_returnsAssociatedPrincipal() {
+ String portfolioId = createPortfolio("ab-principal-list");
+ call("AssociatePrincipalWithPortfolio", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"PrincipalARN\":\"arn:aws:iam::000000000000:role/listed-role\","
+ + "\"PrincipalType\":\"IAM\"}")
+ .then().statusCode(200);
+
+ call("ListPrincipalsForPortfolio", "{\"PortfolioId\":\"" + portfolioId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("Principals.PrincipalARN", hasItem("arn:aws:iam::000000000000:role/listed-role"))
+ .body("Principals.PrincipalType", hasItem("IAM"));
+ }
+
+ // ---------- DisassociatePrincipalFromPortfolio ----------
+
+ @Test
+ void disassociatePrincipalFromPortfolio_removesPrincipal() {
+ String portfolioId = createPortfolio("ab-principal-disassociate");
+ String arn = "arn:aws:iam::000000000000:role/removed-role";
+ call("AssociatePrincipalWithPortfolio", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"PrincipalARN\":\"" + arn + "\",\"PrincipalType\":\"IAM\"}")
+ .then().statusCode(200);
+
+ call("DisassociatePrincipalFromPortfolio", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"PrincipalARN\":\"" + arn + "\"}")
+ .then()
+ .statusCode(200);
+
+ call("ListPrincipalsForPortfolio", "{\"PortfolioId\":\"" + portfolioId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("Principals.PrincipalARN", org.hamcrest.Matchers.not(hasItem(arn)));
+ }
+
+ // ---------- ListPortfolioAccess ----------
+
+ @Test
+ void listPortfolioAccess_returnsAccountsSharedWithPortfolio() {
+ String portfolioId = createPortfolio("ab-portfolio-access");
+ call("CreatePortfolioShare", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"AccountId\":\"333333333333\"}")
+ .then().statusCode(200);
+
+ call("ListPortfolioAccess", "{\"PortfolioId\":\"" + portfolioId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("AccountIds", hasItem("333333333333"));
+ }
+
+ @Test
+ void listPortfolioAccess_unknownPortfolio_returnsResourceNotFound() {
+ call("ListPortfolioAccess", "{\"PortfolioId\":\"port-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- ListOrganizationPortfolioAccess ----------
+
+ @Test
+ void listOrganizationPortfolioAccess_noShares_returnsEmptyList() {
+ String portfolioId = createPortfolio("ab-org-access-empty");
+ call("ListOrganizationPortfolioAccess", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"OrganizationNodeType\":\"ORGANIZATION\"}")
+ .then()
+ .statusCode(200)
+ .body("OrganizationNodes.size()", equalTo(0));
+ }
+
+ /**
+ * botocore pins OrganizationNodeType to ORGANIZATION / ORGANIZATIONAL_UNIT / ACCOUNT.
+ * An unmodelled value used to filter to nothing and report an empty node list, so a
+ * caller with a typo could not tell "no access" from "wrong parameter".
+ */
+ @Test
+ void listOrganizationPortfolioAccess_unknownNodeType_returnsInvalidParameters() {
+ String portfolioId = createPortfolio("ab-org-access-badtype");
+ call("ListOrganizationPortfolioAccess", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"OrganizationNodeType\":\"ORG_UNIT\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"))
+ .body("message", org.hamcrest.Matchers.startsWith("OrganizationNodeType must be one of"));
+ }
+
+ @Test
+ void listOrganizationPortfolioAccess_missingNodeType_returnsInvalidParameters() {
+ String portfolioId = createPortfolio("ab-org-access-missing-type");
+ call("ListOrganizationPortfolioAccess", "{\"PortfolioId\":\"" + portfolioId + "\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogProvisionProductValidationConsumerTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogProvisionProductValidationConsumerTest.java
new file mode 100644
index 0000000000..af6d053158
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogProvisionProductValidationConsumerTest.java
@@ -0,0 +1,259 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItem;
+import static org.hamcrest.Matchers.not;
+
+/**
+ * Wire-level tests for {@code ProvisionProduct}'s request validation.
+ *
+ * <p>The operation used to ignore {@code ProductId} and {@code ProductName}
+ * entirely: any request carrying Account Factory provisioning parameters took the
+ * Control Tower path, so an unrecognised product id still created a real
+ * Organizations member account and recorded it under the seeded Account Factory
+ * identifiers. These tests pin the three outcomes the request now has to choose
+ * between — Account Factory, a plain stored product, and rejection.
+ */
+@QuarkusTest
+class ServiceCatalogProvisionProductValidationConsumerTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private static Response call(String target, String action, String body) {
+ return given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", target + action)
+ .header("Authorization", AUTH_HEADER)
+ .body(body)
+ .when()
+ .post("/");
+ }
+
+ private static Response call(String action, String body) {
+ return call("AWS242ServiceCatalogService.", action, body);
+ }
+
+ private static Response organizations(String action, String body) {
+ return call("AWSOrganizationsV20161128.", action, body);
+ }
+
+ /** The organization is shared across the service-catalog suite; creating it twice is expected to fail. */
+ private static void ensureOrganization() {
+ organizations("CreateOrganization", "{\"FeatureSet\":\"ALL\"}");
+ }
+
+ private static void assertNoAccountWithEmail(String email) {
+ organizations("ListAccounts", "{}")
+ .then()
+ .statusCode(200)
+ .body("Accounts.Email", not(hasItem(email)));
+ }
+
+ private static String createProduct(String name) {
+ return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
+ + "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
+ .then().statusCode(200)
+ .extract().path("ProductViewDetail.ProductViewSummary.Id");
+ }
+
+ private static String firstArtifactId(String productId) {
+ return call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
+ .then().statusCode(200)
+ .extract().path("ProvisioningArtifactDetails[0].Id");
+ }
+
+ private static String accountFactoryParameters(String name, String email) {
+ return "\"ProvisionedProductName\":\"" + name + "\",\"ProvisionToken\":\"tok-" + name + "\","
+ + "\"ProvisioningParameters\":[{\"Key\":\"AccountName\",\"Value\":\"" + name + "\"},"
+ + "{\"Key\":\"AccountEmail\",\"Value\":\"" + email + "\"}]";
+ }
+
+ @Test
+ void provisionProduct_unknownProductId_returnsResourceNotFoundAndCreatesNoAccount() {
+ ensureOrganization();
+ String email = "[email protected]";
+
+ call("ProvisionProduct", "{\"ProductId\":\"prod-doesnotexist\","
+ + "\"ProvisioningArtifactId\":\"pa-doesnotexist\","
+ + accountFactoryParameters("ab-provision-unknown-product", email) + "}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+
+ assertNoAccountWithEmail(email);
+ }
+
+ @Test
+ void provisionProduct_artifactIdAsProductId_returnsResourceNotFoundAndCreatesNoAccount() {
+ ensureOrganization();
+ String email = "[email protected]";
+
+ call("ProvisionProduct", "{\"ProductId\":\"" + ServiceCatalogService.CONTROL_TOWER_ARTIFACT_ID + "\","
+ + accountFactoryParameters("ab-provision-artifact-as-product", email) + "}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+
+ assertNoAccountWithEmail(email);
+ }
+
+ @Test
+ void provisionProduct_ambiguousProductName_returnsDuplicateResourceAndCreatesNoAccount() {
+ // A user-created product may share its Name with another (names are not
+ // unique keys); first-match would nondeterministically pick one — including
+ // the Account Factory product. Ambiguity must fail, not guess.
+ ensureOrganization();
+ String email = "[email protected]";
+ createProduct("AmbiguousName");
+ createProduct("AmbiguousName");
+
+ call("ProvisionProduct", "{\"ProductName\":\"AmbiguousName\","
+ + accountFactoryParameters("ab-provision-ambiguous", email) + "}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("DuplicateResourceException"));
+
+ assertNoAccountWithEmail(email);
+ }
+
+ @Test
+ void provisionProduct_withoutProductIdentifier_returnsInvalidParametersAndCreatesNoAccount() {
+ ensureOrganization();
+ String email = "[email protected]";
+
+ call("ProvisionProduct", "{\"ProvisioningArtifactId\":\"pa-doesnotexist\","
+ + accountFactoryParameters("ab-provision-no-identifier", email) + "}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"));
+
+ assertNoAccountWithEmail(email);
+ }
+
+ @Test
+ void provisionProduct_artifactFromAnotherProduct_returnsResourceNotFound() {
+ String productId = createProduct("ab-provision-artifact-check");
+
+ call("ProvisionProduct", "{\"ProductId\":\"" + productId + "\","
+ + "\"ProvisioningArtifactId\":\"pa-doesnotexist\","
+ + accountFactoryParameters("ab-provision-wrong-artifact", "[email protected]") + "}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ @Test
+ void provisionProduct_storedProduct_recordsThatProductWithoutCreatingAccount() {
+ ensureOrganization();
+ String productId = createProduct("ab-provision-plain-product");
+ String artifactId = firstArtifactId(productId);
+ String email = "[email protected]";
+
+ call("ProvisionProduct", "{\"ProductId\":\"" + productId + "\","
+ + "\"ProvisioningArtifactId\":\"" + artifactId + "\","
+ + accountFactoryParameters("ab-provision-plain", email) + "}")
+ .then()
+ .statusCode(200)
+ .body("RecordDetail.Status", equalTo("SUCCEEDED"));
+
+ call("DescribeProvisionedProduct", "{\"Name\":\"ab-provision-plain\"}")
+ .then()
+ .statusCode(200)
+ .body("ProvisionedProductDetail.ProductId", equalTo(productId))
+ .body("ProvisionedProductDetail.ProvisioningArtifactId", equalTo(artifactId))
+ .body("ProvisionedProductDetail.Type", not(equalTo("CONTROL_TOWER_ACCOUNT")));
+
+ assertNoAccountWithEmail(email);
+
+ call("TerminateProvisionedProduct", "{\"ProvisionedProductName\":\"ab-provision-plain\","
+ + "\"TerminateToken\":\"tok-terminate-plain\"}")
+ .then()
+ .statusCode(200);
+ }
+
+ /**
+ * Without {@code AccountEmail} the Account Factory path used to fall through to
+ * Organizations' {@code validateEmail}, which throws {@code InvalidInputException} — an
+ * Organizations shape, not a Service Catalog one, so a servicecatalog SDK client cannot
+ * deserialize it into a typed exception.
+ */
+ @Test
+ void provisionProduct_accountFactoryWithoutAccountEmail_returnsServiceCatalogInvalidParameters() {
+ ensureOrganization();
+
+ call("ProvisionProduct", "{\"ProductId\":\"" + ServiceCatalogService.CONTROL_TOWER_PRODUCT_ID + "\","
+ + "\"ProvisioningArtifactId\":\"" + ServiceCatalogService.CONTROL_TOWER_ARTIFACT_ID + "\","
+ + "\"ProvisionedProductName\":\"ab-provision-no-email\",\"ProvisionToken\":\"tok-no-email\","
+ + "\"ProvisioningParameters\":[{\"Key\":\"AccountName\",\"Value\":\"ab-provision-no-email\"}]}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"));
+ }
+
+ /**
+ * The guard belongs on the Account Factory path only — a plain stored product needs no
+ * email at all, so provisioning one without {@code AccountEmail} must still succeed.
+ */
+ @Test
+ void provisionProduct_plainProductWithoutAccountEmail_stillSucceeds() {
+ String productId = createProduct("ab-provision-no-email-plain-product");
+ String artifactId = firstArtifactId(productId);
+
+ call("ProvisionProduct", "{\"ProductId\":\"" + productId + "\","
+ + "\"ProvisioningArtifactId\":\"" + artifactId + "\","
+ + "\"ProvisionedProductName\":\"ab-provision-no-email-plain\","
+ + "\"ProvisionToken\":\"tok-no-email-plain\"}")
+ .then()
+ .statusCode(200)
+ .body("RecordDetail.Status", equalTo("SUCCEEDED"));
+
+ call("TerminateProvisionedProduct", "{\"ProvisionedProductName\":\"ab-provision-no-email-plain\","
+ + "\"TerminateToken\":\"tok-terminate-no-email-plain\"}")
+ .then()
+ .statusCode(200);
+ }
+
+ @Test
+ void provisionProduct_accountFactoryProduct_stillCreatesAccount() {
+ ensureOrganization();
+ String email = "[email protected]";
+
+ call("ProvisionProduct", "{\"ProductId\":\"" + ServiceCatalogService.CONTROL_TOWER_PRODUCT_ID + "\","
+ + "\"ProvisioningArtifactId\":\"" + ServiceCatalogService.CONTROL_TOWER_ARTIFACT_ID + "\","
+ + accountFactoryParameters("ab-provision-account-factory", email) + "}")
+ .then()
+ .statusCode(200)
+ .body("RecordDetail.Status", equalTo("SUCCEEDED"));
+
+ call("DescribeProvisionedProduct", "{\"Name\":\"ab-provision-account-factory\"}")
+ .then()
+ .statusCode(200)
+ .body("ProvisionedProductDetail.Type", equalTo("CONTROL_TOWER_ACCOUNT"))
+ .body("ProvisionedProductDetail.ProductId",
+ equalTo(ServiceCatalogService.CONTROL_TOWER_PRODUCT_ID));
+
+ organizations("ListAccounts", "{}")
+ .then()
+ .statusCode(200)
+ .body("Accounts.Email", hasItem(email));
+
+ call("TerminateProvisionedProduct", "{\"ProvisionedProductName\":\"ab-provision-account-factory\","
+ + "\"TerminateToken\":\"tok-terminate-account-factory\"}")
+ .then()
+ .statusCode(200);
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogProvisionedProductLifecycleConsumerTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogProvisionedProductLifecycleConsumerTest.java
new file mode 100644
index 0000000000..e67a18aa23
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogProvisionedProductLifecycleConsumerTest.java
@@ -0,0 +1,191 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+
+/**
+ * Wire-level tests for {@code DescribeProvisionedProduct},
+ * {@code UpdateProvisionedProduct}, {@code UpdateProvisionedProductProperties} and
+ * {@code TerminateProvisionedProduct}.
+ *
+ * <p>New class, not appended to an existing one, so falsifiability isolates per
+ * operation (CS-001). {@code UpdateProvisionedProduct},
+ * {@code UpdateProvisionedProductProperties} and {@code TerminateProvisionedProduct}
+ * all had the same RecordId-discard bug as issues 0021/0023 — fixed the same way.
+ * {@code TerminateProvisionedProduct} also had its {@code RecordType} hardcoded to
+ * the wrong value ({@code PROVISION} instead of
+ * {@code TERMINATE_PROVISIONED_PRODUCT}) and conflated the provisioned product's own
+ * {@code TERMINATED} status with the record's {@code SUCCEEDED} outcome status;
+ * both fixed. {@code UpdateProvisionedProduct} does not apply any request fields —
+ * documented as a validate-and-echo limitation (CS-021 precedent), not fixed further.
+ */
+@QuarkusTest
+class ServiceCatalogProvisionedProductLifecycleConsumerTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private static Response call(String action, String body) {
+ return given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
+ .header("Authorization", AUTH_HEADER)
+ .body(body)
+ .when()
+ .post("/");
+ }
+
+ private static String createProduct(String name) {
+ return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
+ + "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
+ .then().statusCode(200)
+ .extract().path("ProductViewDetail.ProductViewSummary.Id");
+ }
+
+ private static String firstArtifactId(String productId) {
+ return call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
+ .then().statusCode(200)
+ .extract().path("ProvisioningArtifactDetails[0].Id");
+ }
+
+ private static String importProvisionedProduct(String productId, String artifactId, String name) {
+ return call("ImportAsProvisionedProduct", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ProvisionedProductName\":\""
+ + name + "\",\"PhysicalId\":\"phys-" + name + "\",\"IdempotencyToken\":\"tok-" + name + "\"}")
+ .then().statusCode(200)
+ .extract().path("RecordDetail.ProvisionedProductId");
+ }
+
+ // ---------- DescribeProvisionedProduct ----------
+
+ @Test
+ void describeProvisionedProduct_returnsImportedProduct() {
+ String productId = createProduct("ab-describe-pp-product");
+ String artifactId = firstArtifactId(productId);
+ String provisionedId = importProvisionedProduct(productId, artifactId, "ab-describe-pp");
+
+ call("DescribeProvisionedProduct", "{\"Id\":\"" + provisionedId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("ProvisionedProductDetail.Id", equalTo(provisionedId))
+ .body("ProvisionedProductDetail.Status", equalTo("AVAILABLE"));
+ }
+
+ @Test
+ void describeProvisionedProduct_unknownId_returnsResourceNotFound() {
+ call("DescribeProvisionedProduct", "{\"Id\":\"pp-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- UpdateProvisionedProduct ----------
+
+ @Test
+ void updateProvisionedProduct_returnsDescribableRecord() {
+ String productId = createProduct("ab-update-pp-product");
+ String artifactId = firstArtifactId(productId);
+ String provisionedId = importProvisionedProduct(productId, artifactId, "ab-update-pp");
+
+ String recordId = call("UpdateProvisionedProduct", "{\"ProvisionedProductId\":\"" + provisionedId
+ + "\",\"UpdateToken\":\"tok-update-pp\"}")
+ .then()
+ .statusCode(200)
+ .body("RecordDetail.ProvisionedProductId", equalTo(provisionedId))
+ .body("RecordDetail.Status", equalTo("SUCCEEDED"))
+ .extract().path("RecordDetail.RecordId");
+
+ call("DescribeRecord", "{\"Id\":\"" + recordId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("RecordDetail.RecordType", equalTo("UPDATE_PROVISIONED_PRODUCT"));
+ }
+
+ @Test
+ void updateProvisionedProduct_unknownProduct_returnsResourceNotFound() {
+ call("UpdateProvisionedProduct", "{\"ProvisionedProductId\":\"pp-doesnotexist\","
+ + "\"UpdateToken\":\"tok-update-unknown\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- UpdateProvisionedProductProperties ----------
+
+ @Test
+ void updateProvisionedProductProperties_persistsProperties() {
+ String productId = createProduct("ab-update-pp-props-product");
+ String artifactId = firstArtifactId(productId);
+ String provisionedId = importProvisionedProduct(productId, artifactId, "ab-update-pp-props");
+
+ call("UpdateProvisionedProductProperties", "{\"ProvisionedProductId\":\"" + provisionedId
+ + "\",\"ProvisionedProductProperties\":{\"OWNER\":\"someone-else\"},\"IdempotencyToken\":\""
+ + "tok-update-props\"}")
+ .then()
+ .statusCode(200)
+ .body("Status", equalTo("SUCCEEDED"));
+
+ call("DescribeProvisionedProduct", "{\"Id\":\"" + provisionedId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("ProvisionedProductDetail.Id", equalTo(provisionedId));
+ }
+
+ @Test
+ void updateProvisionedProductProperties_unknownProduct_returnsResourceNotFound() {
+ call("UpdateProvisionedProductProperties", "{\"ProvisionedProductId\":\"pp-doesnotexist\","
+ + "\"ProvisionedProductProperties\":{\"OWNER\":\"x\"},\"IdempotencyToken\":\"tok-unknown\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- TerminateProvisionedProduct ----------
+
+ @Test
+ void terminateProvisionedProduct_marksTerminatedAndReturnsDescribableRecord() {
+ String productId = createProduct("ab-terminate-pp-product");
+ String artifactId = firstArtifactId(productId);
+ String provisionedId = importProvisionedProduct(productId, artifactId, "ab-terminate-pp");
+
+ String recordId = call("TerminateProvisionedProduct", "{\"ProvisionedProductId\":\""
+ + provisionedId + "\",\"TerminateToken\":\"tok-terminate-pp\"}")
+ .then()
+ .statusCode(200)
+ .body("RecordDetail.ProvisionedProductId", equalTo(provisionedId))
+ .body("RecordDetail.Status", equalTo("SUCCEEDED"))
+ .body("RecordDetail.RecordType", equalTo("TERMINATE_PROVISIONED_PRODUCT"))
+ .extract().path("RecordDetail.RecordId");
+
+ call("DescribeProvisionedProduct", "{\"Id\":\"" + provisionedId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("ProvisionedProductDetail.Status", equalTo("TERMINATED"));
+
+ call("DescribeRecord", "{\"Id\":\"" + recordId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("RecordDetail.RecordType", equalTo("TERMINATE_PROVISIONED_PRODUCT"));
+ }
+
+ @Test
+ void terminateProvisionedProduct_unknownProduct_returnsResourceNotFound() {
+ call("TerminateProvisionedProduct", "{\"ProvisionedProductId\":\"pp-doesnotexist\","
+ + "\"TerminateToken\":\"tok-terminate-unknown\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogProvisionedProductPlanConsumerTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogProvisionedProductPlanConsumerTest.java
new file mode 100644
index 0000000000..8d1ef61c4b
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogProvisionedProductPlanConsumerTest.java
@@ -0,0 +1,216 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItem;
+
+/**
+ * Wire-level tests for {@code CreateProvisionedProductPlan},
+ * {@code DescribeProvisionedProductPlan}, {@code ExecuteProvisionedProductPlan},
+ * {@code DeleteProvisionedProductPlan} and {@code ListProvisionedProductPlans}.
+ *
+ * <p>New class, not appended to an existing one, so falsifiability isolates per
+ * operation (CS-001). This family had no persistence at all before this session's
+ * fix: {@code createProvisionedProductPlan} built and returned a plan object without
+ * ever storing it, so every other operation in the family failed on a freshly
+ * created plan — {@code describeProvisionedProductPlan} and
+ * {@code deleteProvisionedProductPlan} always 404'd, and
+ * {@code listProvisionedProductPlans} scanned the wrong store entirely
+ * (provisioned products, not plans). Persistence was added via
+ * {@code associationStore} with a new {@code Type: "PROVISIONED_PRODUCT_PLAN"}
+ * discriminator, per this project's established convention for relationships with
+ * no dedicated store. Three of the five handler methods for this family each
+ * expected different field names on the same conceptual object ({@code PlanId} vs
+ * {@code Id}, {@code PlanName} vs {@code Name}) — the stored plan object carries
+ * both names for every dual-named field so each handler's existing (untouched)
+ * response-building code keeps working.
+ */
+@QuarkusTest
+class ServiceCatalogProvisionedProductPlanConsumerTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private static Response call(String action, String body) {
+ return given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
+ .header("Authorization", AUTH_HEADER)
+ .body(body)
+ .when()
+ .post("/");
+ }
+
+ private static String createProduct(String name) {
+ return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
+ + "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
+ .then().statusCode(200)
+ .extract().path("ProductViewDetail.ProductViewSummary.Id");
+ }
+
+ private static String firstArtifactId(String productId) {
+ return call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
+ .then().statusCode(200)
+ .extract().path("ProvisioningArtifactDetails[0].Id");
+ }
+
+ private static String createPlan(String productId, String artifactId, String planName) {
+ return call("CreateProvisionedProductPlan", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"PlanName\":\"" + planName
+ + "\",\"PlanType\":\"CLOUDFORMATION\",\"ProvisionedProductName\":\"" + planName
+ + "-pp\",\"IdempotencyToken\":\"tok-" + planName + "\"}")
+ .then().statusCode(200)
+ .extract().path("PlanId");
+ }
+
+ // ---------- CreateProvisionedProductPlan ----------
+
+ /**
+ * ProvisionedProductPlanType has exactly one member, CLOUDFORMATION. The plan was
+ * created for any PlanType string and then described as CLOUDFORMATION regardless,
+ * so a caller asking for a plan type AWS does not offer got a fake success.
+ */
+ @Test
+ void createProvisionedProductPlan_unknownPlanType_returnsInvalidParameters() {
+ String productId = createProduct("ab-plan-badtype");
+ String artifactId = firstArtifactId(productId);
+
+ call("CreateProvisionedProductPlan", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId
+ + "\",\"PlanName\":\"ab-plan-badtype\",\"PlanType\":\"TERRAFORM\","
+ + "\"ProvisionedProductName\":\"ab-plan-badtype-pp\","
+ + "\"IdempotencyToken\":\"tok-ab-plan-badtype\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"))
+ .body("message", org.hamcrest.Matchers.startsWith("PlanType must be one of"));
+ }
+
+ @Test
+ void createProvisionedProductPlan_returnsPlanMatchingRequest() {
+ String productId = createProduct("ab-plan-create-product");
+ String artifactId = firstArtifactId(productId);
+
+ call("CreateProvisionedProductPlan", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"PlanName\":\"ab-create-plan\","
+ + "\"PlanType\":\"CLOUDFORMATION\",\"ProvisionedProductName\":\"ab-create-plan-pp\","
+ + "\"IdempotencyToken\":\"tok-create-plan\"}")
+ .then()
+ .statusCode(200)
+ .body("PlanName", equalTo("ab-create-plan"))
+ .body("ProvisionProductId", equalTo(productId))
+ .body("ProvisioningArtifactId", equalTo(artifactId))
+ .body("PlanId", org.hamcrest.Matchers.notNullValue());
+ }
+
+ // ---------- DescribeProvisionedProductPlan ----------
+
+ @Test
+ void describeProvisionedProductPlan_returnsCreatedPlan() {
+ String productId = createProduct("ab-plan-describe-product");
+ String artifactId = firstArtifactId(productId);
+ String planId = createPlan(productId, artifactId, "ab-describe-plan");
+
+ call("DescribeProvisionedProductPlan", "{\"PlanId\":\"" + planId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("ProvisionedProductPlanDetails.PlanId", equalTo(planId))
+ .body("ProvisionedProductPlanDetails.PlanName", equalTo("ab-describe-plan"))
+ .body("ProvisionedProductPlanDetails.ProvisionProductId", equalTo(productId))
+ .body("ProvisionedProductPlanDetails.ProvisionProductName", equalTo("ab-describe-plan-pp"))
+ .body("ProvisionedProductPlanDetails.ProductId", equalTo(productId))
+ .body("ProvisionedProductPlanDetails.ProvisioningArtifactId", equalTo(artifactId));
+ }
+
+ @Test
+ void describeProvisionedProductPlan_unknownId_returnsResourceNotFound() {
+ call("DescribeProvisionedProductPlan", "{\"PlanId\":\"plan-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- ExecuteProvisionedProductPlan ----------
+
+ @Test
+ void executeProvisionedProductPlan_returnsRecordDetail() {
+ String productId = createProduct("ab-plan-execute-product");
+ String artifactId = firstArtifactId(productId);
+ String planId = createPlan(productId, artifactId, "ab-execute-plan");
+
+ call("ExecuteProvisionedProductPlan", "{\"PlanId\":\"" + planId
+ + "\",\"IdempotencyToken\":\"tok-execute-plan\"}")
+ .then()
+ .statusCode(200)
+ .body("RecordDetail.Status", equalTo("SUCCEEDED"));
+ }
+
+ @Test
+ void executeProvisionedProductPlan_unknownId_returnsResourceNotFound() {
+ call("ExecuteProvisionedProductPlan", "{\"PlanId\":\"plan-doesnotexist\","
+ + "\"IdempotencyToken\":\"tok-execute-unknown\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- DeleteProvisionedProductPlan ----------
+
+ @Test
+ void deleteProvisionedProductPlan_removesPlan() {
+ String productId = createProduct("ab-plan-delete-product");
+ String artifactId = firstArtifactId(productId);
+ String planId = createPlan(productId, artifactId, "ab-delete-plan");
+
+ call("DeleteProvisionedProductPlan", "{\"PlanId\":\"" + planId + "\"}")
+ .then()
+ .statusCode(200);
+
+ call("DescribeProvisionedProductPlan", "{\"PlanId\":\"" + planId + "\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ @Test
+ void deleteProvisionedProductPlan_unknownId_returnsResourceNotFound() {
+ call("DeleteProvisionedProductPlan", "{\"PlanId\":\"plan-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- ListProvisionedProductPlans ----------
+
+ @Test
+ void listProvisionedProductPlans_scopedToProvisionProductId_returnsOnlyMatchingPlans() {
+ String productA = createProduct("ab-plan-list-product-a");
+ String artifactA = firstArtifactId(productA);
+ String planA = createPlan(productA, artifactA, "ab-list-plan-a");
+
+ String productB = createProduct("ab-plan-list-product-b");
+ String artifactB = firstArtifactId(productB);
+ createPlan(productB, artifactB, "ab-list-plan-b");
+
+ call("ListProvisionedProductPlans", "{\"ProvisionProductId\":\"" + productA + "\"}")
+ .then()
+ .statusCode(200)
+ .body("ProvisionedProductPlans.PlanId", hasItem(planA))
+ .body("ProvisionedProductPlans[0].PlanName", equalTo("ab-list-plan-a"))
+ .body("ProvisionedProductPlans[0].ProvisionProductId", equalTo(productA))
+ .body("ProvisionedProductPlans[0].ProvisionProductName", equalTo("ab-list-plan-a-pp"))
+ .body("ProvisionedProductPlans.size()", equalTo(1));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogProvisionedProductQueryConsumerTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogProvisionedProductQueryConsumerTest.java
new file mode 100644
index 0000000000..c33d99db19
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogProvisionedProductQueryConsumerTest.java
@@ -0,0 +1,135 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItem;
+
+/**
+ * Wire-level tests for {@code ImportAsProvisionedProduct},
+ * {@code GetProvisionedProductOutputs} and {@code ScanProvisionedProducts}.
+ *
+ * <p>New class, not appended to an existing one, so falsifiability isolates per
+ * operation (CS-001).
+ */
+@QuarkusTest
+class ServiceCatalogProvisionedProductQueryConsumerTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private static Response call(String action, String body) {
+ return given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
+ .header("Authorization", AUTH_HEADER)
+ .body(body)
+ .when()
+ .post("/");
+ }
+
+ private static String createProduct(String name) {
+ return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
+ + "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
+ .then().statusCode(200)
+ .extract().path("ProductViewDetail.ProductViewSummary.Id");
+ }
+
+ private static String firstArtifactId(String productId) {
+ return call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
+ .then().statusCode(200)
+ .extract().path("ProvisioningArtifactDetails[0].Id");
+ }
+
+ private static String importProvisionedProduct(String productId, String artifactId, String name) {
+ return call("ImportAsProvisionedProduct", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ProvisionedProductName\":\""
+ + name + "\",\"PhysicalId\":\"phys-" + name + "\",\"IdempotencyToken\":\"tok-" + name + "\"}")
+ .then().statusCode(200)
+ .extract().path("RecordDetail.ProvisionedProductId");
+ }
+
+ // ---------- ImportAsProvisionedProduct ----------
+
+ @Test
+ void importAsProvisionedProduct_returnsRecordMatchingRequest() {
+ String productId = createProduct("ab-import-pp-product");
+ String artifactId = firstArtifactId(productId);
+
+ call("ImportAsProvisionedProduct", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ProvisionedProductName\":\""
+ + "ab-import-pp\",\"PhysicalId\":\"phys-ab-import-pp\",\"IdempotencyToken\":\""
+ + "tok-ab-import-pp\"}")
+ .then()
+ .statusCode(200)
+ .body("RecordDetail.ProvisionedProductName", equalTo("ab-import-pp"))
+ .body("RecordDetail.ProductId", equalTo(productId))
+ .body("RecordDetail.Status", equalTo("SUCCEEDED"))
+ .body("RecordDetail.RecordType", equalTo("IMPORT"));
+ }
+
+ @Test
+ void importAsProvisionedProduct_unknownProduct_returnsResourceNotFound() {
+ call("ImportAsProvisionedProduct", "{\"ProductId\":\"prod-doesnotexist\","
+ + "\"ProvisioningArtifactId\":\"pa-anything\",\"ProvisionedProductName\":\"ab-x\","
+ + "\"PhysicalId\":\"phys-ab-x\",\"IdempotencyToken\":\"tok-ab-x\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- GetProvisionedProductOutputs ----------
+
+ @Test
+ void getProvisionedProductOutputs_knownProduct_returnsEmptyOutputs() {
+ String productId = createProduct("ab-outputs-product");
+ String artifactId = firstArtifactId(productId);
+ String provisionedId = importProvisionedProduct(productId, artifactId, "ab-outputs-pp");
+
+ call("GetProvisionedProductOutputs", "{\"ProvisionedProductId\":\"" + provisionedId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("Outputs.size()", equalTo(0));
+ }
+
+ @Test
+ void getProvisionedProductOutputs_unknownProduct_returnsResourceNotFound() {
+ call("GetProvisionedProductOutputs", "{\"ProvisionedProductId\":\"pp-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ @Test
+ void getProvisionedProductOutputs_missingIdAndName_returnsInvalidParameters() {
+ call("GetProvisionedProductOutputs", "{}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"));
+ }
+
+ // ---------- ScanProvisionedProducts ----------
+
+ @Test
+ void scanProvisionedProducts_includesImportedProduct() {
+ String productId = createProduct("ab-scan-product");
+ String artifactId = firstArtifactId(productId);
+ String provisionedId = importProvisionedProduct(productId, artifactId, "ab-scan-pp");
+
+ call("ScanProvisionedProducts", "{}")
+ .then()
+ .statusCode(200)
+ .body("ProvisionedProducts.Id", hasItem(provisionedId));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogProvisioningArtifactConsumerTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogProvisioningArtifactConsumerTest.java
new file mode 100644
index 0000000000..7a277033f2
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogProvisioningArtifactConsumerTest.java
@@ -0,0 +1,148 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItem;
+
+/**
+ * Wire-level tests for {@code CreateProvisioningArtifact},
+ * {@code UpdateProvisioningArtifact}, {@code DeleteProvisioningArtifact} and
+ * {@code ListProvisioningArtifactsForServiceAction}.
+ *
+ * <p>New class, not appended to an existing one, so falsifiability isolates per
+ * operation (CS-001). {@code ListProvisioningArtifactsForServiceAction} always
+ * returns an empty list — no association between service actions and provisioning
+ * artifacts is tracked for this specific listing (documented as a limitation, not a
+ * bug: unlike {@code ListServiceActions} before this session's fix, nothing else in
+ * the codebase persists data this operation could read).
+ */
+@QuarkusTest
+class ServiceCatalogProvisioningArtifactConsumerTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private static Response call(String action, String body) {
+ return given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
+ .header("Authorization", AUTH_HEADER)
+ .body(body)
+ .when()
+ .post("/");
+ }
+
+ private static String createProduct(String name) {
+ return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
+ + "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
+ .then().statusCode(200)
+ .extract().path("ProductViewDetail.ProductViewSummary.Id");
+ }
+
+ private static String firstArtifactId(String productId) {
+ return call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
+ .then().statusCode(200)
+ .extract().path("ProvisioningArtifactDetails[0].Id");
+ }
+
+ // ---------- CreateProvisioningArtifact ----------
+
+ @Test
+ void createProvisioningArtifact_addsSecondArtifact() {
+ String productId = createProduct("ab-artifact-create");
+
+ call("CreateProvisioningArtifact", "{\"ProductId\":\"" + productId
+ + "\",\"Parameters\":{\"Name\":\"v2\"},\"IdempotencyToken\":\"tok-create-artifact\"}")
+ .then()
+ .statusCode(200)
+ .body("ProvisioningArtifactDetail.Name", equalTo("v2"))
+ .body("Status", equalTo("AVAILABLE"));
+
+ call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("ProvisioningArtifactDetails.Name", hasItem("v2"))
+ .body("ProvisioningArtifactDetails.size()", equalTo(2));
+ }
+
+ @Test
+ void createProvisioningArtifact_unknownProduct_returnsResourceNotFound() {
+ call("CreateProvisioningArtifact", "{\"ProductId\":\"prod-doesnotexist\","
+ + "\"Parameters\":{\"Name\":\"v2\"},\"IdempotencyToken\":\"tok-unknown-product\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- UpdateProvisioningArtifact ----------
+
+ @Test
+ void updateProvisioningArtifact_changesName() {
+ String productId = createProduct("ab-artifact-update");
+ String artifactId = firstArtifactId(productId);
+
+ call("UpdateProvisioningArtifact", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"Name\":\"v1-renamed\"}")
+ .then()
+ .statusCode(200)
+ .body("ProvisioningArtifactDetail.Name", equalTo("v1-renamed"));
+
+ call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("ProvisioningArtifactDetails.Name", hasItem("v1-renamed"));
+ }
+
+ // ---------- DeleteProvisioningArtifact ----------
+
+ @Test
+ void deleteProvisioningArtifact_removesArtifact() {
+ String productId = createProduct("ab-artifact-delete");
+ call("CreateProvisioningArtifact", "{\"ProductId\":\"" + productId
+ + "\",\"Parameters\":{\"Name\":\"v2-to-delete\"},\"IdempotencyToken\":\"tok-delete-artifact\"}")
+ .then().statusCode(200);
+ String artifactId = call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
+ .then().statusCode(200)
+ .extract().path("ProvisioningArtifactDetails.find { it.Name == 'v2-to-delete' }.Id");
+
+ call("DeleteProvisioningArtifact", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\"}")
+ .then()
+ .statusCode(200);
+
+ call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("ProvisioningArtifactDetails.Name", org.hamcrest.Matchers.not(hasItem("v2-to-delete")));
+ }
+
+ // ---------- ListProvisioningArtifactsForServiceAction ----------
+
+ @Test
+ void listProvisioningArtifactsForServiceAction_returnsEmptyList() {
+ call("ListProvisioningArtifactsForServiceAction", "{\"ServiceActionId\":\"sa-anything\"}")
+ .then()
+ .statusCode(200)
+ .body("ProvisioningArtifactViews.size()", equalTo(0));
+ }
+
+ @Test
+ void listProvisioningArtifactsForServiceAction_missingServiceActionId_returnsInvalidParameters() {
+ call("ListProvisioningArtifactsForServiceAction", "{}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogRecordAndResourceQueryConsumerTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogRecordAndResourceQueryConsumerTest.java
new file mode 100644
index 0000000000..e7bec8c0b3
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogRecordAndResourceQueryConsumerTest.java
@@ -0,0 +1,193 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItem;
+
+/**
+ * Wire-level tests for {@code DescribeRecord}, {@code ListRecordHistory},
+ * {@code ListResourcesForTagOption}, {@code ListStackInstancesForProvisionedProduct}
+ * and {@code ListServiceActionsForProvisioningArtifact}.
+ *
+ * <p>New class, not appended to an existing one, so falsifiability isolates per
+ * operation (CS-001). {@code describeRecord} looked up records via a
+ * {@code Type: "RECORD"} association row that nothing ever wrote — every
+ * record-producing operation generated a throwaway random {@code RecordId} in the
+ * handler layer and discarded it, so {@code DescribeRecord} 404'd unconditionally.
+ * Fixed for {@code ImportAsProvisionedProduct}'s path (the one this session already
+ * covers): the service now persists a {@code RECORD} row and returns its id, and the
+ * handler uses that id instead of generating its own. Other record-producing
+ * operations (e.g. {@code ExecuteProvisionedProductServiceAction},
+ * {@code TerminateProvisionedProduct}) still generate unpersisted record ids and
+ * remain undescribable — documented as a limitation, not fixed here (out of this
+ * op-family's scope; same fix pattern applies when those ops are tested).
+ */
+@QuarkusTest
+class ServiceCatalogRecordAndResourceQueryConsumerTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private static Response call(String action, String body) {
+ return given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
+ .header("Authorization", AUTH_HEADER)
+ .body(body)
+ .when()
+ .post("/");
+ }
+
+ private static String createProduct(String name) {
+ return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
+ + "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
+ .then().statusCode(200)
+ .extract().path("ProductViewDetail.ProductViewSummary.Id");
+ }
+
+ private static String firstArtifactId(String productId) {
+ return call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
+ .then().statusCode(200)
+ .extract().path("ProvisioningArtifactDetails[0].Id");
+ }
+
+ // ---------- DescribeRecord ----------
+
+ @Test
+ void describeRecord_returnsRecordForImportedProduct() {
+ String productId = createProduct("ab-record-describe-product");
+ String artifactId = firstArtifactId(productId);
+ String recordId = call("ImportAsProvisionedProduct", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ProvisionedProductName\":\""
+ + "ab-record-describe-pp\",\"PhysicalId\":\"phys-ab-record-describe\","
+ + "\"IdempotencyToken\":\"tok-ab-record-describe\"}")
+ .then().statusCode(200)
+ .extract().path("RecordDetail.RecordId");
+
+ call("DescribeRecord", "{\"Id\":\"" + recordId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("RecordDetail.RecordId", equalTo(recordId))
+ .body("RecordDetail.ProductId", equalTo(productId))
+ .body("RecordDetail.RecordType", equalTo("IMPORT"))
+ .body("RecordDetail.Status", equalTo("SUCCEEDED"));
+ }
+
+ @Test
+ void describeRecord_unknownId_returnsResourceNotFound() {
+ call("DescribeRecord", "{\"Id\":\"rec-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- ListRecordHistory ----------
+
+ @Test
+ void listRecordHistory_includesImportedProduct() {
+ String productId = createProduct("ab-record-history-product");
+ String artifactId = firstArtifactId(productId);
+ String provisionedId = call("ImportAsProvisionedProduct", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ProvisionedProductName\":\""
+ + "ab-record-history-pp\",\"PhysicalId\":\"phys-ab-record-history\","
+ + "\"IdempotencyToken\":\"tok-ab-record-history\"}")
+ .then().statusCode(200)
+ .extract().path("RecordDetail.ProvisionedProductId");
+
+ call("ListRecordHistory", "{}")
+ .then()
+ .statusCode(200)
+ .body("RecordDetails.ProvisionedProductId", hasItem(provisionedId));
+ }
+
+ // ---------- ListResourcesForTagOption ----------
+
+ @Test
+ void listResourcesForTagOption_returnsAssociatedProduct() {
+ String productId = createProduct("ab-tagoption-product");
+ String tagOptionId = call("CreateTagOption", "{\"Key\":\"env\",\"Value\":\"prod\"}")
+ .then().statusCode(200)
+ .extract().path("TagOptionDetail.Id");
+ call("AssociateTagOptionWithResource", "{\"ResourceId\":\"" + productId
+ + "\",\"TagOptionId\":\"" + tagOptionId + "\"}")
+ .then().statusCode(200);
+
+ call("ListResourcesForTagOption", "{\"TagOptionId\":\"" + tagOptionId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("ResourceDetails.Id", hasItem(productId));
+ }
+
+ @Test
+ void listResourcesForTagOption_unknownTagOption_returnsResourceNotFound() {
+ call("ListResourcesForTagOption", "{\"TagOptionId\":\"tag-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- ListStackInstancesForProvisionedProduct ----------
+
+ @Test
+ void listStackInstancesForProvisionedProduct_returnsInstanceForImportedProduct() {
+ String productId = createProduct("ab-stackinstances-product");
+ String artifactId = firstArtifactId(productId);
+ String provisionedId = call("ImportAsProvisionedProduct", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ProvisionedProductName\":\""
+ + "ab-stackinstances-pp\",\"PhysicalId\":\"phys-ab-stackinstances\","
+ + "\"IdempotencyToken\":\"tok-ab-stackinstances\"}")
+ .then().statusCode(200)
+ .extract().path("RecordDetail.ProvisionedProductId");
+
+ call("ListStackInstancesForProvisionedProduct", "{\"ProvisionedProductId\":\""
+ + provisionedId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("StackInstances.size()", org.hamcrest.Matchers.greaterThan(0));
+ }
+
+ @Test
+ void listStackInstancesForProvisionedProduct_unknownProduct_returnsResourceNotFound() {
+ call("ListStackInstancesForProvisionedProduct", "{\"ProvisionedProductId\":\"pp-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- ListServiceActionsForProvisioningArtifact ----------
+
+ @Test
+ void listServiceActionsForProvisioningArtifact_knownArtifact_returnsEmptyList() {
+ String productId = createProduct("ab-safpa-product");
+ String artifactId = firstArtifactId(productId);
+
+ call("ListServiceActionsForProvisioningArtifact", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("ServiceActionSummaries.size()", equalTo(0));
+ }
+
+ @Test
+ void listServiceActionsForProvisioningArtifact_unknownArtifact_returnsResourceNotFound() {
+ String productId = createProduct("ab-safpa-unknown-product");
+
+ call("ListServiceActionsForProvisioningArtifact", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"pa-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogResourceInUseConsumerTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogResourceInUseConsumerTest.java
new file mode 100644
index 0000000000..7068068385
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogResourceInUseConsumerTest.java
@@ -0,0 +1,158 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+
+/**
+ * Wire-level tests for the {@code ResourceInUseException} guard on
+ * {@code DeletePortfolio} and {@code DeleteProduct}.
+ *
+ * <p>Both operations used to delete the resource and then cascade — removing every
+ * association naming the portfolio and every share keyed to it. AWS does the opposite
+ * and refuses the call: "You cannot delete a portfolio if it was shared with you or if
+ * it has associated products, users, constraints, or shared accounts", and
+ * "You cannot delete a product if it was shared with you or is associated with a
+ * portfolio". Both model {@code ResourceInUseException}. The old behaviour turned a
+ * recoverable no-op into unrecoverable data loss reported as 200, which is what these
+ * tests pin.
+ */
+@QuarkusTest
+class ServiceCatalogResourceInUseConsumerTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private static Response call(String action, String body) {
+ return given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
+ .header("Authorization", AUTH_HEADER)
+ .body(body)
+ .when()
+ .post("/");
+ }
+
+ private static String createPortfolio(String name) {
+ return call("CreatePortfolio", "{\"DisplayName\":\"" + name + "\",\"ProviderName\":\"floci-test\"}")
+ .then().statusCode(200)
+ .extract().path("PortfolioDetail.Id");
+ }
+
+ private static String createProduct(String name) {
+ return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
+ + "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
+ .then().statusCode(200)
+ .extract().path("ProductViewDetail.ProductViewSummary.Id");
+ }
+
+ // ---------- DeletePortfolio ----------
+
+ @Test
+ void deletePortfolio_withAssociatedProduct_returnsResourceInUseAndKeepsPortfolio() {
+ String portfolioId = createPortfolio("ab-inuse-portfolio-product");
+ String productId = createProduct("ab-inuse-portfolio-product-prod");
+ call("AssociateProductWithPortfolio", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"ProductId\":\"" + productId + "\"}").then().statusCode(200);
+
+ call("DeletePortfolio", "{\"Id\":\"" + portfolioId + "\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceInUseException"));
+
+ call("DescribePortfolio", "{\"Id\":\"" + portfolioId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("PortfolioDetail.Id", equalTo(portfolioId));
+
+ // the association the old cascade would have destroyed is still there
+ call("ListPortfoliosForProduct", "{\"ProductId\":\"" + productId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("PortfolioDetails.Id", org.hamcrest.Matchers.hasItem(portfolioId));
+ }
+
+ @Test
+ void deletePortfolio_withAssociatedPrincipal_returnsResourceInUse() {
+ String portfolioId = createPortfolio("ab-inuse-portfolio-principal");
+ call("AssociatePrincipalWithPortfolio", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"PrincipalARN\":\"arn:aws:iam::000000000000:role/ab-inuse\","
+ + "\"PrincipalType\":\"IAM\"}").then().statusCode(200);
+
+ call("DeletePortfolio", "{\"Id\":\"" + portfolioId + "\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceInUseException"));
+ }
+
+ @Test
+ void deletePortfolio_withSharedAccount_returnsResourceInUse() {
+ String portfolioId = createPortfolio("ab-inuse-portfolio-share");
+ call("CreatePortfolioShare", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"AccountId\":\"111111111111\"}").then().statusCode(200);
+
+ call("DeletePortfolio", "{\"Id\":\"" + portfolioId + "\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceInUseException"));
+ }
+
+ @Test
+ void deletePortfolio_withNothingAssociated_deletesIt() {
+ String portfolioId = createPortfolio("ab-inuse-portfolio-clean");
+
+ call("DeletePortfolio", "{\"Id\":\"" + portfolioId + "\"}")
+ .then()
+ .statusCode(200);
+
+ call("DescribePortfolio", "{\"Id\":\"" + portfolioId + "\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- DeleteProduct ----------
+
+ @Test
+ void deleteProduct_associatedWithPortfolio_returnsResourceInUseAndKeepsProduct() {
+ String portfolioId = createPortfolio("ab-inuse-product-portfolio");
+ String productId = createProduct("ab-inuse-product-associated");
+ call("AssociateProductWithPortfolio", "{\"PortfolioId\":\"" + portfolioId
+ + "\",\"ProductId\":\"" + productId + "\"}").then().statusCode(200);
+
+ call("DeleteProduct", "{\"Id\":\"" + productId + "\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceInUseException"));
+
+ call("DescribeProductAsAdmin", "{\"Id\":\"" + productId + "\"}")
+ .then()
+ .statusCode(200)
+ .body("ProductViewDetail.ProductViewSummary.Id", equalTo(productId));
+ }
+
+ @Test
+ void deleteProduct_withNoPortfolioAssociation_deletesIt() {
+ String productId = createProduct("ab-inuse-product-clean");
+
+ call("DeleteProduct", "{\"Id\":\"" + productId + "\"}")
+ .then()
+ .statusCode(200);
+
+ call("DescribeProductAsAdmin", "{\"Id\":\"" + productId + "\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogServiceActionArtifactAssociationConsumerTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogServiceActionArtifactAssociationConsumerTest.java
new file mode 100644
index 0000000000..0d3584629d
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogServiceActionArtifactAssociationConsumerTest.java
@@ -0,0 +1,204 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+
+/**
+ * Wire-level tests for {@code AssociateServiceActionWithProvisioningArtifact},
+ * {@code DisassociateServiceActionFromProvisioningArtifact},
+ * {@code BatchAssociateServiceActionWithProvisioningArtifact} and
+ * {@code BatchDisassociateServiceActionFromProvisioningArtifact}.
+ *
+ * <p>New class, not appended to an existing one, so falsifiability isolates per
+ * operation (CS-001). Found two real bugs in this family:
+ *
+ * <ol>
+ * <li>{@code disassociateServiceActionFromProvisioningArtifact} validated the
+ * product/artifact existed but never actually deleted the association — a
+ * complete no-op beyond validation. Fixed to look up and delete the row.</li>
+ * <li>the single-op, batch-associate, and batch-disassociate paths each computed
+ * a <em>different</em> association-store key for the conceptually identical
+ * (product, artifact, service action) triple — batch-associate omitted
+ * {@code productId} entirely, and batch-disassociate used a hand-rolled key with
+ * a missing underscore ({@code "serviceaction|..."} vs {@code "service_action|..."})
+ * that didn't match either of the other two. Associations created one way could
+ * not be found or removed another way. Unified all three onto the single-op's key
+ * formula.</li>
+ * </ol>
+ *
+ * <p>{@code associateServiceActionWithProvisioningArtifact_thenDisassociatedViaBatch}
+ * and its mirror below are what would have caught #2 — they cross the single/batch
+ * boundary deliberately.
+ */
+@QuarkusTest
+class ServiceCatalogServiceActionArtifactAssociationConsumerTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private static Response call(String action, String body) {
+ return given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
+ .header("Authorization", AUTH_HEADER)
+ .body(body)
+ .when()
+ .post("/");
+ }
+
+ private static String createProduct(String name) {
+ return call("CreateProduct", "{\"Name\":\"" + name + "\",\"Owner\":\"floci-test\","
+ + "\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
+ .then().statusCode(200)
+ .extract().path("ProductViewDetail.ProductViewSummary.Id");
+ }
+
+ private static String firstArtifactId(String productId) {
+ return call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
+ .then().statusCode(200)
+ .extract().path("ProvisioningArtifactDetails[0].Id");
+ }
+
+ private static String createServiceAction(String name) {
+ return call("CreateServiceAction", "{\"Name\":\"" + name + "\",\"DefinitionType\":\""
+ + "SSM_AUTOMATION\",\"Definition\":{\"Name\":\"AWS-RestartEC2Instance\"},"
+ + "\"IdempotencyToken\":\"tok-" + name + "\"}")
+ .then().statusCode(200)
+ .extract().path("ServiceActionDetail.ServiceActionSummary.Id");
+ }
+
+ // ---------- AssociateServiceActionWithProvisioningArtifact ----------
+
+ @Test
+ void associateServiceActionWithProvisioningArtifact_returnsEmptyBody() {
+ String productId = createProduct("ab-assoc-sa-product");
+ String artifactId = firstArtifactId(productId);
+ String actionId = createServiceAction("ab-assoc-sa-action");
+
+ call("AssociateServiceActionWithProvisioningArtifact", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ServiceActionId\":\""
+ + actionId + "\"}")
+ .then()
+ .statusCode(200);
+ }
+
+ // ---------- DisassociateServiceActionFromProvisioningArtifact ----------
+
+ @Test
+ void disassociateServiceActionFromProvisioningArtifact_removesAssociation() {
+ String productId = createProduct("ab-disassoc-sa-product");
+ String artifactId = firstArtifactId(productId);
+ String actionId = createServiceAction("ab-disassoc-sa-action");
+ call("AssociateServiceActionWithProvisioningArtifact", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ServiceActionId\":\""
+ + actionId + "\"}")
+ .then().statusCode(200);
+
+ call("DisassociateServiceActionFromProvisioningArtifact", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ServiceActionId\":\""
+ + actionId + "\"}")
+ .then()
+ .statusCode(200);
+
+ // Repeating the disassociate proves the row is really gone, not just
+ // validated: the second call must now fail since nothing is left to remove.
+ call("DisassociateServiceActionFromProvisioningArtifact", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ServiceActionId\":\""
+ + actionId + "\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- BatchAssociateServiceActionWithProvisioningArtifact ----------
+
+ @Test
+ void batchAssociateServiceActionWithProvisioningArtifact_returnsNoFailures() {
+ String productId = createProduct("ab-batch-assoc-product");
+ String artifactId = firstArtifactId(productId);
+ String actionId = createServiceAction("ab-batch-assoc-action");
+
+ call("BatchAssociateServiceActionWithProvisioningArtifact", "{\"ServiceActionAssociations\":["
+ + "{\"ProductId\":\"" + productId + "\",\"ProvisioningArtifactId\":\"" + artifactId
+ + "\",\"ServiceActionId\":\"" + actionId + "\"}]}")
+ .then()
+ .statusCode(200)
+ .body("FailedServiceActionAssociations.size()", equalTo(0));
+ }
+
+ @Test
+ void batchAssociateServiceActionWithProvisioningArtifact_unknownProduct_returnsFailureEntry() {
+ call("BatchAssociateServiceActionWithProvisioningArtifact", "{\"ServiceActionAssociations\":["
+ + "{\"ProductId\":\"prod-doesnotexist\",\"ProvisioningArtifactId\":\"pa-x\","
+ + "\"ServiceActionId\":\"sa-x\"}]}")
+ .then()
+ .statusCode(200)
+ .body("FailedServiceActionAssociations[0].ErrorCode", equalTo("RESOURCE_NOT_FOUND"));
+ }
+
+ /** Crosses the single/batch boundary — proves the key formulas were unified. */
+ @Test
+ void associateViaBatch_thenDisassociatedViaSingleOp() {
+ String productId = createProduct("ab-cross-batch-to-single-product");
+ String artifactId = firstArtifactId(productId);
+ String actionId = createServiceAction("ab-cross-batch-to-single-action");
+
+ call("BatchAssociateServiceActionWithProvisioningArtifact", "{\"ServiceActionAssociations\":["
+ + "{\"ProductId\":\"" + productId + "\",\"ProvisioningArtifactId\":\"" + artifactId
+ + "\",\"ServiceActionId\":\"" + actionId + "\"}]}")
+ .then().statusCode(200)
+ .body("FailedServiceActionAssociations.size()", equalTo(0));
+
+ call("DisassociateServiceActionFromProvisioningArtifact", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ServiceActionId\":\""
+ + actionId + "\"}")
+ .then()
+ .statusCode(200);
+ }
+
+ // ---------- BatchDisassociateServiceActionFromProvisioningArtifact ----------
+
+ /** Crosses the single/batch boundary the other direction. */
+ @Test
+ void associateViaSingleOp_thenDisassociatedViaBatch() {
+ String productId = createProduct("ab-cross-single-to-batch-product");
+ String artifactId = firstArtifactId(productId);
+ String actionId = createServiceAction("ab-cross-single-to-batch-action");
+
+ call("AssociateServiceActionWithProvisioningArtifact", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ServiceActionId\":\""
+ + actionId + "\"}")
+ .then().statusCode(200);
+
+ call("BatchDisassociateServiceActionFromProvisioningArtifact", "{\"ServiceActionAssociations\":["
+ + "{\"ProductId\":\"" + productId + "\",\"ProvisioningArtifactId\":\"" + artifactId
+ + "\",\"ServiceActionId\":\"" + actionId + "\"}]}")
+ .then()
+ .statusCode(200);
+ }
+
+ @Test
+ void batchDisassociateServiceActionFromProvisioningArtifact_unknownAssociation_returnsFailureEntry() {
+ String productId = createProduct("ab-batch-disassoc-unknown-product");
+ String artifactId = firstArtifactId(productId);
+
+ call("BatchDisassociateServiceActionFromProvisioningArtifact", "{\"ServiceActionAssociations\":["
+ + "{\"ProductId\":\"" + productId + "\",\"ProvisioningArtifactId\":\"" + artifactId
+ + "\",\"ServiceActionId\":\"sa-neverassociated\"}]}")
+ .then()
+ .statusCode(200)
+ .body("FailedServiceActionAssociations[0].ErrorCode", equalTo("RESOURCE_NOT_FOUND"));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogServiceActionConsumerTest.java b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogServiceActionConsumerTest.java
new file mode 100644
index 0000000000..0e2264a245
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogServiceActionConsumerTest.java
@@ -0,0 +1,183 @@
+package io.github.hectorvent.floci.services.servicecatalog;
+
+import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasItem;
+
+/**
+ * Wire-level tests for {@code CreateServiceAction}, {@code UpdateServiceAction},
+ * {@code DeleteServiceAction} and {@code ListServiceActions}.
+ *
+ * <p>New class, not appended to an existing one, so falsifiability isolates per
+ * operation (CS-001). These tests exercise the full create-update-delete-list
+ * round trip deliberately: {@code createServiceAction} originally stored its record
+ * under key {@code "service_action|" + id} while {@code deleteServiceAction} and
+ * {@code updateServiceAction} looked it up / re-stored it under the raw {@code id} —
+ * a key mismatch that made {@code DeleteServiceAction} always fail with
+ * {@code ResourceNotFoundException} on a freshly-created action, and made
+ * {@code UpdateServiceAction} silently duplicate the record instead of overwriting
+ * it. {@code listServiceActions} was also a hardcoded-empty stub despite the other
+ * three operations being fully storage-backed. All three were fixed together;
+ * {@code listServiceActions_afterUpdate_hasNoDuplicates} is what would have caught
+ * the duplication specifically.
+ */
+@QuarkusTest
+class ServiceCatalogServiceActionConsumerTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.1";
+ private static final String AUTH_HEADER =
+ "AWS4-HMAC-SHA256 Credential=AKID/20260101/us-east-1/servicecatalog/aws4_request";
+
+ @BeforeAll
+ static void configureRestAssured() {
+ RestAssuredJsonUtils.configureAwsContentTypes();
+ }
+
+ private static Response call(String action, String body) {
+ return given()
+ .contentType(CONTENT_TYPE)
+ .header("X-Amz-Target", "AWS242ServiceCatalogService." + action)
+ .header("Authorization", AUTH_HEADER)
+ .body(body)
+ .when()
+ .post("/");
+ }
+
+ private static String createServiceAction(String name) {
+ return call("CreateServiceAction", "{\"Name\":\"" + name + "\",\"DefinitionType\":\""
+ + "SSM_AUTOMATION\",\"Definition\":{\"Name\":\"AWS-RestartEC2Instance\"},"
+ + "\"IdempotencyToken\":\"tok-" + name + "\"}")
+ .then().statusCode(200)
+ .extract().path("ServiceActionDetail.ServiceActionSummary.Id");
+ }
+
+ // ---------- CreateServiceAction ----------
+
+ @Test
+ void createServiceAction_returnsSummaryMatchingRequest() {
+ call("CreateServiceAction", "{\"Name\":\"ab-create-action\",\"DefinitionType\":\""
+ + "SSM_AUTOMATION\",\"Definition\":{\"Name\":\"AWS-RestartEC2Instance\"},"
+ + "\"IdempotencyToken\":\"tok-create\"}")
+ .then()
+ .statusCode(200)
+ .body("ServiceActionDetail.ServiceActionSummary.Name", equalTo("ab-create-action"))
+ .body("ServiceActionDetail.ServiceActionSummary.DefinitionType", equalTo("SSM_AUTOMATION"))
+ .body("ServiceActionDetail.ServiceActionSummary.Id", org.hamcrest.Matchers.notNullValue());
+ }
+
+ /**
+ * ServiceActionDefinitionType has exactly one member, SSM_AUTOMATION. Any other value
+ * was stored verbatim and handed back by DescribeServiceAction as a real action type.
+ */
+ @Test
+ void createServiceAction_unknownDefinitionType_returnsInvalidParameters() {
+ call("CreateServiceAction", "{\"Name\":\"ab-action-badtype\",\"DefinitionType\":\""
+ + "LAMBDA\",\"Definition\":{\"Name\":\"AWS-RestartEC2Instance\"},"
+ + "\"IdempotencyToken\":\"tok-badtype\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("InvalidParametersException"))
+ .body("message", org.hamcrest.Matchers.startsWith("DefinitionType must be one of"));
+ }
+
+ // ---------- DeleteServiceAction ----------
+
+ @Test
+ void deleteServiceAction_removesFreshlyCreatedAction() {
+ String id = createServiceAction("ab-delete-action");
+
+ call("DeleteServiceAction", "{\"Id\":\"" + id + "\"}")
+ .then()
+ .statusCode(200);
+
+ call("ListServiceActions", "{}")
+ .then()
+ .statusCode(200)
+ .body("ServiceActionSummaries.Id", org.hamcrest.Matchers.not(hasItem(id)));
+ }
+
+ @Test
+ void deleteServiceAction_unknownId_returnsResourceNotFound() {
+ call("DeleteServiceAction", "{\"Id\":\"sa-doesnotexist\"}")
+ .then()
+ .statusCode(400)
+ .body("__type", equalTo("ResourceNotFoundException"));
+ }
+
+ // ---------- UpdateServiceAction ----------
+
+ @Test
+ void updateServiceAction_changesName() {
+ String id = createServiceAction("ab-update-action-before");
+
+ call("UpdateServiceAction", "{\"Id\":\"" + id + "\",\"Name\":\"ab-update-action-after\"}")
+ .then()
+ .statusCode(200)
+ .body("ServiceActionDetail.ServiceActionSummary.Id", equalTo(id))
+ .body("ServiceActionDetail.ServiceActionSummary.Name", equalTo("ab-update-action-after"));
+ }
+
+ @Test
+ void listServiceActions_afterUpdate_hasNoDuplicates() {
+ String id = createServiceAction("ab-update-nodupe");
+ call("UpdateServiceAction", "{\"Id\":\"" + id + "\",\"Name\":\"ab-update-nodupe-2\"}")
+ .then().statusCode(200);
+
+ Response list = call("ListServiceActions", "{}");
+ list.then().statusCode(200);
+ java.util.List<String> ids = list.jsonPath().getList("ServiceActionSummaries.Id", String.class);
+ long matches = ids.stream().filter(id::equals).count();
+ org.junit.jupiter.api.Assertions.assertEquals(1L, matches,
+ "expected exactly one entry for " + id + " after update, found " + matches);
+ }
+
+ /**
+ * {@code associateServiceActionWithProvisioningArtifact} stores its association
+ * row with the same {@code Type: "SERVICE_ACTION"} discriminator that service
+ * action records themselves use, distinguished only by which fields are present
+ * (association rows have no {@code Id} field). {@code listServiceActions()} must
+ * filter those out, not just match on {@code Type}.
+ */
+ @Test
+ void listServiceActions_ignoresProvisioningArtifactAssociationRows() {
+ String productId = call("CreateProduct", "{\"Name\":\"ab-action-artifact-product\","
+ + "\"Owner\":\"floci-test\",\"ProvisioningArtifactParameters\":[{\"Name\":\"v1\"}]}")
+ .then().statusCode(200)
+ .extract().path("ProductViewDetail.ProductViewSummary.Id");
+ String artifactId = call("ListProvisioningArtifacts", "{\"ProductId\":\"" + productId + "\"}")
+ .then().statusCode(200)
+ .extract().path("ProvisioningArtifactDetails[0].Id");
+ String actionId = createServiceAction("ab-action-for-artifact-assoc");
+
+ call("AssociateServiceActionWithProvisioningArtifact", "{\"ProductId\":\"" + productId
+ + "\",\"ProvisioningArtifactId\":\"" + artifactId + "\",\"ServiceActionId\":\""
+ + actionId + "\"}")
+ .then().statusCode(200);
+
+ Response list = call("ListServiceActions", "{}");
+ list.then().statusCode(200);
+ java.util.List<String> ids = list.jsonPath().getList("ServiceActionSummaries.Id", String.class);
+ org.junit.jupiter.api.Assertions.assertFalse(ids.contains(""),
+ "association row leaked into ListServiceActions with an empty Id: " + ids);
+ org.junit.jupiter.api.Assertions.assertTrue(ids.contains(actionId),
+ "the real service action should still be listed: " + ids);
+ }
+
+ // ---------- ListServiceActions ----------
+
+ @Test
+ void listServiceActions_includesCreatedAction() {
+ String id = createServiceAction("ab-list-action");
+
+ call("ListServiceActions", "{}")
+ .then()
+ .statusCode(200)
+ .body("ServiceActionSummaries.Id", hasItem(id));
+ }
+}
diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml
index 2c3ab8ceb1..ebeee2fdf6 100644
--- a/src/test/resources/application.yml
+++ b/src/test/resources/application.yml
@@ -337,6 +337,8 @@ floci:
enabled: true
rum:
enabled: true
+ servicecatalog:
+ enabled: true
guardduty:
enabled: true
emrserverless:
diff --git a/tools/docs/service_matrix.yaml b/tools/docs/service_matrix.yaml
index 79594e01bd..bfe232da8a 100644
--- a/tools/docs/service_matrix.yaml
+++ b/tools/docs/service_matrix.yaml
@@ -27,6 +27,7 @@ aliases:
logs: cloudwatch # CloudWatch Logs facet, at cloudwatch.md
monitoring: cloudwatch # CloudWatch Metrics facet, at cloudwatch.md#metrics
secretsmanager: secrets-manager
+ servicecatalog: service-catalog
cognito-idp: cognito # Cognito's SigV4 signing name
states: step-functions # Step Functions' SigV4 signing name
email: ses # SES's SigV4 signing name
diff --git a/tools/docs/services.yaml b/tools/docs/services.yaml
index 2d99706a87..ae8e36f276 100644
--- a/tools/docs/services.yaml
+++ b/tools/docs/services.yaml
@@ -121,6 +121,10 @@ services:
doc: docs/services/secrets-manager.md
sources:
- { path: src/main/java/io/github/hectorvent/floci/services/secretsmanager/SecretsManagerJsonHandler.java, mode: switch }
+ - service: servicecatalog
+ doc: docs/services/service-catalog.md
+ sources:
+ - { path: src/main/java/io/github/hectorvent/floci/services/servicecatalog/ServiceCatalogJsonHandler.java, mode: switch }
- service: servicequotas
doc: docs/services/servicequotas.md
sources: