From f962fe17b03f4fa35d6d2eb735565b59f1c63f49 Mon Sep 17 00:00:00 2001 From: Xinni Tong Date: Mon, 11 Nov 2024 15:49:53 +0800 Subject: [PATCH] [AppService] Add status code 202 and allow some properties to be empty (#46960) --- .../CHANGELOG.md | 8 +--- .../AppCertificateData.Serialization.cs | 11 ------ .../src/Generated/AppCertificateCollection.cs | 8 +--- .../AppCertificateOperationSource.cs | 38 +++++++++++++++++++ .../CertificatesRestOperations.cs | 20 +++------- .../src/autorest.md | 23 +++++++++++ .../TestsCase/CertificatesCollectionTests.cs | 5 --- 7 files changed, 71 insertions(+), 42 deletions(-) create mode 100644 sdk/websites/Azure.ResourceManager.AppService/src/Generated/LongRunningOperation/AppCertificateOperationSource.cs diff --git a/sdk/websites/Azure.ResourceManager.AppService/CHANGELOG.md b/sdk/websites/Azure.ResourceManager.AppService/CHANGELOG.md index c2a1ea526e4ac..8b2cd7271b7a2 100644 --- a/sdk/websites/Azure.ResourceManager.AppService/CHANGELOG.md +++ b/sdk/websites/Azure.ResourceManager.AppService/CHANGELOG.md @@ -1,14 +1,10 @@ # Release History -## 1.3.0-beta.2 (Unreleased) - -### Features Added - -### Breaking Changes +## 1.3.0-beta.2 (2024-11-11) ### Bugs Fixed -### Other Changes +- Add status code 202 and allow some properties to be empty. Issue at 'https://github.com/Azure/azure-sdk-for-net/issues/46854. ## 1.3.0-beta.1 (2024-10-14) diff --git a/sdk/websites/Azure.ResourceManager.AppService/src/Customization/Models/AppCertificateData.Serialization.cs b/sdk/websites/Azure.ResourceManager.AppService/src/Customization/Models/AppCertificateData.Serialization.cs index a5f0323bcc3ff..5627c58e011e4 100644 --- a/sdk/websites/Azure.ResourceManager.AppService/src/Customization/Models/AppCertificateData.Serialization.cs +++ b/sdk/websites/Azure.ResourceManager.AppService/src/Customization/Models/AppCertificateData.Serialization.cs @@ -130,7 +130,6 @@ internal static AppCertificateData DeserializeAppCertificateData(JsonElement ele { if (property0.Value.ValueKind == JsonValueKind.Null) { - property0.ThrowNonNullablePropertyIsNull(); continue; } List array = new List(); @@ -145,7 +144,6 @@ internal static AppCertificateData DeserializeAppCertificateData(JsonElement ele { if (property0.Value.ValueKind == JsonValueKind.Null) { - property0.ThrowNonNullablePropertyIsNull(); continue; } pfxBlob = property0.Value.GetBytesFromBase64("D"); @@ -170,7 +168,6 @@ internal static AppCertificateData DeserializeAppCertificateData(JsonElement ele { if (property0.Value.ValueKind == JsonValueKind.Null) { - property0.ThrowNonNullablePropertyIsNull(); continue; } issueDate = property0.Value.GetDateTimeOffset("O"); @@ -180,7 +177,6 @@ internal static AppCertificateData DeserializeAppCertificateData(JsonElement ele { if (property0.Value.ValueKind == JsonValueKind.Null) { - property0.ThrowNonNullablePropertyIsNull(); continue; } expirationDate = property0.Value.GetDateTimeOffset("O"); @@ -190,7 +186,6 @@ internal static AppCertificateData DeserializeAppCertificateData(JsonElement ele { if (property0.Value.ValueKind == JsonValueKind.Null) { - property0.ThrowNonNullablePropertyIsNull(); continue; } thumbprintString = property0.Value.GetString(); @@ -200,7 +195,6 @@ internal static AppCertificateData DeserializeAppCertificateData(JsonElement ele { if (property0.Value.ValueKind == JsonValueKind.Null) { - property0.ThrowNonNullablePropertyIsNull(); continue; } valid = property0.Value.GetBoolean(); @@ -210,7 +204,6 @@ internal static AppCertificateData DeserializeAppCertificateData(JsonElement ele { if (property0.Value.ValueKind == JsonValueKind.Null) { - property0.ThrowNonNullablePropertyIsNull(); continue; } cerBlob = property0.Value.GetBytesFromBase64("D"); @@ -225,7 +218,6 @@ internal static AppCertificateData DeserializeAppCertificateData(JsonElement ele { if (property0.Value.ValueKind == JsonValueKind.Null) { - property0.ThrowNonNullablePropertyIsNull(); continue; } hostingEnvironmentProfile = HostingEnvironmentProfile.DeserializeHostingEnvironmentProfile(property0.Value); @@ -235,7 +227,6 @@ internal static AppCertificateData DeserializeAppCertificateData(JsonElement ele { if (property0.Value.ValueKind == JsonValueKind.Null || property0.Value.GetString().Length == 0) { - property0.ThrowNonNullablePropertyIsNull(); continue; } keyVaultId = new ResourceIdentifier(property0.Value.GetString()); @@ -250,7 +241,6 @@ internal static AppCertificateData DeserializeAppCertificateData(JsonElement ele { if (property0.Value.ValueKind == JsonValueKind.Null) { - property0.ThrowNonNullablePropertyIsNull(); continue; } keyVaultSecretStatus = property0.Value.GetString().ToKeyVaultSecretStatus(); @@ -260,7 +250,6 @@ internal static AppCertificateData DeserializeAppCertificateData(JsonElement ele { if (property0.Value.ValueKind == JsonValueKind.Null) { - property0.ThrowNonNullablePropertyIsNull(); continue; } serverFarmId = new ResourceIdentifier(property0.Value.GetString()); diff --git a/sdk/websites/Azure.ResourceManager.AppService/src/Generated/AppCertificateCollection.cs b/sdk/websites/Azure.ResourceManager.AppService/src/Generated/AppCertificateCollection.cs index 124afe53e70ba..97299aa69a10b 100644 --- a/sdk/websites/Azure.ResourceManager.AppService/src/Generated/AppCertificateCollection.cs +++ b/sdk/websites/Azure.ResourceManager.AppService/src/Generated/AppCertificateCollection.cs @@ -89,9 +89,7 @@ public virtual async Task> CreateOrUpdateAs try { var response = await _appCertificateCertificatesRestClient.CreateOrUpdateAsync(Id.SubscriptionId, Id.ResourceGroupName, name, data, cancellationToken).ConfigureAwait(false); - var uri = _appCertificateCertificatesRestClient.CreateCreateOrUpdateRequestUri(Id.SubscriptionId, Id.ResourceGroupName, name, data); - var rehydrationToken = NextLinkOperationImplementation.GetRehydrationToken(RequestMethod.Put, uri.ToUri(), uri.ToString(), "None", null, OperationFinalStateVia.OriginalUri.ToString()); - var operation = new AppServiceArmOperation(Response.FromValue(new AppCertificateResource(Client, response), response.GetRawResponse()), rehydrationToken); + var operation = new AppServiceArmOperation(new AppCertificateOperationSource(Client), _appCertificateCertificatesClientDiagnostics, Pipeline, _appCertificateCertificatesRestClient.CreateCreateOrUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, name, data).Request, response, OperationFinalStateVia.Location); if (waitUntil == WaitUntil.Completed) await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); return operation; @@ -140,9 +138,7 @@ public virtual ArmOperation CreateOrUpdate(WaitUntil wai try { var response = _appCertificateCertificatesRestClient.CreateOrUpdate(Id.SubscriptionId, Id.ResourceGroupName, name, data, cancellationToken); - var uri = _appCertificateCertificatesRestClient.CreateCreateOrUpdateRequestUri(Id.SubscriptionId, Id.ResourceGroupName, name, data); - var rehydrationToken = NextLinkOperationImplementation.GetRehydrationToken(RequestMethod.Put, uri.ToUri(), uri.ToString(), "None", null, OperationFinalStateVia.OriginalUri.ToString()); - var operation = new AppServiceArmOperation(Response.FromValue(new AppCertificateResource(Client, response), response.GetRawResponse()), rehydrationToken); + var operation = new AppServiceArmOperation(new AppCertificateOperationSource(Client), _appCertificateCertificatesClientDiagnostics, Pipeline, _appCertificateCertificatesRestClient.CreateCreateOrUpdateRequest(Id.SubscriptionId, Id.ResourceGroupName, name, data).Request, response, OperationFinalStateVia.Location); if (waitUntil == WaitUntil.Completed) operation.WaitForCompletion(cancellationToken); return operation; diff --git a/sdk/websites/Azure.ResourceManager.AppService/src/Generated/LongRunningOperation/AppCertificateOperationSource.cs b/sdk/websites/Azure.ResourceManager.AppService/src/Generated/LongRunningOperation/AppCertificateOperationSource.cs new file mode 100644 index 0000000000000..7483d77063d11 --- /dev/null +++ b/sdk/websites/Azure.ResourceManager.AppService/src/Generated/LongRunningOperation/AppCertificateOperationSource.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; + +namespace Azure.ResourceManager.AppService +{ + internal class AppCertificateOperationSource : IOperationSource + { + private readonly ArmClient _client; + + internal AppCertificateOperationSource(ArmClient client) + { + _client = client; + } + + AppCertificateResource IOperationSource.CreateResult(Response response, CancellationToken cancellationToken) + { + using var document = JsonDocument.Parse(response.ContentStream); + var data = AppCertificateData.DeserializeAppCertificateData(document.RootElement); + return new AppCertificateResource(_client, data); + } + + async ValueTask IOperationSource.CreateResultAsync(Response response, CancellationToken cancellationToken) + { + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + var data = AppCertificateData.DeserializeAppCertificateData(document.RootElement); + return new AppCertificateResource(_client, data); + } + } +} diff --git a/sdk/websites/Azure.ResourceManager.AppService/src/Generated/RestOperations/CertificatesRestOperations.cs b/sdk/websites/Azure.ResourceManager.AppService/src/Generated/RestOperations/CertificatesRestOperations.cs index 3458d417d160e..354bb7a838c17 100644 --- a/sdk/websites/Azure.ResourceManager.AppService/src/Generated/RestOperations/CertificatesRestOperations.cs +++ b/sdk/websites/Azure.ResourceManager.AppService/src/Generated/RestOperations/CertificatesRestOperations.cs @@ -352,7 +352,7 @@ internal HttpMessage CreateCreateOrUpdateRequest(string subscriptionId, string r /// The cancellation token to use. /// , , or is null. /// , or is an empty string, and was expected to be non-empty. - public async Task> CreateOrUpdateAsync(string subscriptionId, string resourceGroupName, string name, AppCertificateData data, CancellationToken cancellationToken = default) + public async Task CreateOrUpdateAsync(string subscriptionId, string resourceGroupName, string name, AppCertificateData data, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); Argument.AssertNotNullOrEmpty(resourceGroupName, nameof(resourceGroupName)); @@ -364,12 +364,8 @@ public async Task> CreateOrUpdateAsync(string subsc switch (message.Response.Status) { case 200: - { - AppCertificateData value = default; - using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); - value = AppCertificateData.DeserializeAppCertificateData(document.RootElement); - return Response.FromValue(value, message.Response); - } + case 202: + return message.Response; default: throw new RequestFailedException(message.Response); } @@ -383,7 +379,7 @@ public async Task> CreateOrUpdateAsync(string subsc /// The cancellation token to use. /// , , or is null. /// , or is an empty string, and was expected to be non-empty. - public Response CreateOrUpdate(string subscriptionId, string resourceGroupName, string name, AppCertificateData data, CancellationToken cancellationToken = default) + public Response CreateOrUpdate(string subscriptionId, string resourceGroupName, string name, AppCertificateData data, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); Argument.AssertNotNullOrEmpty(resourceGroupName, nameof(resourceGroupName)); @@ -395,12 +391,8 @@ public Response CreateOrUpdate(string subscriptionId, string switch (message.Response.Status) { case 200: - { - AppCertificateData value = default; - using var document = JsonDocument.Parse(message.Response.ContentStream); - value = AppCertificateData.DeserializeAppCertificateData(document.RootElement); - return Response.FromValue(value, message.Response); - } + case 202: + return message.Response; default: throw new RequestFailedException(message.Response); } diff --git a/sdk/websites/Azure.ResourceManager.AppService/src/autorest.md b/sdk/websites/Azure.ResourceManager.AppService/src/autorest.md index 9abfba71e1989..f4a11b4c1e60a 100644 --- a/sdk/websites/Azure.ResourceManager.AppService/src/autorest.md +++ b/sdk/websites/Azure.ResourceManager.AppService/src/autorest.md @@ -1052,4 +1052,27 @@ directive: $.properties.properties.properties.threads.items = { "$ref": "#/definitions/ProcessThreadProperties" }; + # Fix for issue: https://github.com/Azure/azure-sdk-for-net/issues/46854 + # TODO: Remove this workaround after the issue is resolved. Issue link: https://github.com/Azure/azure-rest-api-specs/issues/19022 + - from: Certificates.json + where: $.paths['/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/certificates/{name}'].put + transform: > + $["x-ms-long-running-operation"] = true; + $['responses'] = { + "200": { + "description": "OK.", + "schema": { + "$ref": "#/definitions/Certificate" + } + }, + "202": { + "description": "OK.", + }, + "default": { + "description": "App Service error response.", + "schema": { + "$ref": "./CommonDefinitions.json#/definitions/DefaultErrorResponse" + } + } + }; ``` diff --git a/sdk/websites/Azure.ResourceManager.AppService/tests/TestsCase/CertificatesCollectionTests.cs b/sdk/websites/Azure.ResourceManager.AppService/tests/TestsCase/CertificatesCollectionTests.cs index 562b1673b56bb..113ef1c13f063 100644 --- a/sdk/websites/Azure.ResourceManager.AppService/tests/TestsCase/CertificatesCollectionTests.cs +++ b/sdk/websites/Azure.ResourceManager.AppService/tests/TestsCase/CertificatesCollectionTests.cs @@ -50,15 +50,10 @@ public async Task CreateOrUpdateWithNullKeyVaultId() KeyVaultId = null // Test to see that if service works fine when we set KeyVaultId to null. }; var collection = Client.GetResourceGroupResource(ResourceGroupResource.CreateResourceIdentifier("db1ab6f0-4769-4b27-930e-01e2ef9c123c", "testRG-666")).GetAppCertificates(); -#if DEBUG - Assert.ThrowsAsync(async delegate { await collection.CreateOrUpdateAsync(WaitUntil.Completed, name, data); }); - await Task.CompletedTask; -#else var lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, name, data); var certificate = lro.Value; Assert.AreEqual(name, certificate.Data.Name); Assert.IsNull(certificate.Data.KeyVaultId); -#endif } [TestCase]