Configurable endpoint for transient blobstore

Fixes issue 569.
This commit is contained in:
Andrew Gaul 2011-10-07 14:42:52 -07:00
parent 842da34982
commit 49d07239d2
3 changed files with 27 additions and 18 deletions

View File

@ -31,6 +31,7 @@ import org.jclouds.blobstore.options.GetOptions;
import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpUtils;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.location.Provider;
/**
*
@ -41,23 +42,25 @@ public class TransientBlobRequestSigner implements BlobRequestSigner {
private final BasicAuthentication basicAuth;
private final BlobToHttpGetOptions blob2HttpGetOptions;
private final String endpoint;
@Inject
public TransientBlobRequestSigner(BasicAuthentication basicAuth, BlobToHttpGetOptions blob2HttpGetOptions) {
public TransientBlobRequestSigner(BasicAuthentication basicAuth, BlobToHttpGetOptions blob2HttpGetOptions, @Provider URI endpoint) {
this.basicAuth = checkNotNull(basicAuth, "basicAuth");
this.blob2HttpGetOptions = checkNotNull(blob2HttpGetOptions, "blob2HttpGetOptions");
this.endpoint = endpoint.toString();
}
@Override
public HttpRequest signGetBlob(String container, String name) {
HttpRequest request = new HttpRequest("GET", URI.create(String.format("http://localhost/%s/%s", container, name)));
HttpRequest request = new HttpRequest("GET", URI.create(String.format("%s/%s/%s", endpoint, container, name)));
return basicAuth.filter(request);
}
@Override
public HttpRequest signPutBlob(String container, Blob blob) {
HttpRequest request = HttpRequest.builder().method("PUT").endpoint(
URI.create(String.format("http://localhost/%s/%s", container, blob.getMetadata().getName()))).payload(
URI.create(String.format("%s/%s/%s", endpoint, container, blob.getMetadata().getName()))).payload(
blob.getPayload()).headers(
HttpUtils.getContentHeadersFromMetadata(blob.getMetadata().getContentMetadata())).build();
return basicAuth.filter(request);
@ -65,7 +68,7 @@ public class TransientBlobRequestSigner implements BlobRequestSigner {
@Override
public HttpRequest signRemoveBlob(String container, String name) {
HttpRequest request = new HttpRequest("DELETE", URI.create(String.format("http://localhost/%s/%s", container,
HttpRequest request = new HttpRequest("DELETE", URI.create(String.format("%s/%s/%s", endpoint, container,
name)));
return basicAuth.filter(request);
}
@ -73,7 +76,7 @@ public class TransientBlobRequestSigner implements BlobRequestSigner {
@Override
public HttpRequest signGetBlob(String container, String name, GetOptions options) {
HttpRequest request = HttpRequest.builder().method("GET").endpoint(
URI.create(String.format("http://localhost/%s/%s", container, name))).headers(
URI.create(String.format("%s/%s/%s", endpoint, container, name))).headers(
blob2HttpGetOptions.apply(options).buildRequestHeaders()).build();
return basicAuth.filter(request);
}

View File

@ -37,7 +37,7 @@ public class TransientBlobStorePropertiesBuilder extends PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ENDPOINT, "http://localhost/transient");
properties.setProperty(PROPERTY_ENDPOINT, "http://localhost");
properties.setProperty(PROPERTY_API_VERSION, "1");
properties.setProperty(PROPERTY_IDENTITY, System.getProperty("user.name"));
properties.setProperty(PROPERTY_USER_THREADS, "0");

View File

@ -48,12 +48,16 @@ public class TransientBlobRequestSignerTest extends RestClientTest<TransientAsyn
private BlobRequestSigner signer;
private Provider<BlobBuilder> blobFactory;
private final String endPoint = "http://localhost:8080";
private final String containerName = "container";
private final String blobName = "blob";
private final String fullUrl = String.format("%s/%s/%s", endPoint, containerName, blobName);
public void testSignGetBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
NoSuchMethodException, IOException {
HttpRequest request = signer.signGetBlob("container", "name");
HttpRequest request = signer.signGetBlob(containerName, blobName);
assertRequestLineEquals(request, "GET http://localhost/container/name HTTP/1.1");
assertRequestLineEquals(request, "GET " + fullUrl + " HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Authorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
assertPayloadEquals(request, null, null, false);
@ -62,9 +66,9 @@ public class TransientBlobRequestSignerTest extends RestClientTest<TransientAsyn
public void testSignRemoveBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
NoSuchMethodException, IOException {
HttpRequest request = signer.signRemoveBlob("container", "name");
HttpRequest request = signer.signRemoveBlob(containerName, blobName);
assertRequestLineEquals(request, "DELETE http://localhost/container/name HTTP/1.1");
assertRequestLineEquals(request, "DELETE " + fullUrl + " HTTP/1.1");
assertNonPayloadHeadersEqual(request, "Authorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n");
assertPayloadEquals(request, null, null, false);
@ -73,14 +77,14 @@ public class TransientBlobRequestSignerTest extends RestClientTest<TransientAsyn
public void testSignPutBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
NoSuchMethodException, IOException {
Blob blob = blobFactory.get().name("name").forSigning().contentLength(2l).contentMD5(new byte[] { 0, 2, 4, 8 })
Blob blob = blobFactory.get().name(blobName).forSigning().contentLength(2l).contentMD5(new byte[] { 0, 2, 4, 8 })
.contentType("text/plain").build();
assertEquals(blob.getPayload().getContentMetadata().getContentMD5(), new byte[] { 0, 2, 4, 8 });
HttpRequest request = signer.signPutBlob("container", blob);
HttpRequest request = signer.signPutBlob(containerName, blob);
assertRequestLineEquals(request, "PUT http://localhost/container/name HTTP/1.1");
assertRequestLineEquals(request, "PUT " + fullUrl + " HTTP/1.1");
assertNonPayloadHeadersEqual(
request,
"Authorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\nContent-Length: 2\nContent-MD5: AAIECA==\nContent-Type: text/plain\n");
@ -91,14 +95,14 @@ public class TransientBlobRequestSignerTest extends RestClientTest<TransientAsyn
public void testSignPutBlobWithGenerate() throws ArrayIndexOutOfBoundsException, SecurityException,
IllegalArgumentException, NoSuchMethodException, IOException {
Blob blob = blobFactory.get().name("name").payload("foo").calculateMD5().contentType("text/plain").build();
Blob blob = blobFactory.get().name(blobName).payload("foo").calculateMD5().contentType("text/plain").build();
assertEquals(blob.getPayload().getContentMetadata().getContentMD5(), new byte[] { -84, -67, 24, -37, 76, -62, -8,
92, -19, -17, 101, 79, -52, -60, -92, -40 });
HttpRequest request = signer.signPutBlob("container", blob);
HttpRequest request = signer.signPutBlob(containerName, blob);
assertRequestLineEquals(request, "PUT http://localhost/container/name HTTP/1.1");
assertRequestLineEquals(request, "PUT " + fullUrl + " HTTP/1.1");
assertNonPayloadHeadersEqual(
request,
"Authorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\nContent-Length: 3\nContent-MD5: rL0Y20zC+Fzt72VPzMSk2A==\nContent-Type: text/plain\n");
@ -121,7 +125,9 @@ public class TransientBlobRequestSignerTest extends RestClientTest<TransientAsyn
@Override
public RestContextSpec<?, ?> createContextSpec() {
return new RestContextFactory().createContextSpec("transient", "identity", "credential", new Properties());
Properties properties = new Properties();
properties.setProperty("transient.endpoint", endPoint);
return new RestContextFactory().createContextSpec("transient", "identity", "credential", properties);
}
@Override
@ -130,4 +136,4 @@ public class TransientBlobRequestSignerTest extends RestClientTest<TransientAsyn
};
}
}
}