Skip to content

Commit

Permalink
Fixes to support ACL.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Sung committed Aug 7, 2020
1 parent d5961cb commit 8e88cdc
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/main/java/gyro/google/GoogleStorageFileBackend.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 8e88cdc

Please sign in to comment.