tags = codeArtifact.listTagsForResource(r -> r.resourceArn(domainArn)).tags();
+ assertThat(tags).extracting(Tag::key).contains("owner", "cost-center");
+ }
+
+ @Test
+ @Order(40)
+ @DisplayName("GetRepositoryEndpoint - resolves for a real package format")
+ void getRepositoryEndpoint() {
+ GetRepositoryEndpointResponse resp = codeArtifact.getRepositoryEndpoint(r -> r
+ .domain(DOMAIN)
+ .repository(REPO)
+ .format(PackageFormat.NPM));
+
+ assertThat(resp.repositoryEndpoint()).contains("/codeartifact/npm/" + DOMAIN + "/" + REPO + "/");
+ }
+
+ @Test
+ @Order(50)
+ @DisplayName("Repository permissions policy - put/get/delete with optimistic locking")
+ void repositoryPermissionsPolicyRoundTrip() {
+ String policyDocument = "{\"Version\":\"2012-10-17\",\"Statement\":[]}";
+ PutRepositoryPermissionsPolicyResponse put = codeArtifact.putRepositoryPermissionsPolicy(r -> r
+ .domain(DOMAIN)
+ .repository(REPO)
+ .policyDocument(policyDocument));
+
+ assertThat(put.policy().document()).isEqualTo(policyDocument);
+
+ assertThatThrownBy(() -> codeArtifact.putRepositoryPermissionsPolicy(r -> r
+ .domain(DOMAIN)
+ .repository(REPO)
+ .policyDocument(policyDocument)
+ .policyRevision("not-the-current-revision")))
+ .isInstanceOf(ConflictException.class);
+
+ GetRepositoryPermissionsPolicyResponse got = codeArtifact.getRepositoryPermissionsPolicy(r -> r
+ .domain(DOMAIN)
+ .repository(REPO));
+ assertThat(got.policy().revision()).isEqualTo(put.policy().revision());
+
+ codeArtifact.deleteRepositoryPermissionsPolicy(r -> r.domain(DOMAIN).repository(REPO));
+ assertThatThrownBy(() -> codeArtifact.getRepositoryPermissionsPolicy(r -> r
+ .domain(DOMAIN)
+ .repository(REPO)))
+ .isInstanceOf(ResourceNotFoundException.class);
+ }
+
+ @Test
+ @Order(60)
+ @DisplayName("AssociateExternalConnection - accepts a real AWS-hosted public upstream")
+ void externalConnectionRoundTrip() {
+ AssociateExternalConnectionResponse assoc = codeArtifact.associateExternalConnection(r -> r
+ .domain(DOMAIN)
+ .repository(STORE_REPO)
+ .externalConnection("public:npmjs"));
+
+ assertThat(assoc.repository().externalConnections()).hasSize(1);
+ assertThat(assoc.repository().externalConnections().get(0).packageFormat()).isEqualTo(PackageFormat.NPM);
+
+ assertThatThrownBy(() -> codeArtifact.associateExternalConnection(r -> r
+ .domain(DOMAIN)
+ .repository(STORE_REPO)
+ .externalConnection("public:pypi")))
+ .isInstanceOf(ConflictException.class);
+
+ DisassociateExternalConnectionResponse disassoc = codeArtifact.disassociateExternalConnection(r -> r
+ .domain(DOMAIN)
+ .repository(STORE_REPO)
+ .externalConnection("public:npmjs"));
+ assertThat(disassoc.repository().externalConnections()).isEmpty();
+ }
+
+ @Test
+ @Order(90)
+ @DisplayName("DeleteDomain - fails while repositories still exist")
+ void deleteDomainWithRepositoriesFails() {
+ assertThatThrownBy(() -> codeArtifact.deleteDomain(r -> r.domain(DOMAIN)))
+ .isInstanceOf(ConflictException.class);
+ }
+}
diff --git a/docs/services/codeartifact.md b/docs/services/codeartifact.md
new file mode 100644
index 0000000000..f786cd3895
--- /dev/null
+++ b/docs/services/codeartifact.md
@@ -0,0 +1,81 @@
+# CodeArtifact
+
+**Protocol:** REST JSON
+
+**Endpoint:** `http://localhost:4566`
+
+Floci supports the CodeArtifact control plane: domains, repositories, resource policies, tags,
+and public upstream (external) connections. Package publish/fetch endpoints for each format
+(npm, PyPI, Maven, NuGet, generic, etc.) are not implemented yet.
+
+## Supported Actions
+
+
+| Action | Description |
+| --- | --- |
+| `CreateDomain` | Creates a domain, optionally with a KMS encryption key and initial tags. |
+| `DeleteDomain` | Deletes a domain; fails with `ConflictException` while it still contains repositories. |
+| `DescribeDomain` | Returns a domain's full description, including its repository count. |
+| `ListDomains` | Lists domain summaries for the account and Region, paginated. |
+| `PutDomainPermissionsPolicy` | Attaches or replaces a domain's resource policy, versioned by `policyRevision`. |
+| `GetDomainPermissionsPolicy` | Returns a domain's current resource policy and revision. |
+| `DeleteDomainPermissionsPolicy` | Removes a domain's resource policy, optionally checked against `policyRevision`. |
+| `CreateRepository` | Creates a repository with optional description, upstreams (max 10), and tags. |
+| `DeleteRepository` | Deletes a repository. |
+| `DescribeRepository` | Returns a repository's full description, including upstreams and external connections. |
+| `UpdateRepository` | Updates a repository's description and/or upstream list. |
+| `ListRepositories` | Lists repository summaries across all domains, optionally filtered by name prefix. |
+| `ListRepositoriesInDomain` | Lists repository summaries within one domain, optionally filtered by name prefix. |
+| `GetRepositoryEndpoint` | Returns the package-format-specific endpoint URL for a repository. |
+| `PutRepositoryPermissionsPolicy` | Attaches or replaces a repository's resource policy, versioned by `policyRevision`. |
+| `GetRepositoryPermissionsPolicy` | Returns a repository's current resource policy and revision. |
+| `DeleteRepositoryPermissionsPolicy` | Removes a repository's resource policy, optionally checked against `policyRevision`. |
+| `AssociateExternalConnection` | Attaches a fixed-catalog public upstream (e.g. `public:npmjs`) to a repository; mutually exclusive with repository upstreams. |
+| `DisassociateExternalConnection` | Removes a repository's external connection. |
+| `TagResource` | Adds or updates tags on a domain or repository ARN. |
+| `UntagResource` | Removes tags by key from a domain or repository ARN. |
+| `ListTagsForResource` | Lists the tags on a domain or repository ARN. |
+
+
+Domains and repositories are account and Region scoped and persisted through `StorageFactory`.
+`DeleteDomain` fails with `ConflictException` while the domain still contains repositories, matching
+AWS. `PutDomainPermissionsPolicy`/`PutRepositoryPermissionsPolicy` use the returned `policyRevision`
+for optimistic locking on subsequent updates, also matching AWS.
+
+`AssociateExternalConnection` accepts the same fixed set of AWS-hosted public upstreams
+documented for real CodeArtifact (`public:npmjs`, `public:pypi`, `public:maven-central`, etc.) and
+enforces the one-external-connection-per-repository limit AWS enforces. A repository can have
+upstream repositories or an external connection, but not both, matching AWS; `CreateRepository`
+and `UpdateRepository` also cap direct upstreams at 10, AWS's own repository limit.
+
+## AWS-compatible failures
+
+Domain and repository names, tags, pagination, duplicate names, missing upstreams, policy-revision
+mismatches, and non-empty-domain deletes are validated. Floci returns `ValidationException`,
+`ConflictException`, `ResourceNotFoundException`, and `ServiceQuotaExceededException` (tag limits)
+for deterministic conditions represented by local state.
+
+AWS also models `AccessDeniedException`, `InternalServerException`, and `ThrottlingException`.
+Floci does not inject provider-side failures that cannot be derived from the request or emulator
+state.
+
+## Known limitations
+
+- **Upstream cycles are not rejected.** `CreateRepository`/`UpdateRepository` reject a repository
+ naming itself as its own upstream and require each named upstream to already exist, but a longer
+ cycle (repository A has B as an upstream, B has A) is not detected.
+- **`DeleteRepository` does not check whether other repositories still reference it as an
+ upstream.** Deleting a repository leaves any repository that named it as an upstream pointing at
+ one that no longer exists.
+- **Cross-account `domainOwner` addressing has no authorization check.** Passing a `domainOwner`
+ that is not the caller's own account looks up that account's domain/repository with no
+ trust-policy or permissions-policy enforcement, consistent with Floci's IAM enforcement being
+ opt-in elsewhere, but worth knowing if you rely on domain-sharing semantics.
+
+See the [CodeArtifact API Reference](https://docs.aws.amazon.com/codeartifact/latest/APIReference/Welcome.html).
+
+## Configuration
+
+| Variable | Default | Description |
+|---|---|---|
+| `FLOCI_SERVICES_CODEARTIFACT_ENABLED` | `true` | Enable or disable CodeArtifact |
diff --git a/docs/services/index.md b/docs/services/index.md
index 557a92c61f..2e4091a2e2 100644
--- a/docs/services/index.md
+++ b/docs/services/index.md
@@ -117,6 +117,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac
| [AWS Backup](backup.md) | `/backup-vaults/*`, `/backup/plans/*`, `/backup-jobs/*`, `/supported-resource-types` | REST JSON | 20 |
| [AWS FIS](fis.md) | `/experimentTemplates/*`, `/experiments/*`, `/actions/*`, `/targetResourceTypes/*`, `/safetyLevers/*`, `/tags/*` | REST JSON | 26 |
| [CodeGuru Reviewer](codegurureviewer.md) | `/associations`, `/associations/{associationArn}`, `/tags/*` | REST JSON | 7 |
+| [CodeArtifact](codeartifact.md) | `/v1/domain*`, `/v1/repository*`, `/v1/tag*` | REST JSON | 22 |
| [CloudFront](cloudfront.md) | `/2020-05-31/distribution/*`, `/2020-05-31/cache-policy/*`, `/2020-05-31/function/*` | REST XML | 50 |
| [Route53](route53.md) | `/2013-04-01/hostedzone/*`, `/2013-04-01/healthcheck/*`, `/2013-04-01/change/*` | REST XML | 25 |
| [Route 53 Resolver](route53resolver.md) | `POST /` + `X-Amz-Target: Route53Resolver.*` | JSON 1.1 | 18 |
diff --git a/mkdocs.yml b/mkdocs.yml
index 4e7a6be03c..d1683979a0 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -184,6 +184,7 @@ nav:
- SageMaker: services/sagemaker.md
- CodeDeploy: services/codedeploy.md
- CodeGuru Reviewer: services/codegurureviewer.md
+ - CodeArtifact: services/codeartifact.md
- CodePipeline: services/codepipeline.md
- Service Quotas: services/servicequotas.md
- AWS RAM: services/ram.md
diff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
index 945a8e86d6..c238cd78d6 100644
--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
@@ -789,9 +789,15 @@ public interface EmulatorConfig {
LakeFormationServiceConfig lakeformation();
EfsServiceConfig efs();
CodeGuruReviewerServiceConfig codegurureviewer();
+ CodeArtifactServiceConfig codeartifact();
MarketplaceServiceConfig marketplace();
}
+ interface CodeArtifactServiceConfig {
+ @WithDefault("true")
+ boolean enabled();
+ }
+
interface ConnectServiceConfig {
@WithDefault("true")
boolean enabled();
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java b/src/main/java/io/github/hectorvent/floci/core/common/ResolvedServiceCatalog.java
index 40b71fb2ed..e4bf5ff6a7 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
@@ -709,6 +709,11 @@ public class ResolvedServiceCatalog {
protocols(ServiceProtocol.REST_JSON),
Set.of(), Set.of("codeguru-reviewer"), Set.of(),
Set.of(io.github.hectorvent.floci.services.codegurureviewer.CodeGuruReviewerController.class)),
+ descriptor("codeartifact", "codeartifact", config.services().codeartifact().enabled(), true,
+ "codeartifact", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,
+ protocols(ServiceProtocol.REST_JSON),
+ Set.of(), Set.of("codeartifact"), Set.of(),
+ Set.of(io.github.hectorvent.floci.services.codeartifact.CodeArtifactController.class)),
descriptor("verifiedpermissions", "verifiedpermissions", config.services().verifiedpermissions().enabled(), true,
"verifiedpermissions", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
protocols(ServiceProtocol.JSON),
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/TagDispatcher.java b/src/main/java/io/github/hectorvent/floci/core/common/TagDispatcher.java
index ef77592139..6065628e9a 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/TagDispatcher.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/TagDispatcher.java
@@ -113,8 +113,8 @@ public class TagDispatcher {
ArrayNode arr = root.putArray(key);
tags.forEach((k, v) -> {
ObjectNode entry = arr.addObject();
- entry.put("Key", k);
- entry.put("Value", v);
+ entry.put(handler.tagEntryKeyName(), k);
+ entry.put(handler.tagEntryValueName(), v);
});
} else {
ObjectNode tagsNode = root.putObject(key);
@@ -147,8 +147,8 @@ public class TagDispatcher {
return tags;
}
for (JsonNode entry : tagNode) {
- JsonNode k = entry.get("Key");
- JsonNode v = entry.get("Value");
+ JsonNode k = entry.get(handler.tagEntryKeyName());
+ JsonNode v = entry.get(handler.tagEntryValueName());
if (k == null || k.isNull() || v == null || v.isNull()) {
if (handler.strictTagValidation()) {
throw new AwsException("ValidationException",
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/TagHandler.java b/src/main/java/io/github/hectorvent/floci/core/common/TagHandler.java
index fb9c80223e..69f559e71d 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/TagHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/TagHandler.java
@@ -106,6 +106,24 @@ public interface TagHandler {
return false;
}
+ /**
+ * JSON member name for a tag entry's key when {@link #tagsBodyIsList()} is {@code true}.
+ * Defaults to {@code "Key"}, matching the great majority of list-shaped AWS services.
+ * Override to {@code "key"} for services that lowercase entry members (CodeArtifact).
+ */
+ default String tagEntryKeyName() {
+ return "Key";
+ }
+
+ /**
+ * JSON member name for a tag entry's value when {@link #tagsBodyIsList()} is {@code true}.
+ * Defaults to {@code "Value"}, matching the great majority of list-shaped AWS services.
+ * Override to {@code "value"} for services that lowercase entry members (CodeArtifact).
+ */
+ default String tagEntryValueName() {
+ return "Value";
+ }
+
/** HTTP status for successful path-based TagResource requests. */
default int tagResourceSuccessStatus() {
return 204;
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/V1TagsController.java b/src/main/java/io/github/hectorvent/floci/core/common/V1TagsController.java
index d5a06d6f13..4ccd0bea1c 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/V1TagsController.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/V1TagsController.java
@@ -3,13 +3,20 @@ package io.github.hectorvent.floci.core.common;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.QueryParam;
+import jakarta.ws.rs.core.Context;
+import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
/**
* Dispatcher for the AWS services that put their tag endpoints on {@code /v1/tags/{resourceArn}}
- * (AppSync, MSK).
+ * (AppSync, MSK) or, for CodeArtifact, on the bare {@code /v1/tags} path with {@code resourceArn}
+ * as a query parameter.
*
* Same problem and same resolution as {@link SharedTagsController}, one path up: AWS tells
* these services apart by hostname, floci serves them all on one port, so the owning service is
@@ -26,4 +33,20 @@ public class V1TagsController extends AbstractTagsController {
ObjectMapper objectMapper) {
super(new TagDispatcher(handlers, regionResolver, objectMapper));
}
+
+ /**
+ * {@code ListTagsForResource} for services that address the resource with a query
+ * parameter on the bare path ({@code POST /v1/tags?resourceArn=...}) rather than a path
+ * segment. CodeArtifact is the only registered handler on this shape today.
+ *
+ *
This lives here rather than on {@link AbstractTagsController} because
+ * {@link SharedTagsController} already declares its own bare {@code POST} ({@code
+ * tagResourceByBody}), and a bare {@code POST} on the shared base would collide with it.
+ */
+ @POST
+ @Consumes(MediaType.APPLICATION_JSON)
+ public Response listTagsForResourceByQuery(@Context HttpHeaders headers,
+ @QueryParam("resourceArn") String resourceArn) {
+ return dispatcher().listTagsForArn(headers, resourceArn);
+ }
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactController.java b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactController.java
new file mode 100644
index 0000000000..204457d4f3
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactController.java
@@ -0,0 +1,437 @@
+package io.github.hectorvent.floci.services.codeartifact;
+
+import com.fasterxml.jackson.databind.DeserializationFeature;
+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.common.JsonErrorResponseUtils;
+import io.github.hectorvent.floci.core.common.PaginatedResult;
+import io.github.hectorvent.floci.core.common.Pagination;
+import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.services.codeartifact.CodeArtifactService.DomainView;
+import io.github.hectorvent.floci.services.codeartifact.CodeArtifactService.ResourcePolicy;
+import io.github.hectorvent.floci.services.codeartifact.model.CodeArtifactRepository;
+import io.github.hectorvent.floci.services.codeartifact.model.ExternalConnection;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.DELETE;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.PUT;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.QueryParam;
+import jakarta.ws.rs.WebApplicationException;
+import jakarta.ws.rs.core.Context;
+import jakarta.ws.rs.core.HttpHeaders;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+@Path("/")
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class CodeArtifactController {
+
+ private final CodeArtifactService service;
+ private final RegionResolver regionResolver;
+ private final ObjectMapper objectMapper;
+
+ @Inject
+ public CodeArtifactController(CodeArtifactService service, RegionResolver regionResolver,
+ ObjectMapper objectMapper) {
+ this.service = service;
+ this.regionResolver = regionResolver;
+ this.objectMapper = objectMapper;
+ }
+
+ // ---------------------------------------------------------------- domains
+
+ @POST
+ @Path("/v1/domain")
+ public Response createDomain(@Context HttpHeaders headers, @QueryParam("domain") String domain, String body) {
+ JsonNode req = readTree(body);
+ String region = regionResolver.resolveRegion(headers);
+ DomainView view = service.createDomain(region, domain, text(req, "encryptionKey"), readTagList(req.get("tags")));
+ return ok(single("domain", domainDescription(view)));
+ }
+
+ @DELETE
+ @Path("/v1/domain")
+ public Response deleteDomain(@Context HttpHeaders headers, @QueryParam("domain") String domain,
+ @QueryParam("domain-owner") String domainOwner) {
+ String region = regionResolver.resolveRegion(headers);
+ DomainView view = service.deleteDomain(region, domain, domainOwner);
+ return ok(single("domain", domainDescription(view)));
+ }
+
+ @GET
+ @Path("/v1/domain")
+ public Response describeDomain(@Context HttpHeaders headers, @QueryParam("domain") String domain,
+ @QueryParam("domain-owner") String domainOwner) {
+ String region = regionResolver.resolveRegion(headers);
+ DomainView view = service.describeDomain(region, domain, domainOwner);
+ return ok(single("domain", domainDescription(view)));
+ }
+
+ @POST
+ @Path("/v1/domains")
+ public Response listDomains(@Context HttpHeaders headers, String body) {
+ JsonNode req = readTree(body);
+ String region = regionResolver.resolveRegion(headers);
+ Integer maxResults = req.hasNonNull("maxResults") ? req.get("maxResults").asInt() : null;
+ PaginatedResult page = service.listDomains(region, maxResults, text(req, "nextToken"));
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode items = response.putArray("domains");
+ page.items().forEach(view -> items.add(domainSummary(view)));
+ if (page.nextToken() != null) {
+ response.put("nextToken", page.nextToken());
+ }
+ return ok(response);
+ }
+
+ @PUT
+ @Path("/v1/domain/permissions/policy")
+ public Response putDomainPermissionsPolicy(@Context HttpHeaders headers, String body) {
+ JsonNode req = readTree(body);
+ String region = regionResolver.resolveRegion(headers);
+ ResourcePolicy policy = service.putDomainPermissionsPolicy(region, text(req, "domain"),
+ text(req, "domainOwner"), text(req, "policyDocument"), text(req, "policyRevision"));
+ return ok(single("policy", resourcePolicy(policy)));
+ }
+
+ @GET
+ @Path("/v1/domain/permissions/policy")
+ public Response getDomainPermissionsPolicy(@Context HttpHeaders headers, @QueryParam("domain") String domain,
+ @QueryParam("domain-owner") String domainOwner) {
+ String region = regionResolver.resolveRegion(headers);
+ ResourcePolicy policy = service.getDomainPermissionsPolicy(region, domain, domainOwner);
+ return ok(single("policy", resourcePolicy(policy)));
+ }
+
+ @DELETE
+ @Path("/v1/domain/permissions/policy")
+ public Response deleteDomainPermissionsPolicy(@Context HttpHeaders headers, @QueryParam("domain") String domain,
+ @QueryParam("domain-owner") String domainOwner,
+ @QueryParam("policy-revision") String policyRevision) {
+ String region = regionResolver.resolveRegion(headers);
+ ResourcePolicy policy = service.deleteDomainPermissionsPolicy(region, domain, domainOwner, policyRevision);
+ return ok(single("policy", resourcePolicy(policy)));
+ }
+
+ // ------------------------------------------------------------ repositories
+
+ @POST
+ @Path("/v1/repository")
+ public Response createRepository(@Context HttpHeaders headers, @QueryParam("domain") String domain,
+ @QueryParam("domain-owner") String domainOwner,
+ @QueryParam("repository") String repository, String body) {
+ JsonNode req = readTree(body);
+ String region = regionResolver.resolveRegion(headers);
+ CodeArtifactRepository r = service.createRepository(region, domain, domainOwner, repository,
+ text(req, "description"), readUpstreams(req.get("upstreams")), readTagList(req.get("tags")));
+ return ok(single("repository", repositoryDescription(r)));
+ }
+
+ @DELETE
+ @Path("/v1/repository")
+ public Response deleteRepository(@Context HttpHeaders headers, @QueryParam("domain") String domain,
+ @QueryParam("domain-owner") String domainOwner,
+ @QueryParam("repository") String repository) {
+ String region = regionResolver.resolveRegion(headers);
+ CodeArtifactRepository r = service.deleteRepository(region, domain, domainOwner, repository);
+ return ok(single("repository", repositoryDescription(r)));
+ }
+
+ @GET
+ @Path("/v1/repository")
+ public Response describeRepository(@Context HttpHeaders headers, @QueryParam("domain") String domain,
+ @QueryParam("domain-owner") String domainOwner,
+ @QueryParam("repository") String repository) {
+ String region = regionResolver.resolveRegion(headers);
+ CodeArtifactRepository r = service.describeRepository(region, domain, domainOwner, repository);
+ return ok(single("repository", repositoryDescription(r)));
+ }
+
+ @PUT
+ @Path("/v1/repository")
+ public Response updateRepository(@Context HttpHeaders headers, @QueryParam("domain") String domain,
+ @QueryParam("domain-owner") String domainOwner,
+ @QueryParam("repository") String repository, String body) {
+ JsonNode req = readTree(body);
+ String region = regionResolver.resolveRegion(headers);
+ CodeArtifactRepository r = service.updateRepository(region, domain, domainOwner, repository,
+ text(req, "description"), req.has("upstreams") ? readUpstreams(req.get("upstreams")) : null);
+ return ok(single("repository", repositoryDescription(r)));
+ }
+
+ @POST
+ @Path("/v1/repositories")
+ public Response listRepositories(@Context HttpHeaders headers,
+ @QueryParam("repository-prefix") String repositoryPrefix,
+ @QueryParam("max-results") String maxResults,
+ @QueryParam("next-token") String nextToken) {
+ String region = regionResolver.resolveRegion(headers);
+ PaginatedResult page = service.listRepositories(region, repositoryPrefix,
+ Pagination.parseMaxResults(maxResults, "ValidationException"), nextToken);
+ return ok(repositorySummaryList(page));
+ }
+
+ @POST
+ @Path("/v1/domain/repositories")
+ public Response listRepositoriesInDomain(@Context HttpHeaders headers, @QueryParam("domain") String domain,
+ @QueryParam("domain-owner") String domainOwner,
+ @QueryParam("administrator-account") String administratorAccount,
+ @QueryParam("repository-prefix") String repositoryPrefix,
+ @QueryParam("max-results") String maxResults,
+ @QueryParam("next-token") String nextToken) {
+ String region = regionResolver.resolveRegion(headers);
+ PaginatedResult page = service.listRepositoriesInDomain(region, domain, domainOwner,
+ administratorAccount, repositoryPrefix, Pagination.parseMaxResults(maxResults, "ValidationException"),
+ nextToken);
+ return ok(repositorySummaryList(page));
+ }
+
+ @GET
+ @Path("/v1/repository/endpoint")
+ public Response getRepositoryEndpoint(@Context HttpHeaders headers, @QueryParam("domain") String domain,
+ @QueryParam("domain-owner") String domainOwner,
+ @QueryParam("repository") String repository,
+ @QueryParam("format") String format,
+ @QueryParam("endpointType") String endpointType) {
+ String region = regionResolver.resolveRegion(headers);
+ String endpoint = service.getRepositoryEndpoint(region, domain, domainOwner, repository, format,
+ endpointType);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("repositoryEndpoint", endpoint);
+ return ok(response);
+ }
+
+ @PUT
+ @Path("/v1/repository/permissions/policy")
+ public Response putRepositoryPermissionsPolicy(@Context HttpHeaders headers, @QueryParam("domain") String domain,
+ @QueryParam("domain-owner") String domainOwner,
+ @QueryParam("repository") String repository, String body) {
+ JsonNode req = readTree(body);
+ String region = regionResolver.resolveRegion(headers);
+ ResourcePolicy policy = service.putRepositoryPermissionsPolicy(region, domain, domainOwner, repository,
+ text(req, "policyDocument"), text(req, "policyRevision"));
+ return ok(single("policy", resourcePolicy(policy)));
+ }
+
+ @GET
+ @Path("/v1/repository/permissions/policy")
+ public Response getRepositoryPermissionsPolicy(@Context HttpHeaders headers, @QueryParam("domain") String domain,
+ @QueryParam("domain-owner") String domainOwner,
+ @QueryParam("repository") String repository) {
+ String region = regionResolver.resolveRegion(headers);
+ ResourcePolicy policy = service.getRepositoryPermissionsPolicy(region, domain, domainOwner, repository);
+ return ok(single("policy", resourcePolicy(policy)));
+ }
+
+ @DELETE
+ @Path("/v1/repository/permissions/policies")
+ public Response deleteRepositoryPermissionsPolicy(@Context HttpHeaders headers,
+ @QueryParam("domain") String domain,
+ @QueryParam("domain-owner") String domainOwner,
+ @QueryParam("repository") String repository,
+ @QueryParam("policy-revision") String policyRevision) {
+ String region = regionResolver.resolveRegion(headers);
+ ResourcePolicy policy = service.deleteRepositoryPermissionsPolicy(region, domain, domainOwner, repository,
+ policyRevision);
+ return ok(single("policy", resourcePolicy(policy)));
+ }
+
+ @POST
+ @Path("/v1/repository/external-connection")
+ public Response associateExternalConnection(@Context HttpHeaders headers, @QueryParam("domain") String domain,
+ @QueryParam("domain-owner") String domainOwner,
+ @QueryParam("repository") String repository,
+ @QueryParam("external-connection") String externalConnection) {
+ String region = regionResolver.resolveRegion(headers);
+ CodeArtifactRepository r = service.associateExternalConnection(region, domain, domainOwner, repository,
+ externalConnection);
+ return ok(single("repository", repositoryDescription(r)));
+ }
+
+ @DELETE
+ @Path("/v1/repository/external-connection")
+ public Response disassociateExternalConnection(@Context HttpHeaders headers, @QueryParam("domain") String domain,
+ @QueryParam("domain-owner") String domainOwner,
+ @QueryParam("repository") String repository,
+ @QueryParam("external-connection") String externalConnection) {
+ String region = regionResolver.resolveRegion(headers);
+ CodeArtifactRepository r = service.disassociateExternalConnection(region, domain, domainOwner, repository,
+ externalConnection);
+ return ok(single("repository", repositoryDescription(r)));
+ }
+
+ // -------------------------------------------------------------------- tags
+
+ @POST
+ @Path("/v1/tag")
+ public Response tagResource(@QueryParam("resourceArn") String resourceArn, String body) {
+ JsonNode req = readTree(body);
+ service.tagResource(resourceArn, readTagList(req.get("tags")));
+ return ok(objectMapper.createObjectNode());
+ }
+
+ @POST
+ @Path("/v1/untag")
+ public Response untagResource(@QueryParam("resourceArn") String resourceArn, String body) {
+ JsonNode req = readTree(body);
+ List keys = new ArrayList<>();
+ if (req.hasNonNull("tagKeys") && req.get("tagKeys").isArray()) {
+ req.get("tagKeys").forEach(n -> keys.add(n.asText()));
+ }
+ service.untagResource(resourceArn, keys);
+ return ok(objectMapper.createObjectNode());
+ }
+
+ // ListTagsForResource (POST /v1/tags?resourceArn=) is handled by V1TagsController via
+ // CodeArtifactTagHandler; see their javadoc.
+
+ // ----------------------------------------------------------------- helpers
+
+ private ObjectNode domainDescription(DomainView view) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("arn", view.domain().getArn());
+ node.put("assetSizeBytes", 0L);
+ node.put("createdTime", view.domain().getCreatedTime());
+ node.put("encryptionKey", view.domain().getEncryptionKey());
+ node.put("name", view.domain().getName());
+ node.put("owner", view.domain().getOwner());
+ node.put("repositoryCount", view.repositoryCount());
+ // AWS's internal per-domain bucket naming is not publicly documented; this is a synthesized placeholder.
+ node.put("s3BucketArn", "arn:aws:s3:::codeartifact-" + view.domain().getRegion() + "-" + view.domain().getOwner());
+ node.put("status", "Active");
+ return node;
+ }
+
+ private ObjectNode domainSummary(DomainView view) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("name", view.domain().getName());
+ node.put("owner", view.domain().getOwner());
+ node.put("arn", view.domain().getArn());
+ node.put("status", "Active");
+ node.put("createdTime", view.domain().getCreatedTime());
+ node.put("encryptionKey", view.domain().getEncryptionKey());
+ return node;
+ }
+
+ private ObjectNode repositoryDescription(CodeArtifactRepository r) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("administratorAccount", r.getAdministratorAccount());
+ node.put("arn", r.getArn());
+ node.put("createdTime", r.getCreatedTime());
+ if (r.getDescription() != null) {
+ node.put("description", r.getDescription());
+ }
+ node.put("domainName", r.getDomainName());
+ node.put("domainOwner", r.getDomainOwner());
+ ArrayNode connections = node.putArray("externalConnections");
+ for (ExternalConnection ec : r.getExternalConnections()) {
+ ObjectNode c = objectMapper.createObjectNode();
+ c.put("externalConnectionName", ec.getExternalConnectionName());
+ c.put("packageFormat", ec.getPackageFormat());
+ c.put("status", ec.getStatus());
+ connections.add(c);
+ }
+ node.put("name", r.getName());
+ ArrayNode upstreams = node.putArray("upstreams");
+ for (String upstream : r.getUpstreams()) {
+ ObjectNode u = objectMapper.createObjectNode();
+ u.put("repositoryName", upstream);
+ upstreams.add(u);
+ }
+ return node;
+ }
+
+ private ObjectNode repositorySummary(CodeArtifactRepository r) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("name", r.getName());
+ node.put("administratorAccount", r.getAdministratorAccount());
+ node.put("domainName", r.getDomainName());
+ node.put("domainOwner", r.getDomainOwner());
+ node.put("arn", r.getArn());
+ if (r.getDescription() != null) {
+ node.put("description", r.getDescription());
+ }
+ node.put("createdTime", r.getCreatedTime());
+ return node;
+ }
+
+ private ObjectNode repositorySummaryList(PaginatedResult page) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode items = response.putArray("repositories");
+ page.items().forEach(r -> items.add(repositorySummary(r)));
+ if (page.nextToken() != null) {
+ response.put("nextToken", page.nextToken());
+ }
+ return response;
+ }
+
+ private ObjectNode resourcePolicy(ResourcePolicy policy) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("resourceArn", policy.resourceArn());
+ node.put("revision", policy.revision());
+ node.put("document", policy.document());
+ return node;
+ }
+
+ private ObjectNode single(String field, ObjectNode value) {
+ ObjectNode wrapper = objectMapper.createObjectNode();
+ wrapper.set(field, value);
+ return wrapper;
+ }
+
+ private Response ok(ObjectNode body) {
+ return Response.ok(body).build();
+ }
+
+ private Map readTagList(JsonNode tagsArray) {
+ Map tags = new LinkedHashMap<>();
+ if (tagsArray == null || tagsArray.isNull()) {
+ return tags;
+ }
+ if (!tagsArray.isArray()) {
+ throw new AwsException("ValidationException", "tags must be an array of {key, value} objects.", 400);
+ }
+ tagsArray.forEach(n -> tags.put(text(n, "key"), text(n, "value")));
+ return tags;
+ }
+
+ private List readUpstreams(JsonNode upstreamsArray) {
+ List upstreams = new ArrayList<>();
+ if (upstreamsArray == null || upstreamsArray.isNull()) {
+ return upstreams;
+ }
+ if (!upstreamsArray.isArray()) {
+ throw new AwsException("ValidationException", "upstreams must be an array of {repositoryName} objects.",
+ 400);
+ }
+ upstreamsArray.forEach(n -> upstreams.add(text(n, "repositoryName")));
+ return upstreams;
+ }
+
+ private static String text(JsonNode node, String field) {
+ JsonNode value = node == null ? null : node.get(field);
+ return value != null && value.isTextual() ? value.textValue() : null;
+ }
+
+ private JsonNode readTree(String body) {
+ try {
+ return objectMapper.reader()
+ .with(DeserializationFeature.FAIL_ON_TRAILING_TOKENS)
+ .readTree(body == null || body.isBlank() ? "{}" : body);
+ } catch (Exception e) {
+ throw new WebApplicationException(JsonErrorResponseUtils.createSerializationErrorResponse());
+ }
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactService.java b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactService.java
new file mode 100644
index 0000000000..9887efa1bf
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/codeartifact/CodeArtifactService.java
@@ -0,0 +1,544 @@
+package io.github.hectorvent.floci.services.codeartifact;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import io.github.hectorvent.floci.config.EmulatorConfig;
+import io.github.hectorvent.floci.core.common.AwsArnUtils;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.PaginatedResult;
+import io.github.hectorvent.floci.core.common.Pagination;
+import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.common.Resettable;
+import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
+import io.github.hectorvent.floci.core.storage.StorageFactory;
+import io.github.hectorvent.floci.services.codeartifact.model.CodeArtifactDomain;
+import io.github.hectorvent.floci.services.codeartifact.model.CodeArtifactRepository;
+import io.github.hectorvent.floci.services.codeartifact.model.ExternalConnection;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.UUID;
+import java.util.regex.Pattern;
+
+@ApplicationScoped
+public class CodeArtifactService implements Resettable {
+
+ /** name -> packageFormat, the fixed real set of AWS-hosted public upstream connections. */
+ private static final Map EXTERNAL_CONNECTIONS = Map.ofEntries(
+ Map.entry("public:maven-clojars", "maven"),
+ Map.entry("public:maven-commonsware", "maven"),
+ Map.entry("public:maven-googleandroid", "maven"),
+ Map.entry("public:maven-gradleplugins", "maven"),
+ Map.entry("public:maven-central", "maven"),
+ Map.entry("public:npmjs", "npm"),
+ Map.entry("public:nuget-org", "nuget"),
+ Map.entry("public:pypi", "pypi"),
+ Map.entry("public:ruby-gems-org", "ruby"),
+ Map.entry("public:crates-io", "cargo"));
+
+ private static final Set PACKAGE_FORMATS =
+ Set.of("npm", "pypi", "maven", "nuget", "generic", "ruby", "swift", "cargo");
+ private static final Set ENDPOINT_TYPES = Set.of("dualstack", "ipv4");
+
+ private static final Pattern DOMAIN_NAME = Pattern.compile("[a-z][a-z0-9\\-]{0,48}[a-z0-9]");
+ private static final Pattern REPOSITORY_NAME = Pattern.compile("[A-Za-z0-9][A-Za-z0-9._\\-]{1,99}");
+ private static final Pattern ACCOUNT_ID = Pattern.compile("[0-9]{12}");
+
+ public record DomainView(CodeArtifactDomain domain, int repositoryCount) {}
+ public record ResourcePolicy(String resourceArn, String revision, String document) {}
+
+ private final AccountAwareStorageBackend domains;
+ private final AccountAwareStorageBackend repositories;
+ private final RegionResolver regionResolver;
+ private final EmulatorConfig config;
+
+ @Inject
+ public CodeArtifactService(StorageFactory storageFactory, RegionResolver regionResolver, EmulatorConfig config) {
+ this.domains = storageFactory.create("codeartifact", "codeartifact-domains.json",
+ new TypeReference