Improve testability, packaging, and docs
This commit is contained in:
@@ -13,7 +13,7 @@ namespace LibNftables;
|
||||
public sealed class NftablesClient : INftablesClient
|
||||
{
|
||||
private readonly NftablesClientOptions _options;
|
||||
private readonly System.Func<NftContext> _contextFactory;
|
||||
private readonly System.Func<INftContextHandle> _contextFactory;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="NftablesClient"/> class.
|
||||
@@ -26,11 +26,17 @@ public sealed class NftablesClient : INftablesClient
|
||||
{
|
||||
}
|
||||
|
||||
internal NftablesClient(NftablesClientOptions? options, System.Func<NftContext> contextFactory)
|
||||
internal NftablesClient(
|
||||
NftablesClientOptions? options,
|
||||
System.Func<INftContextHandle> contextFactory,
|
||||
bool skipRuntimeGuard = false)
|
||||
{
|
||||
_options = options ?? new NftablesClientOptions();
|
||||
_contextFactory = contextFactory;
|
||||
NftRuntimeGuard.EnsureInitializedForLinuxX64();
|
||||
if (!skipRuntimeGuard)
|
||||
{
|
||||
NftRuntimeGuard.EnsureInitializedForLinuxX64();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -131,7 +137,7 @@ public sealed class NftablesClient : INftablesClient
|
||||
{
|
||||
ct.ThrowIfCancellationRequested();
|
||||
|
||||
using NftContext ctx = _contextFactory();
|
||||
using INftContextHandle ctx = _contextFactory();
|
||||
ConfigureContext(ctx, request, forceDryRun);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(request.RulesetText))
|
||||
@@ -146,7 +152,7 @@ public sealed class NftablesClient : INftablesClient
|
||||
return new CommandExecutionResult(ctx.GetOutputBuffer(), ctx.GetErrorBuffer());
|
||||
}
|
||||
|
||||
private void ConfigureContext(NftContext ctx, NftApplyRequest request, bool? forceDryRun)
|
||||
private void ConfigureContext(INftContextHandle ctx, NftApplyRequest request, bool? forceDryRun)
|
||||
{
|
||||
ctx.DryRun = forceDryRun ?? request.DryRun;
|
||||
ctx.InputFlags = _options.DefaultInputFlags | request.InputFlags;
|
||||
|
||||
Reference in New Issue
Block a user