mirror of https://github.com/apache/jclouds.git
JCLOUDS-403. Add support for Swift object expiry
This commit is contained in:
parent
7e99ddef5c
commit
3321506c84
|
@ -80,7 +80,9 @@ public class CloudFilesBlobSignerExpectTest extends BaseBlobSignerExpectTest {
|
|||
.endpoint("https://storage101.lon3.clouddrive.com/v1/MossoCloudFS_83a9d536-2e25-4166-bd3b-a503a934f953/container/name")
|
||||
.addHeader("ETag", "00020408")
|
||||
.addHeader("Expect", "100-continue")
|
||||
.addHeader("X-Auth-Token", authToken).build();
|
||||
.addHeader("X-Auth-Token", authToken)
|
||||
.addHeader("X-Delete-At", "1")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,9 +16,11 @@
|
|||
*/
|
||||
package org.jclouds.openstack.swift.binders;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Date;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
@ -72,6 +74,15 @@ public class BindSwiftObjectMetadataToRequest implements Binder {
|
|||
.build();
|
||||
}
|
||||
|
||||
Date expires = object.getPayload().getContentMetadata().getExpires();
|
||||
if (expires != null) {
|
||||
// Swizzle Expires to X-Delete-At
|
||||
request = (R) request.toBuilder()
|
||||
.addHeader("X-Delete-At", String.valueOf(
|
||||
MILLISECONDS.toSeconds(expires.getTime())))
|
||||
.build();
|
||||
}
|
||||
|
||||
request = mdBinder.bindToRequest(request, object2Blob.apply(object));
|
||||
return request;
|
||||
}
|
||||
|
|
|
@ -16,10 +16,12 @@
|
|||
*/
|
||||
package org.jclouds.openstack.swift.binders;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.io.Payload;
|
||||
|
@ -59,6 +61,8 @@ public class BindSwiftObjectMetadataToRequestTest extends CommonSwiftClientTest
|
|||
SwiftObject object = injector.getInstance(SwiftObject.Factory.class).create(null);
|
||||
Payload payload = Payloads.newStringPayload("");
|
||||
payload.getContentMetadata().setContentLength(5 * 1024 * 1024 * 1024l);
|
||||
long expiresMillis = 1000;
|
||||
payload.getContentMetadata().setExpires(new Date(expiresMillis));
|
||||
object.setPayload(payload);
|
||||
object.getInfo().setName("foo");
|
||||
object.getInfo().getMetadata().putAll(ImmutableMap.of("foo", "bar"));
|
||||
|
@ -67,6 +71,8 @@ public class BindSwiftObjectMetadataToRequestTest extends CommonSwiftClientTest
|
|||
BindSwiftObjectMetadataToRequest binder = injector.getInstance(BindSwiftObjectMetadataToRequest.class);
|
||||
|
||||
assertEquals(binder.bindToRequest(request, object), HttpRequest.builder().method("PUT")
|
||||
.addHeader("X-Delete-At", String.valueOf(
|
||||
MILLISECONDS.toSeconds(expiresMillis)))
|
||||
.endpoint("http://localhost").addHeader("X-Object-Meta-foo", "bar").build());
|
||||
}
|
||||
|
||||
|
|
|
@ -78,7 +78,9 @@ public class SwiftBlobSignerExpectTest extends BaseBlobSignerExpectTest {
|
|||
.endpoint("http://storage/container/name")
|
||||
.addHeader("ETag", "00020408")
|
||||
.addHeader("Expect", "100-continue")
|
||||
.addHeader("X-Auth-Token", "testtoken").build();
|
||||
.addHeader("X-Auth-Token", "testtoken")
|
||||
.addHeader("X-Delete-At", "1")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -73,7 +73,9 @@ public class SwiftKeystoneBlobSignerExpectTest extends BaseBlobSignerExpectTest
|
|||
.endpoint("https://objects.jclouds.org/v1.0/40806637803162/container/name")
|
||||
.addHeader("ETag", "00020408")
|
||||
.addHeader("Expect", "100-continue")
|
||||
.addHeader("X-Auth-Token", "Auth_4f173437e4b013bee56d1007").build();
|
||||
.addHeader("X-Auth-Token", "Auth_4f173437e4b013bee56d1007")
|
||||
.addHeader("X-Delete-At", "1")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -76,7 +76,9 @@ public class HPCloudObjectStorageBlobSignerExpectTest extends BaseBlobSignerExpe
|
|||
.endpoint("https://objects.jclouds.org/v1.0/40806637803162/container/name")
|
||||
.addHeader("ETag", "00020408")
|
||||
.addHeader("Expect", "100-continue")
|
||||
.addHeader("X-Auth-Token", "Auth_4f173437e4b013bee56d1007").build();
|
||||
.addHeader("X-Auth-Token", "Auth_4f173437e4b013bee56d1007")
|
||||
.addHeader("X-Delete-At", "1")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue