mirror of
https://github.com/spacebarchat/server.git
synced 2026-03-30 16:05:41 +00:00
admin api packaging
This commit is contained in:
20
extra/admin-api/ConfigTest/ConfigTest.csproj
Normal file
20
extra/admin-api/ConfigTest/ConfigTest.csproj
Normal file
@@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>dotnet-ConfigTest-18d89c0e-df5d-447b-8429-7d526a35ab13</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="10.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Spacebar.ConfigModel\Spacebar.ConfigModel.csproj" />
|
||||
<ProjectReference Include="..\Spacebar.Db\Spacebar.Db.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
14
extra/admin-api/ConfigTest/Program.cs
Normal file
14
extra/admin-api/ConfigTest/Program.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using ConfigTest;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Spacebar.Db.Contexts;
|
||||
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
builder.Services.AddHostedService<Worker>();
|
||||
builder.Services.AddDbContext<SpacebarDbContext>(options => {
|
||||
options
|
||||
.UseNpgsql(builder.Configuration.GetConnectionString("Spacebar"))
|
||||
.EnableDetailedErrors();
|
||||
}, ServiceLifetime.Singleton);
|
||||
|
||||
var host = builder.Build();
|
||||
host.Run();
|
||||
12
extra/admin-api/ConfigTest/Properties/launchSettings.json
Normal file
12
extra/admin-api/ConfigTest/Properties/launchSettings.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"ConfigTest": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"environmentVariables": {
|
||||
"DOTNET_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
43
extra/admin-api/ConfigTest/Worker.cs
Normal file
43
extra/admin-api/ConfigTest/Worker.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Text.Json.Nodes;
|
||||
using Spacebar.ConfigModel.Extensions;
|
||||
using Spacebar.Db.Contexts;
|
||||
|
||||
namespace ConfigTest;
|
||||
|
||||
public class Worker(ILogger<Worker> 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);
|
||||
}
|
||||
}
|
||||
27
extra/admin-api/ConfigTest/appsettings.Development.json
Normal file
27
extra/admin-api/ConfigTest/appsettings.Development.json
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
9
extra/admin-api/ConfigTest/appsettings.json
Normal file
9
extra/admin-api/ConfigTest/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
Reference in New Issue
Block a user