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
5 changes: 5 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
<PackageVersion Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
<PackageVersion Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.8" />
<PackageVersion Include="Microsoft.Azure.SignalR" Version="1.32.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="5.0.3" />
<PackageVersion Include="Microsoft.Extensions.ApiDescription.Server" Version="9.0.5" />
<PackageVersion Include="Microsoft.FeatureManagement" Version="3.2.0" />
Expand Down Expand Up @@ -106,6 +108,7 @@
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="[8.0.0,10.0.0)" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="[8.0.2,10.0.0)" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="[8.0.1,10.0.0)" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" Version="[8.0.8,10.0.0)" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="[8.0.1,10.0.0)" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="[8.0.1,10.0.0)" />
<PackageVersion Include="Microsoft.Extensions.ObjectPool" Version="[8.0.23,10.0.0)" />
Expand All @@ -117,6 +120,7 @@
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="[9.0.0,11.0.0)" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="[9.0.0,11.0.0)" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="[9.0.0,11.0.0)" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" Version="[9.0.0,11.0.0)" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="[9.0.0,11.0.0)" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="[9.0.0,11.0.0)" />
<PackageVersion Include="Microsoft.Extensions.ObjectPool" Version="[9.0.12,11.0.0)" />
Expand All @@ -132,6 +136,7 @@
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.ObjectPool" Version="10.0.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ItemGroup>
<ProjectReference Include="..\..\Persistence\Wolverine.Marten\Wolverine.Marten.csproj" />
<ProjectReference Include="..\Wolverine.Http\Wolverine.Http.csproj" />
<PackageReference Include="Marten.AspNetCore" />
<ProjectReference Include="../../../../marten/src/Marten.AspNetCore/Marten.AspNetCore.csproj" />
</ItemGroup>

</Project>
59 changes: 59 additions & 0 deletions src/Http/Wolverine.Http/HttpCapabilityDescriptor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using JasperFx.Core;
using JasperFx.Core.Reflection;
using JasperFx.Descriptors;
using Wolverine.Configuration.Capabilities;
using Wolverine.Http.CodeGen;

namespace Wolverine.Http;

