69 lines
2.8 KiB
C#
69 lines
2.8 KiB
C#
// SPDX-License-Identifier: BUSL-1.1
|
|
// Copyright (c) 2025 StellaOps
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Routing;
|
|
using StellaOps.Platform.WebService.Constants;
|
|
using StellaOps.Platform.WebService.Services;
|
|
|
|
namespace StellaOps.Platform.WebService.Endpoints;
|
|
|
|
/// <summary>
|
|
/// Admin endpoints for managing DB-layer environment settings (Layer 3).
|
|
/// All endpoints require <c>SetupRead</c> or <c>SetupAdmin</c> authorization.
|
|
/// </summary>
|
|
public static class EnvironmentSettingsAdminEndpoints
|
|
{
|
|
public static IEndpointRouteBuilder MapEnvironmentSettingsAdminEndpoints(this IEndpointRouteBuilder app)
|
|
{
|
|
var group = app.MapGroup("/platform/envsettings/db")
|
|
.WithTags("Environment Settings Admin");
|
|
|
|
group.MapGet("/", async (IEnvironmentSettingsStore store, CancellationToken ct) =>
|
|
{
|
|
var all = await store.GetAllAsync(ct);
|
|
return Results.Ok(all);
|
|
})
|
|
.WithName("ListDbEnvironmentSettings")
|
|
.WithSummary("List all DB-layer environment settings")
|
|
.Produces<IReadOnlyDictionary<string, string>>(StatusCodes.Status200OK)
|
|
.RequireAuthorization(PlatformPolicies.SetupRead);
|
|
|
|
group.MapPut("/{key}", async (string key, SettingValueRequest body, IEnvironmentSettingsStore store, CancellationToken ct) =>
|
|
{
|
|
if (string.IsNullOrWhiteSpace(key))
|
|
return Results.BadRequest(new { error = "Key must not be empty." });
|
|
|
|
if (string.IsNullOrWhiteSpace(body.Value))
|
|
return Results.BadRequest(new { error = "Value must not be empty." });
|
|
|
|
await store.SetAsync(key, body.Value, body.UpdatedBy ?? "admin", ct);
|
|
return Results.Ok(new { key, value = body.Value });
|
|
})
|
|
.WithName("UpsertDbEnvironmentSetting")
|
|
.WithSummary("Create or update a DB-layer environment setting")
|
|
.Produces(StatusCodes.Status200OK)
|
|
.Produces(StatusCodes.Status400BadRequest)
|
|
.RequireAuthorization(PlatformPolicies.SetupAdmin);
|
|
|
|
group.MapDelete("/{key}", async (string key, IEnvironmentSettingsStore store, CancellationToken ct) =>
|
|
{
|
|
if (string.IsNullOrWhiteSpace(key))
|
|
return Results.BadRequest(new { error = "Key must not be empty." });
|
|
|
|
await store.DeleteAsync(key, ct);
|
|
return Results.NoContent();
|
|
})
|
|
.WithName("DeleteDbEnvironmentSetting")
|
|
.WithSummary("Delete a DB-layer environment setting")
|
|
.Produces(StatusCodes.Status204NoContent)
|
|
.Produces(StatusCodes.Status400BadRequest)
|
|
.RequireAuthorization(PlatformPolicies.SetupAdmin);
|
|
|
|
return app;
|
|
}
|
|
|
|
public sealed record SettingValueRequest(string Value, string? UpdatedBy = null);
|
|
}
|