Skip to content

Commit 3f8542f

Browse files
committed
Removed hard gates from new and set cmdlets
1 parent a561d3f commit 3f8542f

8 files changed

+286
-67
lines changed

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

Lines changed: 54 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
216
{
317
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
418
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
@@ -86,6 +100,10 @@ public class NewAzResourceGroupDeploymentStack : DeploymentStacksCmdletBase
86100
HelpMessage = "Description for the stack")]
87101
public string Description { get; set; }
88102

103+
[Parameter(Mandatory = false,
104+
HelpMessage = "Do not ask for confirmation when overwriting an existing stack.")]
105+
public SwitchParameter Force { get; set; }
106+
89107
#endregion
90108

91109
#region Cmdlet Overrides
@@ -123,23 +141,45 @@ public override void ExecuteCmdlet()
123141
break;
124142
}
125143

126-
if (DeploymentStacksSdkClient.GetResourceGroupDeploymentStack(
144+
Action createOrUpdateAction = () =>
145+
{
146+
var deploymentStack = DeploymentStacksSdkClient.ResourceGroupCreateOrUpdateDeploymentStack(
147+
Name,
148+
ResourceGroupName,
149+
TemplateUri,
150+
TemplateSpec,
151+
ParameterUri,
152+
parameters,
153+
Description,
154+
"Detach"
155+
);
156+
WriteObject(deploymentStack);
157+
};
158+
159+
if (!Force.IsPresent && DeploymentStacksSdkClient.GetResourceGroupDeploymentStack(
127160
ResourceGroupName,
128161
Name,
129162
throwIfNotExists: false) != null)
130-
throw new DeploymentStacksErrorException($"The stack '{Name}' in Resource Group '{ResourceGroupName}' you're trying to create already exists. Please Use Set-AzResourceGroupDeploymentStack to make changes to it");
131-
132-
var deploymentStack = DeploymentStacksSdkClient.ResourceGroupCreateOrUpdateDeploymentStack(
133-
Name,
134-
ResourceGroupName,
135-
TemplateUri,
136-
TemplateSpec,
137-
ParameterUri,
138-
parameters,
139-
Description,
140-
"Detach"
163+
{
164+
string confirmationMessage = ($"The stack '{Name}' in Resource Group '{ResourceGroupName}' you're trying to create already exists. Do you want to overwrite it?");
165+
166+
ConfirmAction(
167+
Force.IsPresent,
168+
confirmationMessage,
169+
"Update",
170+
$"{Name}",
171+
createOrUpdateAction
141172
);
142-
WriteObject(deploymentStack);
173+
}
174+
else
175+
{
176+
if (!ShouldProcess($"{Name}", "Create"))
177+
{
178+
return; // Don't perform the actual creation/update action
179+
}
180+
181+
createOrUpdateAction();
182+
}
143183

144184
}
145185
catch (Exception ex)

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

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
216
{
317
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
418
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
@@ -84,6 +98,10 @@ public class NewAzSubscriptionDeploymentStack : DeploymentStacksCmdletBase
8498
HelpMessage = "Location of the stack")]
8599
public string Location { get; set; }
86100

101+
[Parameter(Mandatory = false,
102+
HelpMessage = "Do not ask for confirmation when overwriting an existing stack.")]
103+
public SwitchParameter Force { get; set; }
104+
87105
#endregion
88106

89107
#region Cmdlet Overrides
@@ -121,12 +139,9 @@ public override void ExecuteCmdlet()
121139
break;
122140
}
123141

124-
if (DeploymentStacksSdkClient.GetSubscriptionDeploymentStack(
125-
Name,
126-
throwIfNotExists: false) != null)
127-
throw new DeploymentStacksErrorException($"The stack '{Name}' you're trying to create already exists in the current subscription. Please Use Set-AzResourceGroupDeploymentStack to make changes to it");
128-
129-
var deploymentStack = DeploymentStacksSdkClient.SubscriptionCreateOrUpdateDeploymentStack(
142+
Action createOrUpdateAction = () =>
143+
{
144+
var deploymentStack = DeploymentStacksSdkClient.SubscriptionCreateOrUpdateDeploymentStack(
130145
Name,
131146
Location,
132147
TemplateUri,
@@ -136,7 +151,33 @@ public override void ExecuteCmdlet()
136151
Description,
137152
"Detach"
138153
);
139-
WriteObject(deploymentStack);
154+
WriteObject(deploymentStack);
155+
};
156+
157+
if (!Force.IsPresent && DeploymentStacksSdkClient.GetSubscriptionDeploymentStack(
158+
Name,
159+
throwIfNotExists: false) != null)
160+
{
161+
162+
string confirmationMessage = ($"The stack '{Name}' you're trying to create already exists in the current subscription. Do you want to overwrite it?");
163+
164+
ConfirmAction(
165+
Force.IsPresent,
166+
confirmationMessage,
167+
"Update",
168+
$"{Name}",
169+
createOrUpdateAction
170+
);
171+
}
172+
else
173+
{
174+
if (!ShouldProcess($"{Name}", "Create"))
175+
{
176+
return; // Don't perform the actual creation/update action
177+
}
178+
179+
createOrUpdateAction();
180+
}
140181

141182
}
142183
catch (Exception ex)

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Management.Automation;
5-
using System.Text;
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
614

