Skip to content
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

add ACR repository operations #13946

Merged
merged 15 commits into from
Feb 2, 2021
Merged
1 change: 1 addition & 0 deletions src/Accounts/Accounts/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Updated `Clear-AzContext` to clean token cache created by Az.ContainerRegistry
* Shown correct client request id on debug message [#13745]
* Added common Azure PowerShell exception type
* Supported storage API 2019-06-01
Expand Down
12 changes: 12 additions & 0 deletions src/Accounts/Accounts/Context/ClearAzureRmContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.IO;
using System.Management.Automation;

Expand All @@ -21,6 +23,7 @@
using Microsoft.Azure.Commands.Profile.Common;
using Microsoft.Azure.Commands.Profile.Properties;
using Microsoft.Azure.Commands.ResourceManager.Common;
using Microsoft.WindowsAzure.Commands.Common;

namespace Microsoft.Azure.Commands.Profile.Context
{
Expand Down Expand Up @@ -84,6 +87,15 @@ void ClearContext(AzureRmProfile profile, RMProfileClient client)
profile.TrySetDefaultContext(defaultContext);
result = true;
}

VeryEarly marked this conversation as resolved.
Show resolved Hide resolved
//clean token cache created by Az.ContainerRegistry
string AcrTokenCacheKey = SharedComponentKeys.AcrTokenCacheKey;
IDictionary<string, Tuple<string, DateTime>> acrTokenCache;
if (AzureSession.Instance.TryGetComponent(AcrTokenCacheKey, out acrTokenCache))
{
acrTokenCache.Clear();
AzureSession.Instance.UnregisterComponent<IDictionary<string, Tuple<string, DateTime>>>(AcrTokenCacheKey);
}
}

