Skip to content

Commit 0414344

Browse files
committed
more work on commands
1 parent 315809f commit 0414344

19 files changed

+731
-178
lines changed

src/Resources/ResourceManager/Implementation/DeploymentStacks/ExportAzManagmentGroupDeploymentStackTemplate.cs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
1717
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
1818
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient;
1919
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
20+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.DeploymentStacks;
2021
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Utilities;
2122
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2223
using Newtonsoft.Json.Linq;
2324
using System;
2425
using System.Management.Automation;
2526

2627
[Cmdlet("Export", Common.AzureRMConstants.AzureRMPrefix + "ManagementGroupDeploymentStackTemplate",
27-
DefaultParameterSetName = ExportAzManagementGroupDeploymentStackTemplate.ExportByName)]
28+
DefaultParameterSetName = ExportByName), OutputType(typeof(PSDeploymentStackTemplateDefinition))]
2829
public class ExportAzManagementGroupDeploymentStackTemplate : DeploymentStacksCmdletBase
2930
{
3031
#region Cmdlet Parameters and Parameter Set Definitions
@@ -42,47 +43,28 @@ public class ExportAzManagementGroupDeploymentStackTemplate : DeploymentStacksCm
4243
[ValidateNotNullOrEmpty]
4344
public string Name { get; set; }
4445

45-
[Alias("ManagementGroupId")]
4646
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ExportByName)]
4747
[ValidateNotNullOrEmpty]
4848
public string ManagementGroupId { get; set; }
4949

50-
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The path to the file where the deployment stack template will be output to.")]
51-
[ValidateNotNullOrEmpty]
52-
public string OutputFile { get; set; }
53-
5450
#endregion
5551

5652
#region Cmdlet Overrides
5753
protected override void OnProcessRecord()
5854
{
5955
try
6056
{
61-
JObject template;
6257
switch (ParameterSetName)
6358
{
6459
case ExportByResourceId:
65-
template = DeploymentStacksSdkClient.ExportManagementGroupDeploymentStack(ResourceIdUtility.GetManagementGroupId(ResourceId), ResourceIdUtility.GetDeploymentName(ResourceId));
60+
WriteObject(DeploymentStacksSdkClient.ExportManagementGroupDeploymentStack(ResourceIdUtility.GetManagementGroupId(ResourceId), ResourceIdUtility.GetDeploymentName(ResourceId)), true);
6661
break;
6762
case ExportByName:
68-
template = DeploymentStacksSdkClient.ExportManagementGroupDeploymentStack(ManagementGroupId, Name);
63+
WriteObject(DeploymentStacksSdkClient.ExportManagementGroupDeploymentStack(ManagementGroupId, Name), true);
6964
break;
7065
default:
7166
throw new PSInvalidOperationException();
7267
}
73-
74-
// Ensure our output path is resolved based on the current powershell working
75-
// directory instead of the current process directory:
76-
OutputFile = ResolveUserPath(OutputFile);
77-
78-
string path = FileUtility.SaveTemplateFile(
79-
templateName: this.Name,
80-
contents: template.ToString(),
81-
outputPath: this.OutputFile,
82-
overwrite: true,
83-
shouldContinue: ShouldContinue);
84-
85-
WriteObject(PowerShellUtilities.ConstructPSObject(null, "Path", OutputFile));
8668
}
8769
catch (Exception ex)
8870
{

src/Resources/ResourceManager/Implementation/DeploymentStacks/ExportAzResourceGroupDeploymentStackTemplate.cs

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,36 @@
1515
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
1616
{
1717
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
18+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.DeploymentStacks;
1819
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Utilities;
1920
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2021
using Newtonsoft.Json.Linq;
2122
using System;
2223
using System.Management.Automation;
2324

2425
[Cmdlet("Export", Common.AzureRMConstants.AzureRMPrefix + "ResourceGroupDeploymentStackTemplate",
25-
DefaultParameterSetName = ExportAzResourceGroupDeploymentStackTemplate.ExportByDeploymentStackName)]
26+
DefaultParameterSetName = ExportByName), OutputType(typeof(PSDeploymentStackTemplateDefinition))]
2627
public class ExportAzResourceGroupDeploymentStackTemplate : DeploymentStacksCmdletBase
2728
{
2829
#region Cmdlet Parameters and Parameter Set Definitions
2930

30-
internal const string ExportByResourceIdParameterSetName = "ExportDeploymentStackTemplateByResourceId";
31-
internal const string ExportByDeploymentStackName = "ExportDeploymentStackTemplateByStackName";
31+
internal const string ExportByResourceId = "ExportByResourceId";
32+
internal const string ExportByName = "ExportByName";
3233

3334
[Alias("Id")]
34-
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ExportByResourceIdParameterSetName)]
35+
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ExportByResourceId)]
3536
[ValidateNotNullOrEmpty]
3637
public string ResourceId { get; set; }
3738

38-
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ExportByDeploymentStackName)]
39+
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ExportByName)]
3940
[ValidateNotNullOrEmpty]
4041
public string ResourceGroupName { get; set; }
4142

