Skip to content

Commit c110abf

Browse files
authored
Acr API version upgrade, support network ruleset, new cmdlets for usage/import image/login (#13237)
* upgrade api version and add missing cmdlets * add connect-azcontainerregistry * remove unused reference * typo * fix import/networkrule * add test for new cmdlet and re-record test for API upgrade * fix local environment * fix debug message filter * use suffix from environment * update help markdown * add help for new cmdlets * add changelog * update common version * add missing help markdown * fix test case * remove white spaces * resolve static analysis errors * remove white spaces * remove classic acr from scenario test * skip classic acr from login * remove network ruleset from new-azcontainerregistry * add data plane SDK to required assemblies * update test case * suppress shared assemblyconflict * fix changelog, remove commented line in scenario test * add assembly * remove classic sku from new-azcontainerregistry * remove storage account name from new-azcontainerregistry * polish change log * resolve shared dependencies issue * add mock for token cache test
1 parent 12b7118 commit c110abf

File tree

55 files changed

+6313
-4397
lines changed

Some content is hidden

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

55 files changed

+6313
-4397
lines changed

src/Accounts/Accounts.Test/ContextCmdletTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,15 @@
3434
using System.Linq;
3535
using Microsoft.Azure.Commands.Common.Authentication.ResourceManager;
3636
using Microsoft.Azure.Commands.Profile.Common;
37+
using Microsoft.Azure.Commands.ScenarioTest.Mocks;
3738

3839
namespace Microsoft.Azure.Commands.Profile.Test
3940
{
4041
public class ContextCmdletTests : RMTestBase
4142
{
4243
private MemoryDataStore dataStore;
4344
private MockCommandRuntime commandRuntimeMock;
45+
private MockPowerShellTokenCacheProvider tokenCacheProviderMock;
4446
const string guid1 = "a0cc8bd7-2c6a-47e9-a4c4-3f6ed136e240";
4547
const string guid2 = "eab635c0-a35a-4f70-9e46-e5351c7b5c8b";
4648
const string guid3 = "52f66548-2550-417b-941e-9d6e04f3ac8d";
@@ -52,6 +54,8 @@ public ContextCmdletTests(ITestOutputHelper output)
5254
AzureSession.Instance.DataStore = dataStore;
5355
commandRuntimeMock = new MockCommandRuntime();
5456
AzureSession.Instance.AuthenticationFactory = new MockTokenAuthenticationFactory();
57+
tokenCacheProviderMock = new MockPowerShellTokenCacheProvider();
58+
AzureSession.Instance.RegisterComponent<PowerShellTokenCacheProvider>(PowerShellTokenCacheProvider.PowerShellTokenCacheProviderKey, () => tokenCacheProviderMock);
5559
Environment.SetEnvironmentVariable("Azure_PS_Data_Collection", "True");
5660
}
5761

src/Accounts/Authentication.ResourceManager/Models/PSAzureEnvironment.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public PSAzureEnvironment(PSObject other)
112112
SqlDatabaseDnsSuffix = other.GetProperty<string>(nameof(SqlDatabaseDnsSuffix));
113113
StorageEndpointSuffix = other.GetProperty<string>(nameof(StorageEndpointSuffix));
114114
TrafficManagerDnsSuffix = other.GetProperty<string>(nameof(TrafficManagerDnsSuffix));
115+
ContainerRegistryEndpointSuffix = other.GetProperty<string>(nameof(ContainerRegistryEndpointSuffix));
115116
AzureOperationalInsightsEndpointResourceId =
116117
other.GetProperty<string>(nameof(AzureOperationalInsightsEndpointResourceId));
117118
AzureOperationalInsightsEndpoint = other.GetProperty<string>(nameof(AzureOperationalInsightsEndpoint));
@@ -246,6 +247,11 @@ public bool OnPremise
246247
/// </summary>
247248
public string AzureKeyVaultServiceEndpointResourceId { get; set; }
248249

250+
/// <summary>
251+
/// The domain name suffix for Azure Container Registry
252+
/// </summary>
253+
public string ContainerRegistryEndpointSuffix { get; set; }
254+
249255
/// <summary>
250256
/// The token audience required for communicating with the Azure Log Analytics query service in this environment
251257
/// </summary>
@@ -374,7 +380,6 @@ public string AzureSynapseAnalyticsEndpointResourceId
374380
/// Gets or sets the Azure Batch AD resource ID.
375381
/// </summary>
376382
public string BatchEndpointResourceId { get; set; }
377-
public string ContainerRegistryEndpointSuffix { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
378383

379384
/// <summary>
380385
/// Determine equality of two PSAzureEnvironment instances.
@@ -408,7 +413,8 @@ public override bool Equals(object obj)
408413
&& AzureOperationalInsightsEndpointResourceId == other.AzureOperationalInsightsEndpointResourceId
409414
&& AzureOperationalInsightsEndpoint == other.AzureOperationalInsightsEndpoint
410415
&& AzureAttestationServiceEndpointResourceId == other.AzureAttestationServiceEndpointResourceId
411-
&& AzureAttestationServiceEndpointSuffix == other.AzureAttestationServiceEndpointSuffix;
416+
&& AzureAttestationServiceEndpointSuffix == other.AzureAttestationServiceEndpointSuffix
417+
&& ContainerRegistryEndpointSuffix == other.ContainerRegistryEndpointSuffix;
412418
}
413419

414420
return false;

src/Accounts/Authentication.Test/AuthenticationFactoryTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
using Xunit;
2929
using Xunit.Abstractions;
30+
using System.Text.RegularExpressions;
3031

3132
namespace Common.Authentication.Test
3233
{
@@ -365,7 +366,9 @@ public void CanAuthenticateUsingMSIObjectId()
365366
[Trait(Category.AcceptanceType, Category.CheckIn)]
366367
void ResponseRedactionWorks()
367368
{
368-
Assert.Equal(" \"access_token\": \"<redacted>\"", GeneralUtilities.TransformBody(" \"access_token\": \"eyJo1234567\""));
369+
IList<Regex> matchers = new List<Regex>();
370+
matchers.Add(new Regex("(\\s*\"access_token\"\\s*:\\s*)\"[^\"]+\""));
371+
Assert.Equal(" \"access_token\": \"<redacted>\"", GeneralUtilities.TransformBody(" \"access_token\": \"eyJo1234567\"", matchers));
369372
Assert.Equal(" \"foo\": \"bar\"", GeneralUtilities.TransformBody(" \"foo\": \"bar\""));
370373
}
371374

src/ContainerRegistry/ContainerRegistry.Test/ContainerRegistry.Test.csproj

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

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Azure.Management.ContainerRegistry" Version="2.0.1" />
14+
<PackageReference Include="Microsoft.Azure.Management.ContainerRegistry" Version="4.0.0" />
15+
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.1.1" />
16+
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.6.0" />
17+
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.6.0">
18+
<NoWarn>NU1608</NoWarn>
19+
</PackageReference>
1520
</ItemGroup>
1621

1722
</Project>

src/ContainerRegistry/ContainerRegistry.Test/ScenarioTests/Common.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ function Get-RandomRegistryName
2121
return 'reg' + (getAssetName)
2222
}
2323

24+
<#
25+
.SYNOPSIS
26+
Gets resource name
27+
#>
28+
function Get-RandomResourceName
29+
{
30+
return 'Resource' + (getAssetName)
31+
}
32+
2433
<#
2534
.SYNOPSIS
2635
Gets resource group name
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
using Microsoft.Azure.Commands.ScenarioTest;
16+
using Microsoft.Azure.ServiceManagement.Common.Models;
17+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
19+
using Xunit;
20+
using Xunit.Abstractions;
21+
22+
namespace Microsoft.Azure.Commands.ContainerRegistry.Test.ScenarioTests
23+
{
24+
public class ContainerRegistryCreateWithNetworkRuleSetTests : RMTestBase
25+
{
26+
public XunitTracingInterceptor _logger;
27+
28+
public ContainerRegistryCreateWithNetworkRuleSetTests(Xunit.Abstractions.ITestOutputHelper output)
29+
{
30+
_logger = new XunitTracingInterceptor(output);
31+
XunitTracingInterceptor.AddToContext(_logger);
32+
TestExecutionHelpers.SetUpSessionAndProfile();
33+
}
34+
35+
[Fact]
36+
[Trait(Category.AcceptanceType, Category.CheckIn)]
37+
public void TestCreateWithNetworkRuleSet()
38+
{
39+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateWithNetworkRuleSet");
40+
}
41+
}
42+
}
43+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
<#
16+
.SYNOPSIS
17+
Test Import-AzContainerRegistryImage.
18+
#>
19+
function Test-CreateWithNetworkRuleSet
20+
{
21+
# Setup
22+
$resourceGroupName = Get-RandomResourceGroupName
23+
$RegistryName = Get-RandomRegistryName
24+
$location = Get-ProviderLocation "Microsoft.ContainerRegistry/registries"
25+
$SubnetName = Get-RandomResourceName
26+
$VnetName = Get-RandomResourceName
27+
28+
try
29+
{
30+
New-AzResourceGroup -Name $resourceGroupName -Location $location
31+
32+
$subnet = New-AzVirtualNetworkSubnetConfig -Name $SubnetName -AddressPrefix "10.0.1.0/24" -ServiceEndpoint "Microsoft.ContainerRegistry"
33+
$vnet = New-AzVirtualNetwork -Name $VnetName -ResourceGroupName $resourceGroupName -Location $location -AddressPrefix "10.0.0.0/16" -Subnet $subnet
34+
$rule = New-AzContainerRegistryNetworkRule -VirtualNetworkRule -VirtualNetworkResourceId $vnet.Subnets[0].Id
35+
$set = Set-AzContainerRegistryNetworkRuleSet -DefaultAction "Allow" -NetworkRule $rule
36+
$registry = New-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $RegistryName -Sku "Premium" -Location $location
37+
$registry = Update-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $RegistryName -NetworkRuleSet $set
38+
39+
$usage = Get-AzContainerRegistryUsage -ResourceGroupName $resourceGroupName -RegistryName $RegistryName
40+
41+
Assert-NotNull $usage
42+
Assert-AreEqual $vnet.Subnets[0].Id $registry.NetworkRuleSet.VirtualNetworkRules[0].VirtualNetworkResourceId
43+
44+
Remove-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $RegistryName
45+
Remove-AzVirtualNetwork -Name $VnetName -ResourceGroupName $resourceGroupName -force
46+
}
47+
finally
48+
{
49+
Remove-AzResourceGroup -Name $resourceGroupName -Force
50+
}
51+
}

src/ContainerRegistry/ContainerRegistry.Test/ScenarioTests/ContainerRegistryTests.ps1

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,6 @@ function Test-AzureContainerRegistry
2828
{
2929
New-AzResourceGroup -Name $resourceGroupName -Location $location
3030

31-
# Creating a container registry with a default new storage account
32-
$classicRegistry = New-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $classicRegistryName -Sku "Classic"
33-
Verify-ContainerRegistry $classicRegistry $resourceGroupName $classicRegistryName "Classic" $null $false
34-
35-
# Check if the registry name already exists
36-
$nameStatus = Test-AzContainerRegistryNameAvailability -Name $classicRegistryName
37-
Assert-True {!$nameStatus.nameAvailable}
38-
Assert-AreEqual "AlreadyExists" $nameStatus.Reason
39-
Assert-AreEqual "The registry $($classicRegistryName) is already in use." $nameStatus.Message
40-
41-
# Create different sku registries
42-
$storageAccountName = $classicRegistry.StorageAccountName
43-
$retrievedRegistry = Get-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $classicRegistryName
44-
Verify-ContainerRegistry $retrievedRegistry $resourceGroupName $classicRegistryName "Classic" $storageAccountName $false
45-
4631
$basicRegistryName = Get-RandomRegistryName
4732
$basicRegistry = New-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $basicRegistryName -Sku "Basic" -EnableAdminUser
4833
Verify-ContainerRegistry $basicRegistry $resourceGroupName $basicRegistryName "Basic" $null $true
@@ -62,42 +47,29 @@ function Test-AzureContainerRegistry
6247

6348
# Get list of container registries under a resource group
6449
$registries = Get-AzContainerRegistry -ResourceGroupName $resourceGroupName
65-
Assert-AreEqual 4 $registries.Count
50+
Assert-AreEqual 3 $registries.Count
6651
foreach($r in $registries)
6752
{
6853
switch($r.SkuName)
6954
{
70-
"Classic" { Verify-ContainerRegistry $r $resourceGroupName $classicRegistryName "Classic" $storageAccountName $false }
7155
"Basic" { Verify-ContainerRegistry $r $resourceGroupName $basicRegistryName "Basic" $null $true }
7256
"Standard" { Verify-ContainerRegistry $r $resourceGroupName $standardRegistryName "Standard" $null $false }
7357
"Premium" { Verify-ContainerRegistry $r $resourceGroupName $premiumRegistryName "Premium" $null $false }
7458
}
7559
}
7660

7761
# Delete container registry
78-
Get-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $classicRegistryName | Remove-AzContainerRegistry
7962
Get-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $standardRegistryName | Remove-AzContainerRegistry
8063
Remove-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $premiumRegistryName
8164
Remove-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $basicRegistryName
8265
$registries = Get-AzContainerRegistry -ResourceGroupName $resourceGroupName
8366
Assert-AreEqual 0 $registries.Count
8467

85-
# Creating a container registry with an existing storage account
86-
$classicRegistryName = Get-RandomRegistryName
87-
$classicRegistry = New-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $classicRegistryName -Sku "Classic" -StorageAccountName $storageAccountName
88-
Verify-ContainerRegistry $classicRegistry $resourceGroupName $classicRegistryName "Classic" $storageAccountName $false
89-
9068
# Creating a premium sku container registry with an existing storage account
9169
$premiumRegistryName = Get-RandomRegistryName
92-
Assert-Error {New-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $premiumRegistryName -Sku "Premium" -StorageAccountName $storageAccountName} "User cannot provide storage account in SKU Premium"
93-
94-
# update classic sku container registry
95-
$updatedClassicRegistry = Update-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $classicRegistryName -EnableAdminUser -StorageAccountName $storageAccountName
96-
Verify-ContainerRegistry $updatedClassicRegistry $resourceGroupName $classicRegistryName "Classic" $storageAccountName $true
9770

9871
# update premium sku container registry with storage account
9972
$premiumRegistry = New-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $premiumRegistryName -Sku "Premium"
100-
Assert-Error {Update-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $premiumRegistryName -EnableAdminUser -StorageAccountName $storageAccountName} "Storage account cannot be updated in SKU Premium"
10173

10274
Get-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $premiumRegistryName | Update-AzContainerRegistry -DisableAdminUser
10375
Verify-ContainerRegistry $premiumRegistry $resourceGroupName $premiumRegistryName "Premium" $null $false
@@ -155,8 +127,6 @@ function Test-AzureContainerRegistryCredential
155127
$location = Get-ProviderLocation "Microsoft.ContainerRegistry/registries"
156128

157129
New-AzResourceGroup -Name $resourceGroupName -Location $location
158-
159-
Test-AzureContainerRegistryCredentialBySku $resourceGroupName $location "Classic"
160130

161131
Test-AzureContainerRegistryCredentialBySku $resourceGroupName $location "Basic"
162132

@@ -207,7 +177,7 @@ function Test-AzureContainerRegistryNameAvailability
207177
$nameStatus = Test-AzContainerRegistryNameAvailability -Name "Microsoft"
208178
Assert-True {!$nameStatus.nameAvailable}
209179
Assert-AreEqual "Invalid" $nameStatus.Reason
210-
Assert-AreEqual "The specified resource name is disallowed" $nameStatus.Message
180+
Assert-AreEqual "The specified resource name is disallowed." $nameStatus.Message
211181
}
212182

213183

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
using Microsoft.Azure.Commands.ScenarioTest;
16+
using Microsoft.Azure.ServiceManagement.Common.Models;
17+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
19+
using Xunit;
20+
using Xunit.Abstractions;
21+
22+
namespace Microsoft.Azure.Commands.ContainerRegistry.Test.ScenarioTests
23+
{
24+
public class ImportImageTests : RMTestBase
25+
{
26+
public XunitTracingInterceptor _logger;
27+
28+
public ImportImageTests(Xunit.Abstractions.ITestOutputHelper output)
29+
{
30+
_logger = new XunitTracingInterceptor(output);
31+
XunitTracingInterceptor.AddToContext(_logger);
32+
TestExecutionHelpers.SetUpSessionAndProfile();
33+
}
34+
35+
[Fact]
36+
[Trait(Category.AcceptanceType, Category.CheckIn)]
37+
public void TestImportImage()
38+
{
39+
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ImportImage");
40+
}
41+
}
42+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
<#
16+
.SYNOPSIS
17+
Test Import-AzContainerRegistryImage.
18+
#>
19+
function Test-ImportImage
20+
{
21+
# Setup
22+
$resourceGroupName = Get-RandomResourceGroupName
23+
$RegistryName = Get-RandomRegistryName
24+
$location = Get-ProviderLocation "Microsoft.ContainerRegistry/registries"
25+
26+
try
27+
{
28+
New-AzResourceGroup -Name $resourceGroupName -Location $location
29+
30+
$registry = New-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $RegistryName -Sku "Basic" -Location $location
31+
32+
$import = Import-AzContainerRegistryImage -SourceImage library/busybox:latest -ResourceGroupName $resourceGroupName -RegistryName $RegistryName -SourceRegistryUri docker.io -TargetTag busybox:latest
33+
34+
Assert-AreEqual $true $import
35+
36+
Remove-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $RegistryName
37+
}
38+
finally
39+
{
40+
Remove-AzResourceGroup -Name $resourceGroupName -Force
41+
}
42+
}

0 commit comments

Comments
 (0)