Skip to content

Commit 2ef7869

Browse files
utbarn-msBethanyZhouisra-fel
authored
Powershell changes for supporting ExpressRoutePort authorization (#17392)
* powershell changes for er ports authorization * adding tests and md files * making changes after arm feedback * updating changelog * resolving review comments * Update src/Network/Network/ExpressRoutePort/Authorization/RemoveAzureExpressRoutePortAuthorizationCommand.cs Co-authored-by: Beisi Zhou <[email protected]> * Update src/Network/Network/ExpressRoutePort/Authorization/RemoveAzureExpressRoutePortAuthorizationCommand.cs Co-authored-by: Beisi Zhou <[email protected]> * fixing review comments * adding local sdks * adding authkey property for circuit in network.format Co-authored-by: Beisi Zhou <[email protected]> Co-authored-by: Yeming Liu <[email protected]>
1 parent 4b5f9b3 commit 2ef7869

19 files changed

+3165
-4
lines changed

src/Network/Network.Test/ScenarioTests/ExpressRoutePortTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,12 @@ public void TestExpressRoutePortGenerateLOA()
4949
TestRunner.RunTestScript("Test-ExpressRoutePortGenerateLOA");
5050
}
5151

52+
[Fact(Skip = "No bandwidth available")]
53+
[Trait(Category.AcceptanceType, Category.CheckIn)]
54+
[Trait(Category.Owner, NrpTeamAlias.pgtm)]
55+
public void TestExpressRoutePortAuthorizationCRUD()
56+
{
57+
TestRunner.RunTestScript("Test-ExpressRoutePortAuthorizationCRUD");
58+
}
5259
}
5360
}

src/Network/Network.Test/ScenarioTests/ExpressRoutePortTests.ps1

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,3 +228,69 @@ function Test-ExpressRoutePortGenerateLOA
228228
}
229229
}
230230

231+
<#
232+
.SYNOPSIS
233+
Tests ExpressRoutePortAuthorizationCRUD.
234+
#>
235+
function Test-ExpressRoutePortAuthorizationCRUD
236+
{
237+
# Setup
238+
$rgname = Get-ResourceGroupName
239+
$rglocation = Get-ProviderLocation ResourceManagement
240+
$rname = Get-ResourceName
241+
$resourceTypeParent = "Microsoft.Network/expressRoutePorts"
242+
$location = Get-ProviderLocation $resourceTypeParent
243+
$peeringLocation = "Area51-ERDirect"
244+
$encapsulation = "QinQ"
245+
$bandwidthInGbps = 100.0
246+
$authorizationName = "testkey"
247+
248+
try
249+
{
250+
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation
251+
252+
# Create the ExpressRoutePort
253+
$expressRoutePort = New-AzExpressRoutePort -ResourceGroupName $rgname -Name $rname -Location $location -PeeringLocation $peeringLocation -Encapsulation $encapsulation -BandwidthInGbps $bandwidthInGbps
254+
255+
#verification
256+
Assert-NotNull $expressRoutePort
257+
Assert-AreEqual $rname $expressRoutePort.Name
258+
259+
# add a new authorization
260+
Get-AzExpressRoutePort -ResourceGroupName $rgname -Name $rname | Add-AzExpressRoutePortAuthorization -Name "testkey1"
261+
262+
# get the authorization
263+
$a = $expressRoutePort | Get-AzExpressRoutePortAuthorization -Name "testkey1"
264+
Assert-AreEqual "testkey1" $a.Name
265+
266+
# add another new authorization
267+
Get-AzExpressRoutePort -ResourceGroupName $rgname -Name $rname | Add-AzExpressRoutePortAuthorization -Name "testkey2"
268+
269+
$a = $expressRoutePort | Get-AzExpressRoutePortAuthorization -Name "testkey2"
270+
Assert-AreEqual "testkey2" $a.Name
271+
272+
# list authorizations
273+
$listAuthorization = $expressRoutePort | Get-AzExpressRoutePortAuthorization
274+
Assert-AreEqual 2 @($listAuthorization).Count
275+
276+
# delete an authorization
277+
Get-AzExpressRoutePort -ResourceGroupName $rgname -Name $rname | Remove-AzExpressRoutePortAuthorization -Name "testkey1" -Force
278+
279+
# list authorizations again
280+
$listAuthorization = $expressRoutePort | Get-AzExpressRoutePortAuthorization
281+
Assert-AreEqual 1 @($listAuthorization).Count
282+
283+
# Delete ExpressRoutePort
284+
$removeExpressRoutePort = Remove-AzExpressRoutePort -ResourceGroupName $rgname -Name $rname -PassThru -Force
285+
Assert-AreEqual $true $removeExpressRoutePort
286+
287+
$list = Get-AzExpressRoutePort -ResourceGroupName $rgname
288+
Assert-AreEqual 0 @($list).Count
289+
}
290+
finally
291+
{
292+
# Cleanup
293+
Clean-ResourceGroup $rgname
294+
}
295+
}
296+

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.ExpressRoutePortTests/TestExpressRoutePortAuthorizationCRUD.json

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

