-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged PR 41305: Added new set of credential env variables to be used…
… separately for pull and... Added new set of credential env variables to be used separately for pull and push operations. Old set of variables is used for fallback. ---- #### AI description (iteration 1) #### PR Classification New feature: Added support for separate credential environment variables for different registry modes (push, pull, pull from output). #### PR Summary This pull request introduces new environment variables for Docker credentials based on registry modes and updates the relevant classes and tests to support this feature. - `AuthHandshakeMessageHandler.cs`: Added `GetDockerCredentialsFromEnvironment` method to fetch credentials based on registry mode. - `Registry.cs`: Introduced `RegistryMode` enum and updated constructors to handle different registry modes. - `DefaultRegistryAPI.cs`: Updated to use registry mode when creating HTTP clients. - `ContainerHelpers.cs`: Added new constants for push and pull registry credentials. - Added unit tests in `AuthHandshakeMessageHandlerTests.cs` to verify the new credential fetching logic.
- Loading branch information
1 parent
9952265
commit 375e494
Showing
14 changed files
with
179 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/Tests/Microsoft.NET.Build.Containers.UnitTests/AuthHandshakeMessageHandlerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Microsoft.NET.Build.Containers.UnitTests | ||
{ | ||
public class AuthHandshakeMessageHandlerTests | ||
{ | ||
[Theory] | ||
[InlineData("SDK_CONTAINER_REGISTRY_UNAME", "SDK_CONTAINER_REGISTRY_PWORD", (int)RegistryMode.Push)] | ||
[InlineData("DOTNET_CONTAINER_PUSH_REGISTRY_UNAME", "DOTNET_CONTAINER_PUSH_REGISTRY_PWORD", (int)RegistryMode.Push)] | ||
[InlineData("DOTNET_CONTAINER_PULL_REGISTRY_UNAME", "DOTNET_CONTAINER_PULL_REGISTRY_PWORD", (int)RegistryMode.Pull)] | ||
[InlineData("DOTNET_CONTAINER_PULL_REGISTRY_UNAME", "DOTNET_CONTAINER_PULL_REGISTRY_PWORD", (int)RegistryMode.PullFromOutput)] | ||
[InlineData("SDK_CONTAINER_REGISTRY_UNAME", "SDK_CONTAINER_REGISTRY_PWORD", (int)RegistryMode.PullFromOutput)] | ||
public void GetDockerCredentialsFromEnvironment_ReturnsCorrectValues(string unameVarName, string pwordVarName, int mode) | ||
{ | ||
string? originalUnameValue = Environment.GetEnvironmentVariable(unameVarName); | ||
string? originalPwordValue = Environment.GetEnvironmentVariable(pwordVarName); | ||
|
||
Environment.SetEnvironmentVariable(unameVarName, "uname"); | ||
Environment.SetEnvironmentVariable(pwordVarName, "pword"); | ||
|
||
if (AuthHandshakeMessageHandler.GetDockerCredentialsFromEnvironment((RegistryMode)mode) is (string credU, string credP)) | ||
{ | ||
Assert.Equal("uname", credU); | ||
Assert.Equal("pword", credP); | ||
} | ||
else | ||
{ | ||
Assert.Fail("Should have parsed credentials from environment"); | ||
} | ||
|
||
|
||
// restore env variable values | ||
Environment.SetEnvironmentVariable(unameVarName, originalUnameValue); | ||
Environment.SetEnvironmentVariable(pwordVarName, originalPwordValue); | ||
} | ||
} | ||
} |
Oops, something went wrong.