Skip to content

Commit 187764d

Browse files
committed
changes for incremental release
1 parent b66a5fc commit 187764d

File tree

11 files changed

+167
-54
lines changed

11 files changed

+167
-54
lines changed

src/Resources/ResourceManager/Implementation/CmdletBase/ResourceWithParameterCmdletBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ protected override void OnBeginProcessing()
186186

187187
public new virtual object GetDynamicParameters()
188188
{
189-
if (BicepUtility.IsBicepFile(TemplateUri))
189+
if (BicepUtility.IsBicepFile(TemplateUri))
190190
{
191191
throw new NotSupportedException($"'-TemplateUri {TemplateUri}' is not supported. Please download the bicep file and pass it using -TemplateFile.");
192192
}

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,16 +270,16 @@ protected override void OnProcessRecord()
270270
throwIfNotExists: false) != null)
271271
{
272272
string confirmationMessage = $"The DeploymentStack '{Name}' you're trying to create already exists in ManagementGroup '{ManagementGroupId}'. " +
273-
$"Do you want to overwrite it with the following actions?" +
274-
(!shouldDeleteResources || !shouldDeleteResourceGroups ? "\nDetaching: " : "") +
275-
(!shouldDeleteResources ? "resources" : "") +
276-
(!shouldDeleteResources && !shouldDeleteResourceGroups ? ", " : "") +
277-
(!shouldDeleteResourceGroups ? "resourceGroups" : "") +
273+
$"Do you want to overwrite it\n?" +
274+
$"The following actions will be applied to any resources the are no longer managed by the deployment stack after the template is applied:" +
278275
(shouldDeleteResources || shouldDeleteResourceGroups ? "\nDeleting: " : "") +
279276
(shouldDeleteResources ? "resources" : "") +
280277
(shouldDeleteResources && shouldDeleteResourceGroups ? ", " : "") +
281-
(shouldDeleteResourceGroups ? "resourceGroups" : "");
282-
278+
(shouldDeleteResourceGroups ? "resourceGroups" : "") +
279+
(!shouldDeleteResources || !shouldDeleteResourceGroups ? "\nDetaching: " : "") +
280+
(!shouldDeleteResources ? "resources" : "") +
281+
(!shouldDeleteResources && !shouldDeleteResourceGroups ? ", " : "") +
282+
(!shouldDeleteResourceGroups ? "resourceGroups" : "");
283283
ConfirmAction(
284284
Force.IsPresent,
285285
confirmationMessage,

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,16 @@ protected override void OnProcessRecord()
256256
throwIfNotExists: false) != null)
257257
{
258258
string confirmationMessage = $"The DeploymentStack '{Name}' you're trying to create already exists in ResourceGroup '{ResourceGroupName}'. " +
259-
$"Do you want to overwrite it with the following actions?" +
260-
(!shouldDeleteResources || !shouldDeleteResourceGroups ? "\nDetaching: " : "") +
261-
(!shouldDeleteResources ? "resources" : "") +
262-
(!shouldDeleteResources && !shouldDeleteResourceGroups ? ", " : "") +
263-
(!shouldDeleteResourceGroups ? "resourceGroups" : "") +
259+
$"Do you want to overwrite it?\n" +
260+
$"The following actions will be applied to any resources the are no longer managed by the deployment stack after the template is applied:" +
264261
(shouldDeleteResources || shouldDeleteResourceGroups ? "\nDeleting: " : "") +
265262
(shouldDeleteResources ? "resources" : "") +
266263
(shouldDeleteResources && shouldDeleteResourceGroups ? ", " : "") +
267-
(shouldDeleteResourceGroups ? "resourceGroups" : "");
264+
(shouldDeleteResourceGroups ? "resourceGroups" : "") +
265+
(!shouldDeleteResources || !shouldDeleteResourceGroups ? "\nDetaching: " : "") +
266+
(!shouldDeleteResources ? "resources" : "") +
267+
(!shouldDeleteResources && !shouldDeleteResourceGroups ? ", " : "") +
268+
(!shouldDeleteResourceGroups ? "resourceGroups" : "");
268269

269270
ConfirmAction(
270271
Force.IsPresent,

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -264,16 +264,16 @@ protected override void OnProcessRecord()
264264
{
265265

266266
string confirmationMessage = $"The DeploymentStack '{Name}' you're trying to create already exists in the current subscription. " +
267-
$"Do you want to overwrite it with the following actions?" +
268-
(!shouldDeleteResources || !shouldDeleteResourceGroups ? "\nDetaching: " : "") +
269-
(!shouldDeleteResources ? "resources" : "") +
270-
(!shouldDeleteResources && !shouldDeleteResourceGroups ? ", " : "") +
271-
(!shouldDeleteResourceGroups ? "resourceGroups" : "") +
267+
$"Do you want to overwrite it?\n" +
268+
$"The following actions will be applied to any resources the are no longer managed by the deployment stack after the template is applied:" +
272269
(shouldDeleteResources || shouldDeleteResourceGroups ? "\nDeleting: " : "") +
273270
(shouldDeleteResources ? "resources" : "") +
274271
(shouldDeleteResources && shouldDeleteResourceGroups ? ", " : "") +
275-
(shouldDeleteResourceGroups ? "resourceGroups" : "");
276-
272+
(shouldDeleteResourceGroups ? "resourceGroups" : "") +
273+
(!shouldDeleteResources || !shouldDeleteResourceGroups ? "\nDetaching: " : "") +
274+
(!shouldDeleteResources ? "resources" : "") +
275+
(!shouldDeleteResources && !shouldDeleteResourceGroups ? ", " : "") +
276+
(!shouldDeleteResourceGroups ? "resourceGroups" : "");
277277
ConfirmAction(
278278
Force.IsPresent,
279279
confirmationMessage,

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public class RemoveAzManagementGroupDeploymentStack : DeploymentStacksCmdletBase
6060
/*[Parameter(Mandatory = false, HelpMessage = "Singal to delete unmanaged stack management groups after updating stack.")]
6161
public SwitchParameter DeleteManagementGroups { get; set; }*/
6262

63+
[Parameter(Mandatory = false, HelpMessage = "If set, a boolean will be returned with value dependent on cmdlet success.")]
64+
public SwitchParameter PassThru { get; set; }
65+
6366
[Parameter(Mandatory = false, HelpMessage = "Do not ask for confirmation.")]
6467
public SwitchParameter Force { get; set; }
6568

@@ -109,17 +112,23 @@ protected override void OnProcessRecord()
109112
resourcesCleanupAction: shouldDeleteResources ? "delete" : "detach",
110113
resourceGroupsCleanupAction: shouldDeleteResourceGroups ? "delete" : "detach"
111114
);
112-
WriteObject(true);
115+
if (PassThru.IsPresent)
116+
{
117+
WriteObject(true);
118+
}
113119
}
114120
);
115121
}
116122
catch (Exception ex)
117123
{
118124
if (ex is DeploymentStacksErrorException dex)
125+
{
119126
throw new PSArgumentException(dex.Message + " : " + dex.Body.Error.Code + " : " + dex.Body.Error.Message);
127+
}
120128
else
121-
WriteObject(false);
129+
{
122130
WriteExceptionError(ex);
131+
}
123132
}
124133
}
125134

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ public class RemoveAzResourceGroupDeploymentStack : DeploymentStacksCmdletBase
6262
/*[Parameter(Mandatory = false, HelpMessage = "Singal to delete unmanaged stack management groups after updating stack.")]
6363
public SwitchParameter DeleteManagementGroups { get; set; }*/
6464

