Skip to content

Commit 19febbc

Browse files
committed
Resolving bug bash issues
1 parent 0c7d8a1 commit 19febbc

15 files changed

+347
-82
lines changed

src/Resources/ResourceManager/Components/ResourceIdentifier.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public class ResourceIdentifier
3131

3232
public string Subscription { get; set; }
3333

34+
public string ManagementGroupName { get; set; }
35+
3436
public ResourceIdentifier() { }
3537

3638
public ResourceIdentifier(string idFromServer)
@@ -91,6 +93,25 @@ public static ResourceIdentifier FromResourceGroupIdentifier(string resourceGrou
9193
return new ResourceIdentifier();
9294
}
9395

96+
public static ResourceIdentifier FromManagementGroupResourceIdentifier(string managementGroupResourceId)
97+
{
98+
if (!string.IsNullOrEmpty(managementGroupResourceId))
99+
{
100+
string[] tokens = managementGroupResourceId.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
101+
if (tokens.Length != 8)
102+
{
103+
throw new ArgumentException(ProjectResources.InvalidFormatOfResourceGroupId, "resourceGroupId");
104+
}
105+
return new ResourceIdentifier
106+
{
107+
Subscription = tokens[1],
108+
ResourceGroupName = tokens[3],
109+
};
110+
}
111+
112+
return new ResourceIdentifier();
113+
}
114+
94115
public static string GetProviderFromResourceType(string resourceType)
95116
{
96117
if (resourceType == null)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
1717
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
1818
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.DeploymentStacks;
1919
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Utilities;
20+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
2021
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2122
using Newtonsoft.Json.Linq;
2223
using System;
@@ -39,6 +40,7 @@ public class ExportAzResourceGroupDeploymentStackTemplate : DeploymentStacksCmdl
3940

4041
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = ExportByNameAndResourceGroupNameParameterSetName,
4142
HelpMessage = "The name of the ResourceGroup where the DeploymentStack is deployed")]
43+
[ResourceGroupCompleter]
4244
[ValidateNotNullOrEmpty]
4345
public string ResourceGroupName { get; set; }
4446

@@ -59,7 +61,7 @@ protected override void OnProcessRecord()
5961
switch (ParameterSetName)
6062
{
6163
case ExportByResourceIdParameterSetName:
62-
ResourceGroupName = ResourceIdUtility.GetResourceGroupName(ResourceId);
64+
ResourceGroupName = ResourceIdUtility.GetManagementGroupId(ResourceId);
6365
Name = ResourceIdUtility.GetDeploymentName(ResourceId);
6466
if (ResourceGroupName == null || Name == null)
6567
{

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
1616
{
1717
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
1818
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
19+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
1920
using System;
2021
using System.Collections.Generic;
2122
using System.Management.Automation;
@@ -42,6 +43,7 @@ public class GetAzResourceGroupDeploymentStack : DeploymentStacksCmdletBase
4243
HelpMessage = "The id of the ResourceGroup where the DeploymentStack is deployed")]
4344
[Parameter(Position = 1, Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = GetByDeploymentStackNameParameterSetName,
4445
HelpMessage = "The id of the ResourceGroup where the DeploymentStack is deployed")]
46+
[ResourceGroupCompleter]
4547
[ValidateNotNullOrEmpty]
4648
public string ResourceGroupName { get; set; }
4749

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,23 @@ public class NewAzManagementGroupDeploymentStack : DeploymentStacksCmdletBase
135135
/*[Parameter(Mandatory = false, HelpMessage = "Singal to delete unmanaged stack management groups after updating stack.")]
136136
public SwitchParameter DeleteManagementGroups { get; set; }*/
137137

138+
[Parameter(Mandatory = false, HelpMessage = "Mode for DenySettings. Possible values include: 'denyDelete', 'denyWriteAndDelete', and 'none'.")]
139+
public string DenySettingsMode { get; set; }
140+
141+
[Parameter(Mandatory = false, HelpMessage = "List of AAD principal IDs excluded from the lock. Up to 5 principals are permitted.")]
142+
public string[] DenySettingsExcludedPrincipals { get; set; }
143+
144+
[Parameter(Mandatory = false, HelpMessage = "List of role-based management operations that are excluded from " +
145+
"the denySettings. Up to 200 actions are permitted.")]
146+
public string[] DenySettingsExcludedActions { get; set; }
147+
148+
[Parameter(Mandatory = false, HelpMessage = "List of role-based management operations that are excluded from " +
149+
"the denySettings. Up to 200 actions are permitted.")]
150+
public string[] DenySettingsExcludedDataActions { get; set; }
151+
152+
[Parameter(Mandatory = false, HelpMessage = "Apply to child scopes.")]
153+
public SwitchParameter DenySettingsApplyToChildScopes { get; set; }
154+
138155
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true,
139156
HelpMessage = "The subscription id at which the deployment should be created.")]
140157
public string DeploymentSubscriptionId { get; set; }
@@ -218,7 +235,11 @@ protected override void OnProcessRecord()
218235
resourcesCleanupAction: shouldDeleteResources ? "delete" : "detach",
219236
resourceGroupsCleanupAction: shouldDeleteResourceGroups ? "delete" : "detach",
220237
managementGroupsCleanupAction: "detach",
221-
DeploymentSubscriptionId
238+
DeploymentSubscriptionId,
239+
DenySettingsMode,
240+
DenySettingsExcludedPrincipals,
241+
DenySettingsExcludedActions,
242+
DenySettingsApplyToChildScopes.IsPresent
222243
);
223244

