Skip to content

Commit

Permalink
Changed ShareClient.SetTier() -> .SetProperties() (#15932)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanmcc-msft authored Oct 13, 2020
1 parent 14a2fc9 commit da6b8dd
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 218 deletions.
1 change: 1 addition & 0 deletions sdk/storage/Azure.Storage.Files.Shares/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 12.5.0-preview.2 (Unreleased)
- Fixed bug where ShareDirectoryClient.Exists() and ShareFileClient.Exists() would thrown an exception when the directory or file's parent directory didn't exist.
- Added seekability to ShareFileClient.OpenRead().
- Renamed ShareClient.SetTier() -> ShareClient.SetProperties(). SetProperties() can be used to set both Share Tier and Share Quota.

## 12.5.0-preview.1 (2020-09-30)
- Added support for service version 2020-02-10.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,19 @@ public ShareClient(System.Uri shareUri, Azure.Storage.StorageSharedKeyCredential
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Files.Shares.Models.ShareInfo>> SetAccessPolicyAsync(System.Collections.Generic.IEnumerable<Azure.Storage.Files.Shares.Models.ShareSignedIdentifier> permissions, Azure.Storage.Files.Shares.Models.ShareFileRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Files.Shares.Models.ShareInfo>> SetAccessPolicyAsync(System.Collections.Generic.IEnumerable<Azure.Storage.Files.Shares.Models.ShareSignedIdentifier> permissions, System.Threading.CancellationToken cancellationToken) { throw null; }
public virtual Azure.Response<Azure.Storage.Files.Shares.Models.ShareInfo> SetAccessTier(Azure.Storage.Files.Shares.Models.ShareAccessTier? accessTier, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Files.Shares.Models.ShareInfo>> SetAccessTierAsync(Azure.Storage.Files.Shares.Models.ShareAccessTier? accessTier, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Storage.Files.Shares.Models.ShareInfo> SetMetadata(System.Collections.Generic.IDictionary<string, string> metadata, Azure.Storage.Files.Shares.Models.ShareFileRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public virtual Azure.Response<Azure.Storage.Files.Shares.Models.ShareInfo> SetMetadata(System.Collections.Generic.IDictionary<string, string> metadata, System.Threading.CancellationToken cancellationToken) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Files.Shares.Models.ShareInfo>> SetMetadataAsync(System.Collections.Generic.IDictionary<string, string> metadata, Azure.Storage.Files.Shares.Models.ShareFileRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Files.Shares.Models.ShareInfo>> SetMetadataAsync(System.Collections.Generic.IDictionary<string, string> metadata, System.Threading.CancellationToken cancellationToken) { throw null; }
public virtual Azure.Response<Azure.Storage.Files.Shares.Models.ShareInfo> SetProperties(Azure.Storage.Files.Shares.Models.ShareSetPropertiesOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Files.Shares.Models.ShareInfo>> SetPropertiesAsync(Azure.Storage.Files.Shares.Models.ShareSetPropertiesOptions options, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public virtual Azure.Response<Azure.Storage.Files.Shares.Models.ShareInfo> SetQuota(int quotaInGB = 0, Azure.Storage.Files.Shares.Models.ShareFileRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public virtual Azure.Response<Azure.Storage.Files.Shares.Models.ShareInfo> SetQuota(int quotaInGB, System.Threading.CancellationToken cancellationToken) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Files.Shares.Models.ShareInfo>> SetQuotaAsync(int quotaInGB = 0, Azure.Storage.Files.Shares.Models.ShareFileRequestConditions conditions = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Storage.Files.Shares.Models.ShareInfo>> SetQuotaAsync(int quotaInGB, System.Threading.CancellationToken cancellationToken) { throw null; }
Expand Down Expand Up @@ -821,6 +823,13 @@ public ShareServiceProperties() { }
public Azure.Storage.Files.Shares.Models.ShareMetrics MinuteMetrics { get { throw null; } set { } }
public Azure.Storage.Files.Shares.Models.ShareProtocolSettings Protocol { get { throw null; } set { } }
}
public partial class ShareSetPropertiesOptions
{
public ShareSetPropertiesOptions() { }
public Azure.Storage.Files.Shares.Models.ShareAccessTier? AccessTier { get { throw null; } set { } }
public Azure.Storage.Files.Shares.Models.ShareFileRequestConditions Conditions { get { throw null; } set { } }
public int? QuotaInGB { get { throw null; } set { } }
}
public partial class ShareSignedIdentifier
{
public ShareSignedIdentifier() { }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

namespace Azure.Storage.Files.Shares.Models
{
/// <summary>
///
/// </summary>
public class ShareSetPropertiesOptions
{
/// <summary>
/// Optional, the maximum size to set on the share in GB.
/// </summary>
public int? QuotaInGB { get; set; }

/// <summary>
/// Optional, the access tier to set on the share.
/// </summary>
public ShareAccessTier? AccessTier { get; set; }

/// <summary>
/// Optional <see cref="ShareFileRequestConditions"/> to add conditions
/// on setting the share's properties.
/// </summary>
public ShareFileRequestConditions Conditions { get; set; }
}
}
153 changes: 58 additions & 95 deletions sdk/storage/Azure.Storage.Files.Shares/src/ShareClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1621,16 +1621,16 @@ private async Task<Response<ShareProperties>> GetPropertiesInternal(
}
#endregion GetProperties

#region SetAccessTier
#region SetProperties
/// <summary>
/// Sets access tier of the share.
/// Sets properties of the share.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/set-share-properties">
/// Set Share Properties</see>.
/// </summary>
/// <param name="accessTier">
/// Access tier to set on the share.
/// <param name="options">
/// Properties to set on the share.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
Expand All @@ -1644,24 +1644,27 @@ private async Task<Response<ShareProperties>> GetPropertiesInternal(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
public virtual Response<ShareInfo> SetAccessTier(
ShareAccessTier? accessTier,
public virtual Response<ShareInfo> SetProperties(
ShareSetPropertiesOptions options,
CancellationToken cancellationToken = default) =>
SetAccessTierInternal(
accessTier,
SetPropertiesInternal(
quotaInGB: options?.QuotaInGB,
accessTier: options?.AccessTier,
conditions: options?.Conditions,
operationName: $"{nameof(ShareClient)}.{nameof(SetProperties)}",
async: false,
cancellationToken)
.EnsureCompleted();

/// <summary>
/// Sets access tier of the share.
/// Sets properties of the share.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/set-share-properties">
/// Set Share Properties</see>.
/// </summary>
/// <param name="accessTier">
/// Access tier to set on the share.
/// <param name="options">
/// Properties to set on the share.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
Expand All @@ -1675,11 +1678,14 @@ public virtual Response<ShareInfo> SetAccessTier(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
public virtual async Task<Response<ShareInfo>> SetAccessTierAsync(
ShareAccessTier? accessTier,
public virtual async Task<Response<ShareInfo>> SetPropertiesAsync(
ShareSetPropertiesOptions options,
CancellationToken cancellationToken = default) =>
await SetAccessTierInternal(
accessTier,
await SetPropertiesInternal(
quotaInGB: options?.QuotaInGB,
accessTier: options?.AccessTier,
conditions: options?.Conditions,
operationName: $"{nameof(ShareClient)}.{nameof(SetProperties)}",
async: true,
cancellationToken)
.ConfigureAwait(false);
Expand All @@ -1691,9 +1697,20 @@ await SetAccessTierInternal(
/// <see href="https://docs.microsoft.com/rest/api/storageservices/set-share-properties">
/// Set Share Properties</see>.
/// </summary>
/// <param name="quotaInGB">
/// Optional. The maximum size of the share.
/// If unspecified, use the service's default value.
/// </param>
/// <param name="accessTier">
/// Access tier to set on the share.
/// </param>
/// <param name="conditions">
/// Optional <see cref="ShareFileRequestConditions"/> to add conditions
/// on setting the quota.
/// </param>
/// <param name="operationName">
/// The name of the calling operation.
/// </param>
/// <param name="async">
/// Whether to invoke the operation asynchronously.
/// </param>
Expand All @@ -1709,8 +1726,11 @@ await SetAccessTierInternal(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
internal virtual async Task<Response<ShareInfo>> SetAccessTierInternal(
internal virtual async Task<Response<ShareInfo>> SetPropertiesInternal(
int? quotaInGB,
ShareAccessTier? accessTier,
ShareFileRequestConditions conditions,
string operationName,
bool async,
CancellationToken cancellationToken)
{
Expand All @@ -1728,9 +1748,11 @@ internal virtual async Task<Response<ShareInfo>> SetAccessTierInternal(
Pipeline,
Uri,
version: Version.ToVersionString(),
quotaInGB: quotaInGB,
accessTier: accessTier,
leaseId: conditions?.LeaseId,
async: async,
operationName: $"{nameof(ShareClient)}.{nameof(SetAccessTier)}",
operationName: operationName,
cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
Expand All @@ -1745,7 +1767,7 @@ internal virtual async Task<Response<ShareInfo>> SetAccessTierInternal(
}
}
}
#endregion SetAccessTier
#endregion SetProperties

#region SetQuota
/// <summary>
Expand Down Expand Up @@ -1775,13 +1797,16 @@ internal virtual async Task<Response<ShareInfo>> SetAccessTierInternal(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual Response<ShareInfo> SetQuota(
int quotaInGB = default,
ShareFileRequestConditions conditions = default,
CancellationToken cancellationToken = default) =>
SetQuotaInternal(
quotaInGB,
SetPropertiesInternal(
quotaInGB: quotaInGB,
accessTier: default,
conditions: conditions,
operationName: $"{nameof(ShareClient)}.{nameof(SetQuota)}",
async: false,
cancellationToken)
.EnsureCompleted();
Expand Down Expand Up @@ -1813,13 +1838,16 @@ public virtual Response<ShareInfo> SetQuota(
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual async Task<Response<ShareInfo>> SetQuotaAsync(
int quotaInGB = default,
ShareFileRequestConditions conditions = default,
CancellationToken cancellationToken = default) =>
await SetQuotaInternal(
quotaInGB,
await SetPropertiesInternal(
quotaInGB: quotaInGB,
accessTier: default,
conditions: conditions,
operationName: $"{nameof(ShareClient)}.{nameof(SetQuota)}",
async: true,
cancellationToken)
.ConfigureAwait(false);
Expand Down Expand Up @@ -1854,9 +1882,11 @@ public virtual Response<ShareInfo> SetQuota(
#pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
int quotaInGB,
CancellationToken cancellationToken) =>
SetQuotaInternal(
quotaInGB,
SetPropertiesInternal(
quotaInGB: quotaInGB,
accessTier: default,
conditions: default,
operationName: $"{nameof(ShareClient)}.{nameof(SetQuota)}",
async: false,
cancellationToken)
.EnsureCompleted();
Expand Down Expand Up @@ -1890,81 +1920,14 @@ public virtual async Task<Response<ShareInfo>> SetQuotaAsync(
#pragma warning restore AZC0002 // DO ensure all service methods, both asynchronous and synchronous, take an optional CancellationToken parameter called cancellationToken.
int quotaInGB,
CancellationToken cancellationToken) =>
await SetQuotaInternal(
quotaInGB,
await SetPropertiesInternal(
quotaInGB: quotaInGB,
accessTier: default,
conditions: default,
operationName: $"{nameof(ShareClient)}.{nameof(SetQuota)}",
async: true,
cancellationToken)
.ConfigureAwait(false);

/// <summary>
/// Sets the maximum size of the share.
///
/// For more information, see
/// <see href="https://docs.microsoft.com/rest/api/storageservices/set-share-properties">
/// Set Share Properties</see>.
/// </summary>
/// <param name="quotaInGB">
/// Optional. The maximum size of the share.
/// If unspecified, use the service's default value.
/// </param>
/// <param name="async">
/// Whether to invoke the operation asynchronously.
/// </param>
/// <param name="conditions">
/// Optional <see cref="ShareFileRequestConditions"/> to add conditions
/// on setting the quota.
/// </param>
/// <param name="cancellationToken">
/// Optional <see cref="CancellationToken"/> to propagate
/// notifications that the operation should be cancelled.
/// </param>
/// <returns>
/// A <see cref="Response{ShareInfo}"/> describing the updated
/// share.
/// </returns>
/// <remarks>
/// A <see cref="RequestFailedException"/> will be thrown if
/// a failure occurs.
/// </remarks>
internal virtual async Task<Response<ShareInfo>> SetQuotaInternal(
int quotaInGB,
ShareFileRequestConditions conditions,
bool async,
CancellationToken cancellationToken)
{
using (Pipeline.BeginLoggingScope(nameof(ShareClient)))
{
Pipeline.LogMethodEnter(
nameof(ShareClient),
message:
$"{nameof(Uri)}: {Uri}\n" +
$"{nameof(quotaInGB)}: {quotaInGB}");
try
{
return await FileRestClient.Share.SetPropertiesAsync(
ClientDiagnostics,
Pipeline,
Uri,
version: Version.ToVersionString(),
quotaInGB: quotaInGB,
leaseId: conditions?.LeaseId,
async: async,
operationName: $"{nameof(ShareClient)}.{nameof(SetQuota)}",
cancellationToken: cancellationToken)
.ConfigureAwait(false);
}
catch (Exception ex)
{
Pipeline.LogException(ex);
throw;
}
finally
{
Pipeline.LogMethodExit(nameof(ShareClient));
}
}
}
#endregion SetQuota

#region SetMetadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,12 @@ public async Task ListSharesSegmentAsync_AccessTier()
await using DisposingShare test = await GetTestShareAsync(service);
ShareClient share = test.Share;

await test.Share.SetAccessTierAsync(ShareAccessTier.Hot);
ShareSetPropertiesOptions options = new ShareSetPropertiesOptions
{
AccessTier = ShareAccessTier.Hot
};

await test.Share.SetPropertiesAsync(options);

var shares = new List<ShareItem>();
await foreach (ShareItem shareItem in service.GetSharesAsync())
Expand Down
Loading

0 comments on commit da6b8dd

Please sign in to comment.