Skip to content

Commit 69b09d8

Browse files
committed
addressed comments
1 parent d2135fd commit 69b09d8

File tree

6 files changed

+22
-34
lines changed

6 files changed

+22
-34
lines changed

src/ResourceManager/Insights/Commands.Insights.Test/ActionGroups/NewAzureRmActionGroupReceiverCommandTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ namespace Microsoft.Azure.Commands.Insights.Test.ActionGroups
2424

2525
using Microsoft.Azure.Commands.Insights.OutputClasses;
2626
using Microsoft.Azure.Management.Monitor.Management.Models;
27+
using Microsoft.WindowsAzure.Commands.Utilities.Common;
2728

2829
public class NewAzureRmActionGroupReceiverTests
2930
{
@@ -44,6 +45,7 @@ public NewAzureRmActionGroupReceiverTests(Xunit.Abstractions.ITestOutputHelper o
4445
[Trait(Category.AcceptanceType, Category.CheckIn)]
4546
public void NewAzureRmReceiverCommandEmailParametersProcessing()
4647
{
48+
Cmdlet.SetParameterSet("NewEmailReceiver");
4749
Cmdlet.EmailReceiver = true;
4850
Cmdlet.Name = "email1";
4951
Cmdlet.EmailAddress = "[email protected]";
@@ -63,6 +65,7 @@ public void NewAzureRmReceiverCommandEmailParametersProcessing()
6365
[Trait(Category.AcceptanceType, Category.CheckIn)]
6466
public void NewAzureRmReceiverCommandSmsParametersProcessing()
6567
{
68+
Cmdlet.SetParameterSet("NewSmsReceiver");
6669
Cmdlet.SmsReceiver = true;
6770
Cmdlet.Name = "sms1";
6871
Cmdlet.CountryCode = "1";
@@ -84,6 +87,7 @@ public void NewAzureRmReceiverCommandSmsParametersProcessing()
8487
[Trait(Category.AcceptanceType, Category.CheckIn)]
8588
public void NewAzureRmReceiverCommandWebhookParametersProcessing()
8689
{
90+
Cmdlet.SetParameterSet("NewWebhookReceiver");
8791
Cmdlet.WebhookReceiver = true;
8892
Cmdlet.Name = "webhook1";
8993
Cmdlet.ServiceUri = "http://test.com";

src/ResourceManager/Insights/Commands.Insights/ActionGroups/NewAzureRmActionGroupReceiverCommand.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
namespace Microsoft.Azure.Commands.Insights.ActionGroups
2121
{
22-
using System;
23-
2422
/// <summary>
2523
/// Create an ActionGroup receiver
2624
/// </summary>
@@ -45,7 +43,7 @@ public class NewAzureRmActionGroupReceiverCommand : AzureRMCmdlet
4543
/// <summary>
4644
/// Gets or sets email receiver SwitchParameter
4745
/// </summary>
48-
[Parameter(ParameterSetName = NewEmailReceiver, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Create a email receiver")]
46+
[Parameter(ParameterSetName = NewEmailReceiver, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Create a email receiver")]
4947
public SwitchParameter EmailReceiver { get; set; }
5048

5149
/// <summary>
@@ -58,7 +56,7 @@ public class NewAzureRmActionGroupReceiverCommand : AzureRMCmdlet
5856
/// <summary>
5957
/// Gets or sets sms receiver SwitchParameter
6058
/// </summary>
61-
[Parameter(ParameterSetName = NewSmsReceiver, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Create a sms receiver")]
59+
[Parameter(ParameterSetName = NewSmsReceiver, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Create a sms receiver")]
6260
public SwitchParameter SmsReceiver { get; set; }
6361

6462
/// <summary>
@@ -78,7 +76,7 @@ public class NewAzureRmActionGroupReceiverCommand : AzureRMCmdlet
7876
/// <summary>
7977
/// Gets or sets webhook receiver SwitchParameter
8078
/// </summary>
81-
[Parameter(ParameterSetName = NewWebhookReceiver, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Create a webhook receiver")]
79+
[Parameter(ParameterSetName = NewWebhookReceiver, Mandatory = false, ValueFromPipelineByPropertyName = true, HelpMessage = "Create a webhook receiver")]
8280
public SwitchParameter WebhookReceiver { get; set; }
8381

8482
/// <summary>
@@ -96,15 +94,15 @@ public class NewAzureRmActionGroupReceiverCommand : AzureRMCmdlet
9694
public override void ExecuteCmdlet()
9795
{
9896
PSActionGroupReceiverBase receiverBase = null;
99-
if (this.EmailReceiver.IsPresent)
97+
if (this.ParameterSetName == NewEmailReceiver)
10098
{
10199
receiverBase = new PSEmailReceiver { Name = Name, EmailAddress = EmailAddress };
102100
}
103-
else if (this.SmsReceiver.IsPresent)
101+
else if (this.ParameterSetName == NewSmsReceiver)
104102
{
105103
receiverBase = new PSSmsReceiver { Name = Name, CountryCode = CountryCode, PhoneNumber = PhoneNumber };
106104
}
107-
else if (this.WebhookReceiver.IsPresent)
105+
else if (this.ParameterSetName == NewWebhookReceiver)
108106
{
109107
receiverBase = new PSWebhookReceiver { Name = Name, ServiceUri = ServiceUri };
110108
}

src/ResourceManager/Insights/Commands.Insights/ActionGroups/RemoveAzureRmActionGroupCommand.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ namespace Microsoft.Azure.Commands.Insights.ActionGroups
2121
{
2222
using System;
2323

24+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
25+
2426
/// <summary>
2527
/// Gets an Azure Action Group.
2628
/// </summary>
@@ -77,8 +79,9 @@ protected override void ProcessRecordInternal()
7779
}
7880
else if (ParameterSetName == ByResourceId)
7981
{
80-
this.ResourceGroupName = Utilities.GetResourceGroupFromId(this.ResourceId);
81-
this.Name = Utilities.GetResourceNameFromId(this.ResourceId);
82+
ResourceIdentifier resourceId = new ResourceIdentifier(this.ResourceId);
83+
this.ResourceGroupName = resourceId.ResourceGroupName;
84+
this.Name = resourceId.ResourceName;
8285
}
8386

8487
var result =

src/ResourceManager/Insights/Commands.Insights/ActionGroups/SetAzureRmActionGroupCommand.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace Microsoft.Azure.Commands.Insights.ActionGroups
2323
using System.Collections;
2424
using System.Linq;
2525

26+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
2627
using Microsoft.Azure.Management.Monitor.Management;
2728

2829
/// <summary>
@@ -118,8 +119,9 @@ protected override void ProcessRecordInternal()
118119
}
119120
else if (ParameterSetName == ByResourceId)
120121
{
121-
this.ResourceGroupName = Utilities.GetResourceGroupFromId(this.ResourceId);
122-
this.Name = Utilities.GetResourceNameFromId(this.ResourceId);
122+
ResourceIdentifier resourceId = new ResourceIdentifier(this.ResourceId);
123+
this.ResourceGroupName = resourceId.ResourceGroupName;
124+
this.Name = resourceId.ResourceName;
123125
}
124126

125127
IList<EmailReceiver> emailReceivers =

src/ResourceManager/Insights/Commands.Insights/OutputClasses/PSActionGroupResource.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ namespace Microsoft.Azure.Commands.Insights.OutputClasses
1919
using System.Collections.Generic;
2020
using System.Linq;
2121

22+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
23+
2224
/// <summary>
2325
/// Wraps around an Action Group.
2426
/// </summary>
@@ -73,7 +75,7 @@ public PSActionGroupResource(ActionGroupResource actionGroupResource)
7375
type: actionGroupResource.Type,
7476
tags: actionGroupResource.Tags)
7577
{
76-
this.ResourceGroupName = Utilities.GetResourceGroupFromId(actionGroupResource.Id);
78+
this.ResourceGroupName = new ResourceIdentifier(actionGroupResource.Id).ResourceGroupName;
7779
GroupShortName = actionGroupResource.GroupShortName;
7880
Enabled = actionGroupResource.Enabled;
7981
EmailReceivers = actionGroupResource.EmailReceivers?.Select(o => new PSEmailReceiver(o)).ToList();

src/ResourceManager/Insights/Commands.Insights/Utilities.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,26 +75,5 @@ public static void ExtractCollectionFromResult(this IEnumerator<EventData> enume
7575
}
7676
}
7777
}
78-
79-
public static string GetResourceGroupFromId(string resourceId)
80-
{
81-
const string resourceGroup = "resourceGroups";
82-
83-
var startIndex = resourceId.IndexOf(resourceGroup, StringComparison.OrdinalIgnoreCase) + resourceGroup.Length + 1;
84-
var endIndex = resourceId.IndexOf("/", startIndex, StringComparison.OrdinalIgnoreCase);
85-
86-
return resourceId.Substring(startIndex, endIndex - startIndex);
87-
}
88-
89-
public static string GetResourceNameFromId(string resourceId)
90-
{
91-
if (string.IsNullOrWhiteSpace(resourceId))
92-
{
93-
return null;
94-
}
95-
96-
var parts = resourceId.Split('/');
97-
return parts.LastOrDefault();
98-
}
9978
}
10079
}

0 commit comments

Comments
 (0)