-
-
Notifications
You must be signed in to change notification settings - Fork 346
Expand file tree
/
Copy pathTestcontainersEndpointAuthenticationProvider.cs
More file actions
195 lines (165 loc) · 5.17 KB
/
TestcontainersEndpointAuthenticationProvider.cs
File metadata and controls
195 lines (165 loc) · 5.17 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
namespace DotNet.Testcontainers.Builders
{
using System;
using System.Text.Json;
using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Images;
using JetBrains.Annotations;
/// <summary>
/// When configuring the endpoint for a container runtime, the `DOCKER_HOST`
/// environment variable is commonly used. This approach can become messy due to
/// the variety of alternative container runtimes. Even though Testcontainers logs
/// the container runtime that is being used, developers find it difficult to
/// determine which runtime is driving the tests on their environment. If multiple
/// container runtimes are present in a development environment, we prioritize
/// Testcontainers Cloud if it is running.
/// </summary>
[PublicAPI]
internal sealed class TestcontainersEndpointAuthenticationProvider : DockerEndpointAuthenticationProvider, ICustomConfiguration
{
private readonly ICustomConfiguration _customConfiguration;
private readonly Uri _dockerEngine;
/// <summary>
/// Initializes a new instance of the <see cref="TestcontainersEndpointAuthenticationProvider" /> class.
/// </summary>
public TestcontainersEndpointAuthenticationProvider()
: this(new TestcontainersConfiguration())
{
}
/// <summary>
/// Initializes a new instance of the <see cref="TestcontainersEndpointAuthenticationProvider" /> class.
/// </summary>
/// <param name="lines">A list of Java properties file lines.</param>
public TestcontainersEndpointAuthenticationProvider(params string[] lines)
: this(new TestcontainersConfiguration(lines))
{
}
private TestcontainersEndpointAuthenticationProvider(ICustomConfiguration customConfiguration)
{
_customConfiguration = customConfiguration;
_dockerEngine = customConfiguration.GetDockerHost();
}
/// <inheritdoc />
public override bool IsApplicable()
{
return _dockerEngine != null && "tcp".Equals(_dockerEngine.Scheme, StringComparison.OrdinalIgnoreCase);
}
/// <inheritdoc />
public override IDockerEndpointAuthenticationConfiguration GetAuthConfig()
{
return new DockerEndpointAuthenticationConfiguration(_dockerEngine);
}
/// <inheritdoc />
public Version GetDockerApiVersion()
{
return _customConfiguration.GetDockerApiVersion();
}
/// <inheritdoc />
public string GetDockerConfig()
{
return _customConfiguration.GetDockerConfig();
}
/// <inheritdoc />
public Uri GetDockerHost()
{
return _customConfiguration.GetDockerHost();
}
/// <inheritdoc />
public string GetDockerContext()
{
return _customConfiguration.GetDockerContext();
}
/// <inheritdoc />
public string GetDockerHostOverride()
{
return _customConfiguration.GetDockerHostOverride();
}
/// <inheritdoc />
public string GetDockerSocketOverride()
{
return _customConfiguration.GetDockerSocketOverride();
}
/// <inheritdoc />
public JsonDocument GetDockerAuthConfig()
{
return _customConfiguration.GetDockerAuthConfig();
}
/// <inheritdoc />
public string GetDockerCertPath()
{
return _customConfiguration.GetDockerCertPath();
}
/// <inheritdoc />
public bool GetDockerTls()
{
return _customConfiguration.GetDockerTls();
}
/// <inheritdoc />
public bool GetDockerTlsVerify()
{
return _customConfiguration.GetDockerTlsVerify();
}
/// <inheritdoc />
public bool GetRyukDisabled()
{
return _customConfiguration.GetRyukDisabled();
}
/// <inheritdoc />
public bool? GetRyukContainerPrivileged()
{
return _customConfiguration.GetRyukContainerPrivileged();
}
/// <inheritdoc />
public IImage GetRyukContainerImage()
{
return _customConfiguration.GetRyukContainerImage();
}
/// <inheritdoc />
public string GetHubImageNamePrefix()
{
return _customConfiguration.GetHubImageNamePrefix();
}
/// <inheritdoc />
public ushort? GetWaitStrategyRetries()
{
return _customConfiguration.GetWaitStrategyRetries();
}
/// <inheritdoc />
public TimeSpan? GetWaitStrategyInterval()
{
return _customConfiguration.GetWaitStrategyInterval();
}
/// <inheritdoc />
public TimeSpan? GetWaitStrategyTimeout()
{
return _customConfiguration.GetWaitStrategyTimeout();
}
/// <inheritdoc />
public TimeSpan? GetNamedPipeConnectionTimeout()
{
return _customConfiguration.GetNamedPipeConnectionTimeout();
}
private sealed class TestcontainersConfiguration : PropertiesFileConfiguration
{
public TestcontainersConfiguration()
{
}
public TestcontainersConfiguration(params string[] lines)
: base(lines)
{
}
protected override Uri GetDockerHost(string propertyName)
{
return base.GetDockerHost("tc.host");
}
protected override string GetDockerHostOverride(string propertyName)
{
return null;
}
protected override string GetDockerSocketOverride(string propertyName)
{
return null;
}
}
}
}