if (PassThru.IsPresent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,16 @@ CmdletsToExport = 'New-AzContainerRegistry', 'Get-AzContainerRegistry',
'Get-AzContainerRegistryWebhookEvent',
'Import-AzContainerRegistryImage', 'Get-AzContainerRegistryUsage',
'Set-AzContainerRegistryNetworkRuleSet',
'New-AzContainerRegistryNetworkRule', 'Connect-AzContainerRegistry'
'New-AzContainerRegistryNetworkRule', 'Connect-AzContainerRegistry',
'Get-AzContainerRegistryRepository',
'Remove-AzContainerRegistryRepository',
'Update-AzContainerRegistryRepository',
'Get-AzContainerRegistryManifest',
'Remove-AzContainerRegistryManifest',
'Update-AzContainerRegistryManifest',
'Get-AzContainerRegistryTag',
'Update-AzContainerRegistryTag',
'Remove-AzContainerRegistryTag'

# Variables to export from this module
# VariablesToExport = @()
Expand Down
10 changes: 10 additions & 0 deletions src/ContainerRegistry/ContainerRegistry/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@
- Additional information about change #1
-->
## Upcoming Release
* Added cmdlets:
VeryEarly marked this conversation as resolved.
Show resolved Hide resolved
- `Get-AzContainerRegistryRepository`
- `Update-AzContainerRegistryRepository`
- `Remove-AzContainerRegistryRepository`
- `Get-AzContainerRegistryManifest`
- `Update-AzContainerRegistryManifest`
- `Remove-AzContainerRegistryManifest`
- `Get-AzContainerRegistryTag`
- `Update-AzContainerRegistryTag`
- `Remove-AzContainerRegistryTag`

## Version 2.1.0
* Supported parameter `Name` for and value from pipeline input for `Get-AzContainerRegistryUsage` [#13605]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,8 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.WindowsAzure.Commands.Common;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text.RegularExpressions;

Expand All @@ -27,8 +23,12 @@ namespace Microsoft.Azure.Commands.ContainerRegistry
[OutputType(typeof(bool))]
public class ConnectAzureContainerRegistry : ContainerRegistryCmdletBase
{
protected const string WithoutNameAndPasswordParameterSet = "WithoutNameAndPasswordParameterSet";
protected const string WithNameAndPasswordParameterSet = "WithNameAndPasswordParameterSet";

[Parameter(Mandatory = true, HelpMessage = "Azure Container Registry Name.", ParameterSetName = WithoutNameAndPasswordParameterSet)]
[Parameter(Mandatory = true, HelpMessage = "Azure Container Registry Name.", ParameterSetName = WithNameAndPasswordParameterSet)]
[Alias("RegistryName")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

Expand All @@ -40,8 +40,6 @@ public class ConnectAzureContainerRegistry : ContainerRegistryCmdletBase
[ValidateNotNullOrEmpty]
public string Password { get; set; }

private RecordingTracingInterceptor _httpTracingInterceptor { get; set; }

protected override void InitDebuggingFilter()
{
AddDebuggingFilter(new Regex("(\\s*access_token\\s*=\\s*)[^\"]+"));
Expand All @@ -57,7 +55,7 @@ public override void ExecuteCmdlet() {
if (ParameterSetName.Equals(WithoutNameAndPasswordParameterSet))
{
this.UserName = new Guid().ToString();
this.Password = this.RegistryDataPlaneClient.GetRefreshToken();
this.Password = this.RegistryDataPlaneClient.TryAuthenticate();
}

string LoginScript = string.Format("'{2}' | docker login {0} -u {1} --password-stdin", this.RegistryDataPlaneClient.GetEndPoint(), this.UserName, this.Password);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// ----------------------------------------------------------------------------------
//
// 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.ContainerRegistry.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.ContainerRegistry
{
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ContainerRegistryRepository", DefaultParameterSetName = ListParameterSet)]
[OutputType(typeof(PSAcrManifest), typeof(PSManifestAttribute))]
public class GetAzureContainerRegistryRepository : ContainerRegistryDataPlaneCmdletBase
{
[Parameter(ParameterSetName = GetParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Repository Name.")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

[Parameter(ParameterSetName = ListParameterSet, Mandatory = false, HelpMessage = "First n results.")]
[ValidateNotNullOrEmpty]
public int? First { get; set; } = null;

public override void ExecuteChildCmdlet()
{
if (this.IsParameterBound(c => c.Name))
{
WriteObject(this.RegistryDataPlaneClient.GetRepository(Name));
}
else
{
WriteObject(this.RegistryDataPlaneClient.ListRepository(First), true);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// ----------------------------------------------------------------------------------
//
// 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.ContainerRegistry.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.ContainerRegistry
{
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ContainerRegistryTag", DefaultParameterSetName = ListParameterSet)]
[OutputType(typeof(PSTagAttribute), typeof(PSTagList))]
public class GetAzureContainerRegistryTag : ContainerRegistryDataPlaneCmdletBase
{
[Parameter(ParameterSetName = ListParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Repository Name.")]
[Parameter(ParameterSetName = GetParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Repository Name.")]
[ValidateNotNullOrEmpty]
public string RepositoryName { get; set; }

[Parameter(ParameterSetName = GetParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Tag.")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

public override void ExecuteChildCmdlet()
{
if (this.IsParameterBound(c => c.Name))
{
WriteObject(this.RegistryDataPlaneClient.GetTag(RepositoryName, Name));
}
else
{
WriteObject(this.RegistryDataPlaneClient.ListTag(RepositoryName), true);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// ----------------------------------------------------------------------------------
//
// 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.ContainerRegistry.Models;
using Microsoft.WindowsAzure.Commands.Utilities.Common;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.ContainerRegistry
{
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ContainerRegistryManifest", DefaultParameterSetName = ListParameterSet)]
[OutputType(typeof(PSManifestAttribute), typeof(PSAcrManifest))]
public class GetAzureContainerRegistryManifest : ContainerRegistryDataPlaneCmdletBase
{
[Parameter(ParameterSetName = ListParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Repository Name.")]
[Parameter(ParameterSetName = GetParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Repository Name.")]
[ValidateNotNullOrEmpty]
public string RepositoryName { get; set; }

[Parameter(ParameterSetName = GetParameterSet, Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Manifest reference.")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

public override void ExecuteChildCmdlet()
{
if (this.IsParameterBound(c => c.Name))
{
WriteObject(this.RegistryDataPlaneClient.GetManifest(RepositoryName, Name));
}
else
{
WriteObject(this.RegistryDataPlaneClient.ListManifest(RepositoryName), true);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// ----------------------------------------------------------------------------------
//
// 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 System.Management.Automation;

namespace Microsoft.Azure.Commands.ContainerRegistry.Commands
{
[Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ContainerRegistryManifest", DefaultParameterSetName = ByManifestParameterSet, SupportsShouldProcess = true)]
[OutputType(typeof(bool))]
public class RemoveAzureContainerRegistryManifest : ContainerRegistryDataPlaneCmdletBase
{
[Parameter(Mandatory = true, ParameterSetName = ByManifestParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = "Repository Name.")]
[Parameter(Mandatory = true, ParameterSetName = ByTagParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = "Repository Name.")]
[ValidateNotNullOrEmpty]
public string RepositoryName { get; set; }

[Parameter(Mandatory = true, ParameterSetName = ByManifestParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = "Manifest reference.")]
[ValidateNotNullOrEmpty]
public string Manifest { get; set; }

[Parameter(Mandatory = true, ParameterSetName = ByTagParameterSet, ValueFromPipelineByPropertyName = true, HelpMessage = "Tag.")]
[ValidateNotNullOrEmpty]
public string Tag { get; set; }

public override void ExecuteChildCmdlet()
{
if (ParameterSetName.Equals(ByManifestParameterSet))
{
if (this.ShouldProcess(string.Format("Delete manitest {0}@{1} under {2}", this.RepositoryName, this.Manifest, this.RegistryName)))
{
WriteObject(this.RegistryDataPlaneClient.RemoveManifest(this.RepositoryName, this.Manifest));
}
}
else if (ParameterSetName.Equals(ByTagParameterSet))
{
if (this.ShouldProcess(string.Format("Delete manitest for {0}:{1} under {2}", this.RepositoryName, this.Tag, this.RegistryName)))
{
WriteObject(this.RegistryDataPlaneClient.RemoveManifestByTag(this.RepositoryName, this.Tag));
}
}
else
{
throw new PSArgumentException("Invalid parameter set");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// ----------------------------------------------------------------------------------
//
// 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.ContainerRegistry.Models;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.ContainerRegistry.Commands
{
[Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ContainerRegistryRepository", SupportsShouldProcess = true)]
[OutputType(typeof(PSDeletedRepository))]
public class RemoveAzureContainerRegistryRepository : ContainerRegistryDataPlaneCmdletBase
{
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Repository Name.")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

public override void ExecuteChildCmdlet()
{
if (this.ShouldProcess(string.Format("Delete {0} under {1}", this.Name, this.RegistryName)))
{
WriteObject(this.RegistryDataPlaneClient.RemoveRepository(this.Name));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ----------------------------------------------------------------------------------
//
// 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 System.Management.Automation;

namespace Microsoft.Azure.Commands.ContainerRegistry.Commands
{
[Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "ContainerRegistryTag", SupportsShouldProcess = true)]
[OutputType(typeof(bool))]
public class RemoveAzureContainerRegistryTag : ContainerRegistryDataPlaneCmdletBase
{
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Repository Name.")]
[ValidateNotNullOrEmpty]
public string RepositoryName { get; set; }

[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "Tag.")]
[ValidateNotNullOrEmpty]
public string Name { get; set; }

public override void ExecuteChildCmdlet()
{
if (this.ShouldProcess(string.Format("Untag {0}:{1} under {2}", this.RepositoryName, this.Name, this.RegistryName)))
{
WriteObject(this.RegistryDataPlaneClient.RemoveTag(this.RepositoryName, this.Name));
}
}
}
}
Loading