diff --git a/src/main/java/gyro/google/cloudsql/DbAclEntry.java b/src/main/java/gyro/google/cloudsql/DbAclEntry.java index 14e0fb68..e77fb82a 100644 --- a/src/main/java/gyro/google/cloudsql/DbAclEntry.java +++ b/src/main/java/gyro/google/cloudsql/DbAclEntry.java @@ -70,11 +70,19 @@ public void copyFrom(AclEntry model) { @Override public String primaryKey() { - return String.format( - "Acl Entry [Value: %s, Expiration Time: %s, Name: %s]", - getValue(), - getExpirationTime(), - getName()); + StringBuilder sb = new StringBuilder(); + sb.append("Acl Entry [Value: ").append(getValue()); + + if (getName() != null) { + sb.append(", Name: ").append(getName()); + } + + if (getExpirationTime() != null) { + sb.append(", Expiration Time: ").append(getExpirationTime()); + } + + sb.append("]"); + return sb.toString(); } public AclEntry toAclEntry() { diff --git a/src/main/java/gyro/google/cloudsql/DbBackupConfiguration.java b/src/main/java/gyro/google/cloudsql/DbBackupConfiguration.java index b80acb5e..8b40e91b 100644 --- a/src/main/java/gyro/google/cloudsql/DbBackupConfiguration.java +++ b/src/main/java/gyro/google/cloudsql/DbBackupConfiguration.java @@ -104,7 +104,7 @@ public void setPointInTimeRecoveryEnabled(Boolean pointInTimeRecoveryEnabled) { * The start time for the daily backup configuration in UTC timezone in the 24 hour format - `HH:MM`. */ @Updatable - @Regex("[0-2][0-9]:[0-5][0-9]") + @Regex("([01][0-9]|2[0-3]):([0-5][0-9])") public String getStartTime() { return startTime; } diff --git a/src/main/java/gyro/google/cloudsql/DbInsightsConfig.java b/src/main/java/gyro/google/cloudsql/DbInsightsConfig.java index 1f434429..75abdea0 100644 --- a/src/main/java/gyro/google/cloudsql/DbInsightsConfig.java +++ b/src/main/java/gyro/google/cloudsql/DbInsightsConfig.java @@ -110,10 +110,7 @@ public String primaryKey() { public InsightsConfig toInsightsConfig() { InsightsConfig config = new InsightsConfig(); - - if (getQueryInsightsEnabled() != null) { - config.setQueryInsightsEnabled(getQueryInsightsEnabled()); - } + config.setQueryInsightsEnabled(getQueryInsightsEnabled()); if (getQueryPlansPerMinute() != null) { config.setQueryPlansPerMinute(getQueryPlansPerMinute()); diff --git a/src/main/java/gyro/google/cloudsql/DbMaintenanceWindow.java b/src/main/java/gyro/google/cloudsql/DbMaintenanceWindow.java index c78527a9..f14345bf 100644 --- a/src/main/java/gyro/google/cloudsql/DbMaintenanceWindow.java +++ b/src/main/java/gyro/google/cloudsql/DbMaintenanceWindow.java @@ -20,6 +20,7 @@ import gyro.core.resource.Diffable; import gyro.core.resource.Updatable; import gyro.core.validation.Range; +import gyro.core.validation.Required; import gyro.core.validation.ValidStrings; import gyro.google.Copyable; @@ -35,6 +36,7 @@ public class DbMaintenanceWindow extends Diffable implements Copyable { @@ -148,4 +153,20 @@ public PasswordValidationPolicy toPasswordValidationPolicy() { return policy; } + + @Override + public List validate(Set configuredFields) { + List errors = new ArrayList<>(); + + if (configuredFields.contains("enable-password-policy") && !getEnablePasswordPolicy() && + (getDisallowUsernameSubstring() != null || getMinLength() != null || getComplexity() != null + || getPasswordChangeInterval() != null || getReuseInterval() != null)) { + errors.add(new ValidationError( + this, + "enable-password-policy", + "'enable-password-policy' needs to be set to 'true' explicitly, in order to enable other password validation options.")); + } + + return errors; + } } diff --git a/src/main/java/gyro/google/cloudsql/DbPscConfig.java b/src/main/java/gyro/google/cloudsql/DbPscConfig.java index 8431ee72..54184e85 100644 --- a/src/main/java/gyro/google/cloudsql/DbPscConfig.java +++ b/src/main/java/gyro/google/cloudsql/DbPscConfig.java @@ -24,6 +24,7 @@ import gyro.core.resource.Updatable; import gyro.core.validation.DependsOn; import gyro.core.validation.Required; +import gyro.core.validation.ValidationError; import gyro.google.Copyable; public class DbPscConfig extends Diffable implements Copyable { @@ -82,4 +83,18 @@ public PscConfig toPscConfig() { return config; } + + @Override + public List validate() { + List errors = new ArrayList<>(); + + if (!getPscEnabled() && !getAllowedConsumerProjects().isEmpty()) { + errors.add(new ValidationError( + this, + "allowed-consumer-projects", + "'psc-enabled' should be set to 'true' in order to set 'allowed-consumer-projects'.")); + } + + return errors; + } } diff --git a/src/main/java/gyro/google/cloudsql/DbReplicationCluster.java b/src/main/java/gyro/google/cloudsql/DbReplicationCluster.java index 734241a8..da17d90e 100644 --- a/src/main/java/gyro/google/cloudsql/DbReplicationCluster.java +++ b/src/main/java/gyro/google/cloudsql/DbReplicationCluster.java @@ -20,6 +20,7 @@ import gyro.core.resource.Diffable; import gyro.core.resource.Output; import gyro.core.resource.Updatable; +import gyro.core.validation.Required; import gyro.google.Copyable; public class DbReplicationCluster extends Diffable implements Copyable { @@ -37,6 +38,7 @@ public class DbReplicationCluster extends Diffable implements Copyable { private DbMaintenanceWindow maintenanceWindow; private DbPasswordValidationPolicy passwordValidationPolicy; private String pricingPlan; - private Long settingsVersion; private DbSqlServerAuditConfig sqlServerAuditConfig; private Boolean storageAutoResize; private Long storageAutoResizeLimit; @@ -66,6 +65,9 @@ public class DbSettings extends Diffable implements Copyable { private String timeZone; private Map userLabels; + // Read-only + private Long settingsVersion; + /** * The activation policy specifies when the instance is activated. */