mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
feat(rds): DB proxy endpoints (#6062)
* feat(rds): DB proxy endpoints CreateDBProxyEndpoint, DescribeDBProxyEndpoints, ModifyDBProxyEndpoint and DeleteDBProxyEndpoint store endpoints per account and Region, checked against the service model. Each endpoint reports its proxy's own host, so a client connects through it as through the proxy. DescribeDBProxyEndpoints lists each proxy's default endpoint first; it cannot be modified or deleted. Deleting a proxy deletes its endpoints, and endpoint ARNs take tags. Closes #5805 * fix(rds): report each proxy endpoint at the proxy's current host A custom endpoint kept the proxy's host from when it was created, so after a restore gave the proxy a new host, every custom endpoint still reported the old one while default reported the new one. The host is no longer stored with the endpoint: create, describe, modify and delete take it from the proxy when they answer. A missing DBProxyName, DBProxyEndpointName or VpcSubnetIds is now MissingParameter, checked before the proxy is looked up. * test(rds): import Executable and assertTrue instead of naming them inline
This commit is contained in:
1 parent
1dce18e766
commit
1108bc75dc
9 files changed
+1021
-2
No files matched your search
@@ -22,6 +22,7 @@ import io.github.hectorvent.floci.services.rds.model.DbInstanceStatus;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbParameterGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxy;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxyAuth;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxyEndpoint;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxyTarget;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxyTargetGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbRoleAssociation;
|
||||
@@ -169,6 +170,10 @@ public class RdsQueryHandler {
|
||||
case "CreateDBProxy" -> handleCreateDbProxy(params, region);
|
||||
case "ModifyDBProxy" -> handleModifyDbProxy(params, region);
|
||||
case "DeleteDBProxy" -> handleDeleteDbProxy(params, region);
|
||||
case "CreateDBProxyEndpoint" -> handleCreateDbProxyEndpoint(params, region);
|
||||
case "DescribeDBProxyEndpoints" -> handleDescribeDbProxyEndpoints(params, region);
|
||||
case "ModifyDBProxyEndpoint" -> handleModifyDbProxyEndpoint(params, region);
|
||||
case "DeleteDBProxyEndpoint" -> handleDeleteDbProxyEndpoint(params, region);
|
||||
case "RegisterDBProxyTargets" -> handleRegisterDbProxyTargets(params, region);
|
||||
case "DeregisterDBProxyTargets" -> handleDeregisterDbProxyTargets(params, region);
|
||||
case "DescribeDBProxyTargetGroups" -> handleDescribeDbProxyTargetGroups(params, region);
|
||||
@@ -2205,6 +2210,84 @@ public class RdsQueryHandler {
|
||||
return Response.ok(AwsQueryResponse.envelope("DeleteDBProxy", AwsNamespaces.RDS, result)).build();
|
||||
}
|
||||
|
||||
private Response handleCreateDbProxyEndpoint(MultivaluedMap<String, String> params, String region) {
|
||||
DbProxyEndpoint endpoint = service.createDbProxyEndpoint(region,
|
||||
params.getFirst("DBProxyName"),
|
||||
params.getFirst("DBProxyEndpointName"),
|
||||
memberList(params, "VpcSubnetIds"),
|
||||
memberList(params, "VpcSecurityGroupIds"),
|
||||
params.getFirst("TargetRole"),
|
||||
params.getFirst("EndpointNetworkType"),
|
||||
parseTags(params));
|
||||
return Response.ok(AwsQueryResponse.envelope("CreateDBProxyEndpoint", AwsNamespaces.RDS,
|
||||
dbProxyEndpointXml(endpoint))).build();
|
||||
}
|
||||
|
||||
private Response handleDescribeDbProxyEndpoints(MultivaluedMap<String, String> params, String region) {
|
||||
RdsService.ProxyEndpointPage page = service.describeDbProxyEndpoints(region,
|
||||
params.getFirst("DBProxyName"),
|
||||
params.getFirst("DBProxyEndpointName"),
|
||||
optionalInt(params.getFirst("MaxRecords")),
|
||||
params.getFirst("Marker"));
|
||||
XmlBuilder xml = new XmlBuilder().start("DBProxyEndpoints");
|
||||
for (DbProxyEndpoint endpoint : page.endpoints()) {
|
||||
xml.start("member").raw(dbProxyEndpointInnerXml(endpoint)).end("member");
|
||||
}
|
||||
xml.end("DBProxyEndpoints");
|
||||
if (page.marker() != null) {
|
||||
xml.elem("Marker", page.marker());
|
||||
}
|
||||
return Response.ok(AwsQueryResponse.envelope("DescribeDBProxyEndpoints", AwsNamespaces.RDS,
|
||||
xml.build())).build();
|
||||
}
|
||||
|
||||
private Response handleModifyDbProxyEndpoint(MultivaluedMap<String, String> params, String region) {
|
||||
// Security groups left out of the request are kept; a list given replaces them.
|
||||
DbProxyEndpoint endpoint = service.modifyDbProxyEndpoint(region,
|
||||
params.getFirst("DBProxyEndpointName"),
|
||||
params.getFirst("NewDBProxyEndpointName"),
|
||||
hasMemberKeys(params, "VpcSecurityGroupIds") ? memberList(params, "VpcSecurityGroupIds") : null);
|
||||
return Response.ok(AwsQueryResponse.envelope("ModifyDBProxyEndpoint", AwsNamespaces.RDS,
|
||||
dbProxyEndpointXml(endpoint))).build();
|
||||
}
|
||||
|
||||
private Response handleDeleteDbProxyEndpoint(MultivaluedMap<String, String> params, String region) {
|
||||
DbProxyEndpoint endpoint = service.deleteDbProxyEndpoint(region, params.getFirst("DBProxyEndpointName"));
|
||||
return Response.ok(AwsQueryResponse.envelope("DeleteDBProxyEndpoint", AwsNamespaces.RDS,
|
||||
dbProxyEndpointXml(endpoint))).build();
|
||||
}
|
||||
|
||||
private static String dbProxyEndpointXml(DbProxyEndpoint e) {
|
||||
return new XmlBuilder().start("DBProxyEndpoint").raw(dbProxyEndpointInnerXml(e)).end("DBProxyEndpoint").build();
|
||||
}
|
||||
|
||||
/** The DBProxyEndpoint members; a proxy's default endpoint has no ARN. */
|
||||
private static String dbProxyEndpointInnerXml(DbProxyEndpoint e) {
|
||||
XmlBuilder xml = new XmlBuilder().elem("DBProxyEndpointName", e.getDbProxyEndpointName());
|
||||
if (e.getDbProxyEndpointArn() != null) {
|
||||
xml.elem("DBProxyEndpointArn", e.getDbProxyEndpointArn());
|
||||
}
|
||||
xml.elem("DBProxyName", e.getDbProxyName())
|
||||
.elem("Status", e.getStatus());
|
||||
if (e.getVpcId() != null) {
|
||||
xml.elem("VpcId", e.getVpcId());
|
||||
}
|
||||
xml.start("VpcSecurityGroupIds");
|
||||
e.getVpcSecurityGroupIds().forEach(id -> xml.elem("member", id));
|
||||
xml.end("VpcSecurityGroupIds");
|
||||
xml.start("VpcSubnetIds");
|
||||
e.getVpcSubnetIds().forEach(id -> xml.elem("member", id));
|
||||
xml.end("VpcSubnetIds");
|
||||
xml.elem("Endpoint", e.getEndpoint());
|
||||
if (e.getCreatedDate() != null) {
|
||||
xml.elem("CreatedDate", e.getCreatedDate().toString());
|
||||
}
|
||||
xml.elem("TargetRole", e.getTargetRole())
|
||||
.elem("IsDefault", String.valueOf(e.isDefault()))
|
||||
.elem("EndpointNetworkType", e.getEndpointNetworkType() != null ? e.getEndpointNetworkType() : "IPV4");
|
||||
return xml.build();
|
||||
}
|
||||
|
||||
private Response handleRegisterDbProxyTargets(MultivaluedMap<String, String> params, String region) {
|
||||
String name = params.getFirst("DBProxyName");
|
||||
String tgName = params.getFirst("TargetGroupName");
|
||||
|
||||
@@ -48,6 +48,7 @@ import io.github.hectorvent.floci.services.rds.model.DbInstanceStatus;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbParameterGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxy;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxyAuth;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxyEndpoint;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxyTarget;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbProxyTargetGroup;
|
||||
import io.github.hectorvent.floci.services.rds.model.DbRoleAssociation;
|
||||
@@ -182,6 +183,7 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
private StorageBackend<String, RdsEvent> events = new InMemoryStorage<>();
|
||||
private final StorageBackend<String, EventSubscription> eventSubscriptions;
|
||||
private final StorageBackend<String, DbClusterEndpoint> clusterEndpoints;
|
||||
private final StorageBackend<String, DbProxyEndpoint> proxyEndpoints;
|
||||
private final RdsContainerManager containerManager;
|
||||
private final RdsProxyManager proxyManager;
|
||||
// CreateDBCluster/CreateDBInstance register the new resource only after the
|
||||
@@ -257,6 +259,8 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
new TypeReference<Map<String, EventSubscription>>() {});
|
||||
this.clusterEndpoints = storageFactory.create("rds", "rds-cluster-endpoints.json",
|
||||
new TypeReference<Map<String, DbClusterEndpoint>>() {});
|
||||
this.proxyEndpoints = storageFactory.create("rds", "rds-proxy-endpoints.json",
|
||||
new TypeReference<Map<String, DbProxyEndpoint>>() {});
|
||||
this.clusters = storageFactory.create("rds", "rds-clusters.json",
|
||||
new TypeReference<Map<String, DbCluster>>() {});
|
||||
this.parameterGroups = storageFactory.create("rds", "rds-parameter-groups.json",
|
||||
@@ -419,6 +423,7 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
this.snapshotData = new io.github.hectorvent.floci.core.storage.InMemoryStorage<>();
|
||||
this.eventSubscriptions = new InMemoryStorage<>();
|
||||
this.clusterEndpoints = new InMemoryStorage<>();
|
||||
this.proxyEndpoints = new InMemoryStorage<>();
|
||||
}
|
||||
|
||||
public void restorePersistedRuntime() {
|
||||
@@ -2525,6 +2530,16 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
eventSubscriptions.put(eventSubscriptionKey(effectiveRegion, resourceId), subscription);
|
||||
});
|
||||
}
|
||||
case "db-proxy-endpoint" -> {
|
||||
DbProxyEndpoint endpoint = proxyEndpoints.scan(k -> k.startsWith(effectiveRegion + "::")).stream()
|
||||
.filter(candidate -> resourceName.equals(candidate.getDbProxyEndpointArn()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> proxyEndpointNotFound(resourceId));
|
||||
yield new TagHandle(endpoint.getTags(), updated -> {
|
||||
endpoint.setTags(updated);
|
||||
proxyEndpoints.put(proxyEndpointKey(effectiveRegion, endpoint.getDbProxyEndpointName()), endpoint);
|
||||
});
|
||||
}
|
||||
case "db-proxy" -> {
|
||||
DbProxy proxy = proxies.scan(k -> true).stream()
|
||||
.filter(candidate -> effectiveRegion.equals(regionFromArn(candidate.getDbProxyArn())))
|
||||
@@ -6310,6 +6325,7 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
.or(() -> legacyTargetGroup
|
||||
.filter(candidate -> targetGroupMatchesProxy(candidate, proxy)))
|
||||
.orElse(null);
|
||||
List<DbProxyEndpoint> endpoints = proxyEndpointsOf(effectiveRegion, name);
|
||||
boolean realMode = !config.services().rds().mock();
|
||||
if (realMode) {
|
||||
try {
|
||||
@@ -6320,6 +6336,10 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
}
|
||||
}
|
||||
try {
|
||||
// A proxy's endpoints go with it.
|
||||
for (DbProxyEndpoint endpoint : endpoints) {
|
||||
proxyEndpoints.delete(proxyEndpointKey(effectiveRegion, endpoint.getDbProxyEndpointName()));
|
||||
}
|
||||
deleteTargetGroupKey(accountId, proxyKey);
|
||||
if (legacyTargetGroup.isPresent()) {
|
||||
deleteTargetGroupKey(accountId, name);
|
||||
@@ -6329,6 +6349,10 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
}
|
||||
deleteProxyKey(accountId, proxyKey);
|
||||
} catch (RuntimeException deleteFailure) {
|
||||
for (DbProxyEndpoint endpoint : endpoints) {
|
||||
attemptRollback(deleteFailure, () -> proxyEndpoints.put(
|
||||
proxyEndpointKey(effectiveRegion, endpoint.getDbProxyEndpointName()), endpoint));
|
||||
}
|
||||
attemptRollback(deleteFailure,
|
||||
() -> putProxyForAccount(accountId, proxyKey, proxy));
|
||||
canonicalTargetGroup.ifPresent(targetGroup -> attemptRollback(deleteFailure,
|
||||
@@ -6344,6 +6368,216 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
LOG.infov("DB proxy {0} deleted", name);
|
||||
}
|
||||
|
||||
// ── DB Proxy endpoints ────────────────────────────────────────────────────
|
||||
|
||||
/** AWS's limit on the endpoints a caller adds to one proxy, besides its default endpoint. */
|
||||
private static final int MAX_ENDPOINTS_PER_PROXY = 20;
|
||||
private static final String DEFAULT_PROXY_ENDPOINT_NAME = "default";
|
||||
private static final Set<String> PROXY_ENDPOINT_TARGET_ROLES = Set.of("READ_WRITE", "READ_ONLY");
|
||||
private static final Set<String> PROXY_ENDPOINT_NETWORK_TYPES = Set.of("IPV4", "IPV6", "DUAL");
|
||||
|
||||
public record ProxyEndpointPage(List<DbProxyEndpoint> endpoints, String marker) {}
|
||||
|
||||
/**
|
||||
* Adds an endpoint to a proxy. It reports the proxy's own host, so a client reaches the proxy's
|
||||
* listener through it, and an IAM token signed for that host verifies there.
|
||||
*/
|
||||
public synchronized DbProxyEndpoint createDbProxyEndpoint(String region, String dbProxyName, String endpointName,
|
||||
List<String> vpcSubnetIds,
|
||||
List<String> vpcSecurityGroupIds, String targetRole,
|
||||
String endpointNetworkType, Map<String, String> tags) {
|
||||
String effectiveRegion = effectiveRegion(region);
|
||||
requireParameter(dbProxyName, "DBProxyName");
|
||||
String name = requireProxyEndpointName(endpointName, "DBProxyEndpointName");
|
||||
if (vpcSubnetIds == null || vpcSubnetIds.isEmpty()) {
|
||||
throw new AwsException("MissingParameter", "The request must contain the parameter VpcSubnetIds.", 400);
|
||||
}
|
||||
DbProxy proxy = getDbProxy(dbProxyName, effectiveRegion);
|
||||
String role = isBlank(targetRole) ? "READ_WRITE" : targetRole;
|
||||
if (!PROXY_ENDPOINT_TARGET_ROLES.contains(role)) {
|
||||
throw new AwsException("InvalidParameterValue", "TargetRole must be READ_WRITE or READ_ONLY.", 400);
|
||||
}
|
||||
if ("READ_ONLY".equals(role) && "SQLSERVER".equalsIgnoreCase(proxy.getEngineFamily())) {
|
||||
throw new AwsException("InvalidParameterCombination",
|
||||
"A DB proxy for RDS for SQL Server supports only the READ_WRITE target role.", 400);
|
||||
}
|
||||
String networkType = isBlank(endpointNetworkType) ? "IPV4" : endpointNetworkType;
|
||||
if (!PROXY_ENDPOINT_NETWORK_TYPES.contains(networkType)) {
|
||||
throw new AwsException("InvalidParameterValue", "EndpointNetworkType must be IPV4, IPV6, or DUAL.", 400);
|
||||
}
|
||||
if (!"available".equals(proxy.getStatus())) {
|
||||
throw new AwsException("InvalidDBProxyStateFault",
|
||||
"DB proxy " + proxy.getDbProxyName() + " is not available.", 400);
|
||||
}
|
||||
String key = proxyEndpointKey(effectiveRegion, name);
|
||||
if (DEFAULT_PROXY_ENDPOINT_NAME.equals(name) || proxyEndpoints.get(key).isPresent()) {
|
||||
throw new AwsException("DBProxyEndpointAlreadyExistsFault",
|
||||
"DB proxy endpoint " + name + " already exists.", 400);
|
||||
}
|
||||
if (proxyEndpointsOf(effectiveRegion, proxy.getDbProxyName()).size() >= MAX_ENDPOINTS_PER_PROXY) {
|
||||
throw new AwsException("DBProxyEndpointQuotaExceededFault",
|
||||
"DB proxy " + proxy.getDbProxyName() + " already has " + MAX_ENDPOINTS_PER_PROXY
|
||||
+ " endpoints.", 400);
|
||||
}
|
||||
String vpcId = resolveDbProxyVpc(vpcSubnetIds, effectiveRegion);
|
||||
if (!"IPV4".equals(networkType)) {
|
||||
validateVpcHasIpv6CidrBlock(vpcId, effectiveRegion);
|
||||
validateSubnetsHaveIpv6CidrBlock(vpcSubnetIds, effectiveRegion);
|
||||
}
|
||||
|
||||
DbProxyEndpoint endpoint = new DbProxyEndpoint();
|
||||
endpoint.setDbProxyEndpointName(name);
|
||||
endpoint.setDbProxyEndpointArn(regionResolver.buildArn("rds", effectiveRegion,
|
||||
"db-proxy-endpoint:prx-endpoint-" + randomResourceSuffix()));
|
||||
endpoint.setDbProxyName(proxy.getDbProxyName());
|
||||
endpoint.setStatus("available");
|
||||
endpoint.setVpcId(vpcId);
|
||||
endpoint.setVpcSubnetIds(vpcSubnetIds);
|
||||
endpoint.setVpcSecurityGroupIds(vpcSecurityGroupIds == null || vpcSecurityGroupIds.isEmpty()
|
||||
? defaultSecurityGroupOf(vpcId, effectiveRegion) : vpcSecurityGroupIds);
|
||||
endpoint.setCreatedDate(Instant.now());
|
||||
endpoint.setTargetRole(role);
|
||||
endpoint.setEndpointNetworkType(networkType);
|
||||
endpoint.setTags(tags);
|
||||
proxyEndpoints.put(key, endpoint);
|
||||
return withProxyHost(endpoint, proxy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Each proxy in scope's default endpoint, then the endpoints added to it by name, narrowed by
|
||||
* the request's proxy and endpoint names.
|
||||
*/
|
||||
public synchronized ProxyEndpointPage describeDbProxyEndpoints(String region, String dbProxyName,
|
||||
String endpointName, Integer maxRecords,
|
||||
String marker) {
|
||||
String effectiveRegion = effectiveRegion(region);
|
||||
requireValidMaxRecords(maxRecords);
|
||||
List<DbProxy> scope = !isBlank(dbProxyName)
|
||||
? List.of(getDbProxy(dbProxyName, effectiveRegion))
|
||||
: listDbProxies(null, effectiveRegion).stream()
|
||||
.sorted(Comparator.comparing(DbProxy::getDbProxyName))
|
||||
.toList();
|
||||
List<DbProxyEndpoint> all = new ArrayList<>();
|
||||
for (DbProxy proxy : scope) {
|
||||
all.add(defaultProxyEndpoint(proxy));
|
||||
proxyEndpointsOf(effectiveRegion, proxy.getDbProxyName()).stream()
|
||||
.sorted(Comparator.comparing(DbProxyEndpoint::getDbProxyEndpointName))
|
||||
.map(endpoint -> withProxyHost(endpoint, proxy))
|
||||
.forEach(all::add);
|
||||
}
|
||||
List<DbProxyEndpoint> matching = all.stream()
|
||||
.filter(e -> isBlank(endpointName) || endpointName.equals(e.getDbProxyEndpointName()))
|
||||
.toList();
|
||||
if (!isBlank(endpointName) && matching.isEmpty()) {
|
||||
throw proxyEndpointNotFound(endpointName);
|
||||
}
|
||||
OffsetPage<DbProxyEndpoint> page = offsetPage(matching, maxRecords, marker);
|
||||
return new ProxyEndpointPage(page.items(), page.marker());
|
||||
}
|
||||
|
||||
/** Renames an endpoint or replaces its security groups; a proxy's default endpoint cannot change. */
|
||||
public synchronized DbProxyEndpoint modifyDbProxyEndpoint(String region, String endpointName, String newName,
|
||||
List<String> vpcSecurityGroupIds) {
|
||||
String effectiveRegion = effectiveRegion(region);
|
||||
DbProxyEndpoint endpoint = requireProxyEndpoint(effectiveRegion, endpointName);
|
||||
DbProxy proxy = getDbProxy(endpoint.getDbProxyName(), effectiveRegion);
|
||||
if (!"available".equals(proxy.getStatus())) {
|
||||
throw new AwsException("InvalidDBProxyStateFault",
|
||||
"DB proxy " + proxy.getDbProxyName() + " is not available.", 400);
|
||||
}
|
||||
String name = isBlank(newName) ? endpoint.getDbProxyEndpointName()
|
||||
: requireProxyEndpointName(newName, "NewDBProxyEndpointName");
|
||||
boolean renamed = !name.equals(endpoint.getDbProxyEndpointName());
|
||||
if (renamed && (DEFAULT_PROXY_ENDPOINT_NAME.equals(name)
|
||||
|| proxyEndpoints.get(proxyEndpointKey(effectiveRegion, name)).isPresent())) {
|
||||
throw new AwsException("DBProxyEndpointAlreadyExistsFault",
|
||||
"DB proxy endpoint " + name + " already exists.", 400);
|
||||
}
|
||||
String oldKey = proxyEndpointKey(effectiveRegion, endpoint.getDbProxyEndpointName());
|
||||
endpoint.setDbProxyEndpointName(name);
|
||||
if (vpcSecurityGroupIds != null) {
|
||||
endpoint.setVpcSecurityGroupIds(vpcSecurityGroupIds);
|
||||
}
|
||||
proxyEndpoints.put(proxyEndpointKey(effectiveRegion, name), endpoint);
|
||||
if (renamed) {
|
||||
proxyEndpoints.delete(oldKey);
|
||||
}
|
||||
return withProxyHost(endpoint, proxy);
|
||||
}
|
||||
|
||||
/** Deletes an endpoint; the response reports it as {@code deleting}. */
|
||||
public synchronized DbProxyEndpoint deleteDbProxyEndpoint(String region, String endpointName) {
|
||||
String effectiveRegion = effectiveRegion(region);
|
||||
DbProxyEndpoint endpoint = requireProxyEndpoint(effectiveRegion, endpointName);
|
||||
proxyEndpoints.delete(proxyEndpointKey(effectiveRegion, endpoint.getDbProxyEndpointName()));
|
||||
endpoint.setStatus("deleting");
|
||||
return withProxyHost(endpoint, getDbProxy(endpoint.getDbProxyName(), effectiveRegion));
|
||||
}
|
||||
|
||||
/** A stored endpoint by name; the default endpoint is in a state no change can be made in. */
|
||||
private DbProxyEndpoint requireProxyEndpoint(String region, String endpointName) {
|
||||
String name = requireProxyEndpointName(endpointName, "DBProxyEndpointName");
|
||||
if (DEFAULT_PROXY_ENDPOINT_NAME.equals(name)) {
|
||||
throw new AwsException("InvalidDBProxyEndpointStateFault",
|
||||
"The default endpoint of a DB proxy cannot be modified or deleted.", 400);
|
||||
}
|
||||
return proxyEndpoints.get(proxyEndpointKey(region, name)).orElseThrow(() -> proxyEndpointNotFound(name));
|
||||
}
|
||||
|
||||
private static String requireProxyEndpointName(String name, String parameter) {
|
||||
requireParameter(name, parameter);
|
||||
if (name.length() > 63 || !DB_PROXY_NAME_PATTERN.matcher(name).matches()) {
|
||||
throw new AwsException("InvalidParameterValue", parameter + " must be 1-63 characters, begin with a "
|
||||
+ "letter, and contain only letters, digits, and single hyphens.", 400);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/** Reports the proxy's current host, which a restore can change after the endpoint was created. */
|
||||
private static DbProxyEndpoint withProxyHost(DbProxyEndpoint endpoint, DbProxy proxy) {
|
||||
endpoint.setEndpoint(proxy.getEndpoint());
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
private static AwsException proxyEndpointNotFound(String name) {
|
||||
return new AwsException("DBProxyEndpointNotFoundFault", "DB proxy endpoint " + name + " not found.", 404);
|
||||
}
|
||||
|
||||
/** The endpoint RDS gives every proxy: read/write, in the proxy's VPC, at the proxy's host. */
|
||||
private static DbProxyEndpoint defaultProxyEndpoint(DbProxy proxy) {
|
||||
DbProxyEndpoint endpoint = new DbProxyEndpoint();
|
||||
endpoint.setDbProxyEndpointName(DEFAULT_PROXY_ENDPOINT_NAME);
|
||||
endpoint.setDbProxyName(proxy.getDbProxyName());
|
||||
endpoint.setStatus(proxy.getStatus());
|
||||
endpoint.setVpcId(proxy.getVpcId());
|
||||
endpoint.setVpcSubnetIds(proxy.getVpcSubnetIds());
|
||||
endpoint.setVpcSecurityGroupIds(proxy.getVpcSecurityGroupIds());
|
||||
endpoint.setEndpoint(proxy.getEndpoint());
|
||||
endpoint.setCreatedDate(proxy.getCreatedAt());
|
||||
endpoint.setTargetRole("READ_WRITE");
|
||||
endpoint.setDefault(true);
|
||||
endpoint.setEndpointNetworkType(proxy.getEndpointNetworkType());
|
||||
return endpoint;
|
||||
}
|
||||
|
||||
private List<String> defaultSecurityGroupOf(String vpcId, String region) {
|
||||
return ec2Service.getSecurityGroupsForVpc(region, vpcId, Map.of()).stream()
|
||||
.filter(group -> "default".equals(group.getGroupName()))
|
||||
.map(group -> group.getGroupId())
|
||||
.toList();
|
||||
}
|
||||
|
||||
private List<DbProxyEndpoint> proxyEndpointsOf(String region, String dbProxyName) {
|
||||
String prefix = effectiveRegion(region) + "::";
|
||||
return proxyEndpoints.scan(key -> key.startsWith(prefix)).stream()
|
||||
.filter(endpoint -> dbProxyName.equals(endpoint.getDbProxyName()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private String proxyEndpointKey(String region, String endpointName) {
|
||||
return effectiveRegion(region) + "::" + endpointName;
|
||||
}
|
||||
|
||||
// ── DB Subnet Groups ──────────────────────────────────────────────────────
|
||||
|
||||
public DbSubnetGroup createDbSubnetGroup(String name, String description, List<String> subnetIds) {
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package io.github.hectorvent.floci.services.rds.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A DB proxy endpoint as DescribeDBProxyEndpoints reports it. Endpoints a caller creates are
|
||||
* stored; a proxy's default endpoint is built from the proxy when described and carries no ARN.
|
||||
* Every endpoint reports the proxy's own host, so a connection through it reaches the proxy's
|
||||
* listener and the proxy's one target, whatever its target role. The host is not stored: a restored
|
||||
* proxy can come back on a new one, so each response reads it from the proxy.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
public class DbProxyEndpoint {
|
||||
|
||||
private String dbProxyEndpointName;
|
||||
private String dbProxyEndpointArn;
|
||||
private String dbProxyName;
|
||||
private String status;
|
||||
private String vpcId;
|
||||
private List<String> vpcSubnetIds = new ArrayList<>();
|
||||
private List<String> vpcSecurityGroupIds = new ArrayList<>();
|
||||
/** The owning proxy's host, filled in for each response. */
|
||||
@JsonIgnore
|
||||
private String endpoint;
|
||||
private Instant createdDate;
|
||||
/** READ_WRITE or READ_ONLY. */
|
||||
private String targetRole;
|
||||
private boolean isDefault;
|
||||
private String endpointNetworkType;
|
||||
private Map<String, String> tags = new LinkedHashMap<>();
|
||||
|
||||
public DbProxyEndpoint() {}
|
||||
|
||||
public String getDbProxyEndpointName() { return dbProxyEndpointName; }
|
||||
public void setDbProxyEndpointName(String dbProxyEndpointName) { this.dbProxyEndpointName = dbProxyEndpointName; }
|
||||
|
||||
public String getDbProxyEndpointArn() { return dbProxyEndpointArn; }
|
||||
public void setDbProxyEndpointArn(String dbProxyEndpointArn) { this.dbProxyEndpointArn = dbProxyEndpointArn; }
|
||||
|
||||
public String getDbProxyName() { return dbProxyName; }
|
||||
public void setDbProxyName(String dbProxyName) { this.dbProxyName = dbProxyName; }
|
||||
|
||||
public String getStatus() { return status; }
|
||||
public void setStatus(String status) { this.status = status; }
|
||||
|
||||
public String getVpcId() { return vpcId; }
|
||||
public void setVpcId(String vpcId) { this.vpcId = vpcId; }
|
||||
|
||||
public List<String> getVpcSubnetIds() { return vpcSubnetIds; }
|
||||
public void setVpcSubnetIds(List<String> vpcSubnetIds) {
|
||||
this.vpcSubnetIds = vpcSubnetIds != null ? new ArrayList<>(vpcSubnetIds) : new ArrayList<>();
|
||||
}
|
||||
|
||||
public List<String> getVpcSecurityGroupIds() { return vpcSecurityGroupIds; }
|
||||
public void setVpcSecurityGroupIds(List<String> vpcSecurityGroupIds) {
|
||||
this.vpcSecurityGroupIds = vpcSecurityGroupIds != null ? new ArrayList<>(vpcSecurityGroupIds) : new ArrayList<>();
|
||||
}
|
||||
|
||||
public String getEndpoint() { return endpoint; }
|
||||
public void setEndpoint(String endpoint) { this.endpoint = endpoint; }
|
||||
|
||||
public Instant getCreatedDate() { return createdDate; }
|
||||
public void setCreatedDate(Instant createdDate) { this.createdDate = createdDate; }
|
||||
|
||||
public String getTargetRole() { return targetRole; }
|
||||
public void setTargetRole(String targetRole) { this.targetRole = targetRole; }
|
||||
|
||||
public boolean isDefault() { return isDefault; }
|
||||
public void setDefault(boolean isDefault) { this.isDefault = isDefault; }
|
||||
|
||||
public String getEndpointNetworkType() { return endpointNetworkType; }
|
||||
public void setEndpointNetworkType(String endpointNetworkType) { this.endpointNetworkType = endpointNetworkType; }
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) {
|
||||
this.tags = tags != null ? new LinkedHashMap<>(tags) : new LinkedHashMap<>();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user