mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
feat(redshift-serverless): add endpoint access actions (#5742)
* feat(redshift-serverless): add endpoint access actions Add CreateEndpointAccess, GetEndpointAccess, ListEndpointAccess, UpdateEndpointAccess and DeleteEndpointAccess. Floci creates no VPC endpoint, so an endpoint is recorded and echoed with the workgroup's own address and port. It is tied to the workgroup by the workgroup's generated id, so a workgroup recreated under the same name does not inherit its predecessor's endpoints. Required members and the ownerAccount pattern come from the AWS model through RedshiftServerlessRequestShapes. The endpoint name rule is checked by hand because the model documents it but does not encode it. * fix(redshift-serverless): validate boundary inputs and scope endpoint pagination tokens Validate policy is not null or blank in requireJsonObject before Jackson parsing to avoid unchecked IllegalArgumentException. Validate required endpointName, workgroupName, and subnetIds at create boundary. Validate non-null vpcSecurityGroupIds on endpoint updates. Add namespaced paginate overload with limit validation, scope ListEndpointAccess tokens to endpoint-access, and report pagination errors as ValidationException. * fix(redshift-serverless): allow optional vpcSecurityGroupIds on update and reuse existing pagination overload Allow omitting or passing null vpcSecurityGroupIds in UpdateEndpointAccess to leave existing security groups unchanged. Validate maxResults in the service and call the existing namespaced Pagination.paginate overload instead of adding core overloads. Omit the snapshot policy null check which belongs to #5730.
This commit is contained in:
1 parent
6548c96220
commit
c67a5afbc3
11 files changed
+650
-12
No files matched your search
+33
@@ -9,6 +9,7 @@ import software.amazon.awssdk.services.redshiftdata.model.ExecuteStatementRespon
|
||||
import software.amazon.awssdk.services.redshiftdata.model.StatusString;
|
||||
import software.amazon.awssdk.services.redshiftserverless.RedshiftServerlessClient;
|
||||
import software.amazon.awssdk.services.redshiftserverless.model.ConflictException;
|
||||
import software.amazon.awssdk.services.redshiftserverless.model.EndpointAccess;
|
||||
import software.amazon.awssdk.services.redshiftserverless.model.GetCredentialsResponse;
|
||||
import software.amazon.awssdk.services.redshiftserverless.model.Namespace;
|
||||
import software.amazon.awssdk.services.redshiftserverless.model.NamespaceStatus;
|
||||
@@ -20,6 +21,7 @@ import software.amazon.awssdk.services.redshiftserverless.model.UsageLimit;
|
||||
import software.amazon.awssdk.services.redshiftserverless.model.UsageLimitBreachAction;
|
||||
import software.amazon.awssdk.services.redshiftserverless.model.UsageLimitPeriod;
|
||||
import software.amazon.awssdk.services.redshiftserverless.model.UsageLimitUsageType;
|
||||
import software.amazon.awssdk.services.redshiftserverless.model.ValidationException;
|
||||
import software.amazon.awssdk.services.redshiftserverless.model.Workgroup;
|
||||
import software.amazon.awssdk.services.redshiftserverless.model.WorkgroupStatus;
|
||||
|
||||
@@ -314,6 +316,37 @@ class RedshiftServerlessTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointAccessUsesAwsSdk() {
|
||||
assumeFalse(TestFixtures.isRealAws(), "Creates resources and asserts emulator-local behavior");
|
||||
|
||||
try (RedshiftServerlessClient client = TestFixtures.redshiftServerlessClient()) {
|
||||
String namespaceName = "floci-compat-endpoint-ns";
|
||||
String workgroupName = "floci-compat-endpoint-wg";
|
||||
try {
|
||||
client.createNamespace(request -> request.namespaceName(namespaceName).adminUsername("admin")
|
||||
.adminUserPassword("Secret123!"));
|
||||
client.createWorkgroup(request -> request.workgroupName(workgroupName).namespaceName(namespaceName));
|
||||
|
||||
EndpointAccess endpoint = client.createEndpointAccess(request -> request
|
||||
.endpointName("floci-compat-endpoint-ep").workgroupName(workgroupName)
|
||||
.subnetIds("subnet-a")).endpoint();
|
||||
assertThat(endpoint.endpointStatus()).isEqualTo("ACTIVE");
|
||||
assertThat(endpoint.endpointCreateTime()).isNotNull();
|
||||
assertThat(endpoint.vpcSecurityGroups()).isEmpty();
|
||||
assertThatThrownBy(() -> client.createEndpointAccess(request -> request
|
||||
.endpointName("invalid--endpoint").workgroupName(workgroupName).subnetIds("subnet-a")))
|
||||
.isInstanceOf(ValidationException.class);
|
||||
assertThat(client.listEndpointAccess(request -> request.workgroupName(workgroupName)).endpoints())
|
||||
.extracting(EndpointAccess::endpointName).containsExactly("floci-compat-endpoint-ep");
|
||||
client.deleteEndpointAccess(request -> request.endpointName("floci-compat-endpoint-ep"));
|
||||
} 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 | 36 |
|
||||
| [Redshift Serverless](redshift-serverless.md) | `POST /` + `X-Amz-Target: RedshiftServerless.*` | JSON 1.1 | 41 |
|
||||
| [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 |
|
||||
|
||||
@@ -48,6 +48,11 @@ For the upstream API shape, see the [Amazon Redshift Serverless API Reference](h
|
||||
| `GetReservation` | Always `ResourceNotFoundException`, as no reservation exists |
|
||||
| `GetReservationOffering` | Always `ResourceNotFoundException`, as no offering exists |
|
||||
| `CreateReservation` | Validates `capacity` and `offeringId`, then answers `ResourceNotFoundException` because no offering exists |
|
||||
| `CreateEndpointAccess` | Record a managed VPC endpoint for a workgroup; `address` and `port` are the workgroup's own |
|
||||
| `GetEndpointAccess` | Return an endpoint by `endpointName` |
|
||||
| `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` |
|
||||
<!-- floci:actions:end -->
|
||||
|
||||
Namespace and workgroup state is account and Region scoped and persisted through `StorageFactory`.
|
||||
@@ -123,3 +128,4 @@ aws redshift-serverless delete-namespace --namespace-name analytics
|
||||
- **Snapshots dump the database.** While the namespace's workgroup is running, `CreateSnapshot` runs `pg_dump` on its container and stores the dump under `<persistent-path>/redshift-serverless-dumps/<account>/<region>/`. `RestoreFromSnapshot` drops every user schema (the catalog bootstrap schema excepted) and replays the dump with `psql`, stopping at the first failing statement, so rows written after the snapshot are gone. The current contents are dumped first and put back if the replay fails, and a restore whose recorded dump file has gone missing fails instead of reporting success. A snapshot taken with no running workgroup is metadata only, and restoring it leaves the database untouched. `DeleteSnapshot` removes the dump. Snapshot ARNs use the snapshot name as their id, snapshot names are 3-255 lowercase letters, digits and hyphens, and `retentionPeriod` is `-1` (indefinite, the default) or 1 to 3653 days. Snapshots are taggable by ARN. `snapshotName` and `snapshotArn` cannot be sent together. Floci's own `floci_internal` bootstrap schema, which feeds the `svv_external_*` views from the Glue catalog, is left out of both the dump and the reset, matching AWS where the Glue catalog is outside a namespace snapshot, so a client schema with that exact name is not captured. A real snapshot expires after its retention period; Floci reports `snapshotRemainingDays` but does not expire snapshots.
|
||||
- **`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.
|
||||
+78
-4
@@ -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.EndpointAccess;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.model.ResourcePolicy;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
@@ -26,13 +27,16 @@ public class RedshiftServerlessAdminJsonHandler {
|
||||
private static final List<String> TRACK_NAMES = RedshiftServerlessService.TRACK_NAMES;
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
private final RedshiftServerlessEndpointAccessService endpointAccess;
|
||||
private final RedshiftServerlessResourcePolicyService resourcePolicies;
|
||||
|
||||
@Inject
|
||||
public RedshiftServerlessAdminJsonHandler(ObjectMapper objectMapper,
|
||||
RedshiftServerlessResourcePolicyService resourcePolicies) {
|
||||
RedshiftServerlessResourcePolicyService resourcePolicies,
|
||||
RedshiftServerlessEndpointAccessService endpointAccess) {
|
||||
this.objectMapper = objectMapper;
|
||||
this.resourcePolicies = resourcePolicies;
|
||||
this.endpointAccess = endpointAccess;
|
||||
}
|
||||
|
||||
Supplier<Response> operation(String action, JsonNode request, String region) {
|
||||
@@ -54,6 +58,19 @@ public class RedshiftServerlessAdminJsonHandler {
|
||||
case "GetReservation" -> () -> getReservation(request);
|
||||
case "GetReservationOffering" -> () -> getReservationOffering(request);
|
||||
case "CreateReservation" -> () -> createReservation(request);
|
||||
case "CreateEndpointAccess" -> () -> endpointResponse(endpointAccess.createEndpointAccess(
|
||||
ServerlessSupport.text(request, "endpointName"), ServerlessSupport.text(request, "workgroupName"),
|
||||
ServerlessSupport.stringList(request, "subnetIds"),
|
||||
ServerlessSupport.stringList(request, "vpcSecurityGroupIds"),
|
||||
ServerlessSupport.text(request, "ownerAccount"), region));
|
||||
case "GetEndpointAccess" -> () -> endpointResponse(endpointAccess.getEndpointAccess(
|
||||
ServerlessSupport.text(request, "endpointName"), region));
|
||||
case "ListEndpointAccess" -> () -> listEndpoints(request, region);
|
||||
case "UpdateEndpointAccess" -> () -> endpointResponse(endpointAccess.updateEndpointAccess(
|
||||
ServerlessSupport.text(request, "endpointName"),
|
||||
ServerlessSupport.stringList(request, "vpcSecurityGroupIds"), region));
|
||||
case "DeleteEndpointAccess" -> () -> endpointResponse(endpointAccess.deleteEndpointAccess(
|
||||
ServerlessSupport.text(request, "endpointName"), region));
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
@@ -86,6 +103,57 @@ public class RedshiftServerlessAdminJsonHandler {
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
// ── Endpoint access ────────────────────────────────────────────────────
|
||||
|
||||
private Response listEndpoints(JsonNode request, String region) {
|
||||
PaginatedResult<EndpointAccess> page = endpointAccess.listEndpointAccess(
|
||||
ServerlessSupport.text(request, "workgroupName"), ServerlessSupport.text(request, "vpcId"),
|
||||
ServerlessSupport.text(request, "ownerAccount"), region, ServerlessSupport.maxResults(request),
|
||||
ServerlessSupport.text(request, "nextToken"));
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode items = response.putArray("endpoints");
|
||||
page.items().forEach(endpoint -> items.add(endpointNode(endpoint)));
|
||||
putNextToken(response, page);
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response endpointResponse(EndpointAccess endpoint) {
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.set("endpoint", endpointNode(endpoint));
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
/** No VPC is modelled, so {@code vpcEndpoint.vpcId} is left out rather than invented. */
|
||||
private ObjectNode endpointNode(EndpointAccess endpoint) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
if (endpoint.getAddress() != null) {
|
||||
node.put("address", endpoint.getAddress());
|
||||
}
|
||||
node.put("endpointArn", endpoint.getEndpointArn());
|
||||
node.put("endpointCreateTime", ServerlessSupport.ISO_8601.format(endpoint.getCreateTime()));
|
||||
node.put("endpointName", endpoint.getEndpointName());
|
||||
node.put("endpointStatus", endpoint.getStatus());
|
||||
node.put("port", endpoint.getPort());
|
||||
ArrayNode subnets = node.putArray("subnetIds");
|
||||
endpoint.getSubnetIds().forEach(subnets::add);
|
||||
ObjectNode vpcEndpoint = node.putObject("vpcEndpoint");
|
||||
vpcEndpoint.put("vpcEndpointId", endpoint.getVpcEndpointId());
|
||||
ArrayNode interfaces = vpcEndpoint.putArray("networkInterfaces");
|
||||
for (int i = 0; i < endpoint.getSubnetIds().size() && i < endpoint.getNetworkInterfaceIds().size(); i++) {
|
||||
ObjectNode networkInterface = interfaces.addObject();
|
||||
networkInterface.put("networkInterfaceId", endpoint.getNetworkInterfaceIds().get(i));
|
||||
networkInterface.put("subnetId", endpoint.getSubnetIds().get(i));
|
||||
}
|
||||
ArrayNode groups = node.putArray("vpcSecurityGroups");
|
||||
for (String groupId : endpoint.getVpcSecurityGroupIds()) {
|
||||
ObjectNode group = groups.addObject();
|
||||
group.put("vpcSecurityGroupId", groupId);
|
||||
group.put("status", "active");
|
||||
}
|
||||
node.put("workgroupName", endpoint.getWorkgroupName());
|
||||
return node;
|
||||
}
|
||||
|
||||
// ── Tracks, managed workgroups and reservations ────────────────────────
|
||||
|
||||
/**
|
||||
@@ -108,9 +176,7 @@ public class RedshiftServerlessAdminJsonHandler {
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode items = response.putArray("tracks");
|
||||
page.items().forEach(name -> items.add(trackNode(name)));
|
||||
if (page.nextToken() != null) {
|
||||
response.put("nextToken", page.nextToken());
|
||||
}
|
||||
putNextToken(response, page);
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
@@ -132,4 +198,12 @@ public class RedshiftServerlessAdminJsonHandler {
|
||||
response.putArray(listName);
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
// ── Shared ─────────────────────────────────────────────────────────────
|
||||
|
||||
private static void putNextToken(ObjectNode response, PaginatedResult<?> page) {
|
||||
if (page.nextToken() != null) {
|
||||
response.put("nextToken", page.nextToken());
|
||||
}
|
||||
}
|
||||
}
|
||||
+190
@@ -0,0 +1,190 @@
|
||||
package io.github.hectorvent.floci.services.redshiftserverless;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
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.redshiftserverless.model.EndpointAccess;
|
||||
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.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Redshift Serverless endpoint access (managed VPC endpoints). An endpoint is recorded and echoed:
|
||||
* Floci creates no VPC endpoint, so its {@code address} and {@code port} are the workgroup's own,
|
||||
* which is where a client can actually connect.
|
||||
*
|
||||
* <p>An endpoint 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 endpoint otherwise.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class RedshiftServerlessEndpointAccessService implements Resettable {
|
||||
|
||||
private static final Pattern ENDPOINT_NAME = Pattern.compile("^[A-Za-z][A-Za-z0-9-]{0,29}$");
|
||||
private static final int PAGE_SIZE = 100;
|
||||
|
||||
private final AccountAwareStorageBackend<EndpointAccess> endpoints;
|
||||
private final RegionResolver regionResolver;
|
||||
private final RedshiftServerlessService serverless;
|
||||
|
||||
@Inject
|
||||
public RedshiftServerlessEndpointAccessService(StorageFactory storageFactory, RegionResolver regionResolver,
|
||||
RedshiftServerlessService serverless) {
|
||||
this.endpoints = storageFactory.create("redshiftserverless", "redshiftserverless-endpointaccess.json",
|
||||
new TypeReference<Map<String, EndpointAccess>>() {});
|
||||
this.regionResolver = regionResolver;
|
||||
this.serverless = serverless;
|
||||
}
|
||||
|
||||
public synchronized EndpointAccess createEndpointAccess(String endpointName, String workgroupName,
|
||||
List<String> subnetIds,
|
||||
List<String> vpcSecurityGroupIds,
|
||||
String ownerAccount, String region) {
|
||||
if (endpointName == null || !ENDPOINT_NAME.matcher(endpointName).matches()
|
||||
|| endpointName.contains("--") || endpointName.endsWith("-")) {
|
||||
throw ServerlessSupport.validation("endpointName must be 1 to 30 letters, digits or hyphens, "
|
||||
+ "start with a letter, and contain no consecutive or trailing hyphens.");
|
||||
}
|
||||
if (workgroupName == null || workgroupName.isBlank()) {
|
||||
throw ServerlessSupport.validation("workgroupName must not be blank.");
|
||||
}
|
||||
if (subnetIds == null || subnetIds.isEmpty()) {
|
||||
throw ServerlessSupport.validation("subnetIds must not be empty.");
|
||||
}
|
||||
Workgroup workgroup = serverless.findWorkgroup(workgroupName, region)
|
||||
.filter(found -> ownerAccount == null || ownerAccount.equals(regionResolver.getAccountId()))
|
||||
.orElseThrow(() -> ServerlessSupport.notFound("The workgroup " + workgroupName + " was not found."));
|
||||
if (live(region).stream().anyMatch(existing -> existing.getEndpointName().equals(endpointName))) {
|
||||
throw ServerlessSupport.conflict("The endpoint " + endpointName + " already exists.");
|
||||
}
|
||||
|
||||
EndpointAccess endpoint = new EndpointAccess();
|
||||
endpoint.setEndpointName(endpointName);
|
||||
endpoint.setEndpointArn(regionResolver.buildArn("redshift-serverless", region,
|
||||
"managedvpcendpoint/" + UUID.randomUUID()));
|
||||
endpoint.setWorkgroupName(workgroupName);
|
||||
endpoint.setOwnerId(workgroup.getWorkgroupId());
|
||||
endpoint.setStatus("ACTIVE");
|
||||
endpoint.setCreateTime(Instant.now());
|
||||
refreshConnection(endpoint, workgroup);
|
||||
endpoint.setSubnetIds(subnetIds);
|
||||
endpoint.setNetworkInterfaceIds(networkInterfaceIdsFor(subnetIds));
|
||||
endpoint.setVpcSecurityGroupIds(vpcSecurityGroupIds);
|
||||
endpoint.setVpcEndpointId("vpce-" + hex(17));
|
||||
endpoints.put(storageKey(region, endpointName), endpoint);
|
||||
return new EndpointAccess(endpoint);
|
||||
}
|
||||
|
||||
public synchronized EndpointAccess getEndpointAccess(String endpointName, String region) {
|
||||
return withCurrentConnection(require(endpointName, region), region);
|
||||
}
|
||||
|
||||
public synchronized PaginatedResult<EndpointAccess> listEndpointAccess(String workgroupName, String vpcId,
|
||||
String ownerAccount, String region,
|
||||
Integer maxResults, String nextToken) {
|
||||
// No VPC is modelled, so an endpoint never belongs to a requested VPC.
|
||||
boolean wrongVpc = vpcId != null && !vpcId.isBlank();
|
||||
boolean wrongOwner = ownerAccount != null && !ownerAccount.equals(regionResolver.getAccountId());
|
||||
List<EndpointAccess> matching = live(region).stream()
|
||||
.filter(endpoint -> !wrongVpc && !wrongOwner)
|
||||
.filter(endpoint -> workgroupName == null || workgroupName.equals(endpoint.getWorkgroupName()))
|
||||
.sorted(Comparator.comparing(EndpointAccess::getEndpointName))
|
||||
.map(endpoint -> withCurrentConnection(endpoint, region))
|
||||
.toList();
|
||||
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;
|
||||
return Pagination.paginate(matching, EndpointAccess::getEndpointName, limit, nextToken,
|
||||
"endpoint-access", token -> ServerlessSupport.validation("Invalid nextToken."));
|
||||
}
|
||||
|
||||
/** Replaces the endpoint's security groups, the only member AWS lets an update change. */
|
||||
public synchronized EndpointAccess updateEndpointAccess(String endpointName, List<String> vpcSecurityGroupIds,
|
||||
String region) {
|
||||
EndpointAccess updated = new EndpointAccess(require(endpointName, region));
|
||||
if (vpcSecurityGroupIds != null) {
|
||||
updated.setVpcSecurityGroupIds(vpcSecurityGroupIds);
|
||||
endpoints.put(storageKey(region, endpointName), updated);
|
||||
}
|
||||
return withCurrentConnection(updated, region);
|
||||
}
|
||||
|
||||
public synchronized EndpointAccess deleteEndpointAccess(String endpointName, String region) {
|
||||
EndpointAccess existing = withCurrentConnection(require(endpointName, region), region);
|
||||
endpoints.delete(storageKey(region, endpointName));
|
||||
existing.setStatus("DELETING");
|
||||
return existing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear() {
|
||||
endpoints.clear();
|
||||
}
|
||||
|
||||
private EndpointAccess require(String endpointName, String region) {
|
||||
EndpointAccess endpoint = endpoints.get(storageKey(region, endpointName)).orElse(null);
|
||||
if (endpoint != null && !isOnSameWorkgroup(endpoint, region)) {
|
||||
endpoints.delete(storageKey(region, endpointName));
|
||||
endpoint = null;
|
||||
}
|
||||
if (endpoint == null) {
|
||||
throw ServerlessSupport.notFound("The endpoint " + endpointName + " was not found.");
|
||||
}
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
/** The region's endpoints whose workgroup is still there; any other is deleted as it is found. */
|
||||
private List<EndpointAccess> live(String region) {
|
||||
return ServerlessSupport.live(endpoints, region,
|
||||
endpoint -> isOnSameWorkgroup(endpoint, region),
|
||||
endpoint -> storageKey(region, endpoint.getEndpointName()));
|
||||
}
|
||||
|
||||
/** A workgroup recreated under the same name has a new id, so it never inherits its predecessor's endpoints. */
|
||||
private boolean isOnSameWorkgroup(EndpointAccess endpoint, String region) {
|
||||
return serverless.findWorkgroup(endpoint.getWorkgroupName(), region)
|
||||
.map(workgroup -> Objects.equals(workgroup.getWorkgroupId(), endpoint.getOwnerId()))
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
private EndpointAccess withCurrentConnection(EndpointAccess endpoint, String region) {
|
||||
EndpointAccess response = new EndpointAccess(endpoint);
|
||||
serverless.findWorkgroup(endpoint.getWorkgroupName(), region)
|
||||
.ifPresent(workgroup -> refreshConnection(response, workgroup));
|
||||
return response;
|
||||
}
|
||||
|
||||
private static void refreshConnection(EndpointAccess endpoint, Workgroup workgroup) {
|
||||
endpoint.setAddress(workgroup.getEndpoint() == null ? null : workgroup.getEndpoint().getAddress());
|
||||
endpoint.setPort(workgroup.getEndpoint() == null ? workgroup.getPort() : workgroup.getEndpoint().getPort());
|
||||
}
|
||||
|
||||
private static List<String> networkInterfaceIdsFor(List<String> subnetIds) {
|
||||
List<String> ids = new ArrayList<>();
|
||||
for (int i = 0; i < subnetIds.size(); i++) {
|
||||
ids.add("eni-" + hex(17));
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
private static String hex(int length) {
|
||||
return UUID.randomUUID().toString().replace("-", "").substring(0, length);
|
||||
}
|
||||
|
||||
private static String storageKey(String region, String endpointName) {
|
||||
return region + "::" + endpointName;
|
||||
}
|
||||
}
|
||||
+5
@@ -475,6 +475,11 @@ public class RedshiftServerlessService implements Resettable {
|
||||
return snapshotArn.substring(prefix.length());
|
||||
}
|
||||
|
||||
/** The workgroup called {@code workgroupName} in {@code region}, empty when there is none. */
|
||||
public Optional<Workgroup> findWorkgroup(String workgroupName, String region) {
|
||||
return workgroupName == null ? Optional.empty() : workgroups.get(storageKey(region, workgroupName));
|
||||
}
|
||||
|
||||
/** The snapshot called {@code snapshotName} in {@code region}, empty when there is none. */
|
||||
public Optional<RedshiftServerlessSnapshot> findSnapshot(String snapshotName, String region) {
|
||||
return snapshotName == null ? Optional.empty() : snapshots.get(storageKey(region, snapshotName));
|
||||
|
||||
+17
@@ -2,12 +2,15 @@ package io.github.hectorvent.floci.services.redshiftserverless;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Request parsing and error helpers shared by the Redshift Serverless administration handlers and
|
||||
@@ -118,4 +121,18 @@ final class ServerlessSupport {
|
||||
static Integer maxResults(JsonNode request) {
|
||||
return integer(request, "maxResults");
|
||||
}
|
||||
|
||||
/** Return the Region's surviving records and remove records whose original parent is gone. */
|
||||
static <T> List<T> live(AccountAwareStorageBackend<T> storage, String region,
|
||||
Predicate<T> hasParent, Function<T, String> storageKey) {
|
||||
List<T> alive = new ArrayList<>();
|
||||
for (T record : storage.scan(key -> key.startsWith(region + "::"))) {
|
||||
if (hasParent.test(record)) {
|
||||
alive.add(record);
|
||||
} else {
|
||||
storage.delete(storageKey.apply(record));
|
||||
}
|
||||
}
|
||||
return alive;
|
||||
}
|
||||
}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
package io.github.hectorvent.floci.services.redshiftserverless.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A Redshift Serverless managed VPC endpoint. Floci records it and reports the workgroup's own
|
||||
* endpoint as its address; it creates no network interface in any VPC.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class EndpointAccess {
|
||||
|
||||
private String endpointName;
|
||||
private String endpointArn;
|
||||
private String workgroupName;
|
||||
private String status;
|
||||
private Instant createTime;
|
||||
private String address;
|
||||
private int port;
|
||||
private List<String> subnetIds = new ArrayList<>();
|
||||
private List<String> networkInterfaceIds = new ArrayList<>();
|
||||
private List<String> vpcSecurityGroupIds = new ArrayList<>();
|
||||
private String vpcEndpointId;
|
||||
private String ownerId;
|
||||
|
||||
public EndpointAccess() {
|
||||
}
|
||||
|
||||
public EndpointAccess(EndpointAccess other) {
|
||||
this.ownerId = other.ownerId;
|
||||
this.endpointName = other.endpointName;
|
||||
this.endpointArn = other.endpointArn;
|
||||
this.workgroupName = other.workgroupName;
|
||||
this.status = other.status;
|
||||
this.createTime = other.createTime;
|
||||
this.address = other.address;
|
||||
this.port = other.port;
|
||||
this.subnetIds = new ArrayList<>(other.subnetIds);
|
||||
this.networkInterfaceIds = new ArrayList<>(other.networkInterfaceIds);
|
||||
this.vpcSecurityGroupIds = new ArrayList<>(other.vpcSecurityGroupIds);
|
||||
this.vpcEndpointId = other.vpcEndpointId;
|
||||
}
|
||||
|
||||
public String getEndpointName() {
|
||||
return endpointName;
|
||||
}
|
||||
|
||||
public void setEndpointName(String endpointName) {
|
||||
this.endpointName = endpointName;
|
||||
}
|
||||
|
||||
public String getEndpointArn() {
|
||||
return endpointArn;
|
||||
}
|
||||
|
||||
public void setEndpointArn(String endpointArn) {
|
||||
this.endpointArn = endpointArn;
|
||||
}
|
||||
|
||||
public String getWorkgroupName() {
|
||||
return workgroupName;
|
||||
}
|
||||
|
||||
public void setWorkgroupName(String workgroupName) {
|
||||
this.workgroupName = workgroupName;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public Instant getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Instant createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public List<String> getSubnetIds() {
|
||||
return subnetIds;
|
||||
}
|
||||
|
||||
public void setSubnetIds(List<String> subnetIds) {
|
||||
this.subnetIds = subnetIds == null ? new ArrayList<>() : new ArrayList<>(subnetIds);
|
||||
}
|
||||
|
||||
public List<String> getNetworkInterfaceIds() {
|
||||
return networkInterfaceIds;
|
||||
}
|
||||
|
||||
public void setNetworkInterfaceIds(List<String> networkInterfaceIds) {
|
||||
this.networkInterfaceIds = networkInterfaceIds == null ? new ArrayList<>() : new ArrayList<>(networkInterfaceIds);
|
||||
}
|
||||
|
||||
public List<String> getVpcSecurityGroupIds() {
|
||||
return vpcSecurityGroupIds;
|
||||
}
|
||||
|
||||
public void setVpcSecurityGroupIds(List<String> vpcSecurityGroupIds) {
|
||||
this.vpcSecurityGroupIds = vpcSecurityGroupIds == null ? new ArrayList<>() : new ArrayList<>(vpcSecurityGroupIds);
|
||||
}
|
||||
|
||||
public String getVpcEndpointId() {
|
||||
return vpcEndpointId;
|
||||
}
|
||||
|
||||
public void setVpcEndpointId(String vpcEndpointId) {
|
||||
this.vpcEndpointId = vpcEndpointId;
|
||||
}
|
||||
|
||||
public String getOwnerId() {
|
||||
return ownerId;
|
||||
}
|
||||
|
||||
public void setOwnerId(String ownerId) {
|
||||
this.ownerId = ownerId;
|
||||
}
|
||||
}
|
||||
+145
-5
@@ -14,7 +14,6 @@ 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;
|
||||
@@ -34,8 +33,6 @@ 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 final ObjectMapper mapper = new ObjectMapper();
|
||||
private RedshiftServerlessJsonHandler handler;
|
||||
@@ -46,7 +43,7 @@ class RedshiftServerlessAdministrationHandlerTest {
|
||||
void setUp() {
|
||||
StorageFactory storageFactory = mock(StorageFactory.class);
|
||||
for (String file : List.of("namespaces", "workgroups", "snapshots", "usagelimits", "resourcepolicies",
|
||||
"endpointaccess", "snapshotcopyconfigurations", "scheduledactions", "customdomains")) {
|
||||
"endpointaccess")) {
|
||||
when(storageFactory.create(eq("redshiftserverless"), eq("redshiftserverless-" + file + ".json"),
|
||||
any(TypeReference.class))).thenReturn((AccountAwareStorageBackend)
|
||||
AccountAwareStorageBackend.inMemory(ACCOUNT_ID));
|
||||
@@ -71,7 +68,8 @@ class RedshiftServerlessAdministrationHandlerTest {
|
||||
handler = new RedshiftServerlessJsonHandler(serverlessService, mapper, mock(RedshiftIamDbUserResolver.class),
|
||||
new RedshiftServerlessUsageLimitService(storageFactory, regionResolver, serverlessService),
|
||||
new RedshiftServerlessAdminJsonHandler(mapper,
|
||||
new RedshiftServerlessResourcePolicyService(storageFactory, serverlessService, mapper)));
|
||||
new RedshiftServerlessResourcePolicyService(storageFactory, serverlessService, mapper),
|
||||
new RedshiftServerlessEndpointAccessService(storageFactory, regionResolver, serverlessService)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,6 +138,133 @@ class RedshiftServerlessAdministrationHandlerTest {
|
||||
errorType("GetResourcePolicy", "{\"resourceArn\":\"" + snapshotArn + "\"}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointAccessFollowsTheApiModelAndTheWorkgroupLifecycle() {
|
||||
workgroup("ep-ns", "ep-wg");
|
||||
|
||||
JsonNode created = ok("CreateEndpointAccess", "{\"endpointName\":\"ep-one\",\"workgroupName\":\"ep-wg\","
|
||||
+ "\"subnetIds\":[\"subnet-a\",\"subnet-b\"],\"vpcSecurityGroupIds\":[\"sg-1\"]}").get("endpoint");
|
||||
assertEquals("ep-one", created.get("endpointName").textValue());
|
||||
assertEquals("ep-wg", created.get("workgroupName").textValue());
|
||||
assertEquals("ACTIVE", created.get("endpointStatus").textValue());
|
||||
assertEquals("localhost", created.get("address").textValue());
|
||||
assertEquals(7100, created.get("port").intValue());
|
||||
assertTrue(created.get("endpointCreateTime").textValue().matches("\\d{4}-\\d{2}-\\d{2}T.*Z"));
|
||||
assertTrue(created.get("endpointArn").textValue().contains(":managedvpcendpoint/"));
|
||||
assertEquals(2, created.get("subnetIds").size());
|
||||
assertEquals(2, created.get("vpcEndpoint").get("networkInterfaces").size());
|
||||
assertEquals("subnet-a", created.get("vpcEndpoint").get("networkInterfaces").get(0).get("subnetId").textValue());
|
||||
assertEquals("sg-1", created.get("vpcSecurityGroups").get(0).get("vpcSecurityGroupId").textValue());
|
||||
assertEquals("active", created.get("vpcSecurityGroups").get(0).get("status").textValue());
|
||||
|
||||
assertEquals("ConflictException", errorType("CreateEndpointAccess",
|
||||
"{\"endpointName\":\"ep-one\",\"workgroupName\":\"ep-wg\",\"subnetIds\":[\"subnet-a\"],"
|
||||
+ "\"vpcSecurityGroupIds\":[\"sg-1\"]}"));
|
||||
assertEquals("ValidationException", errorType("CreateEndpointAccess",
|
||||
"{\"endpointName\":\"ep-two\",\"workgroupName\":\"ep-wg\"}"));
|
||||
assertEquals("ValidationException", errorType("CreateEndpointAccess",
|
||||
"{\"endpointName\":\"ep-two\",\"workgroupName\":\"ep-wg\",\"subnetIds\":[]}"));
|
||||
assertEquals("ValidationException", errorType("CreateEndpointAccess",
|
||||
"{\"endpointName\":\"ep-two\",\"workgroupName\":\"ep-wg\",\"subnetIds\":null}"));
|
||||
assertEquals("ValidationException", errorType("CreateEndpointAccess",
|
||||
"{\"endpointName\":\"ep-two\",\"workgroupName\":\"\",\"subnetIds\":[\"subnet-a\"]}"));
|
||||
assertEquals("ResourceNotFoundException", errorType("CreateEndpointAccess",
|
||||
"{\"endpointName\":\"ep-two\",\"workgroupName\":\"nope\",\"subnetIds\":[\"subnet-a\"],"
|
||||
+ "\"vpcSecurityGroupIds\":[\"sg-1\"]}"));
|
||||
|
||||
JsonNode noSgUpdate = ok("UpdateEndpointAccess",
|
||||
"{\"endpointName\":\"ep-one\"}").get("endpoint");
|
||||
assertEquals(1, noSgUpdate.get("vpcSecurityGroups").size());
|
||||
assertEquals("sg-1", noSgUpdate.get("vpcSecurityGroups").get(0).get("vpcSecurityGroupId").textValue());
|
||||
|
||||
JsonNode nullSgUpdate = ok("UpdateEndpointAccess",
|
||||
"{\"endpointName\":\"ep-one\",\"vpcSecurityGroupIds\":null}").get("endpoint");
|
||||
assertEquals(1, nullSgUpdate.get("vpcSecurityGroups").size());
|
||||
assertEquals("sg-1", nullSgUpdate.get("vpcSecurityGroups").get(0).get("vpcSecurityGroupId").textValue());
|
||||
|
||||
JsonNode updated = ok("UpdateEndpointAccess",
|
||||
"{\"endpointName\":\"ep-one\",\"vpcSecurityGroupIds\":[\"sg-2\",\"sg-3\"]}").get("endpoint");
|
||||
assertEquals(2, updated.get("vpcSecurityGroups").size());
|
||||
assertEquals(1, ok("ListEndpointAccess", "{\"workgroupName\":\"ep-wg\"}").get("endpoints").size());
|
||||
assertEquals(0, ok("ListEndpointAccess", "{\"workgroupName\":\"other\"}").get("endpoints").size());
|
||||
assertEquals(0, ok("ListEndpointAccess", "{\"vpcId\":\"vpc-1\"}").get("endpoints").size());
|
||||
assertEquals("ValidationException", errorType("ListEndpointAccess", "{\"maxResults\":0}"));
|
||||
assertEquals("ValidationException", errorType("ListEndpointAccess", "{\"maxResults\":101}"));
|
||||
assertEquals("ValidationException", errorType("ListEndpointAccess", "{\"nextToken\":\"bad-token\"}"));
|
||||
JsonNode trackTokenPage = ok("ListTracks", "{\"maxResults\":1}");
|
||||
assertEquals("ValidationException", errorType("ListEndpointAccess",
|
||||
"{\"nextToken\":\"" + trackTokenPage.get("nextToken").textValue() + "\"}"));
|
||||
|
||||
assertEquals("DELETING", ok("DeleteEndpointAccess", "{\"endpointName\":\"ep-one\"}")
|
||||
.get("endpoint").get("endpointStatus").textValue());
|
||||
assertEquals("ResourceNotFoundException", errorType("GetEndpointAccess", "{\"endpointName\":\"ep-one\"}"));
|
||||
|
||||
ok("CreateEndpointAccess", "{\"endpointName\":\"ep-gone\",\"workgroupName\":\"ep-wg\","
|
||||
+ "\"subnetIds\":[\"subnet-a\"],\"vpcSecurityGroupIds\":[\"sg-1\"]}");
|
||||
serverlessService.findWorkgroup("ep-wg", REGION).orElseThrow()
|
||||
.setEndpoint(new Endpoint("192.168.1.10", 8200));
|
||||
JsonNode refreshed = ok("GetEndpointAccess", "{\"endpointName\":\"ep-gone\"}").get("endpoint");
|
||||
assertEquals("192.168.1.10", refreshed.get("address").textValue());
|
||||
assertEquals(8200, refreshed.get("port").intValue());
|
||||
JsonNode refreshedList = ok("ListEndpointAccess", "{\"workgroupName\":\"ep-wg\"}").get("endpoints");
|
||||
assertEquals("192.168.1.10", refreshedList.get(0).get("address").textValue());
|
||||
assertEquals(8200, refreshedList.get(0).get("port").intValue());
|
||||
|
||||
ok("DeleteWorkgroup", "{\"workgroupName\":\"ep-wg\"}");
|
||||
assertEquals("ResourceNotFoundException", errorType("GetEndpointAccess", "{\"endpointName\":\"ep-gone\"}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointSecurityGroupsAreOptional() {
|
||||
workgroup("optional-ns", "optional-wg");
|
||||
JsonNode omitted = ok("CreateEndpointAccess",
|
||||
"{\"endpointName\":\"optional\",\"workgroupName\":\"optional-wg\",\"subnetIds\":[\"subnet-a\"]}")
|
||||
.get("endpoint");
|
||||
assertEquals(0, omitted.get("vpcSecurityGroups").size());
|
||||
JsonNode empty = ok("CreateEndpointAccess",
|
||||
"{\"endpointName\":\"empty\",\"workgroupName\":\"optional-wg\",\"subnetIds\":[\"subnet-a\"],"
|
||||
+ "\"vpcSecurityGroupIds\":[]}").get("endpoint");
|
||||
assertEquals(0, empty.get("vpcSecurityGroups").size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointNamesFollowAwsConstraints() {
|
||||
workgroup("names-ns", "names-wg");
|
||||
for (String name : List.of("", "1endpoint", "-endpoint", "end--point", "endpoint-", "end_point",
|
||||
"a".repeat(31))) {
|
||||
assertEquals("ValidationException", errorType("CreateEndpointAccess",
|
||||
"{\"endpointName\":\"" + name + "\",\"workgroupName\":\"names-wg\","
|
||||
+ "\"subnetIds\":[\"subnet-a\"],\"vpcSecurityGroupIds\":[\"sg-1\"]}"), name);
|
||||
}
|
||||
for (String name : List.of("A", "Endpoint-123", "a".repeat(30))) {
|
||||
assertEquals(name, ok("CreateEndpointAccess",
|
||||
"{\"endpointName\":\"" + name + "\",\"workgroupName\":\"names-wg\","
|
||||
+ "\"subnetIds\":[\"subnet-a\"],\"vpcSecurityGroupIds\":[\"sg-1\"]}")
|
||||
.get("endpoint").get("endpointName").textValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointAccessPagingWalksPagesAndRefusesForeignTokens() {
|
||||
workgroup("page-ns", "page-wg");
|
||||
for (String name : List.of("ep-alpha", "ep-beta", "ep-gamma")) {
|
||||
ok("CreateEndpointAccess", "{\"endpointName\":\"" + name + "\",\"workgroupName\":\"page-wg\","
|
||||
+ "\"subnetIds\":[\"subnet-a\"]}");
|
||||
}
|
||||
|
||||
JsonNode firstPage = ok("ListEndpointAccess", "{\"workgroupName\":\"page-wg\",\"maxResults\":2}");
|
||||
assertEquals(2, firstPage.get("endpoints").size());
|
||||
assertEquals("ep-alpha", firstPage.get("endpoints").get(0).get("endpointName").textValue());
|
||||
assertEquals("ep-beta", firstPage.get("endpoints").get(1).get("endpointName").textValue());
|
||||
assertTrue(firstPage.has("nextToken"));
|
||||
|
||||
String token = firstPage.get("nextToken").textValue();
|
||||
JsonNode secondPage = ok("ListEndpointAccess", "{\"workgroupName\":\"page-wg\",\"nextToken\":\"" + token + "\"}");
|
||||
assertEquals(1, secondPage.get("endpoints").size());
|
||||
assertEquals("ep-gamma", secondPage.get("endpoints").get(0).get("endpointName").textValue());
|
||||
assertFalse(secondPage.has("nextToken"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tracksAreTheTwoAwsReleaseTracks() {
|
||||
JsonNode track = ok("GetTrack", "{\"trackName\":\"trailing\"}").get("track");
|
||||
@@ -202,6 +327,21 @@ class RedshiftServerlessAdministrationHandlerTest {
|
||||
errorType("CreateReservation", "{\"capacity\":128,\"offeringId\":\"o-1\",\"clientToken\":123}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aWorkgroupRecreatedUnderTheSameNameDoesNotInheritEndpoints() {
|
||||
workgroup("recreate-wg-ns", "recreate-wg");
|
||||
ok("CreateEndpointAccess", "{\"endpointName\":\"old-ep\",\"workgroupName\":\"recreate-wg\","
|
||||
+ "\"subnetIds\":[\"subnet-a\"],\"vpcSecurityGroupIds\":[\"sg-1\"]}");
|
||||
|
||||
ok("DeleteWorkgroup", "{\"workgroupName\":\"recreate-wg\"}");
|
||||
ok("CreateWorkgroup", "{\"workgroupName\":\"recreate-wg\",\"namespaceName\":\"recreate-wg-ns\"}");
|
||||
|
||||
assertEquals("ResourceNotFoundException", errorType("GetEndpointAccess", "{\"endpointName\":\"old-ep\"}"));
|
||||
assertEquals(0, ok("ListEndpointAccess", "{\"workgroupName\":\"recreate-wg\"}").get("endpoints").size());
|
||||
ok("CreateEndpointAccess", "{\"endpointName\":\"old-ep\",\"workgroupName\":\"recreate-wg\","
|
||||
+ "\"subnetIds\":[\"subnet-a\"],\"vpcSecurityGroupIds\":[\"sg-1\"]}");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aSnapshotRecreatedUnderTheSameNameDoesNotInheritItsPolicy() {
|
||||
String arn = snapshot("recreate-snap-ns", "recreate-snap");
|
||||
|
||||
+28
@@ -593,6 +593,34 @@ class RedshiftServerlessIntegrationTest {
|
||||
.then();
|
||||
}
|
||||
|
||||
@Test
|
||||
void endpointAccessRoundTripsOverTheWire() {
|
||||
call("CreateNamespace", "{\"namespaceName\":\"endpoint-ns\",\"adminUsername\":\"admin\"}").statusCode(200);
|
||||
call("CreateWorkgroup", "{\"workgroupName\":\"endpoint-wg\",\"namespaceName\":\"endpoint-ns\"}").statusCode(200);
|
||||
|
||||
call("CreateEndpointAccess", "{\"endpointName\":\"admin-ep\",\"workgroupName\":\"endpoint-wg\","
|
||||
+ "\"subnetIds\":[\"subnet-a\"]}")
|
||||
.statusCode(200)
|
||||
.body("endpoint.endpointName", equalTo("admin-ep"))
|
||||
.body("endpoint.endpointStatus", equalTo("ACTIVE"))
|
||||
.body("endpoint.endpointCreateTime", matchesPattern("\\d{4}-\\d{2}-\\d{2}T.*Z"))
|
||||
.body("endpoint.vpcSecurityGroups", hasSize(0))
|
||||
.body("endpoint.vpcEndpoint.networkInterfaces[0].subnetId", equalTo("subnet-a"));
|
||||
call("CreateEndpointAccess", "{\"endpointName\":\"admin--ep\",\"workgroupName\":\"endpoint-wg\","
|
||||
+ "\"subnetIds\":[\"subnet-a\"]}")
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
call("CreateEndpointAccess", "{\"endpointName\":\"other-ep\",\"workgroupName\":\"endpoint-wg\"}")
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
call("ListEndpointAccess", "{\"workgroupName\":\"endpoint-wg\"}")
|
||||
.statusCode(200)
|
||||
.body("endpoints.endpointName", hasItem("admin-ep"));
|
||||
call("DeleteEndpointAccess", "{\"endpointName\":\"admin-ep\"}")
|
||||
.statusCode(200)
|
||||
.body("endpoint.endpointStatus", equalTo("DELETING"));
|
||||
}
|
||||
|
||||
private static io.restassured.response.ValidatableResponse call(String action, String body) {
|
||||
return given()
|
||||
.header("X-Amz-Target", TARGET_PREFIX + action)
|
||||
|
||||
+3
-2
@@ -89,12 +89,13 @@ class RedshiftServerlessJsonHandlerTest {
|
||||
handler = new RedshiftServerlessJsonHandler(service, mapper, iamDbUserResolver,
|
||||
new RedshiftServerlessUsageLimitService(storageFactory, regionResolver, service),
|
||||
new RedshiftServerlessAdminJsonHandler(mapper,
|
||||
new RedshiftServerlessResourcePolicyService(storageFactory, service, mapper)));
|
||||
new RedshiftServerlessResourcePolicyService(storageFactory, service, mapper),
|
||||
new RedshiftServerlessEndpointAccessService(storageFactory, regionResolver, service)));
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private static void stubAdministrationStores(StorageFactory storageFactory) {
|
||||
for (String file : List.of("resourcepolicies")) {
|
||||
for (String file : List.of("resourcepolicies", "endpointaccess")) {
|
||||
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