Skip to content

Commit b5c926a

Browse files
entvexDavid Jensen
and
David Jensen
authored
chore: Remove PulsarContainer.CreateAuthenticationTokenAsync(TimeSpan) default arg (#1195)
Co-authored-by: David Jensen <djn@danskecommodities.com>
1 parent 56d3eab commit b5c926a

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

docs/modules/pulsar.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,20 @@ If you need to use token authentication, use the following builder configuration
9292
PulsarContainer _pulsarContainer = PulsarBuilder().WithTokenAuthentication().Build();
9393
```
9494

95-
Start the container and get the token from the running instance by using:
95+
Start the container and obtain an authentication token with a specified expiration time
9696

9797
```csharp
9898
var authToken = await container.CreateAuthenticationTokenAsync(TimeSpan.FromHours(1))
9999
.ConfigureAwait(false);
100100
```
101101

102+
Alternatively, set the token to never expire
103+
104+
```csharp
105+
var authToken = await container.CreateAuthenticationTokenAsync(Timeout.InfiniteTimeSpan)
106+
.ConfigureAwait(false);
107+
```
108+
102109
## Enable Pulsar Functions
103110

104111
If you need to use Pulsar Functions, use the following builder configuration to enable it:

src/Testcontainers.Pulsar/PulsarContainer.cs

+21-19
Original file line numberDiff line numberDiff line change
@@ -37,42 +37,44 @@ public string GetServiceAddress()
3737
/// <summary>
3838
/// Creates an authentication token.
3939
/// </summary>
40-
/// <param name="expire">The time after the authentication token expires.</param>
40+
/// <param name="expiryTime">The time after the authentication token expires.</param>
4141
/// <param name="ct">Cancellation token.</param>
4242
/// <returns>A task that completes when the authentication token has been created.</returns>
4343
/// <exception cref="ArgumentException"></exception>
44-
public async Task<string> CreateAuthenticationTokenAsync(TimeSpan expire = default, CancellationToken ct = default)
44+
public async Task<string> CreateAuthenticationTokenAsync(TimeSpan expiryTime, CancellationToken ct = default)
4545
{
46-
int secondsToMilliseconds;
47-
4846
if (_configuration.AuthenticationEnabled.HasValue && !_configuration.AuthenticationEnabled.Value)
4947
{
5048
throw new ArgumentException("Failed to create token. Authentication is not enabled.");
5149
}
52-
53-
if (_configuration.Image.Tag.StartsWith("3.2") || _configuration.Image.Tag.StartsWith("latest"))
54-
{
55-
Logger.LogWarning("The 'apachepulsar/pulsar:3.2.?' image contains a regression. The expiry time is converted to the wrong unit of time: https://github.com/apache/pulsar/issues/22811.");
56-
secondsToMilliseconds = 1000;
57-
}
58-
else
59-
{
60-
secondsToMilliseconds = 1;
61-
}
62-
63-
var command = new[]
50+
51+
var command = new List<string>(9)
6452
{
6553
"bin/pulsar",
6654
"tokens",
6755
"create",
6856
"--secret-key",
6957
PulsarBuilder.SecretKeyFilePath,
7058
"--subject",
71-
PulsarBuilder.Username,
72-
"--expiry-time",
73-
$"{secondsToMilliseconds * expire.TotalSeconds}s",
59+
PulsarBuilder.Username
7460
};
7561

62+
if (expiryTime != Timeout.InfiniteTimeSpan)
63+
{
64+
int secondsToMilliseconds;
65+
if (_configuration.Image.Tag.StartsWith("3.2") || _configuration.Image.Tag.StartsWith("latest"))
66+
{
67+
Logger.LogWarning("The 'apachepulsar/pulsar:3.2.?' image contains a regression. The expiry time is converted to the wrong unit of time: https://github.com/apache/pulsar/issues/22811.");
68+
secondsToMilliseconds = 1000;
69+
}
70+
else
71+
{
72+
secondsToMilliseconds = 1;
73+
}
74+
command.Add("--expiry-time");
75+
command.Add($"{secondsToMilliseconds * expiryTime.TotalSeconds}s");
76+
}
77+
7678
var tokensResult = await ExecAsync(command, ct)
7779
.ConfigureAwait(false);
7880

tests/Testcontainers.Pulsar.Tests/PulsarContainerTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public PulsarAuthConfiguration()
7979

8080
protected override async Task<IPulsarClient> CreateClientAsync(CancellationToken ct = default)
8181
{
82-
var authToken = await _pulsarContainer.CreateAuthenticationTokenAsync(TimeSpan.FromHours(1), ct)
82+
var authToken = await _pulsarContainer.CreateAuthenticationTokenAsync(Timeout.InfiniteTimeSpan, ct)
8383
.ConfigureAwait(false);
8484

8585
return PulsarClient.Builder().ServiceUrl(new Uri(_pulsarContainer.GetBrokerAddress())).Authentication(new TokenAuthentication(authToken)).Build();

0 commit comments

Comments
 (0)