mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
This commit is contained in:
1 parent
7c6e6a6dfa
commit
7af3600bca
8 files changed
+256
-5
No files matched your search
@@ -35,6 +35,9 @@ public interface EmulatorConfig {
|
||||
@WithDefault("us-east-1")
|
||||
String defaultRegion();
|
||||
|
||||
@WithDefault("us-east-1a")
|
||||
String defaultAvailabilityZone();
|
||||
|
||||
@WithDefault("000000000000")
|
||||
String defaultAccountId();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.rds;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsNamespaces;
|
||||
import io.github.hectorvent.floci.core.common.AwsQueryResponse;
|
||||
@@ -28,14 +29,16 @@ public class RdsQueryHandler {
|
||||
private static final Logger LOG = Logger.getLogger(RdsQueryHandler.class);
|
||||
|
||||
private final RdsService service;
|
||||
private final EmulatorConfig config;
|
||||
|
||||
@Inject
|
||||
public RdsQueryHandler(RdsService service) {
|
||||
public RdsQueryHandler(RdsService service, EmulatorConfig config) {
|
||||
this.service = service;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public Response handle(String action, MultivaluedMap<String, String> params) {
|
||||
LOG.debugv("RDS action: {0}", action);
|
||||
LOG.infov("RDS action: {0}", action);
|
||||
try {
|
||||
return switch (action) {
|
||||
case "CreateDBInstance" -> handleCreateDbInstance(params);
|
||||
@@ -366,7 +369,32 @@ public class RdsQueryHandler {
|
||||
xml.elem("IAMDatabaseAuthenticationEnabled", i.isIamDatabaseAuthenticationEnabled())
|
||||
.elem("MultiAZ", false)
|
||||
.elem("StorageType", "gp2")
|
||||
.elem("PubliclyAccessible", false);
|
||||
.elem("PubliclyAccessible", false)
|
||||
.elem("AvailabilityZone", config.defaultAvailabilityZone())
|
||||
.elem("PreferredMaintenanceWindow", "mon:00:00-mon:03:00")
|
||||
.elem("PreferredBackupWindow", "04:00-06:00")
|
||||
.start("VpcSecurityGroups")
|
||||
.start("VpcSecurityGroupMembership")
|
||||
.elem("VpcSecurityGroupId", "sg-00000000")
|
||||
.elem("Status", "active")
|
||||
.end("VpcSecurityGroupMembership")
|
||||
.end("VpcSecurityGroups")
|
||||
.start("DBSubnetGroup")
|
||||
.elem("DBSubnetGroupName", "default")
|
||||
.elem("VpcId", "vpc-00000000")
|
||||
.elem("SubnetGroupStatus", "Complete")
|
||||
.start("Subnets")
|
||||
.start("member")
|
||||
.elem("SubnetIdentifier", "subnet-00000000")
|
||||
.start("SubnetAvailabilityZone")
|
||||
.elem("Name", config.defaultAvailabilityZone())
|
||||
.end("SubnetAvailabilityZone")
|
||||
.elem("SubnetStatus", "Active")
|
||||
.end("member")
|
||||
.end("Subnets")
|
||||
.end("DBSubnetGroup")
|
||||
.elem("DbiResourceId", i.getDbiResourceId())
|
||||
.elem("DBInstanceArn", i.getDbInstanceArn());
|
||||
if (i.getDbClusterIdentifier() != null && !i.getDbClusterIdentifier().isBlank()) {
|
||||
xml.elem("DBClusterIdentifier", i.getDbClusterIdentifier());
|
||||
}
|
||||
@@ -401,6 +429,31 @@ public class RdsQueryHandler {
|
||||
}
|
||||
xml.elem("IAMDatabaseAuthenticationEnabled", c.isIamDatabaseAuthenticationEnabled())
|
||||
.elem("MultiAZ", false)
|
||||
.elem("AvailabilityZone", config.defaultAvailabilityZone())
|
||||
.elem("PreferredMaintenanceWindow", "mon:00:00-mon:03:00")
|
||||
.elem("PreferredBackupWindow", "04:00-06:00")
|
||||
.start("VpcSecurityGroups")
|
||||
.start("VpcSecurityGroupMembership")
|
||||
.elem("VpcSecurityGroupId", "sg-00000000")
|
||||
.elem("Status", "active")
|
||||
.end("VpcSecurityGroupMembership")
|
||||
.end("VpcSecurityGroups")
|
||||
.start("DBSubnetGroup")
|
||||
.elem("DBSubnetGroupName", "default")
|
||||
.elem("VpcId", "vpc-00000000")
|
||||
.elem("SubnetGroupStatus", "Complete")
|
||||
.start("Subnets")
|
||||
.start("member")
|
||||
.elem("SubnetIdentifier", "subnet-00000000")
|
||||
.start("SubnetAvailabilityZone")
|
||||
.elem("Name", config.defaultAvailabilityZone())
|
||||
.end("SubnetAvailabilityZone")
|
||||
.elem("SubnetStatus", "Active")
|
||||
.end("member")
|
||||
.end("Subnets")
|
||||
.end("DBSubnetGroup")
|
||||
.elem("DbClusterResourceId", c.getDbClusterResourceId())
|
||||
.elem("DBClusterArn", c.getDbClusterArn())
|
||||
.start("DBClusterMembers");
|
||||
if (c.getDbClusterMembers() != null) {
|
||||
for (String memberId : c.getDbClusterMembers()) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.rds;
|
||||
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.services.rds.container.RdsContainerHandle;
|
||||
@@ -38,15 +39,18 @@ public class RdsService {
|
||||
private final StorageBackend<String, DbParameterGroup> parameterGroups;
|
||||
private final RdsContainerManager containerManager;
|
||||
private final RdsProxyManager proxyManager;
|
||||
private final RegionResolver regionResolver;
|
||||
private final EmulatorConfig config;
|
||||
private final Set<Integer> usedPorts = ConcurrentHashMap.newKeySet();
|
||||
|
||||
@Inject
|
||||
public RdsService(RdsContainerManager containerManager,
|
||||
RdsProxyManager proxyManager,
|
||||
RegionResolver regionResolver,
|
||||
EmulatorConfig config) {
|
||||
this.containerManager = containerManager;
|
||||
this.proxyManager = proxyManager;
|
||||
this.regionResolver = regionResolver;
|
||||
this.config = config;
|
||||
this.instances = new InMemoryStorage<>();
|
||||
this.clusters = new InMemoryStorage<>();
|
||||
@@ -103,6 +107,10 @@ public class RdsService {
|
||||
instance.setContainerHost(containerHost);
|
||||
instance.setContainerPort(containerPort);
|
||||
|
||||
String region = regionResolver.getDefaultRegion();
|
||||
instance.setDbiResourceId("db-" + java.util.UUID.randomUUID().toString().replace("-", "").substring(0, 24).toUpperCase());
|
||||
instance.setDbInstanceArn(regionResolver.buildArn("rds", region, "db:" + id));
|
||||
|
||||
String effectiveMasterUser = masterUsername != null ? masterUsername : "root";
|
||||
proxyManager.startProxy(id, engine, iamEnabled, proxyPort, backendHost, backendPort,
|
||||
effectiveMasterUser, masterPassword, dbName,
|
||||
@@ -129,7 +137,7 @@ public class RdsService {
|
||||
|
||||
public Collection<DbInstance> listDbInstances(String filterId) {
|
||||
if (filterId != null && !filterId.isBlank()) {
|
||||
return instances.get(filterId).map(List::of).orElse(List.of());
|
||||
return instances.scan(k -> k.equalsIgnoreCase(filterId));
|
||||
}
|
||||
return instances.scan(k -> true);
|
||||
}
|
||||
@@ -246,6 +254,10 @@ public class RdsService {
|
||||
cluster.setContainerHost(handle.getHost());
|
||||
cluster.setContainerPort(handle.getPort());
|
||||
|
||||
String region = regionResolver.getDefaultRegion();
|
||||
cluster.setDbClusterResourceId("cluster-" + java.util.UUID.randomUUID().toString().replace("-", "").substring(0, 24).toUpperCase());
|
||||
cluster.setDbClusterArn(regionResolver.buildArn("rds", region, "cluster:" + id));
|
||||
|
||||
String effectiveMasterUser = masterUsername != null ? masterUsername : "root";
|
||||
proxyManager.startProxy(id, engine, iamEnabled, proxyPort, handle.getHost(), handle.getPort(),
|
||||
effectiveMasterUser, masterPassword, databaseName,
|
||||
@@ -264,7 +276,7 @@ public class RdsService {
|
||||
|
||||
public Collection<DbCluster> listDbClusters(String filterId) {
|
||||
if (filterId != null && !filterId.isBlank()) {
|
||||
return clusters.get(filterId).map(List::of).orElse(List.of());
|
||||
return clusters.scan(k -> k.equalsIgnoreCase(filterId));
|
||||
}
|
||||
return clusters.scan(k -> true);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,8 @@ public class DbCluster {
|
||||
private boolean iamDatabaseAuthenticationEnabled;
|
||||
private List<String> dbClusterMembers = new ArrayList<>();
|
||||
private String parameterGroupName;
|
||||
private String dbClusterResourceId;
|
||||
private String dbClusterArn;
|
||||
private Instant createdAt;
|
||||
private int proxyPort;
|
||||
|
||||
@@ -90,6 +92,12 @@ public class DbCluster {
|
||||
public String getParameterGroupName() { return parameterGroupName; }
|
||||
public void setParameterGroupName(String parameterGroupName) { this.parameterGroupName = parameterGroupName; }
|
||||
|
||||
public String getDbClusterResourceId() { return dbClusterResourceId; }
|
||||
public void setDbClusterResourceId(String dbClusterResourceId) { this.dbClusterResourceId = dbClusterResourceId; }
|
||||
|
||||
public String getDbClusterArn() { return dbClusterArn; }
|
||||
public void setDbClusterArn(String dbClusterArn) { this.dbClusterArn = dbClusterArn; }
|
||||
|
||||
public Instant getCreatedAt() { return createdAt; }
|
||||
public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; }
|
||||
|
||||
|
||||
@@ -20,6 +20,8 @@ public class DbInstance {
|
||||
private boolean iamDatabaseAuthenticationEnabled;
|
||||
private String parameterGroupName;
|
||||
private String dbClusterIdentifier;
|
||||
private String dbiResourceId;
|
||||
private String dbInstanceArn;
|
||||
private Instant createdAt;
|
||||
private int proxyPort;
|
||||
|
||||
@@ -94,6 +96,12 @@ public class DbInstance {
|
||||
public String getDbClusterIdentifier() { return dbClusterIdentifier; }
|
||||
public void setDbClusterIdentifier(String dbClusterIdentifier) { this.dbClusterIdentifier = dbClusterIdentifier; }
|
||||
|
||||
public String getDbiResourceId() { return dbiResourceId; }
|
||||
public void setDbiResourceId(String dbiResourceId) { this.dbiResourceId = dbiResourceId; }
|
||||
|
||||
public String getDbInstanceArn() { return dbInstanceArn; }
|
||||
public void setDbInstanceArn(String dbInstanceArn) { this.dbInstanceArn = dbInstanceArn; }
|
||||
|
||||
public Instant getCreatedAt() { return createdAt; }
|
||||
public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; }
|
||||
|
||||
|
||||
Reference in new issue
Block a user