Skip to content

Commit 7dbf2c0

Browse files
committed
Begin implementing database zone provider
1 parent 0e281be commit 7dbf2c0

File tree

65 files changed

+1393
-246
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1393
-246
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Ignore Visual Studio temporary files, build results, and
22
## files generated by popular Visual Studio add-ons.
33
Dns.Cli/appsettings.Development.json
4+
Dns.Cli/dns.db*
45

56
# User-specific files
67
*.suo

Dns.Cli/Controllers/DnsController.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using System.Linq;
2+
using System.Threading.Tasks;
3+
using Dns.Db.Models.EntityFramework;
4+
using Dns.Db.Repositories;
25
using Dns.Services;
36
using Microsoft.AspNetCore.Http;
47
using Microsoft.AspNetCore.Mvc;
@@ -7,9 +10,14 @@ namespace Dns.Cli.Controllers;
710

811
#pragma warning disable CS9113
912

13+
/// <summary>
14+
///
15+
/// </summary>
16+
/// <param name="dnsService"></param>
17+
/// <param name="dnsServer"></param>
1018
[ApiController]
1119
[Route("dns/")]
12-
public class DnsController(IDnsService dnsService, IDnsServer dnsServer) : ControllerBase
20+
public class DnsController(IDnsService dnsService, IDnsServer dnsServer, IZoneRepository zoneRepository) : ControllerBase
1321
{
1422
/// <summary>
1523
/// Dump Resolver data
@@ -21,6 +29,31 @@ public class DnsController(IDnsService dnsService, IDnsServer dnsServer) : Contr
2129
[HttpGet("resolvers")]
2230
public IActionResult? GetDnsResolverData()
2331
=> Ok(dnsService.Resolvers.Select(s => s.GetObject()));
32+
33+
/// <summary>
34+
/// Get database zones
35+
/// </summary>
36+
/// <returns>html</returns>
37+
[ProducesResponseType(StatusCodes.Status200OK)]
38+
[ProducesResponseType(StatusCodes.Status404NotFound)]
39+
[ProducesResponseType(StatusCodes.Status400BadRequest)]
40+
[HttpGet("zones")]
41+
public async Task<IActionResult?> GetZones()
42+
=> Ok(await zoneRepository.GetZones().ConfigureAwait(false));
43+
44+
/// <summary>
45+
/// Get database zones
46+
/// </summary>
47+
/// <returns>html</returns>
48+
[ProducesResponseType(StatusCodes.Status200OK)]
49+
[ProducesResponseType(StatusCodes.Status404NotFound)]
50+
[ProducesResponseType(StatusCodes.Status400BadRequest)]
51+
[HttpPut("zones")]
52+
public async Task<IActionResult?> AddZone([FromBody] Zone zone)
53+
{
54+
await zoneRepository.AddZone(zone).ConfigureAwait(false);
55+
return Created();
56+
}
2457
}
2558

2659
#pragma warning restore CS9113

Dns.Cli/Controllers/DumpController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
namespace Dns.Cli.Controllers;
88

9+
/// <summary>
10+
///
11+
/// </summary>
12+
/// <param name="dnsService"></param>
13+
/// <param name="dnsServer"></param>
914
[ApiController]
1015
[Route("dump/")]
1116
[Obsolete("Only available for backwards compatibility")]

Dns.Cli/Dns.Cli.csproj

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
<Nullable>enable</Nullable>
1010
</PropertyGroup>
1111

12+
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
13+
<DocumentationFile>bin\Debug\net9.0\Dns.Cli.xml</DocumentationFile>
14+
</PropertyGroup>
15+
16+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
17+
<DocumentationFile>bin\Release\net9.0\Dns.Cli.xml</DocumentationFile>
18+
</PropertyGroup>
19+
1220
<ItemGroup>
1321
<ProjectReference Include="..\Dns\Dns.csproj" />
1422
</ItemGroup>
@@ -18,21 +26,23 @@
1826
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.9" />
1927
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="9.0.9" />
2028
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.9" />
21-
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.20" />
29+
<PackageReference Include="Newtonsoft.Json" Version="13.0.4"/>
30+
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6" />
31+
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.14.0" />
2232
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.20">
2333
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2434
<PrivateAssets>all</PrivateAssets>
2535
</PackageReference>
26-
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.3"/>
27-
<PackageReference Include="Newtonsoft.Json" Version="13.0.4"/>
28-
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6" />
29-
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.14.0" />
3036
</ItemGroup>
3137

