Skip to content

Commit

Permalink
Merge pull request #660 from perfectsense/bugfix/add-writer-endpoint-…
Browse files Browse the repository at this point in the history
…type-for-db-cluster

Add writer endpoint type For database clusters
  • Loading branch information
harjain99 authored Oct 1, 2024
2 parents 5187cab + 6e1a966 commit 88732e5
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/main/java/gyro/aws/rds/DbClusterEndpointResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import gyro.core.scope.State;
import gyro.core.validation.Required;
import gyro.core.validation.ValidStrings;
import gyro.core.validation.ValidationError;
import software.amazon.awssdk.services.rds.RdsClient;
import software.amazon.awssdk.services.rds.model.CreateDbClusterEndpointResponse;
import software.amazon.awssdk.services.rds.model.DBClusterEndpoint;
Expand Down Expand Up @@ -92,11 +93,11 @@ public void setDbCluster(DbClusterResource dbCluster) {
}

/**
* The type of the endpoint.
* The type of the endpoint. Cannot be set to ``WRITER`` if 'db-cluster' is set to ``Aurora``.
*/
@Required
@Updatable
@ValidStrings({"READER", "ANY"})
@ValidStrings({"READER", "WRITER", "ANY"})
public String getEndpointType() {
return endpointType;
}
Expand Down Expand Up @@ -226,4 +227,25 @@ public void delete(GyroUI ui, State state) {
r -> r.dbClusterEndpointIdentifier(getIdentifier())
);
}

@Override
public List<ValidationError> validate(Set<String> configuredFields) {
List<ValidationError> errors = new ArrayList<>();

// Add validation for Aurora DB and endpointType 'WRITER'
if (getDbCluster() != null) {
String engine = getDbCluster().getEngine();
if (engine != null && getEndpointType() != null) {
if ((engine.equalsIgnoreCase("aurora-mysql") || engine.equalsIgnoreCase("aurora-postgresql"))
&& getEndpointType().equalsIgnoreCase("WRITER")) {
errors.add(new ValidationError(
this,
"dbCluster",
"Database engine " + engine + " with endpointType 'WRITER' is not supported"));
}
}
}

return errors;
}
}

0 comments on commit 88732e5

Please sign in to comment.