65+
[Parameter(Mandatory = false, HelpMessage = "If set, a boolean will be returned with value dependent on cmdlet success.")]
66+
public SwitchParameter PassThru { get; set; }
67+
6568
[Parameter(Mandatory = false, HelpMessage = "Do not ask for confirmation.")]
6669
public SwitchParameter Force { get; set; }
6770

@@ -110,17 +113,23 @@ protected override void OnProcessRecord()
110113
resourcesCleanupAction: shouldDeleteResources ? "delete" : "detach",
111114
resourceGroupsCleanupAction: shouldDeleteResourceGroups ? "delete" : "detach"
112115
);
113-
WriteObject(true);
116+
if (PassThru.IsPresent)
117+
{
118+
WriteObject(true);
119+
}
114120
}
115121
);
116122
}
117123
catch (Exception ex)
118124
{
119125
if (ex is DeploymentStacksErrorException dex)
126+
{
120127
throw new PSArgumentException(dex.Message + " : " + dex.Body.Error.Code + " : " + dex.Body.Error.Message);
128+
}
121129
else
122-
WriteObject(false);
130+
{
123131
WriteExceptionError(ex);
132+
}
124133
}
125134
}
126135

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ public class RemoveAzSubscriptionDeploymentStack : DeploymentStacksCmdletBase
5656
/*[Parameter(Mandatory = false, HelpMessage = "Singal to delete unmanaged stack management groups after updating stack.")]
5757
public SwitchParameter DeleteManagementGroups { get; set; }*/
5858

