Skip to content

Commit 0e57bf5

Browse files
author
Maddie Clayton
authored
Merge branch 'preview' into policyIdentity
2 parents 7e4b330 + 25f2a12 commit 0e57bf5

File tree

21 files changed

+4413
-8
lines changed

21 files changed

+4413
-8
lines changed

src/ResourceManager/Cdn/Commands.Cdn.Test/Commands.Cdn.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@
125125
<None Include="SessionRecords\Microsoft.Azure.Commands.Cdn.Test.ScenarioTests.ScenarioTest.ProfileTests\TestProfileGetResourceUsage.json">
126126
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
127127
</None>
128+
<None Include="SessionRecords\Microsoft.Azure.Commands.Cdn.Test.ScenarioTests.ScenarioTest.ProfileTests\TestSkuCreate.json">
129+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
130+
</None>
128131
<None Include="SessionRecords\Microsoft.Azure.Commands.Cdn.Test.ScenarioTests.ScenarioTest.EndpointTests\TestEndpointResourceUsage.json">
129132
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
130133
</None>

src/ResourceManager/Cdn/Commands.Cdn.Test/ScenarioTests/ProfileTests.cs

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

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

src/ResourceManager/Cdn/Commands.Cdn.Test/ScenarioTests/ProfileTests.ps1

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,49 @@
1212
# limitations under the License.
1313
# ----------------------------------------------------------------------------------
1414

15+
<#
16+
.SYNOPSIS
17+
Create Profile with different Sku
18+
#>
19+
function Test-SkuCreate
20+
{
21+
$profileName = getAssetName
22+
$resourceGroup = TestSetup-CreateResourceGroup
23+
$profileLocation = "EastUS"
24+
$profileSku = "Standard_Microsoft"
25+
$createdProfile = New-AzureRmCdnProfile -ProfileName $profileName -ResourceGroupName $resourceGroup.ResourceGroupName -Location $profileLocation -Sku $profileSku
26+
27+
Assert-NotNull $createdProfile
28+
Assert-AreEqual $profileName $createdProfile.Name
29+
Assert-AreEqual $resourceGroup.ResourceGroupName $createdProfile.ResourceGroupName
30+
Assert-AreEqual $profileSku $createdProfile.Sku.Name
31+
32+
$profileSku = "Standard_Verizon"
33+
$profileName = getAssetName
34+
$createdProfile = New-AzureRmCdnProfile -ProfileName $profileName -ResourceGroupName $resourceGroup.ResourceGroupName -Location $profileLocation -Sku $profileSku
35+
Assert-NotNull $createdProfile
36+
Assert-AreEqual $profileName $createdProfile.Name
37+
Assert-AreEqual $resourceGroup.ResourceGroupName $createdProfile.ResourceGroupName
38+
Assert-AreEqual $profileSku $createdProfile.Sku.Name
39+
40+
$profileSku = "Premium_Verizon"
41+
$profileName = getAssetName
42+
$createdProfile = New-AzureRmCdnProfile -ProfileName $profileName -ResourceGroupName $resourceGroup.ResourceGroupName -Location $profileLocation -Sku $profileSku
43+
Assert-NotNull $createdProfile
44+
Assert-AreEqual $profileName $createdProfile.Name
45+
Assert-AreEqual $resourceGroup.ResourceGroupName $createdProfile.ResourceGroupName
46+
Assert-AreEqual $profileSku $createdProfile.Sku.Name
47+
48+
$profileSku = "Standard_Akamai"
49+
$profileName = getAssetName
50+
$createdProfile = New-AzureRmCdnProfile -ProfileName $profileName -ResourceGroupName $resourceGroup.ResourceGroupName -Location $profileLocation -Sku $profileSku
51+
Assert-NotNull $createdProfile
52+
Assert-AreEqual $profileName $createdProfile.Name
53+
Assert-AreEqual $resourceGroup.ResourceGroupName $createdProfile.ResourceGroupName
54+
Assert-AreEqual $profileSku $createdProfile.Sku.Name
55+
56+
Remove-AzureRmResourceGroup -Name $resourceGroup.ResourceGroupName -Force
57+
}
1558
<#
1659
.SYNOPSIS
1760
Full Profile CRUD cycle

src/ResourceManager/Cdn/Commands.Cdn.Test/SessionRecords/Microsoft.Azure.Commands.Cdn.Test.ScenarioTests.ScenarioTest.ProfileTests/TestSkuCreate.json

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

src/ResourceManager/Cdn/Commands.Cdn/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Added Standard_Microsoft in Cdn pricing sku.
2122

2223
## Version 5.0.5
2324
* Fixed issue with default resource groups not being set.

