Skip to content

Commit 854c80f

Browse files
committed
Incorporating review comments
1 parent 0c7a77f commit 854c80f

8 files changed

+90
-80
lines changed

src/ResourceManager/Network/Commands.Network.Test/ScenarioTests/VirtualNetworkGatewayTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ public void VirtualNetworkGatewayRouteApiTest()
6262
[Fact()]
6363
public void TestVirtualNetworkGatewayP2SVpnProfile()
6464
{
65-
NetworkResourcesController.NewInstance.RunPsTest(string.Format("Test-VirtualNetworkGatewayGenerateVpnProfile -baseDir '{0}'", AppDomain.CurrentDomain.BaseDirectory));
65+
NetworkResourcesController.NewInstance.RunPsTest(string.Format(
66+
"Test-VirtualNetworkGatewayGenerateVpnProfile -baseDir '{0}'", AppDomain.CurrentDomain.BaseDirectory));
67+
}
6668

6769
[Fact]
6870
[Trait(Category.AcceptanceType, Category.CheckIn)]

src/ResourceManager/Network/Commands.Network/VirtualNetworkGateway/GetAzureVpnClientConfigurationCommand.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
namespace Microsoft.Azure.Commands.Network.VirtualNetworkGateway
2525
{
26-
[Cmdlet(VerbsCommon.Get, "AzureRmVpnClientConfiguration"), OutputType(typeof(MNM.PSVpnProfile))]
26+
[Cmdlet(VerbsCommon.Get, "AzureRmVpnClientConfiguration", SupportsShouldProcess = true), OutputType(typeof(MNM.PSVpnProfile))]
2727
public class GetAzureVpnClientConfigurationCommand : VirtualNetworkGatewayBaseCmdlet
2828
{
2929
[Alias("ResourceName")]
@@ -49,20 +49,23 @@ public override void Execute()
4949
// Just get the package URL if the package exists
5050
// There may be a required Json serialize for the package URL to conform to REST-API
5151
// The try-catch below handles the case till the change is made and deployed to PROD
52-
string serializedPackageUrl = this.NetworkClient.GetVpnProfilePackageUrl(this.ResourceGroupName, this.Name);
53-
string packageUrl = string.Empty;
54-
try
52+
if (ShouldProcess("AzureRmVpnClientConfiguration", VerbsCommon.Get))
5553
{
56-
packageUrl = JsonConvert.DeserializeObject<string>(serializedPackageUrl);
57-
}
58-
catch (Exception e)
59-
{
60-
Console.WriteLine(e.Message);
61-
packageUrl = serializedPackageUrl;
62-
}
54+
string serializedPackageUrl = this.NetworkClient.GetVpnProfilePackageUrl(this.ResourceGroupName, this.Name);
55+
string packageUrl = string.Empty;
56+
try
57+
{
58+
packageUrl = JsonConvert.DeserializeObject<string>(serializedPackageUrl);
59+
}
60+
catch (Exception e)
61+
{
62+
Console.WriteLine(e.Message);
63+
packageUrl = serializedPackageUrl;
64+
}
6365

64-
MNM.PSVpnProfile vpnProfile = new MNM.PSVpnProfile() { VpnProfileSASUrl = packageUrl };
65-
WriteObject(vpnProfile);
66+
MNM.PSVpnProfile vpnProfile = new MNM.PSVpnProfile() { VpnProfileSASUrl = packageUrl };
67+
WriteObject(vpnProfile);
68+
}
6669
}
6770
}
6871
}

