Skip to content

Commit 3d5b557

Browse files
committed
Merge branch 'master' of https://github.com/Azure/azure-powershell into nullreferenceexception-in-AzAccounts#10292
2 parents aa31c21 + 38cc7f7 commit 3d5b557

File tree

201 files changed

+40188
-1780
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201 files changed

+40188
-1780
lines changed

.azure-pipelines/powershell-core.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
variables:
22
WindowsName: windows
3-
WindowsImage: VS2017-Win2016
3+
WindowsImage: vs2017-win2016
44
LinuxName: linux
5-
LinuxImage: Ubuntu-18.04
5+
LinuxImage: ubuntu-18.04
66
MacOSName: macOS
77
MacOSImage: macOS-10.13
88
TestFramework: netcoreapp2.1

src/Cdn/Cdn.Test/Cdn.Test.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Azure.Management.Cdn" Version="4.2.2-preview" />
14+
<PackageReference Include="Microsoft.Azure.Management.Cdn" Version="4.2.4-preview" />
1515
</ItemGroup>
1616

1717
</Project>

src/Cdn/Cdn.Test/ScenarioTests/EndpointTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ public void TestEndpointCrudAndAction()
3535
TestController.NewInstance.RunPowerShellTest(_logger, "Test-EndpointCrudAndAction");
3636
}
3737

38+
[Fact]
39+
[Trait(Category.AcceptanceType, Category.CheckIn)]
40+
public void TestEndpointCreateWithRulesEngine()
41+
{
42+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-EndpointCreateWithRulesEngine");
43+
}
44+
3845
[Fact]
3946
[Trait(Category.AcceptanceType, Category.CheckIn)]
4047
public void TestEndpointCrudAndActionWithPiping()

src/Cdn/Cdn.Test/ScenarioTests/EndpointTests.ps1

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,53 @@ function Test-EndpointCrudAndAction
7070
Remove-AzResourceGroup -Name $resourceGroup.ResourceGroupName -Force
7171
}
7272

73+
<#
74+
.SYNOPSIS
75+
Create ENdpoint with RulesEngine config
76+
#>
77+
function Test-EndpointCreateWithRulesEngine
78+
{
79+
$profileName = getAssetName
80+
$resourceGroup = TestSetup-CreateResourceGroup
81+
$resourceLocation = "EastUS"
82+
$profileSku = "Standard_Microsoft"
83+
$createdProfile = New-AzCdnProfile -ProfileName $profileName -ResourceGroupName $resourceGroup.ResourceGroupName -Location $resourceLocation -Sku $profileSku
84+
85+
$endpointName = getAssetName
86+
$originName = getAssetName
87+
$originHostName = "www.microsoft.com"
88+
89+
$nameAvailability = Get-AzCdnEndpointNameAvailability -EndpointName $endpointName
90+
Assert-True{$nameAvailability.NameAvailable}
91+
92+
$description = 'Sample delivery policy'
93+
$cond1 = New-AzCdnDeliveryRuleCondition -MatchVariable IsDevice -Operator Equal -MatchValue "Desktop"
94+
$action1 = New-AzCdnDeliveryRuleAction -SourcePattern "/abc" -Destination "/def" -PreservePath
95+
$action2 = New-AzCdnDeliveryRuleAction -QueryStringBehavior ExcludeAll -QueryParameter "abc","def"
96+
$action3 = New-AzCdnDeliveryRuleAction -QueryStringBehavior IncludeAll
97+
$redirect = New-AzCdnDeliveryRuleAction -RedirectType Found -DestinationProtocol MatchRequest
98+
$rule0 = New-AzCdnDeliveryRule -Name "EmptyCondition" -Order 0 -Action $redirect,$action3
99+
$rule1 = New-AzCdnDeliveryRule -Name "Rule1" -Order 1 -Condition $cond1 -Action $action1,$action2
100+
$deliverypolicy = New-AzCdnDeliveryPolicy -Description $description -Rule $rule0,$rule1
101+
102+
$createdEndpoint = New-AzCdnEndpoint -EndpointName $endpointName -ProfileName $profileName -ResourceGroupName $resourceGroup.ResourceGroupName -Location $resourceLocation -OriginName $originName -OriginHostName $originHostName -DeliveryPolicy $deliveryPolicy
103+
Assert-AreEqual $description $createdEndpoint.DeliveryPolicy.Description
104+
Assert-AreEqual $endpointName $createdEndpoint.Name
105+
Assert-AreEqual $deliverypolicy.Count $createdEndpoint.DeliveryPolicy.Count
106+
Assert-AreEqual $profileName $createdEndpoint.ProfileName
107+
Assert-AreEqual $resourceGroup.ResourceGroupName $createdEndpoint.ResourceGroupName
108+
Assert-AreEqual $originName $createdEndpoint.Origins[0].Name
109+
Assert-AreEqual $originHostName $createdEndpoint.Origins[0].HostName
110+
111+
$endpointRemoved = Remove-AzCdnEndpoint -EndpointName $endpointName -ProfileName $profileName -ResourceGroupName $resourceGroup.ResourceGroupName -PassThru -Force
112+
Assert-True{$endpointRemoved}
113+
114+
Assert-ThrowsContains { Get-AzCdnEndpoint -EndpointName $endpointName -ProfileName $profileName -ResourceGroupName $resourceGroup.ResourceGroupName } "NotFound"
115+
116+
Remove-AzResourceGroup -Name $resourceGroup.ResourceGroupName -Force
117+
}
118+
119+
73120
<#
74121
.SYNOPSIS
75122
Endpoint cycle with piping

