Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(efs): implement UpdateFileSystemProtection and report protection on describe (#2842)

Allen Sanborndb182b3048b8
diff --git a/docs/services/efs.md b/docs/services/efs.md
index 6c7f03c276..d6ca5fd71b 100644
--- a/docs/services/efs.md
+++ b/docs/services/efs.md
@@ -13,6 +13,7 @@ The EFS emulator provides a metadata control plane for file systems, mount targe
| `CreateFileSystem` | - |
| `DescribeFileSystems` | - |
| `UpdateFileSystem` | - |
+| `UpdateFileSystemProtection` | - |
| `DeleteFileSystem` | - |
| `CreateTags` | - |
| `DescribeTags` | - |
diff --git a/src/main/java/io/github/hectorvent/floci/services/efs/EfsController.java b/src/main/java/io/github/hectorvent/floci/services/efs/EfsController.java
index b6a32f138f..4bb0b51839 100644
--- a/src/main/java/io/github/hectorvent/floci/services/efs/EfsController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/efs/EfsController.java
@@ -56,6 +56,14 @@ public class EfsController {
return Response.status(202).entity(fs).build();
}
+ @PUT
+ @Path("/file-systems/{FileSystemId}/protection")
+ public Response updateFileSystemProtection(@Context HttpHeaders headers, @PathParam("FileSystemId") String fileSystemId, UpdateFileSystemProtectionRequest request) {
+ String region = regionResolver.resolveRegion(headers);
+ FileSystemProtectionDescription protection = efsService.updateFileSystemProtection(region, fileSystemId, request);
+ return Response.ok(protection).build();
+ }
+
@DELETE
@Path("/file-systems/{FileSystemId}")
public Response deleteFileSystem(@Context HttpHeaders headers, @PathParam("FileSystemId") String fileSystemId) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/efs/EfsService.java b/src/main/java/io/github/hectorvent/floci/services/efs/EfsService.java
index 2aadda1578..3baefa2d7b 100644
--- a/src/main/java/io/github/hectorvent/floci/services/efs/EfsService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/efs/EfsService.java
@@ -112,6 +112,10 @@ public class EfsService implements Resettable {
size.setValueInStandard(0L);
fs.setSizeInBytes(size);
+ // "Replication overwrite protection is ENABLED by default" -- the file system is
+ // writeable and cannot be a replication destination until something disables it.
+ fs.setFileSystemProtection(protection(ReplicationOverwriteProtection.ENABLED));
+
fileSystemStore.put(regionKey, fs);
BackupPolicy bp = new BackupPolicy();
@@ -134,7 +138,7 @@ public class EfsService implements Resettable {
fs.setName(tag.getValue());
});
}
- return fs;
+ return withDefaultProtection(fs);
})
.sorted(Comparator.comparing(FileSystem::getFileSystemId))
.collect(Collectors.toList());
@@ -181,9 +185,40 @@ public class EfsService implements Resettable {
if (fs == null) {
throw EfsException.fileSystemNotFound(fileSystemId);
}
+ return withDefaultProtection(fs);
+ }
+
+ private static FileSystemProtectionDescription protection(ReplicationOverwriteProtection value) {
+ FileSystemProtectionDescription description = new FileSystemProtectionDescription();
+ description.setReplicationOverwriteProtection(value);
+ return description;
+ }
+
+ /**
+ * AWS always reports a protection status; there is no such thing as a file system
+ * without one. Applied on read as well as on create so that file systems already in
+ * a persisted store -- written before protection was modelled -- describe the same
+ * as one created today, rather than omitting the field.
+ */
+ private static FileSystem withDefaultProtection(FileSystem fs) {
+ if (fs.getFileSystemProtection() == null) {
+ fs.setFileSystemProtection(protection(ReplicationOverwriteProtection.ENABLED));
+ }
return fs;
}
+ public FileSystemProtectionDescription updateFileSystemProtection(
+ String region, String fileSystemId, UpdateFileSystemProtectionRequest request) {
+ synchronized (lockFor(regionKey(region, fileSystemId))) {
+ FileSystem fs = getFileSystem(region, fileSystemId);
+ if (request != null && request.getReplicationOverwriteProtection() != null) {
+ fs.setFileSystemProtection(protection(request.getReplicationOverwriteProtection()));
+ fileSystemStore.put(regionKey(region, fileSystemId), fs);
+ }
+ return fs.getFileSystemProtection();
+ }
+ }
+
public FileSystem updateFileSystem(String region, String fileSystemId, UpdateFileSystemRequest request) {
synchronized (lockFor(regionKey(region, fileSystemId))) {
FileSystem fs = getFileSystem(region, fileSystemId);
diff --git a/src/main/java/io/github/hectorvent/floci/services/efs/model/FileSystem.java b/src/main/java/io/github/hectorvent/floci/services/efs/model/FileSystem.java
index 0c49fec5c9..81d7435ea9 100644
--- a/src/main/java/io/github/hectorvent/floci/services/efs/model/FileSystem.java
+++ b/src/main/java/io/github/hectorvent/floci/services/efs/model/FileSystem.java
@@ -88,11 +88,16 @@ public class FileSystem {
this.fileSystemId = fileSystemId;
}
- public FileSystemProtectionDescription getFileSystemProtectionDescription() {
+ // The wire name is FileSystemProtection, not FileSystemProtectionDescription --
+ // FileSystemProtectionDescription is the *shape* name, and the member on
+ // FileSystemDescription that carries it is called FileSystemProtection. Because
+ // UpperCamelCaseStrategy derives the JSON key from the accessor, the old
+ // getFileSystemProtectionDescription() name put the shape name on the wire.
+ public FileSystemProtectionDescription getFileSystemProtection() {
return fileSystemProtection;
}
- public void setFileSystemProtectionDescription(FileSystemProtectionDescription fileSystemProtection) {
+ public void setFileSystemProtection(FileSystemProtectionDescription fileSystemProtection) {
this.fileSystemProtection = fileSystemProtection;
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/efs/model/UpdateFileSystemProtectionRequest.java b/src/main/java/io/github/hectorvent/floci/services/efs/model/UpdateFileSystemProtectionRequest.java
new file mode 100644
index 0000000000..2f806a8517
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/efs/model/UpdateFileSystemProtectionRequest.java
@@ -0,0 +1,22 @@
+package io.github.hectorvent.floci.services.efs.model;
+
+import io.quarkus.runtime.annotations.RegisterForReflection;
+
+import com.fasterxml.jackson.databind.annotation.JsonNaming;
+import com.fasterxml.jackson.databind.PropertyNamingStrategies;
+
+@JsonNaming(PropertyNamingStrategies.UpperCamelCaseStrategy.class)
+@RegisterForReflection
+public class UpdateFileSystemProtectionRequest {
+
+ private ReplicationOverwriteProtection replicationOverwriteProtection;
+
+ public ReplicationOverwriteProtection getReplicationOverwriteProtection() {
+ return replicationOverwriteProtection;
+ }
+
+ public void setReplicationOverwriteProtection(
+ ReplicationOverwriteProtection replicationOverwriteProtection) {
+ this.replicationOverwriteProtection = replicationOverwriteProtection;
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/services/efs/EfsIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/efs/EfsIntegrationTest.java
index c45d175b64..9a1e5d59d5 100644
--- a/src/test/java/io/github/hectorvent/floci/services/efs/EfsIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/efs/EfsIntegrationTest.java
@@ -46,6 +46,7 @@ class EfsIntegrationTest {
.body("FileSystemId", startsWith("fs-"))
.body("Encrypted", equalTo(true))
.body("NumberOfMountTargets", equalTo(0))
+ .body("FileSystemProtection.ReplicationOverwriteProtection", equalTo("ENABLED"))
.body("Tags[0].Value", equalTo("MyFS"))
.extract().jsonPath().getString("FileSystemId");
}
@@ -200,6 +201,63 @@ class EfsIntegrationTest {
@Test
@Order(10)
+ void describeReportsProtectionEnabledByDefault() {
+ given()
+ .queryParam("FileSystemId", fileSystemId)
+ .when()
+ .get("/2015-02-01/file-systems")
+ .then()
+ .statusCode(200)
+ .body("FileSystems[0].FileSystemProtection.ReplicationOverwriteProtection",
+ equalTo("ENABLED"));
+ }
+
+ @Test
+ @Order(11)
+ void updateFileSystemProtection() {
+ given()
+ .contentType("application/json")
+ .body("""
+ {
+ "ReplicationOverwriteProtection": "DISABLED"
+ }
+ """)
+ .when()
+ .put("/2015-02-01/file-systems/" + fileSystemId + "/protection")
+ .then()
+ .statusCode(200)
+ .body("ReplicationOverwriteProtection", equalTo("DISABLED"));
+
+ // The change has to survive the round trip, not just echo back: the terraform
+ // provider reads protection back through DescribeFileSystems.
+ given()
+ .queryParam("FileSystemId", fileSystemId)
+ .when()
+ .get("/2015-02-01/file-systems")
+ .then()
+ .statusCode(200)
+ .body("FileSystems[0].FileSystemProtection.ReplicationOverwriteProtection",
+ equalTo("DISABLED"));
+ }
+
+ @Test
+ @Order(12)
+ void updateFileSystemProtectionOnMissingFileSystemIs404() {
+ given()
+ .contentType("application/json")
+ .body("""
+ {
+ "ReplicationOverwriteProtection": "DISABLED"
+ }
+ """)
+ .when()
+ .put("/2015-02-01/file-systems/fs-does-not-exist/protection")
+ .then()
+ .statusCode(404);
+ }
+
+ @Test
+ @Order(13)
void deleteResources() {
given()
.contentType("application/json")