/// <summary>
/// Describes Wolverine.HTTP capabilities including options and all HTTP routes
/// for display in CritterWatch.
/// </summary>
public class HttpCapabilityDescriptor : ICapabilityDescriptor
{
private readonly WolverineHttpOptions _options;

public HttpCapabilityDescriptor(WolverineHttpOptions options)
{
_options = options;
}

public OptionsDescription Describe()
{
var description = new OptionsDescription
{
Subject = "Wolverine.Http"
};

description.AddTag("http");

description.AddValue(nameof(_options.WarmUpRoutes), _options.WarmUpRoutes);
description.AddValue(nameof(_options.ServiceProviderSource), _options.ServiceProviderSource);

var endpoints = _options.Endpoints;
if (endpoints != null)
{
var routeSet = description.AddChildSet("Routes");
routeSet.SummaryColumns = ["HttpMethods", "Route", "Endpoint"];

foreach (var chain in endpoints.Chains.OrderBy(c => c.RoutePattern?.RawText ?? string.Empty))
{
var routeDescription = new OptionsDescription
{
Subject = chain.RoutePattern?.RawText ?? string.Empty,
Title = chain.RoutePattern?.RawText ?? string.Empty
};

routeDescription.AddValue("HttpMethods", chain.HttpMethods.Join(", "));
routeDescription.AddValue("Route", chain.RoutePattern?.RawText ?? string.Empty);
routeDescription.AddValue("Endpoint",
$"{chain.Method.HandlerType.FullNameInCode()}.{chain.Method.Method.Name}");

routeSet.Rows.Add(routeDescription);
}
}

return description;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Wolverine.Configuration;
using Wolverine.Configuration.Capabilities;
using Wolverine.Http.CodeGen;
using Wolverine.Http.Transport;
using Wolverine.Http.Validation;
Expand Down Expand Up @@ -161,10 +162,12 @@ public static IServiceCollection AddWolverineHttp(this IServiceCollection servic
services.AddSingleton<WolverineHttpOptions>();
services.AddSingleton<NewtonsoftHttpSerialization>();
services.AddSingleton<HttpTransportExecutor>();

services.AddSingleton(typeof(IProblemDetailSource<>), typeof(ProblemDetailSource<>));
services.AddSingleton<MatcherPolicy, ContentTypeEndpointSelectorPolicy>();

services.AddSingleton<ICapabilityDescriptor, HttpCapabilityDescriptor>();

services.ConfigureWolverine(opts =>
{
opts.CodeGeneration.Sources.Add(new NullableHttpContextSource());
Expand Down
1 change: 1 addition & 0 deletions src/Persistence/MySql/Wolverine.MySql/MySqlMessageStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ public override IEnumerable<ISchemaObject> AllObjects()
var tenantTable = new Table(new DbObjectName(SchemaName, DatabaseConstants.TenantsTableName));
tenantTable.AddColumn<string>(StorageConstants.TenantIdColumn).AsPrimaryKey();
tenantTable.AddColumn<string>(StorageConstants.ConnectionStringColumn).NotNull();
tenantTable.AddColumn<bool>(DatabaseConstants.DisabledColumn).DefaultValueByExpression("false").NotNull();
yield return tenantTable;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<ItemGroup>
<PackageReference Include="MySqlConnector" />
<PackageReference Include="Weasel.MySql" />
<ProjectReference Include="..\..\..\..\..\weasel\src\Weasel.MySql\Weasel.MySql.csproj" />
</ItemGroup>

<Import Project="../../../../Analysis.Build.props" />
Expand Down
83 changes: 82 additions & 1 deletion src/Persistence/Oracle/Wolverine.Oracle/OracleMessageStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ public IEnumerable<ISchemaObject> AllObjects()
var tenantTable = new Table(new OracleObjectName(SchemaName, DatabaseConstants.TenantsTableName.ToUpperInvariant()));
tenantTable.AddColumn("tenant_id", "VARCHAR2(100)").AsPrimaryKey();
tenantTable.AddColumn("connection_string", "VARCHAR2(500)").NotNull();
tenantTable.AddColumn("disabled", "NUMBER(1)").DefaultValueByExpression("0").NotNull();
yield return tenantTable;
}

Expand Down Expand Up @@ -473,7 +474,7 @@ public async Task<IReadOnlyList<Assignment<string>>> LoadAllTenantConnectionStri
try
{
var cmd = conn.CreateCommand(
$"SELECT tenant_id, connection_string FROM {SchemaName}.{DatabaseConstants.TenantsTableName}");
$"SELECT tenant_id, connection_string FROM {SchemaName}.{DatabaseConstants.TenantsTableName} WHERE disabled = 0");
await using var reader = await cmd.ExecuteReaderAsync(_cancellation);

while (await reader.ReadAsync(_cancellation))
Expand Down Expand Up @@ -520,4 +521,84 @@ public async Task SeedDatabasesAsync(ITenantedSource<string> tenantConnectionStr
await conn.CloseAsync();
}
}

public async Task AddTenantRecordAsync(string tenantId, string connectionString)
{
await using var conn = CreateConnection();
await conn.OpenAsync(_cancellation);
try
{
// Oracle MERGE for upsert
var cmd = conn.CreateCommand(
$"MERGE INTO {SchemaName}.{DatabaseConstants.TenantsTableName} t USING (SELECT :id AS tenant_id FROM DUAL) s ON (t.tenant_id = s.tenant_id) WHEN MATCHED THEN UPDATE SET connection_string = :conn, disabled = 0 WHEN NOT MATCHED THEN INSERT (tenant_id, connection_string, disabled) VALUES (:id, :conn, 0)");
cmd.With("id", tenantId);
cmd.With("conn", connectionString);
await cmd.ExecuteNonQueryAsync(_cancellation);
}
finally
{
await conn.CloseAsync();
}
}

public async Task SetTenantDisabledAsync(string tenantId, bool disabled)
{
await using var conn = CreateConnection();
await conn.OpenAsync(_cancellation);
try
{
var cmd = conn.CreateCommand(
$"UPDATE {SchemaName}.{DatabaseConstants.TenantsTableName} SET disabled = :disabled WHERE tenant_id = :id");
cmd.With("id", tenantId);
cmd.With("disabled", disabled ? 1 : 0);
await cmd.ExecuteNonQueryAsync(_cancellation);
}
finally
{
await conn.CloseAsync();
}
}

public async Task DeleteTenantRecordAsync(string tenantId)
{
await using var conn = CreateConnection();
await conn.OpenAsync(_cancellation);
try
{
var cmd = conn.CreateCommand(
$"DELETE FROM {SchemaName}.{DatabaseConstants.TenantsTableName} WHERE tenant_id = :id");
cmd.With("id", tenantId);
await cmd.ExecuteNonQueryAsync(_cancellation);
}
finally
{
await conn.CloseAsync();
}
}

public async Task<IReadOnlyList<string>> LoadDisabledTenantIdsAsync()
{
var list = new List<string>();
await using var conn = CreateConnection();
await conn.OpenAsync(_cancellation);
try
{
await using var reader = await conn.CreateCommand(
$"SELECT tenant_id FROM {SchemaName}.{DatabaseConstants.TenantsTableName} WHERE disabled = 1")
.ExecuteReaderAsync(_cancellation);

while (await reader.ReadAsync(_cancellation))
{
list.Add(await reader.GetFieldValueAsync<string>(0));
}

await reader.CloseAsync();
}
finally
{
await conn.CloseAsync();
}

return list;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<ItemGroup>
<PackageReference Include="Oracle.ManagedDataAccess.Core" />
<PackageReference Include="Weasel.Oracle" />
<ProjectReference Include="..\..\..\..\..\weasel\src\Weasel.Oracle\Weasel.Oracle.csproj" />
</ItemGroup>

<Import Project="../../../../Analysis.Build.props" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational"/>
<PackageReference Include="Weasel.EntityFrameworkCore" />
<ProjectReference Include="..\..\..\..\weasel\src\Weasel.EntityFrameworkCore\Weasel.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\Wolverine.RDBMS\Wolverine.RDBMS.csproj"/>
</ItemGroup>

Expand Down
Loading
Loading