Skip to content

Commit

Permalink
Move Features to SDK (#70)
Browse files Browse the repository at this point in the history
* Move features to SDK

* Finish Features Migration

* Update Mode

* Lower TargetFramework

* Lower Microsoft.AspNetCore.TestHost Version
  • Loading branch information
justindbaur authored Dec 20, 2024
1 parent ac75a69 commit 99e0770
Show file tree
Hide file tree
Showing 34 changed files with 277 additions and 220 deletions.
30 changes: 20 additions & 10 deletions bitwarden-dotnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{C0
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MinimalApi", "extensions\Bitwarden.Extensions.Configuration\examples\MinimalApi\MinimalApi.csproj", "{0C4EE450-B1FF-42F6-AE44-9E79493A47B5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{1D751C2C-4102-4A95-B411-95F31FC50A26}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MinimalApi", "extensions\Bitwarden.Extensions.Hosting\examples\MinimalApi\MinimalApi.csproj", "{441E6BF0-4C2B-4512-9ECD-3C0390CE83C5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Bitwarden.Server.Sdk", "Bitwarden.Server.Sdk", "{82253883-A5E2-4917-A690-A744C3855FAB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bitwarden.Server.Sdk", "extensions\Bitwarden.Server.Sdk\src\Bitwarden.Server.Sdk.csproj", "{482E0C0B-586D-41B7-AF90-35CD8B383084}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{AEF7870E-D4E5-4ECC-88A1-BD2C5A6CC9C7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Standard", "extensions\Bitwarden.Server.Sdk\examples\Standard\Standard.csproj", "{061FB6BF-6F7E-4E48-BD89-6BA826B15432}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{384C7FC2-51CB-4723-B2EC-353833AB4354}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bitwarden.Server.Sdk.UnitTests", "extensions\Bitwarden.Server.Sdk\tests\Bitwarden.Server.Sdk.UnitTests\Bitwarden.Server.Sdk.UnitTests.csproj", "{6CF2554F-67DA-494F-A414-3974FAB96E6E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -78,14 +82,18 @@ Global
{0C4EE450-B1FF-42F6-AE44-9E79493A47B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0C4EE450-B1FF-42F6-AE44-9E79493A47B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0C4EE450-B1FF-42F6-AE44-9E79493A47B5}.Release|Any CPU.Build.0 = Release|Any CPU
{441E6BF0-4C2B-4512-9ECD-3C0390CE83C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{441E6BF0-4C2B-4512-9ECD-3C0390CE83C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{441E6BF0-4C2B-4512-9ECD-3C0390CE83C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{441E6BF0-4C2B-4512-9ECD-3C0390CE83C5}.Release|Any CPU.Build.0 = Release|Any CPU
{482E0C0B-586D-41B7-AF90-35CD8B383084}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{482E0C0B-586D-41B7-AF90-35CD8B383084}.Debug|Any CPU.Build.0 = Debug|Any CPU
{482E0C0B-586D-41B7-AF90-35CD8B383084}.Release|Any CPU.ActiveCfg = Release|Any CPU
{482E0C0B-586D-41B7-AF90-35CD8B383084}.Release|Any CPU.Build.0 = Release|Any CPU
{061FB6BF-6F7E-4E48-BD89-6BA826B15432}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{061FB6BF-6F7E-4E48-BD89-6BA826B15432}.Debug|Any CPU.Build.0 = Debug|Any CPU
{061FB6BF-6F7E-4E48-BD89-6BA826B15432}.Release|Any CPU.ActiveCfg = Release|Any CPU
{061FB6BF-6F7E-4E48-BD89-6BA826B15432}.Release|Any CPU.Build.0 = Release|Any CPU
{6CF2554F-67DA-494F-A414-3974FAB96E6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6CF2554F-67DA-494F-A414-3974FAB96E6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CF2554F-67DA-494F-A414-3974FAB96E6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CF2554F-67DA-494F-A414-3974FAB96E6E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5EC8B943-2E9E-437D-9FFC-D18B5DB4D7D0} = {695C76EF-1102-4805-970F-7C995EE54930}
Expand All @@ -100,9 +108,11 @@ Global
{2EABE7A5-6B68-4DAC-9D37-F312059C3C27} = {A1C893A6-887B-44FE-9DA3-B85E6ACADC55}
{C0631F08-D41D-4FCE-AE2B-2F4990254ACC} = {0008B44C-95E9-4A33-92EF-66741AC8AE47}
{0C4EE450-B1FF-42F6-AE44-9E79493A47B5} = {C0631F08-D41D-4FCE-AE2B-2F4990254ACC}
{1D751C2C-4102-4A95-B411-95F31FC50A26} = {A1C893A6-887B-44FE-9DA3-B85E6ACADC55}
{441E6BF0-4C2B-4512-9ECD-3C0390CE83C5} = {1D751C2C-4102-4A95-B411-95F31FC50A26}
{82253883-A5E2-4917-A690-A744C3855FAB} = {695C76EF-1102-4805-970F-7C995EE54930}
{482E0C0B-586D-41B7-AF90-35CD8B383084} = {82253883-A5E2-4917-A690-A744C3855FAB}
{AEF7870E-D4E5-4ECC-88A1-BD2C5A6CC9C7} = {82253883-A5E2-4917-A690-A744C3855FAB}
{061FB6BF-6F7E-4E48-BD89-6BA826B15432} = {AEF7870E-D4E5-4ECC-88A1-BD2C5A6CC9C7}
{384C7FC2-51CB-4723-B2EC-353833AB4354} = {82253883-A5E2-4917-A690-A744C3855FAB}
{6CF2554F-67DA-494F-A414-3974FAB96E6E} = {384C7FC2-51CB-4723-B2EC-353833AB4354}
EndGlobalSection
EndGlobal

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

18 changes: 18 additions & 0 deletions extensions/Bitwarden.Server.Sdk/examples/Standard/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#if BIT_INCLUDE_FEATURES
using Bitwarden.Server.Sdk.Features;
#endif

var builder = WebApplication.CreateBuilder(args);

builder.UseBitwardenSdk();

var app = builder.Build();

#if BIT_INCLUDE_FEATURES
app.MapGet("/features", (IFeatureService featureService) =>
{
return featureService.GetAll();
});
#endif

app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5087",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7186;http://localhost:5087",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
27 changes: 27 additions & 0 deletions extensions/Bitwarden.Server.Sdk/examples/Standard/Standard.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<Import Project="../../src/Sdk/Sdk.props" />

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(Mode)' == '1'">
<BitIncludeLogging>false</BitIncludeLogging>
</PropertyGroup>

<PropertyGroup Condition="'$(Mode)' == '2'">
<BitIncludeLogging>false</BitIncludeLogging>
<BitIncludeTelemetry>false</BitIncludeTelemetry>
</PropertyGroup>

<PropertyGroup Condition="'$(Mode)' == '3'">
<BitIncludeLogging>false</BitIncludeLogging>
<BitIncludeTelemetry>false</BitIncludeTelemetry>
<BitIncludeFeatures>false</BitIncludeFeatures>
</PropertyGroup>

<Import Project="../../src/Sdk/Sdk.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"Features": {
"KnownFlags": ["one"],
"FlagValues": {
"feature-one": true,
"feature-two": 1,
"feature-three": "my-value"
},
"KnownFlags": ["feature-one", "feature-two"]
"one": true
}
}
}
32 changes: 29 additions & 3 deletions extensions/Bitwarden.Server.Sdk/src/Bitwarden.Server.Sdk.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Not a true dependency, we just need one to make the CLI happy -->
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<PackageType>MSBuildSdk</PackageType>
<!-- We are a meta package, we don't actually want people to have to use netstandard to use us. -->
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
Expand All @@ -16,15 +15,31 @@
<PreReleaseVersionLabel>beta</PreReleaseVersionLabel>
<PreReleaseVersionIteration>1</PreReleaseVersionIteration>
<VersionSuffix Condition="'$(VersionSuffix)' == '' AND '$(IsPreRelease)' == 'true'">$(PreReleaseVersionLabel).$(PreReleaseVersionIteration)</VersionSuffix>
<ImplicitUsings>true</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
<DefineConstants>$(DefineConstants);BIT_INCLUDE_FEATURES;BIT_INCLUDE_TELEMETRY</DefineConstants>
</PropertyGroup>

<ItemGroup>
<InternalsVisibleTo Include="Bitwarden.Server.Sdk.UnitTests" />
</ItemGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<PropertyGroup>
<Authors>Bitwarden Inc.</Authors>
<Description>Bitwarden Server SDK.</Description>
</PropertyGroup>

<PropertyGroup>
<ExtensionsHostingRoot>../../Bitwarden.Extensions.Hosting/src/</ExtensionsHostingRoot>
<!-- Don't warn about our own internal usage of items -->
<NoWarn>$(NoWarn);BWSDK0001</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand All @@ -33,7 +48,18 @@
</ItemGroup>

<ItemGroup>
<Content Include="$(ExtensionsHostingRoot)**/*.cs" Exclude="$(ExtensionsHostingRoot)bin/**;$(ExtensionsHostingRoot)obj/**" Pack="true" PackagePath="content/Bitwarden.Server.Sdk" Visible="false" BuildAction="none" />
<Content Include="Content/**/*.cs" Pack="true" PackagePath="Content" Visible="false" BuildAction="none" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="3.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.4" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0" />
<PackageReference Include="LaunchDarkly.ServerSdk" Version="8.6.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Bitwarden.Extensions.Hosting.Features;
#pragma warning disable BWSDK0001

using Bitwarden.Server.Sdk.Features;

namespace Microsoft.AspNetCore.Builder;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System.ComponentModel;
using Bitwarden.Server.Sdk.Utilities.Internal;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Bitwarden.Extensions.Hosting.Features;
namespace Bitwarden.Server.Sdk.Features;

[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete(InternalConstants.InternalMessage, DiagnosticId = InternalConstants.InternalId)]
internal sealed class FeatureCheckMiddleware
{
private readonly RequestDelegate _next;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Bitwarden.Extensions.Hosting.Features;
using Bitwarden.Server.Sdk.Features;

namespace Microsoft.AspNetCore.Builder;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Bitwarden.Extensions.Hosting.Features;
#nullable enable

namespace Bitwarden.Server.Sdk.Features;

/// <summary>
/// A collection of Launch Darkly specific options.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Bitwarden.Extensions.Hosting.Features;
using Bitwarden.Server.Sdk.Features;

namespace Microsoft.Extensions.DependencyInjection;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma warning disable BWSDK0001
#nullable enable

using System.ComponentModel;
using Bitwarden.Server.Sdk.Utilities.Internal;

namespace Bitwarden.Server.Sdk.Features;


[EditorBrowsable(EditorBrowsableState.Never)]
[Obsolete(InternalConstants.InternalMessage, DiagnosticId = InternalConstants.InternalId)]
internal interface IFeatureMetadata
{
/// <summary>
/// A method to run to check if the feature is enabled.
/// </summary>
Func<IFeatureService, bool> FeatureCheck { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#nullable enable

using System.Text.Json.Nodes;

namespace Bitwarden.Extensions.Hosting.Features;
namespace Bitwarden.Server.Sdk.Features;

/// <summary>
/// Checks feature status for the current request.
Expand Down
Loading

0 comments on commit 99e0770

Please sign in to comment.