Skip to content

Commit

Permalink
[#370] #UPDATE 'assemblyName: DotNet.Testcontainers; refactor: IAuthe…
Browse files Browse the repository at this point in the history
…nticationProvider'

{Prepare the authentication provider for different configurations.}
  • Loading branch information
HofmeisterAn committed Jun 6, 2022
1 parent 88eca9b commit d535f16
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/DotNet.Testcontainers/Builders/Base64Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;

/// <inheritdoc cref="IAuthenticationProvider" />
internal sealed class Base64Provider : IAuthenticationProvider
/// <inheritdoc cref="IAuthenticationProvider{TAuthenticationConfiguration}" />
internal sealed class Base64Provider : IAuthenticationProvider<IDockerRegistryAuthenticationConfiguration>
{
private readonly JsonElement rootElement;

Expand Down
4 changes: 2 additions & 2 deletions src/DotNet.Testcontainers/Builders/CredsHelperProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{
using DotNet.Testcontainers.Configurations;

/// <inheritdoc cref="IAuthenticationProvider" />
internal sealed class CredsHelperProvider : IAuthenticationProvider
/// <inheritdoc cref="IAuthenticationProvider{TAuthenticationConfiguration}" />
internal sealed class CredsHelperProvider : IAuthenticationProvider<IDockerRegistryAuthenticationConfiguration>
{
/// <inheritdoc />
public bool IsApplicable()
Expand Down
4 changes: 2 additions & 2 deletions src/DotNet.Testcontainers/Builders/CredsStoreProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;

/// <inheritdoc cref="IAuthenticationProvider" />
internal sealed class CredsStoreProvider : IAuthenticationProvider
/// <inheritdoc cref="IAuthenticationProvider{TAuthenticationConfiguration}" />
internal sealed class CredsStoreProvider : IAuthenticationProvider<IDockerRegistryAuthenticationConfiguration>
{
private static readonly JsonSerializerOptions JsonSerializerOptions = new JsonSerializerOptions();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;

/// <inheritdoc />
internal sealed class DockerRegistryAuthenticationProvider : IAuthenticationProvider
/// <inheritdoc cref="IAuthenticationProvider{TAuthenticationConfiguration}" />
internal sealed class DockerRegistryAuthenticationProvider : IAuthenticationProvider<IDockerRegistryAuthenticationConfiguration>
{
private const string DockerHub = "index.docker.io";

Expand Down Expand Up @@ -81,7 +81,7 @@ private IDockerRegistryAuthenticationConfiguration GetUncachedAuthConfig(string
{
using (var dockerConfigDocument = JsonDocument.Parse(dockerConfigFileStream))
{
authConfig = new IAuthenticationProvider[] { new CredsHelperProvider(), new CredsStoreProvider(dockerConfigDocument, this.logger), new Base64Provider(dockerConfigDocument, this.logger) }
authConfig = new IAuthenticationProvider<IDockerRegistryAuthenticationConfiguration>[] { new CredsHelperProvider(), new CredsStoreProvider(dockerConfigDocument, this.logger), new Base64Provider(dockerConfigDocument, this.logger) }
.AsParallel()
.Select(authenticationProvider => authenticationProvider.GetAuthConfig(hostname))
.FirstOrDefault(authenticationProvider => authenticationProvider != null);
Expand Down
14 changes: 7 additions & 7 deletions src/DotNet.Testcontainers/Builders/IAuthenticationProvider.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
namespace DotNet.Testcontainers.Builders
{
using DotNet.Testcontainers.Configurations;
using JetBrains.Annotations;

/// <summary>
/// A Docker registry authentication provider.
/// A Docker authentication provider.
/// </summary>
/// <typeparam name="TAuthenticationConfiguration">Type of the authentication configuration.</typeparam>
[PublicAPI]
internal interface IAuthenticationProvider
internal interface IAuthenticationProvider<out TAuthenticationConfiguration>
{
/// <summary>
/// Is true when the authentication provider contains any credentials, otherwise false.
Expand All @@ -17,12 +17,12 @@ internal interface IAuthenticationProvider
bool IsApplicable();

/// <summary>
/// Gets the Docker registry authentication configuration.
/// Gets the Docker authentication configuration.
/// </summary>
/// <param name="hostname">The Docker registry hostname.</param>
/// <returns>The Docker registry authentication configuration or null if no configuration matches the hostname.</returns>
/// <param name="hostname">The Docker hostname.</param>
/// <returns>The Docker authentication configuration or null if no configuration matches the hostname.</returns>
[PublicAPI]
[CanBeNull]
IDockerRegistryAuthenticationConfiguration GetAuthConfig(string hostname);
TAuthenticationConfiguration GetAuthConfig(string hostname);
}
}

0 comments on commit d535f16

Please sign in to comment.