Skip to content

Commit

Permalink
Addressed comments for immutable storage with versioning (#22388)
Browse files Browse the repository at this point in the history
  • Loading branch information
gapra-msft authored Jun 18, 2021
1 parent e79d228 commit a5d3f39
Show file tree
Hide file tree
Showing 11 changed files with 382 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.storage.blob.implementation.models;

import com.azure.storage.blob.models.BlobLegalHoldResult;

/**
* The blob legal hold result.
*/
public class InternalBlobLegalHoldResult implements BlobLegalHoldResult {

private final boolean hasLegalHold;

/**
* Creates a new BlobLegalHoldResult
* @param hasLegalHold whether or not a legal hold is enabled on the blob.
*/
public InternalBlobLegalHoldResult(boolean hasLegalHold) {
this.hasLegalHold = hasLegalHold;
}

/**
* @return whether or not a legal hold is enabled on the blob.
*/
public boolean hasLegalHold() {
return hasLegalHold;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.storage.blob.implementation.util;

public enum BlobRequestConditionProperty {
LEASE_ID,
TAGS_CONDITIONS,
IF_MODIFIED_SINCE,
IF_UNMODIFIED_SINCE,
IF_MATCH,
IF_NONE_MATCH;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.azure.storage.blob.models.BlobItemProperties;
import com.azure.storage.blob.models.BlobLeaseRequestConditions;
import com.azure.storage.blob.models.BlobQueryHeaders;
import com.azure.storage.blob.models.BlobRequestConditions;
import com.azure.storage.blob.models.ObjectReplicationPolicy;
import com.azure.storage.blob.models.ObjectReplicationRule;
import com.azure.storage.blob.models.ObjectReplicationStatus;
Expand All @@ -37,6 +38,7 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -500,4 +502,39 @@ public static BlobQueryHeaders transformQueryHeaders(HttpHeaders headers) {
throw LOGGER.logExceptionAsError(new RuntimeException(e));
}
}

public static void validateConditionsNotPresent(BlobRequestConditions requestConditions,
EnumSet<BlobRequestConditionProperty> invalidConditions) {
if (requestConditions == null) {
return;
}
if (invalidConditions.contains(BlobRequestConditionProperty.LEASE_ID)
&& requestConditions.getLeaseId() != null) {
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'leaseId' is not applicable to this API."));
}
if (invalidConditions.contains(BlobRequestConditionProperty.TAGS_CONDITIONS)
&& requestConditions.getTagsConditions() != null) {
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'tagsConditions' is not applicable to "
+ "this API."));
}
if (invalidConditions.contains(BlobRequestConditionProperty.IF_MODIFIED_SINCE)
&& requestConditions.getIfModifiedSince() != null) {
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'ifModifiedSince' is not applicable to "
+ "this API."));
}
if (invalidConditions.contains(BlobRequestConditionProperty.IF_UNMODIFIED_SINCE)
&& requestConditions.getIfUnmodifiedSince() != null) {
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'ifUnmodifiedSince' is not applicable to "
+ "this API."));
}
if (invalidConditions.contains(BlobRequestConditionProperty.IF_MATCH)
&& requestConditions.getIfMatch() != null) {
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'ifMatch' is not applicable to this API."));
}
if (invalidConditions.contains(BlobRequestConditionProperty.IF_NONE_MATCH)
&& requestConditions.getIfNoneMatch() != null) {
throw LOGGER.logExceptionAsError(new IllegalArgumentException("'ifNoneMatch' is not applicable to this "
+ "API."));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,10 @@
/**
* The blob legal hold result.
*/
public class BlobLegalHoldResult {

private final boolean hasLegalHold;

/**
* Creates a new BlobLegalHoldResult
* @param hasLegalHold whether or not a legal hold is enabled on the blob.
*/
public BlobLegalHoldResult(boolean hasLegalHold) {
this.hasLegalHold = hasLegalHold;
}
public interface BlobLegalHoldResult {

/**
* @return whether or not a legal hold is enabled on the blob.
*/
public boolean hasLegalHold() {
return hasLegalHold;
}
boolean hasLegalHold();
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,21 @@
import com.azure.storage.blob.implementation.models.BlobsSetImmutabilityPolicyHeaders;
import com.azure.storage.blob.implementation.models.BlobsStartCopyFromURLHeaders;
import com.azure.storage.blob.implementation.models.EncryptionScope;
import com.azure.storage.blob.implementation.models.InternalBlobLegalHoldResult;
import com.azure.storage.blob.implementation.models.QueryRequest;
import com.azure.storage.blob.implementation.models.QuerySerialization;
import com.azure.storage.blob.implementation.util.BlobQueryReader;
import com.azure.storage.blob.implementation.util.BlobRequestConditionProperty;
import com.azure.storage.blob.implementation.util.BlobSasImplUtil;
import com.azure.storage.blob.implementation.util.ChunkedDownloadUtils;
import com.azure.storage.blob.implementation.util.ModelHelper;
import com.azure.storage.blob.models.AccessTier;
import com.azure.storage.blob.models.ArchiveStatus;
import com.azure.storage.blob.models.BlobDownloadContentAsyncResponse;
import com.azure.storage.blob.models.BlobDownloadHeaders;
import com.azure.storage.blob.models.BlobBeginCopySourceRequestConditions;
import com.azure.storage.blob.models.BlobCopyInfo;
import com.azure.storage.blob.models.BlobDownloadAsyncResponse;
import com.azure.storage.blob.models.BlobDownloadContentAsyncResponse;
import com.azure.storage.blob.models.BlobDownloadHeaders;
import com.azure.storage.blob.models.BlobHttpHeaders;
import com.azure.storage.blob.models.BlobImmutabilityPolicy;
import com.azure.storage.blob.models.BlobImmutabilityPolicyMode;
Expand Down Expand Up @@ -99,6 +101,7 @@
import java.time.Duration;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -2240,7 +2243,12 @@ Mono<Response<BlobImmutabilityPolicy>> setImmutabilityPolicyWithResponse(

BlobRequestConditions finalRequestConditions = requestConditions == null
? new BlobRequestConditions() : requestConditions;
// TODO (gapra) : Discuss, should we just expose ifUnmodifiedSince here?

ModelHelper.validateConditionsNotPresent(finalRequestConditions,
EnumSet.of(BlobRequestConditionProperty.LEASE_ID, BlobRequestConditionProperty.TAGS_CONDITIONS,
BlobRequestConditionProperty.IF_MATCH, BlobRequestConditionProperty.IF_NONE_MATCH,
BlobRequestConditionProperty.IF_MODIFIED_SINCE));

return this.azureBlobStorage.getBlobs().setImmutabilityPolicyWithResponseAsync(containerName, blobName, null,
null, finalRequestConditions.getIfUnmodifiedSince(), finalImmutabilityPolicy.getExpiryTime(),
finalImmutabilityPolicy.getPolicyMode(),
Expand Down Expand Up @@ -2349,6 +2357,6 @@ Mono<Response<BlobLegalHoldResult>> setLegalHoldWithResponse(boolean legalHold,
legalHold, null, null,
context.addData(AZ_TRACING_NAMESPACE_KEY, STORAGE_TRACING_NAMESPACE_VALUE))
.map(response -> new SimpleResponse<>(response,
new BlobLegalHoldResult(response.getDeserializedHeaders().isXMsLegalHold())));
new InternalBlobLegalHoldResult(response.getDeserializedHeaders().isXMsLegalHold())));
}
}
Loading

0 comments on commit a5d3f39

Please sign in to comment.