diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index a7cfec28c..24214b73b 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -55,6 +55,7 @@ jobs: - name: Get Logs run: Get-ChildItem -Path . -Include *.log -Recurse | % { Get-Content -Path $_.FullName } shell: pwsh + if: always() - name: Rename Test And Coverage Results run: Get-ChildItem -Path 'test-coverage' -Filter *.xml | Rename-Item -NewName { $_.Name -Replace 'coverage', '${{ matrix.os }}'.ToLower() } diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d6d29d4b..2c8ccea4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ - 516 Add `ITestcontainersBuilder.WithTmpfsMount` (@chrisbbe) - 520 Add MariaDB module (@renemadsen) +### Fixed + +- 525 Read ServerURL, Username and Secret field from CredsStore response to pull private Docker images + ## [2.1.0] ### Added diff --git a/src/Testcontainers/Builders/CredsHelperProvider.cs b/src/Testcontainers/Builders/CredsHelperProvider.cs index 2edf480f7..8bdc7667b 100644 --- a/src/Testcontainers/Builders/CredsHelperProvider.cs +++ b/src/Testcontainers/Builders/CredsHelperProvider.cs @@ -90,20 +90,8 @@ public IDockerRegistryAuthenticationConfiguration GetAuthConfig(string hostname) return null; } - var username = credential.TryGetProperty("Username", out var usernameProperty) ? usernameProperty.GetString() : null; - - var password = credential.TryGetProperty("Secret", out var passwordProperty) ? passwordProperty.GetString() : null; - this.logger.DockerRegistryCredentialFound(hostname); - - if ("".Equals(username, StringComparison.OrdinalIgnoreCase)) - { - return new DockerRegistryAuthenticationConfiguration(hostname, null, null, password); - } - else - { - return new DockerRegistryAuthenticationConfiguration(hostname, username, password); - } + return new DockerRegistryAuthenticationConfiguration(hostname, credential); } } } diff --git a/src/Testcontainers/Builders/CredsStoreProvider.cs b/src/Testcontainers/Builders/CredsStoreProvider.cs index deccc8918..efc84465c 100644 --- a/src/Testcontainers/Builders/CredsStoreProvider.cs +++ b/src/Testcontainers/Builders/CredsStoreProvider.cs @@ -68,12 +68,8 @@ public IDockerRegistryAuthenticationConfiguration GetAuthConfig(string hostname) return null; } - var username = credential.TryGetProperty("Username", out var usernameProperty) ? usernameProperty.GetString() : null; - - var password = credential.TryGetProperty("Secret", out var passwordProperty) ? passwordProperty.GetString() : null; - this.logger.DockerRegistryCredentialFound(hostname); - return new DockerRegistryAuthenticationConfiguration(hostname, username, password); + return new DockerRegistryAuthenticationConfiguration(hostname, credential); } } } diff --git a/src/Testcontainers/Configurations/Images/DockerRegistryAuthenticationConfiguration.cs b/src/Testcontainers/Configurations/Images/DockerRegistryAuthenticationConfiguration.cs index 71da468c4..12e883b34 100644 --- a/src/Testcontainers/Configurations/Images/DockerRegistryAuthenticationConfiguration.cs +++ b/src/Testcontainers/Configurations/Images/DockerRegistryAuthenticationConfiguration.cs @@ -1,5 +1,8 @@ namespace DotNet.Testcontainers.Configurations { + using System; + using System.Text.Json; + /// internal readonly struct DockerRegistryAuthenticationConfiguration : IDockerRegistryAuthenticationConfiguration { @@ -22,6 +25,35 @@ public DockerRegistryAuthenticationConfiguration( this.IdentityToken = identityToken; } + /// + /// Initializes a new instance of the struct. + /// + /// The Docker registry endpoint. + /// The CredHelpers or CredsStore JSON response. + public DockerRegistryAuthenticationConfiguration( + string registryEndpoint, + JsonElement credential) + { + var username = credential.TryGetProperty("Username", out var usernameProperty) ? usernameProperty.GetString() : null; + + var password = credential.TryGetProperty("Secret", out var passwordProperty) ? passwordProperty.GetString() : null; + + if ("".Equals(username, StringComparison.OrdinalIgnoreCase)) + { + this.RegistryEndpoint = registryEndpoint; + this.Username = null; + this.Password = null; + this.IdentityToken = password; + } + else + { + this.RegistryEndpoint = registryEndpoint; + this.Username = username; + this.Password = password; + this.IdentityToken = null; + } + } + /// public string RegistryEndpoint { get; }