Skip to content

Commit 0010475

Browse files
authored
Merge pull request #414 from nblumhardt/wrapper-naming
Rename `FowardingChannelWrapper` to `ForwardingAuthenticationStrategy`
2 parents 62b65a8 + a2c43c1 commit 0010475

13 files changed

+227
-142
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ dotnet tool install --global seqcli
1515
To set a default server URL and API key, run:
1616

1717
```
18-
seqcli config -k connection.serverUrl -v https://your-seq-server
19-
seqcli config -k connection.apiKey -v your-api-key
18+
seqcli config set -k connection.serverUrl -v https://your-seq-server
19+
seqcli config set -k connection.apiKey -v your-api-key
2020
```
2121

2222
The API key will be stored in your `SeqCli.json` configuration file; on Windows, this is encrypted using DPAPI; on Mac/Linux the key is stored in plain text unless an encryptor is defined in `encryption.encryptor`. As an alternative to storing the API key in configuration, it can be passed to each command via the `--apikey=` argument.

src/SeqCli/Config/Forwarder/SeqCliForwarderStorageConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ namespace SeqCli.Config.Forwarder;
44

55
public class SeqCliForwarderStorageConfig
66
{
7-
public long TargetChunkSizeBytes { get; set; } = 10 * 512 * 1024;
7+
public long TargetChunkSizeBytes { get; set; } = 100 * 512 * 1024;
88
public int? MaxChunks { get; set; } = null;
99
}

src/SeqCli/Encryptor/ExternalDataProtector.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Diagnostics;
44
using System.Text;
55
using System.Threading;
6-
using SeqCli.Config;
76

87
namespace SeqCli.Encryptor;
98

@@ -110,6 +109,8 @@ static int Invoke(string fullExePath, string? args, byte[] stdin, out byte[] std
110109

111110
stdout = stdoutBuf.AsSpan()[..stdoutBufLength].ToArray();
112111
ArrayPool<byte>.Shared.Return(stdoutBuf);
112+
113+
process.WaitForExit(TimeSpan.FromSeconds(30));
113114

114115
return process.ExitCode;
115116
}

src/SeqCli/Forwarder/Channel/ApiKeyForwardingChannelWrapper.cs

Lines changed: 0 additions & 90 deletions
This file was deleted.

src/SeqCli/Forwarder/Channel/ForwardingChannelWrapper.cs renamed to src/SeqCli/Forwarder/Channel/ForwardingAuthenticationStrategy.cs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
// Copyright © Datalust Pty Ltd
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System;
116
using System.IO;
217
using System.Threading;
318
using System.Threading.Tasks;
@@ -9,13 +24,12 @@
924

1025
namespace SeqCli.Forwarder.Channel;
1126

12-
internal abstract class ForwardingChannelWrapper(string bufferPath, SeqConnection connection, SeqCliConfig config)
27+
abstract class ForwardingAuthenticationStrategy(string bufferPath, SeqConnection connection, SeqCliConfig config)
1328
{
14-
protected const string SeqCliConnectionChannelId = "SeqCliConnection";
29+
readonly CancellationTokenSource _shutdownTokenSource = new();
30+
1531
protected readonly string BufferPath = bufferPath;
1632
protected readonly SeqCliConfig Config = config;
17-
protected readonly CancellationTokenSource ShutdownTokenSource = new();
18-
protected readonly Lock ChannelsSync = new();
1933

2034
// <param name="id">The id used for the channel storage on the file system.</param>
2135
// <param name="apiKey">The apiKey that will be used to connect to the downstream Seq instance.</param>
@@ -24,7 +38,7 @@ protected ForwardingChannel OpenOrCreateChannel(string id, string? apiKey)
2438
var storePath = GetStorePath(id);
2539
var store = new SystemStoreDirectory(storePath);
2640

27-
Log.ForContext<ForwardingChannelWrapper>().Information("Opening local buffer in {StorePath}", storePath);
41+
Log.ForContext<ForwardingAuthenticationStrategy>().Information("Opening local buffer in {StorePath}", storePath);
2842

2943
return new ForwardingChannel(
3044
BufferAppender.Open(store),
@@ -35,15 +49,25 @@ protected ForwardingChannel OpenOrCreateChannel(string id, string? apiKey)
3549
Config.Forwarder.Storage.TargetChunkSizeBytes,
3650
Config.Forwarder.Storage.MaxChunks,
3751
Config.Connection.BatchSizeLimitBytes,
38-
ShutdownTokenSource.Token);
52+
_shutdownTokenSource.Token);
3953
}
4054

4155
public abstract ForwardingChannel GetForwardingChannel(string? requestApiKey);
4256

4357
public abstract Task StopAsync();
4458

59+
protected async Task OnStoppedAsync()
60+
{
61+
await _shutdownTokenSource.CancelAsync();
62+
}
63+
64+
protected void OnStopping()
65+
{
66+
_shutdownTokenSource.CancelAfter(TimeSpan.FromSeconds(30));
67+
}
68+
4569
protected string GetStorePath(string id)
4670
{
4771
return Path.Combine(BufferPath, id);
4872
}
49-
}
73+
}

src/SeqCli/Forwarder/Channel/ForwardingChannel.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright © Datalust Pty Ltd
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
using System;
216
using System.IO;
317
using System.Threading;

src/SeqCli/Forwarder/Channel/ForwardingChannelEntry.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright © Datalust Pty Ltd
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
using System;
216
using System.Threading.Tasks;
317

src/SeqCli/Forwarder/Channel/SeqCliConnectionForwardingChannelWrapper.cs

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright © Datalust Pty Ltd
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
using System.Threading.Tasks;
16+
using Seq.Api;
17+
using SeqCli.Config;
18+
using Serilog;
19+
20+
namespace SeqCli.Forwarder.Channel;
21+
22+
class SharedConnectionForwardingAuthenticationStrategy: ForwardingAuthenticationStrategy
23+
{
24+
public const string ChannelId = "SharedConnection";
25+
26+
readonly ForwardingChannel _sharedForwardingChannel;
27+
28+
public SharedConnectionForwardingAuthenticationStrategy(string bufferPath, SeqConnection connection, SeqCliConfig config, string? seqCliApiKey): base(bufferPath, connection, config)
29+
{
30+
_sharedForwardingChannel = OpenOrCreateChannel(ChannelId, seqCliApiKey);
31+
}
32+
33+
public override ForwardingChannel GetForwardingChannel(string? _)
34+
{
35+
return _sharedForwardingChannel;
36+
}
37+
38+
public override async Task StopAsync()
39+
{
40+
Log.ForContext<SharedConnectionForwardingAuthenticationStrategy>().Information("Flushing log buffer");
41+
OnStopping();
42+
43+
await _sharedForwardingChannel.StopAsync();
44+
await OnStoppedAsync();
45+
}
46+
}

0 commit comments

Comments
 (0)