Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,12 @@ public void TestExpressRoutePortGenerateLOA()
TestRunner.RunTestScript("Test-ExpressRoutePortGenerateLOA");
}

[Fact(Skip = "No bandwidth available")]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.pgtm)]
public void TestExpressRoutePortAuthorizationCRUD()
{
TestRunner.RunTestScript("Test-ExpressRoutePortAuthorizationCRUD");
}
}
}
66 changes: 66 additions & 0 deletions src/Network/Network.Test/ScenarioTests/ExpressRoutePortTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,69 @@ function Test-ExpressRoutePortGenerateLOA
}
}

<#
.SYNOPSIS
Tests ExpressRoutePortAuthorizationCRUD.
#>
function Test-ExpressRoutePortAuthorizationCRUD
{
# Setup
$rgname = Get-ResourceGroupName
$rglocation = Get-ProviderLocation ResourceManagement
$rname = Get-ResourceName
$resourceTypeParent = "Microsoft.Network/expressRoutePorts"
$location = Get-ProviderLocation $resourceTypeParent
$peeringLocation = "Area51-ERDirect"
$encapsulation = "QinQ"
$bandwidthInGbps = 100.0
$authorizationName = "testkey"

try
{
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation

# Create the ExpressRoutePort
$expressRoutePort = New-AzExpressRoutePort -ResourceGroupName $rgname -Name $rname -Location $location -PeeringLocation $peeringLocation -Encapsulation $encapsulation -BandwidthInGbps $bandwidthInGbps

#verification
Assert-NotNull $expressRoutePort
Assert-AreEqual $rname $expressRoutePort.Name

# add a new authorization
Get-AzExpressRoutePort -ResourceGroupName $rgname -Name $rname | Add-AzExpressRoutePortAuthorization -Name "testkey1"

# get the authorization
$a = $expressRoutePort | Get-AzExpressRoutePortAuthorization -Name "testkey1"
Assert-AreEqual "testkey1" $a.Name

# add another new authorization
Get-AzExpressRoutePort -ResourceGroupName $rgname -Name $rname | Add-AzExpressRoutePortAuthorization -Name "testkey2"

$a = $expressRoutePort | Get-AzExpressRoutePortAuthorization -Name "testkey2"
Assert-AreEqual "testkey2" $a.Name

# list authorizations
$listAuthorization = $expressRoutePort | Get-AzExpressRoutePortAuthorization
Assert-AreEqual 2 @($listAuthorization).Count

# delete an authorization
Get-AzExpressRoutePort -ResourceGroupName $rgname -Name $rname | Remove-AzExpressRoutePortAuthorization -Name "testkey1"

# list authorizations again
$listAuthorization = $expressRoutePort | Get-AzExpressRoutePortAuthorization
Assert-AreEqual 1 @($listAuthorization).Count

# Delete ExpressRoutePort
$removeExpressRoutePort = Remove-AzExpressRoutePort -ResourceGroupName $rgname -Name $rname -PassThru -Force
Assert-AreEqual $true $removeExpressRoutePort

$list = Get-AzExpressRoutePort -ResourceGroupName $rgname
Assert-AreEqual 0 @($list).Count
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/Network/Network/Az.Network.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate',
'Get-AzExpressRoutePortIdentity', 'New-AzExpressRoutePortIdentity',
'Remove-AzExpressRoutePortIdentity',
'Set-AzExpressRoutePortIdentity',
'Add-AzExpressRoutePortAuthorization',
'Get-AzExpressRoutePortAuthorization',
'Remove-AzExpressRoutePortAuthorization',
'Get-AzEffectiveNetworkSecurityGroup', 'Get-AzEffectiveRouteTable',
'Add-AzNetworkInterfaceIpConfig', 'Get-AzNetworkInterfaceIpConfig',
'New-AzNetworkInterfaceIpConfig',
Expand Down
6 changes: 6 additions & 0 deletions src/Network/Network/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
--->

## Upcoming Release
* Added new cmdlets to create/manage authorization objects for ExpressRoutePort:
- `Add-AzExpressRoutePortAuthorization`
- `Get-AzExpressRoutePortAuthorization`
- `Remove-AzExpressRoutePortAuthorization`
* Added option parameter `AuthorizationKey` to cmdlet `New-AzExpressRouteCircuit` to allow creating
ExpressRoute Circuit on a ExpressRoutePort with a different owner.
Comment thread
utbarn-ms marked this conversation as resolved.
Outdated

## Version 4.14.0
* Used case-insensitive comparison for ResourceId (Set/New-NetworkWatcherFlowLog)
Expand Down
2 changes: 2 additions & 0 deletions src/Network/Network/Common/NetworkResourceManagerProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -776,10 +776,12 @@ private static void Initialize()
// CNM to MNM
cfg.CreateMap<CNM.PSExpressRoutePort, MNM.ExpressRoutePort>();
cfg.CreateMap<CNM.PSExpressRouteLink, MNM.ExpressRouteLink>();
cfg.CreateMap<CNM.PSExpressRoutePortAuthorization, MNM.ExpressRoutePortAuthorization>();

// MNM to CNM
cfg.CreateMap<MNM.ExpressRoutePort, CNM.PSExpressRoutePort>();
cfg.CreateMap<MNM.ExpressRouteLink, CNM.PSExpressRouteLink>();
cfg.CreateMap<MNM.ExpressRoutePortAuthorization, CNM.PSExpressRoutePortAuthorization>();

// ExpressRouteCircuit
// CNM to MNM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public class NewAzureExpressRouteCircuitCommand : ExpressRouteCircuitBaseCmdlet
ValueFromPipelineByPropertyName = true)]
public double BandwidthInGbps { get; set; }

