Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions util/SeederUtility/Commands/IndividualArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class IndividualArgs : IArgumentModel
public bool SelfHosted { get; set; }

[Option("account-age-days", Description = "Backdate the account's CreationDate by N days (default: 0 = today)")]
public int AccountAgeDays { get; set; }
public int? AccountAgeDays { get; set; }

[Option("mangle", Description = "Enable ID mangling for test isolation")]
public bool Mangle { get; set; }
Expand Down Expand Up @@ -82,6 +82,6 @@ public void Validate()
Password = Password,
KdfIterations = KdfIterations,
SelfHosted = SelfHosted,
AccountAgeDays = AccountAgeDays
AccountAgeDays = AccountAgeDays ?? 0
};
}
23 changes: 14 additions & 9 deletions util/SeederUtility/Configuration/GlobalSettingsFactory.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ο»Ώusing Bit.Core.Settings;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;

namespace Bit.SeederUtility.Configuration;

Expand All @@ -14,18 +15,22 @@ public static GlobalSettings GlobalSettings

private static GlobalSettings LoadGlobalSettings()
{
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-seeder-utility")
.AddEnvironmentVariables();
// The generic host only reads DOTNET_ENVIRONMENT, while the rest of the repo keys off
// ASPNETCORE_ENVIRONMENT; honor both. The seeder is a local development tool, so fall
// back to Development rather than Production so appsettings.Development.json applies.
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")
?? Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT")
?? Environments.Development;

var configuration = configBuilder.Build();
var globalSettingsSection = configuration.GetSection("globalSettings");
var builder = Host.CreateApplicationBuilder(new HostApplicationBuilderSettings
{
// Resolve appsettings files next to the binary, not the caller's working directory.
ContentRootPath = AppContext.BaseDirectory,
EnvironmentName = environment,
});

var settings = new GlobalSettings();
globalSettingsSection.Bind(settings);
builder.Configuration.GetSection("globalSettings").Bind(settings);

return settings;
}
Expand Down
9 changes: 9 additions & 0 deletions util/SeederUtility/SeederUtility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@
<PackageReference Include="Spectre.Console" Version="[0.55.2]" />
</ItemGroup>

<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="appsettings.Development.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Loading