diff --git a/src/Network/Network.Test/ScenarioTests/ExpressRoutePortTests.cs b/src/Network/Network.Test/ScenarioTests/ExpressRoutePortTests.cs index 2c5c1045cf68..d82d2e7632da 100644 --- a/src/Network/Network.Test/ScenarioTests/ExpressRoutePortTests.cs +++ b/src/Network/Network.Test/ScenarioTests/ExpressRoutePortTests.cs @@ -40,5 +40,14 @@ public void TestExpressRoutePortIdentityCRUD() { TestRunner.RunTestScript("Test-ExpressRoutePortIdentityCRUD"); } + + [Fact(Skip = "Nfv-RP rollout in progress")] + [Trait(Category.AcceptanceType, Category.CheckIn)] + [Trait(Category.Owner, NrpTeamAlias.pgtm)] + public void TestExpressRoutePortGenerateLOA() + { + TestRunner.RunTestScript("Test-ExpressRoutePortGenerateLOA"); + } + } } diff --git a/src/Network/Network.Test/ScenarioTests/ExpressRoutePortTests.ps1 b/src/Network/Network.Test/ScenarioTests/ExpressRoutePortTests.ps1 index 327f9c4c266d..639c4fa2a03f 100644 --- a/src/Network/Network.Test/ScenarioTests/ExpressRoutePortTests.ps1 +++ b/src/Network/Network.Test/ScenarioTests/ExpressRoutePortTests.ps1 @@ -187,4 +187,44 @@ function Test-ExpressRoutePortIdentityCRUD } } +<# +.SYNOPSIS +Test creating new ExpressRoutePort +#> +function Test-ExpressRoutePortGenerateLOA +{ + # Setup + $rgname = Get-ResourceGroupName + $rname = Get-ResourceName + $resourceTypeParent = "Microsoft.Network/expressRoutePorts" + + # Only available peering location and location for now. + $rglocation = "eastus2euap" + $location = "eastus2euap" + $peeringLocation = "Good Grief" + $encapsulation = "QinQ" + $bandwidthInGbps = 25 + $customerName = "contoso" + + try + { + $resourceGroup = New-AzResourceGroup -Name $rgname -Location $rglocation + + # Create ExpressRoutePort + $vExpressRoutePort = New-AzExpressRoutePort -ResourceGroupName $rgname -Name $rname -Location $location -PeeringLocation $peeringLocation -Encapsulation $encapsulation -BandwidthInGbps $bandwidthInGbps + Assert-NotNull $vExpressRoutePort + Assert-True { Check-CmdletReturnType "New-AzExpressRoutePort" $vExpressRoutePort } + Assert-NotNull $vExpressRoutePort.Links + Assert-True { $vExpressRoutePort.Links.Count -eq 2 } + Assert-AreEqual $rname $vExpressRoutePort.Name + + $loa = New-AzExpressRoutePortLOA -ResourceGroupName $rgname -PortName $rname -CustomerName $customerName -PassThru + Assert-True { $loa -eq $true } + } + finally + { + # Cleanup + Clean-ResourceGroup $rgname + } +} diff --git a/src/Network/Network/Az.Network.psd1 b/src/Network/Network/Az.Network.psd1 index ce697cb96250..9d9ded2be5b2 100644 --- a/src/Network/Network/Az.Network.psd1 +++ b/src/Network/Network/Az.Network.psd1 @@ -502,7 +502,8 @@ CmdletsToExport = 'Add-AzApplicationGatewayAuthenticationCertificate', 'Get-AzNetworkVirtualApplianceSku', 'New-AzVirtualApplianceSkuProperty', 'New-AzCustomIpPrefix', 'Update-AzCustomIpPrefix', - 'Get-AzCustomIpPrefix', 'Remove-AzCustomIpPrefix' + 'Get-AzCustomIpPrefix', 'Remove-AzCustomIpPrefix', + 'New-AzExpressRoutePortLOA' # Variables to export from this module diff --git a/src/Network/Network/ChangeLog.md b/src/Network/Network/ChangeLog.md index 9ff8c129debb..f4904b7f5b0d 100644 --- a/src/Network/Network/ChangeLog.md +++ b/src/Network/Network/ChangeLog.md @@ -19,6 +19,8 @@ ---> ## Upcoming Release +* Added new cmdlet for Azure Express Route Port + - `New-AzExpressRoutePortLOA` * [Breaking Change] Updated below cmdlets to align resource virtual router and virtual hub - `New-AzVirtualRouter`: - Added -HostedSubnet parameter to support IP configuration child resource diff --git a/src/Network/Network/ExpressRoutePort/LOA/NewAzureRmExpressRoutePortLOACommand.cs b/src/Network/Network/ExpressRoutePort/LOA/NewAzureRmExpressRoutePortLOACommand.cs new file mode 100644 index 000000000000..fe942dd84487 --- /dev/null +++ b/src/Network/Network/ExpressRoutePort/LOA/NewAzureRmExpressRoutePortLOACommand.cs @@ -0,0 +1,128 @@ +// ---------------------------------------------------------------------------------- +// +// 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.ResourceManager.Common.ArgumentCompleters; +using Microsoft.Azure.Commands.Network.Models; +using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; +using Microsoft.Azure.Management.Network; +using System; +using System.Management.Automation; +using System.IO; +using Microsoft.Azure.Management.Network.Models; +using System.ComponentModel; +using System.Security.Cryptography; + +namespace Microsoft.Azure.Commands.Network +{ + [Cmdlet(VerbsCommon.New, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ExpressRoutePortLOA", SupportsShouldProcess = false, DefaultParameterSetName = ResourceNameParameterSet), OutputType(typeof(bool))] + public partial class NewAzureRmExpressRoutePortLOA : NetworkBaseCmdlet + { + private const string ResourceIdParameterSet = "ResourceIdParameterSet"; + private const string ResourceNameParameterSet = "ResourceNameParameterSet"; + private const string ResourceObjectParameterSet = "ResourceObjectParameterSet"; + private const string DefaultFileName = "LOA.pdf"; + + [Parameter( + ParameterSetName = ResourceNameParameterSet, + Mandatory = true, + HelpMessage = "The express route port name.", + ValueFromPipelineByPropertyName = false)] + [ValidateNotNullOrEmpty] + public string PortName { get; set; } + + [Parameter( + ParameterSetName = ResourceNameParameterSet, + Mandatory = true, + HelpMessage = "The resource group name of the express route port.", + ValueFromPipelineByPropertyName = false)] + [ResourceGroupCompleter] + [ValidateNotNullOrEmpty] + public string ResourceGroupName { get; set; } + + [Parameter( + ParameterSetName = ResourceObjectParameterSet, + Mandatory = true, + HelpMessage = "The express route port resource.", + ValueFromPipelineByPropertyName = false)] + [ValidateNotNullOrEmpty] + public PSExpressRoutePort ExpressRoutePort { get; set; } + + [Alias("ResourceId")] + [Parameter( + ParameterSetName = ResourceIdParameterSet, + Mandatory = true, + HelpMessage = "ResourceId of the express route port.", + ValueFromPipelineByPropertyName = true)] + [ValidateNotNullOrEmpty] + public string Id { get; set; } + + [Alias("Name")] + [Parameter( + Mandatory = true, + HelpMessage = "The customer name to whom this Express Route Port is assigned to.", + ValueFromPipelineByPropertyName = false)] + [ValidateNotNullOrEmpty] + public string CustomerName { get; set; } + + [Parameter( + Mandatory = false, + HelpMessage = "The output filepath to store the Letter of Authorization to.", + ValueFromPipelineByPropertyName = false)] + public string Destination { get; set; } + + [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(); + + if (string.Equals(this.ParameterSetName, ResourceObjectParameterSet, StringComparison.OrdinalIgnoreCase)) + { + ResourceGroupName = ExpressRoutePort.ResourceGroupName; + PortName = ExpressRoutePort.Name; + } + if (string.Equals(this.ParameterSetName, ResourceIdParameterSet, StringComparison.OrdinalIgnoreCase)) + { + var resourceInfo = new ResourceIdentifier(Id); + ResourceGroupName = resourceInfo.ResourceGroupName; + PortName = resourceInfo.ResourceName; + } + if(this.ResourceGroupName == null || this.PortName == null){ + Console.WriteLine("Empty resource group or port name."); + return; + } + GenerateExpressRoutePortsLOARequest generateExpressRoutePortsLOARequest = new GenerateExpressRoutePortsLOARequest(CustomerName); + var response = this.NetworkClient.NetworkManagementClient.ExpressRoutePorts.GenerateLOA(this.ResourceGroupName, this.PortName, generateExpressRoutePortsLOARequest); + var decodedDocument = Convert.FromBase64String(response.EncodedContent); + if (String.IsNullOrEmpty(Destination)) + { + Destination = DefaultFileName; + } + if (!(Path.IsPathRooted(Destination))) + { + Destination = Directory.GetCurrentDirectory() + "\\" + Destination; + } + File.WriteAllBytes(Destination, decodedDocument); + Console.WriteLine("Written Letter of Authorization To: " + Destination); + if (PassThru) + { + WriteObject(true); + } + } + } +} diff --git a/src/Network/Network/help/New-AzExpressRoutePortLOA.md b/src/Network/Network/help/New-AzExpressRoutePortLOA.md new file mode 100644 index 000000000000..5b1646634cb0 --- /dev/null +++ b/src/Network/Network/help/New-AzExpressRoutePortLOA.md @@ -0,0 +1,196 @@ +--- +external help file: Microsoft.Azure.PowerShell.Cmdlets.Network.dll-Help.xml +Module Name: Az.Network +online version: https://docs.microsoft.com/en-us/powershell/module/az.network/new-azexpressrouteportloa +schema: 2.0.0 +--- + +# New-AzExpressRoutePortLOA + +## SYNOPSIS +Download letter of authorization document for an express route port. + +## SYNTAX + +### ResourceNameParameterSet (Default) +``` +New-AzExpressRoutePortLOA -PortName -ResourceGroupName -CustomerName + [-Destination ] [-PassThru] [-AsJob] [-DefaultProfile ] [] +``` + +### ResourceObjectParameterSet +``` +New-AzExpressRoutePortLOA -ExpressRoutePort -CustomerName [-Destination ] + [-PassThru] [-AsJob] [-DefaultProfile ] [] +``` + +### ResourceIdParameterSet +``` +New-AzExpressRoutePortLOA -Id -CustomerName [-Destination ] [-PassThru] [-AsJob] + [-DefaultProfile ] [] +``` + +## DESCRIPTION +New-AzExpressRoutePortLOA cmdlet downloads a letter of authorization document in PDF format for an express route port. + + +## EXAMPLES + +### Example 1 +```powershell +PS C:\> New-AzExpressRoutePortLOA -ResourceGroupName myRg -PortName myPort -CustomerName Contoso -Destination loa.pdf +``` + +Download the letter of authorization document for express route port 'myPort' and store it in file 'loa.pdf'. + +## PARAMETERS + +### -AsJob +Run cmdlet in the background + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -CustomerName +The customer name to whom this Express Route Port is assigned to. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: Name + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DefaultProfile +The credentials, account, tenant, and subscription used for communication with Azure. + +```yaml +Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer +Parameter Sets: (All) +Aliases: AzContext, AzureRmContext, AzureCredential + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Destination +The output filepath to store the Letter of Authorization to. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ExpressRoutePort +The express route port resource. + +```yaml +Type: Microsoft.Azure.Commands.Network.Models.PSExpressRoutePort +Parameter Sets: ResourceObjectParameterSet +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Id +ResourceId of the express route port. + +```yaml +Type: System.String +Parameter Sets: ResourceIdParameterSet +Aliases: ResourceId + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByPropertyName) +Accept wildcard characters: False +``` + +### -PassThru +Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output. + +```yaml +Type: System.Management.Automation.SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PortName +The express route port name. + +```yaml +Type: System.String +Parameter Sets: ResourceNameParameterSet +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ResourceGroupName +The resource group name of the express route port. + +```yaml +Type: System.String +Parameter Sets: ResourceNameParameterSet +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.String + +## OUTPUTS + +### System.Boolean + +## NOTES + +## RELATED LINKS diff --git a/tools/StaticAnalysis/Exceptions/Az.Network/SignatureIssues.csv b/tools/StaticAnalysis/Exceptions/Az.Network/SignatureIssues.csv index 943073093a2d..1d3ce5ee3e3f 100644 --- a/tools/StaticAnalysis/Exceptions/Az.Network/SignatureIssues.csv +++ b/tools/StaticAnalysis/Exceptions/Az.Network/SignatureIssues.csv @@ -370,3 +370,4 @@ "Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.UpdateAzureRmVpnServerConfigurationCommand","Update-AzVpnServerConfiguration","1","8700","Parameter set 'ByVpnServerConfigurationResourceIdByCertificateAuthentication', 'ByVpnServerConfigurationResourceIdByRadiusAuthentication', 'ByVpnServerConfigurationResourceIdByAadAuthentication' of cmdlet 'Update-AzVpnServerConfiguration' have the same mandatory parameters, and both of them are not default parameter set which may cause confusion.","Merge these parameter sets into one parameter set." "Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.GetAzureRmVpnSiteCommand","Get-AzVpnSite","1","8700","Parameter set 'ListByResourceGroupName', '__AllParameterSets' of cmdlet 'Get-AzVpnSite' have the same mandatory parameters, and both of them are not default parameter set which may cause confusion.","Merge these parameter sets into one parameter set." "Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.Bastion.GetAzBastionCommand","Get-AzBastion","1","8700","Parameter set 'ListByResourceGroupName', '__AllParameterSets' of cmdlet 'Get-AzBastion' have the same mandatory parameters, and both of them are not default parameter set which may cause confusion.","Merge these parameter sets into one parameter set." +"Microsoft.Azure.PowerShell.Cmdlets.Network.dll","Microsoft.Azure.Commands.Network.NewAzureRmExpressRoutePortLOA","New-AzExpressRoutePortLOA","1","8100","New-AzExpressRoutePortLOA Does not support ShouldProcess but the cmdlet verb New indicates that it should.","Determine if the cmdlet should implement ShouldProcess and if so determine if it should implement Force / ShouldContinue"