From 50871a55ecb4c3ef1a92a2d06faeee2eab96dc25 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Tue, 28 Jul 2015 15:19:05 -0700 Subject: [PATCH] Partially emulate arbitrary markers with GCS S3 supports arbitrary keys for the marker while GCS only supports its opaque marker. Emulate the common case for GCS by mapping the last key from a listing to the corresponding previously returned marker. --- .../java/org/gaul/s3proxy/S3ProxyHandler.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java b/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java index 537fe80..158f7bf 100644 --- a/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java +++ b/src/main/java/org/gaul/s3proxy/S3ProxyHandler.java @@ -158,6 +158,11 @@ final class S3ProxyHandler extends AbstractHandler { "bucket-owner-full-control", "log-delivery-write" ); + /** Blobstores with opaque markers. */ + private static final Set BLOBSTORE_OPAQUE_MARKERS = ImmutableSet.of( + "azureblob", + "google-cloud-storage" + ); private final boolean anonymousIdentity; private final Optional virtualHost; @@ -169,9 +174,10 @@ final class S3ProxyHandler extends AbstractHandler { // TODO: hack to allow per-request anonymous access private final BlobStore defaultBlobStore; /** - * S3 supports arbitrary keys for the marker while Azure only supports its - * opaque marker. Emulate the common case for Azure by mapping the last - * key from a listing to the corresponding previously returned marker. + * S3 supports arbitrary keys for the marker while some blobstores only + * support opaque markers. Emulate the common case for these by mapping + * the last key from a listing to the corresponding previously returned + * marker. */ private final Cache, String> lastKeyToMarker = CacheBuilder.newBuilder() @@ -874,7 +880,7 @@ final class S3ProxyHandler extends AbstractHandler { } String marker = request.getParameter("marker"); if (marker != null) { - if (blobStoreType.equals("azureblob")) { + if (BLOBSTORE_OPAQUE_MARKERS.contains(blobStoreType)) { String realMarker = lastKeyToMarker.getIfPresent( Maps.immutableEntry(containerName, marker)); if (realMarker != null) { @@ -930,7 +936,7 @@ final class S3ProxyHandler extends AbstractHandler { if (nextMarker != null) { writeSimpleElement(xml, "IsTruncated", "true"); writeSimpleElement(xml, "NextMarker", nextMarker); - if (blobStoreType.equals("azureblob")) { + if (BLOBSTORE_OPAQUE_MARKERS.contains(blobStoreType)) { lastKeyToMarker.put(Maps.immutableEntry(containerName, Iterables.getLast(set).getName()), nextMarker); }