From 9272783627c9ffc3afe16dfab62dcedb40210df0 Mon Sep 17 00:00:00 2001 From: Sean McCullough Date: Sun, 12 Apr 2020 13:23:41 -0700 Subject: [PATCH] Added Share Soft Delete swagger --- .../api/Azure.Storage.Blobs.netstandard2.0.cs | 2 +- .../src/Models/BlobsModelFactory.cs | 4 +- ...ure.Storage.Files.Shares.netstandard2.0.cs | 10 +- .../src/Generated/FileRestClient.cs | 223 +++++++++++++++++- .../src/Models/ShareModelFactory.cs | 17 ++ .../swagger/readme.md | 11 +- 6 files changed, 259 insertions(+), 8 deletions(-) diff --git a/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.netstandard2.0.cs b/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.netstandard2.0.cs index 6911714bc858..f3b8ba61f5af 100644 --- a/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.netstandard2.0.cs +++ b/sdk/storage/Azure.Storage.Blobs/api/Azure.Storage.Blobs.netstandard2.0.cs @@ -694,7 +694,7 @@ public static partial class BlobsModelFactory public static Azure.Storage.Blobs.Models.BlobHierarchyItem BlobHierarchyItem(string prefix, Azure.Storage.Blobs.Models.BlobItem blob) { throw null; } public static Azure.Storage.Blobs.Models.BlobInfo BlobInfo(Azure.ETag eTag, System.DateTimeOffset lastModified) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] - public static Azure.Storage.Blobs.Models.BlobItem BlobItem(string name, bool deleted, Azure.Storage.Blobs.Models.BlobItemProperties properties, string snapshot = null, System.Collections.Generic.IDictionary metadata = null) { throw null; } + public static Azure.Storage.Blobs.Models.BlobItem BlobItem(string name, bool deleted, Azure.Storage.Blobs.Models.BlobItemProperties properties, string snapshot, System.Collections.Generic.IDictionary metadata) { throw null; } public static Azure.Storage.Blobs.Models.BlobItem BlobItem(string name, bool deleted, Azure.Storage.Blobs.Models.BlobItemProperties properties, string snapshot = null, string versionId = null, bool? isCurrentVersion = default(bool?), System.Collections.Generic.IDictionary metadata = null, System.Collections.Generic.IDictionary tags = null) { throw null; } public static Azure.Storage.Blobs.Models.BlobItemProperties BlobItemProperties(bool accessTierInferred, string copyProgress = null, string contentType = null, string contentEncoding = null, string contentLanguage = null, byte[] contentHash = null, string contentDisposition = null, string cacheControl = null, long? blobSequenceNumber = default(long?), Azure.Storage.Blobs.Models.BlobType? blobType = default(Azure.Storage.Blobs.Models.BlobType?), Azure.Storage.Blobs.Models.LeaseStatus? leaseStatus = default(Azure.Storage.Blobs.Models.LeaseStatus?), Azure.Storage.Blobs.Models.LeaseState? leaseState = default(Azure.Storage.Blobs.Models.LeaseState?), Azure.Storage.Blobs.Models.LeaseDurationType? leaseDuration = default(Azure.Storage.Blobs.Models.LeaseDurationType?), string copyId = null, Azure.Storage.Blobs.Models.CopyStatus? copyStatus = default(Azure.Storage.Blobs.Models.CopyStatus?), System.Uri copySource = null, long? contentLength = default(long?), string copyStatusDescription = null, bool? serverEncrypted = default(bool?), bool? incrementalCopy = default(bool?), string destinationSnapshot = null, int? remainingRetentionDays = default(int?), Azure.Storage.Blobs.Models.AccessTier? accessTier = default(Azure.Storage.Blobs.Models.AccessTier?), System.DateTimeOffset? lastModified = default(System.DateTimeOffset?), Azure.Storage.Blobs.Models.ArchiveStatus? archiveStatus = default(Azure.Storage.Blobs.Models.ArchiveStatus?), string customerProvidedKeySha256 = null, string encryptionScope = null, Azure.ETag? eTag = default(Azure.ETag?), System.DateTimeOffset? createdOn = default(System.DateTimeOffset?), System.DateTimeOffset? copyCompletedOn = default(System.DateTimeOffset?), System.DateTimeOffset? deletedOn = default(System.DateTimeOffset?), System.DateTimeOffset? accessTierChangedOn = default(System.DateTimeOffset?)) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] diff --git a/sdk/storage/Azure.Storage.Blobs/src/Models/BlobsModelFactory.cs b/sdk/storage/Azure.Storage.Blobs/src/Models/BlobsModelFactory.cs index 6b41d0dc5de9..dcd6f37cd8f8 100644 --- a/sdk/storage/Azure.Storage.Blobs/src/Models/BlobsModelFactory.cs +++ b/sdk/storage/Azure.Storage.Blobs/src/Models/BlobsModelFactory.cs @@ -315,8 +315,8 @@ public static BlobItem BlobItem( string name, bool deleted, BlobItemProperties properties, - string snapshot = default, - IDictionary metadata = default) + string snapshot, + IDictionary metadata) => new BlobItem() { Name = name, diff --git a/sdk/storage/Azure.Storage.Files.Shares/api/Azure.Storage.Files.Shares.netstandard2.0.cs b/sdk/storage/Azure.Storage.Files.Shares/api/Azure.Storage.Files.Shares.netstandard2.0.cs index 5b55ae772402..783598d8996a 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/api/Azure.Storage.Files.Shares.netstandard2.0.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/api/Azure.Storage.Files.Shares.netstandard2.0.cs @@ -588,9 +588,11 @@ internal ShareInfo() { } public partial class ShareItem { internal ShareItem() { } + public bool? Deleted { get { throw null; } } public string Name { get { throw null; } } public Azure.Storage.Files.Shares.Models.ShareProperties Properties { get { throw null; } } public string Snapshot { get { throw null; } } + public string Version { get { throw null; } } } public enum ShareLeaseDuration { @@ -628,10 +630,12 @@ public static partial class ShareModelFactory public static Azure.Storage.Files.Shares.Models.ShareFileRangeInfo ShareFileRangeInfo(System.DateTimeOffset lastModified, Azure.ETag eTag, long fileContentLength, System.Collections.Generic.IEnumerable ranges) { throw null; } public static Azure.Storage.Files.Shares.Models.ShareFileUploadInfo ShareFileUploadInfo(Azure.ETag eTag, System.DateTimeOffset lastModified, byte[] contentHash, bool isServerEncrypted) { throw null; } public static Azure.Storage.Files.Shares.Models.ShareInfo ShareInfo(Azure.ETag eTag, System.DateTimeOffset lastModified) { throw null; } - public static Azure.Storage.Files.Shares.Models.ShareItem ShareItem(string name, Azure.Storage.Files.Shares.Models.ShareProperties properties, string snapshot = null) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] + public static Azure.Storage.Files.Shares.Models.ShareItem ShareItem(string name, Azure.Storage.Files.Shares.Models.ShareProperties properties, string snapshot) { throw null; } + public static Azure.Storage.Files.Shares.Models.ShareItem ShareItem(string name, Azure.Storage.Files.Shares.Models.ShareProperties properties, string snapshot = null, bool? deleted = default(bool?), string version = null) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static Azure.Storage.Files.Shares.Models.ShareProperties ShareProperties(System.DateTimeOffset? lastModified, Azure.ETag? eTag, int? quotaInGB, System.Collections.Generic.IDictionary metadata) { throw null; } - public static Azure.Storage.Files.Shares.Models.ShareProperties ShareProperties(System.DateTimeOffset? lastModified = default(System.DateTimeOffset?), Azure.ETag? eTag = default(Azure.ETag?), int? provisionedIops = default(int?), int? provisionedIngressMBps = default(int?), int? provisionedEgressMBps = default(int?), System.DateTimeOffset? nextAllowedQuotaDowngradeTime = default(System.DateTimeOffset?), int? quotaInGB = default(int?), System.Collections.Generic.IDictionary metadata = null) { throw null; } + public static Azure.Storage.Files.Shares.Models.ShareProperties ShareProperties(System.DateTimeOffset? lastModified = default(System.DateTimeOffset?), Azure.ETag? eTag = default(Azure.ETag?), int? provisionedIops = default(int?), int? provisionedIngressMBps = default(int?), int? provisionedEgressMBps = default(int?), System.DateTimeOffset? nextAllowedQuotaDowngradeTime = default(System.DateTimeOffset?), System.DateTimeOffset? deletedTime = default(System.DateTimeOffset?), int? remainingRetentionDays = default(int?), int? quotaInGB = default(int?), System.Collections.Generic.IDictionary metadata = null) { throw null; } public static Azure.Storage.Files.Shares.Models.ShareSnapshotInfo ShareSnapshotInfo(string snapshot, Azure.ETag eTag, System.DateTimeOffset lastModified) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static Azure.Storage.Files.Shares.Models.ShareStatistics ShareStatistics(int shareUsageBytes) { throw null; } @@ -643,6 +647,7 @@ public static partial class ShareModelFactory public partial class ShareProperties { internal ShareProperties() { } + public System.DateTimeOffset? DeletedTime { get { throw null; } } public Azure.ETag? ETag { get { throw null; } } public System.DateTimeOffset? LastModified { get { throw null; } } public System.Collections.Generic.IDictionary Metadata { get { throw null; } } @@ -651,6 +656,7 @@ internal ShareProperties() { } public int? ProvisionedIngressMBps { get { throw null; } } public int? ProvisionedIops { get { throw null; } } public int? QuotaInGB { get { throw null; } } + public int? RemainingRetentionDays { get { throw null; } } } public partial class ShareRetentionPolicy { diff --git a/sdk/storage/Azure.Storage.Files.Shares/src/Generated/FileRestClient.cs b/sdk/storage/Azure.Storage.Files.Shares/src/Generated/FileRestClient.cs index 131c6a01f64c..6d7836677a3a 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/src/Generated/FileRestClient.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/src/Generated/FileRestClient.cs @@ -2195,6 +2195,170 @@ internal static Azure.Core.HttpMessage GetStatisticsAsync_CreateMessage( } } #endregion Share.GetStatisticsAsync + + #region Share.RestoreAsync + /// + /// Restores a previously deleted Share. + /// + /// The ClientDiagnostics instance used for operation reporting. + /// The pipeline used for sending requests. + /// The URL of the service account, share, directory or file that is the target of the desired operation. + /// Specifies the version of the operation to use for this request. + /// The timeout parameter is expressed in seconds. For more information, see Setting Timeouts for File Service Operations. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Specifies the name of the preivously-deleted share. + /// Specifies the version of the preivously-deleted share. + /// Whether to invoke the operation asynchronously. The default value is true. + /// Operation name. + /// Cancellation token. + /// Azure.Response{Azure.Storage.Files.Shares.Models.ShareInfo} + public static async System.Threading.Tasks.ValueTask> RestoreAsync( + Azure.Core.Pipeline.ClientDiagnostics clientDiagnostics, + Azure.Core.Pipeline.HttpPipeline pipeline, + System.Uri resourceUri, + string version, + int? timeout = default, + string requestId = default, + string deletedShareName = default, + string deletedShareVersion = default, + bool async = true, + string operationName = "ShareClient.Restore", + System.Threading.CancellationToken cancellationToken = default) + { + Azure.Core.Pipeline.DiagnosticScope _scope = clientDiagnostics.CreateScope(operationName); + try + { + _scope.AddAttribute("url", resourceUri); + _scope.Start(); + using (Azure.Core.HttpMessage _message = RestoreAsync_CreateMessage( + pipeline, + resourceUri, + version, + timeout, + requestId, + deletedShareName, + deletedShareVersion)) + { + if (async) + { + // Send the request asynchronously if we're being called via an async path + await pipeline.SendAsync(_message, cancellationToken).ConfigureAwait(false); + } + else + { + // Send the request synchronously through the API that blocks if we're being called via a sync path + // (this is safe because the Task will complete before the user can call Wait) + pipeline.Send(_message, cancellationToken); + } + Azure.Response _response = _message.Response; + cancellationToken.ThrowIfCancellationRequested(); + return RestoreAsync_CreateResponse(clientDiagnostics, _response); + } + } + catch (System.Exception ex) + { + _scope.Failed(ex); + throw; + } + finally + { + _scope.Dispose(); + } + } + + /// + /// Create the Share.RestoreAsync request. + /// + /// The pipeline used for sending requests. + /// The URL of the service account, share, directory or file that is the target of the desired operation. + /// Specifies the version of the operation to use for this request. + /// The timeout parameter is expressed in seconds. For more information, see Setting Timeouts for File Service Operations. + /// Provides a client-generated, opaque value with a 1 KB character limit that is recorded in the analytics logs when storage analytics logging is enabled. + /// Specifies the name of the preivously-deleted share. + /// Specifies the version of the preivously-deleted share. + /// The Share.RestoreAsync Message. + internal static Azure.Core.HttpMessage RestoreAsync_CreateMessage( + Azure.Core.Pipeline.HttpPipeline pipeline, + System.Uri resourceUri, + string version, + int? timeout = default, + string requestId = default, + string deletedShareName = default, + string deletedShareVersion = default) + { + // Validation + if (resourceUri == null) + { + throw new System.ArgumentNullException(nameof(resourceUri)); + } + if (version == null) + { + throw new System.ArgumentNullException(nameof(version)); + } + + // Create the request + Azure.Core.HttpMessage _message = pipeline.CreateMessage(); + Azure.Core.Request _request = _message.Request; + + // Set the endpoint + _request.Method = Azure.Core.RequestMethod.Put; + _request.Uri.Reset(resourceUri); + _request.Uri.AppendQuery("restype", "share", escapeValue: false); + _request.Uri.AppendQuery("comp", "undelete", escapeValue: false); + if (timeout != null) { _request.Uri.AppendQuery("timeout", timeout.Value.ToString(System.Globalization.CultureInfo.InvariantCulture)); } + + // Add request headers + _request.Headers.SetValue("x-ms-version", version); + if (requestId != null) { _request.Headers.SetValue("x-ms-client-request-id", requestId); } + if (deletedShareName != null) { _request.Headers.SetValue("x-ms-deleted-share-name", deletedShareName); } + if (deletedShareVersion != null) { _request.Headers.SetValue("x-ms-deleted-share-version", deletedShareVersion); } + + return _message; + } + + /// + /// Create the Share.RestoreAsync response or throw a failure exception. + /// + /// The ClientDiagnostics instance to use. + /// The raw Response. + /// The Share.RestoreAsync Azure.Response{Azure.Storage.Files.Shares.Models.ShareInfo}. + internal static Azure.Response RestoreAsync_CreateResponse( + Azure.Core.Pipeline.ClientDiagnostics clientDiagnostics, + Azure.Response response) + { + // Process the response + switch (response.Status) + { + case 201: + { + // Create the result + Azure.Storage.Files.Shares.Models.ShareInfo _value = new Azure.Storage.Files.Shares.Models.ShareInfo(); + + // Get response headers + string _header; + if (response.Headers.TryGetValue("ETag", out _header)) + { + _value.ETag = new Azure.ETag(_header); + } + if (response.Headers.TryGetValue("Last-Modified", out _header)) + { + _value.LastModified = System.DateTimeOffset.Parse(_header, System.Globalization.CultureInfo.InvariantCulture); + } + + // Create the response + return Response.FromValue(_value, response); + } + default: + { + // Create the result + System.Xml.Linq.XDocument _xml = System.Xml.Linq.XDocument.Load(response.ContentStream, System.Xml.Linq.LoadOptions.PreserveWhitespace); + Azure.Storage.Files.Shares.Models.StorageError _value = Azure.Storage.Files.Shares.Models.StorageError.FromXml(_xml.Root); + + throw _value.CreateException(clientDiagnostics, response); + } + } + } + #endregion Share.RestoreAsync } #endregion Share operations @@ -7935,7 +8099,12 @@ internal enum ListSharesIncludeType /// /// metadata /// - Metadata + Metadata, + + /// + /// deleted + /// + Deleted } } @@ -7951,6 +8120,7 @@ public static string ToString(Azure.Storage.Files.Shares.Models.ListSharesInclud { Azure.Storage.Files.Shares.Models.ListSharesIncludeType.Snapshots => "snapshots", Azure.Storage.Files.Shares.Models.ListSharesIncludeType.Metadata => "metadata", + Azure.Storage.Files.Shares.Models.ListSharesIncludeType.Deleted => "deleted", _ => throw new System.ArgumentOutOfRangeException(nameof(value), value, "Unknown Azure.Storage.Files.Shares.Models.ListSharesIncludeType value.") }; } @@ -7961,6 +8131,7 @@ public static Azure.Storage.Files.Shares.Models.ListSharesIncludeType ParseListS { "snapshots" => Azure.Storage.Files.Shares.Models.ListSharesIncludeType.Snapshots, "metadata" => Azure.Storage.Files.Shares.Models.ListSharesIncludeType.Metadata, + "deleted" => Azure.Storage.Files.Shares.Models.ListSharesIncludeType.Deleted, _ => throw new System.ArgumentOutOfRangeException(nameof(value), value, "Unknown Azure.Storage.Files.Shares.Models.ListSharesIncludeType value.") }; } @@ -9549,6 +9720,16 @@ public partial class ShareItem /// public string Snapshot { get; internal set; } + /// + /// Deleted + /// + public bool? Deleted { get; internal set; } + + /// + /// Version + /// + public string Version { get; internal set; } + /// /// Properties of a share. /// @@ -9594,6 +9775,16 @@ internal static Azure.Storage.Files.Shares.Models.ShareItem FromXml(System.Xml.L { _value.Snapshot = _child.Value; } + _child = element.Element(System.Xml.Linq.XName.Get("Deleted", "")); + if (_child != null) + { + _value.Deleted = bool.Parse(_child.Value); + } + _child = element.Element(System.Xml.Linq.XName.Get("Version", "")); + if (_child != null) + { + _value.Version = _child.Value; + } _child = element.Element(System.Xml.Linq.XName.Get("Properties", "")); if (_child != null) { @@ -9617,13 +9808,17 @@ public static partial class ShareModelFactory public static ShareItem ShareItem( string name, Azure.Storage.Files.Shares.Models.ShareProperties properties, - string snapshot = default) + string snapshot = default, + bool? deleted = default, + string version = default) { return new ShareItem() { Name = name, Properties = properties, Snapshot = snapshot, + Deleted = deleted, + Version = version, }; } } @@ -9962,6 +10157,16 @@ public partial class ShareProperties /// public System.DateTimeOffset? NextAllowedQuotaDowngradeTime { get; internal set; } + /// + /// DeletedTime + /// + public System.DateTimeOffset? DeletedTime { get; internal set; } + + /// + /// RemainingRetentionDays + /// + public int? RemainingRetentionDays { get; internal set; } + /// /// QuotaInGB /// @@ -10032,6 +10237,16 @@ internal static Azure.Storage.Files.Shares.Models.ShareProperties FromXml(System { _value.NextAllowedQuotaDowngradeTime = System.DateTimeOffset.Parse(_child.Value, System.Globalization.CultureInfo.InvariantCulture); } + _child = element.Element(System.Xml.Linq.XName.Get("DeletedTime", "")); + if (_child != null) + { + _value.DeletedTime = System.DateTimeOffset.Parse(_child.Value, System.Globalization.CultureInfo.InvariantCulture); + } + _child = element.Element(System.Xml.Linq.XName.Get("RemainingRetentionDays", "")); + if (_child != null) + { + _value.RemainingRetentionDays = int.Parse(_child.Value, System.Globalization.CultureInfo.InvariantCulture); + } _child = element.Element(System.Xml.Linq.XName.Get("Quota", "")); if (_child != null) { @@ -10068,6 +10283,8 @@ public static ShareProperties ShareProperties( int? provisionedIngressMBps = default, int? provisionedEgressMBps = default, System.DateTimeOffset? nextAllowedQuotaDowngradeTime = default, + System.DateTimeOffset? deletedTime = default, + int? remainingRetentionDays = default, int? quotaInGB = default, System.Collections.Generic.IDictionary metadata = default) { @@ -10079,6 +10296,8 @@ public static ShareProperties ShareProperties( ProvisionedIngressMBps = provisionedIngressMBps, ProvisionedEgressMBps = provisionedEgressMBps, NextAllowedQuotaDowngradeTime = nextAllowedQuotaDowngradeTime, + DeletedTime = deletedTime, + RemainingRetentionDays = remainingRetentionDays, QuotaInGB = quotaInGB, Metadata = metadata, }; diff --git a/sdk/storage/Azure.Storage.Files.Shares/src/Models/ShareModelFactory.cs b/sdk/storage/Azure.Storage.Files.Shares/src/Models/ShareModelFactory.cs index 3fdb632b0f02..a334e373d5b0 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/src/Models/ShareModelFactory.cs +++ b/sdk/storage/Azure.Storage.Files.Shares/src/Models/ShareModelFactory.cs @@ -36,5 +36,22 @@ public static ShareProperties ShareProperties( eTag: eTag, quotaInGB: quotaInGB, metadata: metadata); + + /// + /// Creates a new ShareItem instance for mocking. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public static ShareItem ShareItem( + string name, + ShareProperties properties, + string snapshot) + { + return new ShareItem() + { + Name = name, + Properties = properties, + Snapshot = snapshot, + }; + } } } diff --git a/sdk/storage/Azure.Storage.Files.Shares/swagger/readme.md b/sdk/storage/Azure.Storage.Files.Shares/swagger/readme.md index f56b9a9b851f..92366621608f 100644 --- a/sdk/storage/Azure.Storage.Files.Shares/swagger/readme.md +++ b/sdk/storage/Azure.Storage.Files.Shares/swagger/readme.md @@ -4,7 +4,7 @@ ## Configuration ``` yaml # Generate file storage -input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/storage-dataplane-preview/specification/storage/data-plane/Microsoft.FileStorage/preview/2019-07-07/file.json +input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/storage-dataplane-preview/specification/storage/data-plane/Microsoft.FileStorage/preview/2019-12-12/file.json output-folder: ../src/Generated clear-output-folder: false @@ -850,6 +850,15 @@ directive: $.head.responses["200"].headers["x-ms-lease-status"]["x-ms-enum"].name = "ShareLeaseStatus"; ``` +### Rename ShareRestoreResult +``` yaml +directive: +- from: swagger-document + where: $["x-ms-paths"]["/{shareName}?restype=share&comp=undelete"] + transform: > + $.put.responses["201"]["x-az-response-name"] = "ShareInfo"; +``` + ### Treat the API version as a parameter instead of a constant ``` yaml directive: