kopia lustrzana https://github.com/gaul/s3proxy
Centralize blobstore quirks
rodzic
744d126331
commit
587a4a6670
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright 2014-2016 Andrew Gaul <andrew@gaul.org>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.gaul.s3proxy;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
final class Quirks {
|
||||
/** Blobstores which do not support blob-level access control. */
|
||||
static final Set<String> NO_BLOB_ACCESS_CONTROL = ImmutableSet.of(
|
||||
"azureblob",
|
||||
"rackspace-cloudfiles-uk",
|
||||
"rackspace-cloudfiles-us",
|
||||
"openstack-swift"
|
||||
);
|
||||
|
||||
/** Blobstores which do not support the Cache-Control header. */
|
||||
static final Set<String> NO_CACHE_CONTROL_SUPPORT = ImmutableSet.of(
|
||||
"atmos",
|
||||
"rackspace-cloudfiles-uk",
|
||||
"rackspace-cloudfiles-us",
|
||||
"openstack-swift"
|
||||
);
|
||||
|
||||
/** Blobstores which do not support the Content-Language header. */
|
||||
static final Set<String> NO_CONTENT_LANGUAGE = ImmutableSet.of(
|
||||
"rackspace-cloudfiles-uk",
|
||||
"rackspace-cloudfiles-us",
|
||||
"openstack-swift"
|
||||
);
|
||||
|
||||
/** Blobstores with opaque ETags. */
|
||||
static final Set<String> OPAQUE_ETAG = ImmutableSet.of(
|
||||
"azureblob",
|
||||
"google-cloud-storage"
|
||||
);
|
||||
|
||||
/** Blobstores with opaque markers. */
|
||||
static final Set<String> OPAQUE_MARKERS = ImmutableSet.of(
|
||||
"azureblob",
|
||||
"google-cloud-storage"
|
||||
);
|
||||
|
||||
private Quirks() {
|
||||
throw new AssertionError("Intentionally unimplemented");
|
||||
}
|
||||
}
|
|
@ -184,11 +184,6 @@ final class S3ProxyHandler extends AbstractHandler {
|
|||
"bucket-owner-full-control",
|
||||
"log-delivery-write"
|
||||
);
|
||||
/** Blobstores with opaque markers. */
|
||||
private static final Set<String> BLOBSTORE_OPAQUE_MARKERS = ImmutableSet.of(
|
||||
"azureblob",
|
||||
"google-cloud-storage"
|
||||
);
|
||||
|
||||
private final boolean anonymousIdentity;
|
||||
private final Optional<String> virtualHost;
|
||||
|
@ -1029,7 +1024,7 @@ final class S3ProxyHandler extends AbstractHandler {
|
|||
}
|
||||
String marker = request.getParameter("marker");
|
||||
if (marker != null) {
|
||||
if (BLOBSTORE_OPAQUE_MARKERS.contains(blobStoreType)) {
|
||||
if (Quirks.OPAQUE_MARKERS.contains(blobStoreType)) {
|
||||
String realMarker = lastKeyToMarker.getIfPresent(
|
||||
Maps.immutableEntry(containerName, marker));
|
||||
if (realMarker != null) {
|
||||
|
@ -1094,7 +1089,7 @@ final class S3ProxyHandler extends AbstractHandler {
|
|||
writeSimpleElement(xml, "IsTruncated", "true");
|
||||
writeSimpleElement(xml, "NextMarker", encodeBlob(
|
||||
encodingType, nextMarker));
|
||||
if (BLOBSTORE_OPAQUE_MARKERS.contains(blobStoreType)) {
|
||||
if (Quirks.OPAQUE_MARKERS.contains(blobStoreType)) {
|
||||
lastKeyToMarker.put(Maps.immutableEntry(containerName,
|
||||
Iterables.getLast(set).getName()), nextMarker);
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import java.security.cert.X509Certificate;
|
|||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
|
@ -64,7 +63,6 @@ import com.amazonaws.services.s3.model.UploadPartRequest;
|
|||
import com.amazonaws.services.s3.model.UploadPartResult;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.io.ByteSource;
|
||||
|
||||
import org.assertj.core.api.Fail;
|
||||
|
@ -86,11 +84,6 @@ public final class S3AwsSdkTest {
|
|||
disableSslVerification();
|
||||
}
|
||||
|
||||
/** Blobstores with opaque ETags. */
|
||||
private static final Set<String> BLOBSTORE_OPAQUE_ETAG = ImmutableSet.of(
|
||||
"azureblob",
|
||||
"google-cloud-storage"
|
||||
);
|
||||
private static final ByteSource BYTE_SOURCE = ByteSource.wrap(new byte[1]);
|
||||
|
||||
private URI s3Endpoint;
|
||||
|
@ -116,7 +109,7 @@ public final class S3AwsSdkTest {
|
|||
info.getBlobStore().createContainerInLocation(null, containerName);
|
||||
|
||||
String blobStoreType = context.unwrap().getProviderMetadata().getId();
|
||||
if (BLOBSTORE_OPAQUE_ETAG.contains(blobStoreType)) {
|
||||
if (Quirks.OPAQUE_ETAG.contains(blobStoreType)) {
|
||||
// AWK SDK checks that ETag matches Content-MD5 during PUT
|
||||
System.setProperty(
|
||||
"com.amazonaws.services.s3.disablePutObjectMD5Validation",
|
||||
|
|
|
@ -24,7 +24,6 @@ import java.net.URI;
|
|||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
@ -70,18 +69,6 @@ import org.junit.Test;
|
|||
|
||||
public final class S3ProxyTest {
|
||||
private static final ByteSource BYTE_SOURCE = ByteSource.wrap(new byte[1]);
|
||||
private static final Set<String> BLOBSTORE_NO_CACHE_CONTROL_SUPPORT =
|
||||
ImmutableSet.of(
|
||||
"atmos",
|
||||
"rackspace-cloudfiles-uk",
|
||||
"rackspace-cloudfiles-us",
|
||||
"openstack-swift"
|
||||
);
|
||||
private static final Set<String> SWIFT_BLOBSTORES = ImmutableSet.of(
|
||||
"rackspace-cloudfiles-uk",
|
||||
"rackspace-cloudfiles-us",
|
||||
"openstack-swift"
|
||||
);
|
||||
|
||||
private URI s3Endpoint;
|
||||
private S3Proxy s3Proxy;
|
||||
|
@ -138,9 +125,7 @@ public final class S3ProxyTest {
|
|||
.build();
|
||||
blobStore.putBlob(containerName, blob);
|
||||
|
||||
if (blobStoreType.equals("azureblob") ||
|
||||
SWIFT_BLOBSTORES.contains(blobStoreType)) {
|
||||
// Azure and Swift do not support blob access control
|
||||
if (Quirks.NO_BLOB_ACCESS_CONTROL.contains(blobStoreType)) {
|
||||
blobStore.setContainerAccess(containerName,
|
||||
ContainerAccess.PUBLIC_READ);
|
||||
} else {
|
||||
|
@ -405,7 +390,7 @@ public final class S3ProxyTest {
|
|||
}
|
||||
ContentMetadata newContentMetadata =
|
||||
newBlob.getMetadata().getContentMetadata();
|
||||
if (!BLOBSTORE_NO_CACHE_CONTROL_SUPPORT.contains(blobStoreType)) {
|
||||
if (!Quirks.NO_CACHE_CONTROL_SUPPORT.contains(blobStoreType)) {
|
||||
assertThat(newContentMetadata.getCacheControl()).isEqualTo(
|
||||
cacheControl);
|
||||
}
|
||||
|
@ -413,7 +398,7 @@ public final class S3ProxyTest {
|
|||
contentDisposition);
|
||||
assertThat(newContentMetadata.getContentEncoding()).isEqualTo(
|
||||
contentEncoding);
|
||||
if (!SWIFT_BLOBSTORES.contains(blobStoreType)) {
|
||||
if (!Quirks.NO_CONTENT_LANGUAGE.contains(blobStoreType)) {
|
||||
assertThat(newContentMetadata.getContentLanguage()).isEqualTo(
|
||||
contentLanguage);
|
||||
}
|
||||
|
@ -474,7 +459,7 @@ public final class S3ProxyTest {
|
|||
}
|
||||
ContentMetadata newContentMetadata =
|
||||
newBlob.getMetadata().getContentMetadata();
|
||||
if (!BLOBSTORE_NO_CACHE_CONTROL_SUPPORT.contains(blobStoreType)) {
|
||||
if (!Quirks.NO_CACHE_CONTROL_SUPPORT.contains(blobStoreType)) {
|
||||
assertThat(newContentMetadata.getCacheControl()).isEqualTo(
|
||||
cacheControl);
|
||||
}
|
||||
|
@ -482,7 +467,7 @@ public final class S3ProxyTest {
|
|||
contentDisposition);
|
||||
assertThat(newContentMetadata.getContentEncoding()).isEqualTo(
|
||||
contentEncoding);
|
||||
if (!SWIFT_BLOBSTORES.contains(blobStoreType)) {
|
||||
if (!Quirks.NO_CONTENT_LANGUAGE.contains(blobStoreType)) {
|
||||
assertThat(newContentMetadata.getContentLanguage()).isEqualTo(
|
||||
contentLanguage);
|
||||
}
|
||||
|
@ -563,7 +548,7 @@ public final class S3ProxyTest {
|
|||
}
|
||||
ContentMetadata contentMetadata =
|
||||
toBlob.getMetadata().getContentMetadata();
|
||||
if (!BLOBSTORE_NO_CACHE_CONTROL_SUPPORT.contains(blobStoreType)) {
|
||||
if (!Quirks.NO_CACHE_CONTROL_SUPPORT.contains(blobStoreType)) {
|
||||
assertThat(contentMetadata.getCacheControl()).isEqualTo(
|
||||
cacheControl);
|
||||
}
|
||||
|
@ -571,7 +556,7 @@ public final class S3ProxyTest {
|
|||
contentDisposition);
|
||||
assertThat(contentMetadata.getContentEncoding()).isEqualTo(
|
||||
contentEncoding);
|
||||
if (!SWIFT_BLOBSTORES.contains(blobStoreType)) {
|
||||
if (!Quirks.NO_CONTENT_LANGUAGE.contains(blobStoreType)) {
|
||||
assertThat(contentMetadata.getContentLanguage()).isEqualTo(
|
||||
contentLanguage);
|
||||
}
|
||||
|
@ -630,7 +615,7 @@ public final class S3ProxyTest {
|
|||
}
|
||||
ContentMetadata toContentMetadata =
|
||||
toBlob.getMetadata().getContentMetadata();
|
||||
if (!BLOBSTORE_NO_CACHE_CONTROL_SUPPORT.contains(blobStoreType)) {
|
||||
if (!Quirks.NO_CACHE_CONTROL_SUPPORT.contains(blobStoreType)) {
|
||||
assertThat(contentMetadata.getCacheControl()).isEqualTo(
|
||||
cacheControl);
|
||||
}
|
||||
|
@ -638,7 +623,7 @@ public final class S3ProxyTest {
|
|||
contentDisposition);
|
||||
assertThat(toContentMetadata.getContentEncoding()).isEqualTo(
|
||||
contentEncoding);
|
||||
if (!SWIFT_BLOBSTORES.contains(blobStoreType)) {
|
||||
if (!Quirks.NO_CONTENT_LANGUAGE.contains(blobStoreType)) {
|
||||
assertThat(toContentMetadata.getContentLanguage()).isEqualTo(
|
||||
contentLanguage);
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue