mirror of
https://github.com/bitwarden/server
synced 2025-12-20 10:13:39 +00:00
* Upgrade Stripe.net to v48.4.0 * Update PreviewTaxAmountCommand * Remove unused UpcomingInvoiceOptionExtensions * Added SubscriptionExtensions with GetCurrentPeriodEnd * Update PremiumUserBillingService * Update OrganizationBillingService * Update GetOrganizationWarningsQuery * Update BillingHistoryInfo * Update SubscriptionInfo * Remove unused Sql Billing folder * Update StripeAdapter * Update StripePaymentService * Update InvoiceCreatedHandler * Update PaymentFailedHandler * Update PaymentSucceededHandler * Update ProviderEventService * Update StripeEventUtilityService * Update SubscriptionDeletedHandler * Update SubscriptionUpdatedHandler * Update UpcomingInvoiceHandler * Update ProviderSubscriptionResponse * Remove unused Stripe Subscriptions Admin Tool * Update RemoveOrganizationFromProviderCommand * Update ProviderBillingService * Update RemoveOrganizatinoFromProviderCommandTests * Update PreviewTaxAmountCommandTests * Update GetCloudOrganizationLicenseQueryTests * Update GetOrganizationWarningsQueryTests * Update StripePaymentServiceTests * Update ProviderBillingControllerTests * Update ProviderEventServiceTests * Update SubscriptionDeletedHandlerTests * Update SubscriptionUpdatedHandlerTests * Resolve Billing test failures I completely removed tests for the StripeEventService as they were using a system I setup a while back that read JSON files of the Stripe event structure. I did not anticipate how frequently these structures would change with each API version and the cost of trying to update these specific JSON files to test a very static data retrieval service far outweigh the benefit. * Resolve Core test failures * Run dotnet format * Remove unused provider migration * Fixed failing tests * Run dotnet format * Replace the old webhook secret key with new one (#6223) * Fix compilation failures in additions * Run dotnet format * Bump Stripe API version * Fix recent addition: CreatePremiumCloudHostedSubscriptionCommand * Fix new code in main according to Stripe update * Fix InvoiceExtensions * Bump SDK version to match API Version * Fix provider invoice generation validation * More QA fixes * Fix tests * QA defect resolutions * QA defect resolutions * Run dotnet format * Fix tests --------- Co-authored-by: cyprain-okeke <108260115+cyprain-okeke@users.noreply.github.com>
165 lines
5.4 KiB
C#
165 lines
5.4 KiB
C#
using System.Globalization;
|
|
using Bit.Admin.IdentityServer;
|
|
using Bit.Core.Context;
|
|
using Bit.Core.Settings;
|
|
using Bit.Core.Utilities;
|
|
using Bit.SharedWeb.Utilities;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Stripe;
|
|
using Microsoft.AspNetCore.Mvc.Razor;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using Bit.Admin.Services;
|
|
using Bit.Core.Billing.Extensions;
|
|
|
|
#if !OSS
|
|
using Bit.Commercial.Core.Utilities;
|
|
using Bit.Commercial.Infrastructure.EntityFramework.SecretsManager;
|
|
#endif
|
|
|
|
namespace Bit.Admin;
|
|
|
|
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)
|
|
{
|
|
// Options
|
|
services.AddOptions();
|
|
|
|
// Settings
|
|
var globalSettings = services.AddGlobalSettingsServices(Configuration, Environment);
|
|
services.Configure<AdminSettings>(Configuration.GetSection("AdminSettings"));
|
|
|
|
// Data Protection
|
|
services.AddCustomDataProtectionServices(Environment, globalSettings);
|
|
|
|
// Stripe Billing
|
|
StripeConfiguration.ApiKey = globalSettings.Stripe.ApiKey;
|
|
StripeConfiguration.MaxNetworkRetries = globalSettings.Stripe.MaxNetworkRetries;
|
|
|
|
// Repositories
|
|
var databaseProvider = services.AddDatabaseRepositories(globalSettings);
|
|
switch (databaseProvider)
|
|
{
|
|
case Core.Enums.SupportedDatabaseProviders.SqlServer:
|
|
services.AddSingleton<IDbMigrator, Migrator.SqlServerDbMigrator>();
|
|
break;
|
|
case Core.Enums.SupportedDatabaseProviders.MySql:
|
|
services.AddSingleton<IDbMigrator, MySqlMigrations.MySqlDbMigrator>();
|
|
break;
|
|
case Core.Enums.SupportedDatabaseProviders.Postgres:
|
|
services.AddSingleton<IDbMigrator, PostgresMigrations.PostgresDbMigrator>();
|
|
break;
|
|
case Core.Enums.SupportedDatabaseProviders.Sqlite:
|
|
services.AddSingleton<IDbMigrator, SqliteMigrations.SqliteDbMigrator>();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
// Context
|
|
services.AddScoped<ICurrentContext, CurrentContext>();
|
|
services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|
|
|
// Identity
|
|
services.AddPasswordlessIdentityServices<ReadOnlyEnvIdentityUserStore>(globalSettings);
|
|
services.Configure<SecurityStampValidatorOptions>(options =>
|
|
{
|
|
options.ValidationInterval = TimeSpan.FromMinutes(5);
|
|
});
|
|
if (globalSettings.SelfHosted)
|
|
{
|
|
services.ConfigureApplicationCookie(options =>
|
|
{
|
|
options.Cookie.Path = "/admin";
|
|
});
|
|
}
|
|
|
|
// Services
|
|
services.AddBaseServices(globalSettings);
|
|
services.AddDefaultServices(globalSettings);
|
|
services.AddScoped<IAccessControlService, AccessControlService>();
|
|
services.AddDistributedCache(globalSettings);
|
|
services.AddBillingOperations();
|
|
services.AddHttpClient();
|
|
|
|
#if OSS
|
|
services.AddOosServices();
|
|
#else
|
|
services.AddCommercialCoreServices();
|
|
services.AddSecretsManagerEfRepositories();
|
|
#endif
|
|
|
|
// Mvc
|
|
services.AddMvc(config =>
|
|
{
|
|
config.Filters.Add(new LoggingExceptionHandlerFilterAttribute());
|
|
});
|
|
services.Configure<RouteOptions>(options => options.LowercaseUrls = true);
|
|
|
|
services.Configure<RazorViewEngineOptions>(o =>
|
|
{
|
|
o.ViewLocationFormats.Add("/Auth/Views/{1}/{0}.cshtml");
|
|
o.ViewLocationFormats.Add("/AdminConsole/Views/{1}/{0}.cshtml");
|
|
o.ViewLocationFormats.Add("/Billing/Views/{1}/{0}.cshtml");
|
|
});
|
|
|
|
// Jobs service
|
|
Jobs.JobsHostedService.AddJobsServices(services, globalSettings.SelfHosted);
|
|
services.AddHostedService<Jobs.JobsHostedService>();
|
|
if (globalSettings.SelfHosted)
|
|
{
|
|
services.AddHostedService<HostedServices.DatabaseMigrationHostedService>();
|
|
}
|
|
else
|
|
{
|
|
if (CoreHelpers.SettingHasValue(globalSettings.Mail.ConnectionString))
|
|
{
|
|
services.AddHostedService<HostedServices.AzureQueueMailHostedService>();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Configure(
|
|
IApplicationBuilder app,
|
|
IWebHostEnvironment env,
|
|
IHostApplicationLifetime appLifetime,
|
|
GlobalSettings globalSettings)
|
|
{
|
|
app.UseSerilog(env, appLifetime, globalSettings);
|
|
|
|
// Add general security headers
|
|
app.UseMiddleware<SecurityHeadersMiddleware>();
|
|
|
|
if (globalSettings.SelfHosted)
|
|
{
|
|
app.UsePathBase("/admin");
|
|
app.UseForwardedHeaders(globalSettings);
|
|
}
|
|
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
else
|
|
{
|
|
app.UseExceptionHandler("/error");
|
|
}
|
|
|
|
app.UseStaticFiles();
|
|
app.UseRouting();
|
|
app.UseAuthentication();
|
|
app.UseAuthorization();
|
|
app.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute());
|
|
}
|
|
}
|