715
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
816
{
17+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Management.Automation;
21+
using System.Text;
22+
923
[Cmdlet("Remove", Common.AzureRMConstants.AzureRMPrefix + "ResourceGroupDeploymentStack",
1024
SupportsShouldProcess = true, DefaultParameterSetName = RemoveAzResourceGroupDeploymentStack.RemoveByResourceIdParameterSetName), OutputType(typeof(bool))]
1125
public class RemoveAzResourceGroupDeploymentStack : DeploymentStacksCmdletBase

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Management.Automation;
5-
using System.Text;
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
614

715
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
816
{
17+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Management.Automation;
21+
using System.Text;
22+
923
[Cmdlet("Remove", Common.AzureRMConstants.AzureRMPrefix + "ResourceGroupDeploymentStackSnapshot",
1024
SupportsShouldProcess = true, DefaultParameterSetName = RemoveAzResourceGroupDeploymentStackSnapshot.RemoveByResourceIdParameterSetName), OutputType(typeof(bool))]
1125
public class RemoveAzResourceGroupDeploymentStackSnapshot : DeploymentStacksCmdletBase

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Management.Automation;
5-
using System.Text;
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
614

715
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
816
{
17+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Management.Automation;
21+
using System.Text;
22+
923
[Cmdlet("Remove", Common.AzureRMConstants.AzureRMPrefix + "SubscriptionDeploymentStack",
1024
SupportsShouldProcess = true, DefaultParameterSetName = RemoveAzSubscriptionDeploymentStack.RemoveByResourceIdParameterSetName), OutputType(typeof(bool))]
1125
public class RemoveAzSubscriptionDeploymentStack : DeploymentStacksCmdletBase

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
2-
using System;
3-
using System.Collections.Generic;
4-
using System.Management.Automation;
5-
using System.Text;
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
614

715
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
816
{
17+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
18+
using System;
19+
using System.Collections.Generic;
20+
using System.Management.Automation;
21+
using System.Text;
22+
923
[Cmdlet("Remove", Common.AzureRMConstants.AzureRMPrefix + "SubscriptionDeploymentStackSnapshot",
1024
SupportsShouldProcess = true, DefaultParameterSetName = RemoveAzSubscriptionDeploymentStackSnapshot.RemoveByResourceIdParameterSetName), OutputType(typeof(bool))]
1125
public class RemoveAzSubscriptionDeploymentStackSnapshot : DeploymentStacksCmdletBase

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

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
1-
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
216
{
317
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
418
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
@@ -90,6 +104,10 @@ public class SetAzResourceGroupDeploymentStack : DeploymentStacksCmdletBase
90104
HelpMessage = "Update behavior for the stack. Value can be \"Detach\" or \"Purge\".")]
91105
public String UpdateBehavior { get; set; }
92106

107+
[Parameter(Mandatory = false,
108+
HelpMessage = "Do not ask for confirmation when overwriting an existing stack.")]
109+
public SwitchParameter Force { get; set; }
110+
93111
#endregion
94112

95113
#region Cmdlet Overrides
@@ -127,13 +145,9 @@ public override void ExecuteCmdlet()
127145
break;
128146
}
129147

130-
if (DeploymentStacksSdkClient.GetResourceGroupDeploymentStack(
131-
ResourceGroupName,
132-
Name,
133-
throwIfNotExists: false) == null)
134-
throw new DeploymentStacksErrorException($"The stack '{Name}' you're trying to modify does not exist in '{ResourceGroupName}'. Please Use New-AzResourceGroupDeploymentStack to create it");
135-
136-
var deploymentStack = DeploymentStacksSdkClient.ResourceGroupCreateOrUpdateDeploymentStack(
148+
Action createOrUpdateAction = () =>
149+
{
150+
var deploymentStack = DeploymentStacksSdkClient.ResourceGroupCreateOrUpdateDeploymentStack(
137151
Name,
138152
ResourceGroupName,
139153
TemplateUri,
@@ -142,8 +156,35 @@ public override void ExecuteCmdlet()
142156
parameters,
143157
Description,
144158
UpdateBehavior
145-
) ;
146-
WriteObject(deploymentStack);
159+
);
160+
WriteObject(deploymentStack);
161+
};
162+
163+
if (!Force.IsPresent && DeploymentStacksSdkClient.GetResourceGroupDeploymentStack(
164+
ResourceGroupName,
165+
Name,
166+
throwIfNotExists: false) == null)
167+
{
168+
string confirmationMessage =
169+
$"The stack '{Name}' you're trying to modify does not exist in '{ResourceGroupName}'. Do you want to create a new stack?";
170+
171+
ConfirmAction(
172+
Force.IsPresent,
173+
confirmationMessage,
174+
"Update",
175+
$"{Name}",
176+
createOrUpdateAction
177+
);
178+
}
179+
else
180+
{
181+
if (!ShouldProcess($"{Name}", "Create"))
182+
{
183+
return; // Don't perform the actual creation/update action
184+
}
185+
186+
createOrUpdateAction();
187+
}
147188

148189
}
149190
catch (Exception ex)

0 commit comments

Comments
 (0)