diff --git a/src/Testcontainers/Clients/DefaultLabels.cs b/src/Testcontainers/Clients/DefaultLabels.cs index b5e4994fb..f3a54461f 100644 --- a/src/Testcontainers/Clients/DefaultLabels.cs +++ b/src/Testcontainers/Clients/DefaultLabels.cs @@ -2,7 +2,6 @@ namespace DotNet.Testcontainers.Clients { using System.Collections.Generic; using System.Collections.ObjectModel; - using System.Reflection; using DotNet.Testcontainers.Containers; internal sealed class DefaultLabels : ReadOnlyDictionary @@ -16,7 +15,7 @@ private DefaultLabels() { { TestcontainersClient.TestcontainersLabel, bool.TrueString.ToLowerInvariant() }, { TestcontainersClient.TestcontainersLangLabel, "dotnet" }, - { TestcontainersClient.TestcontainersVersionLabel, typeof(DefaultLabels).Assembly.GetCustomAttribute().InformationalVersion }, + { TestcontainersClient.TestcontainersVersionLabel, TestcontainersClient.Version }, { TestcontainersClient.TestcontainersSessionIdLabel, ResourceReaper.DefaultSessionId.ToString("D") }, { ResourceReaper.ResourceReaperSessionLabel, ResourceReaper.DefaultSessionId.ToString("D") }, }) diff --git a/src/Testcontainers/Clients/TestcontainersClient.cs b/src/Testcontainers/Clients/TestcontainersClient.cs index 71cdcce71..002136f32 100644 --- a/src/Testcontainers/Clients/TestcontainersClient.cs +++ b/src/Testcontainers/Clients/TestcontainersClient.cs @@ -4,6 +4,7 @@ namespace DotNet.Testcontainers.Clients using System.Collections.Generic; using System.IO; using System.Linq; + using System.Reflection; using System.Text; using System.Text.RegularExpressions; using System.Threading; @@ -28,6 +29,8 @@ internal sealed class TestcontainersClient : ITestcontainersClient public const string TestcontainersSessionIdLabel = TestcontainersLabel + ".session-id"; + public static readonly string Version = typeof(TestcontainersClient).Assembly.GetCustomAttribute().InformationalVersion; + private static readonly string OSRootDirectory = Path.GetPathRoot(Directory.GetCurrentDirectory()); private static readonly Regex FromLinePattern = new Regex("FROM (?--[^\\s]+\\s)*(?[^\\s]+).*", RegexOptions.None, TimeSpan.FromSeconds(1)); diff --git a/src/Testcontainers/Configurations/AuthConfigs/DockerEndpointAuthenticationConfiguration.cs b/src/Testcontainers/Configurations/AuthConfigs/DockerEndpointAuthenticationConfiguration.cs index 29a1e09ec..7ae894ed0 100644 --- a/src/Testcontainers/Configurations/AuthConfigs/DockerEndpointAuthenticationConfiguration.cs +++ b/src/Testcontainers/Configurations/AuthConfigs/DockerEndpointAuthenticationConfiguration.cs @@ -4,6 +4,7 @@ namespace DotNet.Testcontainers.Configurations using System.Collections.Generic; using System.Collections.ObjectModel; using Docker.DotNet; + using DotNet.Testcontainers.Clients; using JetBrains.Annotations; /// @@ -30,7 +31,12 @@ public DockerEndpointAuthenticationConfiguration(Uri endpoint, Credentials crede /// public DockerClientConfiguration GetDockerClientConfiguration(Guid sessionId = default) { - var defaultHttpRequestHeaders = new ReadOnlyDictionary(new Dictionary { { "x-tc-sid", sessionId.ToString("D") } }); + var defaultHttpRequestHeaders = new ReadOnlyDictionary(new Dictionary + { + { "User-Agent", "tc-dotnet/" + TestcontainersClient.Version }, + { "x-tc-sid", sessionId.ToString("D") }, + }); + return new DockerClientConfiguration(Endpoint, Credentials, defaultHttpRequestHeaders: defaultHttpRequestHeaders); } }