Skip to content

Commit 603df06

Browse files
committed
Switch to SDK use in ResourceGroup Deployments cmdlets
1 parent 6ffe307 commit 603df06

File tree

3 files changed

+1652
-6205
lines changed

3 files changed

+1652
-6205
lines changed

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

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -58,68 +58,11 @@ public class GetAzureResourceGroupDeploymentOperationCmdlet : ResourceManagerCmd
5858
/// </summary>
5959
protected override void OnProcessRecord()
6060
{
61-
base.OnProcessRecord();
61+
var deploymentOperations = ResourceManagerSdkClient.ListDeploymentOperationsAtResourceGroup(
62+
ResourceGroupName, DeploymentName);
6263

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);
64+
WriteObject(deploymentOperations, true);
10065
}
10166

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-
}
12467
}
12568
}

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

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -66,30 +66,7 @@ protected override void OnProcessRecord()
6666
base.OnProcessRecord();
6767
if (ShouldProcess(DeploymentName, VerbsData.Save))
6868
{
69-
var resourceId = this.GetResourceId();
70-
71-
var apiVersion = this.DetermineApiVersion(resourceId: resourceId).Result;
72-
73-
var operationResult = this.GetResourcesClient()
74-
.InvokeActionOnResource<JObject>(
75-
resourceId: resourceId,
76-
action: Constants.ExportTemplate,
77-
apiVersion: apiVersion,
78-
cancellationToken: this.CancellationToken.Value)
79-
.Result;
80-
81-
var managementUri = this.GetResourcesClient()
82-
.GetResourceManagementRequestUri(
83-
resourceId: resourceId,
84-
apiVersion: apiVersion,
85-
action: Constants.ExportTemplate);
86-
87-
var activity = string.Format("POST {0}", managementUri.PathAndQuery);
88-
var resultString = this.GetLongRunningOperationTracker(activityName: activity,
89-
isResourceCreateOrUpdate: false)
90-
.WaitOnOperation(operationResult: operationResult);
91-
92-
var template = JToken.FromObject(JObject.Parse(resultString)["template"]);
69+
var template = ResourceManagerSdkClient.GetDeploymentTemplateAtResourceGroup(ResourceGroupName, DeploymentName);
9370

9471
string path = FileUtility.SaveTemplateFile(
9572
templateName: this.DeploymentName,
@@ -104,17 +81,5 @@ protected override void OnProcessRecord()
10481
WriteObject(PowerShellUtilities.ConstructPSObject(null, "Path", path));
10582
}
10683
}
107-
108-
/// <summary>
109-
/// Gets the resource Id from the supplied PowerShell parameters.
110-
/// </summary>
111-
protected string GetResourceId()
112-
{
113-
return ResourceIdUtility.GetResourceId(
114-
subscriptionId: DefaultContext.Subscription.GetId(),
115-
resourceGroupName: this.ResourceGroupName,
116-
resourceType: Constants.MicrosoftResourcesDeploymentType,
117-
resourceName: this.DeploymentName);
118-
}
11984
}
12085
}

0 commit comments

Comments
 (0)