3238
<ItemGroup>
3339
<Content Update="appsettings.json">
3440
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
3541
</Content>
3642
</ItemGroup>
37-
38-
</Project>
43+
44+
<ItemGroup>
45+
<Folder Include="Configuration\" />
46+
</ItemGroup>
47+
48+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using Dns.Db.Contexts;
2+
using Microsoft.AspNetCore.Builder;
3+
using Microsoft.EntityFrameworkCore.Infrastructure;
4+
using Microsoft.EntityFrameworkCore.Migrations;
5+
using Microsoft.Extensions.DependencyInjection;
6+
7+
namespace Dns.Cli.Extensions;
8+
9+
/// <summary>
10+
///
11+
/// </summary>
12+
public static class ApplicationBuilderExtensions
13+
{
14+
/// <summary>
15+
///
16+
/// </summary>
17+
/// <param name="app"></param>
18+
public static void UpdateDatabase(this IApplicationBuilder app)
19+
{
20+
using var serviceScope = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>().CreateScope();
21+
using var context = serviceScope.ServiceProvider.GetService<DnsServerDbContext>();
22+
23+
var migrator = context?.Database.GetService<IMigrator>();
24+
migrator?.Migrate();
25+
}
26+
}

Dns.Cli/Extensions/ConfigurationExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55

66
namespace Dns.Cli.Extensions;
77

8+
/// <summary>
9+
///
10+
/// </summary>
811
public static class ConfigurationExtensions
912
{
1013
private static JsonNode ToJsonNode(this IConfiguration section)
@@ -33,6 +36,11 @@ private static JsonNode ToJsonNode(this IConfiguration section)
3336
return obj;
3437
}
3538

39+
/// <summary>
40+
///
41+
/// </summary>
42+
/// <param name="section"></param>
43+
/// <returns></returns>
3644
public static JsonElement ReadJsonElement(this IConfiguration section)
3745
=> JsonSerializer.SerializeToElement(ToJsonNode(section));
3846
}

Dns.Cli/Extensions/MiddlewareExtensions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@
33

44
namespace Dns.Cli.Extensions;
55

6+
/// <summary>
7+
///
8+
/// </summary>
69
public static class MiddlewareExtensions
710
{
11+
/// <summary>
12+
///
13+
/// </summary>
14+
/// <param name="app"></param>
15+
/// <returns></returns>
816
public static IApplicationBuilder UseLoadCurrentUser(this IApplicationBuilder app)
917
=> app.UseMiddleware<LoadCurrentUserMiddleware>();
1018
}

Dns.Cli/Migrations/20251011113400_InitialCreate.Designer.cs

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Microsoft.EntityFrameworkCore.Migrations;
2+
3+
#nullable disable
4+
5+
namespace Dns.Cli.Migrations
6+
{
7+
/// <inheritdoc />
8+
public partial class InitialCreate : Migration
9+
{
10+
/// <inheritdoc />
11+
protected override void Up(MigrationBuilder migrationBuilder)
12+
{
13+
migrationBuilder.CreateTable(
14+
name: "users",
15+
columns: table => new
16+
{
17+
id = table.Column<int>(type: "INTEGER", nullable: false)
18+
.Annotation("Sqlite:Autoincrement", true),
19+
account = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
20+
password = table.Column<string>(type: "TEXT", maxLength: 32, nullable: true),
21+
salt = table.Column<string>(type: "TEXT", maxLength: 3, nullable: true),
22+
activated = table.Column<bool>(type: "INTEGER", nullable: false),
23+
adminlevel = table.Column<byte>(type: "INTEGER", nullable: false)
24+
},
25+
constraints: table =>
26+
{
27+
table.PrimaryKey("PK_users", x => x.id);
28+
});
29+
30+
migrationBuilder.CreateIndex(
31+
name: "IX_users_account",
32+
table: "users",
33+
column: "account",
34+
unique: true);
35+
}
36+
37+
/// <inheritdoc />
38+
protected override void Down(MigrationBuilder migrationBuilder)
39+
{
40+
migrationBuilder.DropTable(
41+
name: "users");
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)