From 70cb4a57e2328fdc2fa273b6e44fed201fdc2df0 Mon Sep 17 00:00:00 2001 From: Dapeng Zhang Date: Tue, 5 Apr 2022 13:42:09 +0800 Subject: [PATCH] change the outputs in AzureXXXScript from Dictionary to BinaryData (#27985) --- .../Azure.ResourceManager.Resources.netstandard2.0.cs | 4 ++-- .../Models/ArmDeploymentScriptPropertiesBase.cs | 5 +---- .../Generated/Models/AzureCliScript.Serialization.cs | 11 +++-------- .../src/Generated/Models/AzureCliScript.cs | 5 ++--- .../Models/AzurePowerShellScript.Serialization.cs | 11 +++-------- .../src/Generated/Models/AzurePowerShellScript.cs | 5 ++--- .../Azure.ResourceManager.Resources/src/autorest.md | 4 ++++ .../tests/Scenario/DeploymentScriptCollectionTests.cs | 11 +++++++---- 8 files changed, 24 insertions(+), 32 deletions(-) diff --git a/sdk/resources/Azure.ResourceManager.Resources/api/Azure.ResourceManager.Resources.netstandard2.0.cs b/sdk/resources/Azure.ResourceManager.Resources/api/Azure.ResourceManager.Resources.netstandard2.0.cs index f1dd4af0a0cc2..e3b69a41650ea 100644 --- a/sdk/resources/Azure.ResourceManager.Resources/api/Azure.ResourceManager.Resources.netstandard2.0.cs +++ b/sdk/resources/Azure.ResourceManager.Resources/api/Azure.ResourceManager.Resources.netstandard2.0.cs @@ -745,7 +745,7 @@ public AzureCliScript(Azure.Core.AzureLocation location, System.TimeSpan retenti public string ContainerGroupName { get { throw null; } set { } } public System.Collections.Generic.IList EnvironmentVariables { get { throw null; } } public string ForceUpdateTag { get { throw null; } set { } } - public System.Collections.Generic.IReadOnlyDictionary Outputs { get { throw null; } } + public System.BinaryData Outputs { get { throw null; } } public System.Uri PrimaryScriptUri { get { throw null; } set { } } public Azure.ResourceManager.Resources.Models.ScriptProvisioningState? ProvisioningState { get { throw null; } } public System.TimeSpan RetentionInterval { get { throw null; } set { } } @@ -764,7 +764,7 @@ public AzurePowerShellScript(Azure.Core.AzureLocation location, System.TimeSpan public string ContainerGroupName { get { throw null; } set { } } public System.Collections.Generic.IList EnvironmentVariables { get { throw null; } } public string ForceUpdateTag { get { throw null; } set { } } - public System.Collections.Generic.IReadOnlyDictionary Outputs { get { throw null; } } + public System.BinaryData Outputs { get { throw null; } } public System.Uri PrimaryScriptUri { get { throw null; } set { } } public Azure.ResourceManager.Resources.Models.ScriptProvisioningState? ProvisioningState { get { throw null; } } public System.TimeSpan RetentionInterval { get { throw null; } set { } } diff --git a/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/ArmDeploymentScriptPropertiesBase.cs b/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/ArmDeploymentScriptPropertiesBase.cs index 7ae474045e999..ff134d48f3e23 100644 --- a/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/ArmDeploymentScriptPropertiesBase.cs +++ b/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/ArmDeploymentScriptPropertiesBase.cs @@ -6,8 +6,6 @@ #nullable disable using System; -using System.Collections.Generic; -using Azure.Core; namespace Azure.ResourceManager.Resources.Models { @@ -17,7 +15,6 @@ internal partial class ArmDeploymentScriptPropertiesBase /// Initializes a new instance of ArmDeploymentScriptPropertiesBase. internal ArmDeploymentScriptPropertiesBase() { - Outputs = new ChangeTrackingDictionary(); } /// Container settings. @@ -38,6 +35,6 @@ public string ContainerGroupName /// Contains the results of script execution. public ScriptStatus Status { get; } /// List of script outputs. - public IReadOnlyDictionary Outputs { get; } + public BinaryData Outputs { get; } } } diff --git a/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/AzureCliScript.Serialization.cs b/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/AzureCliScript.Serialization.cs index 56930d251566b..ca881cd5fd3a2 100644 --- a/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/AzureCliScript.Serialization.cs +++ b/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/AzureCliScript.Serialization.cs @@ -123,7 +123,7 @@ internal static AzureCliScript DeserializeAzureCliScript(JsonElement element) Optional cleanupPreference = default; Optional provisioningState = default; Optional status = default; - Optional> outputs = default; + Optional outputs = default; Optional primaryScriptUri = default; Optional> supportingScriptUris = default; Optional scriptContent = default; @@ -256,12 +256,7 @@ internal static AzureCliScript DeserializeAzureCliScript(JsonElement element) property0.ThrowNonNullablePropertyIsNull(); continue; } - Dictionary dictionary = new Dictionary(); - foreach (var property1 in property0.Value.EnumerateObject()) - { - dictionary.Add(property1.Name, BinaryData.FromString(property1.Value.GetRawText())); - } - outputs = dictionary; + outputs = BinaryData.FromString(property0.Value.GetRawText()); continue; } if (property0.NameEquals("primaryScriptUri")) @@ -343,7 +338,7 @@ internal static AzureCliScript DeserializeAzureCliScript(JsonElement element) continue; } } - return new AzureCliScript(id, name, type, systemData, identity.Value, location, Optional.ToDictionary(tags), kind, containerSettings.Value, storageAccountSettings.Value, Optional.ToNullable(cleanupPreference), Optional.ToNullable(provisioningState), status.Value, Optional.ToDictionary(outputs), primaryScriptUri.Value, Optional.ToList(supportingScriptUris), scriptContent.Value, arguments.Value, Optional.ToList(environmentVariables), forceUpdateTag.Value, retentionInterval, Optional.ToNullable(timeout), azCliVersion); + return new AzureCliScript(id, name, type, systemData, identity.Value, location, Optional.ToDictionary(tags), kind, containerSettings.Value, storageAccountSettings.Value, Optional.ToNullable(cleanupPreference), Optional.ToNullable(provisioningState), status.Value, outputs.Value, primaryScriptUri.Value, Optional.ToList(supportingScriptUris), scriptContent.Value, arguments.Value, Optional.ToList(environmentVariables), forceUpdateTag.Value, retentionInterval, Optional.ToNullable(timeout), azCliVersion); } } } diff --git a/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/AzureCliScript.cs b/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/AzureCliScript.cs index 2ec2a79f5b101..1ccc58492092c 100644 --- a/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/AzureCliScript.cs +++ b/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/AzureCliScript.cs @@ -28,7 +28,6 @@ public AzureCliScript(AzureLocation location, TimeSpan retentionInterval, string throw new ArgumentNullException(nameof(azCliVersion)); } - Outputs = new ChangeTrackingDictionary(); SupportingScriptUris = new ChangeTrackingList(); EnvironmentVariables = new ChangeTrackingList(); RetentionInterval = retentionInterval; @@ -60,7 +59,7 @@ public AzureCliScript(AzureLocation location, TimeSpan retentionInterval, string /// Interval for which the service retains the script resource after it reaches a terminal state. Resource will be deleted when this duration expires. Duration is based on ISO 8601 pattern (for example P1D means one day). /// Maximum allowed script execution time specified in ISO 8601 format. Default value is P1D. /// Azure CLI module version to be used. - internal AzureCliScript(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, ArmDeploymentScriptManagedIdentity identity, AzureLocation location, IDictionary tags, ScriptType kind, ContainerConfiguration containerSettings, ScriptStorageConfiguration storageAccountSettings, ScriptCleanupOptions? cleanupPreference, ScriptProvisioningState? provisioningState, ScriptStatus status, IReadOnlyDictionary outputs, Uri primaryScriptUri, IList supportingScriptUris, string scriptContent, string arguments, IList environmentVariables, string forceUpdateTag, TimeSpan retentionInterval, TimeSpan? timeout, string azCliVersion) : base(id, name, resourceType, systemData, identity, location, tags, kind) + internal AzureCliScript(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, ArmDeploymentScriptManagedIdentity identity, AzureLocation location, IDictionary tags, ScriptType kind, ContainerConfiguration containerSettings, ScriptStorageConfiguration storageAccountSettings, ScriptCleanupOptions? cleanupPreference, ScriptProvisioningState? provisioningState, ScriptStatus status, BinaryData outputs, Uri primaryScriptUri, IList supportingScriptUris, string scriptContent, string arguments, IList environmentVariables, string forceUpdateTag, TimeSpan retentionInterval, TimeSpan? timeout, string azCliVersion) : base(id, name, resourceType, systemData, identity, location, tags, kind) { ContainerSettings = containerSettings; StorageAccountSettings = storageAccountSettings; @@ -103,7 +102,7 @@ public string ContainerGroupName /// Contains the results of script execution. public ScriptStatus Status { get; } /// List of script outputs. - public IReadOnlyDictionary Outputs { get; } + public BinaryData Outputs { get; } /// Uri for the script. This is the entry point for the external script. public Uri PrimaryScriptUri { get; set; } /// Supporting files for the external script. diff --git a/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/AzurePowerShellScript.Serialization.cs b/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/AzurePowerShellScript.Serialization.cs index 74e4b5deb947a..b2818f5efa0d8 100644 --- a/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/AzurePowerShellScript.Serialization.cs +++ b/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/AzurePowerShellScript.Serialization.cs @@ -123,7 +123,7 @@ internal static AzurePowerShellScript DeserializeAzurePowerShellScript(JsonEleme Optional cleanupPreference = default; Optional provisioningState = default; Optional status = default; - Optional> outputs = default; + Optional outputs = default; Optional primaryScriptUri = default; Optional> supportingScriptUris = default; Optional scriptContent = default; @@ -256,12 +256,7 @@ internal static AzurePowerShellScript DeserializeAzurePowerShellScript(JsonEleme property0.ThrowNonNullablePropertyIsNull(); continue; } - Dictionary dictionary = new Dictionary(); - foreach (var property1 in property0.Value.EnumerateObject()) - { - dictionary.Add(property1.Name, BinaryData.FromString(property1.Value.GetRawText())); - } - outputs = dictionary; + outputs = BinaryData.FromString(property0.Value.GetRawText()); continue; } if (property0.NameEquals("primaryScriptUri")) @@ -343,7 +338,7 @@ internal static AzurePowerShellScript DeserializeAzurePowerShellScript(JsonEleme continue; } } - return new AzurePowerShellScript(id, name, type, systemData, identity.Value, location, Optional.ToDictionary(tags), kind, containerSettings.Value, storageAccountSettings.Value, Optional.ToNullable(cleanupPreference), Optional.ToNullable(provisioningState), status.Value, Optional.ToDictionary(outputs), primaryScriptUri.Value, Optional.ToList(supportingScriptUris), scriptContent.Value, arguments.Value, Optional.ToList(environmentVariables), forceUpdateTag.Value, retentionInterval, Optional.ToNullable(timeout), azPowerShellVersion); + return new AzurePowerShellScript(id, name, type, systemData, identity.Value, location, Optional.ToDictionary(tags), kind, containerSettings.Value, storageAccountSettings.Value, Optional.ToNullable(cleanupPreference), Optional.ToNullable(provisioningState), status.Value, outputs.Value, primaryScriptUri.Value, Optional.ToList(supportingScriptUris), scriptContent.Value, arguments.Value, Optional.ToList(environmentVariables), forceUpdateTag.Value, retentionInterval, Optional.ToNullable(timeout), azPowerShellVersion); } } } diff --git a/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/AzurePowerShellScript.cs b/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/AzurePowerShellScript.cs index b9df28244e2fd..3f8f5668b158b 100644 --- a/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/AzurePowerShellScript.cs +++ b/sdk/resources/Azure.ResourceManager.Resources/src/Generated/Models/AzurePowerShellScript.cs @@ -28,7 +28,6 @@ public AzurePowerShellScript(AzureLocation location, TimeSpan retentionInterval, throw new ArgumentNullException(nameof(azPowerShellVersion)); } - Outputs = new ChangeTrackingDictionary(); SupportingScriptUris = new ChangeTrackingList(); EnvironmentVariables = new ChangeTrackingList(); RetentionInterval = retentionInterval; @@ -60,7 +59,7 @@ public AzurePowerShellScript(AzureLocation location, TimeSpan retentionInterval, /// Interval for which the service retains the script resource after it reaches a terminal state. Resource will be deleted when this duration expires. Duration is based on ISO 8601 pattern (for example P1D means one day). /// Maximum allowed script execution time specified in ISO 8601 format. Default value is P1D. /// Azure PowerShell module version to be used. - internal AzurePowerShellScript(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, ArmDeploymentScriptManagedIdentity identity, AzureLocation location, IDictionary tags, ScriptType kind, ContainerConfiguration containerSettings, ScriptStorageConfiguration storageAccountSettings, ScriptCleanupOptions? cleanupPreference, ScriptProvisioningState? provisioningState, ScriptStatus status, IReadOnlyDictionary outputs, Uri primaryScriptUri, IList supportingScriptUris, string scriptContent, string arguments, IList environmentVariables, string forceUpdateTag, TimeSpan retentionInterval, TimeSpan? timeout, string azPowerShellVersion) : base(id, name, resourceType, systemData, identity, location, tags, kind) + internal AzurePowerShellScript(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, ArmDeploymentScriptManagedIdentity identity, AzureLocation location, IDictionary tags, ScriptType kind, ContainerConfiguration containerSettings, ScriptStorageConfiguration storageAccountSettings, ScriptCleanupOptions? cleanupPreference, ScriptProvisioningState? provisioningState, ScriptStatus status, BinaryData outputs, Uri primaryScriptUri, IList supportingScriptUris, string scriptContent, string arguments, IList environmentVariables, string forceUpdateTag, TimeSpan retentionInterval, TimeSpan? timeout, string azPowerShellVersion) : base(id, name, resourceType, systemData, identity, location, tags, kind) { ContainerSettings = containerSettings; StorageAccountSettings = storageAccountSettings; @@ -103,7 +102,7 @@ public string ContainerGroupName /// Contains the results of script execution. public ScriptStatus Status { get; } /// List of script outputs. - public IReadOnlyDictionary Outputs { get; } + public BinaryData Outputs { get; } /// Uri for the script. This is the entry point for the external script. public Uri PrimaryScriptUri { get; set; } /// Supporting files for the external script. diff --git a/sdk/resources/Azure.ResourceManager.Resources/src/autorest.md b/sdk/resources/Azure.ResourceManager.Resources/src/autorest.md index 68cc6f2ec1982..cb5fa48070e1b 100644 --- a/sdk/resources/Azure.ResourceManager.Resources/src/autorest.md +++ b/sdk/resources/Azure.ResourceManager.Resources/src/autorest.md @@ -324,6 +324,10 @@ directive: where: $.definitions.DeploymentProperties.properties.onErrorDeployment transform: > $["x-ms-client-name"] = "ErrorDeployment" + - from: deploymentScripts.json + where: $.definitions.DeploymentScriptPropertiesBase.properties.outputs + transform: > + $.additionalProperties = undefined ``` ### Tag: package-track2-preview diff --git a/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DeploymentScriptCollectionTests.cs b/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DeploymentScriptCollectionTests.cs index 1926f1990f8c3..f78fe9a487673 100644 --- a/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DeploymentScriptCollectionTests.cs +++ b/sdk/resources/Azure.ResourceManager.Resources/tests/Scenario/DeploymentScriptCollectionTests.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System; +using System.Collections.Generic; using System.Threading.Tasks; using Azure.Core; using Azure.Core.TestFramework; @@ -126,11 +127,13 @@ private static void AssertValidDeploymentScript(AzurePowerShellScript model, Azu Assert.AreEqual(model.Status.ExpirationOn, getResult.Status.ExpirationOn); //Assert.AreEqual(model.Status.Error, getResult.Status.Error); } - Assert.AreEqual(model.Outputs.Count, getResult.Outputs.Count); - foreach (var kv in model.Outputs) + var modelOutputs = model.Outputs.ToObjectFromJson>(); + var getOutputs = getResult.Outputs.ToObjectFromJson>(); + Assert.AreEqual(modelOutputs.Count, getOutputs.Count); + foreach (var kv in modelOutputs) { - Assert.IsTrue(getResult.Outputs.ContainsKey(kv.Key)); - Assert.AreEqual(kv.Value.ToArray(), getResult.Outputs[kv.Key].ToArray()); + Assert.IsTrue(getOutputs.ContainsKey(kv.Key)); + Assert.AreEqual(kv.Value.ToString(), getOutputs[kv.Key].ToString()); } Assert.AreEqual(model.PrimaryScriptUri, getResult.PrimaryScriptUri); Assert.AreEqual(model.SupportingScriptUris, getResult.SupportingScriptUris);