forked from gongxuegit/tiku-backend.net
feat: establish dotnet engineering foundation
This commit is contained in:
@@ -1,7 +1,42 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Tiku.Application.Security;
|
||||
|
||||
namespace Tiku.Api.Options;
|
||||
|
||||
public static class OptionsValidation
|
||||
{
|
||||
public const string DevelopmentSigningKey = "development-only-tiku-signing-key-change-before-production";
|
||||
|
||||
public static string ResolveDatabaseConnectionString(
|
||||
IConfiguration configuration,
|
||||
bool isDevelopment)
|
||||
{
|
||||
var connectionString =
|
||||
configuration.GetConnectionString("Database") ??
|
||||
configuration["DATABASE_URL"];
|
||||
if (!string.IsNullOrWhiteSpace(connectionString))
|
||||
{
|
||||
return connectionString;
|
||||
}
|
||||
|
||||
if (isDevelopment)
|
||||
{
|
||||
return $"Host=localhost;Database=tiku;Username={Environment.UserName}";
|
||||
}
|
||||
|
||||
throw new InvalidOperationException(
|
||||
"Database connection is required outside Development. Configure ConnectionStrings:Database or DATABASE_URL.");
|
||||
}
|
||||
|
||||
public static bool BeValidJwtOptions(JwtOptions options, bool isProduction)
|
||||
{
|
||||
return !isProduction ||
|
||||
!string.Equals(
|
||||
options.SigningKey,
|
||||
DevelopmentSigningKey,
|
||||
StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
public static bool BeValidCorsOptions(CorsOptions options)
|
||||
{
|
||||
if (options.AllowCredentials && options.AllowedOrigins.Length == 0)
|
||||
|
||||
Reference in New Issue
Block a user