Skip to content

Commit ddaee47

Browse files
authored
Remove ApiVersion Parameter and change Get-AzResourceGroupOperation implementation to use SDK (#12642)
* Remove ApiVersion Parameter from deployments * update changelog * Delete ApiVersion param * Switch to SDK use in ResourceGroup Deployments cmdlets * Include review fixes * Changed help file to reflect new output type * Rollback breaking changes from PR #12141 * Change Get-AzResourceGroupDeploymentOperation implementation to use SDK * Update help * Rollback changes to help files of untouched cmdlets * Suppress breaking change issues * remove subscriptionId param * Update breakingchanges csv * Suppress breaking changes
1 parent 526a74b commit ddaee47

File tree

51 files changed

+1950
-10705
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1950
-10705
lines changed

src/Resources/ResourceManager/Implementation/CmdletBase/ResourceManagerCmdletBase.cs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
2525
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.RestClients;
2626
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient;
2727
using Microsoft.Rest.Azure;
28-
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
2928
using Newtonsoft.Json.Linq;
3029
using System;
3130
using System.Collections.Generic;
3231
using System.Linq;
3332
using System.Management.Automation;
3433
using System.Runtime.ExceptionServices;
3534
using System.Threading;
36-
using System.Threading.Tasks;
3735

3836
/// <summary>
3937
/// The base class for resource manager cmdlets.
@@ -66,14 +64,6 @@ protected CancellationToken? CancellationToken
6664
/// </summary>
6765
private SubscriptionSdkClient subscriptionSdkClient;
6866

69-
/// <summary>
70-
/// Gets or sets the API version.
71-
/// </summary>
72-
[CmdletParameterBreakingChange("ApiVersion", ChangeDescription = "Parameter is being deprecated without being replaced")]
73-
[Parameter(Mandatory = false, HelpMessage = "When set, indicates the version of the resource provider API to use. If not specified, the API version is automatically determined as the latest available.")]
74-
[ValidateNotNullOrEmpty]
75-
public virtual string ApiVersion { get; set; }
76-
7767
/// <summary>
7868
/// Gets or sets the switch that indicates if pre-release API version should be considered.
7969
/// </summary>
@@ -223,42 +213,6 @@ protected virtual void OnStopProcessing()
223213
// no-op
224214
}
225215

226-
/// <summary>
227-
/// Determines the API version.
228-
/// </summary>
229-
/// <param name="resourceId">The resource Id.</param>
230-
/// <param name="pre">When specified, indicates if pre-release API versions should be considered.</param>
231-
protected Task<string> DetermineApiVersion(string resourceId, bool? pre = null)
232-
{
233-
return string.IsNullOrWhiteSpace(this.ApiVersion)
234-
? ApiVersionHelper.DetermineApiVersion(
235-
context: DefaultContext,
236-
resourceId: resourceId,
237-
cancellationToken: this.CancellationToken.Value,
238-
pre: pre ?? this.Pre,
239-
cmdletHeaderValues: this.GetCmdletHeaders())
240-
: Task.FromResult(this.ApiVersion);
241-
}
242-
243-
/// <summary>
244-
/// Determines the API version.
245-
/// </summary>
246-
/// <param name="providerNamespace">The provider namespace.</param>
247-
/// <param name="resourceType">The resource type.</param>
248-
/// <param name="pre">When specified, indicates if pre-release API versions should be considered.</param>
249-
protected Task<string> DetermineApiVersion(string providerNamespace, string resourceType, bool? pre = null)
250-
{
251-
return string.IsNullOrWhiteSpace(this.ApiVersion)
252-
? ApiVersionHelper.DetermineApiVersion(
253-
DefaultContext,
254-
providerNamespace: providerNamespace,
255-
resourceType: resourceType,
256-
cancellationToken: this.CancellationToken.Value,
257-
pre: pre ?? this.Pre,
258-
cmdletHeaderValues: this.GetCmdletHeaders())
259-
: Task.FromResult(this.ApiVersion);
260-
}
261-
262216
/// <summary>
263217
/// Gets a new instance of the <see cref="ResourceManagerRestRestClient"/>.
264218
/// </summary>

