mirror of https://github.com/apache/jclouds.git
added forSigning to blobBuilder
This commit is contained in:
parent
c352895ae2
commit
5ddf9aabca
|
@ -23,13 +23,14 @@ import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.inject.Provider;
|
||||||
|
|
||||||
import org.jclouds.blobstore.BlobRequestSigner;
|
import org.jclouds.blobstore.BlobRequestSigner;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.Blob.Factory;
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
import org.jclouds.date.TimeStamp;
|
import org.jclouds.date.TimeStamp;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.RequiresHttp;
|
import org.jclouds.http.RequiresHttp;
|
||||||
import org.jclouds.io.payloads.PhantomPayload;
|
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||||
import org.jclouds.s3.BaseS3AsyncClientTest;
|
import org.jclouds.s3.BaseS3AsyncClientTest;
|
||||||
|
@ -59,7 +60,7 @@ public class S3BlobRequestSignerTest extends BaseS3AsyncClientTest<S3AsyncClient
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlobRequestSigner signer;
|
private BlobRequestSigner signer;
|
||||||
private Factory blobFactory;
|
private Provider<BlobBuilder> blobFactory;
|
||||||
|
|
||||||
public void testSignGetBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
|
public void testSignGetBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
|
||||||
NoSuchMethodException, IOException {
|
NoSuchMethodException, IOException {
|
||||||
|
@ -89,12 +90,8 @@ public class S3BlobRequestSignerTest extends BaseS3AsyncClientTest<S3AsyncClient
|
||||||
|
|
||||||
public void testSignPutBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
|
public void testSignPutBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
|
||||||
NoSuchMethodException, IOException {
|
NoSuchMethodException, IOException {
|
||||||
Blob blob = blobFactory.create(null);
|
Blob blob = blobFactory.get().name("name").forSigning().contentLength(2l).contentMD5(new byte[] { 0, 2, 4, 8 }).contentType(
|
||||||
blob.getMetadata().setName("name");
|
"text/plain").build();
|
||||||
blob.setPayload(new PhantomPayload());
|
|
||||||
blob.getPayload().getContentMetadata().setContentLength(2l);
|
|
||||||
blob.getPayload().getContentMetadata().setContentMD5(new byte[] { 0, 2, 4, 8 });
|
|
||||||
blob.getPayload().getContentMetadata().setContentType("text/plain");
|
|
||||||
|
|
||||||
HttpRequest request = signer.signPutBlob("container", blob);
|
HttpRequest request = signer.signPutBlob("container", blob);
|
||||||
|
|
||||||
|
@ -111,7 +108,7 @@ public class S3BlobRequestSignerTest extends BaseS3AsyncClientTest<S3AsyncClient
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
protected void setupFactory() throws IOException {
|
protected void setupFactory() throws IOException {
|
||||||
super.setupFactory();
|
super.setupFactory();
|
||||||
this.blobFactory = injector.getInstance(Blob.Factory.class);
|
this.blobFactory = injector.getProvider(BlobBuilder.class);
|
||||||
this.signer = injector.getInstance(BlobRequestSigner.class);
|
this.signer = injector.getInstance(BlobRequestSigner.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,9 +20,9 @@
|
||||||
package org.jclouds.blobstore;
|
package org.jclouds.blobstore;
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
import org.jclouds.blobstore.internal.RequestSigningUnsupported;
|
import org.jclouds.blobstore.internal.RequestSigningUnsupported;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.io.payloads.PhantomPayload;
|
|
||||||
|
|
||||||
import com.google.inject.ImplementedBy;
|
import com.google.inject.ImplementedBy;
|
||||||
|
|
||||||
|
@ -65,10 +65,8 @@ public interface BlobRequestSigner {
|
||||||
* client.
|
* client.
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* Blob blob = context.getBlobStore.newBlob();
|
* Blob blob = context.getBlobStore.blobBuilder().name("name").forSigning().contentType("text/plain")
|
||||||
* blob.getMetadata().setName("name");
|
* .contentLength(length).build();
|
||||||
* blob.setPayload(new PhantomPayload(length, md5));
|
|
||||||
* blob.getPayload().setContentType("text/plain");
|
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @param container
|
* @param container
|
||||||
|
@ -77,7 +75,7 @@ public interface BlobRequestSigner {
|
||||||
* what to upload
|
* what to upload
|
||||||
* @throws UnsupportedOperationException
|
* @throws UnsupportedOperationException
|
||||||
* if not supported by the provider
|
* if not supported by the provider
|
||||||
* @see PhantomPayload
|
* @see BlobBuilder#forSigning
|
||||||
*/
|
*/
|
||||||
HttpRequest signPutBlob(String container, Blob blob);
|
HttpRequest signPutBlob(String container, Blob blob);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,11 @@ public interface BlobBuilder {
|
||||||
*/
|
*/
|
||||||
PayloadBlobBuilder payload(InputStream payload);
|
PayloadBlobBuilder payload(InputStream payload);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If you are creating a blob only for signing, use this. {@see BlobRequestSigner}
|
||||||
|
*/
|
||||||
|
PayloadBlobBuilder forSigning();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param payload
|
* @param payload
|
||||||
|
|
|
@ -38,6 +38,7 @@ import org.jclouds.blobstore.domain.StorageType;
|
||||||
import org.jclouds.crypto.Crypto;
|
import org.jclouds.crypto.Crypto;
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.io.Payload;
|
||||||
import org.jclouds.io.Payloads;
|
import org.jclouds.io.Payloads;
|
||||||
|
import org.jclouds.io.payloads.PhantomPayload;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
@ -225,5 +226,15 @@ public class BlobBuilderImpl implements BlobBuilder {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PayloadBlobBuilder forSigning() {
|
||||||
|
return builder.forSigning();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PayloadBlobBuilder forSigning() {
|
||||||
|
return payload(new PhantomPayload());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,10 +24,11 @@ import static org.testng.Assert.assertEquals;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import javax.inject.Provider;
|
||||||
|
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.domain.Blob.Factory;
|
import org.jclouds.blobstore.domain.BlobBuilder;
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.io.payloads.PhantomPayload;
|
|
||||||
import org.jclouds.rest.RestClientTest;
|
import org.jclouds.rest.RestClientTest;
|
||||||
import org.jclouds.rest.RestContextFactory;
|
import org.jclouds.rest.RestContextFactory;
|
||||||
import org.jclouds.rest.RestContextSpec;
|
import org.jclouds.rest.RestContextSpec;
|
||||||
|
@ -47,7 +48,7 @@ import com.google.inject.TypeLiteral;
|
||||||
public class TransientBlobRequestSignerTest extends RestClientTest<TransientAsyncBlobStore> {
|
public class TransientBlobRequestSignerTest extends RestClientTest<TransientAsyncBlobStore> {
|
||||||
|
|
||||||
private BlobRequestSigner signer;
|
private BlobRequestSigner signer;
|
||||||
private Factory blobFactory;
|
private Provider<BlobBuilder> blobFactory;
|
||||||
|
|
||||||
public void testSignGetBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
|
public void testSignGetBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
|
||||||
NoSuchMethodException, IOException {
|
NoSuchMethodException, IOException {
|
||||||
|
@ -73,12 +74,8 @@ public class TransientBlobRequestSignerTest extends RestClientTest<TransientAsyn
|
||||||
|
|
||||||
public void testSignPutBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
|
public void testSignPutBlob() throws ArrayIndexOutOfBoundsException, SecurityException, IllegalArgumentException,
|
||||||
NoSuchMethodException, IOException {
|
NoSuchMethodException, IOException {
|
||||||
Blob blob = blobFactory.create(null);
|
Blob blob = blobFactory.get().name("name").forSigning().contentLength(2l).contentMD5(new byte[] { 0, 2, 4, 8 })
|
||||||
blob.getMetadata().setName("name");
|
.contentType("text/plain").build();
|
||||||
blob.setPayload(new PhantomPayload());
|
|
||||||
blob.getPayload().getContentMetadata().setContentLength(2l);
|
|
||||||
blob.getPayload().getContentMetadata().setContentMD5(new byte[] { 0, 2, 4, 8 });
|
|
||||||
blob.getPayload().getContentMetadata().setContentType("text/plain");
|
|
||||||
|
|
||||||
HttpRequest request = signer.signPutBlob("container", blob);
|
HttpRequest request = signer.signPutBlob("container", blob);
|
||||||
|
|
||||||
|
@ -94,7 +91,7 @@ public class TransientBlobRequestSignerTest extends RestClientTest<TransientAsyn
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
protected void setupFactory() throws IOException {
|
protected void setupFactory() throws IOException {
|
||||||
super.setupFactory();
|
super.setupFactory();
|
||||||
this.blobFactory = injector.getInstance(Blob.Factory.class);
|
this.blobFactory = injector.getProvider(BlobBuilder.class);
|
||||||
this.signer = injector.getInstance(BlobRequestSigner.class);
|
this.signer = injector.getInstance(BlobRequestSigner.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue