-
-
Notifications
You must be signed in to change notification settings - Fork 345
Expand file tree
/
Copy pathDockerEndpointAuthenticationConfiguration.cs
More file actions
55 lines (47 loc) · 2.57 KB
/
DockerEndpointAuthenticationConfiguration.cs
File metadata and controls
55 lines (47 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
namespace DotNet.Testcontainers.Configurations
{
using System;
using System.Collections.Generic;
using Docker.DotNet;
using DotNet.Testcontainers.Clients;
using JetBrains.Annotations;
/// <inheritdoc cref="IDockerEndpointAuthenticationConfiguration" />
[PublicAPI]
public readonly struct DockerEndpointAuthenticationConfiguration : IDockerEndpointAuthenticationConfiguration
{
// https://github.com/moby/moby/releases/tag/docker-v29.0.0.
private static readonly Version DockerEngineApi = EnvironmentConfiguration.Instance.GetDockerApiVersion() ?? PropertiesFileConfiguration.Instance.GetDockerApiVersion() ?? new Version(1, 44);
// Since the static `TestcontainersSettings` class holds the detected container
// runtime information from the auto-discovery mechanism, we can't add a static
// `NamedPipeConnectionTimeout` property to it because that would create a
// circular dependency during discovery. To fix this, we either need to split the
// class or stop exposing the `TestcontainersSettings` properties publicly.
// Instead, we could rely only on custom configurations via environment variables
// or the properties file.
private static readonly TimeSpan NamedPipeConnectionTimeout = EnvironmentConfiguration.Instance.GetNamedPipeConnectionTimeout() ?? PropertiesFileConfiguration.Instance.GetNamedPipeConnectionTimeout() ?? TimeSpan.FromSeconds(1);
/// <summary>
/// Initializes a new instance of the <see cref="DockerEndpointAuthenticationConfiguration" /> struct.
/// </summary>
/// <param name="endpoint">The Docker API endpoint.</param>
/// <param name="credentials">The Docker API authentication credentials.</param>
public DockerEndpointAuthenticationConfiguration(Uri endpoint, Credentials credentials = null)
{
Endpoint = endpoint;
Credentials = credentials;
}
/// <inheritdoc />
public Version Version => DockerEngineApi;
/// <inheritdoc />
public Uri Endpoint { get; }
/// <inheritdoc />
public Credentials Credentials { get; }
/// <inheritdoc />
public DockerClientConfiguration GetDockerClientConfiguration(Guid sessionId = default)
{
var defaultHttpRequestHeaders = new Dictionary<string, string>();
defaultHttpRequestHeaders.Add("User-Agent", "tc-dotnet/" + TestcontainersClient.Version);
defaultHttpRequestHeaders.Add("x-tc-sid", sessionId.ToString("D"));
return new DockerClientConfiguration(Endpoint, Credentials, namedPipeConnectTimeout: NamedPipeConnectionTimeout, defaultHttpRequestHeaders: defaultHttpRequestHeaders);
}
}
}