Skip to content

Commit f042cdf

Browse files
committed
Rollback breaking changes from PR Azure#12141
1 parent bb5cf7e commit f042cdf

File tree

4 files changed

+1262
-1455
lines changed

4 files changed

+1262
-1455
lines changed

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

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,20 @@
1414

1515
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
1616
{
17+
using Commands.Common.Authentication.Abstractions;
1718
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;
1823
using System;
1924
using System.Management.Automation;
20-
using Microsoft.WindowsAzure.Commands.Common.CustomAttributes;
21-
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
25+
using System.Threading.Tasks;
2226

2327
/// <summary>
2428
/// Gets the deployment operation.
2529
/// </summary>
26-
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ResourceGroupDeploymentOperation"), OutputType(typeof(PSDeploymentOperation))]
30+
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ResourceGroupDeploymentOperation"), OutputType(typeof(PSObject))]
2731
public class GetAzureResourceGroupDeploymentOperationCmdlet : ResourceManagerCmdletBase
2832
{
2933
/// <summary>
@@ -37,7 +41,6 @@ public class GetAzureResourceGroupDeploymentOperationCmdlet : ResourceManagerCmd
3741
/// <summary>
3842
/// Gets or sets the subscription id parameter.
3943
/// </summary>
40-
[CmdletParameterBreakingChange("SubscriptionId", ChangeDescription = "Parameter is deprecated and is a no-op parameter. It will be retired in a future release")]
4144
[Parameter(Mandatory = false, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The subscription to use.")]
4245
[ValidateNotNullOrEmpty]
4346
public Guid? SubscriptionId { get; set; }
@@ -55,11 +58,68 @@ public class GetAzureResourceGroupDeploymentOperationCmdlet : ResourceManagerCmd
5558
/// </summary>
5659
protected override void OnProcessRecord()
5760
{
58-
var deploymentOperations = ResourceManagerSdkClient.ListDeploymentOperationsAtResourceGroup(
59-
ResourceGroupName, DeploymentName);
61+
base.OnProcessRecord();
6062

61-
WriteObject(deploymentOperations, true);
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);
62100
}
63101

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+
}
64124
}
65-
}
125+
}

0 commit comments

Comments
 (0)