src/ResourceManager/Cdn/Commands.Cdn/Models/Profile/PSSkuName.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public enum PSSkuName
2020
Premium_Verizon,
2121
Custom_Verizon,
2222
Standard_Akamai,
23-
Standard_ChinaCdn
23+
Standard_ChinaCdn,
24+
Standard_Microsoft
2425
}
2526
}

src/ResourceManager/Cdn/Commands.Cdn/Profile/NewAzureRmCdnProfile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public class NewAzureRmCdnProfile : AzureCdnCmdletBase
5252
/// <summary>
5353
/// The pricing sku name of the profile.
5454
/// </summary>
55-
[Parameter(Mandatory = true, HelpMessage = "The pricing sku name of the Azure CDN profile. Valid values are StandardVerizon, StandardAkamai, and PremiumVerizon.")]
55+
[Parameter(Mandatory = true, HelpMessage = "The pricing sku name of the Azure CDN profile. Valid values are StandardVerizon, StandardAkamai, Standard_Microsoft and PremiumVerizon.")]
5656
public PSSkuName Sku { get; set; }
5757

5858
/// <summary>

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Commands.Resources.Rest.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<PropertyGroup>
66
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
77
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8-
<ProjectGuid>{E8FFEA7F-A9CB-4FE6-A4D3-9334125B57B4}</ProjectGuid>
8+
<ProjectGuid>{8058D403-06E3-4BED-8924-D166CE303961}</ProjectGuid>
99
<OutputType>Library</OutputType>
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>Microsoft.Azure.Commands.ResourceManager.Cmdlets</RootNamespace>
@@ -139,9 +139,11 @@
139139
<Compile Include="Implementation\ManagedApplications\NewAzureManagedApplication.cs" />
140140
<Compile Include="Implementation\ManagedApplications\ManagedApplicationCmdletBase.cs" />
141141
<Compile Include="Implementation\Policy\GetAzurePolicySetDefinition.cs" />
142+
<Compile Include="Implementation\Policy\GetAzurePolicyAliasCmdlet.cs" />
142143
<Compile Include="Implementation\Policy\PolicyHelpStrings.cs" />
143144
<Compile Include="Implementation\Policy\NewAzurePolicySetDefinition.cs" />
144145
<Compile Include="Implementation\Policy\PolicyCmdletBase.cs" />
146+
<Compile Include="Implementation\Policy\PsResourceProviderAlias.cs" />
145147
<Compile Include="Implementation\Policy\RemoveAzurePolicySetDefinition.cs" />
146148
<Compile Include="Implementation\Policy\SetAzurePolicySetDefinition.cs" />
147149
<Compile Include="Implementation\ResourceGroups\ExportAzureResourceGroupCmdlet.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
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+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
16+
{
17+
using System;
18+
using System.Collections.Generic;
19+
using System.Linq;
20+
using System.Management.Automation;
21+
22+
using Microsoft.Azure.Commands.ResourceManager.Common;
23+
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
24+
using Microsoft.Azure.Management.ResourceManager;
25+
using Microsoft.Azure.Management.ResourceManager.Models;
26+
27+
/// <summary>
28+
/// Get an existing resource.
29+
/// </summary>
30+
[Cmdlet(VerbsCommon.Get, AzureRMConstants.AzureRMPrefix + "PolicyAlias"), OutputType(typeof(PsResourceProviderAlias))]
31+
public class GetAzurePolicyAlias : ResourceManagerCmdletBase
32+
{
33+
/// <summary>
34+
/// Gets or sets the provider namespace match string
35+
/// </summary>
36+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, HelpMessage = "Limits the output to items whose namespace matches this value.")]
37+
[Alias("Name", "Namespace")]
38+
[ValidateNotNullOrEmpty]
39+
public string NamespaceMatch { get; set; } = string.Empty;
40+
41+
/// <summary>
42+
/// Gets or sets the resource type match string
43+
/// </summary>
44+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, HelpMessage = "Limits the output to items whose resource type matches this value.")]
45+
[Alias("ResourceType", "Resource")]
46+
[ValidateNotNullOrEmpty]
47+
public string ResourceTypeMatch { get; set; } = string.Empty;
48+
49+
/// <summary>
50+
/// Gets or sets the alias match string
51+
/// </summary>
52+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, HelpMessage = "Includes in the output items with aliases whose name matches this value.")]
53+
[Alias("Alias")]
54+
[ValidateNotNullOrEmpty]
55+
public string AliasMatch { get; set; } = string.Empty;
56+
57+
/// <summary>
58+
/// Gets or sets the alias path match string
59+
/// </summary>
60+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, HelpMessage = "Includes in the output items with aliases containing a path that matches this value.")]
61+
[Alias("Path")]
62+
[ValidateNotNullOrEmpty]
63+
public string PathMatch { get; set; } = string.Empty;
64+
65+
/// <summary>
66+
/// Gets or sets the api version match string
67+
/// </summary>
68+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, HelpMessage = "Includes in the output items whose resource types or aliases have a matching api version.")]
69+
[ValidateNotNullOrEmpty]
70+
public string ApiVersionMatch { get; set; } = string.Empty;
71+
72+
/// <summary>
73+
/// Gets or sets the alias match string
74+
/// </summary>
75+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, HelpMessage = "Includes in the output items whose resource types have a matching location.")]
76+
[Alias("Location")]
77+
[ValidateNotNullOrEmpty]
78+
[LocationCompleter("Microsoft.Resources/resourceGroups")]
79+
public string LocationMatch { get; set; } = string.Empty;
80+
81+
/// <summary>
82+
/// Gets or sets list available flag
83+
/// </summary>
84+
[Parameter(Mandatory = false, ValueFromPipelineByPropertyName = false, HelpMessage = "Includes in the output matching items with and without aliases.")]
85+
[Alias("ShowAll")]
86+
[ValidateNotNullOrEmpty]
87+
public SwitchParameter ListAvailable { get; set; }
88+
89+
/// <summary>
90+
/// Executes the cmdlet
91+
/// </summary>
92+
public override void ExecuteCmdlet()
93+
{
94+
// remove leading and trailing whitespace
95+
this.NamespaceMatch = this.NamespaceMatch?.Trim() ?? string.Empty;
96+
this.ResourceTypeMatch = this.ResourceTypeMatch?.Trim() ?? string.Empty;
97+
this.AliasMatch = this.AliasMatch?.Trim() ?? string.Empty;
98+
this.PathMatch = this.PathMatch?.Trim() ?? String.Empty;
99+
this.ApiVersionMatch = this.ApiVersionMatch?.Trim() ?? string.Empty;
100+
this.LocationMatch = this.LocationMatch?.Trim() ?? string.Empty;
101+
102+
var resourceTypes = this.GetProviderResourceTypes(this.ListAvailable, this.NamespaceMatch, this.ResourceTypeMatch, this.AliasMatch, this.PathMatch, this.ApiVersionMatch, this.LocationMatch);
103+
this.WriteObject(resourceTypes, enumerateCollection: true);
104+
}
105+
106+
private bool IsStringMatch(string input, string match)
107+
{
108+
return input.IndexOf(match, StringComparison.OrdinalIgnoreCase) >= 0;
109+
}
110+
111+
private bool IsMatch(string input, string match)
112+
{
113+
return string.IsNullOrEmpty(match) || this.IsStringMatch(input, match);
114+
}
115+
116+
private IEnumerable<Provider> GetAllProviders()
117+
{
118+
return this.ResourceManagerSdkClient.ResourceManagementClient.Providers.List(expand: "resourceTypes/aliases");
119+
}
120+
121+
private IEnumerable<Provider> GetMatchingProviders(IEnumerable<Provider> input, string namespaceMatch, string resourceTypeMatch)
122+
{
123+
// Filter the list of all providers to what matches on namespace and resource type
124+
return input.Where(item => this.IsMatch(item.NamespaceProperty, namespaceMatch) && item.ResourceTypes.Any(r => IsMatch(r.ResourceType, resourceTypeMatch)));
125+
}
126+
127+
private bool FilterFunction(ProviderResourceType providerResourceType, bool listAvailable, string resourceTypesMatch, string aliasMatch, string pathMatch, string apiVersionMatch, string locationMatch)
128+
{
129+
return
130+
// if resource type match was provided, the resource type name must match
131+
(string.IsNullOrEmpty(resourceTypesMatch) || this.IsStringMatch(providerResourceType.ResourceType, resourceTypesMatch)) &&
132+
133+
// include everything remaining if list available switch is provided
134+
(listAvailable ||
135+
136+
// otherwise just those with aliases that match the rest of the parameters
137+
providerResourceType.Aliases.Coalesce().Any() &&
138+
139+
// if no match strings provided, include everything
140+
(string.IsNullOrEmpty(locationMatch) && string.IsNullOrEmpty(aliasMatch) && string.IsNullOrEmpty(pathMatch) && string.IsNullOrEmpty(apiVersionMatch) ||
141+
142+
// if location match was provided, include those with matching location
143+
!string.IsNullOrEmpty(locationMatch) && providerResourceType.Locations.Coalesce().Any(l => this.IsStringMatch(l, locationMatch)) ||
144+
145+
// if API match was provided, include those with matching resource type API version
146+
!string.IsNullOrEmpty(apiVersionMatch) && providerResourceType.ApiVersions.Coalesce().Any(v => this.IsStringMatch(v, apiVersionMatch)) ||
147+
148+
// if alias match was provided, include those with matching alias name
149+
!string.IsNullOrEmpty(aliasMatch) && providerResourceType.Aliases.Coalesce().Any(a => this.IsStringMatch(a.Name, aliasMatch)) ||
150+
151+
// if alias path match was provided, includes those with matching path
152+
!string.IsNullOrEmpty(pathMatch) && providerResourceType.Aliases.Coalesce().Any(a => a.Paths.Any(p => this.IsStringMatch(p.Path, pathMatch))) ||
153+
154+
// if API version match was provided, also include those with matching alias API version
155+
!string.IsNullOrEmpty(apiVersionMatch) && providerResourceType.Aliases.Coalesce().Any(a => a.Paths.Coalesce().Any(p => p.ApiVersions.Coalesce().Any(v => this.IsStringMatch(v, apiVersionMatch))))));
156+
}
157+
158+
private IEnumerable<PsResourceProviderAlias> GetProviderResourceTypes(bool listAvailable, string namespaceMatch, string resourceTypeMatch, string aliasMatch, string pathMatch, string apiVersionMatch, string locationMatch)
159+
{
160+
var allProviders = this.GetAllProviders();
161+
var providers = this.GetMatchingProviders(allProviders, namespaceMatch, resourceTypeMatch);
162+
var rv = new List<PsResourceProviderAlias>();
163+
foreach (var provider in providers)
164+
{
165+
var match = provider.ResourceTypes.Where(r => this.FilterFunction(r, listAvailable, resourceTypeMatch, aliasMatch, pathMatch, apiVersionMatch, locationMatch));
166+
rv.AddRange(match.Select(t => new PsResourceProviderAlias {Aliases = t.Aliases, ApiVersions = t.ApiVersions, Locations = t.Locations, Namespace = provider.NamespaceProperty, ResourceType = t.ResourceType}));
167+
}
168+
169+
return rv;
170+
}
171+
}
172+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
16+
{
17+
using System.Collections.Generic;
18+
using Microsoft.Azure.Management.ResourceManager.Models;
19+
using Microsoft.WindowsAzure.Commands.Common.Attributes;
20+
21+
public class PsResourceProviderAlias
22+
{
23+
/// <summary>
24+
/// Gets or sets the namespace of this resource type
25+
/// </summary>
26+
[Ps1Xml(Target = ViewControl.All, Position = 0)]
27+
public string Namespace { get; set; }
28+
29+
/// <summary>
30+
/// Gets or sets the resource type (name) of this resource type
31+
/// </summary>
32+
[Ps1Xml(Target = ViewControl.All, Position = 1)]
33+
public string ResourceType { get; set; }
34+
35+
/// <summary>
36+
/// Gets or sets the collection of locations where this resource type
37+
/// can be created.
38+
/// </summary>
39+
[Ps1Xml(Target = ViewControl.List, Position = 4)]
40+
public IList<string> Locations { get; set; }
41+
42+
/// <summary>
43+
/// Gets or sets the aliases that are supported by this resource type.
44+
/// </summary>
45+
[Ps1Xml(Target = ViewControl.All, Position = 2)]
46+
public IList<AliasType> Aliases { get; set; }
47+
48+
/// <summary>Gets or sets the API version collection.</summary>
49+
[Ps1Xml(Target = ViewControl.List, Position = 3)]
50+
public IList<string> ApiVersions { get; set; }
51+
}
52+
}

src/ResourceManager/Resources/Commands.Resources.Test/Commands.Resources.Test.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@
7676
<Compile Include="ScenarioTests\ManagementGroupsTests.cs" />
7777
<Compile Include="ScenarioTests\MoveResourceTest.cs" />
7878
<Compile Include="ScenarioTests\ManagedApplicationDefinitionTests.cs" />
79+
<Compile Include="ScenarioTests\PolicyAliasTests.cs" />
7980
<Compile Include="ScenarioTests\ProviderFeatureTests.cs" />
81+
<Compile Include="ScenarioTests\ProviderListBuilder.cs" />
8082
<Compile Include="ScenarioTests\ProviderTests.cs" />
8183
<Compile Include="ScenarioTests\ResourcesController.cs" />
8284
<Compile Include="ScenarioTests\DeploymentTests.cs" />

0 commit comments

Comments
 (0)