src/Resources/ResourceManager/Implementation/CmdletBase/ResourceManagerCmdletBaseWithAPiVersion.cs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System.Management.Automation;
16+
using System.Threading.Tasks;
17+
using System.Collections.Generic;
1618

1719
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
1820
{
@@ -23,6 +25,51 @@ public abstract class ResourceManagerCmdletBaseWithAPiVersion : ResourceManagerC
2325
/// </summary>
2426
[Parameter(Mandatory = false, HelpMessage = "When set, indicates the version of the resource provider API to use. If not specified, the API version is automatically determined as the latest available.")]
2527
[ValidateNotNullOrEmpty]
26-
public override string ApiVersion { get; set; }
28+
public string ApiVersion { get; set; }
29+
30+
private Dictionary<string, string> GetCmdletHeaders()
31+
{
32+
return new Dictionary<string, string>
33+
{
34+
{"ParameterSetName", this.ParameterSetName },
35+
{"CommandName", this.CommandRuntime.ToString() }
36+
};
37+
}
38+
39+
/// <summary>
40+
/// Determines the API version.
41+
/// </summary>
42+
/// <param name="resourceId">The resource Id.</param>
43+
/// <param name="pre">When specified, indicates if pre-release API versions should be considered.</param>
44+
protected Task<string> DetermineApiVersion(string resourceId, bool? pre = null)
45+
{
46+
return string.IsNullOrWhiteSpace(this.ApiVersion)
47+
? Components.ApiVersionHelper.DetermineApiVersion(
48+
context: DefaultContext,
49+
resourceId: resourceId,
50+
cancellationToken: this.CancellationToken.Value,
51+
pre: pre ?? this.Pre,
52+
cmdletHeaderValues: this.GetCmdletHeaders())
53+
: Task.FromResult(this.ApiVersion);
54+
}
55+
56+
/// <summary>
57+
/// Determines the API version.
58+
/// </summary>
59+
/// <param name="providerNamespace">The provider namespace.</param>
60+
/// <param name="resourceType">The resource type.</param>
61+
/// <param name="pre">When specified, indicates if pre-release API versions should be considered.</param>
62+
protected Task<string> DetermineApiVersion(string providerNamespace, string resourceType, bool? pre = null)
63+
{
64+
return string.IsNullOrWhiteSpace(this.ApiVersion)
65+
? Components.ApiVersionHelper.DetermineApiVersion(
66+
DefaultContext,
67+
providerNamespace: providerNamespace,
68+
resourceType: resourceType,
69+
cancellationToken: this.CancellationToken.Value,
70+
pre: pre ?? this.Pre,
71+
cmdletHeaderValues: this.GetCmdletHeaders())
72+
: Task.FromResult(this.ApiVersion);
73+
}
2774
}
2875
}

src/Resources/ResourceManager/Implementation/ResourceGroupDeployments/GetAzureResourceGroupDeploymentOperationCmdlet.cs

Lines changed: 6 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,14 @@
1414