59+
[Parameter(Mandatory = false, HelpMessage = "If set, a boolean will be returned with value dependent on cmdlet success.")]
60+
public SwitchParameter PassThru { get; set; }
61+
5962
[Parameter(Mandatory = false, HelpMessage = "Do not ask for confirmation.")]
6063
public SwitchParameter Force { get; set; }
6164

@@ -103,20 +106,26 @@ protected override void OnProcessRecord()
103106
resourcesCleanupAction: shouldDeleteResources ? "delete" : "detach",
104107
resourceGroupsCleanupAction: shouldDeleteResourceGroups ? "delete" : "detach"
105108
);
106-
WriteObject(true);
109+
if (PassThru.IsPresent)
110+
{
111+
WriteObject(true);
112+
}
107113
}
108114
);
109115
}
110116
catch (Exception ex)
111117
{
112118
if (ex is DeploymentStacksErrorException dex)
119+
{
113120
throw new PSArgumentException(dex.Message + " : " + dex.Body.Error.Code + " : " + dex.Body.Error.Message);
121+
}
114122
else
115-
WriteObject(false);
123+
{
116124
WriteExceptionError(ex);
125+
}
117126
}
118127
}
119128

120129
#endregion
121130
}
122-
}
131+
}

src/Resources/ResourceManager/SdkClient/DeploymentStacksSdkClient.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,14 +460,16 @@ internal void DeleteResourceGroupDeploymentStack(string resourceGroupName, strin
460460

461461
internal void DeleteSubscriptionDeploymentStack(string name, string resourcesCleanupAction, string resourceGroupsCleanupAction)
462462
{
463-
var deleteResponse = DeploymentStacksClient.DeploymentStacks.DeleteAtSubscription(name, resourcesCleanupAction, resourceGroupsCleanupAction);
463+
var deleteResponse = DeploymentStacksClient.DeploymentStacks.DeleteAtSubscriptionWithHttpMessagesAsync(name, resourcesCleanupAction, resourceGroupsCleanupAction)
464+
.GetAwaiter()
465+
.GetResult();
464466

465-
/* if (deleteResponse.Response.StatusCode == System.Net.HttpStatusCode.NoContent)
467+
if (deleteResponse.Response.StatusCode == System.Net.HttpStatusCode.NoContent)
466468
{
467469
throw new PSArgumentException(
468470
$"DeploymentStack '{name}' not found in the curent subscription scope."
469471
);
470-
}*/
472+
}
471473

472474
return;
473475
}

src/Resources/ResourceManager/SdkExtensions/ResourcesExtensions.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,40 @@ public static string ConstructTagsTable(Hashtable tags)
176176
return resourcesTable.ToString();
177177
}
178178

