Skip to content

Commit

Permalink
Replace magic string with enum
Browse files Browse the repository at this point in the history
Issue Azure#42
  • Loading branch information
Renaud Paquay committed Nov 19, 2011
1 parent d736a73 commit ce7d2a4
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.microsoft.windowsazure.services.blob.models.BlockList;
import com.microsoft.windowsazure.services.blob.models.CommitBlobBlocksOptions;
import com.microsoft.windowsazure.services.blob.models.ContainerACL;
import com.microsoft.windowsazure.services.blob.models.ContainerACL.PublicAccessType;
import com.microsoft.windowsazure.services.blob.models.CopyBlobOptions;
import com.microsoft.windowsazure.services.blob.models.CreateBlobBlockOptions;
import com.microsoft.windowsazure.services.blob.models.CreateBlobOptions;
Expand Down Expand Up @@ -345,7 +346,15 @@ public GetContainerACLResult getContainerACL(String container, BlobServiceOption
ContainerACL.SignedIdentifiers si = response.getEntity(ContainerACL.SignedIdentifiers.class);
ContainerACL acl = new ContainerACL();
acl.setSignedIdentifiers(si.getSignedIdentifiers());
acl.setPublicAccess(response.getHeaders().getFirst("x-ms-blob-public-access"));
if ("container".equals(response.getHeaders().getFirst("x-ms-blob-public-access"))) {
acl.setPublicAccess(PublicAccessType.CONTAINER_AND_BLOBS);
}
else if ("blob".equals(response.getHeaders().getFirst("x-ms-blob-public-access"))) {
acl.setPublicAccess(PublicAccessType.BLOBS_ONLY);
}
else {
acl.setPublicAccess(PublicAccessType.NONE);
}
acl.setEtag(response.getHeaders().getFirst("ETag"));
acl.setLastModified(dateMapper.parse(response.getHeaders().getFirst("Last-Modified")));

Expand All @@ -363,7 +372,12 @@ public void setContainerACL(String container, ContainerACL acl, BlobServiceOptio
.queryParam("comp", "acl");

Builder builder = webResource.header("x-ms-version", API_VERSION);
builder = addOptionalHeader(builder, "x-ms-blob-public-access", acl.getPublicAccess());
if (acl.getPublicAccess() == PublicAccessType.BLOBS_ONLY) {
builder = addOptionalHeader(builder, "x-ms-blob-public-access", "blob");
}
else if (acl.getPublicAccess() == PublicAccessType.CONTAINER_AND_BLOBS) {
builder = addOptionalHeader(builder, "x-ms-blob-public-access", "container");
}

ContainerACL.SignedIdentifiers si = new ContainerACL.SignedIdentifiers();
si.setSignedIdentifiers(acl.getSignedIdentifiers());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
public class ContainerACL {
private String etag;
private Date lastModified;
private String publicAccess; // "blob", "container" or null
private PublicAccessType publicAccess;
private List<SignedIdentifier> signedIdentifiers = new ArrayList<SignedIdentifier>();

public String getEtag() {
Expand All @@ -32,11 +32,11 @@ public void setLastModified(Date lastModified) {
this.lastModified = lastModified;
}

public String getPublicAccess() {
public PublicAccessType getPublicAccess() {
return publicAccess;
}

public void setPublicAccess(String publicAccess) {
public void setPublicAccess(PublicAccessType publicAccess) {
this.publicAccess = publicAccess;
}

Expand Down Expand Up @@ -132,4 +132,8 @@ public void setPermission(String permission) {
this.permission = permission;
}
}

public static enum PublicAccessType {
NONE, BLOBS_ONLY, CONTAINER_AND_BLOBS,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.microsoft.windowsazure.services.blob.models.BlobProperties;
import com.microsoft.windowsazure.services.blob.models.BlockList;
import com.microsoft.windowsazure.services.blob.models.ContainerACL;
import com.microsoft.windowsazure.services.blob.models.ContainerACL.PublicAccessType;
import com.microsoft.windowsazure.services.blob.models.CreateBlobOptions;
import com.microsoft.windowsazure.services.blob.models.CreateBlobPagesResult;
import com.microsoft.windowsazure.services.blob.models.CreateBlobSnapshotOptions;
Expand Down Expand Up @@ -285,7 +286,7 @@ public void setContainerACLWorks() throws Exception {
service.createContainer(container);

ContainerACL acl = new ContainerACL();
acl.setPublicAccess("blob");
acl.setPublicAccess(PublicAccessType.BLOBS_ONLY);
acl.addSignedIdentifier("test", expiryStartDate, expiryEndDate, "rwd");
service.setContainerACL(container, acl);

Expand All @@ -297,7 +298,7 @@ public void setContainerACLWorks() throws Exception {
assertNotNull(acl2.getEtag());
assertNotNull(acl2.getLastModified());
assertNotNull(acl2.getPublicAccess());
assertEquals("blob", acl2.getPublicAccess());
assertEquals(PublicAccessType.BLOBS_ONLY, acl2.getPublicAccess());
assertEquals(1, acl2.getSignedIdentifiers().size());
assertEquals("test", acl2.getSignedIdentifiers().get(0).getId());
assertEquals(expiryStartDate, acl2.getSignedIdentifiers().get(0).getAccessPolicy().getStart());
Expand Down

0 comments on commit ce7d2a4

Please sign in to comment.