diff --git a/src/main/java/io/github/hectorvent/floci/services/backup/model/BackupRule.java b/src/main/java/io/github/hectorvent/floci/services/backup/model/BackupRule.java index 3ba221ac1e..0fc3496289 100644 --- a/src/main/java/io/github/hectorvent/floci/services/backup/model/BackupRule.java +++ b/src/main/java/io/github/hectorvent/floci/services/backup/model/BackupRule.java @@ -1,6 +1,7 @@ package io.github.hectorvent.floci.services.backup.model; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import io.quarkus.runtime.annotations.RegisterForReflection; @@ -19,6 +20,10 @@ public class BackupRule { @JsonProperty("TargetBackupVaultName") private String targetBackupVaultName; + @JsonProperty("TargetLogicallyAirGappedBackupVaultArn") + @JsonInclude(JsonInclude.Include.NON_NULL) + private String targetLogicallyAirGappedBackupVaultArn; + @JsonProperty("ScheduleExpression") private String scheduleExpression; @@ -54,6 +59,9 @@ public class BackupRule { public String getTargetBackupVaultName() { return targetBackupVaultName; } public void setTargetBackupVaultName(String targetBackupVaultName) { this.targetBackupVaultName = targetBackupVaultName; } + public String getTargetLogicallyAirGappedBackupVaultArn() { return targetLogicallyAirGappedBackupVaultArn; } + public void setTargetLogicallyAirGappedBackupVaultArn(String targetLogicallyAirGappedBackupVaultArn) { this.targetLogicallyAirGappedBackupVaultArn = targetLogicallyAirGappedBackupVaultArn; } + public String getScheduleExpression() { return scheduleExpression; } public void setScheduleExpression(String scheduleExpression) { this.scheduleExpression = scheduleExpression; } diff --git a/src/test/java/io/github/hectorvent/floci/services/backup/BackupIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/backup/BackupIntegrationTest.java index 8a93bebdae..20f17f2a17 100644 --- a/src/test/java/io/github/hectorvent/floci/services/backup/BackupIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/backup/BackupIntegrationTest.java @@ -1989,4 +1989,36 @@ class BackupIntegrationTest { backupService.deleteRecoveryPoint(vault, point, "us-east-1"); backupService.deleteBackupVault(vault, "us-east-1"); } + + @Test + void ruleKeepsTargetLogicallyAirGappedBackupVaultArn() { + String airGapped = "arn:aws:backup:us-east-1:000000000000:backup-vault:air-gapped"; + String rule = """ + {"RuleName": "%s", "TargetBackupVaultName": "%s", "ScheduleExpression": "cron(0 12 * * ? *)"%s}"""; + String withArn = rule.formatted("air", VAULT_NAME, + ", \"TargetLogicallyAirGappedBackupVaultArn\": \"" + airGapped + "\""); + String without = rule.formatted("plain", VAULT_NAME, ""); + String id = given().header("Authorization", AUTH).contentType("application/json") + .body("{\"BackupPlan\": {\"BackupPlanName\": \"air-gapped-plan\", \"Rules\": [" + + withArn + ", " + without + "]}}") + .when().put("/backup/plans/").then().statusCode(200) + .extract().path("BackupPlanId"); + given().header("Authorization", AUTH).when().get("/backup/plans/" + id + "/").then().statusCode(200) + .body("BackupPlan.Rules[0].TargetLogicallyAirGappedBackupVaultArn", equalTo(airGapped)) + .body("BackupPlan.Rules[1]", not(hasKey("TargetLogicallyAirGappedBackupVaultArn"))); + + // UpdateBackupPlan swaps which rule carries it; GetBackupPlan must reflect the update. + String updatedWith = rule.formatted("plain", VAULT_NAME, + ", \"TargetLogicallyAirGappedBackupVaultArn\": \"" + airGapped + "-2\""); + String updatedWithout = rule.formatted("air", VAULT_NAME, ""); + given().header("Authorization", AUTH).contentType("application/json") + .body("{\"BackupPlan\": {\"BackupPlanName\": \"air-gapped-plan\", \"Rules\": [" + + updatedWithout + ", " + updatedWith + "]}}") + .when().post("/backup/plans/" + id).then().statusCode(200); + given().header("Authorization", AUTH).when().get("/backup/plans/" + id + "/").then().statusCode(200) + .body("BackupPlan.Rules[0].RuleName", equalTo("air")) + .body("BackupPlan.Rules[0]", not(hasKey("TargetLogicallyAirGappedBackupVaultArn"))) + .body("BackupPlan.Rules[1].TargetLogicallyAirGappedBackupVaultArn", equalTo(airGapped + "-2")); + given().header("Authorization", AUTH).when().delete("/backup/plans/" + id); + } }