Skip to content

Commit

Permalink
Review comments #2
Browse files Browse the repository at this point in the history
  • Loading branch information
akshaysngupta committed Jun 29, 2017
1 parent c8106b8 commit 1c95f3a
Show file tree
Hide file tree
Showing 30 changed files with 247 additions and 80 deletions.
3 changes: 2 additions & 1 deletion src/ResourceManager/Network/AzureRM.Network.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ CmdletsToExport = 'Add-AzureRmApplicationGatewayAuthenticationCertificate',

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = 'List-AzureRmApplicationGatewayAvailableWafRuleSets',
'List-AzureRmApplicationGatewayAvailableSslOptions'
'List-AzureRmApplicationGatewayAvailableSslOptions',
'List-AzureRmApplicationGatewaySslPredefinedPolicy'

# DSC resources to export from this module
# DscResourcesToExport = @()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@ public ApplicationGatewayTests(ITestOutputHelper output)
XunitTracingInterceptor.AddToContext(new XunitTracingInterceptor(output));
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestAvailableSslOptions()
{
NetworkResourcesController.NewInstance.RunPsTest(string.Format("Test-AvailableSslOptions"));
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestAvailableWafRuleSets()
{
NetworkResourcesController.NewInstance.RunPsTest(string.Format("Test-AvailableWafRuleSets -baseDir '{0}'", AppDomain.CurrentDomain.BaseDirectory));
NetworkResourcesController.NewInstance.RunPsTest(string.Format("Test-AvailableWafRuleSets"));
}

[Fact]
Expand All @@ -41,5 +48,12 @@ public void TestApplicationGatewayCRUD()
{
NetworkResourcesController.NewInstance.RunPsTest(string.Format("Test-ApplicationGatewayCRUD -baseDir '{0}'", AppDomain.CurrentDomain.BaseDirectory));
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestApplicationGatewayCRUD2()
{
NetworkResourcesController.NewInstance.RunPsTest(string.Format("Test-ApplicationGatewayCRUD2 -baseDir '{0}'", AppDomain.CurrentDomain.BaseDirectory));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,135 @@ function Test-ApplicationGatewayCRUD
}
}

<#
.SYNOPSIS
Application gateway tests
#>
function Test-ApplicationGatewayCRUD2
{
param
(
$basedir = ".\"
)

# Setup

$rglocation = Get-ProviderLocation ResourceManagement
$resourceTypeParent = "Microsoft.Network/applicationgateways"
$location = Get-ProviderLocation $resourceTypeParent

$rgname = Get-ResourceGroupName
$appgwName = Get-ResourceName
$vnetName = Get-ResourceName
$gwSubnetName = Get-ResourceName
$nicSubnetName = Get-ResourceName
$publicIpName = Get-ResourceName
$gipconfigname = Get-ResourceName

$frontendPort01Name = Get-ResourceName
$frontendPort02Name = Get-ResourceName
$fipconfigName = Get-ResourceName
$listener01Name = Get-ResourceName
$listener02Name = Get-ResourceName

$poolName = Get-ResourceName
$poolSetting01Name = Get-ResourceName

$redirect01Name = Get-ResourceName
$redirect02Name = Get-ResourceName
$redirect03Name = Get-ResourceName
$rule01Name = Get-ResourceName
$rule02Name = Get-ResourceName

$probeHttpName = Get-ResourceName

try
{
# Create the resource group
$resourceGroup = New-AzureRmResourceGroup -Name $rgname -Location $location -Tags @{ testtag = "APPGw tag"}

# Create the Virtual Network
$gwSubnet = New-AzureRmVirtualNetworkSubnetConfig -Name $gwSubnetName -AddressPrefix 10.0.0.0/24
$nicSubnet = New-AzureRmVirtualNetworkSubnetConfig -Name $nicSubnetName -AddressPrefix 10.0.2.0/24
$vnet = New-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $gwSubnet, $nicSubnet
$vnet = Get-AzureRmvirtualNetwork -Name $vnetName -ResourceGroupName $rgname
$gwSubnet = Get-AzureRmVirtualNetworkSubnetConfig -Name $gwSubnetName -VirtualNetwork $vnet
  $nicSubnet = Get-AzureRmVirtualNetworkSubnetConfig -Name $nicSubnetName -VirtualNetwork $vnet

# Create public ip
$publicip = New-AzureRmPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -location $location -AllocationMethod Dynamic

# Create ip configuration
$gipconfig = New-AzureRmApplicationGatewayIPConfiguration -Name $gipconfigname -Subnet $gwSubnet

#frontend part
$fipconfig = New-AzureRmApplicationGatewayFrontendIPConfig -Name $fipconfigName -PublicIPAddress $publicip
$fp01 = New-AzureRmApplicationGatewayFrontendPort -Name $frontendPort01Name  -Port 80
$fp02 = New-AzureRmApplicationGatewayFrontendPort -Name $frontendPort02Name  -Port 81
$listener01 = New-AzureRmApplicationGatewayHttpListener -Name $listener01Name -Protocol Http -FrontendIPConfiguration $fipconfig -FrontendPort $fp01
$listener02 = New-AzureRmApplicationGatewayHttpListener -Name $listener02Name -Protocol Http -FrontendIPConfiguration $fipconfig -FrontendPort $fp02

# backend part
$pool = New-AzureRmApplicationGatewayBackendAddressPool -Name $poolName -BackendIPAddresses www.microsoft.com, www.bing.com
$match = New-AzureRmApplicationGatewayProbeHealthResponseMatch -Body "helloworld" -StatusCode "200-300","404"
$probeHttp = New-AzureRmApplicationGatewayProbeConfig -Name $probeHttpName -Protocol Http -HostName "probe.com" -Path "/path/path.htm" -Interval 89 -Timeout 88 -UnhealthyThreshold 8 -Match $match
$poolSetting01 = New-AzureRmApplicationGatewayBackendHttpSettings -Name $poolSetting01Name -Port 80 -Protocol Http -Probe $probeHttp -CookieBasedAffinity Enabled -ProbeEnabled -PickHostNameFromBackendAddress

# rule part
$redirect01 = New-AzureRmApplicationGatewayRedirectConfiguration -Name $redirect01Name -RedirectType Permanent -TargetListener $listener01

$rule01 = New-AzureRmApplicationGatewayRequestRoutingRule -Name $rule01Name -RuleType basic -BackendHttpSettings $poolSetting01 -HttpListener $listener01 -BackendAddressPool $pool
$rule02 = New-AzureRmApplicationGatewayRequestRoutingRule -Name $rule02Name -RuleType basic -HttpListener $listener02 -RedirectConfiguration $redirect01

$sku = New-AzureRmApplicationGatewaySku -Name Standard_Medium -Tier Standard -Capacity 2

# security part
$sslPolicy = New-AzureRmApplicationGatewaySslPolicy -PolicyType Custom -MinProtocolVersion TLSv1_1 -CipherSuite "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", "TLS_RSA_WITH_AES_128_GCM_SHA256"

# Create Application Gateway
$appgw = New-AzureRmApplicationGateway -Name $appgwName -ResourceGroupName $rgname -Location $location -Probes $probeHttp -BackendAddressPools $pool -BackendHttpSettingsCollection $poolSetting01 -FrontendIpConfigurations $fipconfig -GatewayIpConfigurations $gipconfig -FrontendPorts $fp01, $fp02 -HttpListeners $listener01, $listener02 -RedirectConfiguration $redirect01 -RequestRoutingRules $rule01, $rule02 -Sku $sku -SslPolicy $sslPolicy

# Check get/set/remove for RedirectConfiguration
$redirect02 = Get-AzureRmApplicationGatewayRedirectConfiguration -ApplicationGateway $appgw -Name $redirect01Name
Assert-AreEqual $redirect01.TargetListenerId $redirect02.TargetListenerId
$getgw = Set-AzureRmApplicationGatewayRedirectConfiguration -ApplicationGateway $appgw -Name $redirect01Name -RedirectType Permanent -TargetUrl "https://www.bing.com"

$getgw = Add-AzureRmApplicationGatewayRedirectConfiguration -ApplicationGateway $getgw -Name $redirect03Name -RedirectType Permanent -TargetListener $listener01 -IncludePath
$getgw = Remove-AzureRmApplicationGatewayRedirectConfiguration -ApplicationGateway $getgw -Name $redirect03Name

# Get for SslPolicy
$sslPolicy01 = Get-AzureRmApplicationGatewaySslPolicy -ApplicationGateway $getgw
Assert-AreEqual $sslPolicy.MinProtocolVersion $sslPolicy01.MinProtocolVersion

# Set for sslPolicy
$getgw = Set-AzureRmApplicationGatewaySslPolicy -ApplicationGateway $getgw -PolicyType Predefined -PolicyName AppGwSslPolicy20170401

# Get Match
$probeHttp01 = Get-AzureRmApplicationGatewayProbeConfig -ApplicationGateway $getgw -Name $probeHttpName
Assert-AreEqual $probeHttp.Match.Body $probeHttp01.Match.Body

# Get Application Gateway
$getgw = Get-AzureRmApplicationGateway -Name $appgwName -ResourceGroupName $rgname

# Modify existing application gateway with new configuration
$getgw = Set-AzureRmApplicationGateway -ApplicationGateway $getgw

Assert-AreEqual "Running" $getgw.OperationalState

# Stop Application Gateway
$getgw = Stop-AzureRmApplicationGateway -ApplicationGateway $getgw

Assert-AreEqual "Stopped" $getgw.OperationalState

# Delete Application Gateway
Remove-AzureRmApplicationGateway -Name $appgwName -ResourceGroupName $rgname -Force
}
finally
{
# Cleanup
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public class AzureApplicationGatewayBackendHttpSettingsBase : NetworkBaseCmdlet

[Parameter(
Mandatory = false,
HelpMessage = "Path which should be used as a prefix for all HTTP requests. Null means no path will be prefixed. Default value is null")]
HelpMessage = "Path which should be used as a prefix for all HTTP requests. If no value is provided for this parameter, then no path will be prefixed.")]
[ValidateNotNullOrEmpty]
public string Path { get; set; }

Expand Down Expand Up @@ -144,12 +144,18 @@ public PSApplicationGatewayBackendHttpSettings NewObject()
});
}
}
backendHttpSettings.PickHostNameFromBackendAddress = this.PickHostNameFromBackendAddress;
if(this.PickHostNameFromBackendAddress.IsPresent)
{
backendHttpSettings.PickHostNameFromBackendAddress = true;
}
if (this.AffinityCookieName != null)
{
backendHttpSettings.AffinityCookieName = this.AffinityCookieName;
}
backendHttpSettings.ProbeEnabled = this.ProbeEnabled;
if (this.ProbeEnabled.IsPresent)
{
backendHttpSettings.ProbeEnabled = true;
}
if (this.Path != null)
{
backendHttpSettings.Path = this.Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public class GetAzureApplicationGatewaySslPredefinedPolicy : ApplicationGatewayB
Mandatory = false,
HelpMessage = "Name of the ssl predefined policy")]
[ValidateNotNullOrEmpty]
public string PredefinedPolicyName { get; set; }
public string Name { get; set; }

