Skip to content

Commit dec54d0

Browse files
authored
Added support for Inbound Security Rule for Network Virtual Appliance (#24898)
* Adding support for Inbound Security Rule creation for NVA * Adding Tests fixing cmdlet import issue * Removing changes made for local testing failures * Removing changes from the file CommandMappings.json * Adding online versions for the help file * Adding changes to fix static analysis errors for command naming * Adding Parameter checks * Adding mandatory check for Name Parameter & removing * for protocol * Adding missed mappings
1 parent e96b5a9 commit dec54d0

13 files changed

+1198
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// limitations under the License.
2+
// ----------------------------------------------------------------------------------
3+
4+
using Microsoft.Azure.Commands.Network.Test.ScenarioTests;
5+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
6+
using Xunit;
7+
using Xunit.Abstractions;
8+
9+
namespace Commands.Network.Test.ScenarioTests
10+
{
11+
public class InboundSecurityRuleTests : NetworkTestRunner
12+
{
13+
public InboundSecurityRuleTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
14+
{
15+
}
16+
17+
[Fact]
18+
[Trait(Category.AcceptanceType, Category.CheckIn)]
19+
[Trait(Category.Owner, NrpTeamAlias.nvadev)]
20+
public void TestInboundSecurityRule()
21+
{
22+
TestRunner.RunTestScript(string.Format("Test-InboundSecurityRule"));
23+
}
24+
}
25+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
<#
16+
.SYNOPSIS
17+
Test creating new Inbound Security Rule
18+
#>
19+
function Test-InboundSecurityRule
20+
{
21+
$rgname = "AshuSneaky"
22+
23+
# The commands are not supported in all regions yet.
24+
$location = "eastus2euap"
25+
$nvaname = "sneaky4"
26+
$applieson = "slbip"
27+
$rulecollectionname = "PermanentRuleCollection"
28+
$resourceTypeParent = "Microsoft.Network/networkVirtualAppliances/inboundSecurityRules"
29+
$rulename1 = "InboundRule1"
30+
$protocol = "TCP"
31+
$sourceaddressprefix = "*"
32+
$destinationportranges = "80-120","121-124"
33+
$ruletype = "Permanent"
34+
try{
35+
$rule = New-AzVirtualApplianceInboundSecurityRulesProperty -Name $rulename1 -Protocol $protocol -SourceAddressPrefix $sourceaddressprefix -DestinationPortRangeList $destinationportranges -AppliesOn $applieson
36+
Assert-NotNull $rule
37+
38+
$updateresult = Update-AzVirtualApplianceInboundSecurityRule -ResourceGroupName $rgname -VirtualApplianceName $nvaname -Name $rulecollectionname -RuleType $ruletype -Rule $rule
39+
Assert-True { $updateresult }
40+
}
41+
finally{
42+
43+
}
44+
}
45+
46+

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.InboundSecurityRuleTests/TestInboundSecurityRule.json

Lines changed: 351 additions & 0 deletions
Large diffs are not rendered by default.

src/Network/Network/Az.Network.psd1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,8 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
639639
'Test-AzPrivateLinkServiceVisibility', 'Update-AzCustomIpPrefix',
640640
'Update-AzNetworkVirtualApplianceConnection',
641641
'New-AzVirtualApplianceInternetIngressIpsProperty',
642+
'New-AzVirtualApplianceInboundSecurityRulesProperty',
643+
'Update-AzVirtualApplianceInboundSecurityRule',
642644
'New-AzFirewallPacketCaptureRule',
643645
'New-AzFirewallPacketCaptureParameter',
644646
'Invoke-AzFirewallPacketCapture',

src/Network/Network/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
- `New-AzApplicationGatewayFirewallPolicySetting`
2525
* Added optional property `HeaderValueMatcher` to `New-AzApplicationGatewayRewriteRuleHeaderConfiguration`
2626
* Added new cmdlet `New-AzApplicationGatewayHeaderValueMatcher` to support for the new property `HeaderValueMatcher`
27+
* Added new cmdlet `Update-AzVirtualApplianceInboundSecurityRule` to support Inbound Security Rule for Network Virtual Appliance
28+
* Added new cmdlet `New-AzVirtualApplianceInboundSecurityRulesProperty` to support for the property 'rules' of Inbound Security Rules
2729
* Added AdminState parameter to Load Balancer Backend Address
2830
- `New-AzLoadBalancerBackendAddressConfig`
2931
* Updated PS SDK to older SDK removing identity field

src/Network/Network/Common/NetworkResourceManagerProfile.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2218,6 +2218,8 @@ private static void Initialize()
22182218
);
22192219
cfg.CreateMap<CNM.PSVirtualApplianceSite, MNM.VirtualApplianceSite>();
22202220
cfg.CreateMap<CNM.PSVirtualApplianceSkuProperties, MNM.VirtualApplianceSkuProperties>();
2221+
cfg.CreateMap<CNM.PSInboundSecurityRule, MNM.InboundSecurityRule>();
2222+
cfg.CreateMap<CNM.PSInboundSecurityRulesProperty, MNM.InboundSecurityRules>();
22212223
cfg.CreateMap<CNM.PSNetworkVirtualApplianceConnection, MNM.NetworkVirtualApplianceConnection>();
22222224
cfg.CreateMap<CNM.PSVirtualApplianceInternetIngressIpsProperties, MNM.InternetIngressPublicIpsProperties>();
22232225
cfg.CreateMap<CNM.PSNetworkVirtualApplianceDelegationProperties, MNM.DelegationProperties>();
@@ -2241,6 +2243,8 @@ private static void Initialize()
22412243
);
22422244
cfg.CreateMap<MNM.VirtualApplianceSite, CNM.PSVirtualApplianceSite>();
22432245
cfg.CreateMap<MNM.VirtualApplianceSkuProperties, CNM.PSVirtualApplianceSkuProperties>();
2246+
cfg.CreateMap<MNM.InboundSecurityRule, CNM.PSInboundSecurityRule>();
2247+
cfg.CreateMap<MNM.InboundSecurityRules, CNM.PSInboundSecurityRulesProperty>();
22442248
cfg.CreateMap<MNM.VirtualApplianceAdditionalNicProperties, CNM.PSVirtualApplianceAdditionalNicProperties>();
22452249
cfg.CreateMap<MNM.InternetIngressPublicIpsProperties, CNM.PSVirtualApplianceInternetIngressIpsProperties>();
22462250
cfg.CreateMap<MNM.NetworkVirtualApplianceConnection,CNM.PSNetworkVirtualApplianceConnection>();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright Microsoft Corporation
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
// Unless required by applicable law or agreed to in writing, software
7+
// distributed under the License is distributed on an "AS IS" BASIS,
8+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
// See the License for the specific language governing permissions and
10+
// limitations under the License.
11+
// ----------------------------------------------------------------------------------
12+
13+
14+
using Microsoft.WindowsAzure.Commands.Common.Attributes;
15+
using Newtonsoft.Json;
16+
using System.Collections.Generic;
17+
using System.Reflection.Emit;
18+
19+
namespace Microsoft.Azure.Commands.Network.Models
20+
{
21+
public class PSInboundSecurityRule : PSChildResource
22+
{
23+
public string RuleType { get; set; }
24+
public string ProvisioningState { get; set; }
25+
public string Type { get; set; }
26+
public List<PSInboundSecurityRulesProperty> Rules { get; set; }
27+
}
28+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright Microsoft Corporation
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
// http://www.apache.org/licenses/LICENSE-2.0
6+
// Unless required by applicable law or agreed to in writing, software
7+
// distributed under the License is distributed on an "AS IS" BASIS,
8+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
// See the License for the specific language governing permissions and
10+
// limitations under the License.
11+
// ----------------------------------------------------------------------------------
12+
13+
14+
using Microsoft.WindowsAzure.Commands.Common.Attributes;
15+
using Newtonsoft.Json;
16+
using System.Collections.Generic;
17+
using System.Reflection.Emit;
18+
19+
namespace Microsoft.Azure.Commands.Network.Models
20+
{
21+
public class PSInboundSecurityRulesProperty
22+
{
23+
public string Name { get; set; }
24+
public string Protocol { get; set; }
25+
public string SourceAddressPrefix { get; set; }
26+
public int? DestinationPortRange { get; set; }
27+
public List<string> DestinationPortRanges{ get; set; }
28+
public List<string> AppliesOn { get; set; }
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+

2+
// ----------------------------------------------------------------------------------
3+
//
4+
// Copyright Microsoft Corporation
5+
// Licensed under the Apache License, Version 2.0 (the "License");
6+
// you may not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
// ----------------------------------------------------------------------------------
15+
16+
namespace Microsoft.Azure.Commands.Network
17+
{
18+
using Microsoft.Azure.Commands.Network.Models;
19+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
20+
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
21+
using Microsoft.Azure.Management.Network.Models;
22+
using System;
23+
using System.Collections.Generic;
24+
using System.Linq;
25+
using System.Management.Automation;
26+
27+
[Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VirtualApplianceInboundSecurityRulesProperty",
28+
SupportsShouldProcess = true),
29+
OutputType(typeof(PSInboundSecurityRulesProperty))]
30+
public class NewVirtualApplianceInboundSecurityRulesPropertyCommand : VirtualApplianceInboundSecurityRuleBaseCmdlet
31+
{
32+
[Parameter(
33+
Mandatory = true,
34+
HelpMessage = "Name of the Inbound Security Rules Property")]
35+
public string Name { get; set; }
36+
37+
[Parameter(
38+
Mandatory = true,
39+
HelpMessage = "Rule protocol")]
40+
[ValidateSet(
41+
SecurityRuleProtocol.Tcp,
42+
SecurityRuleProtocol.Udp,
43+
IgnoreCase = true)]
44+
[ValidateNotNullOrEmpty]
45+
public string Protocol { get; set; }
46+
47+
[Parameter(
48+
Mandatory = true,
49+
HelpMessage = "The Source Address Prefix of the rule")]
50+
public string SourceAddressPrefix { get; set; }
51+
52+
[Parameter(
53+
Mandatory = false,
54+
HelpMessage = "Destination Port Range of the rule")]
55+
public int? DestinationPortRange { get; set; }
56+
57+
[Parameter(
58+
Mandatory = false,
59+
HelpMessage = "Destination Port Ranges of the rule")]
60+
public string[] DestinationPortRangeList { get; set; }
61+
62+
[Parameter(
63+
Mandatory = true,
64+
HelpMessage = "The Applies On value of the rule for the SLP IP/Interface")]
65+
public string[] AppliesOn { get; set; }
66+
67+
public override void Execute()
68+
{
69+
base.Execute();
70+
71+
if (!this.DestinationPortRange.HasValue && (this.DestinationPortRangeList == null || this.DestinationPortRangeList.Length == 0))
72+
{
73+
throw new PSArgumentException("Both 'DestinationPortRange' and 'DestinationPortRangeList' cannot be null. Please make sure to input value for one of the parameters.");
74+
}
75+
76+
if (this.DestinationPortRange.HasValue && this.DestinationPortRangeList != null && this.DestinationPortRangeList.Length >= 0)
77+
{
78+
throw new PSArgumentException("Both 'DestinationPortRange' and 'DestinationPortRangeList' cannot have values. Please make sure to input value for only one of the parameters.");
79+
}
80+
81+
var rule = new PSInboundSecurityRulesProperty();
82+
rule.Name = this.Name;
83+
rule.Protocol = this.Protocol;
84+
rule.SourceAddressPrefix = this.SourceAddressPrefix;
85+
rule.DestinationPortRange = this.DestinationPortRange;
86+
rule.DestinationPortRanges = this.DestinationPortRangeList !=null ? this.DestinationPortRangeList.ToList() : null;
87+
rule.AppliesOn = this.AppliesOn.ToList();
88+
89+
WriteObject(rule, true);
90+
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)