1515
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
1616
{
17-
using Commands.Common.Authentication.Abstractions;
1817
using Common.ArgumentCompleters;
19-
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
20-
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
21-
using Microsoft.Azure.Commands.ResourceManager.Common;
22-
using Newtonsoft.Json.Linq;
23-
using System;
2418
using System.Management.Automation;
25-
using System.Threading.Tasks;
19+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
2620

2721
/// <summary>
2822
/// Gets the deployment operation.
2923
/// </summary>
30-
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ResourceGroupDeploymentOperation"), OutputType(typeof(PSObject))]
24+
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ResourceGroupDeploymentOperation"), OutputType(typeof(PSDeploymentOperation))]
3125
public class GetAzureResourceGroupDeploymentOperationCmdlet : ResourceManagerCmdletBase
3226
{
3327
/// <summary>
@@ -38,13 +32,6 @@ public class GetAzureResourceGroupDeploymentOperationCmdlet : ResourceManagerCmd
3832
[ValidateNotNullOrEmpty]
3933
public string DeploymentName { get; set; }
4034

41-
/// <summary>
42-
/// Gets or sets the subscription id parameter.
43-
/// </summary>
44-
[Parameter(Mandatory = false, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The subscription to use.")]
45-
[ValidateNotNullOrEmpty]
46-
public Guid? SubscriptionId { get; set; }
47-
4835
/// <summary>
4936
/// Gets or sets the resource group name parameter.
5037
/// </summary>
@@ -58,68 +45,12 @@ public class GetAzureResourceGroupDeploymentOperationCmdlet : ResourceManagerCmd
5845
/// </summary>
5946
protected override void OnProcessRecord()
6047
{
48+
var deploymentOperations = ResourceManagerSdkClient.ListDeploymentOperationsAtResourceGroup(
49+
ResourceGroupName, DeploymentName);
6150
base.OnProcessRecord();
6251

63-
if (this.SubscriptionId == null)
64-
{
65-
this.SubscriptionId = DefaultContext.Subscription.GetId();
66-
}
67-
68-
this.RunCmdlet();
69-
}
70-
71-
/// <summary>
72-
/// Contains the cmdlet's execution logic.
73-
/// </summary>
74-
private void RunCmdlet()
75-
{
76-
PaginatedResponseHelper.ForEach(
77-
getFirstPage: () => this.GetResources(),
78-
getNextPage: nextLink => this.GetNextLink<JObject>(nextLink),
79-
cancellationToken: this.CancellationToken,
80-
action: resources => this.WriteObject(sendToPipeline: resources.CoalesceEnumerable().SelectArray(resource =>
81-
resource.ToPsObject("System.Management.Automation.PSCustomObject#DeploymentOperation")), enumerateCollection: true));
82-
}
83-
84-
/// <summary>
85-
/// Queries the ARM cache and returns the cached resource that match the query specified.
86-
/// </summary>
87-
private async Task<ResponseWithContinuation<JObject[]>> GetResources()
88-
{
89-
var resourceId = this.GetResourceId();
90-
91-
var apiVersion = string.IsNullOrWhiteSpace(this.ApiVersion) ? Constants.DeploymentOperationApiVersion : this.ApiVersion;
92-
93-
return await this
94-
.GetResourcesClient()
95-
.ListObjectColleciton<JObject>(
96-
resourceCollectionId: resourceId,
97-
apiVersion: apiVersion,
98-
cancellationToken: this.CancellationToken.Value)
99-
.ConfigureAwait(continueOnCapturedContext: false);
52+
WriteObject(deploymentOperations, true);
10053
}
10154

102-
/// <summary>
103-
/// Gets the next set of resources using the <paramref name="nextLink"/>
104-
/// </summary>
105-
/// <param name="nextLink">The next link.</param>
106-
private Task<ResponseWithContinuation<TType[]>> GetNextLink<TType>(string nextLink)
107-
{
108-
return this
109-
.GetResourcesClient()
110-
.ListNextBatch<TType>(nextLink: nextLink, cancellationToken: this.CancellationToken.Value);
111-
}
112-
113-
/// <summary>
114-
/// Gets the resource Id from the supplied PowerShell parameters.
115-
/// </summary>
116-
protected string GetResourceId()
117-
{
118-
return ResourceIdUtility.GetResourceId(
119-
subscriptionId: this.SubscriptionId,
120-
resourceGroupName: this.ResourceGroupName,
121-
resourceType: Constants.MicrosoftResourcesDeploymentOperationsType,
122-
resourceName: this.DeploymentName);
123-
}
12455
}
125-
}
56+
}

0 commit comments

Comments
 (0)