|
24 | 24 |
|
25 | 25 | namespace Microsoft.Azure.Commands.Network
|
26 | 26 | {
|
27 |
| - [Cmdlet(VerbsCommon.New, "AzureRmVpnClientConfiguration"), OutputType(typeof(PSVpnProfile))] |
| 27 | + [Cmdlet(VerbsCommon.New, "AzureRmVpnClientConfiguration", SupportsShouldProcess = true), OutputType(typeof(PSVpnProfile))] |
28 | 28 | public class NewAzureVpnClientConfigurationCommand : VirtualNetworkGatewayBaseCmdlet
|
29 | 29 | {
|
30 | 30 | [Alias("ResourceName")]
|
@@ -77,84 +77,87 @@ public class NewAzureVpnClientConfigurationCommand : VirtualNetworkGatewayBaseCm
|
77 | 77 | public override void Execute()
|
78 | 78 | {
|
79 | 79 | base.Execute();
|
80 |
| - |
81 |
| - PSVpnClientParameters vpnClientParams = new PSVpnClientParameters(); |
82 | 80 |
|
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(); |
86 | 84 |
|
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; |
90 | 88 |
|
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)) |
95 | 95 | {
|
96 |
| - try |
| 96 | + if (File.Exists(this.RadiusRootCertificateFile)) |
97 | 97 | {
|
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 | + } |
100 | 107 | }
|
101 |
| - catch (Exception) |
| 108 | + else |
102 | 109 | {
|
103 |
| - WriteWarning("Invalid radius root certificate specified at path " + this.RadiusRootCertificateFile); |
| 110 | + WriteWarning("Cannot find radius root certificate with path " + this.RadiusRootCertificateFile); |
104 | 111 | }
|
105 | 112 | }
|
106 |
| - else |
107 |
| - { |
108 |
| - WriteWarning("Cannot find radius root certificate with path " + this.RadiusRootCertificateFile); |
109 |
| - } |
110 |
| - } |
111 | 113 |
|
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) |
116 | 116 | {
|
117 |
| - vpnClientParams.ClientRootCertificates = new List<string>(); |
118 |
| - if (File.Exists(clientRootCertPath)) |
| 117 | + foreach (string clientRootCertPath in this.ClientRootCertificateFileList) |
119 | 118 | {
|
120 |
| - try |
| 119 | + vpnClientParams.ClientRootCertificates = new List<string>(); |
| 120 | + if (File.Exists(clientRootCertPath)) |
121 | 121 | {
|
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 | + } |
125 | 133 | }
|
126 |
| - catch (Exception) |
| 134 | + else |
127 | 135 | {
|
128 |
| - WriteWarning("Invalid cer file specified for client root certificate with path " + |
| 136 | + WriteWarning("Cannot find client root certificate with path " + |
129 | 137 | clientRootCertPath);
|
130 | 138 | }
|
131 | 139 | }
|
132 |
| - else |
133 |
| - { |
134 |
| - WriteWarning("Cannot find client root certificate with path " + |
135 |
| - clientRootCertPath); |
136 |
| - } |
137 | 140 | }
|
138 |
| - } |
139 | 141 |
|
140 |
| - var vnetVpnClientParametersModel = Mapper.Map<MNM.VpnClientParameters>(vpnClientParams); |
| 142 | + var vnetVpnClientParametersModel = Mapper.Map<MNM.VpnClientParameters>(vpnClientParams); |
141 | 143 |
|
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 | + } |
155 | 157 |
|
156 |
| - PSVpnProfile vpnProfile = new PSVpnProfile() {VpnProfileSASUrl = packageUrl}; |
157 |
| - WriteObject(vpnProfile); |
| 158 | + PSVpnProfile vpnProfile = new PSVpnProfile() { VpnProfileSASUrl = packageUrl }; |
| 159 | + WriteObject(vpnProfile); |
| 160 | + } |
158 | 161 | }
|
159 | 162 | }
|
160 | 163 | }
|
|
0 commit comments