Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/storage/blob base client request validation #22136

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
- Added support for OAuth copy sources for synchronous copy operations.
- Added support for Parquet as an input format in BlockBlobClient.Query().
- Added optimization to unwrap encryption key once for DownloadTo and OpenRead when Client Side Encryption is enabled.
- Added support for RequestConditions parameter validation. If a request condition is set for an API that doesn't support it, and Arguement Exception will be thrown.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should mention compat switch in changelog.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compat switch?

- This feature can be disabled with the environment variable "AZURE_STORAGE_DISABLE_REQUEST_CONDITIONS_VALIDATION" or the App Context switch "Azure.Storage.DisableRequestConditionsValidation".

## 12.9.1 (2021-06-23)
- Added optimization to unwrap encryption key once for DownloadTo and OpenRead when Client Side Encryption is enabled.
Expand Down
96 changes: 96 additions & 0 deletions sdk/storage/Azure.Storage.Blobs/src/BlobBaseClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,12 @@ private async Task<Response<BlobDownloadStreamingResult>> StartDownloadAsync(

ResponseWithHeaders<Stream, BlobDownloadHeaders> response;

// All BlobRequestConditions are valid.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is the case, is this just here just in case of the future that there are conditions added that are invalid?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep!

conditions.ValidateConditionsNotPresent(
invalidConditions: BlobRequestConditionProperty.None,
operationName: nameof(BlobBaseClient.Download),
parameterName: nameof(conditions));

if (async)
{
response = await BlobRestClient.DownloadAsync(
Expand Down Expand Up @@ -2546,6 +2552,18 @@ private async Task<Response<BlobCopyInfo>> StartCopyFromUriInternal(

DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(BlobBaseClient)}.{nameof(StartCopyFromUri)}");

// All BlobRequestConditions are valid.
destinationConditions.ValidateConditionsNotPresent(
invalidConditions: BlobRequestConditionProperty.None,
operationName: nameof(BlobBaseClient.StartCopyFromUri),
parameterName: nameof(destinationConditions));

sourceConditions.ValidateConditionsNotPresent(
invalidConditions:
BlobRequestConditionProperty.LeaseId,
operationName: nameof(BlobBaseClient.StartCopyFromUri),
parameterName: nameof(sourceConditions));

try
{
scope.Start();
Expand Down Expand Up @@ -2746,6 +2764,16 @@ private async Task<Response> AbortCopyFromUriInternal(

DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(BlobBaseClient)}.{nameof(AbortCopyFromUri)}");

conditions.ValidateConditionsNotPresent(
invalidConditions:
BlobRequestConditionProperty.IfModifiedSince
| BlobRequestConditionProperty.IfUnmodifiedSince
| BlobRequestConditionProperty.IfMatch
| BlobRequestConditionProperty.IfNoneMatch
| BlobRequestConditionProperty.TagConditions,
operationName: nameof(BlobBaseClient.AbortCopyFromUri),
parameterName: nameof(conditions));

try
{
scope.Start();
Expand Down Expand Up @@ -2974,6 +3002,17 @@ private async Task<Response<BlobCopyInfo>> SyncCopyFromUriInternal(
{
DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(BlobBaseClient)}.{nameof(SyncCopyFromUri)}");

// All BlobRequestConditions are valid for destinationConditions.
destinationConditions.ValidateConditionsNotPresent(
invalidConditions: BlobRequestConditionProperty.None,
operationName: nameof(BlobBaseClient.SyncCopyFromUri),
parameterName: nameof(destinationConditions));

sourceConditions.ValidateConditionsNotPresent(
invalidConditions: BlobRequestConditionProperty.LeaseId,
operationName: nameof(BlobBaseClient.SyncCopyFromUri),
parameterName: nameof(sourceConditions));

try
{
ClientConfiguration.Pipeline.LogMethodEnter(
Expand Down Expand Up @@ -3363,6 +3402,12 @@ private async Task<Response> DeleteInternal(
operationName ??= $"{nameof(BlobBaseClient)}.{nameof(Delete)}";
DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope(operationName);

// All BlobRequestConditions are valid.
conditions.ValidateConditionsNotPresent(
invalidConditions: BlobRequestConditionProperty.None,
operationName: nameof(BlobBaseClient.Delete),
parameterName: nameof(conditions));

try
{
scope.Start();
Expand Down Expand Up @@ -3767,6 +3812,12 @@ internal async Task<Response<BlobProperties>> GetPropertiesInternal(
operationName ??= $"{nameof(BlobBaseClient)}.{nameof(GetProperties)}";
DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope(operationName);

// All BlobRequestConditions are valid.
conditions.ValidateConditionsNotPresent(
invalidConditions: BlobRequestConditionProperty.None,
operationName: nameof(BlobBaseClient.GetProperties),
parameterName: nameof(conditions));

try
{
scope.Start();
Expand Down Expand Up @@ -3946,6 +3997,12 @@ private async Task<Response<BlobInfo>> SetHttpHeadersInternal(

DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(BlobBaseClient)}.{nameof(SetHttpHeaders)}");

// All BlobRequestConditions are valid.
conditions.ValidateConditionsNotPresent(
invalidConditions: BlobRequestConditionProperty.None,
operationName: nameof(BlobBaseClient.SetHttpHeaders),
parameterName: nameof(conditions));

try
{
scope.Start();
Expand Down Expand Up @@ -4129,6 +4186,12 @@ private async Task<Response<BlobInfo>> SetMetadataInternal(

DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(BlobBaseClient)}.{nameof(SetMetadata)}");

// All BlobRequestConditions are valid.
conditions.ValidateConditionsNotPresent(
invalidConditions: BlobRequestConditionProperty.None,
operationName: nameof(BlobBaseClient.SetMetadata),
parameterName: nameof(conditions));

try
{
scope.Start();
Expand Down Expand Up @@ -4310,6 +4373,12 @@ private async Task<Response<BlobSnapshotInfo>> CreateSnapshotInternal(

DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(BlobBaseClient)}.{nameof(CreateSnapshot)}");

// All BlobRequestConditions are valid.
conditions.ValidateConditionsNotPresent(
invalidConditions:BlobRequestConditionProperty.None,
operationName: nameof(BlobBaseClient.CreateSnapshot),
parameterName: nameof(conditions));

try
{
scope.Start();
Expand Down Expand Up @@ -4533,6 +4602,15 @@ private async Task<Response> SetAccessTierInternal(

DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(BlobBaseClient)}.{nameof(SetAccessTier)}");

conditions.ValidateConditionsNotPresent(
invalidConditions:
BlobRequestConditionProperty.IfModifiedSince
| BlobRequestConditionProperty.IfUnmodifiedSince
| BlobRequestConditionProperty.IfMatch
| BlobRequestConditionProperty.IfNoneMatch,
operationName: nameof(BlobBaseClient.SetAccessTier),
parameterName: nameof(conditions));

try
{
scope.Start();
Expand Down Expand Up @@ -4680,6 +4758,15 @@ private async Task<Response<GetBlobTagResult>> GetTagsInternal(

DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(BlobBaseClient)}.{nameof(GetTags)}");

conditions.ValidateConditionsNotPresent(
invalidConditions:
BlobRequestConditionProperty.IfModifiedSince
| BlobRequestConditionProperty.IfUnmodifiedSince
| BlobRequestConditionProperty.IfMatch
| BlobRequestConditionProperty.IfNoneMatch,
operationName: nameof(BlobBaseClient.GetTags),
parameterName: nameof(conditions));

try
{
scope.Start();
Expand Down Expand Up @@ -4855,6 +4942,15 @@ private async Task<Response> SetTagsInternal(

DiagnosticScope scope = ClientConfiguration.ClientDiagnostics.CreateScope($"{nameof(BlobBaseClient)}.{nameof(SetTags)}");

conditions.ValidateConditionsNotPresent(
invalidConditions:
BlobRequestConditionProperty.IfModifiedSince
| BlobRequestConditionProperty.IfUnmodifiedSince
| BlobRequestConditionProperty.IfMatch
| BlobRequestConditionProperty.IfNoneMatch,
operationName: nameof(BlobBaseClient.SetTags),
parameterName: nameof(conditions));

try
{
scope.Start();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;

namespace Azure.Storage.Blobs.Models
{
[Flags]
internal enum BlobRequestConditionProperty
{
None = 0,
Expand Down
Loading