src/Cdn/Cdn.Test/SessionRecords/Microsoft.Azure.Commands.Cdn.Test.ScenarioTests.ScenarioTest.EndpointTests/TestEndpointCreateWithRulesEngine.json

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

src/Cdn/Cdn/Cdn.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Azure.Management.Cdn" Version="4.2.2-preview" />
14+
<PackageReference Include="Microsoft.Azure.Management.Cdn" Version="4.2.4-preview" />
1515
</ItemGroup>
1616

1717
</Project>

src/Cdn/Cdn/ChangeLog.md

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

2121
## Upcoming Release
22+
* Introduced UrlRewriteAction and CacheKeyQueryStringAction to RulesEngine.
23+
* Fixed several bugs like missing "Selector" Input in New-AzDeliveryRuleCondition cmdlet.
2224

2325
## Version 1.3.1
2426
* Fixed miscellaneous typos across module

src/Cdn/Cdn/Common/AzureCdnCmdletBase.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public class AzureCdnCmdletBase : AzureRMCmdlet
3636
public const string CacheExpirationActionParameterSet = "CacheExpirationActionParameterSet";
3737
public const string HeaderActionParameterSet = "HeaderActionParameterSet";
3838
public const string UrlRedirectActionParameterSet = "UrlRedirectActionParameterSet";
39+
public const string CacheKeyQueryStringActionParameterSet = "CacheKeyQueryStringActionParameterSet";
40+
public const string UrlRewriteActionParameterSet = "UrlRewriteActionParameterSet";
3941

4042

4143
/// <summary>

src/Cdn/Cdn/Endpoint/NewAzCdnDdliveryRuleCondition.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@ public class NewAzCdnDeliveryRuleCondition : AzureCdnCmdletBase
3434
[Parameter(Mandatory = true, HelpMessage = "Match variable of the condition.")]
3535
[ValidateNotNullOrEmpty]
3636
[PSArgumentCompleter("RemoteAddress", "RequestMethod", "QueryString", "PostArgs", "RequestUri",
37-
"RequestHeader", "RequestBody", "RequestScheme", "UrlPath", "UrlFileExtension", "UrlFileName", "IsDevice")]
37+
"RequestHeader", "RequestBody", "RequestScheme", "UrlPath", "UrlFileExtension", "UrlFileName", "IsDevice", "Cookies", "HttpVersion")]
3838
public string MatchVariable { get; set; }
3939

4040
[Parameter(Mandatory = true, HelpMessage = "Describes operator to be matched")]
4141
[ValidateNotNullOrEmpty]
4242
[PSArgumentCompleter("Any", "IPMatch", "GeoMatch", "Equal", "Contains","LessThan", "GreaterThan",
4343
"LessThanOrEqual", "GreaterThanOrEqual", "BeginsWith", "EndsWith", "Wildcard")]
4444
public string Operator { get; set; }
45+
46+
[Parameter(Mandatory = false, HelpMessage = "Name of Selector to be matched")]
47+
public string Selector { get; set; }
4548

