Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.

Commit f27493d

Browse files
committed
Added worm support
1 parent 2d82ab7 commit f27493d

File tree

11 files changed

+144
-1
lines changed

11 files changed

+144
-1
lines changed

ChangeLog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
XXXX.XX.XX Version X.X.X
2+
* Support for write-once read-many containers.
3+
14
2018.02.05 Version 7.0.0
25
* Support for 2017-07-29 REST version. Please see our REST api documentation and blogs for information about the related added features.
36
* Added support for soft delete feature. If a delete retention policy is enabled through the set service properties API, then blobs or snapshots can be deleted softly and retained for a specified number of days, before being permanently removed by garbage collection.

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlobClientTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ public void testListContainers() throws StorageException, URISyntaxException {
7777
for (final CloudBlobContainer container : segment.getResults()) {
7878
container.downloadAttributes();
7979
assertEquals(CloudBlobContainer.class, container.getClass());
80+
assertNotNull(container.getProperties().hasImmutabilityPolicy());
81+
assertNotNull(container.getProperties().hasLegalHold());
82+
assertFalse(container.getProperties().hasImmutabilityPolicy());
83+
assertFalse(container.getProperties().hasLegalHold());
8084
containerList.remove(container.getName());
8185
}
8286

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlobContainerTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ public void testCloudBlobContainerExists() throws StorageException {
316316
this.container.create();
317317
assertTrue(this.container.exists());
318318
assertNotNull(this.container.getProperties().getEtag());
319+
assertNotNull(this.container.getProperties().hasImmutabilityPolicy());
320+
assertNotNull(this.container.getProperties().hasLegalHold());
321+
assertFalse(this.container.getProperties().hasImmutabilityPolicy());
322+
assertFalse(this.container.getProperties().hasLegalHold());
319323

320324
this.container.delete();
321325
assertFalse(this.container.exists());
@@ -549,6 +553,8 @@ public void testCloudBlobContainerListBlobs() throws StorageException, IOExcepti
549553
EnumSet.noneOf(BlobListingDetails.class), 150, token, null, null);
550554
for (ListBlobItem blob : result.getResults()) {
551555
assertEquals(CloudBlockBlob.class, blob.getClass());
556+
assertNotNull(((CloudBlockBlob)blob).getProperties().getCreatedTime());
557+
assertTrue(((CloudBlockBlob)blob).getProperties().getCreatedTime().before(new Date()));
552558
assertTrue(blobNames.remove(((CloudBlockBlob) blob).getName()));
553559
}
554560
token = result.getContinuationToken();

microsoft-azure-storage-test/src/com/microsoft/azure/storage/blob/CloudBlockBlobTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ public void testBlockBlobCreate() throws StorageException, URISyntaxException, I
9999
// Create again (should succeed)
100100
blob.uploadText("text");
101101
assertTrue(blob.exists());
102+
assertNotNull(blob.getProperties().getCreatedTime());
103+
assertTrue(blob.getProperties().getCreatedTime().before(new Date()));
102104

103105
// Create again, specifying not to if it already exists
104106
// This should fail

microsoft-azure-storage/src/com/microsoft/azure/storage/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ public static class HeaderConstants {
650650
/**
651651
* The current storage version header value.
652652
*/
653-
public static final String TARGET_STORAGE_VERSION = "2017-07-29";
653+
public static final String TARGET_STORAGE_VERSION = "2017-11-09";
654654

655655
/**
656656
* The header that specifies the next visible time for a queue message.

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobConstants.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,16 @@ final class BlobConstants {
150150
*/
151151
public static final String CONTENT_TYPE_HEADER = Constants.PREFIX_FOR_STORAGE_HEADER + "blob-content-type";
152152

153+
/**
154+
* The header that specifies the blob creation time.
155+
*/
156+
public static final String CREATION_TIME_HEADER = Constants.PREFIX_FOR_STORAGE_HEADER + "creation-time";
157+
158+
/**
159+
* XML element for the creation time.
160+
*/
161+
public static final String CREATION_TIME_ELEMENT = "Creation-Time";
162+
153163
/**
154164
* The number of default concurrent requests for parallel operation.
155165
*/
@@ -170,6 +180,26 @@ final class BlobConstants {
170180
*/
171181
public static final int DEFAULT_POLLING_INTERVAL_IN_SECONDS = 30;
172182

183+
/**
184+
* The header that specifies the immutability policy for the resource.
185+
*/
186+
public static final String HAS_IMMUTABILITY_POLICY_HEADER = Constants.PREFIX_FOR_STORAGE_HEADER + "has-immutability-policy";
187+
188+
/**
189+
* The header that specifies the legal hold value for the resource.
190+
*/
191+
public static final String HAS_LEGAL_HOLD_HEADER = Constants.PREFIX_FOR_STORAGE_HEADER + "has-legal-hold";
192+
193+
/**
194+
* XML element for immutability policy.
195+
*/
196+
public static final String HAS_IMMUTABILITY_POLICY_ELEMENT = "HasImmutabilityPolicy";
197+
198+
/**
199+
* XML element for legal hold.
200+
*/
201+
public static final String HAS_LEGAL_HOLD_ELEMENT = "HasLegalHold";
202+
173203
/**
174204
* XML element for the latest.
175205
*/

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobContainerProperties.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ public final class BlobContainerProperties {
2828
*/
2929
private String etag;
3030

31+
/**
32+
* Represents whether the container has an immutability policy.
33+
*/
34+
private Boolean hasImmutabilityPolicy;
35+
36+
/**
37+
* Represents whether the container has a legal hold.
38+
*/
39+
private Boolean hasLegalHold;
40+
3141
/**
3242
* Represents the container's last-modified time.
3343
*/
@@ -69,6 +79,24 @@ public String getEtag() {
6979
return this.etag;
7080
}
7181

82+
/**
83+
* Gets the hasImmutabilityPolicy value of the container.
84+
*
85+
* @return A <code>Boolean</code> which represents the hasImmutabilityPolicy value.
86+
*/
87+
public Boolean hasImmutabilityPolicy() {
88+
return this.hasImmutabilityPolicy;
89+
}
90+
91+
/**
92+
* Gets the hasLegalHold value of the container.
93+
*
94+
* @return A <code>Boolean</code> which represents the hasLegalHold value.
95+
*/
96+
public Boolean hasLegalHold() {
97+
return this.hasLegalHold;
98+
}
99+
72100
/**
73101
* Gets the last modified time on the container.
74102
*
@@ -128,6 +156,26 @@ protected void setEtag(final String etag) {
128156
this.etag = etag;
129157
}
130158

159+
/**
160+
* Sets the hasImmutabilityPolicy value on the container.
161+
*
162+
* @param hasImmutabilityPolicy
163+
* A <code>Boolean</code> which represents the hasImmutabilityProperty value to set.
164+
*/
165+
protected void setHasImmutabilityPolicy(final Boolean hasImmutabilityPolicy) {
166+
this.hasImmutabilityPolicy = hasImmutabilityPolicy;
167+
}
168+
169+
/**
170+
* Sets the hasLegalHold value on the container.
171+
*
172+
* @param hasLegalHold
173+
* A <code>Boolean</code> which represents the hasLegalHold value to set.
174+
*/
175+
protected void setHasLegalHold(final Boolean hasLegalHold) {
176+
this.hasLegalHold= hasLegalHold;
177+
}
178+
131179
/**
132180
* Sets the last modified time on the container.
133181
*

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobListHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,5 +366,8 @@ else if (BlobConstants.DELETED_TIME.equals(currentNode)) {
366366
else if (BlobConstants.REMAINING_RETENTION_DAYS.equals(currentNode)) {
367367
this.properties.setRemainingRetentionDays(Integer.parseInt(value));
368368
}
369+
else if (BlobConstants.CREATION_TIME_ELEMENT.equals(currentNode)) {
370+
this.properties.setCreatedTime(Utility.parseRFC1123DateFromStringInGMT(value));
371+
}
369372
}
370373
}

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobProperties.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ public final class BlobProperties {
7272
*/
7373
private CopyState copyState;
7474

75+
/**
76+
* Represents the creation time for the blob, expressed as a UTC value.
77+
*/
78+
private Date createdTime;
79+
7580
/**
7681
* Represents the blob's ETag value.
7782
*/
@@ -176,6 +181,7 @@ public BlobProperties(final BlobProperties other) {
176181
this.contentMD5 = other.contentMD5;
177182
this.contentType = other.contentType;
178183
this.copyState = other.copyState;
184+
this.createdTime = other.createdTime;
179185
this.etag = other.etag;
180186
this.isBlobTierInferredTier = other.isBlobTierInferredTier;
181187
this.isIncrementalCopy = other.isIncrementalCopy;
@@ -288,6 +294,14 @@ public CopyState getCopyState() {
288294
return this.copyState;
289295
}
290296

297+
/**
298+
* Gets the time when the blob was created.
299+
* @return A {@link java.util.Date} object which represents the time when the blob was created.
300+
*/
301+
public Date getCreatedTime() {
302+
return this.createdTime;
303+
}
304+
291305
/**
292306
* Gets the ETag value for the blob.
293307
* <p>
@@ -521,6 +535,16 @@ protected void setCopyState(final CopyState copyState) {
521535
this.copyState = copyState;
522536
}
523537

538+
/**
539+
* Sets the createdTime value for the blob
540+
*
541+
* @param createdTime
542+
* A <code>Date</code> which represents the time when the blob was created.
543+
*/
544+
protected void setCreatedTime(final Date createdTime) {
545+
this.createdTime = createdTime;
546+
}
547+
524548
/**
525549
* Sets the ETag value for the blob.
526550
*

microsoft-azure-storage/src/com/microsoft/azure/storage/blob/BlobResponse.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,12 @@ else if (properties.getPremiumPageBlobTier() != null || properties.getStandardB
172172
properties.setTierChangeTime(new Date(tierChangeTime));
173173
}
174174

175+
// Get the creation time of the blob.
176+
final long creationTime = request.getHeaderFieldDate(BlobConstants.CREATION_TIME_HEADER, 0);
177+
if (creationTime != 0) {
178+
properties.setCreatedTime(new Date(creationTime));
179+
}
180+
175181
final String incrementalCopyHeaderString =
176182
request.getHeaderField(Constants.HeaderConstants.INCREMENTAL_COPY);
177183
if (!Utility.isNullOrEmpty(incrementalCopyHeaderString)) {
@@ -222,6 +228,17 @@ public static BlobContainerAttributes getBlobContainerAttributes(final HttpURLCo
222228

223229
containerProperties.setPublicAccess(getPublicAccessLevel(request));
224230

231+
// Worm policy
232+
String hasImmutability = request.getHeaderField(BlobConstants.HAS_IMMUTABILITY_POLICY_HEADER);
233+
if (!Utility.isNullOrEmpty(hasImmutability)) {
234+
containerProperties.setHasImmutabilityPolicy(Boolean.parseBoolean(hasImmutability));
235+
}
236+
237+
String hasLegalHold = request.getHeaderField(BlobConstants.HAS_LEGAL_HOLD_HEADER);
238+
if (!Utility.isNullOrEmpty(hasLegalHold)) {
239+
containerProperties.setHasLegalHold(Boolean.parseBoolean(hasLegalHold));
240+
}
241+
225242
return containerAttributes;
226243
}
227244

0 commit comments

Comments
 (0)