diff --git a/src/main/java/gyro/google/GoogleStorageFileBackend.java b/src/main/java/gyro/google/GoogleStorageFileBackend.java index e7c9df34..130b001c 100644 --- a/src/main/java/gyro/google/GoogleStorageFileBackend.java +++ b/src/main/java/gyro/google/GoogleStorageFileBackend.java @@ -29,6 +29,7 @@ import com.google.cloud.storage.StorageOptions; import com.psddev.dari.util.ObjectUtils; import gyro.core.FileBackend; +import gyro.core.FileBackendAccess; import gyro.core.GyroCore; import gyro.core.GyroException; import gyro.core.Type; @@ -87,8 +88,10 @@ public InputStream openInput(String file) throws Exception { } @Override - public OutputStream openOutput(String file) throws Exception { - return Channels.newOutputStream(service().writer(BlobInfo.newBuilder(getBucket(), prefixed(file)).build())); + public OutputStream openOutput(String file, FileBackendAccess acl) throws Exception { + return Channels.newOutputStream(service().writer( + BlobInfo.newBuilder(getBucket(), prefixed(file)).build(), + Storage.BlobWriteOption.predefinedAcl(predefinedAcl(acl)))); } @Override @@ -102,8 +105,14 @@ public boolean exists(String file) throws Exception { } @Override - public void copy(String source, String destination) throws Exception { - service().copy(Storage.CopyRequest.of(getBucket(), prefixed(source), prefixed(destination))).getResult(); + public void copy(String source, String destination, FileBackendAccess acl) throws Exception { + String bucket = getBucket(); + service().copy(Storage.CopyRequest.newBuilder() + .setSource(bucket, prefixed(source)) + .setTarget( + BlobInfo.newBuilder(bucket, prefixed(destination)).build(), + Storage.BlobTargetOption.predefinedAcl(predefinedAcl(acl))) + .build()).getResult(); } private Storage service() { @@ -131,4 +140,13 @@ private String removePrefix(String file) { return file; } + + private Storage.PredefinedAcl predefinedAcl(FileBackendAccess acl) { + Storage.PredefinedAcl predefinedAcl = Storage.PredefinedAcl.PRIVATE; + + if (acl == FileBackendAccess.PUBLIC) { + predefinedAcl = Storage.PredefinedAcl.PUBLIC_READ; + } + return predefinedAcl; + } }