Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support to Get IKE Security Associations on Virtual Network Gateway Connections #13853

Merged
merged 39 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7bd90a2
Adding GetIkeSas
Dec 21, 2020
2c3703c
Implemented as string
Dec 21, 2020
592def5
Returning Ike Sas
Dec 23, 2020
34f42e1
Changed IkeSas to IkeSa
Dec 28, 2020
07b3431
Revert "Changed IkeSas to IkeSa"
Dec 28, 2020
6b4ea27
GetIkeSas
Dec 28, 2020
1c6fa2b
Changed IkeSas to IkeSa
Dec 28, 2020
9d9f67c
Updating changelog.md
Dec 30, 2020
a2ea28e
Merge branch 'network-august' into vng-ikesas
abhi7860 Dec 30, 2020
e2842ef
Removing unnecessary usings
Dec 31, 2020
84a1add
Adding csproj
Dec 31, 2020
782d349
Revert "Adding csproj"
Dec 31, 2020
1ddcb32
Adding required proj files and packages
Jan 4, 2021
9a557f1
Resolving comment
Jan 4, 2021
ac48586
Update Get-AzVirtualNetworkGatewayConnectionIkeSa.md
Jan 4, 2021
0e9e7ce
Update Get-AzVirtualNetworkGatewayConnectionIkeSa.md
Jan 4, 2021
5d09e38
Changing mandatory parameters
Jan 6, 2021
3885cb0
Update GetAzVirtualNetworkGatewayConnectionIkeSaCommand.cs
Jan 6, 2021
4e579f1
Adding test
Jan 7, 2021
02290b8
Merge branch 'network-august' into vng-ikesas
isra-fel Jan 7, 2021
4d1622f
Update VirtualNetworkGatewayConnectionTests.ps1
Jan 7, 2021
e79d904
Revert "Adding required proj files and packages"
Jan 8, 2021
10d2180
Merge remote-tracking branch 'upstream/network-august' into vng-ikesas
Jan 8, 2021
84ecf3b
Updating tests
Jan 11, 2021
73d054d
Modifying data type
Jan 12, 2021
d51019a
Update VirtualNetworkGatewayConnectionTests.cs
Jan 12, 2021
22490d3
Cherry-Picked changes
Jan 12, 2021
7e9cc32
Test case
Jan 12, 2021
85257dc
Resolving comment
abhi7860 Jan 12, 2021
d865935
Resolving comment
abhi7860 Jan 12, 2021
6a70a09
Revert "Resolving comment"
Jan 12, 2021
3409f18
Merge from upstream/release-2021-01-19
Jan 12, 2021
8ba6ff6
Modifying test
Jan 12, 2021
e3b573f
Adding Session Record
Jan 12, 2021
ee22629
New Session Record
Jan 13, 2021
1deaa3f
Bug fix
Jan 13, 2021
2c87cc7
Merge branch 'release-2021-01-19' into vng-ikesas
Jan 13, 2021
456b966
Updated test case and session record
Jan 13, 2021
c7ce283
Merge branch 'release-2021-01-19' into vng-ikesas
isra-fel Jan 14, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function Test-VirtualNetworkGatewayConnectionWithIpsecPoliciesCRUD
Assert-AreEqual $connection.IpsecPolicies[0].DhGroup $actual.IpsecPolicies[0].DhGroup
Assert-AreEqual $connection.IpsecPolicies[0].PfsGroup $actual.IpsecPolicies[0].PfsGroup
Assert-AreEqual 30 $connection.DpdTimeoutSeconds

# Set & Get VirtualNetworkGatewayConnection with policy cleared
$job = Set-AzVirtualNetworkGatewayConnection -VirtualNetworkGatewayConnection $connection -UsePolicyBasedTrafficSelectors $false -IpsecPolicies @() -DpdTimeoutInSeconds 10 -Force -AsJob
$job | Wait-Job
Expand Down
1 change: 1 addition & 0 deletions src/Network/Network/Az.Network.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
'Get-AzLocalNetworkGateway', 'New-AzLocalNetworkGateway',
'Set-AzLocalNetworkGateway',
'Get-AzVirtualNetworkGatewayConnection',
'Get-AzVirtualNetworkGatewayConnectionIkeSa',
'Get-AzVirtualNetworkGatewayConnectionSharedKey',
'New-AzVirtualNetworkGatewayConnection',
'Remove-AzVirtualNetworkGatewayConnection',
Expand Down
2 changes: 2 additions & 0 deletions src/Network/Network/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
- Added parameter -IntrusionDetection
- Added parameter -TransportSecurityName
- Added parameter -TransportSecurityKeyVaultSecretId
* Adding new cmdlet to fetch IKE Security Associations for Virtual Network Gateway Connections.
abhi7860 marked this conversation as resolved.
Show resolved Hide resolved
- `Get-AzVirtualNetworkGatewayConnectionIkeSa`

