JCLOUDS-403. Add support for Swift object expiry

This commit is contained in:
Andrew Gaul 2013-12-09 22:20:43 -08:00
parent 7e99ddef5c
commit 3321506c84
6 changed files with 29 additions and 4 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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());
}

View File

@ -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

View File

@ -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

View File

@ -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