Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Network/Network/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
--->

## Upcoming Release
* Added name validation for `New-AzIpGroup`

## Version 3.0.0
* Added breaking change attribute to notify that Zone default behaviour will be changed
Expand Down
13 changes: 13 additions & 0 deletions src/Network/Network/IpGroup/NewIpGroupCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text.RegularExpressions;
using Microsoft.Azure.Commands.Network.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
Expand Down Expand Up @@ -88,6 +89,8 @@ public override void Execute()
throw new PSArgumentException(string.Format(Properties.Resources.ResourceAlreadyPresentInResourceGroup, this.Name, this.ResourceGroupName));
}

ValidateName(this.Name);

ConfirmAction(
Force.IsPresent,
string.Format(Properties.Resources.OverwritingResource, Name),
Expand Down Expand Up @@ -115,5 +118,15 @@ private PSIpGroup CreateIpGroups()
this.IpGroupsClient.CreateOrUpdate(this.ResourceGroupName, this.Name, ipGroupSdkObject);
return this.GetIpGroup(this.ResourceGroupName, this.Name);
}

private void ValidateName(string name)
{
var IpgroupNameRegex = new Regex("^[^_\\W]([\\w-.]{0,78}[\\w])?$");

if (!IpgroupNameRegex.IsMatch(name))
{
throw new PSArgumentException(string.Format(Properties.Resources.InvalidName, this.Name));
}
}
}
}
62 changes: 32 additions & 30 deletions src/Network/Network/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Network/Network/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@
<data name="ResourceAlreadyPresentInResourceGroup" xml:space="preserve">
<value>A resource with the same name {0} and same type already exists in ResourceGroup {1}. If you wish to modify this resource please use the Update operation instead.</value>
</data>
<data name="InvalidName" xml:space="preserve">
<value>Field Name {0} contains invalid character.</value>
</data>
<data name="VirtualHubToUpdateNotFound" xml:space="preserve">
<value>The VirtualHub to update could not be found.</value>
</data>
Expand Down