public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();
if (this.PredefinedPolicyName != null)
if (this.Name != null)
{
var policy = this.ApplicationGatewayClient.GetSslPredefinedPolicy(this.PredefinedPolicyName);
var policy = this.ApplicationGatewayClient.GetSslPredefinedPolicy(this.Name);
var psPolicy = Mapper.Map<PSApplicationGatewaySslPredefinedPolicy>(policy);
WriteObject(psPolicy);
}
Expand All @@ -49,7 +49,7 @@ public override void ExecuteCmdlet()
psPolicies.Add(Mapper.Map<PSApplicationGatewaySslPolicy>(policy));
}

WriteObject(psPolicies);
WriteObject(psPolicies, true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class AzureApplicationGatewayProbeConfigBase : NetworkBaseCmdlet
public string Protocol { get; set; }

[Parameter(
Mandatory = true,
Mandatory = false,
HelpMessage = "Host name to send probe to")]
[ValidateNotNullOrEmpty]
public string HostName { get; set; }
Expand Down Expand Up @@ -71,6 +71,7 @@ public class AzureApplicationGatewayProbeConfigBase : NetworkBaseCmdlet
[Parameter(
Mandatory = false,
HelpMessage = "Minimum number of servers that are always marked healthy. Default value is 0")]
[ValidateRange(0, int.MaxValue)]
public uint MinServers { get; set; }

[Parameter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class AzureApplicationGatewayProbeHealthResponseMatchBase : NetworkBaseCm
[Parameter(
HelpMessage = "Allowed ranges of healthy status codes.Default range of healthy status codes is 200 - 399")]
[ValidateNotNullOrEmpty]
public List<string> StatusCodes { get; set; }
public List<string> StatusCode { get; set; }

public override void ExecuteCmdlet()
{
Expand All @@ -41,7 +41,7 @@ protected PSApplicationGatewayProbeHealthResponseMatch NewObject()
return new PSApplicationGatewayProbeHealthResponseMatch()
{
Body = this.Body,
StatusCodes = this.StatusCodes
StatusCodes = this.StatusCode
};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ public class AzureApplicationGatewayRedirectConfigurationBase : NetworkBaseCmdle
ParameterSetName = "SetByResource",
HelpMessage = "HTTPListener to redirect the request to")]
[ValidateNotNullOrEmpty]
public PSApplicationGatewayBackendHttpSettings TargetListener { get; set; }
public PSApplicationGatewayHttpListener TargetListener { get; set; }

[Parameter(
ParameterSetName = "SetByURL",
HelpMessage = "Target URL fo redirection")]
[ValidateNotNullOrEmpty]
public string TargetUrl { get; set; }
Expand Down Expand Up @@ -76,6 +77,7 @@ public PSApplicationGatewayRedirectConfiguration NewObject()
{
var redirectConfiguration = new PSApplicationGatewayRedirectConfiguration();
redirectConfiguration.Name = this.Name;
redirectConfiguration.RedirectType = this.RedirectType;

if (this.TargetUrl != null
&& this.TargetListenerID != null
Expand All @@ -92,8 +94,14 @@ public PSApplicationGatewayRedirectConfiguration NewObject()
}

redirectConfiguration.TargetUrl = this.TargetUrl;
redirectConfiguration.IncludePath = this.IncludePath;
redirectConfiguration.IncludeQueryString = this.IncludeQueryString;
if (this.IncludePath)
{
redirectConfiguration.IncludePath = this.IncludePath;
}
if (this.IncludeQueryString)
{
redirectConfiguration.IncludeQueryString = this.IncludeQueryString;
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override void ExecuteCmdlet()
resource =>
string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

WriteObject(redirectConfiguration);
WriteObject(redirectConfiguration, true);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

namespace Microsoft.Azure.Commands.Network
{
[Cmdlet(VerbsCommon.Remove, "AzureRmApplicationGatewayRedirectConfiguration"), OutputType(typeof(PSApplicationGatewayRedirectConfiguration))]
[Cmdlet(VerbsCommon.Remove, "AzureRmApplicationGatewayRedirectConfiguration"), OutputType(typeof(PSApplicationGateway))]
public class RemoveAzureApplicationGatewayRedirectConfigurationCommand : NetworkBaseCmdlet
{
[Parameter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,25 @@ public class SetAzureApplicationGatewayRedirectConfigurationCommand : AzureAppli
public PSApplicationGateway ApplicationGateway { get; set; }
public override void ExecuteCmdlet()
{
base.ExecuteCmdlet();
if (ShouldProcess(Name, Microsoft.Azure.Commands.Network.Properties.Resources.OverwritingResourceMessage))
{
base.ExecuteCmdlet();

var oldRedirectConfiguration = this.ApplicationGateway.RedirectConfigurations.SingleOrDefault
(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));
var oldRedirectConfiguration = this.ApplicationGateway.RedirectConfigurations.SingleOrDefault
(resource => string.Equals(resource.Name, this.Name, System.StringComparison.CurrentCultureIgnoreCase));

if (oldRedirectConfiguration == null)
{
throw new ArgumentException("RedirectConfiguration with the specified name does not exist");
}
if (oldRedirectConfiguration == null)
{
throw new ArgumentException("RedirectConfiguration with the specified name does not exist");
}

var newRedirectConfiguration = base.NewObject();
var newRedirectConfiguration = base.NewObject();

this.ApplicationGateway.RedirectConfigurations.Remove(oldRedirectConfiguration);
this.ApplicationGateway.RedirectConfigurations.Add(newRedirectConfiguration);
this.ApplicationGateway.RedirectConfigurations.Remove(oldRedirectConfiguration);
this.ApplicationGateway.RedirectConfigurations.Add(newRedirectConfiguration);

WriteObject(this.ApplicationGateway);
WriteObject(this.ApplicationGateway);
}
}
}
}
Loading

0 comments on commit 1c95f3a

Please sign in to comment.