Skip to content

Acr API version upgrade, support network ruleset, new cmdlets for usage/import image/login #13237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
7a43e01
upgrade api version and add missing cmdlets
VeryEarly Aug 11, 2020
d1e295d
Merge branch 'master' into acr-upgrade
VeryEarly Aug 11, 2020
566444f
Merge branch 'master' of https://github.com/Azure/azure-powershell in…
VeryEarly Sep 14, 2020
d5c0b3b
add connect-azcontainerregistry
VeryEarly Sep 27, 2020
0263959
remove unused reference
VeryEarly Sep 28, 2020
6a927b6
Merge branch 'master' into acr-upgrade
VeryEarly Sep 28, 2020
1f7b542
typo
VeryEarly Sep 28, 2020
01634f7
fix import/networkrule
VeryEarly Oct 13, 2020
d9a835e
add test for new cmdlet and re-record test for API upgrade
VeryEarly Oct 14, 2020
58f1a97
fix local environment
VeryEarly Oct 15, 2020
3131c16
fix debug message filter
VeryEarly Oct 15, 2020
766e313
use suffix from environment
VeryEarly Oct 15, 2020
eed7c11
update help markdown
VeryEarly Oct 16, 2020
9220e92
add help for new cmdlets
VeryEarly Oct 16, 2020
1364cb2
add changelog
VeryEarly Oct 16, 2020
9f6ace8
update common version
VeryEarly Oct 16, 2020
d34eb73
add missing help markdown
VeryEarly Oct 16, 2020
182414b
fix test case
VeryEarly Oct 16, 2020
fc0ca67
remove white spaces
VeryEarly Oct 16, 2020
622475e
resolve static analysis errors
VeryEarly Oct 16, 2020
5572b06
remove white spaces
VeryEarly Oct 19, 2020
7b18206
remove classic acr from scenario test
VeryEarly Oct 19, 2020
a17c7d5
skip classic acr from login
VeryEarly Oct 19, 2020
c9cb9d0
remove network ruleset from new-azcontainerregistry
VeryEarly Oct 19, 2020
5f2a1e6
add data plane SDK to required assemblies
VeryEarly Oct 19, 2020
266264b
update test case
VeryEarly Oct 19, 2020
9a66ce5
suppress shared assemblyconflict
VeryEarly Oct 19, 2020
8504c25
fix changelog, remove commented line in scenario test
VeryEarly Oct 19, 2020
f51cc8c
add assembly
VeryEarly Oct 19, 2020
490dd63
remove classic sku from new-azcontainerregistry
VeryEarly Oct 19, 2020
8e2c153
remove storage account name from new-azcontainerregistry
VeryEarly Oct 20, 2020
5eef292
polish change log
VeryEarly Oct 20, 2020
62ccdaf
resolve shared dependencies issue
VeryEarly Oct 20, 2020
a2f81a8
merge master
VeryEarly Oct 20, 2020
c52e8d3
add mock for token cache test
VeryEarly Oct 20, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Accounts/Accounts.Test/ContextCmdletTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
using System.Linq;
using Microsoft.Azure.Commands.Common.Authentication.ResourceManager;
using Microsoft.Azure.Commands.Profile.Common;
using Microsoft.Azure.Commands.ScenarioTest.Mocks;