src/Network/Network/Az.Network.psd1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
255255
'Get-AzExpressRoutePortIdentity', 'New-AzExpressRoutePortIdentity',
256256
'Remove-AzExpressRoutePortIdentity',
257257
'Set-AzExpressRoutePortIdentity',
258+
'Add-AzExpressRoutePortAuthorization',
259+
'Get-AzExpressRoutePortAuthorization',
260+
'Remove-AzExpressRoutePortAuthorization',
258261
'Get-AzEffectiveNetworkSecurityGroup', 'Get-AzEffectiveRouteTable',
259262
'Add-AzNetworkInterfaceIpConfig', 'Get-AzNetworkInterfaceIpConfig',
260263
'New-AzNetworkInterfaceIpConfig',

src/Network/Network/ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
--->
2020

2121
## Upcoming Release
22+
* Added new cmdlets to create/manage authorization objects for ExpressRoutePort:
23+
- `Add-AzExpressRoutePortAuthorization`
24+
- `Get-AzExpressRoutePortAuthorization`
25+
- `Remove-AzExpressRoutePortAuthorization`
26+
* Added option parameter `AuthorizationKey` to cmdlet `New-AzExpressRouteCircuit` to allow creating ExpressRoute Circuit on a ExpressRoutePort with a different owner.
2227
* Fixed `ArgumentNullException` in `Add-AzureRmRouteConfig` when `RouteTable.Routes` is null.
2328
* Fix bug that can't display CustomIpPrefix in PublicIpPrefix.
2429

src/Network/Network/Common/NetworkResourceManagerProfile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,10 +792,12 @@ private static void Initialize()
792792
// CNM to MNM
793793
cfg.CreateMap<CNM.PSExpressRoutePort, MNM.ExpressRoutePort>();
794794
cfg.CreateMap<CNM.PSExpressRouteLink, MNM.ExpressRouteLink>();
795+
cfg.CreateMap<CNM.PSExpressRoutePortAuthorization, MNM.ExpressRoutePortAuthorization>();
795796

796797
// MNM to CNM
797798
cfg.CreateMap<MNM.ExpressRoutePort, CNM.PSExpressRoutePort>();
798799
cfg.CreateMap<MNM.ExpressRouteLink, CNM.PSExpressRouteLink>();
800+
cfg.CreateMap<MNM.ExpressRoutePortAuthorization, CNM.PSExpressRoutePortAuthorization>();
799801

800802
// ExpressRouteCircuit
801803
// CNM to MNM

src/Network/Network/ExpressRouteCircuit/NewAzureExpressRouteCircuitCommand.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ public class NewAzureExpressRouteCircuitCommand : ExpressRouteCircuitBaseCmdlet
104104
ValueFromPipelineByPropertyName = true)]
105105
public double BandwidthInGbps { get; set; }
106106