4243
[Alias("StackName")]
43-
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ExportByDeploymentStackName)]
44+
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ExportByName)]
4445
[ValidateNotNullOrEmpty]
4546
public string Name { get; set; }
4647

47-
48-
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The path to the file where the deployment stack template will be output to.")]
49-
[ValidateNotNullOrEmpty]
50-
public string OutputFile { get; set; }
51-
5248
#endregion
5349

5450
#region Cmdlet Overrides
@@ -57,32 +53,17 @@ protected override void OnProcessRecord()
5753
{
5854
try
5955
{
60-
JObject template;
6156
switch (ParameterSetName)
6257
{
63-
case ExportByResourceIdParameterSetName:
64-
template = DeploymentStacksSdkClient.ExportResourceGroupDeploymentStack(ResourceIdUtility.GetResourceGroupName(ResourceId), ResourceIdUtility.GetDeploymentName(ResourceId));
58+
case ExportByResourceId:
59+
WriteObject(DeploymentStacksSdkClient.ExportResourceGroupDeploymentStack(ResourceIdUtility.GetResourceGroupName(ResourceId), ResourceIdUtility.GetDeploymentName(ResourceId)), true);
6560
break;
66-
case ExportByDeploymentStackName:
67-
template = DeploymentStacksSdkClient.ExportResourceGroupDeploymentStack(ResourceGroupName, Name);
61+
case ExportByName:
62+
WriteObject(DeploymentStacksSdkClient.ExportResourceGroupDeploymentStack(ResourceGroupName, Name), true);
6863
break;
6964
default:
7065
throw new PSInvalidOperationException();
7166
}
72-
73-
74-
// Ensure our output path is resolved based on the current powershell working
75-
// directory instead of the current process directory:
76-
OutputFile = ResolveUserPath(OutputFile);
77-
78-
string path = FileUtility.SaveTemplateFile(
79-
templateName: this.Name,
80-
contents: template.ToString(),
81-
outputPath: OutputFile,
82-
overwrite: true,
83-
shouldContinue: ShouldContinue);
84-
85-
WriteObject(PowerShellUtilities.ConstructPSObject(null, "Path", OutputFile));
8667
}
8768
catch (Exception ex)
8869
{

src/Resources/ResourceManager/Implementation/DeploymentStacks/ExportAzSubscriptionDeploymentStackTemplate.cs

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
1717

1818
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
1919
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
20+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.DeploymentStacks;
2021
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Utilities;
2122
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2223
using Newtonsoft.Json;
@@ -25,61 +26,42 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
2526
using System.Management.Automation;
2627

2728
[Cmdlet("Export", Common.AzureRMConstants.AzureRMPrefix + "SubscriptionDeploymentStackTemplate",
28-
DefaultParameterSetName = ExportAzSubscriptionDeploymentStackTemplate.ExportByDeploymentStackName)]
29+
DefaultParameterSetName = ExportByName), OutputType(typeof(PSDeploymentStackTemplateDefinition))]
2930
public class ExportAzSubscriptionDeploymentStackTemplate : DeploymentStacksCmdletBase
3031
{
3132
#region Cmdlet Parameters and Parameter Set Definitions
3233

33-
internal const string ExportByResourceIdParameterSetName = "ExportDeploymentStackTemplateByResourceId";
34-
internal const string ExportByDeploymentStackName = "ExportDeploymentStackTemplateByStackName";
34+
internal const string ExportByResourceId = "ExportByResourceId";
35+
internal const string ExportByName = "ExportByName";
3536

3637
[Alias("Id")]
37-
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ExportByResourceIdParameterSetName)]
38+
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ExportByResourceId)]
3839
[ValidateNotNullOrEmpty]
3940
public string ResourceId { get; set; }
4041

4142
[Alias("StackName")]
42-
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ExportByDeploymentStackName)]
43+
[Parameter(Position = 0, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ExportByName)]
4344
[ValidateNotNullOrEmpty]
4445
public string Name { get; set; }
4546

46-
47-
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The path to the file where the deployment stack template will be output to.")]
48-
[ValidateNotNullOrEmpty]
49-
public string OutputFile { get; set; }
50-
5147
#endregion
5248

