Distribution_GL Initialization

This commit is contained in:
2026-10-20 13:07:07 +05:30
commit 3f16e0cb44
194 changed files with 35659 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
using System.Security.Cryptography;
using General_Ledger_Service.DTOs.Common;
using General_Ledger_Service.Exceptions;
using General_Ledger_Service.Interfaces.Services;
namespace General_Ledger_Service.Services
{
// Dev-only bootstrap tool: generates the shared secret ApiKeyMiddleware checks. Never
// callable outside Development, no matter what - production has no way to reach this branch.
// The generated key is only returned, never persisted - it still has to be copied into
// appsettings.*.json (this service) and the core backend's matching config by hand.
public class DevToolsService(IHostEnvironment hostEnvironment) : IDevToolsService
{
private readonly IHostEnvironment _hostEnvironment = hostEnvironment;
public ApiResponse GenerateApiKey()
{
if (!_hostEnvironment.IsDevelopment())
{
throw new ForbiddenException("This endpoint is only available in the Development environment");
}
var apiKey = Convert.ToHexString(RandomNumberGenerator.GetBytes(32));
return ResponseHelpers.Ok(
"API key generated. Copy this into ApiKey:Value in appsettings.Development.json (and appsettings.Production.json / the deploy-time secret store, plus the core backend's matching config) - it is not saved anywhere by this call.",
new { apiKey });
}
}
}