mirror of https://github.com/apache/jclouds.git
JCLOUDS-1228: Include PublicAccess in responses
REST API version 2016-05-31 includes PublicAccess in List Containers and Get Container Properties APIs.
This commit is contained in:
parent
32bb2db06e
commit
87a6f2a615
|
@ -29,5 +29,7 @@ public interface ContainerProperties extends Comparable<ContainerProperties> {
|
|||
|
||||
String getETag();
|
||||
|
||||
PublicAccess getPublicAccess();
|
||||
|
||||
Map<String, String> getMetadata();
|
||||
}
|
||||
|
|
|
@ -46,6 +46,8 @@ public interface MutableContainerPropertiesWithMetadata extends ContainerPropert
|
|||
*/
|
||||
void setETag(String eTag);
|
||||
|
||||
void setPublicAccess(PublicAccess publicAccess);
|
||||
|
||||
/**
|
||||
* @see ListableContainerProperties#setMetadata
|
||||
*/
|
||||
|
|
|
@ -40,4 +40,7 @@ public enum PublicAccess {
|
|||
*/
|
||||
PRIVATE;
|
||||
|
||||
public static PublicAccess fromString(String string) {
|
||||
return valueOf(string.toUpperCase());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.Date;
|
|||
import java.util.Map;
|
||||
|
||||
import org.jclouds.azureblob.domain.ContainerProperties;
|
||||
import org.jclouds.azureblob.domain.PublicAccess;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
|
@ -35,14 +36,21 @@ public class ContainerPropertiesImpl implements ContainerProperties {
|
|||
private final URI url;
|
||||
private final Date lastModified;
|
||||
private final String eTag;
|
||||
private final PublicAccess publicAccess;
|
||||
private final Map<String, String> metadata = Maps.newLinkedHashMap();
|
||||
|
||||
public ContainerPropertiesImpl(URI url, Date lastModified, String eTag, Map<String, String> metadata) {
|
||||
public ContainerPropertiesImpl(URI url, Date lastModified, String eTag, Map<String, String> metadata, PublicAccess publicAccess) {
|
||||
this.url = checkNotNull(url, "url");
|
||||
this.name = checkNotNull(url.getPath(), "url.getPath()").replaceFirst("/", "");
|
||||
this.lastModified = checkNotNull(lastModified, "lastModified");
|
||||
this.eTag = checkNotNull(eTag, "eTag");
|
||||
this.metadata.putAll(checkNotNull(metadata, "metadata"));
|
||||
this.publicAccess = checkNotNull(publicAccess);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public ContainerPropertiesImpl(URI url, Date lastModified, String eTag, Map<String, String> metadata) {
|
||||
this(url, lastModified, eTag, metadata, PublicAccess.PRIVATE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -89,6 +97,11 @@ public class ContainerPropertiesImpl implements ContainerProperties {
|
|||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PublicAccess getPublicAccess() {
|
||||
return publicAccess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
@ -97,6 +110,7 @@ public class ContainerPropertiesImpl implements ContainerProperties {
|
|||
result = prime * result + ((lastModified == null) ? 0 : lastModified.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((url == null) ? 0 : url.hashCode());
|
||||
result = prime * result + ((publicAccess == null) ? 0 : publicAccess.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -129,6 +143,11 @@ public class ContainerPropertiesImpl implements ContainerProperties {
|
|||
return false;
|
||||
} else if (!url.equals(other.url))
|
||||
return false;
|
||||
if (publicAccess == null) {
|
||||
if (other.publicAccess != null)
|
||||
return false;
|
||||
} else if (!publicAccess.equals(other.publicAccess))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.Map;
|
|||
|
||||
import org.jclouds.azureblob.domain.ContainerProperties;
|
||||
import org.jclouds.azureblob.domain.MutableContainerPropertiesWithMetadata;
|
||||
import org.jclouds.azureblob.domain.PublicAccess;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
|
@ -35,6 +36,7 @@ public class MutableContainerPropertiesWithMetadataImpl implements
|
|||
private URI url;
|
||||
private Date lastModified;
|
||||
private String eTag;
|
||||
private PublicAccess publicAccess;
|
||||
|
||||
private Map<String, String> metadata = Maps.newHashMap();
|
||||
|
||||
|
@ -65,6 +67,11 @@ public class MutableContainerPropertiesWithMetadataImpl implements
|
|||
return eTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PublicAccess getPublicAccess() {
|
||||
return publicAccess;
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
*/
|
||||
|
@ -89,6 +96,11 @@ public class MutableContainerPropertiesWithMetadataImpl implements
|
|||
this.eTag = eTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPublicAccess(PublicAccess publicAccess) {
|
||||
this.publicAccess = publicAccess;
|
||||
}
|
||||
|
||||
/**
|
||||
*{@inheritDoc}
|
||||
*/
|
||||
|
@ -130,6 +142,7 @@ public class MutableContainerPropertiesWithMetadataImpl implements
|
|||
result = prime * result + ((metadata == null) ? 0 : metadata.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((url == null) ? 0 : url.hashCode());
|
||||
result = prime * result + ((publicAccess == null) ? 0 : publicAccess.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -167,6 +180,11 @@ public class MutableContainerPropertiesWithMetadataImpl implements
|
|||
return false;
|
||||
} else if (!url.equals(other.url))
|
||||
return false;
|
||||
if (publicAccess == null) {
|
||||
if (other.publicAccess != null)
|
||||
return false;
|
||||
} else if (!publicAccess.equals(other.publicAccess))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,7 @@ public class ParseContainerPropertiesFromHeaders implements Function<HttpRespons
|
|||
parseLastModifiedOrThrowException(from, to);
|
||||
addETagTo(from, to);
|
||||
to.setUrl(request.getEndpoint());
|
||||
to.setPublicAccess(new ParsePublicAccessHeader().apply(from));
|
||||
return to;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ import javax.inject.Inject;
|
|||
import org.jclouds.azure.storage.domain.BoundedSet;
|
||||
import org.jclouds.azure.storage.domain.internal.BoundedHashSet;
|
||||
import org.jclouds.azureblob.domain.ContainerProperties;
|
||||
import org.jclouds.azureblob.domain.PublicAccess;
|
||||
import org.jclouds.azureblob.domain.internal.ContainerPropertiesImpl;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
|
@ -56,6 +57,7 @@ public class AccountNameEnumerationResultsHandler extends
|
|||
private String currentName;
|
||||
private Date currentLastModified;
|
||||
private String currentETag;
|
||||
private PublicAccess currentPublicAccess = PublicAccess.PRIVATE;
|
||||
private boolean inMetadata;
|
||||
|
||||
private Map<String, String> currentMetadata = Maps.newHashMap();
|
||||
|
@ -111,10 +113,11 @@ public class AccountNameEnumerationResultsHandler extends
|
|||
throw propagate(use);
|
||||
}
|
||||
containerMetadata.add(new ContainerPropertiesImpl(currentUrl, currentLastModified,
|
||||
currentETag, currentMetadata));
|
||||
currentETag, currentMetadata, currentPublicAccess));
|
||||
currentName = null;
|
||||
currentLastModified = null;
|
||||
currentETag = null;
|
||||
currentPublicAccess = PublicAccess.PRIVATE;
|
||||
currentMetadata = Maps.newHashMap();
|
||||
} else if (qName.equals("Name")) {
|
||||
currentName = currentText.toString().trim();
|
||||
|
@ -122,6 +125,8 @@ public class AccountNameEnumerationResultsHandler extends
|
|||
currentLastModified = dateParser.rfc822DateParse(currentText.toString().trim());
|
||||
} else if (qName.equals("Etag")) {
|
||||
currentETag = currentText.toString().trim();
|
||||
} else if (qName.equals("PublicAccess")) {
|
||||
currentPublicAccess = PublicAccess.fromString(currentText.toString().trim());
|
||||
}
|
||||
currentText.setLength(0);
|
||||
}
|
||||
|
|
|
@ -129,11 +129,18 @@ public class AzureBlobClientLiveTest extends BaseBlobStoreIntegrationTest {
|
|||
throw e;
|
||||
}
|
||||
}
|
||||
// TODO
|
||||
// URL url = new URL(String.format("http://%s.blob.core.windows.net/%s",
|
||||
// identity,
|
||||
// publicContainer));
|
||||
// Utils.toStringAndClose(url.openStream());
|
||||
|
||||
ContainerProperties properties = null;
|
||||
for (ContainerProperties p : getApi().listContainers(includeMetadata())) {
|
||||
if (p.getName().equals(publicContainer)) {
|
||||
properties = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertThat(properties.getPublicAccess()).isEqualTo(PublicAccess.BLOB);
|
||||
|
||||
properties = getApi().getContainerProperties(publicContainer);
|
||||
assertThat(properties.getPublicAccess()).isEqualTo(PublicAccess.BLOB);
|
||||
}
|
||||
|
||||
@Test(timeOut = 10 * 60 * 1000)
|
||||
|
|
|
@ -25,6 +25,7 @@ import java.util.SortedSet;
|
|||
import org.jclouds.azure.storage.domain.BoundedSet;
|
||||
import org.jclouds.azure.storage.domain.internal.BoundedHashSet;
|
||||
import org.jclouds.azureblob.domain.ContainerProperties;
|
||||
import org.jclouds.azureblob.domain.PublicAccess;
|
||||
import org.jclouds.azureblob.domain.internal.ContainerPropertiesImpl;
|
||||
import org.jclouds.date.DateService;
|
||||
import org.jclouds.http.functions.BaseHandlerTest;
|
||||
|
@ -57,15 +58,15 @@ public class AccountNameEnumerationResultsHandlerTest extends BaseHandlerTest {
|
|||
contents.add(new ContainerPropertiesImpl(URI
|
||||
.create("http://myaccount.blob.core.windows.net/audio"), dateService
|
||||
.rfc822DateParse("Wed, 13 Aug 2008 20:39:39 GMT"), "0x8CACB9BD7C6B1B2", Maps
|
||||
.<String, String> newHashMap()));
|
||||
.<String, String> newHashMap(), PublicAccess.CONTAINER));
|
||||
contents.add(new ContainerPropertiesImpl(URI
|
||||
.create("http://myaccount.blob.core.windows.net/images"), dateService
|
||||
.rfc822DateParse("Wed, 14 Aug 2008 20:39:39 GMT"), "0x8CACB9BD7C1EEEC", Maps
|
||||
.<String, String> newHashMap()));
|
||||
.<String, String> newHashMap(), PublicAccess.BLOB));
|
||||
contents.add(new ContainerPropertiesImpl(URI
|
||||
.create("http://myaccount.blob.core.windows.net/textfiles"), dateService
|
||||
.rfc822DateParse("Wed, 15 Aug 2008 20:39:39 GMT"), "0x8CACB9BD7BACAC3", Maps
|
||||
.<String, String> newHashMap()));
|
||||
.<String, String> newHashMap(), PublicAccess.PRIVATE));
|
||||
BoundedSet<ContainerProperties> list = new BoundedHashSet<ContainerProperties>(contents, URI
|
||||
.create("http://myaccount.blob.core.windows.net/"), null, null, 3, "video");
|
||||
|
||||
|
@ -80,15 +81,15 @@ public class AccountNameEnumerationResultsHandlerTest extends BaseHandlerTest {
|
|||
contents.add(new ContainerPropertiesImpl(URI
|
||||
.create("http://myaccount.blob.core.windows.net/audio"), dateService
|
||||
.rfc822DateParse("Wed, 13 Aug 2008 20:39:39 GMT"), "0x8CACB9BD7C6B1B2", Maps
|
||||
.<String, String> newHashMap()));
|
||||
.<String, String> newHashMap(), PublicAccess.CONTAINER));
|
||||
contents.add(new ContainerPropertiesImpl(URI
|
||||
.create("http://myaccount.blob.core.windows.net/images"), dateService
|
||||
.rfc822DateParse("Wed, 14 Aug 2008 20:39:39 GMT"), "0x8CACB9BD7C1EEEC", Maps
|
||||
.<String, String> newHashMap()));
|
||||
.<String, String> newHashMap(), PublicAccess.BLOB));
|
||||
contents.add(new ContainerPropertiesImpl(URI
|
||||
.create("http://myaccount.blob.core.windows.net/textfiles"), dateService
|
||||
.rfc822DateParse("Wed, 15 Aug 2008 20:39:39 GMT"), "0x8CACB9BD7BACAC3", Maps
|
||||
.<String, String> newHashMap()));
|
||||
.<String, String> newHashMap(), PublicAccess.PRIVATE));
|
||||
InputStream is = getClass().getResourceAsStream("/test_list_containers_options.xml");
|
||||
BoundedSet<ContainerProperties> list = new BoundedHashSet<ContainerProperties>(contents, URI
|
||||
.create("http://myaccount.blob.core.windows.net"), "prefix", "marker", 1, "video");
|
||||
|
|
|
@ -6,11 +6,13 @@
|
|||
<Name>audio</Name>
|
||||
<Last-Modified>Wed, 13 Aug 2008 20:39:39 GMT</Last-Modified>
|
||||
<Etag>0x8CACB9BD7C6B1B2</Etag>
|
||||
<PublicAccess>container</PublicAccess>
|
||||
</Container>
|
||||
<Container>
|
||||
<Name>images</Name>
|
||||
<Last-Modified>Wed, 14 Aug 2008 20:39:39 GMT</Last-Modified>
|
||||
<Etag>0x8CACB9BD7C1EEEC</Etag>
|
||||
<PublicAccess>blob</PublicAccess>
|
||||
</Container>
|
||||
<Container>
|
||||
<Name>textfiles</Name>
|
||||
|
|
|
@ -8,11 +8,13 @@
|
|||
<Name>audio</Name>
|
||||
<Last-Modified>Wed, 13 Aug 2008 20:39:39 GMT</Last-Modified>
|
||||
<Etag>0x8CACB9BD7C6B1B2</Etag>
|
||||
<PublicAccess>container</PublicAccess>
|
||||
</Container>
|
||||
<Container>
|
||||
<Name>images</Name>
|
||||
<Last-Modified>Wed, 14 Aug 2008 20:39:39 GMT</Last-Modified>
|
||||
<Etag>0x8CACB9BD7C1EEEC</Etag>
|
||||
<PublicAccess>blob</PublicAccess>
|
||||
</Container>
|
||||
<Container>
|
||||
<Name>textfiles</Name>
|
||||
|
|
Loading…
Reference in New Issue