kopia lustrzana https://github.com/gaul/s3proxy
add a way to lookup blobstore with a callback
remove the old map based lookuppull/52/head
rodzic
4ca219470e
commit
4450c6aebb
|
@ -0,0 +1,26 @@
|
|||
/*
|
||||
* Copyright 2014-2015 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.Map;
|
||||
|
||||
import org.jclouds.blobstore.BlobStore;
|
||||
|
||||
public interface BlobStoreLocator {
|
||||
Map.Entry<String, BlobStore> locateBlobStore(String identity,
|
||||
String container, String blob);
|
||||
}
|
|
@ -21,7 +21,6 @@ import static java.util.Objects.requireNonNull;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.google.common.base.Strings;
|
||||
|
@ -154,8 +153,8 @@ public final class S3Proxy {
|
|||
return server.getState();
|
||||
}
|
||||
|
||||
public void setProviders(
|
||||
Map<String, Map.Entry<String, BlobStore>> providers) {
|
||||
handler.setProviders(providers);
|
||||
public void setBlobStoreLocator(BlobStoreLocator lookup) {
|
||||
handler.setBlobStoreLocator(lookup);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ import java.util.ArrayList;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -151,22 +150,34 @@ final class S3ProxyHandler extends AbstractHandler {
|
|||
"log-delivery-write"
|
||||
);
|
||||
|
||||
private Map<String, Map.Entry<String, BlobStore>> providers =
|
||||
new HashMap<>();
|
||||
private final BlobStore defaultBlobStore;
|
||||
private final Optional<String> virtualHost;
|
||||
private final XMLInputFactory xmlInputFactory =
|
||||
XMLInputFactory.newInstance();
|
||||
private final XMLOutputFactory xmlOutputFactory =
|
||||
XMLOutputFactory.newInstance();
|
||||
private BlobStoreLocator blobStoreLocator;
|
||||
|
||||
S3ProxyHandler(BlobStore blobStore, String identity, String credential,
|
||||
Optional<String> virtualHost) {
|
||||
requireNonNull(blobStore);
|
||||
S3ProxyHandler(final BlobStore blobStore, String identity,
|
||||
final String credential, Optional<String> virtualHost) {
|
||||
if (identity != null) {
|
||||
providers.put(identity, Maps.immutableEntry(credential, blobStore));
|
||||
blobStoreLocator = new BlobStoreLocator() {
|
||||
@Override
|
||||
public Map.Entry<String, BlobStore> locateBlobStore(
|
||||
String identity, String container, String blob) {
|
||||
return Maps.immutableEntry(credential, blobStore);
|
||||
}
|
||||
};
|
||||
|
||||
defaultBlobStore = null;
|
||||
} else {
|
||||
blobStoreLocator = new BlobStoreLocator() {
|
||||
@Override
|
||||
public Map.Entry<String, BlobStore> locateBlobStore(
|
||||
String identity, String container, String blob) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
defaultBlobStore = blobStore;
|
||||
}
|
||||
this.virtualHost = requireNonNull(virtualHost);
|
||||
|
@ -278,9 +289,16 @@ final class S3ProxyHandler extends AbstractHandler {
|
|||
requestSignature = request.getParameter("Signature");
|
||||
}
|
||||
|
||||
String[] path = uri.split("/", 3);
|
||||
for (int i = 0; i < path.length; i++) {
|
||||
path[i] = URLDecoder.decode(path[i], "UTF-8");
|
||||
}
|
||||
|
||||
if (requestIdentity != null) {
|
||||
Map.Entry<String, BlobStore> provider =
|
||||
providers.get(requestIdentity);
|
||||
blobStoreLocator.locateBlobStore(
|
||||
requestIdentity, path.length > 1 ? path[1] : null,
|
||||
path.length > 2 ? path[2] : null);
|
||||
if (provider == null) {
|
||||
throw new S3Exception(S3ErrorCode.INVALID_ACCESS_KEY_ID);
|
||||
}
|
||||
|
@ -319,10 +337,6 @@ final class S3ProxyHandler extends AbstractHandler {
|
|||
}
|
||||
}
|
||||
|
||||
String[] path = uri.split("/", 3);
|
||||
for (int i = 0; i < path.length; i++) {
|
||||
path[i] = URLDecoder.decode(path[i], "UTF-8");
|
||||
}
|
||||
String uploadId = request.getParameter("uploadId");
|
||||
switch (method) {
|
||||
case "DELETE":
|
||||
|
@ -1647,9 +1661,8 @@ final class S3ProxyHandler extends AbstractHandler {
|
|||
}
|
||||
}
|
||||
|
||||
public void setProviders(
|
||||
Map<String, Map.Entry<String, BlobStore>> providers) {
|
||||
this.providers = ImmutableMap.copyOf(providers);
|
||||
public void setBlobStoreLocator(BlobStoreLocator locator) {
|
||||
this.blobStoreLocator = locator;
|
||||
}
|
||||
|
||||
static class S3Exception extends Exception {
|
||||
|
|
Ładowanie…
Reference in New Issue