Skip to content

Commit dcc0d9f

Browse files
authored
add exposeToken parameter for Connect-AzContainerRegistry to get the actual token (#24368)
* add exposeToken parameter for Connect-AzContainerRegistry to get the actual token * fix connect-AzcontainerRegistry with token
1 parent 5e19527 commit dcc0d9f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/ContainerRegistry/ContainerRegistry/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
## Upcoming Release
2121
* Upgraded Azure.Core to 1.37.0.
2222
* Fixed vulnerability https://github.com/advisories/GHSA-8g9c-28fc-mcx2
23+
* Added exposeToken parameter for Connect-AzContainerRegistry to get token
2324

2425
## Version 4.1.3
2526
* Fixed bug in `Get-AzContainerRegistryManifest` returns only 100 results [#22922]

src/ContainerRegistry/ContainerRegistry/Commands/ConnectAzureContainerRegistry.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.WindowsAzure.Commands.Utilities.Common;
16+
using Newtonsoft.Json;
1617
using System;
1718
using System.Management.Automation;
1819
using System.Text.RegularExpressions;
@@ -40,6 +41,9 @@ public class ConnectAzureContainerRegistry : ContainerRegistryCmdletBase
4041
[ValidateNotNullOrEmpty]
4142
public string Password { get; set; }
4243

44+
[Parameter(Mandatory = false, ParameterSetName = WithoutNameAndPasswordParameterSet)]
45+
[Parameter(Mandatory = false, ParameterSetName = WithNameAndPasswordParameterSet)]
46+
public SwitchParameter ExposeToken { get; set; }
4347
protected override void InitDebuggingFilter()
4448
{
4549
AddDebuggingFilter(new Regex("(\\s*access_token\\s*=\\s*)[^\"]+"));
@@ -59,7 +63,19 @@ public override void ExecuteCmdlet() {
5963
}
6064

6165
string LoginScript = string.Format("'{2}' | docker login {0} -u {1} --password-stdin", this.RegistryDataPlaneClient.GetEndPoint(), this.UserName, this.Password);
62-
WriteObject(this.ExecuteScript<object>(LoginScript));
66+
if (ExposeToken) {
67+
WriteWarning("You can perform manual login using the provided access token, for example: 'docker login <loginServer> -u 00000000-0000-0000-0000-000000000000 -p <accessToken>'");
68+
var cred = new
69+
{
70+
status = this.ExecuteScript<object>(LoginScript),
71+
loginServer = Name + ".azurecr.io",
72+
accessToken = this.RegistryDataPlaneClient.Authenticate()
73+
};
74+
WriteObject(cred);
75+
} else
76+
{
77+
WriteObject(this.ExecuteScript<object>(LoginScript));
78+
}
6379
}
6480
}
6581
}

0 commit comments

Comments
 (0)