This commit is contained in:
Jöran Malek 2023-11-19 23:36:11 +01:00
parent ef87548623
commit 9fc737bdc4
3 changed files with 39 additions and 7 deletions

View file

@ -2,22 +2,54 @@ using Microsoft.Extensions.Hosting;
using pdns_dhcp.Options; using pdns_dhcp.Options;
using Stl.IO;
namespace pdns_dhcp.Kea; namespace pdns_dhcp.Kea;
public abstract class KeaDhcpLeaseWatcher : BackgroundService public abstract class KeaDhcpLeaseWatcher : BackgroundService
{ {
private readonly FileSystemWatcher fsw; private readonly FileSystemWatcher _fsw;
protected KeaDhcpServerOptions Options { get; } protected KeaDhcpServerOptions Options { get; }
protected KeaDhcpLeaseWatcher(KeaDhcpServerOptions options) protected KeaDhcpLeaseWatcher(KeaDhcpServerOptions options)
{ {
Options = options; Options = options;
var leases = options.Leases.AsSpan();
if (leases.IsWhiteSpace())
{
throw new ArgumentException($"{nameof(options.Leases)} must not be empty.", nameof(options));
}
var leaseFile = Path.GetFileName(leases);
var leaseDirectory = Path.GetDirectoryName(leases).ToString();
if (!Directory.Exists(leaseDirectory))
{
throw new ArgumentException($"{nameof(options.Leases)} must point to a file in an existing path.", nameof(options));
}
_fsw = new(leaseDirectory, leaseFile.ToString());
_fsw.Changed += OnLeaseChanged;
_fsw.Created += OnLeaseChanged;
_fsw.Deleted += OnLeaseChanged;
_fsw.Renamed += OnLeaseRenamed;
_fsw.Error += OnLeaseError;
} }
protected override Task ExecuteAsync(CancellationToken stoppingToken) protected override Task ExecuteAsync(CancellationToken stoppingToken)
{
return Task.CompletedTask;
}
private void OnLeaseChanged(object sender, FileSystemEventArgs e)
{
throw new NotImplementedException();
}
private void OnLeaseError(object sender, ErrorEventArgs e)
{
throw new NotImplementedException();
}
private void OnLeaseRenamed(object sender, RenamedEventArgs e)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View file

@ -1,8 +1,8 @@
namespace pdns_dhcp.Options; namespace pdns_dhcp.Options;
public class PowerDnsOptions public class PowerDnsOptions(PowerDnsListenerOptions listener)
{ {
public PowerDnsListenerOptions Listener { get; set; } public PowerDnsListenerOptions Listener { get; } = listener;
} }
public class PowerDnsListenerOptions(string socket) public class PowerDnsListenerOptions(string socket)

View file

@ -13,8 +13,8 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Sep" Version="0.2.7" /> <PackageReference Include="Sep" Version="0.2.7" />
<PackageReference Include="Stl.Generators" Version="6.6.5" /> <PackageReference Include="Stl.Generators" Version="6.7.1" />
<PackageReference Include="Stl.Interception" Version="6.6.5" /> <PackageReference Include="Stl.Interception" Version="6.7.1" />
</ItemGroup> </ItemGroup>
</Project> </Project>