Files
server/util/SeederApi/Startup.cs
Matt Gibson 2e6bf44504 Add SeederApi PlayData delete scheduled job (#7281)
* Use Quartz-based hosted service to clear old play data

We need to stop possible bloat of databases should users of a seeded data fail to appropriately clean up after themselves.

Using the hosted services present in other projects, this adds an alive job and play data delete job to the SeederApi

* Trigger play data delete frequently enough for dev servers

Development servers are unlikely to be running at midnight UTC, so we need to delete more frequently to ensure data is cleaned up. The Job still deletes things older than a day, it just checks much more frequently, now.

* Fixup sonarqube

* Fixup parallel test issues with jobs hosted services

* Remove alive job and unneeded fixme

* Revert "Remove alive job and unneeded fixme"

This reverts commit 0c10e4a675.

* Simplify alive job

Used the wrong job as a template, the api alive job is much more like what we want.

* Update readme to callout ephemeral data
2026-04-13 09:57:23 -07:00

89 lines
2.8 KiB
C#

using System.Globalization;
using Bit.Core.Settings;
using Bit.SeederApi.Extensions;
using Bit.SeederApi.Utilities;
using Bit.SharedWeb.Utilities;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace Bit.SeederApi;
public class Startup
{
public Startup(IWebHostEnvironment env, IConfiguration configuration)
{
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");
Configuration = configuration;
Environment = env;
}
public IConfiguration Configuration { get; private set; }
public IWebHostEnvironment Environment { get; set; }
public void ConfigureServices(IServiceCollection services)
{
services.AddOptions();
var globalSettings = services.AddGlobalSettingsServices(Configuration, Environment);
services.AddCustomDataProtectionServices(Environment, globalSettings);
services.AddTokenizers();
services.AddDatabaseRepositories(globalSettings);
services.AddTestPlayIdTracking(globalSettings);
services.AddManglerService(globalSettings);
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddScoped<IPasswordHasher<Core.Entities.User>, PasswordHasher<Core.Entities.User>>();
services.AddSeederApiServices();
services.AddScenes();
services.AddQueries();
services.Configure<SeederSettings>(Configuration.GetSection("seederSettings"));
services.AddAuthentication(BasicAuthenticationOptions.DefaultScheme)
.AddScheme<BasicAuthenticationOptions, BasicAuthenticationHandler>(
BasicAuthenticationOptions.DefaultScheme, null);
services.AddAuthorization();
services.AddControllers();
Jobs.JobsHostedService.AddJobsServices(services);
services.AddHostedService<Jobs.JobsHostedService>();
}
public void Configure(
IApplicationBuilder app,
IWebHostEnvironment env,
IHostApplicationLifetime appLifetime,
GlobalSettings globalSettings)
{
if (env.IsProduction())
{
throw new InvalidOperationException(
"SeederApi cannot be run in production environments. This service is intended for test data generation only.");
}
if (globalSettings.TestPlayIdTrackingEnabled)
{
app.UseMiddleware<PlayIdMiddleware>();
}
if (!env.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
}
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(name: "default", pattern: "{controller=Seed}/{action=Index}/{id?}");
});
}
}