224245
WriteObject(deploymentStack);

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

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ public class NewAzResourceGroupDeploymentStack : DeploymentStacksCmdletBase
115115
Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "A hash table which represents the parameters.")]
116116
public Hashtable TemplateParameterObject { get; set; }
117117

118-
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true,
119-
HelpMessage = "Description for the stack")]
118+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Description for the stack")]
120119
public string Description { get; set; }
121120

122121
[Parameter(Mandatory = false, HelpMessage = "Signal to delete both unmanaged Resources and ResourceGroups after updating stack.")]
@@ -131,6 +130,23 @@ public class NewAzResourceGroupDeploymentStack : DeploymentStacksCmdletBase
131130
// Not Yet Supported.
132131
/*[Parameter(Mandatory = false, HelpMessage = "Singal to delete unmanaged stack management groups after updating stack.")]
133132
public SwitchParameter DeleteManagementGroups { get; set; }*/
133+
134+
[Parameter(Mandatory = false, HelpMessage = "Mode for DenySettings. Possible values include: 'denyDelete', 'denyWriteAndDelete', and 'none'.")]
135+
public string DenySettingsMode { get; set; }
136+
137+
[Parameter(Mandatory = false, HelpMessage = "List of AAD principal IDs excluded from the lock. Up to 5 principals are permitted.")]
138+
public string[] DenySettingsExcludedPrincipals { get; set; }
139+
140+
[Parameter(Mandatory = false, HelpMessage = "List of role-based management operations that are excluded from " +
141+
"the denySettings. Up to 200 actions are permitted.")]
142+
public string[] DenySettingsExcludedActions { get; set; }
143+
144+
[Parameter(Mandatory = false, HelpMessage = "List of role-based management operations that are excluded from " +
145+
"the denySettings. Up to 200 actions are permitted.")]
146+
public string[] DenySettingsExcludedDataActions { get; set; }
147+
148+
[Parameter(Mandatory = false, HelpMessage = "Apply to child scopes.")]
149+
public SwitchParameter DenySettingsApplyToChildScopes { get; set; }
134150

135151
[Parameter(Mandatory = false,
136152
HelpMessage = "Do not ask for confirmation when overwriting an existing stack.")]
@@ -194,8 +210,6 @@ protected override void OnProcessRecord()
194210
break;
195211
}
196212

197-
198-
199213
var shouldDeleteResources = (DeleteAll.ToBool() || DeleteResources.ToBool()) ? true : false;
200214
var shouldDeleteResourceGroups = (DeleteAll.ToBool() || DeleteResourceGroups.ToBool()) ? true : false;
201215

@@ -211,7 +225,11 @@ protected override void OnProcessRecord()
211225
Description,
212226
resourcesCleanupAction: shouldDeleteResources ? "delete" : "detach",
213227
resourceGroupsCleanupAction: shouldDeleteResourceGroups ? "delete" : "detach",
214-
managementGroupsCleanupAction: "detach"
228+
managementGroupsCleanupAction: "detach",
229+
DenySettingsMode,
230+
DenySettingsExcludedPrincipals,
231+
DenySettingsExcludedActions,
232+
DenySettingsApplyToChildScopes.IsPresent
215233
);
216234

