mirror of
https://github.com/bitwarden/server.git
synced 2026-01-31 06:03:12 +08:00
65 lines
2.2 KiB
C#
65 lines
2.2 KiB
C#
using AutoMapper;
|
|
using Bit.Core.Entities;
|
|
using Bit.Infrastructure.EntityFramework.Repositories;
|
|
using Bit.RustSDK;
|
|
using Bit.Seeder.Recipes;
|
|
using CommandDotNet;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Bit.DbSeederUtility;
|
|
|
|
public class Program
|
|
{
|
|
private static int Main(string[] args)
|
|
{
|
|
return new AppRunner<Program>()
|
|
.Run(args);
|
|
}
|
|
|
|
[Command("organization", Description = "Seed an organization and organization users")]
|
|
public void Organization(
|
|
[Option('n', "Name", Description = "Name of organization")]
|
|
string name,
|
|
[Option('u', "users", Description = "Number of users to generate")]
|
|
int users,
|
|
[Option('d', "domain", Description = "Email domain for users")]
|
|
string domain
|
|
)
|
|
{
|
|
// Create service provider with necessary services
|
|
var services = new ServiceCollection();
|
|
ServiceCollectionExtension.ConfigureServices(services);
|
|
var serviceProvider = services.BuildServiceProvider();
|
|
|
|
// Get a scoped DB context
|
|
using var scope = serviceProvider.CreateScope();
|
|
var scopedServices = scope.ServiceProvider;
|
|
var db = scopedServices.GetRequiredService<DatabaseContext>();
|
|
|
|
var recipe = new OrganizationWithUsersRecipe(db);
|
|
recipe.Seed(name: name, domain: domain, users: users);
|
|
}
|
|
|
|
[Command("vault-organization", Description = "Seed an organization with users and encrypted vault data (ciphers, collections, groups)")]
|
|
public void VaultOrganization(VaultOrganizationArgs args)
|
|
{
|
|
args.Validate();
|
|
|
|
var services = new ServiceCollection();
|
|
ServiceCollectionExtension.ConfigureServices(services);
|
|
var serviceProvider = services.BuildServiceProvider();
|
|
|
|
using var scope = serviceProvider.CreateScope();
|
|
var scopedServices = scope.ServiceProvider;
|
|
|
|
var recipe = new OrganizationWithVaultRecipe(
|
|
scopedServices.GetRequiredService<DatabaseContext>(),
|
|
scopedServices.GetRequiredService<IMapper>(),
|
|
scopedServices.GetRequiredService<RustSdkService>(),
|
|
scopedServices.GetRequiredService<IPasswordHasher<User>>());
|
|
|
|
recipe.Seed(args.ToOptions());
|
|
}
|
|
}
|