Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions src/Docker.DotNet.X509/CertificateCredentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,38 @@ public HttpMessageHandler ConfigureHandler(HttpMessageHandler handler)
#if NET6_0_OR_GREATER
if (handler is SocketsHttpHandler socketsHandler)
{
socketsHandler.SslOptions.ClientCertificates = new X509Certificate2Collection();
socketsHandler.SslOptions.ClientCertificates.Add(_certificate);
if (_certificate != null)
{
socketsHandler.SslOptions.ClientCertificates = new X509Certificate2Collection();
socketsHandler.SslOptions.ClientCertificates.Add(_certificate);
}

socketsHandler.SslOptions.RemoteCertificateValidationCallback = ServerCertificateValidationCallback;
return socketsHandler;
}
#else
if (handler is HttpClientHandler httpHandler)
{
httpHandler.ClientCertificates.Add(_certificate);
if (_certificate != null && !httpHandler.ClientCertificates.Contains(_certificate))
{
httpHandler.ClientCertificates.Add(_certificate);
}

httpHandler.ServerCertificateCustomValidationCallback = (message, certificate, chain, sslPolicyErrors) => ServerCertificateValidationCallback(message, certificate, chain, sslPolicyErrors);
return httpHandler;
}
#endif
if (handler is not ManagedHandler managedHandler)
if (handler is ManagedHandler managedHandler)
{
return handler;
}
if (_certificate != null && !managedHandler.ClientCertificates.Contains(_certificate))
{
managedHandler.ClientCertificates.Add(_certificate);
}

if (!managedHandler.ClientCertificates.Contains(_certificate))
{
managedHandler.ClientCertificates.Add(_certificate);
managedHandler.ServerCertificateValidationCallback = ServerCertificateValidationCallback;
return managedHandler;
}

managedHandler.ServerCertificateValidationCallback = ServerCertificateValidationCallback;

return handler;
}
}
3 changes: 3 additions & 0 deletions src/Docker.DotNet/DockerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal DockerClient(
_clientOptions = clientOptions;
_hijack = hijack;

Options = clientOptions;
System = new SystemOperations(this);
Containers = new ContainerOperations(this);
Images = new ImageOperations(this);
Expand All @@ -39,6 +40,8 @@ internal DockerClient(
Exec = new ExecOperations(this);
}

public ClientOptions Options { get; }

public ISystemOperations System { get; }

public IContainerOperations Containers { get; }
Expand Down
8 changes: 5 additions & 3 deletions src/Docker.DotNet/DockerClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public DockerClientBuilder()
/// </summary>
/// <param name="version">The requested API version.</param>
/// <returns>The builder instance.</returns>
public DockerClientBuilder WithApiVersion(Version version)
public DockerClientBuilder WithApiVersion(Version? version)
{
ClientOptions = ClientOptions with { ApiVersion = version };
return this;
Expand All @@ -59,9 +59,11 @@ public DockerClientBuilder WithEndpoint(Uri endpoint)
/// </summary>
/// <param name="authProvider">The authentication provider.</param>
/// <returns>The builder instance.</returns>
public DockerClientBuilder WithAuthProvider(IAuthProvider authProvider)
public DockerClientBuilder WithAuthProvider(IAuthProvider? authProvider)
{
ClientOptions = ClientOptions with { AuthProvider = authProvider };
var nonNullableAuthProvider = authProvider ?? NoopAuthProvider.Instance;

ClientOptions = ClientOptions with { AuthProvider = nonNullableAuthProvider };
return this;
}

Expand Down
2 changes: 2 additions & 0 deletions src/Docker.DotNet/IDockerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ namespace Docker.DotNet;

public interface IDockerClient : IDisposable
{
ClientOptions Options { get; }

ISystemOperations System { get; }

IContainerOperations Containers { get; }
Expand Down
Loading