217235
WriteObject(deploymentStack);

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,27 @@ public class NewAzSubscriptionDeploymentStack : DeploymentStacksCmdletBase
129129
/*[Parameter(Mandatory = false, HelpMessage = "Singal to delete unmanaged stack management groups after updating stack.")]
130130
public SwitchParameter DeleteManagementGroups { get; set; }*/
131131

132+
[Parameter(Mandatory = false, HelpMessage = "Mode for DenySettings. Possible values include: 'denyDelete', 'denyWriteAndDelete', and 'none'.")]
133+
public string DenySettingsMode { get; set; }
134+
135+
[Parameter(Mandatory = false, HelpMessage = "List of AAD principal IDs excluded from the lock. Up to 5 principals are permitted.")]
136+
public string[] DenySettingsExcludedPrincipals { get; set; }
137+
138+
[Parameter(Mandatory = false, HelpMessage = "List of role-based management operations that are excluded from " +
139+
"the denySettings. Up to 200 actions are permitted.")]
140+
public string[] DenySettingsExcludedActions { get; set; }
141+
142+
[Parameter(Mandatory = false, HelpMessage = "List of role-based management operations that are excluded from " +
143+
"the denySettings. Up to 200 actions are permitted.")]
144+
public string[] DenySettingsExcludedDataActions { get; set; }
145+
146+
[Parameter(Mandatory = false, HelpMessage = "Apply to child scopes.")]
147+
public SwitchParameter DenySettingsApplyToChildScopes { get; set; }
148+
132149
[Parameter(Mandatory = false,
133-
HelpMessage = "The scope at which the initial deployment should be created. If a scope isn't specified, it will default to the scope of the deployment stack.")]
134-
public string DeploymentScope { get; set; }
150+
HelpMessage = "The ResourceGroup at which the deployment will be created. If none is specified, it will default to the " +
151+
"subscription level scope of the deployment stack.")]
152+
public string ResourceGroupName { get; set; }
135153

136154
[Parameter(Mandatory = false,
137155
HelpMessage = "Do not ask for confirmation when overwriting an existing stack.")]
@@ -198,6 +216,10 @@ protected override void OnProcessRecord()
198216
var shouldDeleteResources = (DeleteAll.ToBool() || DeleteResources.ToBool()) ? true : false;
199217
var shouldDeleteResourceGroups = (DeleteAll.ToBool() || DeleteResourceGroups.ToBool()) ? true : false;
200218

