From 4534d4dbf5f5071fa71c5dec4444bf4b2bbd040c Mon Sep 17 00:00:00 2001 From: Rory& Date: Sun, 14 Dec 2025 23:18:35 +0100 Subject: admin api packaging --- extra/admin-api/ConfigTest/ConfigTest.csproj | 20 ++++++++++ extra/admin-api/ConfigTest/Program.cs | 14 +++++++ .../ConfigTest/Properties/launchSettings.json | 12 ++++++ extra/admin-api/ConfigTest/Worker.cs | 43 ++++++++++++++++++++++ .../ConfigTest/appsettings.Development.json | 27 ++++++++++++++ extra/admin-api/ConfigTest/appsettings.json | 9 +++++ 6 files changed, 125 insertions(+) create mode 100644 extra/admin-api/ConfigTest/ConfigTest.csproj create mode 100644 extra/admin-api/ConfigTest/Program.cs create mode 100644 extra/admin-api/ConfigTest/Properties/launchSettings.json create mode 100644 extra/admin-api/ConfigTest/Worker.cs create mode 100644 extra/admin-api/ConfigTest/appsettings.Development.json create mode 100644 extra/admin-api/ConfigTest/appsettings.json (limited to 'extra/admin-api/ConfigTest') diff --git a/extra/admin-api/ConfigTest/ConfigTest.csproj b/extra/admin-api/ConfigTest/ConfigTest.csproj new file mode 100644 index 000000000..7244b6736 --- /dev/null +++ b/extra/admin-api/ConfigTest/ConfigTest.csproj @@ -0,0 +1,20 @@ + + + + net10.0 + enable + enable + dotnet-ConfigTest-18d89c0e-df5d-447b-8429-7d526a35ab13 + + + + + + + + + + + + + diff --git a/extra/admin-api/ConfigTest/Program.cs b/extra/admin-api/ConfigTest/Program.cs new file mode 100644 index 000000000..5945bcf62 --- /dev/null +++ b/extra/admin-api/ConfigTest/Program.cs @@ -0,0 +1,14 @@ +using ConfigTest; +using Microsoft.EntityFrameworkCore; +using Spacebar.Db.Contexts; + +var builder = Host.CreateApplicationBuilder(args); +builder.Services.AddHostedService(); +builder.Services.AddDbContext(options => { + options + .UseNpgsql(builder.Configuration.GetConnectionString("Spacebar")) + .EnableDetailedErrors(); +}, ServiceLifetime.Singleton); + +var host = builder.Build(); +host.Run(); diff --git a/extra/admin-api/ConfigTest/Properties/launchSettings.json b/extra/admin-api/ConfigTest/Properties/launchSettings.json new file mode 100644 index 000000000..c355f360c --- /dev/null +++ b/extra/admin-api/ConfigTest/Properties/launchSettings.json @@ -0,0 +1,12 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "ConfigTest": { + "commandName": "Project", + "dotnetRunMessages": true, + "environmentVariables": { + "DOTNET_ENVIRONMENT": "Development" + } + } + } +} diff --git a/extra/admin-api/ConfigTest/Worker.cs b/extra/admin-api/ConfigTest/Worker.cs new file mode 100644 index 000000000..dd3ef7791 --- /dev/null +++ b/extra/admin-api/ConfigTest/Worker.cs @@ -0,0 +1,43 @@ +using System.Text.Json.Nodes; +using Spacebar.ConfigModel.Extensions; +using Spacebar.Db.Contexts; + +namespace ConfigTest; + +public class Worker(ILogger logger, SpacebarDbContext db) : BackgroundService +{ + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + var config = db.Configs + .OrderBy(x => x.Key) + .ToDictionary(x => x.Key, x => x.Value); + foreach (var (key, value) in config) + { + Console.WriteLine("Config Key: {0}, Value: {1}", key, value ?? "[NULL]"); + } + + var readConfig = config.ToNestedJsonObject(); + Console.WriteLine(readConfig); + var mapped = readConfig.ToFlatKv(); + foreach (var (key, value) in mapped) + { + Console.WriteLine("Mapped Key: {0}, Value: {1}", key, value ?? "[NULL]"); + } + + // check that they're equal + foreach (var (key, value) in config) + { + if (!mapped.ContainsKey(key)) + { + Console.WriteLine("Missing Key in Mapped: {0}", key); + continue; + } + + if (mapped[key] != value) + { + Console.WriteLine("Value Mismatch for Key: {0}, Original: {1}, Mapped: {2}", key, value ?? "[NULL]", mapped[key] ?? "[NULL]"); + } + } + Environment.Exit(0); + } +} \ No newline at end of file diff --git a/extra/admin-api/ConfigTest/appsettings.Development.json b/extra/admin-api/ConfigTest/appsettings.Development.json new file mode 100644 index 000000000..032457733 --- /dev/null +++ b/extra/admin-api/ConfigTest/appsettings.Development.json @@ -0,0 +1,27 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Trace", //Warning + "Microsoft.AspNetCore.Mvc": "Warning", //Warning + "Microsoft.AspNetCore.HostFiltering": "Warning", //Warning + "Microsoft.AspNetCore.Cors": "Warning", //Warning + // "Microsoft.EntityFrameworkCore": "Warning" + "Microsoft.EntityFrameworkCore.Database.Command": "Debug" + } + }, + "ConnectionStrings": { + "Spacebar": "Host=127.0.0.1; Username=postgres; Database=spacebar; Port=5432; Include Error Detail=true; Maximum Pool Size=1000; Command Timeout=6000; Timeout=600;", + }, + "RabbitMQ": { + "Host": "127.0.0.1", + "Port": 5673, + "Username": "guest", + "Password": "guest" + }, + "SpacebarAdminApi": { + "Enforce2FA": true, + "OverrideUid": null, + "DisableAuthentication": false + } +} diff --git a/extra/admin-api/ConfigTest/appsettings.json b/extra/admin-api/ConfigTest/appsettings.json new file mode 100644 index 000000000..10f68b8c8 --- /dev/null +++ b/extra/admin-api/ConfigTest/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} -- cgit 1.5.1