namespace Microsoft.Azure.Commands.Profile.Test
{
public class ContextCmdletTests : RMTestBase
{
private MemoryDataStore dataStore;
private MockCommandRuntime commandRuntimeMock;
private MockPowerShellTokenCacheProvider tokenCacheProviderMock;
const string guid1 = "a0cc8bd7-2c6a-47e9-a4c4-3f6ed136e240";
const string guid2 = "eab635c0-a35a-4f70-9e46-e5351c7b5c8b";
const string guid3 = "52f66548-2550-417b-941e-9d6e04f3ac8d";
Expand All @@ -52,6 +54,8 @@ public ContextCmdletTests(ITestOutputHelper output)
AzureSession.Instance.DataStore = dataStore;
commandRuntimeMock = new MockCommandRuntime();
AzureSession.Instance.AuthenticationFactory = new MockTokenAuthenticationFactory();
tokenCacheProviderMock = new MockPowerShellTokenCacheProvider();
AzureSession.Instance.RegisterComponent<PowerShellTokenCacheProvider>(PowerShellTokenCacheProvider.PowerShellTokenCacheProviderKey, () => tokenCacheProviderMock);
Environment.SetEnvironmentVariable("Azure_PS_Data_Collection", "True");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public PSAzureEnvironment(PSObject other)
SqlDatabaseDnsSuffix = other.GetProperty<string>(nameof(SqlDatabaseDnsSuffix));
StorageEndpointSuffix = other.GetProperty<string>(nameof(StorageEndpointSuffix));
TrafficManagerDnsSuffix = other.GetProperty<string>(nameof(TrafficManagerDnsSuffix));
ContainerRegistryEndpointSuffix = other.GetProperty<string>(nameof(ContainerRegistryEndpointSuffix));
AzureOperationalInsightsEndpointResourceId =
other.GetProperty<string>(nameof(AzureOperationalInsightsEndpointResourceId));
AzureOperationalInsightsEndpoint = other.GetProperty<string>(nameof(AzureOperationalInsightsEndpoint));
Expand Down Expand Up @@ -246,6 +247,11 @@ public bool OnPremise
/// </summary>
public string AzureKeyVaultServiceEndpointResourceId { get; set; }

/// <summary>
/// The domain name suffix for Azure Container Registry
/// </summary>
public string ContainerRegistryEndpointSuffix { get; set; }

/// <summary>
/// The token audience required for communicating with the Azure Log Analytics query service in this environment
/// </summary>
Expand Down Expand Up @@ -374,7 +380,6 @@ public string AzureSynapseAnalyticsEndpointResourceId
/// Gets or sets the Azure Batch AD resource ID.
/// </summary>
public string BatchEndpointResourceId { get; set; }
public string ContainerRegistryEndpointSuffix { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }

/// <summary>
/// Determine equality of two PSAzureEnvironment instances.
Expand Down Expand Up @@ -408,7 +413,8 @@ public override bool Equals(object obj)
&& AzureOperationalInsightsEndpointResourceId == other.AzureOperationalInsightsEndpointResourceId
&& AzureOperationalInsightsEndpoint == other.AzureOperationalInsightsEndpoint
&& AzureAttestationServiceEndpointResourceId == other.AzureAttestationServiceEndpointResourceId
&& AzureAttestationServiceEndpointSuffix == other.AzureAttestationServiceEndpointSuffix;
&& AzureAttestationServiceEndpointSuffix == other.AzureAttestationServiceEndpointSuffix
&& ContainerRegistryEndpointSuffix == other.ContainerRegistryEndpointSuffix;
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

using Xunit;
using Xunit.Abstractions;
using System.Text.RegularExpressions;

namespace Common.Authentication.Test
{
Expand Down Expand Up @@ -365,7 +366,9 @@ public void CanAuthenticateUsingMSIObjectId()
[Trait(Category.AcceptanceType, Category.CheckIn)]
void ResponseRedactionWorks()
{
Assert.Equal(" \"access_token\": \"<redacted>\"", GeneralUtilities.TransformBody(" \"access_token\": \"eyJo1234567\""));
IList<Regex> matchers = new List<Regex>();
matchers.Add(new Regex("(\\s*\"access_token\"\\s*:\\s*)\"[^\"]+\""));
Assert.Equal(" \"access_token\": \"<redacted>\"", GeneralUtilities.TransformBody(" \"access_token\": \"eyJo1234567\"", matchers));
Assert.Equal(" \"foo\": \"bar\"", GeneralUtilities.TransformBody(" \"foo\": \"bar\""));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.ContainerRegistry" Version="2.0.1" />
<PackageReference Include="Microsoft.Azure.Management.ContainerRegistry" Version="4.0.0" />
<PackageReference Include="Microsoft.Azure.Management.Network" Version="20.1.1" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="5.6.0" />
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="5.6.0">
<NoWarn>NU1608</NoWarn>
</PackageReference>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ function Get-RandomRegistryName
return 'reg' + (getAssetName)
}

<#
.SYNOPSIS
Gets resource name
#>
function Get-RandomResourceName
{
return 'Resource' + (getAssetName)
}

<#
.SYNOPSIS
Gets resource group name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// ----------------------------------------------------------------------------------
//
// 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.ScenarioTest;
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.Azure.Commands.ContainerRegistry.Test.ScenarioTests
{
public class ContainerRegistryCreateWithNetworkRuleSetTests : RMTestBase
{
public XunitTracingInterceptor _logger;

public ContainerRegistryCreateWithNetworkRuleSetTests(Xunit.Abstractions.ITestOutputHelper output)
{
_logger = new XunitTracingInterceptor(output);
XunitTracingInterceptor.AddToContext(_logger);
TestExecutionHelpers.SetUpSessionAndProfile();
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestCreateWithNetworkRuleSet()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-CreateWithNetworkRuleSet");
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# ----------------------------------------------------------------------------------
#
# 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.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Test Import-AzContainerRegistryImage.
#>
function Test-CreateWithNetworkRuleSet
{
# Setup
$resourceGroupName = Get-RandomResourceGroupName
$RegistryName = Get-RandomRegistryName
$location = Get-ProviderLocation "Microsoft.ContainerRegistry/registries"
$SubnetName = Get-RandomResourceName
$VnetName = Get-RandomResourceName

try
{
New-AzResourceGroup -Name $resourceGroupName -Location $location

$subnet = New-AzVirtualNetworkSubnetConfig -Name $SubnetName -AddressPrefix "10.0.1.0/24" -ServiceEndpoint "Microsoft.ContainerRegistry"
$vnet = New-AzVirtualNetwork -Name $VnetName -ResourceGroupName $resourceGroupName -Location $location -AddressPrefix "10.0.0.0/16" -Subnet $subnet
$rule = New-AzContainerRegistryNetworkRule -VirtualNetworkRule -VirtualNetworkResourceId $vnet.Subnets[0].Id
$set = Set-AzContainerRegistryNetworkRuleSet -DefaultAction "Allow" -NetworkRule $rule
$registry = New-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $RegistryName -Sku "Premium" -Location $location
$registry = Update-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $RegistryName -NetworkRuleSet $set

$usage = Get-AzContainerRegistryUsage -ResourceGroupName $resourceGroupName -RegistryName $RegistryName

Assert-NotNull $usage
Assert-AreEqual $vnet.Subnets[0].Id $registry.NetworkRuleSet.VirtualNetworkRules[0].VirtualNetworkResourceId

Remove-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $RegistryName
Remove-AzVirtualNetwork -Name $VnetName -ResourceGroupName $resourceGroupName -force
}
finally
{
Remove-AzResourceGroup -Name $resourceGroupName -Force
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,6 @@ function Test-AzureContainerRegistry
{
New-AzResourceGroup -Name $resourceGroupName -Location $location

# Creating a container registry with a default new storage account
$classicRegistry = New-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $classicRegistryName -Sku "Classic"
Verify-ContainerRegistry $classicRegistry $resourceGroupName $classicRegistryName "Classic" $null $false

# Check if the registry name already exists
$nameStatus = Test-AzContainerRegistryNameAvailability -Name $classicRegistryName
Assert-True {!$nameStatus.nameAvailable}
Assert-AreEqual "AlreadyExists" $nameStatus.Reason
Assert-AreEqual "The registry $($classicRegistryName) is already in use." $nameStatus.Message

# Create different sku registries
$storageAccountName = $classicRegistry.StorageAccountName
$retrievedRegistry = Get-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $classicRegistryName
Verify-ContainerRegistry $retrievedRegistry $resourceGroupName $classicRegistryName "Classic" $storageAccountName $false

$basicRegistryName = Get-RandomRegistryName
$basicRegistry = New-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $basicRegistryName -Sku "Basic" -EnableAdminUser
Verify-ContainerRegistry $basicRegistry $resourceGroupName $basicRegistryName "Basic" $null $true
Expand All @@ -62,42 +47,29 @@ function Test-AzureContainerRegistry

# Get list of container registries under a resource group
$registries = Get-AzContainerRegistry -ResourceGroupName $resourceGroupName
Assert-AreEqual 4 $registries.Count
Assert-AreEqual 3 $registries.Count
foreach($r in $registries)
{
switch($r.SkuName)
{
"Classic" { Verify-ContainerRegistry $r $resourceGroupName $classicRegistryName "Classic" $storageAccountName $false }
"Basic" { Verify-ContainerRegistry $r $resourceGroupName $basicRegistryName "Basic" $null $true }
"Standard" { Verify-ContainerRegistry $r $resourceGroupName $standardRegistryName "Standard" $null $false }
"Premium" { Verify-ContainerRegistry $r $resourceGroupName $premiumRegistryName "Premium" $null $false }
}
}

# Delete container registry
Get-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $classicRegistryName | Remove-AzContainerRegistry
Get-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $standardRegistryName | Remove-AzContainerRegistry
Remove-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $premiumRegistryName
Remove-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $basicRegistryName
$registries = Get-AzContainerRegistry -ResourceGroupName $resourceGroupName
Assert-AreEqual 0 $registries.Count

# Creating a container registry with an existing storage account
$classicRegistryName = Get-RandomRegistryName
$classicRegistry = New-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $classicRegistryName -Sku "Classic" -StorageAccountName $storageAccountName
Verify-ContainerRegistry $classicRegistry $resourceGroupName $classicRegistryName "Classic" $storageAccountName $false

# Creating a premium sku container registry with an existing storage account
$premiumRegistryName = Get-RandomRegistryName
Assert-Error {New-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $premiumRegistryName -Sku "Premium" -StorageAccountName $storageAccountName} "User cannot provide storage account in SKU Premium"

# update classic sku container registry
$updatedClassicRegistry = Update-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $classicRegistryName -EnableAdminUser -StorageAccountName $storageAccountName
Verify-ContainerRegistry $updatedClassicRegistry $resourceGroupName $classicRegistryName "Classic" $storageAccountName $true

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

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

New-AzResourceGroup -Name $resourceGroupName -Location $location

Test-AzureContainerRegistryCredentialBySku $resourceGroupName $location "Classic"

Test-AzureContainerRegistryCredentialBySku $resourceGroupName $location "Basic"

Expand Down Expand Up @@ -207,7 +177,7 @@ function Test-AzureContainerRegistryNameAvailability
$nameStatus = Test-AzContainerRegistryNameAvailability -Name "Microsoft"
Assert-True {!$nameStatus.nameAvailable}
Assert-AreEqual "Invalid" $nameStatus.Reason
Assert-AreEqual "The specified resource name is disallowed" $nameStatus.Message
Assert-AreEqual "The specified resource name is disallowed." $nameStatus.Message
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// ----------------------------------------------------------------------------------
//
// 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.ScenarioTest;
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.Azure.Commands.ContainerRegistry.Test.ScenarioTests
{
public class ImportImageTests : RMTestBase
{
public XunitTracingInterceptor _logger;

public ImportImageTests(Xunit.Abstractions.ITestOutputHelper output)
{
_logger = new XunitTracingInterceptor(output);
XunitTracingInterceptor.AddToContext(_logger);
TestExecutionHelpers.SetUpSessionAndProfile();
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestImportImage()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ImportImage");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# ----------------------------------------------------------------------------------
#
# 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.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Test Import-AzContainerRegistryImage.
#>
function Test-ImportImage
{
# Setup
$resourceGroupName = Get-RandomResourceGroupName
$RegistryName = Get-RandomRegistryName
$location = Get-ProviderLocation "Microsoft.ContainerRegistry/registries"

try
{
New-AzResourceGroup -Name $resourceGroupName -Location $location

$registry = New-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $RegistryName -Sku "Basic" -Location $location

$import = Import-AzContainerRegistryImage -SourceImage library/busybox:latest -ResourceGroupName $resourceGroupName -RegistryName $RegistryName -SourceRegistryUri docker.io -TargetTag busybox:latest

Assert-AreEqual $true $import

Remove-AzContainerRegistry -ResourceGroupName $resourceGroupName -Name $RegistryName
}
finally
{
Remove-AzResourceGroup -Name $resourceGroupName -Force
}
}
Loading