Skip to content

Commit

Permalink
Handle updates correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
harjain99 committed Sep 25, 2024
1 parent 4f15508 commit f2b3218
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 193 deletions.
401 changes: 235 additions & 166 deletions src/main/java/gyro/google/cloudsql/DatabaseInstanceResource.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import gyro.core.resource.Diffable;
import gyro.core.resource.Output;
import gyro.core.resource.Updatable;
import gyro.core.validation.Range;
import gyro.core.validation.Regex;
import gyro.core.validation.Required;
import gyro.google.Copyable;
Expand Down Expand Up @@ -116,7 +115,6 @@ public void setStartTime(String startTime) {
* The number of days of transaction logs we retain for point in time restore, from 1-7.
*/
@Updatable
@Range(min = 1, max = 7)
public Integer getTransactionLogRetentionDays() {
return transactionLogRetentionDays;
}
Expand Down Expand Up @@ -149,7 +147,7 @@ public void copyFrom(BackupConfiguration model) throws Exception {

setBackupRetentionSettings(null);
if (model.getBackupRetentionSettings() != null) {
DbBackupRetentionSettings settings = new DbBackupRetentionSettings();
DbBackupRetentionSettings settings = newSubresource(DbBackupRetentionSettings.class);
settings.copyFrom(model.getBackupRetentionSettings());
setBackupRetentionSettings(settings);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public String primaryKey() {

@Override
public void copyFrom(DiskEncryptionConfiguration model) throws Exception {
setKey(findById(CryptoKeyResource.class, model.getKmsKeyName()));
setKey(null);
if (model.getKmsKeyName() != null) {
setKey(findById(CryptoKeyResource.class, model.getKmsKeyName()));
}
}

public DiskEncryptionConfiguration toDiskEncryptionConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ public String primaryKey() {

@Override
public void copyFrom(DiskEncryptionStatus model) throws Exception {
setKeyVersion(findById(CryptoKeyVersionResource.class, model.getKmsKeyVersionName()));
setKeyVersion(null);
if (model.getKmsKeyVersionName() != null) {
setKeyVersion(findById(CryptoKeyVersionResource.class, model.getKmsKeyVersionName()));
}
}

public DiskEncryptionStatus toDiskEncryptionStatus() {
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/gyro/google/cloudsql/DbIpConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,27 @@ public void copyFrom(IpConfiguration model) throws Exception {
setIpv4Enabled(model.getIpv4Enabled());
setServerCaMode(model.getServerCaMode());
setSslMode(model.getSslMode());
setPrivateNetwork(findById(NetworkResource.class, model.getPrivateNetwork()));

setPrivateNetwork(null);
String network = model.getPrivateNetwork();
String selfLinkPrefix = "https://www.googleapis.com/compute/v1/";
if (network != null) {
network = network.startsWith(selfLinkPrefix) ? network : selfLinkPrefix + network;
setPrivateNetwork(findById(NetworkResource.class, network));
}

getAuthorizedNetworks().clear();
if (model.getAuthorizedNetworks() != null) {
getAuthorizedNetworks().addAll(model.getAuthorizedNetworks().stream().map(n -> {
DbAclEntry entry = new DbAclEntry();
DbAclEntry entry = newSubresource(DbAclEntry.class);
entry.copyFrom(n);
return entry;
}).collect(Collectors.toList()));
}

setPscConfig(null);
if (model.getPscConfig() != null) {
DbPscConfig config = new DbPscConfig();
DbPscConfig config = newSubresource(DbPscConfig.class);
config.copyFrom(model.getPscConfig());
setPscConfig(config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void copyFrom(ReplicaConfiguration model) throws Exception {

setMysqlReplicaConfiguration(null);
if (model.getMysqlReplicaConfiguration() != null) {
DbMySqlReplicaConfiguration config = new DbMySqlReplicaConfiguration();
DbMySqlReplicaConfiguration config = newSubresource(DbMySqlReplicaConfiguration.class);
config.copyFrom(model.getMysqlReplicaConfiguration());
setMysqlReplicaConfiguration(config);
}
Expand Down
21 changes: 4 additions & 17 deletions src/main/java/gyro/google/cloudsql/DbSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import gyro.core.resource.Output;
import gyro.core.resource.Updatable;
import gyro.core.validation.Range;
import gyro.core.validation.Required;
import gyro.core.validation.ValidStrings;
import gyro.google.Copyable;

Expand Down Expand Up @@ -410,23 +411,7 @@ public void setStorageAutoResizeLimit(Long storageAutoResizeLimit) {
* The tier (or machine type) for this instance.
*/
@Updatable
@ValidStrings({
"db-custom-1-3840",
"db-custom-2-7680",
"db-custom-4-15360",
"db-custom-8-30720",
"db-custom-16-61440",
"db-custom-32-122880",
"db-custom-64-245760",
"db-custom-96-368640",
"db-custom-2-13312",
"db-custom-4-26624",
"db-custom-8-53248",
"db-custom-16-106496",
"db-custom-32-212992",
"db-custom-64-425984",
"db-custom-96-638976"
})
@Required
public String getTier() {
return tier;
}
Expand Down Expand Up @@ -643,6 +628,7 @@ public Settings toSettings() {
for (DbDatabaseFlag flag : getDatabaseFlags()) {
flags.add(flag.toDatabaseFlags());
}

settings.setDatabaseFlags(flags);
}

Expand All @@ -659,6 +645,7 @@ public Settings toSettings() {
for (DbDenyMaintenancePeriod period : getDenyMaintenancePeriods()) {
periods.add(period.toDenyMaintenancePeriod());
}

settings.setDenyMaintenancePeriods(periods);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ public void setUploadInterval(String uploadInterval) {

@Override
public void copyFrom(SqlServerAuditConfig model) throws Exception {
setBucket(findById(BucketResource.class, model.getBucket()));
setBucket(null);
if (model.getBucket() != null) {
setBucket(findById(BucketResource.class, model.getBucket()));
}
setRetentionInterval(model.getRetentionInterval());
setUploadInterval(model.getUploadInterval());
}
Expand Down

0 comments on commit f2b3218

Please sign in to comment.