4649
[Parameter(Mandatory = true, HelpMessage = "List of possible match values.")]
4750
public string[] MatchValue { get; set; }
@@ -59,6 +62,7 @@ public override void ExecuteCmdlet()
5962
{
6063
MatchVariable = MatchVariable,
6164
Operator = Operator,
65+
Selector = Selector,
6266
MatchValue = MatchValue,
6367
NegateCondition = NegateCondition,
6468
Transfroms = Transform == null? null : new List<string> { Transform }

src/Cdn/Cdn/Endpoint/NewAzCdnDeliveryRuleAction.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ public class NewAzCdnDeliveryRuleAction : AzureCdnCmdletBase
8383
[ValidateNotNullOrEmpty]
8484
public string CustomFragment { get; set; }
8585

86+
[Parameter(Mandatory = true, HelpMessage = "QueryString behavior for the requests", ParameterSetName = CacheKeyQueryStringActionParameterSet)]
87+
[PSArgumentCompleter("Include", "IncludeAll", "Exclude", "ExcludeAll")]
88+
[ValidateNotNullOrEmpty]
89+
public string QueryStringBehavior { get; set; }
90+
91+
[Parameter(Mandatory = false, HelpMessage = "Query parameters to include or exclude (comma separated).", ParameterSetName = CacheKeyQueryStringActionParameterSet)]
92+
public string[] QueryParameter { get; set; }
93+
94+
[Parameter(Mandatory = true, HelpMessage = "Define a request URI pattern that identifies the type of requests that may be rewritten. If value is blank, all strings are matched.", ParameterSetName = UrlRewriteActionParameterSet)]
95+
public string SourcePattern { get; set; }
96+
97+
[Parameter(Mandatory = true, HelpMessage = "Define the relative URL to which the above requests will be rewritten by.", ParameterSetName = UrlRewriteActionParameterSet)]
98+
public string Destination { get; set; }
99+
100+
[Parameter(Mandatory = false, HelpMessage = "Whether to preserve unmatched path.", ParameterSetName = UrlRewriteActionParameterSet)]
101+
public SwitchParameter PreservePath { get; set; }
86102

87103
public override void ExecuteCmdlet()
88104
{
@@ -120,6 +136,32 @@ public override void ExecuteCmdlet()
120136
CustomFragment = CustomFragment
121137
};
122138
}
139+
else if (ParameterSetName == CacheKeyQueryStringActionParameterSet)
140+
{
141+
if ((QueryStringBehavior == "Exclude" || QueryStringBehavior == "Include") && QueryParameter == null)
142+
{
143+
throw new PSArgumentException("QueryParameter cannot be empty when QueryStringBehavior is {0}", QueryStringBehavior);
144+
}
145+
else if (QueryStringBehavior == "ExcludeAll" || QueryStringBehavior == "IncludeAll")
146+
{
147+
QueryParameter = null;
148+
}
149+
150+
deliveryRuleAction = new PSDeliveryRuleCacheKeyQueryStringAction
151+
{
152+
QueryStringBehavior = QueryStringBehavior,
153+
QueryParameter = QueryParameter == null? string.Empty : string.Join(",", QueryParameter)
154+
};
155+
}
156+
else if (ParameterSetName == UrlRewriteActionParameterSet)
157+
{
158+
deliveryRuleAction = new PSDeliveryRuleUrlRewriteAction
159+
{
160+
SourcePattern = SourcePattern,
161+
Destination = Destination,
162+
PreservePath = PreservePath
163+
};
164+
}
123165
else
124166
{
125167
deliveryRuleAction = new PSDeliveryRuleAction();

src/Cdn/Cdn/Endpoint/SetAzureRmCdnEndpoint.cs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,34 @@ private void SetEndpoint()
4343
{
4444
var resourceGroupName = CdnEndpoint.ResourceGroupName;
4545
var profileName = CdnEndpoint.ProfileName;
46+
try
47+
{
48+
var endpoint = CdnManagementClient.Endpoints.Update(
49+
resourceGroupName,
50+
profileName,
51+
CdnEndpoint.Name,
52+
new EndpointUpdateParameters(
53+
CdnEndpoint.Tags.ToDictionaryTags(),
54+
CdnEndpoint.OriginHostHeader,
55+
CdnEndpoint.OriginPath,
56+
CdnEndpoint.ContentTypesToCompress.ToList(),
57+
CdnEndpoint.IsCompressionEnabled,
58+
CdnEndpoint.IsHttpAllowed,
59+
CdnEndpoint.IsHttpsAllowed,
60+
(QueryStringCachingBehavior)Enum.Parse(typeof(QueryStringCachingBehavior), CdnEndpoint.QueryStringCachingBehavior.ToString()),
61+
CdnEndpoint.OptimizationType,
62+
CdnEndpoint.ProbePath,
63+
CdnEndpoint.GeoFilters.Select(g => g.ToSdkGeoFilter()).ToList(),
64+
CdnEndpoint.DeliveryPolicy?.ToSdkDeliveryPolicy()));
4665

47-
var endpoint = CdnManagementClient.Endpoints.Update(
48-
resourceGroupName,
49-
profileName,
50-
CdnEndpoint.Name,
51-
new EndpointUpdateParameters(
52-
CdnEndpoint.Tags.ToDictionaryTags(),
53-
CdnEndpoint.OriginHostHeader,
54-
CdnEndpoint.OriginPath,
55-
CdnEndpoint.ContentTypesToCompress.ToList(),
56-
CdnEndpoint.IsCompressionEnabled,
57-
CdnEndpoint.IsHttpAllowed,
58-
CdnEndpoint.IsHttpsAllowed,
59-
(QueryStringCachingBehavior)Enum.Parse(typeof(QueryStringCachingBehavior), CdnEndpoint.QueryStringCachingBehavior.ToString()),
60-
CdnEndpoint.OptimizationType,
61-
CdnEndpoint.ProbePath,
62-
CdnEndpoint.GeoFilters.Select(g => g.ToSdkGeoFilter()).ToList(),
63-
CdnEndpoint.DeliveryPolicy?.ToSdkDeliveryPolicy()));
64-
65-
WriteVerbose(Resources.Success);
66-
WriteObject(endpoint.ToPsEndpoint());
66+
WriteVerbose(Resources.Success);
67+
WriteObject(endpoint.ToPsEndpoint());
68+
}
69+
catch (Microsoft.Azure.Management.Cdn.Models.ErrorResponseException e)
70+
{
71+
throw new PSArgumentException(string.Format("Error response received.Error Message: '{0}'",
72+
e.Response.Content));
73+
}
6774
}
6875
}
6976
}

0 commit comments

Comments
 (0)