mirror of
https://github.com/bitwarden/server
synced 2026-01-03 09:03:44 +00:00
[PM-21075] Initial database seeder (#5703)
Adds a database seeder which can be used standalone using a CLI for seeding your local development environment, or used in unit tests to seed complex scenarios. --------- Co-authored-by: Robert Y <rkac@bitwarden.com>
This commit is contained in:
34
util/DbSeederUtility/GlobalSettingsFactory.cs
Normal file
34
util/DbSeederUtility/GlobalSettingsFactory.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using Bit.Core.Settings;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Bit.DbSeederUtility;
|
||||
|
||||
public static class GlobalSettingsFactory
|
||||
{
|
||||
private static GlobalSettings? _globalSettings;
|
||||
|
||||
public static GlobalSettings GlobalSettings
|
||||
{
|
||||
get { return _globalSettings ??= LoadGlobalSettings(); }
|
||||
}
|
||||
|
||||
private static GlobalSettings LoadGlobalSettings()
|
||||
{
|
||||
Console.WriteLine("Loading global settings...");
|
||||
|
||||
var configBuilder = new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
||||
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", optional: true, reloadOnChange: true)
|
||||
.AddUserSecrets("bitwarden-Api") // Load user secrets from the API project
|
||||
.AddEnvironmentVariables();
|
||||
|
||||
var configuration = configBuilder.Build();
|
||||
var globalSettingsSection = configuration.GetSection("globalSettings");
|
||||
|
||||
var settings = new GlobalSettings();
|
||||
globalSettingsSection.Bind(settings);
|
||||
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user