107+
[Parameter(
108+
ParameterSetName = "ExpressRoutePort",
109+
Mandatory = false,
110+
ValueFromPipelineByPropertyName = true)]
111+
public string AuthorizationKey { get; set; }
112+
107113
[Parameter(
108114
Mandatory = false,
109115
ValueFromPipelineByPropertyName = true)]
@@ -161,7 +167,7 @@ private PSExpressRouteCircuit CreateExpressRouteCircuit()
161167
circuit.Name = this.Name;
162168
circuit.ResourceGroupName = this.ResourceGroupName;
163169
circuit.Location = this.Location;
164-
170+
circuit.AuthorizationKey = this.AuthorizationKey;
165171
// Construct sku
166172
if (!string.IsNullOrEmpty(this.SkuTier))
167173
{
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
using Microsoft.Azure.Commands.Network.Models;
16+
using System;
17+
using System.Linq;
18+
using System.Management.Automation;
19+
using System.Net;
20+
using MNM = Microsoft.Azure.Management.Network.Models;
21+
22+
namespace Microsoft.Azure.Commands.Network
23+
{
24+
[Cmdlet("Add", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ExpressRoutePortAuthorization", SupportsShouldProcess = true), OutputType(typeof(PSExpressRoutePortAuthorization))]
25+
public class AddAzureExpressRoutePortAuthorizationCommand : NetworkBaseCmdlet
26+
{
27+
[Parameter(
28+
Mandatory = true,
29+
HelpMessage = "The name of the Authorization")]
30+
[ValidateNotNullOrEmpty]
31+
public string Name { get; set; }
32+
33+
[Parameter(
34+
Mandatory = true,
35+
ValueFromPipeline = true,
36+
HelpMessage = "The ExpressRoutePort Object")]
37+
public PSExpressRoutePort ExpressRoutePortObject { get; set; }
38+
39+
public override void Execute()
40+
{
41+
base.Execute();
42+
var present = true;
43+
44+
try
45+
{
46+
this.NetworkClient.NetworkManagementClient.ExpressRoutePortAuthorizations.GetWithHttpMessagesAsync(this.ExpressRoutePortObject.ResourceGroupName, this.ExpressRoutePortObject.Name, this.Name).GetAwaiter().GetResult();
47+
}
48+
catch (Microsoft.Rest.Azure.CloudException exception)
49+
{
50+
if (exception.Response.StatusCode == HttpStatusCode.NotFound)
51+
{
52+
// Resource is not present
53+
present = false;
54+
}
55+
else
56+
{
57+
throw;
58+
}
59+
}
60+
61+
if (present)
62+
{
63+
throw new ArgumentException("Authorization with the specified name already exists");
64+
}
65+
66+
var authorizationParameters = new MNM.ExpressRoutePortAuthorization();
67+
authorizationParameters.Name = this.Name;
68+
69+
// Execute the PUT ExpressRoutePortAuthorizations call
70+
var putExpressRoutePortAuthorization = this.NetworkClient.NetworkManagementClient.ExpressRoutePortAuthorizations.CreateOrUpdateWithHttpMessagesAsync(this.ExpressRoutePortObject.ResourceGroupName, this.ExpressRoutePortObject.Name, this.Name, authorizationParameters).GetAwaiter().GetResult().Body;
71+
var psExpressRoutePortAuthorization = NetworkResourceManagerProfile.Mapper.Map<PSExpressRoutePortAuthorization>(putExpressRoutePortAuthorization);
72+
WriteObject(psExpressRoutePortAuthorization, true);
73+
}
74+
}
75+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
using Microsoft.Azure.Commands.Network.Models;
16+
using System.Collections.Generic;
17+
using System.Linq;
18+
using System.Management.Automation;
19+
20+
namespace Microsoft.Azure.Commands.Network
21+
{
22+
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ExpressRoutePortAuthorization"), OutputType(typeof(PSExpressRoutePortAuthorization))]
23+
public class GetAzureExpressRoutePortAuthorizationCommand : NetworkBaseCmdlet
24+
{
25+
[Parameter(
26+
Mandatory = false,
27+
HelpMessage = "The name of the Authorization")]
28+
[ValidateNotNullOrEmpty]
29+
public string Name { get; set; }
30+
31+
[Parameter(
32+
Mandatory = true,
33+
ValueFromPipeline = true,
34+
HelpMessage = "The ExpressRoutePort Object")]
35+
public PSExpressRoutePort ExpressRoutePortObject { get; set; }
36+
37+
public override void Execute()
38+
{
39+
base.Execute();
40+
if (!string.IsNullOrEmpty(this.Name))
41+
{
42+
var getExpressRoutePortAuthorization = this.NetworkClient.NetworkManagementClient.ExpressRoutePortAuthorizations.GetWithHttpMessagesAsync(this.ExpressRoutePortObject.ResourceGroupName, this.ExpressRoutePortObject.Name, this.Name).GetAwaiter().GetResult().Body;
43+
var psExpressRoutePortAuthorization = NetworkResourceManagerProfile.Mapper.Map<PSExpressRoutePortAuthorization>(getExpressRoutePortAuthorization);
44+
WriteObject(psExpressRoutePortAuthorization);
45+
}
46+
else
47+
{
48+
49+
var listExpressRoutePortAuthorizations = this.NetworkClient.NetworkManagementClient.ExpressRoutePortAuthorizations.ListWithHttpMessagesAsync(this.ExpressRoutePortObject.ResourceGroupName, this.ExpressRoutePortObject.Name).GetAwaiter().GetResult().Body;
50+
var psExpressRoutePortAuthorizations = new List<PSExpressRoutePortAuthorization>();
51+
if (listExpressRoutePortAuthorizations != null)
52+
{
53+
psExpressRoutePortAuthorizations = NetworkResourceManagerProfile.Mapper.Map<List<PSExpressRoutePortAuthorization>>(listExpressRoutePortAuthorizations);
54+
}
55+
56+
WriteObject(psExpressRoutePortAuthorizations, true);
57+
}
58+
}
59+
}
60+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
using Microsoft.Azure.Commands.Network.Models;
16+
using System.Linq;
17+
using System.Management.Automation;
18+
19+
20+
namespace Microsoft.Azure.Commands.Network
21+
{
22+
[Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ExpressRoutePortAuthorization", SupportsShouldProcess = true), OutputType(typeof(bool))]
23+
public class RemoveAzureExpressRoutePortAuthorizationCommand : NetworkBaseCmdlet
24+
{
25+
[Parameter(
26+
Mandatory = true,
27+
HelpMessage = "The name of the Authorization")]
28+
[ValidateNotNullOrEmpty]
29+
public string Name { get; set; }
30+
31+
[Parameter(
32+
Mandatory = true,
33+
ValueFromPipeline = true,
34+
HelpMessage = "The ExpressRoutePort Object")]
35+
public PSExpressRoutePort ExpressRoutePortObject { get; set; }
36+
37+
[Parameter(
38+
Mandatory = false,
39+
HelpMessage = "Do not ask for confirmation if you want to delete resource")]
40+
public SwitchParameter Force { get; set; }
41+
42+
[Parameter(Mandatory = false)]
43+
public SwitchParameter PassThru { get; set; }
44+
45+
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
46+
public SwitchParameter AsJob { get; set; }
47+
48+
public override void Execute()
49+
{
50+
base.Execute();
51+
52+
ConfirmAction(
53+
Force.IsPresent,
54+
string.Format(Properties.Resources.RemovingResource, Name),
55+
Properties.Resources.RemoveResourceMessage,
56+
Name,
57+
() =>
58+
{
59+
this.NetworkClient.NetworkManagementClient.ExpressRoutePortAuthorizations.DeleteWithHttpMessagesAsync(ExpressRoutePortObject.ResourceGroupName, ExpressRoutePortObject.Name, Name).GetAwaiter().GetResult();
60+
if (PassThru.IsPresent)
61+
{
62+
WriteObject(true);
63+
}
64+
});
65+
}
66+
}
67+
}

src/Network/Network/ExpressRoutePort/NewAzureRMExpressRoutePortCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public override void Execute()
131131
BandwidthInGbps = this.BandwidthInGbps,
132132
Encapsulation = this.Encapsulation,
133133
Location = this.Location,
134-
Links = this.Link?.ToList(),
134+
Links = this.Link?.ToList()
135135
};
136136

137137
if (this.Identity != null)

src/Network/Network/Generated/Models/PSExpressRouteCircuit.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public partial class PSExpressRouteCircuit : PSTopLevelResource
6060
public double? BandwidthInGbps { get; set; }
6161
[Ps1Xml(Target = ViewControl.Table)]
6262
public int? Stag { get; set; }
63+
[Ps1Xml(Target = ViewControl.Table)]
64+
public string AuthorizationKey { get; set; }
6365

6466
[JsonIgnore]
6567
public string SkuText

0 commit comments

Comments
 (0)