5349
#region Cmdlet Overrides
5450
protected override void OnProcessRecord()
5551
{
5652
try
5753
{
58-
JObject template;
5954
switch (ParameterSetName)
6055
{
61-
case ExportByResourceIdParameterSetName:
62-
template = DeploymentStacksSdkClient.ExportSubscriptionDeploymentStack(ResourceIdUtility.GetResourceGroupName(ResourceId));
56+
case ExportByResourceId:
57+
WriteObject(DeploymentStacksSdkClient.ExportSubscriptionDeploymentStack(ResourceIdUtility.GetResourceGroupName(ResourceId)), true);
6358
break;
64-
case ExportByDeploymentStackName:
65-
template = DeploymentStacksSdkClient.ExportSubscriptionDeploymentStack(Name);
59+
case ExportByName:
60+
WriteObject(DeploymentStacksSdkClient.ExportSubscriptionDeploymentStack(Name), true);
6661
break;
6762
default:
6863
throw new PSInvalidOperationException();
6964
}
70-
71-
// Ensure our output path is resolved based on the current powershell working
72-
// directory instead of the current process directory:
73-
OutputFile = ResolveUserPath(OutputFile);
74-
75-
string path = FileUtility.SaveTemplateFile(
76-
templateName: this.Name,
77-
contents: template.ToString(),
78-
outputPath: this.OutputFile,
79-
overwrite: true,
80-
shouldContinue: ShouldContinue);
81-
82-
WriteObject(PowerShellUtilities.ConstructPSObject(null, "Path", OutputFile));
8365
}
8466
catch (Exception ex)
8567
{

src/Resources/ResourceManager/Implementation/DeploymentStacks/GetAzManagementGroupDeploymentStack.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public class GetAzManagementGroupDeploymentStack : DeploymentStacksCmdletBase
4343
[ValidateNotNullOrEmpty]
4444
public string ResourceId { get; set; }
4545

46-
[Alias("Id")]
4746
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ListDeploymentStacksByManagementGroupId)]
4847
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = GetDeploymentStackByManagementGroupIdAndStackName)]
4948
[ValidateNotNullOrEmpty]

src/Resources/ResourceManager/SdkClient/DeploymentStacksSdkClient.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using Microsoft.Rest.Azure;
2121
using System.Threading.Tasks;
2222
using ProjectResources = Microsoft.Azure.Commands.ResourceManager.Cmdlets.Properties.Resources;
23+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.DeploymentStacks;
2324

2425
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient
2526
{
@@ -92,7 +93,7 @@ public PSDeploymentStack GetResourceGroupDeploymentStack(
9293
}
9394
}
9495

95-
public JObject ExportResourceGroupDeploymentStack(
96+
public PSDeploymentStackTemplateDefinition ExportResourceGroupDeploymentStack(
9697
string resourceGroupName,
9798
string deploymentStackName,
9899
bool throwIfNotExists = true)
@@ -101,8 +102,7 @@ public JObject ExportResourceGroupDeploymentStack(
101102
{
102103
var deploymentStack = DeploymentStacksClient.DeploymentStacks.ExportTemplateAtResourceGroup(resourceGroupName, deploymentStackName);
103104

104-
// TODO: If a template link is set, we have to do something else.
105-
return (JObject) deploymentStack.Template;
105+
return new PSDeploymentStackTemplateDefinition(deploymentStack);
106106
}
107107
catch (Exception ex)
108108
{
@@ -128,18 +128,15 @@ public JObject ExportResourceGroupDeploymentStack(
128128
}
129129
}
130130

131-
public JObject ExportSubscriptionDeploymentStack(
131+
public PSDeploymentStackTemplateDefinition ExportSubscriptionDeploymentStack(
132132
string deploymentStackName,
133133
bool throwIfNotExists = true)
134134
{
135135
try
136136
{
137137
var deploymentStack = DeploymentStacksClient.DeploymentStacks.ExportTemplateAtSubscription(deploymentStackName);
138138

139-
deploymentStack.TemplateLink.ToJson();
140-
141-
// TODO: If a template link is set, we have to do something else.
142-
return (JObject)deploymentStack.Template.ToJson();
139+
return new PSDeploymentStackTemplateDefinition(deploymentStack);
143140
}
144141
catch (Exception ex)
145142
{
@@ -165,7 +162,7 @@ public JObject ExportSubscriptionDeploymentStack(
165162
}
166163
}
167164

168-
public JObject ExportManagementGroupDeploymentStack(
165+
public PSDeploymentStackTemplateDefinition ExportManagementGroupDeploymentStack(
169166
string managementGroupId,
170167
string deploymentStackName,
171168
bool throwIfNotExists = true)
@@ -174,10 +171,7 @@ public JObject ExportManagementGroupDeploymentStack(
174171
{
175172
var deploymentStack = DeploymentStacksClient.DeploymentStacks.ExportTemplateAtSubscription(deploymentStackName);
176173

177-
deploymentStack.TemplateLink.ToJson();
178-
179-
// TODO: If a template link is set, we have to do something else.
180-
return (JObject)deploymentStack.Template.ToJson();
174+
return new PSDeploymentStackTemplateDefinition(deploymentStack);
181175
}
182176
catch (Exception ex)
183177
{

src/Resources/ResourceManager/SdkModels/DeploymentStacks/PSActionOnUnmanage.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.Azure.Management.ResourceManager.Models;
2+
3+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.DeploymentStacks
4+
{
5+
public class PSDeploymentStackTemplateDefinition
6+
{
7+
public object Template { get; set; }
8+
9+
public DeploymentStacksTemplateLink TemplateLink { get; set; }
10+
11+
internal PSDeploymentStackTemplateDefinition(DeploymentStackTemplateDefinition deploymentStackTemplateDefinition)
12+
{
13+
Template = deploymentStackTemplateDefinition.Template;
14+
TemplateLink = deploymentStackTemplateDefinition.TemplateLink;
15+
}
16+
17+
}
18+
}

0 commit comments

Comments
 (0)