219+
// construct deploymentScope if ResourceGroup was provided
220+
var deploymentScope = ResourceGroupName != null ? "/subscriptions/" + DeploymentStacksSdkClient.DeploymentStacksClient.SubscriptionId
221+
+ "/resourceGroups/" + ResourceGroupName : null;
222+
201223
Action createOrUpdateAction = () =>
202224
{
203225
var deploymentStack = DeploymentStacksSdkClient.SubscriptionCreateOrUpdateDeploymentStack(
@@ -211,7 +233,11 @@ protected override void OnProcessRecord()
211233
resourcesCleanupAction: shouldDeleteResources ? "delete" : "detach",
212234
resourceGroupsCleanupAction: shouldDeleteResourceGroups ? "delete" : "detach",
213235
managementGroupsCleanupAction: "detach",
214-
DeploymentScope
236+
deploymentScope,
237+
DenySettingsMode,
238+
DenySettingsExcludedPrincipals,
239+
DenySettingsExcludedActions,
240+
DenySettingsApplyToChildScopes.IsPresent
215241
);
216242

217243
WriteObject(deploymentStack);

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@ protected override void OnProcessRecord()
7474
var shouldDeleteResources = (DeleteAll.ToBool() || DeleteResources.ToBool()) ? true : false;
7575
var shouldDeleteResourceGroups = (DeleteAll.ToBool() || DeleteResourceGroups.ToBool()) ? true : false;
7676

77+
// resolve Name and ManagementGroupId if ResourceId was provided
7778
ManagementGroupId = ManagementGroupId ?? ResourceIdUtility.GetManagementGroupId(ResourceId);
7879
Name = Name ?? ResourceIdUtility.GetDeploymentName(ResourceId);
7980

8081
// failed resolving the resource id
81-
if (Name == null)
82+
if (Name == null || ManagementGroupId == null)
8283
{
8384
throw new PSArgumentException($"Provided Id '{ResourceId}' is not in correct form.");
8485
}
@@ -90,21 +91,24 @@ protected override void OnProcessRecord()
9091
confirmationMessage,
9192
"Deleting Deployment Stack ...",
9293
Name,
93-
() => DeploymentStacksSdkClient.DeleteManagementGroupDeploymentStack(
94-
Name,
95-
ManagementGroupId,
96-
resourcesCleanupAction: shouldDeleteResources ? "delete" : "detach",
97-
resourceGroupsCleanupAction: shouldDeleteResourceGroups ? "delete" : "detach"
98-
)
94+
() =>
95+
{
96+
DeploymentStacksSdkClient.DeleteManagementGroupDeploymentStack(
97+
Name,
98+
ManagementGroupId,
99+
resourcesCleanupAction: shouldDeleteResources ? "delete" : "detach",
100+
resourceGroupsCleanupAction: shouldDeleteResourceGroups ? "delete" : "detach"
101+
);
102+
WriteObject(true);
103+
}
99104
);
100-
101-
WriteObject(true);
102105
}
103106
catch (Exception ex)
104107
{
105108
if (ex is DeploymentStacksErrorException dex)
106109
throw new PSArgumentException(dex.Message + " : " + dex.Body.Error.Code + " : " + dex.Body.Error.Message);
107110
else
111+
WriteObject(false);
108112
WriteExceptionError(ex);
109113
}
110114
}

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
1616
{
1717
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
18+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
1819
using Microsoft.Azure.Management.ResourceManager.Models;
1920
using System;
2021
using System.Collections.Generic;
@@ -38,6 +39,7 @@ public class RemoveAzResourceGroupDeploymentStack : DeploymentStacksCmdletBase
3839

3940
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = RemoveByNameAndResourceGroupNameParameterSetName,
4041
HelpMessage = "The name of the Resource Group with the stack to delete")]
42+
[ResourceGroupCompleter]
4143
[ValidateNotNullOrEmpty]
4244
public string ResourceGroupName { get; set; }
4345

@@ -74,11 +76,12 @@ protected override void OnProcessRecord()
7476
var shouldDeleteResources = (DeleteAll.ToBool() || DeleteResources.ToBool()) ? true : false;
7577
var shouldDeleteResourceGroups = (DeleteAll.ToBool() || DeleteResourceGroups.ToBool()) ? true : false;
7678

79+
// resolve Name and ResourceGroupName if ResourceId was provided
7780
ResourceGroupName = ResourceGroupName ?? ResourceIdUtility.GetResourceGroupName(ResourceId);
7881
Name = Name ?? ResourceIdUtility.GetDeploymentName(ResourceId);
7982

8083
// failed resolving the resource id
81-
if(Name == null)
84+
if(Name == null || ResourceGroupName == null)
8285
{
8386
throw new PSArgumentException($"Provided Id '{ResourceId}' is not in correct form.");
8487
}
@@ -90,21 +93,24 @@ protected override void OnProcessRecord()
9093
confirmationMessage,
9194
"Deleting Deployment Stack ...",
9295
Name,
93-
() => DeploymentStacksSdkClient.DeleteResourceGroupDeploymentStack(
94-
ResourceGroupName,
95-
Name,
96-
resourcesCleanupAction: shouldDeleteResources ? "delete" : "detach",
97-
resourceGroupsCleanupAction: shouldDeleteResourceGroups ? "delete" : "detach"
98-
)
96+
() =>
97+
{
98+
DeploymentStacksSdkClient.DeleteResourceGroupDeploymentStack(
99+
ResourceGroupName,
100+
Name,
101+
resourcesCleanupAction: shouldDeleteResources ? "delete" : "detach",
102+
resourceGroupsCleanupAction: shouldDeleteResourceGroups ? "delete" : "detach"
103+
);
104+
WriteObject(true);
105+
}
99106
);
100-
101-
WriteObject(true);
102107
}
103108
catch (Exception ex)
104109
{
105110
if (ex is DeploymentStacksErrorException dex)
106111
throw new PSArgumentException(dex.Message + " : " + dex.Body.Error.Code + " : " + dex.Body.Error.Message);
107112
else
113+
WriteObject(false);
108114
WriteExceptionError(ex);
109115
}
110116
}

0 commit comments

Comments
 (0)