mirror of https://github.com/apache/jclouds.git
Updated files from other git repo for Swift public ACL
This commit is contained in:
parent
3984d1057d
commit
c8ee6c10cc
|
@ -18,6 +18,14 @@
|
|||
*/
|
||||
package org.jclouds.openstack.swift.domain;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -28,14 +36,20 @@ public class ContainerMetadata implements Comparable<ContainerMetadata> {
|
|||
private String name;
|
||||
private long count;
|
||||
private long bytes;
|
||||
@SerializedName("X-Container-Read")
|
||||
private String readACL;
|
||||
//private Map<String, String> metadata = Maps.newLinkedHashMap();
|
||||
|
||||
|
||||
public ContainerMetadata() {
|
||||
}
|
||||
|
||||
public ContainerMetadata(String name, long count, long bytes) {
|
||||
setName(name);
|
||||
setBytes(bytes);
|
||||
setCount(count);
|
||||
public ContainerMetadata(String name, long count, long bytes, String readACL) {
|
||||
this.name = name;
|
||||
this.count = count;
|
||||
this.bytes = bytes;
|
||||
this.readACL = readACL;
|
||||
//this.metadata = metadata;
|
||||
}
|
||||
|
||||
public long getCount() {
|
||||
|
@ -46,22 +60,37 @@ public class ContainerMetadata implements Comparable<ContainerMetadata> {
|
|||
this.count = count;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
public long getBytes() {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public void setBytes(long bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public long getBytes() {
|
||||
return bytes;
|
||||
public boolean isPublic() {
|
||||
if (readACL == null)
|
||||
return false;
|
||||
return readACL.equals(".r:*,.rlistings");
|
||||
}
|
||||
|
||||
public void setReadACL(String readACL) {
|
||||
this.readACL = readACL;
|
||||
|
||||
}
|
||||
/*public Map<String, String> getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
@ -99,4 +128,10 @@ public class ContainerMetadata implements Comparable<ContainerMetadata> {
|
|||
return (this == o) ? 0 : getName().compareTo(o.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ContainerMetadata [name=" + name + ", count=" + count + ", bytes="
|
||||
+ bytes + ", isPublic=" + isPublic() + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,8 +51,8 @@ public class ParseContainerListFromJsonResponseTest {
|
|||
InputStream is = Strings2
|
||||
.toInputStream("[ {\"name\":\"test_container_1\",\"count\":2,\"bytes\":78}, {\"name\":\"test_container_2\",\"count\":1,\"bytes\":17} ] ");
|
||||
|
||||
List<ContainerMetadata> expects = ImmutableList.of(new ContainerMetadata("test_container_1", 2, 78),
|
||||
new ContainerMetadata("test_container_2", 1, 17));
|
||||
List<ContainerMetadata> expects = ImmutableList.of(new ContainerMetadata("test_container_1", 2, 78, null),
|
||||
new ContainerMetadata("test_container_2", 1, 17, null));
|
||||
ParseJson<List<ContainerMetadata>> parser = i.getInstance(Key
|
||||
.get(new TypeLiteral<ParseJson<List<ContainerMetadata>>>() {
|
||||
}));
|
||||
|
|
|
@ -146,7 +146,7 @@ public class StubSwiftAsyncClient implements CommonSwiftAsyncClient {
|
|||
return immediateFuture(Sets.newHashSet(Iterables.transform(blobStore.getContainerToBlobs().keySet(),
|
||||
new Function<String, ContainerMetadata>() {
|
||||
public ContainerMetadata apply(String name) {
|
||||
return new ContainerMetadata(name, -1, -1);
|
||||
return new ContainerMetadata(name, -1, -1, null);
|
||||
}
|
||||
})));
|
||||
}
|
||||
|
|
|
@ -36,11 +36,14 @@ import org.jclouds.blobstore.functions.ReturnNullOnContainerNotFound;
|
|||
import org.jclouds.hpcloud.object.storage.domain.ContainerCDNMetadata;
|
||||
import org.jclouds.hpcloud.object.storage.functions.ParseCDNUriFromHeaders;
|
||||
import org.jclouds.hpcloud.object.storage.functions.ParseContainerCDNMetadataFromHeaders;
|
||||
import org.jclouds.hpcloud.object.storage.functions.ParseContainerMetadataFromHeaders;
|
||||
import org.jclouds.hpcloud.object.storage.options.CreateContainerOptions;
|
||||
import org.jclouds.hpcloud.object.storage.options.ListCDNContainerOptions;
|
||||
import org.jclouds.hpcloud.object.storage.reference.HPCloudObjectStorageHeaders;
|
||||
import org.jclouds.openstack.filters.AuthenticateRequest;
|
||||
import org.jclouds.openstack.swift.CommonSwiftAsyncClient;
|
||||
import org.jclouds.openstack.swift.Storage;
|
||||
import org.jclouds.openstack.swift.domain.ContainerMetadata;
|
||||
import org.jclouds.rest.annotations.Endpoint;
|
||||
import org.jclouds.rest.annotations.ExceptionParser;
|
||||
import org.jclouds.rest.annotations.Headers;
|
||||
|
@ -87,6 +90,23 @@ public interface HPCloudObjectStorageAsyncClient extends CommonSwiftAsyncClient
|
|||
@Endpoint(CDNManagement.class)
|
||||
ListenableFuture<ContainerCDNMetadata> getCDNMetadata(@PathParam("container") String container);
|
||||
|
||||
/**
|
||||
* @see HPCloudObjectStorageClient#getCDNMetadata(String)
|
||||
*/
|
||||
@HEAD
|
||||
@ResponseParser(ParseContainerMetadataFromHeaders.class)
|
||||
@ExceptionParser(ReturnNullOnContainerNotFound.class)
|
||||
@Path("/{container}")
|
||||
ListenableFuture<ContainerMetadata> getContainerMetadata(@PathParam("container") String container);
|
||||
|
||||
/**
|
||||
* @see HPCloudObjectStorageClient#createContainer
|
||||
*/
|
||||
@PUT
|
||||
@Path("/{container}")
|
||||
ListenableFuture<Boolean> createContainer(@PathParam("container") String container,
|
||||
CreateContainerOptions... options);
|
||||
|
||||
/**
|
||||
* @see HPCloudObjectStorageClient#enableCDN(String, long)
|
||||
*/
|
||||
|
|
|
@ -25,8 +25,10 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.hpcloud.object.storage.domain.ContainerCDNMetadata;
|
||||
import org.jclouds.hpcloud.object.storage.options.CreateContainerOptions;
|
||||
import org.jclouds.hpcloud.object.storage.options.ListCDNContainerOptions;
|
||||
import org.jclouds.openstack.swift.CommonSwiftClient;
|
||||
import org.jclouds.openstack.swift.domain.ContainerMetadata;
|
||||
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
|
@ -44,10 +46,14 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
@Timeout(duration = 120, timeUnit = TimeUnit.SECONDS)
|
||||
public interface HPCloudObjectStorageClient extends CommonSwiftClient {
|
||||
|
||||
boolean createContainer(String container, CreateContainerOptions... options);
|
||||
|
||||
Set<ContainerCDNMetadata> listCDNContainers(ListCDNContainerOptions... options);
|
||||
|
||||
ContainerCDNMetadata getCDNMetadata(String container);
|
||||
|
||||
ContainerMetadata getContainerMetadata(String container);
|
||||
|
||||
URI enableCDN(String container, long ttl);
|
||||
|
||||
URI enableCDN(String container);
|
||||
|
@ -56,8 +62,4 @@ public interface HPCloudObjectStorageClient extends CommonSwiftClient {
|
|||
|
||||
boolean disableCDN(String container);
|
||||
|
||||
/*boolean isContainerPublic(String container);
|
||||
|
||||
boolean setContainerACL(String container);
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.jclouds.openstack.swift.config.BaseSwiftRestClientModule;
|
|||
import org.jclouds.rest.ConfiguresRestClient;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
|
|
|
@ -19,7 +19,9 @@
|
|||
package org.jclouds.hpcloud.object.storage.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.google.common.collect.Lists.newArrayList;
|
||||
|
||||
import java.util.List;
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.hpcloud.object.storage.domain.ContainerCDNMetadata;
|
||||
|
@ -30,6 +32,8 @@ import org.jclouds.openstack.swift.domain.AccountMetadata;
|
|||
import org.jclouds.rest.InvocationContext;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* This parses {@link AccountMetadata} from HTTP headers.
|
||||
|
@ -52,10 +56,13 @@ public class ParseContainerCDNMetadataFromHeaders implements
|
|||
String cdnEnabled = checkNotNull(from.getFirstHeaderOrNull(HPCloudObjectStorageHeaders.CDN_ENABLED),
|
||||
HPCloudObjectStorageHeaders.CDN_ENABLED);
|
||||
if (cdnUri == null) {
|
||||
// CDN is not, and has never, been enabled for this container.
|
||||
// CDN is not enabled for this container.
|
||||
return null;
|
||||
} else {
|
||||
return new ContainerCDNMetadata(request.getEndpoint().getPath(), Boolean
|
||||
// just need the name from the path
|
||||
List<String> parts = newArrayList(Splitter.on('/').split(request.getEndpoint().getPath()));
|
||||
|
||||
return new ContainerCDNMetadata(parts.get(parts.size()-1), Boolean
|
||||
.parseBoolean(cdnEnabled), Long.parseLong(cdnTTL), URI.create(cdnUri));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.hpcloud.object.storage.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.jclouds.blobstore.reference.BlobStoreConstants;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.hpcloud.object.storage.reference.HPCloudObjectStorageHeaders;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.openstack.swift.domain.ContainerMetadata;
|
||||
import org.jclouds.rest.InvocationContext;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* This parses @{link {@link org.jclouds.hpcloud.object.storage.domain.ContainerMetadata} from
|
||||
* HTTP headers.
|
||||
*
|
||||
* @author Jeremy Daggett
|
||||
*/
|
||||
public class ParseContainerMetadataFromHeaders implements Function<HttpResponse, ContainerMetadata>,
|
||||
InvocationContext<ParseContainerMetadataFromHeaders> {
|
||||
|
||||
private final DateService dateParser;
|
||||
private final String metadataPrefix;
|
||||
private GeneratedHttpRequest<?> request;
|
||||
|
||||
@Inject
|
||||
public ParseContainerMetadataFromHeaders(DateService dateParser,
|
||||
@Named(BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX) String metadataPrefix) {
|
||||
this.dateParser = dateParser;
|
||||
this.metadataPrefix = metadataPrefix;
|
||||
}
|
||||
|
||||
public ContainerMetadata apply(HttpResponse from) {
|
||||
ContainerMetadata to = new ContainerMetadata();
|
||||
|
||||
to.setName(request.getArgs().get(0).toString());
|
||||
|
||||
to.setReadACL(from.getFirstHeaderOrNull(HPCloudObjectStorageHeaders.CONTAINER_READ));
|
||||
|
||||
to.setBytes(new Long(from.getFirstHeaderOrNull(HPCloudObjectStorageHeaders.CONTAINER_BYTES_USED)));
|
||||
to.setCount(new Long(from.getFirstHeaderOrNull(HPCloudObjectStorageHeaders.CONTAINER_OBJECT_COUNT)));
|
||||
|
||||
//addUserMetadataTo(from, to);
|
||||
|
||||
return to;
|
||||
}
|
||||
|
||||
/*
|
||||
@VisibleForTesting
|
||||
void addUserMetadataTo(HttpResponse from, ContainerMetadata metadata) {
|
||||
for (Entry<String, String> header : from.getHeaders().entries()) {
|
||||
if (header.getKey() != null && header.getKey().startsWith(metadataPrefix))
|
||||
metadata.getMetadata().put((header.getKey().substring(metadataPrefix.length())).toLowerCase(),
|
||||
header.getValue());
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public ParseContainerMetadataFromHeaders setContext(HttpRequest request) {
|
||||
checkArgument(request instanceof GeneratedHttpRequest<?>, "note this handler requires a GeneratedHttpRequest");
|
||||
this.request = (GeneratedHttpRequest<?>) request;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.hpcloud.object.storage.options;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.jclouds.hpcloud.object.storage.reference.HPCloudObjectStorageHeaders;
|
||||
import org.jclouds.http.options.BaseHttpRequestOptions;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
/**
|
||||
* Contains options supported in the REST API for the Create Container operation.
|
||||
*
|
||||
* This specifically enabes the Swift ACL for public reads using the 'X-Container-Read'
|
||||
* header. This should be refactored into the Swift API.
|
||||
*
|
||||
* @author Jeremy Daggett
|
||||
*/
|
||||
public class CreateContainerOptions extends BaseHttpRequestOptions {
|
||||
public static final CreateContainerOptions NONE = new CreateContainerOptions();
|
||||
|
||||
/**
|
||||
* A name-value pair to associate with the container as metadata.
|
||||
*/
|
||||
public CreateContainerOptions withMetadata(Multimap<String, String> metadata) {
|
||||
for (Entry<String, String> entry : metadata.entries()) {
|
||||
System.err.println(entry.getValue());
|
||||
if (entry.getKey().startsWith(HPCloudObjectStorageHeaders.USER_METADATA_PREFIX))
|
||||
this.headers.put(entry.getKey(), entry.getValue());
|
||||
else
|
||||
this.headers.put(HPCloudObjectStorageHeaders.USER_METADATA_PREFIX + entry.getKey(),
|
||||
entry.getValue());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Indicates whether a container may be accessed publicly
|
||||
*/
|
||||
public CreateContainerOptions withPublicAccess() {
|
||||
this.headers.put(HPCloudObjectStorageHeaders.CONTAINER_READ, ".r:*,.rlistings");
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see CreateContainerOptions#withPublicAccess
|
||||
*/
|
||||
public static CreateContainerOptions withPublicAccess() {
|
||||
CreateContainerOptions options = new CreateContainerOptions();
|
||||
return options.withPublicAccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see CreateContainerOptions#withMetadata(Multimap<String, String>)
|
||||
*/
|
||||
public static CreateContainerOptions withMetadata(Multimap<String, String> metadata) {
|
||||
CreateContainerOptions options = new CreateContainerOptions();
|
||||
return (CreateContainerOptions) options.withMetadata(metadata);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue