-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Aspirification of API service (incl admin + identity dbs) #5902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maddymontaquila
wants to merge
2
commits into
bitwarden:main
Choose a base branch
from
maddymontaquila:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+961
โ123
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"sdk": { | ||
"version": "8.0.100", | ||
"version": "9.0.100", | ||
"rollForward": "latestFeature" | ||
}, | ||
"msbuild-sdks": { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"appHostPath": "../Apphost/Apphost.csproj" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,52 @@ | ||
๏ปฟusing Bit.Core.Utilities; | ||
๏ปฟusing Bit.Core.Settings; | ||
|
||
namespace Bit.Admin; | ||
|
||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
Host | ||
.CreateDefaultBuilder(args) | ||
.ConfigureCustomAppConfiguration(args) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
{ | ||
webBuilder.ConfigureKestrel(o => | ||
{ | ||
o.Limits.MaxRequestLineSize = 20_000; | ||
}); | ||
webBuilder.UseStartup<Startup>(); | ||
webBuilder.ConfigureLogging((hostingContext, logging) => | ||
logging.AddSerilog(hostingContext, (e, globalSettings) => | ||
{ | ||
var context = e.Properties["SourceContext"].ToString(); | ||
if (e.Properties.ContainsKey("RequestPath") && | ||
!string.IsNullOrWhiteSpace(e.Properties["RequestPath"]?.ToString()) && | ||
(context.Contains(".Server.Kestrel") || context.Contains(".Core.IISHttpServer"))) | ||
{ | ||
return false; | ||
} | ||
return e.Level >= globalSettings.MinLogLevel.AdminSettings.Default; | ||
})); | ||
}) | ||
.Build() | ||
.Run(); | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.AddServiceDefaults(); | ||
|
||
var startup = new Startup(builder.Environment, builder.Configuration); | ||
|
||
startup.ConfigureServices(builder.Services); | ||
|
||
var app = builder.Build(); | ||
|
||
app.MapDefaultEndpoints(); | ||
|
||
var settings = app.Services.GetRequiredService<GlobalSettings>(); | ||
|
||
startup.Configure(app, app.Environment, app.Lifetime, settings); | ||
|
||
app.Run(); | ||
// Host | ||
// .CreateDefaultBuilder(args) | ||
// .ConfigureCustomAppConfiguration(args) | ||
// .ConfigureWebHostDefaults(webBuilder => | ||
// { | ||
// webBuilder.ConfigureKestrel(o => | ||
// { | ||
// o.Limits.MaxRequestLineSize = 20_000; | ||
// }); | ||
// webBuilder.UseStartup<Startup>(); | ||
// webBuilder.ConfigureLogging((hostingContext, logging) => | ||
// logging.AddSerilog(hostingContext, (e, globalSettings) => | ||
// { | ||
// var context = e.Properties["SourceContext"].ToString(); | ||
// if (e.Properties.ContainsKey("RequestPath") && | ||
// !string.IsNullOrWhiteSpace(e.Properties["RequestPath"]?.ToString()) && | ||
// (context.Contains(".Server.Kestrel") || context.Contains(".Core.IISHttpServer"))) | ||
// { | ||
// return false; | ||
// } | ||
// return e.Level >= globalSettings.MinLogLevel.AdminSettings.Default; | ||
// })); | ||
// }) | ||
// .Build() | ||
// .Run(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,77 @@ | ||
๏ปฟusing AspNetCoreRateLimit; | ||
using Bit.Core.Utilities; | ||
using Microsoft.IdentityModel.Tokens; | ||
๏ปฟusing Bit.Core.Settings; | ||
using Bit.SharedWeb.Health; | ||
using Microsoft.AspNetCore.Diagnostics.HealthChecks; | ||
|
||
namespace Bit.Api; | ||
|
||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
Host | ||
.CreateDefaultBuilder(args) | ||
.ConfigureCustomAppConfiguration(args) | ||
.ConfigureWebHostDefaults(webBuilder => | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.AddServiceDefaults(); | ||
|
||
var startup = new Startup(builder.Environment, builder.Configuration); | ||
|
||
startup.ConfigureServices(builder.Services); | ||
|
||
var app = builder.Build(); | ||
|
||
app.MapDefaultEndpoints(); | ||
|
||
var globalSettings = app.Services.GetRequiredService<GlobalSettings>(); | ||
var logger = app.Services.GetRequiredService<ILogger<Startup>>(); | ||
|
||
startup.Configure(app, app.Environment, app.Lifetime, globalSettings, logger); | ||
|
||
app.MapDefaultControllerRoute(); | ||
|
||
if (!globalSettings.SelfHosted) | ||
{ | ||
app.MapHealthChecks("/healthz"); | ||
|
||
app.MapHealthChecks("/healthz/extended", new HealthCheckOptions | ||
{ | ||
webBuilder.UseStartup<Startup>(); | ||
webBuilder.ConfigureLogging((hostingContext, logging) => | ||
logging.AddSerilog(hostingContext, (e, globalSettings) => | ||
{ | ||
var context = e.Properties["SourceContext"].ToString(); | ||
if (e.Exception != null && | ||
(e.Exception.GetType() == typeof(SecurityTokenValidationException) || | ||
e.Exception.Message == "Bad security stamp.")) | ||
{ | ||
return false; | ||
} | ||
|
||
if ( | ||
context.Contains(typeof(IpRateLimitMiddleware).FullName)) | ||
{ | ||
return e.Level >= globalSettings.MinLogLevel.ApiSettings.IpRateLimit; | ||
} | ||
|
||
if (context.Contains("Duende.IdentityServer.Validation.TokenValidator") || | ||
context.Contains("Duende.IdentityServer.Validation.TokenRequestValidator")) | ||
{ | ||
return e.Level >= globalSettings.MinLogLevel.ApiSettings.IdentityToken; | ||
} | ||
|
||
return e.Level >= globalSettings.MinLogLevel.ApiSettings.Default; | ||
})); | ||
}) | ||
.Build() | ||
.Run(); | ||
ResponseWriter = HealthCheckServiceExtensions.WriteResponse | ||
}); | ||
} | ||
|
||
app.Run(); | ||
|
||
// Host | ||
// .CreateDefaultBuilder(args) | ||
// .ConfigureCustomAppConfiguration(args) | ||
// .ConfigureWebHostDefaults(webBuilder => | ||
// { | ||
// webBuilder.UseStartup<Startup>(); | ||
// webBuilder.ConfigureLogging((hostingContext, logging) => | ||
// logging.AddSerilog(hostingContext, (e, globalSettings) => | ||
// { | ||
// var context = e.Properties["SourceContext"].ToString(); | ||
// if (e.Exception != null && | ||
// (e.Exception.GetType() == typeof(SecurityTokenValidationException) || | ||
// e.Exception.Message == "Bad security stamp.")) | ||
// { | ||
// return false; | ||
// } | ||
|
||
// if ( | ||
// context.Contains(typeof(IpRateLimitMiddleware).FullName)) | ||
// { | ||
// return e.Level >= globalSettings.MinLogLevel.ApiSettings.IpRateLimit; | ||
// } | ||
|
||
// if (context.Contains("Duende.IdentityServer.Validation.TokenValidator") || | ||
// context.Contains("Duende.IdentityServer.Validation.TokenRequestValidator")) | ||
// { | ||
// return e.Level >= globalSettings.MinLogLevel.ApiSettings.IdentityToken; | ||
// } | ||
|
||
// return e.Level >= globalSettings.MinLogLevel.ApiSettings.Default; | ||
// })); | ||
// }) | ||
// .Build() | ||
// .Run(); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
var builder = DistributedApplication.CreateBuilder(args); | ||
|
||
var bitwardenid = builder.AddParameter("bitwardenid", secret: true); | ||
var bitwardenkey = builder.AddParameter("bitwardenkey", secret: true); | ||
|
||
// var mail = builder.AddMailPit("mail") | ||
// .WithLifetime(ContainerLifetime.Persistent) | ||
// .WithDataVolume("mail-data") | ||
// .WithHttpHealthCheck("/health"); | ||
|
||
builder.AddGlobalSettings(c => | ||
{ | ||
// var smtp = mail.Resource.GetEndpoint("smtp"); | ||
|
||
// Set selfhosted to true in all projects | ||
// and pass bitwarden id and keys | ||
c.WithEnvironment(context => | ||
{ | ||
var prefix = "globalSettings__"; | ||
context.EnvironmentVariables[$"{prefix}selfHosted"] = "true"; | ||
context.EnvironmentVariables[$"{prefix}installation__id"] = bitwardenid; | ||
context.EnvironmentVariables[$"{prefix}installation__key"] = bitwardenkey; | ||
|
||
// context.EnvironmentVariables[$"{prefix}mail__smtp__host"] = smtp.Property(EndpointProperty.Host); | ||
// context.EnvironmentVariables[$"{prefix}mail__smtp__port"] = smtp.Property(EndpointProperty.Port); | ||
}); | ||
}); | ||
|
||
var iconServce = builder.AddProject<Projects.Icons>("icons", launchProfileName: "Icons"); | ||
|
||
var sql = builder.AddSqlServer("sql") | ||
.WithLifetime(ContainerLifetime.Persistent) | ||
.WithDataVolume("sql-data"); | ||
var theDb = sql.AddDatabase("the-db"); | ||
|
||
var identityapi = builder.AddProject<Projects.Identity>("identity", launchProfileName: "Identity") | ||
.WithHttpHealthCheck("/health") | ||
.WithDb(theDb); | ||
|
||
builder.AddProject<Projects.Api>("api", launchProfileName: "Api") | ||
.WithHttpHealthCheck("/health") | ||
.WithReference(identityapi) | ||
.WithDb(theDb); | ||
|
||
builder.AddProject<Projects.Billing>("billing", launchProfileName: "Billing") | ||
.WithUrlForEndpoint("http", url => url.Url = "/swagger") | ||
.WithHttpHealthCheck("/alive"); | ||
|
||
builder.AddProject<Projects.Admin>("admin", launchProfileName: "Admin") | ||
.WithHttpHealthCheck("/alive") | ||
.WithReference(identityapi) | ||
.WithDb(theDb) | ||
.InstallAssets(); | ||
|
||
builder.Build().Run(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Sdk Name="Aspire.AppHost.Sdk" Version="9.3.0" /> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<UserSecretsId>79ddae47-9251-44d8-9897-e44dd94074c5</UserSecretsId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.3.0" /> | ||
<PackageReference Include="Aspire.Hosting.SqlServer" Version="9.3.0" /> | ||
<PackageReference Include="CommunityToolkit.Aspire.Hosting.MailPit" Version="9.5.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Admin\Admin.csproj" /> | ||
<ProjectReference Include="..\Api\Api.csproj" /> | ||
<ProjectReference Include="..\Billing\Billing.csproj" /> | ||
<ProjectReference Include="..\Icons\Icons.csproj" /> | ||
<ProjectReference Include="..\Identity\Identity.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๐ @justindbaur, @withinfocus - Wanted to draw your attention to this. I'm not sure who owns the .Net SDK dependency, but it looks like it needs to update before we merge this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, and we are currently planning on just jumping to 10. We'll see.