mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
feat(redshift-serverless): add custom domain association actions (#5766)
* feat(redshift-serverless): add custom domain association actions Add CreateCustomDomainAssociation, GetCustomDomainAssociation, ListCustomDomainAssociations, UpdateCustomDomainAssociation and DeleteCustomDomainAssociation. An association is recorded and echoed; Floci serves no traffic on the domain and reads no ACM certificate. It is tied to the workgroup by the workgroup's generated id, so a workgroup recreated under the same name does not inherit it. The domain name and certificate ARN patterns, lengths and the required members come from the AWS model through RedshiftServerlessRequestShapes, so the service carries no validation of its own. * fix(redshift-serverless): address review findings for custom domains - Expose custom domain name and certificate ARN in workgroup responses. - Ensure custom domain names are unique across workgroups in a region. - Remove ambiguous Pagination.paginate overload in favor of paginateNamespaced. - Add domain name and certificate ARN validation patterns and length checks. - Enforce validation for required parameters in custom domain operations. * fix(redshift-serverless): enforce single custom domain per workgroup and populate certificate expiry * fix(redshift-serverless): read certificate expiry dynamically and share custom domain serialization
This commit is contained in:
1 parent
92be67d2df
commit
7cab804d22
11 files changed
+626
-19
No files matched your search
+26
@@ -347,6 +347,32 @@ class RedshiftServerlessTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void customDomainAssociationUsesAwsSdk() {
|
||||
assumeFalse(TestFixtures.isRealAws(), "Creates resources and asserts emulator-local behavior");
|
||||
|
||||
try (RedshiftServerlessClient client = TestFixtures.redshiftServerlessClient()) {
|
||||
String namespaceName = "floci-compat-domain-ns";
|
||||
String workgroupName = "floci-compat-domain-wg";
|
||||
String certificate = "arn:aws:acm:us-east-1:000000000000:certificate/11111111-2222-3333-4444-555555555555";
|
||||
try {
|
||||
client.createNamespace(request -> request.namespaceName(namespaceName).adminUsername("admin")
|
||||
.adminUserPassword("Secret123!"));
|
||||
client.createWorkgroup(request -> request.workgroupName(workgroupName).namespaceName(namespaceName));
|
||||
|
||||
client.createCustomDomainAssociation(request -> request.workgroupName(workgroupName)
|
||||
.customDomainName("db.example.com").customDomainCertificateArn(certificate));
|
||||
assertThat(client.listCustomDomainAssociations(request -> request.customDomainName("db.example.com"))
|
||||
.associations()).hasSize(1);
|
||||
client.deleteCustomDomainAssociation(request -> request.workgroupName(workgroupName)
|
||||
.customDomainName("db.example.com"));
|
||||
} finally {
|
||||
deleteWorkgroupBestEffort(client, workgroupName);
|
||||
deleteBestEffort(client, namespaceName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void deleteSnapshotBestEffort(RedshiftServerlessClient client, String snapshotName) {
|
||||
try {
|
||||
client.deleteSnapshot(request -> request.snapshotName(snapshotName));
|
||||
|
||||
@@ -77,7 +77,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac
|
||||
| [DMS](dms.md) | `POST /` + `X-Amz-Target: AmazonDMSv20160101.*` | JSON 1.1 | 20 |
|
||||
| [Redshift](redshift.md) | `POST /` with `Action=` param + PostgreSQL container | Query + PostgreSQL wire (+ CFN) | 43 |
|
||||
| [Redshift Data API](redshift-data.md) | `POST /` + `X-Amz-Target: RedshiftData.*` | JSON 1.1 | 11 |
|
||||
| [Redshift Serverless](redshift-serverless.md) | `POST /` + `X-Amz-Target: RedshiftServerless.*` | JSON 1.1 | 41 |
|
||||
| [Redshift Serverless](redshift-serverless.md) | `POST /` + `X-Amz-Target: RedshiftServerless.*` | JSON 1.1 | 46 |
|
||||
| [EMR](emr.md) | `POST /` + `X-Amz-Target: ElasticMapReduce.*` | JSON 1.1 | 37 |
|
||||
| [EMR Serverless](emr-serverless.md) | `/applications/*`, `/tags/*` | REST JSON | 10 |
|
||||
| [Data Firehose](firehose.md) | `POST /` + `X-Amz-Target: Firehose_20150804.*` | JSON 1.1 | 12 |
|
||||
|
||||
@@ -53,6 +53,11 @@ For the upstream API shape, see the [Amazon Redshift Serverless API Reference](h
|
||||
| `ListEndpointAccess` | Page through the endpoints, filtered by `workgroupName`, `ownerAccount` and `vpcId` |
|
||||
| `UpdateEndpointAccess` | Replace the `vpcSecurityGroupIds` of an endpoint |
|
||||
| `DeleteEndpointAccess` | Remove an endpoint and return it with `endpointStatus` `DELETING` |
|
||||
| `CreateCustomDomainAssociation` | Record a custom domain and ACM certificate ARN for a workgroup |
|
||||
| `GetCustomDomainAssociation` | Return a custom domain association |
|
||||
| `ListCustomDomainAssociations` | Page through the associations, filtered by `customDomainName` and `customDomainCertificateArn` |
|
||||
| `UpdateCustomDomainAssociation` | Point an association at another certificate ARN |
|
||||
| `DeleteCustomDomainAssociation` | Remove a custom domain association |
|
||||
<!-- floci:actions:end -->
|
||||
|
||||
Namespace and workgroup state is account and Region scoped and persisted through `StorageFactory`.
|
||||
@@ -80,7 +85,7 @@ Namespace and workgroup state is account and Region scoped and persisted through
|
||||
- **Capacity, network and security settings are stored and echoed, not enforced.** `baseCapacity`, `maxCapacity`, `subnetIds`, `securityGroupIds`, `enhancedVpcRouting`, `publiclyAccessible` and `configParameters` have no effect on the emulator. `configParameters` returns only what the caller supplied: AWS also adds a set of default parameters that the API reference does not enumerate, and Terraform treats the attribute as computed, so the difference does not produce a plan diff.
|
||||
- **`port` is validated and echoed.** It must be in 5431-5455 or 8191-8215. The `endpoint.port` is the port Floci allocated, which is what a client connects to.
|
||||
- **`UpdateWorkgroup` applies only the fields present.** AWS documents that several parameters cannot be changed in one request; Floci accepts any combination. A `trackName` different from the current one is recorded as `pendingTrackName` and `trackName` is unchanged, as AWS switches tracks on the next release. `workgroupName` and `namespaceName` cannot be changed.
|
||||
- **`workgroupArn` is `arn:aws:redshift-serverless:<region>:<account>:workgroup/<workgroupId>`**, and `creationDate` is an ISO-8601 string like the namespace one. `workgroupVersion`, `patchVersion`, `crossAccountVpcs`, the custom domain members and `endpoint.vpcEndpoints` are omitted.
|
||||
- **`workgroupArn` is `arn:aws:redshift-serverless:<region>:<account>:workgroup/<workgroupId>`**, and `creationDate` is an ISO-8601 string like the namespace one. `workgroupVersion`, `patchVersion`, `crossAccountVpcs` and `endpoint.vpcEndpoints` are omitted.
|
||||
- **Tagging is keyed by `resourceArn`, not by name**, and namespaces and workgroups are the taggable Redshift Serverless resources in Floci. `TagResource` merges into the existing tags rather than replacing them, `UntagResource` removes by key, and any ARN that does not name a known namespace or workgroup in the caller's Region returns `ResourceNotFoundException`. Tags supplied at create are readable through `ListTagsForResource` and survive an update.
|
||||
|
||||
## AWS-compatible failures
|
||||
@@ -129,3 +134,4 @@ aws redshift-serverless delete-namespace --namespace-name analytics
|
||||
- **`UpdateSnapshot` changes only `retentionPeriod`.** It is validated like `CreateSnapshot` (`-1` or 1 to 3653 days), `-1` makes the snapshot indefinite, and an omitted period leaves the snapshot unchanged. `snapshotRemainingDays` keeps counting from the creation time, because Floci stores no separate retention start.
|
||||
- **Resource policies are recorded, not acted on.** A policy is stored per account and Region, echoed in the shape of the API model, and dropped on read once the snapshot it belongs to is gone. A snapshot recreated under the same name is a different snapshot: the record keeps the snapshot's creation time, so the policy is not inherited. `PutResourcePolicy` accepts a JSON object for a snapshot ARN of this account and Region; no principal in it gains access. A foreign or non-snapshot ARN is a `ValidationException`.
|
||||
- **Endpoint access is recorded, not acted on.** An endpoint is stored per account and Region, echoed in the shape of the API model, and dropped on read once its workgroup is gone; a workgroup recreated under the same name is a different workgroup and does not inherit it. `CreateEndpointAccess` creates no VPC endpoint. `address` and `port` are the workgroup's own, so a client can connect; `vpcEndpoint` carries a generated id and one network interface per subnet, without a `vpcId`, and `ListEndpointAccess` with a `vpcId` returns nothing. `vpcSecurityGroupIds` is optional. Endpoint names are 1 to 30 letters, digits or hyphens, start with a letter, and contain no consecutive or trailing hyphens. Security groups are the only member `UpdateEndpointAccess` changes.
|
||||
- **Custom domain associations are recorded, not acted on.** An association is stored per account and Region and dropped on read once its workgroup is gone; a workgroup recreated under the same name does not inherit it. A workgroup has at most one custom domain association. The certificate expiry time comes from ACM when the certificate exists in the emulator.
|
||||
+54
-2
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.PaginatedResult;
|
||||
import io.github.hectorvent.floci.core.common.Pagination;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.model.CustomDomainAssociation;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.model.EndpointAccess;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.model.ResourcePolicy;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
@@ -27,16 +28,19 @@ public class RedshiftServerlessAdminJsonHandler {
|
||||
private static final List<String> TRACK_NAMES = RedshiftServerlessService.TRACK_NAMES;
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
private final RedshiftServerlessCustomDomainService customDomains;
|
||||
private final RedshiftServerlessEndpointAccessService endpointAccess;
|
||||
private final RedshiftServerlessResourcePolicyService resourcePolicies;
|
||||
|
||||
@Inject
|
||||
public RedshiftServerlessAdminJsonHandler(ObjectMapper objectMapper,
|
||||
RedshiftServerlessResourcePolicyService resourcePolicies,
|
||||
RedshiftServerlessEndpointAccessService endpointAccess) {
|
||||
RedshiftServerlessEndpointAccessService endpointAccess,
|
||||
RedshiftServerlessCustomDomainService customDomains) {
|
||||
this.objectMapper = objectMapper;
|
||||
this.resourcePolicies = resourcePolicies;
|
||||
this.endpointAccess = endpointAccess;
|
||||
this.customDomains = customDomains;
|
||||
}
|
||||
|
||||
Supplier<Response> operation(String action, JsonNode request, String region) {
|
||||
@@ -48,7 +52,7 @@ public class RedshiftServerlessAdminJsonHandler {
|
||||
ServerlessSupport.text(request, "resourceArn"), region));
|
||||
case "DeleteResourcePolicy" -> () -> {
|
||||
resourcePolicies.deleteResourcePolicy(ServerlessSupport.text(request, "resourceArn"), region);
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
return emptyResponse();
|
||||
};
|
||||
case "GetTrack" -> () -> getTrack(ServerlessSupport.text(request, "trackName"));
|
||||
case "ListTracks" -> () -> listTracks(request);
|
||||
@@ -71,6 +75,25 @@ public class RedshiftServerlessAdminJsonHandler {
|
||||
ServerlessSupport.stringList(request, "vpcSecurityGroupIds"), region));
|
||||
case "DeleteEndpointAccess" -> () -> endpointResponse(endpointAccess.deleteEndpointAccess(
|
||||
ServerlessSupport.text(request, "endpointName"), region));
|
||||
case "CreateCustomDomainAssociation" -> () -> customDomainResponse(
|
||||
customDomains.createCustomDomainAssociation(
|
||||
ServerlessSupport.text(request, "workgroupName"),
|
||||
ServerlessSupport.text(request, "customDomainName"),
|
||||
ServerlessSupport.text(request, "customDomainCertificateArn"), region));
|
||||
case "GetCustomDomainAssociation" -> () -> customDomainResponse(
|
||||
customDomains.getCustomDomainAssociation(ServerlessSupport.text(request, "workgroupName"),
|
||||
ServerlessSupport.text(request, "customDomainName"), region));
|
||||
case "ListCustomDomainAssociations" -> () -> listCustomDomains(request, region);
|
||||
case "UpdateCustomDomainAssociation" -> () -> customDomainResponse(
|
||||
customDomains.updateCustomDomainAssociation(
|
||||
ServerlessSupport.text(request, "workgroupName"),
|
||||
ServerlessSupport.text(request, "customDomainName"),
|
||||
ServerlessSupport.text(request, "customDomainCertificateArn"), region));
|
||||
case "DeleteCustomDomainAssociation" -> () -> {
|
||||
customDomains.deleteCustomDomainAssociation(ServerlessSupport.text(request, "workgroupName"),
|
||||
ServerlessSupport.text(request, "customDomainName"), region);
|
||||
return emptyResponse();
|
||||
};
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
@@ -154,6 +177,31 @@ public class RedshiftServerlessAdminJsonHandler {
|
||||
return node;
|
||||
}
|
||||
|
||||
// ── Custom domain association ──────────────────────────────────────────
|
||||
|
||||
private Response listCustomDomains(JsonNode request, String region) {
|
||||
PaginatedResult<CustomDomainAssociation> page = customDomains.listCustomDomainAssociations(
|
||||
ServerlessSupport.text(request, "customDomainName"),
|
||||
ServerlessSupport.text(request, "customDomainCertificateArn"), region,
|
||||
ServerlessSupport.maxResults(request), ServerlessSupport.text(request, "nextToken"));
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode items = response.putArray("associations");
|
||||
page.items().forEach(association -> items.add(customDomainNode(association)));
|
||||
putNextToken(response, page);
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response customDomainResponse(CustomDomainAssociation association) {
|
||||
return Response.ok(customDomainNode(association)).build();
|
||||
}
|
||||
|
||||
private ObjectNode customDomainNode(CustomDomainAssociation association) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
ServerlessSupport.populateCustomDomain(node, association);
|
||||
node.put("workgroupName", association.getWorkgroupName());
|
||||
return node;
|
||||
}
|
||||
|
||||
// ── Tracks, managed workgroups and reservations ────────────────────────
|
||||
|
||||
/**
|
||||
@@ -201,6 +249,10 @@ public class RedshiftServerlessAdminJsonHandler {
|
||||
|
||||
// ── Shared ─────────────────────────────────────────────────────────────
|
||||
|
||||
private Response emptyResponse() {
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
private static void putNextToken(ObjectNode response, PaginatedResult<?> page) {
|
||||
if (page.nextToken() != null) {
|
||||
response.put("nextToken", page.nextToken());
|
||||
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
package io.github.hectorvent.floci.services.redshiftserverless;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
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.Resettable;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.acm.AcmService;
|
||||
import io.github.hectorvent.floci.services.acm.model.Certificate;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.model.CustomDomainAssociation;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.model.Workgroup;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Redshift Serverless custom domain associations. An association is recorded and echoed: Floci
|
||||
* serves no traffic on the domain, but reads the ACM certificate to report expiry when available.
|
||||
*
|
||||
* <p>An association belongs to a workgroup but lives in its own store, so deleting the workgroup
|
||||
* needs no hook here. Each read checks that the workgroup is still there and drops the association
|
||||
* otherwise.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class RedshiftServerlessCustomDomainService implements Resettable {
|
||||
|
||||
private static final int PAGE_SIZE = 100;
|
||||
|
||||
private final AccountAwareStorageBackend<CustomDomainAssociation> associations;
|
||||
private final RedshiftServerlessService serverless;
|
||||
private final AcmService acmService;
|
||||
|
||||
@Inject
|
||||
public RedshiftServerlessCustomDomainService(StorageFactory storageFactory,
|
||||
RedshiftServerlessService serverless,
|
||||
AcmService acmService) {
|
||||
this.associations = storageFactory.create("redshiftserverless",
|
||||
"redshiftserverless-customdomains.json",
|
||||
new TypeReference<Map<String, CustomDomainAssociation>>() {});
|
||||
this.serverless = serverless;
|
||||
this.acmService = acmService;
|
||||
}
|
||||
|
||||
public synchronized CustomDomainAssociation createCustomDomainAssociation(
|
||||
String workgroupName, String customDomainName, String certificateArn, String region) {
|
||||
Workgroup workgroup = serverless.findWorkgroup(workgroupName, region)
|
||||
.orElseThrow(() -> ServerlessSupport.notFound("The workgroup " + workgroupName + " was not found."));
|
||||
CustomDomainAssociation forWorkgroup = findForWorkgroup(workgroupName, region).orElse(null);
|
||||
if (forWorkgroup != null) {
|
||||
if (customDomainName.equals(forWorkgroup.getCustomDomainName())) {
|
||||
throw ServerlessSupport.conflict("The custom domain " + customDomainName
|
||||
+ " is already associated with the workgroup " + workgroupName + ".");
|
||||
}
|
||||
throw ServerlessSupport.conflict("The workgroup " + workgroupName
|
||||
+ " already has a custom domain associated with it.");
|
||||
}
|
||||
CustomDomainAssociation existing = findByDomain(customDomainName, region);
|
||||
if (existing != null) {
|
||||
throw ServerlessSupport.conflict("The custom domain " + customDomainName
|
||||
+ " is already associated with the workgroup " + existing.getWorkgroupName() + ".");
|
||||
}
|
||||
CustomDomainAssociation association = new CustomDomainAssociation();
|
||||
association.setWorkgroupName(workgroupName);
|
||||
association.setOwnerId(workgroup.getWorkgroupId());
|
||||
association.setCustomDomainName(customDomainName);
|
||||
association.setCustomDomainCertificateArn(certificateArn);
|
||||
associations.put(storageKey(region, workgroupName, customDomainName), association);
|
||||
return withCertificateExpiry(association, region);
|
||||
}
|
||||
|
||||
public synchronized CustomDomainAssociation getCustomDomainAssociation(
|
||||
String workgroupName, String customDomainName, String region) {
|
||||
return withCertificateExpiry(require(workgroupName, customDomainName, region), region);
|
||||
}
|
||||
|
||||
public synchronized Optional<CustomDomainAssociation> findForWorkgroup(String workgroupName, String region) {
|
||||
return live(region).stream()
|
||||
.filter(association -> association.getWorkgroupName().equals(workgroupName))
|
||||
.findFirst()
|
||||
.map(association -> withCertificateExpiry(association, region));
|
||||
}
|
||||
|
||||
public synchronized PaginatedResult<CustomDomainAssociation> listCustomDomainAssociations(
|
||||
String customDomainName, String certificateArn, String region, Integer maxResults, String nextToken) {
|
||||
if (maxResults != null && (maxResults < 1 || maxResults > PAGE_SIZE)) {
|
||||
throw ServerlessSupport.validation("maxResults must be between 1 and " + PAGE_SIZE);
|
||||
}
|
||||
int limit = maxResults != null ? maxResults : PAGE_SIZE;
|
||||
List<CustomDomainAssociation> matching = live(region).stream()
|
||||
.filter(association -> customDomainName == null
|
||||
|| customDomainName.equals(association.getCustomDomainName()))
|
||||
.filter(association -> certificateArn == null
|
||||
|| certificateArn.equals(association.getCustomDomainCertificateArn()))
|
||||
.sorted(Comparator.comparing(CustomDomainAssociation::getWorkgroupName)
|
||||
.thenComparing(CustomDomainAssociation::getCustomDomainName))
|
||||
.map(association -> withCertificateExpiry(association, region))
|
||||
.toList();
|
||||
return Pagination.paginate(matching,
|
||||
association -> association.getWorkgroupName() + "|" + association.getCustomDomainName(),
|
||||
limit, nextToken, "custom-domain",
|
||||
token -> new AwsException("InvalidPaginationException", "Invalid nextToken.", 400));
|
||||
}
|
||||
|
||||
/** Points the association at another certificate, the only member AWS lets an update change. */
|
||||
public synchronized CustomDomainAssociation updateCustomDomainAssociation(
|
||||
String workgroupName, String customDomainName, String certificateArn, String region) {
|
||||
CustomDomainAssociation updated = new CustomDomainAssociation(require(workgroupName, customDomainName, region));
|
||||
updated.setCustomDomainCertificateArn(certificateArn);
|
||||
updated.setCustomDomainCertificateExpiryTime(null);
|
||||
associations.put(storageKey(region, workgroupName, customDomainName), updated);
|
||||
return withCertificateExpiry(updated, region);
|
||||
}
|
||||
|
||||
public synchronized void deleteCustomDomainAssociation(String workgroupName, String customDomainName,
|
||||
String region) {
|
||||
require(workgroupName, customDomainName, region);
|
||||
associations.delete(storageKey(region, workgroupName, customDomainName));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
associations.clear();
|
||||
}
|
||||
|
||||
private CustomDomainAssociation require(String workgroupName, String customDomainName, String region) {
|
||||
CustomDomainAssociation association = find(workgroupName, customDomainName, region);
|
||||
if (association == null) {
|
||||
throw ServerlessSupport.notFound("The custom domain " + customDomainName
|
||||
+ " is not associated with the workgroup " + workgroupName + ".");
|
||||
}
|
||||
return association;
|
||||
}
|
||||
|
||||
/** The association, or null when there is none or its workgroup is gone, in which case it is dropped. */
|
||||
private CustomDomainAssociation find(String workgroupName, String customDomainName, String region) {
|
||||
String key = storageKey(region, workgroupName, customDomainName);
|
||||
CustomDomainAssociation association = associations.get(key).orElse(null);
|
||||
if (association != null && !isOnSameWorkgroup(association, region)) {
|
||||
associations.delete(key);
|
||||
return null;
|
||||
}
|
||||
return association;
|
||||
}
|
||||
|
||||
/** The region's associations whose workgroup is still there; any other is deleted as it is found. */
|
||||
private List<CustomDomainAssociation> live(String region) {
|
||||
return ServerlessSupport.live(associations, region,
|
||||
association -> isOnSameWorkgroup(association, region),
|
||||
association -> storageKey(region, association.getWorkgroupName(), association.getCustomDomainName()));
|
||||
}
|
||||
|
||||
/** A workgroup recreated under the same name has a new id, so it never inherits its predecessor's domains. */
|
||||
private boolean isOnSameWorkgroup(CustomDomainAssociation association, String region) {
|
||||
return serverless.findWorkgroup(association.getWorkgroupName(), region)
|
||||
.map(workgroup -> Objects.equals(workgroup.getWorkgroupId(), association.getOwnerId()))
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
/** The live association claiming this custom domain in the region, or null when none does. */
|
||||
private CustomDomainAssociation findByDomain(String customDomainName, String region) {
|
||||
return live(region).stream()
|
||||
.filter(association -> customDomainName.equals(association.getCustomDomainName()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private Instant certificateExpiryTime(String certificateArn, String region) {
|
||||
if (certificateArn == null || certificateArn.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
String certRegion = region;
|
||||
if (AwsArnUtils.isArn(certificateArn)) {
|
||||
String arnRegion = AwsArnUtils.parse(certificateArn).region();
|
||||
if (arnRegion != null && !arnRegion.isBlank()) {
|
||||
certRegion = arnRegion;
|
||||
}
|
||||
}
|
||||
try {
|
||||
Certificate certificate = acmService.describeCertificate(certificateArn, certRegion);
|
||||
return certificate != null ? certificate.getNotAfter() : null;
|
||||
} catch (AwsException ignored) {
|
||||
// A missing certificate in ACM leaves the expiry time unknown.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private CustomDomainAssociation withCertificateExpiry(CustomDomainAssociation association, String region) {
|
||||
CustomDomainAssociation copy = new CustomDomainAssociation(association);
|
||||
copy.setCustomDomainCertificateExpiryTime(certificateExpiryTime(copy.getCustomDomainCertificateArn(), region));
|
||||
return copy;
|
||||
}
|
||||
|
||||
private static String storageKey(String region, String workgroupName, String customDomainName) {
|
||||
return region + "::" + workgroupName + "::" + customDomainName;
|
||||
}
|
||||
}
|
||||
+15
-10
@@ -44,17 +44,20 @@ public class RedshiftServerlessJsonHandler {
|
||||
private final RedshiftIamDbUserResolver iamDbUserResolver;
|
||||
private final RedshiftServerlessUsageLimitService usageLimits;
|
||||
private final RedshiftServerlessAdminJsonHandler admin;
|
||||
private final RedshiftServerlessCustomDomainService customDomains;
|
||||
|
||||
@Inject
|
||||
public RedshiftServerlessJsonHandler(RedshiftServerlessService service, ObjectMapper objectMapper,
|
||||
RedshiftIamDbUserResolver iamDbUserResolver,
|
||||
RedshiftServerlessUsageLimitService usageLimits,
|
||||
RedshiftServerlessAdminJsonHandler admin) {
|
||||
RedshiftServerlessAdminJsonHandler admin,
|
||||
RedshiftServerlessCustomDomainService customDomains) {
|
||||
this.service = service;
|
||||
this.objectMapper = objectMapper;
|
||||
this.iamDbUserResolver = iamDbUserResolver;
|
||||
this.usageLimits = usageLimits;
|
||||
this.admin = admin;
|
||||
this.customDomains = customDomains;
|
||||
}
|
||||
|
||||
public Response handle(String action, JsonNode request, String region) {
|
||||
@@ -163,11 +166,11 @@ public class RedshiftServerlessJsonHandler {
|
||||
parseWorkgroupSettings(request),
|
||||
parseTagList(request.path("tags"), "tags"),
|
||||
region);
|
||||
return workgroupResponse(workgroup);
|
||||
return workgroupResponse(workgroup, region);
|
||||
}
|
||||
|
||||
private Response handleGetWorkgroup(JsonNode request, String region) {
|
||||
return workgroupResponse(service.getWorkgroup(ServerlessSupport.text(request, "workgroupName"), region));
|
||||
return workgroupResponse(service.getWorkgroup(ServerlessSupport.text(request, "workgroupName"), region), region);
|
||||
}
|
||||
|
||||
private Response handleListWorkgroups(JsonNode request, String region) {
|
||||
@@ -175,7 +178,7 @@ public class RedshiftServerlessJsonHandler {
|
||||
region, ServerlessSupport.maxResults(request), ServerlessSupport.text(request, "nextToken"));
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode items = response.putArray("workgroups");
|
||||
page.items().forEach(workgroup -> items.add(workgroupNode(workgroup)));
|
||||
page.items().forEach(workgroup -> items.add(workgroupNode(workgroup, region)));
|
||||
if (page.nextToken() != null) {
|
||||
response.put("nextToken", page.nextToken());
|
||||
}
|
||||
@@ -184,11 +187,11 @@ public class RedshiftServerlessJsonHandler {
|
||||
|
||||
private Response handleUpdateWorkgroup(JsonNode request, String region) {
|
||||
return workgroupResponse(service.updateWorkgroup(
|
||||
ServerlessSupport.text(request, "workgroupName"), parseWorkgroupSettings(request), region));
|
||||
ServerlessSupport.text(request, "workgroupName"), parseWorkgroupSettings(request), region), region);
|
||||
}
|
||||
|
||||
private Response handleDeleteWorkgroup(JsonNode request, String region) {
|
||||
return workgroupResponse(service.deleteWorkgroup(ServerlessSupport.text(request, "workgroupName"), region));
|
||||
return workgroupResponse(service.deleteWorkgroup(ServerlessSupport.text(request, "workgroupName"), region), region);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -420,24 +423,26 @@ public class RedshiftServerlessJsonHandler {
|
||||
return node;
|
||||
}
|
||||
|
||||
private Response workgroupResponse(Workgroup workgroup) {
|
||||
private Response workgroupResponse(Workgroup workgroup, String region) {
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.set("workgroup", workgroupNode(workgroup));
|
||||
response.set("workgroup", workgroupNode(workgroup, region));
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Members the emulator does not model ({@code workgroupVersion}, {@code patchVersion},
|
||||
* {@code crossAccountVpcs}, the custom domain members and {@code endpoint.vpcEndpoints}) are
|
||||
* {@code crossAccountVpcs} and {@code endpoint.vpcEndpoints}) are
|
||||
* omitted rather than invented; all of them are optional in the API model.
|
||||
*/
|
||||
private ObjectNode workgroupNode(Workgroup workgroup) {
|
||||
private ObjectNode workgroupNode(Workgroup workgroup, String region) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("workgroupName", workgroup.getWorkgroupName());
|
||||
node.put("workgroupId", workgroup.getWorkgroupId());
|
||||
node.put("workgroupArn", workgroup.getWorkgroupArn());
|
||||
node.put("namespaceName", workgroup.getNamespaceName());
|
||||
node.put("status", workgroup.getStatus());
|
||||
customDomains.findForWorkgroup(workgroup.getWorkgroupName(), region)
|
||||
.ifPresent(association -> ServerlessSupport.populateCustomDomain(node, association));
|
||||
if (workgroup.getBaseCapacity() != null) {
|
||||
node.put("baseCapacity", workgroup.getBaseCapacity());
|
||||
}
|
||||
|
||||
+11
@@ -1,8 +1,10 @@
|
||||
package io.github.hectorvent.floci.services.redshiftserverless;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.model.CustomDomainAssociation;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneOffset;
|
||||
@@ -26,6 +28,15 @@ final class ServerlessSupport {
|
||||
private ServerlessSupport() {
|
||||
}
|
||||
|
||||
static void populateCustomDomain(ObjectNode node, CustomDomainAssociation association) {
|
||||
node.put("customDomainCertificateArn", association.getCustomDomainCertificateArn());
|
||||
if (association.getCustomDomainCertificateExpiryTime() != null) {
|
||||
node.put("customDomainCertificateExpiryTime",
|
||||
ISO_8601.format(association.getCustomDomainCertificateExpiryTime()));
|
||||
}
|
||||
node.put("customDomainName", association.getCustomDomainName());
|
||||
}
|
||||
|
||||
static AwsException validation(String message) {
|
||||
return new AwsException("ValidationException", message, 400);
|
||||
}
|
||||
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
package io.github.hectorvent.floci.services.redshiftserverless.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* A custom domain bound to a Redshift Serverless workgroup. The certificate expiry time is read from
|
||||
* ACM when the certificate exists in the emulator.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class CustomDomainAssociation {
|
||||
|
||||
private String workgroupName;
|
||||
private String customDomainName;
|
||||
private String customDomainCertificateArn;
|
||||
private Instant customDomainCertificateExpiryTime;
|
||||
private String ownerId;
|
||||
|
||||
public CustomDomainAssociation() {
|
||||
}
|
||||
|
||||
public CustomDomainAssociation(CustomDomainAssociation other) {
|
||||
this.ownerId = other.ownerId;
|
||||
this.workgroupName = other.workgroupName;
|
||||
this.customDomainName = other.customDomainName;
|
||||
this.customDomainCertificateArn = other.customDomainCertificateArn;
|
||||
this.customDomainCertificateExpiryTime = other.customDomainCertificateExpiryTime;
|
||||
}
|
||||
|
||||
public String getWorkgroupName() {
|
||||
return workgroupName;
|
||||
}
|
||||
|
||||
public void setWorkgroupName(String workgroupName) {
|
||||
this.workgroupName = workgroupName;
|
||||
}
|
||||
|
||||
public String getCustomDomainName() {
|
||||
return customDomainName;
|
||||
}
|
||||
|
||||
public void setCustomDomainName(String customDomainName) {
|
||||
this.customDomainName = customDomainName;
|
||||
}
|
||||
|
||||
public String getCustomDomainCertificateArn() {
|
||||
return customDomainCertificateArn;
|
||||
}
|
||||
|
||||
public void setCustomDomainCertificateArn(String customDomainCertificateArn) {
|
||||
this.customDomainCertificateArn = customDomainCertificateArn;
|
||||
}
|
||||
|
||||
public Instant getCustomDomainCertificateExpiryTime() {
|
||||
return customDomainCertificateExpiryTime;
|
||||
}
|
||||
|
||||
public void setCustomDomainCertificateExpiryTime(Instant customDomainCertificateExpiryTime) {
|
||||
this.customDomainCertificateExpiryTime = customDomainCertificateExpiryTime;
|
||||
}
|
||||
|
||||
public String getOwnerId() {
|
||||
return ownerId;
|
||||
}
|
||||
|
||||
public void setOwnerId(String ownerId) {
|
||||
this.ownerId = ownerId;
|
||||
}
|
||||
}
|
||||
+199
-3
@@ -7,6 +7,8 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.acm.AcmService;
|
||||
import io.github.hectorvent.floci.services.acm.model.Certificate;
|
||||
import io.github.hectorvent.floci.services.redshift.RedshiftIamDbUserResolver;
|
||||
import io.github.hectorvent.floci.services.redshift.model.Endpoint;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
@@ -14,6 +16,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -33,17 +36,22 @@ import static org.mockito.Mockito.when;
|
||||
class RedshiftServerlessAdministrationHandlerTest {
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String ACCOUNT_ID = "123456789012";
|
||||
private static final String CERTIFICATE_ARN =
|
||||
"arn:aws:acm:us-east-1:123456789012:certificate/11111111-2222-3333-4444-555555555555";
|
||||
private static final String REPLACEMENT_CERTIFICATE_ARN =
|
||||
"arn:aws:acm:us-east-1:123456789012:certificate/99999999-2222-3333-4444-555555555555";
|
||||
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
private RedshiftServerlessJsonHandler handler;
|
||||
private RedshiftServerlessService serverlessService;
|
||||
private Certificate testCert;
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
void setUp() {
|
||||
StorageFactory storageFactory = mock(StorageFactory.class);
|
||||
for (String file : List.of("namespaces", "workgroups", "snapshots", "usagelimits", "resourcepolicies",
|
||||
"endpointaccess")) {
|
||||
"endpointaccess", "customdomains")) {
|
||||
when(storageFactory.create(eq("redshiftserverless"), eq("redshiftserverless-" + file + ".json"),
|
||||
any(TypeReference.class))).thenReturn((AccountAwareStorageBackend)
|
||||
AccountAwareStorageBackend.inMemory(ACCOUNT_ID));
|
||||
@@ -65,11 +73,26 @@ class RedshiftServerlessAdministrationHandlerTest {
|
||||
when(config.storage().persistentPath()).thenReturn(System.getProperty("java.io.tmpdir"));
|
||||
serverlessService =
|
||||
new RedshiftServerlessService(storageFactory, regionResolver, endpoints, runtime, config);
|
||||
|
||||
AcmService acmService = mock(AcmService.class);
|
||||
testCert = new Certificate();
|
||||
testCert.setArn(CERTIFICATE_ARN);
|
||||
testCert.setNotAfter(Instant.parse("2028-06-15T12:00:00Z"));
|
||||
when(acmService.describeCertificate(eq(CERTIFICATE_ARN), any())).thenReturn(testCert);
|
||||
Certificate replacementCert = new Certificate();
|
||||
replacementCert.setArn(REPLACEMENT_CERTIFICATE_ARN);
|
||||
replacementCert.setNotAfter(Instant.parse("2029-01-01T00:00:00Z"));
|
||||
when(acmService.describeCertificate(eq(REPLACEMENT_CERTIFICATE_ARN), any())).thenReturn(replacementCert);
|
||||
|
||||
RedshiftServerlessCustomDomainService customDomains =
|
||||
new RedshiftServerlessCustomDomainService(storageFactory, serverlessService, acmService);
|
||||
handler = new RedshiftServerlessJsonHandler(serverlessService, mapper, mock(RedshiftIamDbUserResolver.class),
|
||||
new RedshiftServerlessUsageLimitService(storageFactory, regionResolver, serverlessService),
|
||||
new RedshiftServerlessAdminJsonHandler(mapper,
|
||||
new RedshiftServerlessResourcePolicyService(storageFactory, serverlessService, mapper),
|
||||
new RedshiftServerlessEndpointAccessService(storageFactory, regionResolver, serverlessService)));
|
||||
new RedshiftServerlessEndpointAccessService(storageFactory, regionResolver, serverlessService),
|
||||
customDomains),
|
||||
customDomains);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -265,6 +288,173 @@ class RedshiftServerlessAdministrationHandlerTest {
|
||||
assertFalse(secondPage.has("nextToken"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void customDomainAssociationIsKeyedByWorkgroupAndDomain() {
|
||||
workgroup("domain-ns", "domain-wg");
|
||||
|
||||
JsonNode wgBefore = ok("GetWorkgroup", "{\"workgroupName\":\"domain-wg\"}").get("workgroup");
|
||||
assertFalse(wgBefore.has("customDomainName"));
|
||||
assertFalse(wgBefore.has("customDomainCertificateArn"));
|
||||
assertFalse(wgBefore.has("customDomainCertificateExpiryTime"));
|
||||
|
||||
String request = "{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"db.example.com\","
|
||||
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}";
|
||||
|
||||
JsonNode created = ok("CreateCustomDomainAssociation", request);
|
||||
assertEquals("db.example.com", created.get("customDomainName").textValue());
|
||||
assertEquals("domain-wg", created.get("workgroupName").textValue());
|
||||
assertEquals(CERTIFICATE_ARN, created.get("customDomainCertificateArn").textValue());
|
||||
assertEquals("2028-06-15T12:00:00.000Z", created.get("customDomainCertificateExpiryTime").textValue());
|
||||
|
||||
JsonNode wgWithDomain = ok("GetWorkgroup", "{\"workgroupName\":\"domain-wg\"}").get("workgroup");
|
||||
assertEquals("db.example.com", wgWithDomain.get("customDomainName").textValue());
|
||||
assertEquals(CERTIFICATE_ARN, wgWithDomain.get("customDomainCertificateArn").textValue());
|
||||
assertEquals("2028-06-15T12:00:00.000Z", wgWithDomain.get("customDomainCertificateExpiryTime").textValue());
|
||||
|
||||
JsonNode listWg = ok("ListWorkgroups", "{}").get("workgroups");
|
||||
boolean foundInList = false;
|
||||
for (JsonNode wg : listWg) {
|
||||
if ("domain-wg".equals(wg.get("workgroupName").textValue())) {
|
||||
assertEquals("db.example.com", wg.get("customDomainName").textValue());
|
||||
assertEquals(CERTIFICATE_ARN, wg.get("customDomainCertificateArn").textValue());
|
||||
assertEquals("2028-06-15T12:00:00.000Z", wg.get("customDomainCertificateExpiryTime").textValue());
|
||||
foundInList = true;
|
||||
}
|
||||
}
|
||||
assertTrue(foundInList);
|
||||
|
||||
testCert.setNotAfter(Instant.parse("2030-01-01T00:00:00Z"));
|
||||
JsonNode renewed = ok("GetCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"db.example.com\"}");
|
||||
assertEquals("2030-01-01T00:00:00.000Z", renewed.get("customDomainCertificateExpiryTime").textValue());
|
||||
testCert.setNotAfter(Instant.parse("2028-06-15T12:00:00Z"));
|
||||
|
||||
assertEquals("ConflictException", errorType("CreateCustomDomainAssociation", request));
|
||||
assertEquals("ConflictException", errorType("CreateCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"other.example.com\","
|
||||
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}"));
|
||||
assertTrue(errorMessage("CreateCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"other.example.com\","
|
||||
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}")
|
||||
.contains("already has a custom domain"));
|
||||
|
||||
assertEquals("ValidationException", errorType("CreateCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"-bad\","
|
||||
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}"));
|
||||
assertEquals("ValidationException", errorType("CreateCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"third.example.com\","
|
||||
+ "\"customDomainCertificateArn\":\"not-an-arn\"}"));
|
||||
assertEquals("ResourceNotFoundException", errorType("CreateCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"nope\",\"customDomainName\":\"x.example.com\","
|
||||
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}"));
|
||||
|
||||
String replacement = REPLACEMENT_CERTIFICATE_ARN;
|
||||
JsonNode updated = ok("UpdateCustomDomainAssociation", "{\"workgroupName\":\"domain-wg\","
|
||||
+ "\"customDomainName\":\"db.example.com\",\"customDomainCertificateArn\":\"" + replacement + "\"}");
|
||||
assertEquals(replacement, updated.get("customDomainCertificateArn").textValue());
|
||||
assertEquals("2029-01-01T00:00:00.000Z", updated.get("customDomainCertificateExpiryTime").textValue());
|
||||
|
||||
JsonNode got = ok("GetCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"db.example.com\"}");
|
||||
assertEquals(replacement, got.get("customDomainCertificateArn").textValue());
|
||||
assertEquals("2029-01-01T00:00:00.000Z", got.get("customDomainCertificateExpiryTime").textValue());
|
||||
|
||||
JsonNode wgUpdated = ok("GetWorkgroup", "{\"workgroupName\":\"domain-wg\"}").get("workgroup");
|
||||
assertEquals("db.example.com", wgUpdated.get("customDomainName").textValue());
|
||||
assertEquals(replacement, wgUpdated.get("customDomainCertificateArn").textValue());
|
||||
assertEquals("2029-01-01T00:00:00.000Z", wgUpdated.get("customDomainCertificateExpiryTime").textValue());
|
||||
|
||||
JsonNode associationsList = ok("ListCustomDomainAssociations", "{\"customDomainName\":\"db.example.com\"}")
|
||||
.get("associations");
|
||||
assertEquals(1, associationsList.size());
|
||||
assertEquals("2029-01-01T00:00:00.000Z", associationsList.get(0).get("customDomainCertificateExpiryTime").textValue());
|
||||
assertEquals(0, ok("ListCustomDomainAssociations", "{\"customDomainName\":\"x.example.com\"}")
|
||||
.get("associations").size());
|
||||
assertEquals("ValidationException", errorType("UpdateCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"db.example.com\"}"));
|
||||
assertEquals("ValidationException", errorType("ListCustomDomainAssociations", "{\"maxResults\":0}"));
|
||||
assertEquals("ValidationException", errorType("ListCustomDomainAssociations", "{\"maxResults\":101}"));
|
||||
assertEquals("InvalidPaginationException", errorType("ListCustomDomainAssociations", "{\"nextToken\":\"bad-token\"}"));
|
||||
JsonNode trackToken = ok("ListTracks", "{\"maxResults\":1}");
|
||||
assertEquals("InvalidPaginationException", errorType("ListCustomDomainAssociations",
|
||||
"{\"nextToken\":\"" + trackToken.get("nextToken").textValue() + "\"}"));
|
||||
|
||||
assertEquals(0, ok("DeleteCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"db.example.com\"}").size());
|
||||
assertEquals("ResourceNotFoundException", errorType("GetCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"db.example.com\"}"));
|
||||
|
||||
JsonNode wgAfterDelete = ok("GetWorkgroup", "{\"workgroupName\":\"domain-wg\"}").get("workgroup");
|
||||
assertFalse(wgAfterDelete.has("customDomainName"));
|
||||
assertFalse(wgAfterDelete.has("customDomainCertificateArn"));
|
||||
assertFalse(wgAfterDelete.has("customDomainCertificateExpiryTime"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void customDomainNameCannotBeClaimedByMultipleWorkgroups() {
|
||||
workgroup("domain-ns-a", "domain-wg-a");
|
||||
workgroup("domain-ns-b", "domain-wg-b");
|
||||
ok("CreateCustomDomainAssociation", "{\"workgroupName\":\"domain-wg-a\",\"customDomainName\":\"shared.example.com\","
|
||||
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}");
|
||||
|
||||
assertEquals("ConflictException", errorType("CreateCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"domain-wg-b\",\"customDomainName\":\"shared.example.com\","
|
||||
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}"));
|
||||
assertTrue(errorMessage("CreateCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"domain-wg-b\",\"customDomainName\":\"shared.example.com\","
|
||||
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}")
|
||||
.contains("domain-wg-a"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void customDomainOperationsValidateInputs() {
|
||||
workgroup("val-ns", "val-wg");
|
||||
assertEquals("ValidationException", errorType("GetCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"\",\"customDomainName\":\"db.example.com\"}"));
|
||||
assertEquals("ValidationException", errorType("GetCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"val-wg\",\"customDomainName\":\"\"}"));
|
||||
assertEquals("ValidationException", errorType("GetCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"val-wg\"}"));
|
||||
assertEquals("ValidationException", errorType("GetCustomDomainAssociation",
|
||||
"{\"customDomainName\":\"db.example.com\"}"));
|
||||
|
||||
assertEquals("ValidationException", errorType("DeleteCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"\",\"customDomainName\":\"db.example.com\"}"));
|
||||
assertEquals("ValidationException", errorType("DeleteCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"val-wg\",\"customDomainName\":\"\"}"));
|
||||
assertEquals("ValidationException", errorType("DeleteCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"val-wg\"}"));
|
||||
assertEquals("ValidationException", errorType("DeleteCustomDomainAssociation",
|
||||
"{\"customDomainName\":\"db.example.com\"}"));
|
||||
|
||||
assertEquals("ValidationException", errorType("UpdateCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"\",\"customDomainName\":\"db.example.com\",\"customDomainCertificateArn\":\""
|
||||
+ CERTIFICATE_ARN + "\"}"));
|
||||
assertEquals("ValidationException", errorType("UpdateCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"val-wg\",\"customDomainName\":\"\",\"customDomainCertificateArn\":\""
|
||||
+ CERTIFICATE_ARN + "\"}"));
|
||||
assertEquals("ValidationException", errorType("UpdateCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"val-wg\",\"customDomainName\":\"db.example.com\"}"));
|
||||
assertEquals("ValidationException", errorType("UpdateCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"val-wg\",\"customDomainName\":\"db.example.com\",\"customDomainCertificateArn\":\"\"}"));
|
||||
assertEquals("ValidationException", errorType("UpdateCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"val-wg\",\"customDomainName\":\"-bad\",\"customDomainCertificateArn\":\""
|
||||
+ CERTIFICATE_ARN + "\"}"));
|
||||
assertEquals("ValidationException", errorType("UpdateCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"val-wg\",\"customDomainName\":\"db.example.com\",\"customDomainCertificateArn\":\"not-an-arn\"}"));
|
||||
|
||||
for (String badDomain : List.of("", "-bad.com", "bad-.com", "bad_domain.com", "a".repeat(254) + ".com")) {
|
||||
assertEquals("ValidationException", errorType("CreateCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"val-wg\",\"customDomainName\":\"" + badDomain
|
||||
+ "\",\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}"), badDomain);
|
||||
}
|
||||
for (String badArn : List.of("", "short", "arn:aws:s3:::mybucket", "arn:aws:acm:bad")) {
|
||||
assertEquals("ValidationException", errorType("CreateCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"val-wg\",\"customDomainName\":\"db.example.com\","
|
||||
+ "\"customDomainCertificateArn\":\"" + badArn + "\"}"), badArn);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void tracksAreTheTwoAwsReleaseTracks() {
|
||||
JsonNode track = ok("GetTrack", "{\"trackName\":\"trailing\"}").get("track");
|
||||
@@ -328,18 +518,24 @@ class RedshiftServerlessAdministrationHandlerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void aWorkgroupRecreatedUnderTheSameNameDoesNotInheritEndpoints() {
|
||||
void aWorkgroupRecreatedUnderTheSameNameDoesNotInheritEndpointsOrDomains() {
|
||||
workgroup("recreate-wg-ns", "recreate-wg");
|
||||
ok("CreateEndpointAccess", "{\"endpointName\":\"old-ep\",\"workgroupName\":\"recreate-wg\","
|
||||
+ "\"subnetIds\":[\"subnet-a\"],\"vpcSecurityGroupIds\":[\"sg-1\"]}");
|
||||
ok("CreateCustomDomainAssociation", "{\"workgroupName\":\"recreate-wg\",\"customDomainName\":\"old.example.com\","
|
||||
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}");
|
||||
|
||||
ok("DeleteWorkgroup", "{\"workgroupName\":\"recreate-wg\"}");
|
||||
ok("CreateWorkgroup", "{\"workgroupName\":\"recreate-wg\",\"namespaceName\":\"recreate-wg-ns\"}");
|
||||
|
||||
assertEquals("ResourceNotFoundException", errorType("GetEndpointAccess", "{\"endpointName\":\"old-ep\"}"));
|
||||
assertEquals("ResourceNotFoundException", errorType("GetCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"recreate-wg\",\"customDomainName\":\"old.example.com\"}"));
|
||||
assertEquals(0, ok("ListEndpointAccess", "{\"workgroupName\":\"recreate-wg\"}").get("endpoints").size());
|
||||
ok("CreateEndpointAccess", "{\"endpointName\":\"old-ep\",\"workgroupName\":\"recreate-wg\","
|
||||
+ "\"subnetIds\":[\"subnet-a\"],\"vpcSecurityGroupIds\":[\"sg-1\"]}");
|
||||
ok("CreateCustomDomainAssociation", "{\"workgroupName\":\"recreate-wg\",\"customDomainName\":\"old.example.com\","
|
||||
+ "\"customDomainCertificateArn\":\"" + CERTIFICATE_ARN + "\"}");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+28
@@ -679,6 +679,34 @@ class RedshiftServerlessIntegrationTest {
|
||||
.body("endpoint.endpointStatus", equalTo("DELETING"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void customDomainAssociationRoundTripsOverTheWire() {
|
||||
call("CreateNamespace", "{\"namespaceName\":\"domain-ns\",\"adminUsername\":\"admin\"}").statusCode(200);
|
||||
call("CreateWorkgroup", "{\"workgroupName\":\"domain-wg\",\"namespaceName\":\"domain-ns\"}").statusCode(200);
|
||||
|
||||
String certificate = "arn:aws:acm:us-east-1:000000000000:certificate/11111111-2222-3333-4444-555555555555";
|
||||
call("CreateCustomDomainAssociation", "{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"db.example.com\","
|
||||
+ "\"customDomainCertificateArn\":\"" + certificate + "\"}")
|
||||
.statusCode(200)
|
||||
.body("customDomainName", equalTo("db.example.com"));
|
||||
call("CreateCustomDomainAssociation", "{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"bad_domain\","
|
||||
+ "\"customDomainCertificateArn\":\"" + certificate + "\"}")
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
call("GetWorkgroup", "{\"workgroupName\":\"domain-wg\"}")
|
||||
.statusCode(200)
|
||||
.body("workgroup.customDomainName", equalTo("db.example.com"))
|
||||
.body("workgroup.customDomainCertificateArn", equalTo(certificate));
|
||||
call("ListCustomDomainAssociations", "{\"customDomainName\":\"db.example.com\"}")
|
||||
.statusCode(200)
|
||||
.body("associations", hasSize(1));
|
||||
call("DeleteCustomDomainAssociation",
|
||||
"{\"workgroupName\":\"domain-wg\",\"customDomainName\":\"db.example.com\"}").statusCode(200);
|
||||
call("GetWorkgroup", "{\"workgroupName\":\"domain-wg\"}")
|
||||
.statusCode(200)
|
||||
.body("workgroup.customDomainName", nullValue());
|
||||
}
|
||||
|
||||
private static io.restassured.response.ValidatableResponse call(String action, String body) {
|
||||
return given()
|
||||
.header("X-Amz-Target", TARGET_PREFIX + action)
|
||||
|
||||
+8
-2
@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
import io.github.hectorvent.floci.services.acm.AcmService;
|
||||
import io.github.hectorvent.floci.services.redshift.RedshiftIamDbUserResolver;
|
||||
import io.github.hectorvent.floci.services.redshift.TempCredential;
|
||||
import io.github.hectorvent.floci.services.redshift.model.Endpoint;
|
||||
@@ -86,16 +87,21 @@ class RedshiftServerlessJsonHandlerTest {
|
||||
stubAdministrationStores(storageFactory);
|
||||
RedshiftServerlessService service =
|
||||
new RedshiftServerlessService(storageFactory, regionResolver, endpoints, runtime, config);
|
||||
AcmService acmService = mock(AcmService.class);
|
||||
RedshiftServerlessCustomDomainService customDomains =
|
||||
new RedshiftServerlessCustomDomainService(storageFactory, service, acmService);
|
||||
handler = new RedshiftServerlessJsonHandler(service, mapper, iamDbUserResolver,
|
||||
new RedshiftServerlessUsageLimitService(storageFactory, regionResolver, service),
|
||||
new RedshiftServerlessAdminJsonHandler(mapper,
|
||||
new RedshiftServerlessResourcePolicyService(storageFactory, service, mapper),
|
||||
new RedshiftServerlessEndpointAccessService(storageFactory, regionResolver, service)));
|
||||
new RedshiftServerlessEndpointAccessService(storageFactory, regionResolver, service),
|
||||
customDomains),
|
||||
customDomains);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private static void stubAdministrationStores(StorageFactory storageFactory) {
|
||||
for (String file : List.of("resourcepolicies", "endpointaccess")) {
|
||||
for (String file : List.of("resourcepolicies", "endpointaccess", "customdomains")) {
|
||||
when(storageFactory.create(eq("redshiftserverless"), eq("redshiftserverless-" + file + ".json"),
|
||||
any(TypeReference.class))).thenReturn((AccountAwareStorageBackend)
|
||||
AccountAwareStorageBackend.inMemory(ACCOUNT_ID));
|
||||
|
||||
Reference in new issue
Block a user