[Parameter(
ParameterSetName = "ExpressRoutePort",
Mandatory = false,
ValueFromPipelineByPropertyName = true)]
public string AuthorizationKey { get; set; }
Comment thread
utbarn-ms marked this conversation as resolved.

[Parameter(
Mandatory = false,
ValueFromPipelineByPropertyName = true)]
Expand Down Expand Up @@ -161,7 +167,7 @@ private PSExpressRouteCircuit CreateExpressRouteCircuit()
circuit.Name = this.Name;
circuit.ResourceGroupName = this.ResourceGroupName;
circuit.Location = this.Location;

circuit.AuthorizationKey = this.AuthorizationKey;
// Construct sku
if (!string.IsNullOrEmpty(this.SkuTier))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// ----------------------------------------------------------------------------------
//
// 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.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Network.Models;
using System;
using System.Linq;
using System.Management.Automation;
using System.Net;
using MNM = Microsoft.Azure.Management.Network.Models;

namespace Microsoft.Azure.Commands.Network
{
[Cmdlet("Add", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ExpressRoutePortAuthorization"), OutputType(typeof(PSExpressRoutePortAuthorization))]
Comment thread
utbarn-ms marked this conversation as resolved.
Outdated
public class AddAzureExpressRoutePortAuthorizationCommand : NetworkBaseCmdlet
{
[Parameter(
Mandatory = true,
HelpMessage = "The name of the Authorization")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(
Mandatory = true,
ValueFromPipeline = true,
HelpMessage = "The ExpressRoutePort")]
public PSExpressRoutePort ExpressRoutePort { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }
Comment thread
utbarn-ms marked this conversation as resolved.
Outdated

public override void Execute()
{
base.Execute();
var present = true;

try
{
this.NetworkClient.NetworkManagementClient.ExpressRoutePortAuthorizations.GetWithHttpMessagesAsync(this.ExpressRoutePort.ResourceGroupName, this.ExpressRoutePort.Name, this.Name).GetAwaiter().GetResult();
}
catch (Microsoft.Rest.Azure.CloudException exception)
{
if (exception.Response.StatusCode == HttpStatusCode.NotFound)
{
// Resource is not present
present = false;
}
else
{
throw;
}
}

if (present)
{
throw new ArgumentException("Authorization with the specified name already exists");
}

var authorizationParameters = new MNM.ExpressRoutePortAuthorization();
authorizationParameters.Name = this.Name;

// Execute the PUT ExpressRoutePortAuthorizations call
var putExpressRoutePortAuthorization = this.NetworkClient.NetworkManagementClient.ExpressRoutePortAuthorizations.CreateOrUpdateWithHttpMessagesAsync(this.ExpressRoutePort.ResourceGroupName, this.ExpressRoutePort.Name, this.Name, authorizationParameters).GetAwaiter().GetResult().Body;
var psExpressRoutePortAuthorization = NetworkResourceManagerProfile.Mapper.Map<PSExpressRoutePortAuthorization>(putExpressRoutePortAuthorization);
WriteObject(psExpressRoutePortAuthorization, true);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// ----------------------------------------------------------------------------------
//
// 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.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Network.Models;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.Network
{
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ExpressRoutePortAuthorization"), OutputType(typeof(PSExpressRoutePortAuthorization))]
public class GetAzureExpressRoutePortAuthorizationCommand : NetworkBaseCmdlet
{
[Parameter(
Mandatory = false,
HelpMessage = "The name of the Authorization")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(
Mandatory = true,
ValueFromPipeline = true,
HelpMessage = "The ExpressRoutePort")]
public PSExpressRoutePort ExpressRoutePort { get; set; }

public override void Execute()
{
base.Execute();
if (!string.IsNullOrEmpty(this.Name))
{
var getExpressRoutePortAuthorization = this.NetworkClient.NetworkManagementClient.ExpressRoutePortAuthorizations.GetWithHttpMessagesAsync(this.ExpressRoutePort.ResourceGroupName, this.ExpressRoutePort.Name, this.Name).GetAwaiter().GetResult().Body;
var psExpressRoutePortAuthorization = NetworkResourceManagerProfile.Mapper.Map<PSExpressRoutePortAuthorization>(getExpressRoutePortAuthorization);
WriteObject(psExpressRoutePortAuthorization);
}
else
{

var listExpressRoutePortAuthorizations = this.NetworkClient.NetworkManagementClient.ExpressRoutePortAuthorizations.ListWithHttpMessagesAsync(this.ExpressRoutePort.ResourceGroupName, this.ExpressRoutePort.Name).GetAwaiter().GetResult().Body;
var psExpressRoutePortAuthorizations = new List<PSExpressRoutePortAuthorization>();
if (listExpressRoutePortAuthorizations != null)
{
psExpressRoutePortAuthorizations = NetworkResourceManagerProfile.Mapper.Map<List<PSExpressRoutePortAuthorization>>(listExpressRoutePortAuthorizations);
}

WriteObject(psExpressRoutePortAuthorizations, true);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// ----------------------------------------------------------------------------------
//
// 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.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Network.Models;
using System.Linq;
using System.Management.Automation;


namespace Microsoft.Azure.Commands.Network
{
[Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ExpressRoutePortAuthorization"), OutputType(typeof(bool))]
Comment thread
utbarn-ms marked this conversation as resolved.
Outdated
public class RemoveAzureExpressRoutePortAuthorizationCommand : NetworkBaseCmdlet
{
[Parameter(
Mandatory = true,
HelpMessage = "The name of the Authorization")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(
Mandatory = true,
ValueFromPipeline = true,
HelpMessage = "The ExpressRoutePort")]
public PSExpressRoutePort ExpressRoutePort { get; set; }
Comment thread
utbarn-ms marked this conversation as resolved.
Outdated

[Parameter(Mandatory = false)]
public SwitchParameter PassThru { get; set; }

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

public override void Execute()
{
base.Execute();
this.NetworkClient.NetworkManagementClient.ExpressRoutePortAuthorizations.DeleteWithHttpMessagesAsync(this.ExpressRoutePort.ResourceGroupName, this.ExpressRoutePort.Name, this.Name).GetAwaiter().GetResult();
if (PassThru)
{
WriteObject(true);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public override void Execute()
BandwidthInGbps = this.BandwidthInGbps,
Encapsulation = this.Encapsulation,
Location = this.Location,
Links = this.Link?.ToList(),
Links = this.Link?.ToList()
};

if (this.Identity != null)
Expand Down
2 changes: 2 additions & 0 deletions src/Network/Network/Generated/Models/PSExpressRouteCircuit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public partial class PSExpressRouteCircuit : PSTopLevelResource
public double? BandwidthInGbps { get; set; }
[Ps1Xml(Target = ViewControl.Table)]
public int? Stag { get; set; }
[Ps1Xml(Target = ViewControl.Table)]
public string AuthorizationKey { get; set; }

[JsonIgnore]
public string SkuText
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// <auto-generated>
// Copyright (c) Microsoft and contributors. All rights reserved.
//
// 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.
//
//
// Warning: This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if the
// code is regenerated.
//
// For documentation on code generator please visit
// https://aka.ms/nrp-code-generation
// Please contact wanrpdev@microsoft.com if you need to make changes to this file.
// </auto-generated>

using Microsoft.WindowsAzure.Commands.Common.Attributes;
using Newtonsoft.Json;

namespace Microsoft.Azure.Commands.Network.Models
{
public partial class PSExpressRoutePortAuthorization : PSChildResource
{
[JsonProperty(Order = 1)]
public string AuthorizationKey { get; set; }
[JsonProperty(Order = 1)]
[Ps1Xml(Target = ViewControl.Table)]
public string AuthorizationUseStatus { get; set; }
[JsonProperty(Order = 1)]
[Ps1Xml(Target = ViewControl.Table)]
public string ProvisioningState { get; set; }
[JsonProperty(Order = 1)]
[Ps1Xml(Target = ViewControl.Table)]
public string CircuitResourceUri { get; set; }
}
}
Loading