Skip to content

Commit

Permalink
Implemented SAS for STG 73 (#13244)
Browse files Browse the repository at this point in the history
  • Loading branch information
gapra-msft authored Jul 17, 2020
1 parent 26f1b12 commit b3ccd7a
Show file tree
Hide file tree
Showing 334 changed files with 5,704 additions and 22,373 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public final class BlobContainerSasPermission {

private boolean listPermission;

private boolean tagsPermission;

/**
* Initializes an {@code BlobContainerSasPermission} object with all fields set to false.
*/
Expand All @@ -41,7 +43,7 @@ public BlobContainerSasPermission() {
*
* @param permString A {@code String} which represents the {@code BlobContainerSasPermission}.
* @return A {@code BlobContainerSasPermission} generated from the given {@code String}.
* @throws IllegalArgumentException If {@code permString} contains a character other than r, a, c, w, d, x or l.
* @throws IllegalArgumentException If {@code permString} contains a character other than r, a, c, w, d, x, l or t.
*/
public static BlobContainerSasPermission parse(String permString) {
BlobContainerSasPermission permissions = new BlobContainerSasPermission();
Expand Down Expand Up @@ -70,6 +72,9 @@ public static BlobContainerSasPermission parse(String permString) {
case 'l':
permissions.listPermission = true;
break;
case 't':
permissions.tagsPermission = true;
break;
default:
throw new IllegalArgumentException(
String.format(Locale.ROOT, Constants.ENUM_COULD_NOT_BE_PARSED_INVALID_VALUE,
Expand Down Expand Up @@ -205,6 +210,24 @@ public BlobContainerSasPermission setListPermission(boolean hasListPermission) {
return this;
}

/**
* @return the tags permission status.
*/
public boolean hasTagsPermission() {
return tagsPermission;
}

/**
* Sets the tags permission status.
*
* @param tagsPermission Permission status to set
* @return the updated BlobContainerSasPermission object.
*/
public BlobContainerSasPermission setTagsPermission(boolean tagsPermission) {
this.tagsPermission = tagsPermission;
return this;
}

/**
* Converts the given permissions to a {@code String}. Using this method will guarantee the permissions are in an
* order accepted by the service.
Expand Down Expand Up @@ -245,6 +268,10 @@ public String toString() {
builder.append('l');
}

if (this.tagsPermission) {
builder.append('t');
}

return builder.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ public final class BlobSasPermission {

private boolean deleteVersionPermission;

private boolean tagsPermission;

/**
* Initializes a {@code BlobSasPermission} object with all fields set to false.
*/
Expand All @@ -39,7 +41,7 @@ public BlobSasPermission() {
*
* @param permString A {@code String} which represents the {@code BlobSasPermission}.
* @return A {@code BlobSasPermission} generated from the given {@code String}.
* @throws IllegalArgumentException If {@code permString} contains a character other than r, a, c, w, d or x.
* @throws IllegalArgumentException If {@code permString} contains a character other than r, a, c, w, d, x or t.
*/
public static BlobSasPermission parse(String permString) {
BlobSasPermission permissions = new BlobSasPermission();
Expand All @@ -65,6 +67,9 @@ public static BlobSasPermission parse(String permString) {
case 'x':
permissions.deleteVersionPermission = true;
break;
case 't':
permissions.tagsPermission = true;
break;
default:
throw new IllegalArgumentException(
String.format(Locale.ROOT, Constants.ENUM_COULD_NOT_BE_PARSED_INVALID_VALUE,
Expand Down Expand Up @@ -182,6 +187,24 @@ public BlobSasPermission setDeleteVersionPermission(boolean hasDeleteVersionPerm
return this;
}

/**
* @return the tags permission status.
*/
public boolean hasTagsPermission() {
return tagsPermission;
}

/**
* Sets the tags permission status.
*
* @param tagsPermission Permission status to set
* @return the updated BlobSasPermission object.
*/
public BlobSasPermission setTagsPermission(boolean tagsPermission) {
this.tagsPermission = tagsPermission;
return this;
}

/**
* Converts the given permissions to a {@code String}. Using this method will guarantee the permissions are in an
* order accepted by the service.
Expand Down Expand Up @@ -219,6 +242,10 @@ public String toString() {
builder.append('x');
}

if (this.tagsPermission) {
builder.append('t');
}

return builder.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,38 @@ class BlobAPITest extends APISpec {
bc.createSnapshotWithResponse(null, null, null, null).getStatusCode() == 201
}

def "getSnapshot"() {
setup:
def data = "test".getBytes()
def blobName = generateBlobName()
def bu = cc.getBlobClient(blobName).getBlockBlobClient()
bu.upload(new ByteArrayInputStream(data), data.length)
def snapshotId = bu.createSnapshot().getSnapshotId()

when:
def snapshotBlob = cc.getBlobClient(blobName, snapshotId).getBlockBlobClient()

then:
snapshotBlob.getSnapshotId() == snapshotId
bu.getSnapshotId() == null
}

def "isSnapshot"() {
setup:
def data = "test".getBytes()
def blobName = generateBlobName()
def bu = cc.getBlobClient(blobName).getBlockBlobClient()
bu.upload(new ByteArrayInputStream(data), data.length)
def snapshotId = bu.createSnapshot().getSnapshotId()

when:
def snapshotBlob = cc.getBlobClient(blobName, snapshotId).getBlockBlobClient()

then:
snapshotBlob.isSnapshot()
!bu.isSnapshot()
}

@Unroll
def "Snapshot metadata"() {
setup:
Expand Down
Loading

0 comments on commit b3ccd7a

Please sign in to comment.