src/ResourceManager/Network/Commands.Network/VirtualNetworkGateway/NewAzureVirtualNetworkGatewayCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace Microsoft.Azure.Commands.Network
3030
[Cmdlet(VerbsCommon.New,
3131
"AzureRmVirtualNetworkGateway",
3232
SupportsShouldProcess = true,
33-
DefaultParameterSetName = VirtualNetworkGatewayParameterSets.Empty),
33+
DefaultParameterSetName = VirtualNetworkGatewayParameterSets.Default),
3434
OutputType(typeof(PSVirtualNetworkGateway))]
3535
public class NewAzureVirtualNetworkGatewayCommand : VirtualNetworkGatewayBaseCmdlet
3636
{
@@ -179,7 +179,7 @@ public class NewAzureVirtualNetworkGatewayCommand : VirtualNetworkGatewayBaseCmd
179179
[Parameter(
180180
Mandatory = false,
181181
ValueFromPipelineByPropertyName = true,
182-
ParameterSetName = VirtualNetworkGatewayParameterSets.Empty,
182+
ParameterSetName = VirtualNetworkGatewayParameterSets.Default,
183183
HelpMessage = "P2S External Radius server secret.")]
184184
[Parameter(
185185
Mandatory = true,

src/ResourceManager/Network/Commands.Network/VirtualNetworkGateway/NewAzureVpnClientConfigurationCommand.cs

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
namespace Microsoft.Azure.Commands.Network
2626
{
27-
[Cmdlet(VerbsCommon.New, "AzureRmVpnClientConfiguration"), OutputType(typeof(PSVpnProfile))]
27+
[Cmdlet(VerbsCommon.New, "AzureRmVpnClientConfiguration", SupportsShouldProcess = true), OutputType(typeof(PSVpnProfile))]
2828
public class NewAzureVpnClientConfigurationCommand : VirtualNetworkGatewayBaseCmdlet
2929
{
3030
[Alias("ResourceName")]
@@ -77,84 +77,87 @@ public class NewAzureVpnClientConfigurationCommand : VirtualNetworkGatewayBaseCm
7777
public override void Execute()
7878
{
7979
base.Execute();
80-
81-
PSVpnClientParameters vpnClientParams = new PSVpnClientParameters();
8280

83-
vpnClientParams.ProcessorArchitecture = string.IsNullOrWhiteSpace(this.ProcessorArchitecture) ?
84-
MNM.ProcessorArchitecture.Amd64.ToString() :
85-
this.ProcessorArchitecture;
81+
if (ShouldProcess("AzureVpnClientConfiguration", VerbsCommon.New))
82+
{
83+
PSVpnClientParameters vpnClientParams = new PSVpnClientParameters();
8684

87-
vpnClientParams.AuthenticationMethod = string.IsNullOrWhiteSpace(this.AuthenticationMethod)
88-
? MNM.AuthenticationMethod.EAPTLS.ToString()
89-
: this.AuthenticationMethod;
85+
vpnClientParams.ProcessorArchitecture = string.IsNullOrWhiteSpace(this.ProcessorArchitecture) ?
86+
MNM.ProcessorArchitecture.Amd64.ToString() :
87+
this.ProcessorArchitecture;
9088

91-
// Read the radius server root certificate if present
92-
if (!string.IsNullOrWhiteSpace(this.RadiusRootCertificateFile))
93-
{
94-
if (File.Exists(this.RadiusRootCertificateFile))
89+
vpnClientParams.AuthenticationMethod = string.IsNullOrWhiteSpace(this.AuthenticationMethod)
90+
? MNM.AuthenticationMethod.EAPTLS.ToString()
91+
: this.AuthenticationMethod;
92+
93+
// Read the radius server root certificate if present
94+
if (!string.IsNullOrWhiteSpace(this.RadiusRootCertificateFile))
9595
{
96-
try
96+
if (File.Exists(this.RadiusRootCertificateFile))
9797
{
98-
X509Certificate2 radiusRootCertificate = new X509Certificate2(this.RadiusRootCertificateFile);
99-
vpnClientParams.RadiusServerAuthCertificate = Convert.ToBase64String(radiusRootCertificate.Export(X509ContentType.Cert));
98+
try
99+
{
100+
X509Certificate2 radiusRootCertificate = new X509Certificate2(this.RadiusRootCertificateFile);
101+
vpnClientParams.RadiusServerAuthCertificate = Convert.ToBase64String(radiusRootCertificate.Export(X509ContentType.Cert));
102+
}
103+
catch (Exception)
104+
{
105+
WriteWarning("Invalid radius root certificate specified at path " + this.RadiusRootCertificateFile);
106+
}
100107
}
101-
catch (Exception)
108+
else
102109
{
103-
WriteWarning("Invalid radius root certificate specified at path " + this.RadiusRootCertificateFile);
110+
WriteWarning("Cannot find radius root certificate with path " + this.RadiusRootCertificateFile);
104111
}
105112
}
106-
else
107-
{
108-
WriteWarning("Cannot find radius root certificate with path " + this.RadiusRootCertificateFile);
109-
}
110-
}
111113

112-
// Read the radius server root certificate if present
113-
if (this.ClientRootCertificateFileList != null)
114-
{
115-
foreach (string clientRootCertPath in this.ClientRootCertificateFileList)
114+
// Read the radius server root certificate if present
115+
if (this.ClientRootCertificateFileList != null)
116116
{
117-
vpnClientParams.ClientRootCertificates = new List<string>();
118-
if (File.Exists(clientRootCertPath))
117+
foreach (string clientRootCertPath in this.ClientRootCertificateFileList)
119118
{
120-
try
119+
vpnClientParams.ClientRootCertificates = new List<string>();
120+
if (File.Exists(clientRootCertPath))
121121
{
122-
X509Certificate2 clientRootCertificate = new X509Certificate2(clientRootCertPath);
123-
vpnClientParams.ClientRootCertificates.Add(
124-
Convert.ToBase64String(clientRootCertificate.Export(X509ContentType.Cert)));
122+
try
123+
{
124+
X509Certificate2 clientRootCertificate = new X509Certificate2(clientRootCertPath);
125+
vpnClientParams.ClientRootCertificates.Add(
126+
Convert.ToBase64String(clientRootCertificate.Export(X509ContentType.Cert)));
127+
}
128+
catch (Exception)
129+
{
130+
WriteWarning("Invalid cer file specified for client root certificate with path " +
131+
clientRootCertPath);
132+
}
125133
}
126-
catch (Exception)
134+
else
127135
{
128-
WriteWarning("Invalid cer file specified for client root certificate with path " +
136+
WriteWarning("Cannot find client root certificate with path " +
129137
clientRootCertPath);
130138
}
131139
}
132-
else
133-
{
134-
WriteWarning("Cannot find client root certificate with path " +
135-
clientRootCertPath);
136-
}
137140
}
138-
}
139141

140-
var vnetVpnClientParametersModel = Mapper.Map<MNM.VpnClientParameters>(vpnClientParams);
142+
var vnetVpnClientParametersModel = Mapper.Map<MNM.VpnClientParameters>(vpnClientParams);
141143

142-
// There may be a required Json serialize for the package URL to conform to REST-API
143-
// The try-catch below handles the case till the change is made and deployed to PROD
144-
string serializedPackageUrl = this.NetworkClient.GenerateVpnProfile(this.ResourceGroupName, this.Name, vnetVpnClientParametersModel);
145-
string packageUrl = string.Empty;
146-
try
147-
{
148-
packageUrl = JsonConvert.DeserializeObject<string>(serializedPackageUrl);
149-
}
150-
catch (Exception e)
151-
{
152-
Console.WriteLine(e.Message);
153-
packageUrl = serializedPackageUrl;
154-
}
144+
// There may be a required Json serialize for the package URL to conform to REST-API
145+
// The try-catch below handles the case till the change is made and deployed to PROD
146+
string serializedPackageUrl = this.NetworkClient.GenerateVpnProfile(this.ResourceGroupName, this.Name, vnetVpnClientParametersModel);
147+
string packageUrl = string.Empty;
148+
try
149+
{
150+
packageUrl = JsonConvert.DeserializeObject<string>(serializedPackageUrl);
151+
}
152+
catch (Exception e)
153+
{
154+
Console.WriteLine(e.Message);
155+
packageUrl = serializedPackageUrl;
156+
}
155157

156-
PSVpnProfile vpnProfile = new PSVpnProfile() {VpnProfileSASUrl = packageUrl};
157-
WriteObject(vpnProfile);
158+
PSVpnProfile vpnProfile = new PSVpnProfile() { VpnProfileSASUrl = packageUrl };
159+
WriteObject(vpnProfile);
160+
}
158161
}
159162
}
160163
}

src/ResourceManager/Network/Commands.Network/VirtualNetworkGateway/SetAzureVirtualNetworkGatewayVpnClientConfig.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace Microsoft.Azure.Commands.Network
2828
{
2929
[Cmdlet(VerbsCommon.Set,
3030
"AzureRmVirtualNetworkGatewayVpnClientConfig",
31-
DefaultParameterSetName = VirtualNetworkGatewayParameterSets.Empty),
31+
DefaultParameterSetName = VirtualNetworkGatewayParameterSets.Default),
3232
OutputType(typeof(PSVirtualNetworkGateway))]
3333
public class SetAzureVirtualNetworkGatewayVpnClientConfigCommand : VirtualNetworkGatewayBaseCmdlet
3434
{
@@ -57,7 +57,7 @@ public class SetAzureVirtualNetworkGatewayVpnClientConfigCommand : VirtualNetwor
5757
[Parameter(
5858
Mandatory = false,
5959
ValueFromPipelineByPropertyName = true,
60-
ParameterSetName = VirtualNetworkGatewayParameterSets.Empty,
60+
ParameterSetName = VirtualNetworkGatewayParameterSets.Default,
6161
HelpMessage = "P2S External Radius server secret.")]
6262
[Parameter(
6363
Mandatory = true,

src/ResourceManager/Network/Commands.Network/VirtualNetworkGateway/UpdateAzureVirtualNetworkGatewayCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace Microsoft.Azure.Commands.Network
2828
{
2929
[Cmdlet(VerbsCommon.Set,
3030
"AzureRmVirtualNetworkGateway",
31-
DefaultParameterSetName = VirtualNetworkGatewayParameterSets.Empty),
31+
DefaultParameterSetName = VirtualNetworkGatewayParameterSets.Default),
3232
OutputType(typeof(PSVirtualNetworkGateway))]
3333
public class SetAzureVirtualNetworkGatewayCommand : VirtualNetworkGatewayBaseCmdlet
3434
{
@@ -121,7 +121,7 @@ public class SetAzureVirtualNetworkGatewayCommand : VirtualNetworkGatewayBaseCmd
121121
[Parameter(
122122
Mandatory = false,
123123
ValueFromPipelineByPropertyName = true,
124-
ParameterSetName = VirtualNetworkGatewayParameterSets.Empty,
124+
ParameterSetName = VirtualNetworkGatewayParameterSets.Default,
125125
HelpMessage = "P2S External Radius server secret.")]
126126
[Parameter(
127127
Mandatory = true,

src/ResourceManager/Network/Commands.Network/VirtualNetworkGateway/VirtualNetworkGatewayParameterSets.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Microsoft.Azure.Commands.Network.VirtualNetworkGateway
88
{
99
public class VirtualNetworkGatewayParameterSets
1010
{
11-
public const string Empty = @"Empty";
11+
public const string Default = @"Default";
1212

1313
public const string RadiusServerConfiguration = @"RadiusServerConfiguration";
1414
}

src/ResourceManager/Network/Commands.Network/help/New-AzureRmVirtualNetworkGateway.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ Accept wildcard characters: False
255255
```
256256
257257
### -RadiusServerAddress
258-
P2S External Radius server address.```yaml
258+
P2S External Radius server address.
259+
```yaml
259260
Type: String
260261
Parameter Sets: RadiusServerConfiguration
261262
Aliases:
@@ -268,7 +269,8 @@ Accept wildcard characters: False
268269
```
269270
270271
### -RadiusServerSecret
271-
P2S External Radius server secret.```yaml
272+
P2S External Radius server secret.
273+
```yaml
272274
Type: SecureString
273275
Parameter Sets: Empty
274276
Aliases:

0 commit comments

Comments
 (0)