kopia lustrzana https://github.com/jortage/poolmgr
Fix paths being lost, remove bucket names for compat
rodzic
9e91a779fd
commit
6bff25a76e
|
@ -13,6 +13,9 @@ dependencies {
|
|||
implementation 'org.gaul:s3proxy:1.6.1'
|
||||
}
|
||||
|
||||
project.configurations.implementation.setCanBeResolved(true)
|
||||
|
||||
task capsule(type: FatCapsule) {
|
||||
embedConfiguration configurations.implementation
|
||||
applicationClass 'com.jortage.proxy.JortageProxy'
|
||||
}
|
|
@ -30,6 +30,7 @@ import org.jclouds.domain.Location;
|
|||
import org.jclouds.io.Payload;
|
||||
import org.jclouds.io.payloads.FilePayload;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.hash.Hashing;
|
||||
import com.google.common.hash.HashingOutputStream;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
@ -46,12 +47,19 @@ public class JortageBlobStore extends ForwardingBlobStore {
|
|||
this.paths = paths;
|
||||
}
|
||||
|
||||
private String buildKey(String container, String name) {
|
||||
return JortageProxy.buildKey(identity, container, name);
|
||||
private String buildKey(String name) {
|
||||
return JortageProxy.buildKey(identity, name);
|
||||
}
|
||||
|
||||
private void checkContainer(String container) {
|
||||
if (!Objects.equal(container, identity)) {
|
||||
throw new IllegalArgumentException("Bucket name must match your access ID");
|
||||
}
|
||||
}
|
||||
|
||||
private String map(String container, String name) {
|
||||
String hash = paths.get(buildKey(container, name));
|
||||
checkContainer(container);
|
||||
String hash = paths.get(buildKey(name));
|
||||
if (hash == null) throw new IllegalArgumentException("Not found");
|
||||
return JortageProxy.hashToPath(hash);
|
||||
}
|
||||
|
@ -119,6 +127,7 @@ public class JortageBlobStore extends ForwardingBlobStore {
|
|||
|
||||
@Override
|
||||
public String putBlob(String container, Blob blob) {
|
||||
checkContainer(container);
|
||||
File tempFile = null;
|
||||
try {
|
||||
File f = File.createTempFile("jortage-proxy-", ".dat");
|
||||
|
@ -134,14 +143,16 @@ public class JortageBlobStore extends ForwardingBlobStore {
|
|||
try (Payload payload = new FilePayload(f)) {
|
||||
payload.getContentMetadata().setContentType(contentType);
|
||||
if (delegate().blobExists(bucket, JortageProxy.hashToPath(hash))) {
|
||||
return delegate().blobMetadata(bucket, JortageProxy.hashToPath(hash)).getETag();
|
||||
String etag = delegate().blobMetadata(bucket, JortageProxy.hashToPath(hash)).getETag();
|
||||
paths.put(buildKey(blob.getMetadata().getName()), hash);
|
||||
return etag;
|
||||
}
|
||||
Blob blob2 = blobBuilder(JortageProxy.hashToPath(hash))
|
||||
.payload(payload)
|
||||
.userMetadata(blob.getMetadata().getUserMetadata())
|
||||
.build();
|
||||
String etag = delegate().putBlob(bucket, blob2, new PutOptions().setBlobAccess(BlobAccess.PUBLIC_READ));
|
||||
paths.put(buildKey(container, blob.getMetadata().getName()), hash);
|
||||
paths.put(buildKey(blob.getMetadata().getName()), hash);
|
||||
return etag;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -37,7 +37,7 @@ import blue.endless.jankson.JsonPrimitive;
|
|||
|
||||
public class JortageProxy {
|
||||
|
||||
private static final Splitter SPLITTER = Splitter.on('/').limit(3).omitEmptyStrings();
|
||||
private static final Splitter SPLITTER = Splitter.on('/').limit(2).omitEmptyStrings();
|
||||
|
||||
private static final File configFile = new File("config.jkson");
|
||||
private static JsonObject config;
|
||||
|
@ -99,9 +99,8 @@ public class JortageProxy {
|
|||
System.out.println(en);
|
||||
}
|
||||
String identity = split.get(0);
|
||||
String container = split.get(1);
|
||||
String name = split.get(2);
|
||||
String key = buildKey(identity, container, name);
|
||||
String name = split.get(1);
|
||||
String key = buildKey(identity, name);
|
||||
if (paths.containsKey(key)) {
|
||||
response.setHeader("Location", publicHost+"/"+hashToPath(paths.get(key)));
|
||||
response.setStatus(301);
|
||||
|
@ -144,8 +143,8 @@ public class JortageProxy {
|
|||
}
|
||||
}
|
||||
|
||||
public static String buildKey(String identity, String container, String name) {
|
||||
return identity+":"+container+":"+name;
|
||||
public static String buildKey(String identity, String name) {
|
||||
return identity+":"+name;
|
||||
}
|
||||
|
||||
public static String hashToPath(String hash) {
|
||||
|
|
Ładowanie…
Reference in New Issue