179+
public static string ConstructTagsTableFromIDictionary(IDictionary<string, string> tags)
180+
{
181+
// TODO: Can I change existing code?
182+
183+
if (tags == null || tags.Count == 0)
184+
{
185+
return null;
186+
}
187+
188+
StringBuilder resourcesTable = new StringBuilder();
189+
190+
int maxNameLength = Math.Max("Name".Length, tags.Max(tag => tag.Key.Length));
191+
int maxValueLength = Math.Max("Value".Length, tags.Max(tag => tag.Value.Length));
192+
193+
string rowFormat = "{0, -" + maxNameLength + "} {1, -" + maxValueLength + "}\r\n";
194+
resourcesTable.AppendLine();
195+
resourcesTable.AppendFormat(rowFormat, "Name", "Value");
196+
resourcesTable.AppendFormat(rowFormat,
197+
GeneralUtilities.GenerateSeparator(maxNameLength, "="),
198+
GeneralUtilities.GenerateSeparator(maxValueLength, "="));
199+
200+
foreach (var tag in tags)
201+
{
202+
if (tag.Key.StartsWith(TagsClient.ExecludedTagPrefix))
203+
{
204+
continue;
205+
}
206+
207+
resourcesTable.AppendFormat(rowFormat, tag.Key, tag.Value);
208+
}
209+
210+
return resourcesTable.ToString();
211+
}
212+
179213
private static string ConstructTemplateLinkView(TemplateLink templateLink)
180214
{
181215
if (templateLink == null)

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

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkExtensions;
1+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
2+
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkExtensions;
23
using Microsoft.Azure.Management.Internal.Network.Version2017_10_01;
34
using Microsoft.Azure.Management.ResourceManager.Models;
45
using Microsoft.Rest;
@@ -11,6 +12,8 @@
1112
using System.Collections.Generic;
1213
using System.Globalization;
1314
using System.Linq;
15+
using System.Text;
16+
using ProjectResources = Microsoft.Azure.Commands.ResourceManager.Cmdlets.Properties.Resources;
1417

1518
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels
1619
{
@@ -106,6 +109,52 @@ internal PSDeploymentStack(DeploymentStack deploymentStack)
106109

107110
}
108111

112+
public string GetFormattedParameterTable()
113+
{
114+
return ResourcesExtensions.ConstructDeploymentVariableTable(this.parameters);
115+
}
116+
117+
public string GetFormattedOutputTable()
118+
{
119+
return ResourcesExtensions.ConstructDeploymentVariableTable(this.outputs);
120+
}
121+
122+
public string GetFormattedTagTable()
123+
{
124+
return ResourcesExtensions.ConstructTagsTableFromIDictionary(this.Tags);
125+
}
126+
127+
private const char Whitespace = ' ';
128+
129+
public string GetFormattedErrorString()
130+
{
131+
return this.error == null
132+
? string.Empty
133+
: GetFormattedErrorString(this.error).TrimEnd('\r', '\n');
134+
}
135+
136+
private static string GetFormattedErrorString(ErrorResponse error, int level = 0)
137+
{
138+
if (error.Details == null)
139+
{
140+
return string.Format(ProjectResources.DeploymentOperationErrorMessageNoDetails, error.Message, error.Code);
141+
}
142+
143+
string errorDetail = null;
144+
145+
foreach (ErrorResponse detail in error.Details)
146+
{
147+
errorDetail += GetIndentation(level) + GetFormattedErrorString(detail, level + 1) + System.Environment.NewLine;
148+
}
149+
150+
return string.Format(ProjectResources.DeploymentOperationErrorMessage, error.Message, error.Code, errorDetail);
151+
}
152+
153+
private static string GetIndentation(int l)
154+
{
155+
return new StringBuilder().Append(Whitespace, l * 2).Append(" - ").ToString();
156+
}
157+
109158
internal static PSDeploymentStack FromAzureSDKDeploymentStack(DeploymentStack stack)
110159
{
111160
return stack != null

0 commit comments

Comments
 (0)