## Version 4.3.0
* Updated below cmdlet
Expand Down
124 changes: 124 additions & 0 deletions src/Network/Network/Models/PSVirtualNetworkGatewayConnectionIkeSa.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.Network.Models
{
using Microsoft.WindowsAzure.Commands.Common.Attributes;
using System;
using System.Collections.Generic;

public class PSVirtualNetworkGatewayConnectionIkeSa
{
public List<PSVirtualNetworkGatewayConnectionIkeSaMainModeSa> ikesas;

public PSVirtualNetworkGatewayConnectionIkeSa()
{
ikesas = new List<PSVirtualNetworkGatewayConnectionIkeSaMainModeSa>();
}
}

public class PSVirtualNetworkGatewayConnectionIkeSaMainModeSa
{
[Ps1Xml(Target = ViewControl.Table)]
public string localEndpoint { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public string remoteEndpoint { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public ulong initiatorCookie { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public ulong responderCookie { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public uint localUdpEncapsulationPort { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public uint remoteUdpEncapsulationPort { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public string encryption { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public string integrity { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public string dhGroup { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public uint lifeTimeSeconds { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public bool isSaInitiator { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public UInt32 elapsedTimeInseconds { get; set; }

public List<PSVirtualNetworkGatewayConnectionIkeSaQuickModeSa> quickModeSa { get; set; }

public PSVirtualNetworkGatewayConnectionIkeSaMainModeSa()
{
quickModeSa = new List<PSVirtualNetworkGatewayConnectionIkeSaQuickModeSa>();
}
}

public class PSVirtualNetworkGatewayConnectionIkeSaQuickModeSa
{
[Ps1Xml(Target = ViewControl.Table)]
public string localEndpoint { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public string remoteEndpoint { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public string encryption { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public string integrity { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public string pfsGroupId { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public uint inboundSPI { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public uint outboundSPI { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public List<string> localTrafficSelectors { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public List<string> remoteTrafficSelectors { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public ulong lifetimeKilobytes { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public ulong lifeTimeSeconds { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public bool isSaInitiator { get; set; }

[Ps1Xml(Target = ViewControl.Table)]
public UInt32 elapsedTimeInseconds { get; set; }

public PSVirtualNetworkGatewayConnectionIkeSaQuickModeSa()
{
localTrafficSelectors = new List<string>();
remoteTrafficSelectors = new List<string>();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

namespace Microsoft.Azure.Commands.Network
{
using System.Management.Automation;
using Microsoft.Azure.Commands.Network.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.Management.Network.Models;

[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VirtualNetworkGatewayConnectionIkeSa"), OutputType(typeof(PSVirtualNetworkGatewayConnectionIkeSa))]
public class GetAzVirtualNetworkGatewayConnectionIkeSaCommand : VirtualNetworkGatewayConnectionBaseCmdlet
{
[Alias("ResourceName", "ConnectionName")]
[Parameter(
ParameterSetName = "ByName",
Mandatory = false,
HelpMessage = "The virtual network gateway connection name for which IKE SAs needs to be fetched.")]
[ResourceNameCompleter("Microsoft.Network/connections", "ResourceGroupName")]
[ValidateNotNullOrEmpty]
public virtual string Name { get; set; }

[Parameter(
ParameterSetName = "ByName",
Mandatory = true,
ValueFromPipelineByPropertyName = true,
HelpMessage = "The resource group name.")]
[ResourceGroupCompleter]
[ValidateNotNullOrEmpty]
public virtual string ResourceGroupName { get; set; }

[Parameter(
ParameterSetName = "ByInputObject",
Mandatory = true,
HelpMessage = "The virtual network gateway connection object for which IKE SAs needs to be fetched.")]
[ValidateNotNullOrEmpty]
public PSVirtualNetworkGatewayConnection InputObject { get; set; }

[Parameter(
ParameterSetName = "ByResourceId",
HelpMessage = "The Azure resource ID of the Virtual Network Gateway Connection for which IKE SAs needs to be fetched.")]
[ValidateNotNullOrEmpty]
public string ResourceId { get; set; }

[Parameter(
Mandatory = false,
HelpMessage = "Run cmdlet in the background.")]
public SwitchParameter AsJob { get; set; }

public override void Execute()
{
if (ParameterSetName.Equals("ByInputObject"))
{
this.ResourceGroupName = this.InputObject.ResourceGroupName;
this.Name = this.InputObject.Name;
}
else
{
if (ParameterSetName.Equals("ByResourceId"))
{
var parsedResourceId = new ResourceIdentifier(ResourceId);
Name = parsedResourceId.ResourceName;
ResourceGroupName = parsedResourceId.ResourceGroupName;
}
}

base.Execute();

if(this.IsVirtualNetworkGatewayConnectionPresent(this.ResourceGroupName, this.Name))
{
var result = this.GetVirtualNetworkGatewayConnectionIkeSa(this.ResourceGroupName, this.Name);
WriteObject(result.ikesas, true);

}
else
{
throw new PSArgumentException(Properties.Resources.ResourceNotFound, this.Name);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.Azure.Commands.ResourceManager.Common.Tags;
using Microsoft.Azure.Management.Network;
using Microsoft.Azure.Management.Network.Models;
using Newtonsoft.Json;
using System.Net;

namespace Microsoft.Azure.Commands.Network
Expand Down Expand Up @@ -77,6 +78,19 @@ public string GetVirtualNetworkGatewayConnectionSharedKey(string resourceGroupNa
return psVirtualNetworkGatewayConnectionSharedKey;
}

public PSVirtualNetworkGatewayConnectionIkeSa GetVirtualNetworkGatewayConnectionIkeSa(string resourceGroupName, string name)
{
this.VirtualNetworkGatewayConnectionClient.GetIkeSas(resourceGroupName, name);

string response = this.VirtualNetworkGatewayConnectionClient.GetIkeSas(resourceGroupName, name);

WriteObject(response);

PSVirtualNetworkGatewayConnectionIkeSa result = JsonConvert.DeserializeObject<PSVirtualNetworkGatewayConnectionIkeSa>(response);

return result;
}

public bool IsVirtualNetworkGatewayConnectionSharedKeyPresent(string resourceGroupName, string name)
{
try
Expand Down
Loading