Skip to content

Commit 50210c9

Browse files
Server sdk prep for inclusion (#88)
* Split Features Into Seperate Package * Remove pragma * Restructure Tests to Allow for local nuget feed * Add comments on tests * Add docs to Features entrypoint * Don't include entrypoint in non-web sdk projects * Centralize TargetFramework * Update extensions/Bitwarden.Server.Sdk/src/Sdk/Sdk.targets Co-authored-by: Daniel García <[email protected]> --------- Co-authored-by: Daniel García <[email protected]>
1 parent d4bc532 commit 50210c9

33 files changed

+213
-229
lines changed

bitwarden-dotnet.sln

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Bitwarden.Server.Sdk", "Bit
3333
EndProject
3434
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bitwarden.Server.Sdk", "extensions\Bitwarden.Server.Sdk\src\Bitwarden.Server.Sdk.csproj", "{482E0C0B-586D-41B7-AF90-35CD8B383084}"
3535
EndProject
36-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{AEF7870E-D4E5-4ECC-88A1-BD2C5A6CC9C7}"
36+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{384C7FC2-51CB-4723-B2EC-353833AB4354}"
3737
EndProject
38-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Standard", "extensions\Bitwarden.Server.Sdk\examples\Standard\Standard.csproj", "{061FB6BF-6F7E-4E48-BD89-6BA826B15432}"
38+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bitwarden.Server.Sdk.IntegrationTests", "extensions\Bitwarden.Server.Sdk\tests\Bitwarden.Server.Sdk.IntegrationTests\Bitwarden.Server.Sdk.IntegrationTests.csproj", "{C0601B8C-1A72-400F-8CCF-C5493221E555}"
3939
EndProject
40-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{384C7FC2-51CB-4723-B2EC-353833AB4354}"
40+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Bitwarden.Server.Sdk.Features", "Bitwarden.Server.Sdk.Features", "{026589E0-5AAA-44EB-B973-3CFFF5B54AFC}"
4141
EndProject
42-
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}"
42+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bitwarden.Server.Sdk.Features", "extensions\Bitwarden.Server.Sdk.Features\src\Bitwarden.Server.Sdk.Features.csproj", "{DF914CD1-F916-4A58-B749-625DB67FAAA7}"
4343
EndProject
44-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bitwarden.Server.Sdk.IntegrationTests", "extensions\Bitwarden.Server.Sdk\tests\Bitwarden.Server.Sdk.IntegrationTests\Bitwarden.Server.Sdk.IntegrationTests.csproj", "{C0601B8C-1A72-400F-8CCF-C5493221E555}"
44+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{4949B721-5C7F-4D85-AB35-F57B54D7A6E6}"
45+
EndProject
46+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bitwarden.Server.Sdk.Features.Tests", "extensions\Bitwarden.Server.Sdk.Features\tests\Bitwarden.Server.Sdk.Features.Tests\Bitwarden.Server.Sdk.Features.Tests.csproj", "{1789F567-87B3-4313-80CF-E3CCFA1B6D5E}"
4547
EndProject
4648
Global
4749
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -88,18 +90,18 @@ Global
8890
{482E0C0B-586D-41B7-AF90-35CD8B383084}.Debug|Any CPU.Build.0 = Debug|Any CPU
8991
{482E0C0B-586D-41B7-AF90-35CD8B383084}.Release|Any CPU.ActiveCfg = Release|Any CPU
9092
{482E0C0B-586D-41B7-AF90-35CD8B383084}.Release|Any CPU.Build.0 = Release|Any CPU
91-
{061FB6BF-6F7E-4E48-BD89-6BA826B15432}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
92-
{061FB6BF-6F7E-4E48-BD89-6BA826B15432}.Debug|Any CPU.Build.0 = Debug|Any CPU
93-
{061FB6BF-6F7E-4E48-BD89-6BA826B15432}.Release|Any CPU.ActiveCfg = Release|Any CPU
94-
{061FB6BF-6F7E-4E48-BD89-6BA826B15432}.Release|Any CPU.Build.0 = Release|Any CPU
95-
{6CF2554F-67DA-494F-A414-3974FAB96E6E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
96-
{6CF2554F-67DA-494F-A414-3974FAB96E6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
97-
{6CF2554F-67DA-494F-A414-3974FAB96E6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
98-
{6CF2554F-67DA-494F-A414-3974FAB96E6E}.Release|Any CPU.Build.0 = Release|Any CPU
9993
{C0601B8C-1A72-400F-8CCF-C5493221E555}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
10094
{C0601B8C-1A72-400F-8CCF-C5493221E555}.Debug|Any CPU.Build.0 = Debug|Any CPU
10195
{C0601B8C-1A72-400F-8CCF-C5493221E555}.Release|Any CPU.ActiveCfg = Release|Any CPU
10296
{C0601B8C-1A72-400F-8CCF-C5493221E555}.Release|Any CPU.Build.0 = Release|Any CPU
97+
{DF914CD1-F916-4A58-B749-625DB67FAAA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
98+
{DF914CD1-F916-4A58-B749-625DB67FAAA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
99+
{DF914CD1-F916-4A58-B749-625DB67FAAA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
100+
{DF914CD1-F916-4A58-B749-625DB67FAAA7}.Release|Any CPU.Build.0 = Release|Any CPU
101+
{1789F567-87B3-4313-80CF-E3CCFA1B6D5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
102+
{1789F567-87B3-4313-80CF-E3CCFA1B6D5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
103+
{1789F567-87B3-4313-80CF-E3CCFA1B6D5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
104+
{1789F567-87B3-4313-80CF-E3CCFA1B6D5E}.Release|Any CPU.Build.0 = Release|Any CPU
103105
EndGlobalSection
104106
GlobalSection(NestedProjects) = preSolution
105107
{5EC8B943-2E9E-437D-9FFC-D18B5DB4D7D0} = {695C76EF-1102-4805-970F-7C995EE54930}
@@ -116,10 +118,11 @@ Global
116118
{0C4EE450-B1FF-42F6-AE44-9E79493A47B5} = {C0631F08-D41D-4FCE-AE2B-2F4990254ACC}
117119
{82253883-A5E2-4917-A690-A744C3855FAB} = {695C76EF-1102-4805-970F-7C995EE54930}
118120
{482E0C0B-586D-41B7-AF90-35CD8B383084} = {82253883-A5E2-4917-A690-A744C3855FAB}
119-
{AEF7870E-D4E5-4ECC-88A1-BD2C5A6CC9C7} = {82253883-A5E2-4917-A690-A744C3855FAB}
120-
{061FB6BF-6F7E-4E48-BD89-6BA826B15432} = {AEF7870E-D4E5-4ECC-88A1-BD2C5A6CC9C7}
121121
{384C7FC2-51CB-4723-B2EC-353833AB4354} = {82253883-A5E2-4917-A690-A744C3855FAB}
122-
{6CF2554F-67DA-494F-A414-3974FAB96E6E} = {384C7FC2-51CB-4723-B2EC-353833AB4354}
123122
{C0601B8C-1A72-400F-8CCF-C5493221E555} = {384C7FC2-51CB-4723-B2EC-353833AB4354}
123+
{026589E0-5AAA-44EB-B973-3CFFF5B54AFC} = {695C76EF-1102-4805-970F-7C995EE54930}
124+
{DF914CD1-F916-4A58-B749-625DB67FAAA7} = {026589E0-5AAA-44EB-B973-3CFFF5B54AFC}
125+
{4949B721-5C7F-4D85-AB35-F57B54D7A6E6} = {026589E0-5AAA-44EB-B973-3CFFF5B54AFC}
126+
{1789F567-87B3-4313-80CF-E3CCFA1B6D5E} = {4949B721-5C7F-4D85-AB35-F57B54D7A6E6}
124127
EndGlobalSection
125128
EndGlobal
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
<PropertyGroup>
10+
<VersionPrefix>0.0.2</VersionPrefix>
11+
<PreReleaseVersionLabel>beta</PreReleaseVersionLabel>
12+
<PreReleaseVersionIteration>1</PreReleaseVersionIteration>
13+
<VersionSuffix Condition="'$(VersionSuffix)' == '' AND '$(IsPreRelease)' == 'true'">$(PreReleaseVersionLabel).$(PreReleaseVersionIteration)</VersionSuffix>
14+
</PropertyGroup>
15+
16+
<ItemGroup>
17+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<PackageReference Include="LaunchDarkly.ServerSdk" Version="8.6.0" />
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<InternalsVisibleTo Include="Bitwarden.Server.Sdk" />
26+
<InternalsVisibleTo Include="Bitwarden.Server.Sdk.Features.Tests" />
27+
</ItemGroup>
28+
29+
</Project>
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#pragma warning disable BWSDK0001
2-
31
using Bitwarden.Server.Sdk.Features;
42

53
namespace Microsoft.AspNetCore.Builder;

extensions/Bitwarden.Server.Sdk/src/Content/Features/FeatureCheckMiddleware.cs renamed to extensions/Bitwarden.Server.Sdk.Features/src/FeatureCheckMiddleware.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
using System.ComponentModel;
2-
using Bitwarden.Server.Sdk.Utilities.Internal;
32
using Microsoft.AspNetCore.Http;
43
using Microsoft.AspNetCore.Mvc;
54
using Microsoft.Extensions.Hosting;
65
using Microsoft.Extensions.Logging;
76

87
namespace Bitwarden.Server.Sdk.Features;
98

10-
[EditorBrowsable(EditorBrowsableState.Never)]
11-
[Obsolete(InternalConstants.InternalMessage, DiagnosticId = InternalConstants.InternalId)]
129
internal sealed class FeatureCheckMiddleware
1310
{
1411
private readonly RequestDelegate _next;

extensions/Bitwarden.Server.Sdk/src/Content/Features/FeatureFlagOptions.cs renamed to extensions/Bitwarden.Server.Sdk.Features/src/FeatureFlagOptions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable enable
2-
31
namespace Bitwarden.Server.Sdk.Features;
42

53
/// <summary>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
using Bitwarden.Server.Sdk.Features;
2+
using Microsoft.Extensions.Configuration;
3+
using Microsoft.Extensions.DependencyInjection.Extensions;
4+
using LaunchDarkly.Sdk.Server.Interfaces;
25

36
namespace Microsoft.Extensions.DependencyInjection;
47

@@ -7,6 +10,34 @@ namespace Microsoft.Extensions.DependencyInjection;
710
/// </summary>
811
public static class ServiceCollectionExtensions
912
{
13+
/// <summary>
14+
/// Adds Feature flag related services to <see cref="IServiceCollection"/>. This makes <see cref="IFeatureService"/>
15+
/// available. This method does not need to be called manually if <c>UseBitwardenSdk</c> is used alongside the
16+
/// MSBuild property <c>BitIncludeFeatures</c> is set to <c>true</c> which is the default value.
17+
/// </summary>
18+
/// <param name="services">The service collection to add services to.</param>
19+
/// <param name="configuration">The configuration to be used to customize features.</param>
20+
/// <returns>The <see cref="IServiceCollection"/> to chain additional calls.</returns>
21+
public static IServiceCollection AddFeatureFlagServices(this IServiceCollection services, IConfiguration configuration)
22+
{
23+
ArgumentNullException.ThrowIfNull(services);
24+
25+
services.AddProblemDetails();
26+
services.AddHttpContextAccessor();
27+
28+
services.Configure<FeatureFlagOptions>(configuration.GetSection("Features"));
29+
30+
services.TryAddSingleton<LaunchDarklyClientProvider>();
31+
32+
// This needs to be scoped so a "new" ILdClient can be given per request, this makes it possible to
33+
// have the ILdClient be rebuilt if configuration changes but for the most part this will return a cached
34+
// client from LaunchDarklyClientProvider, effectively being a singleton.
35+
services.TryAddScoped<ILdClient>(sp => sp.GetRequiredService<LaunchDarklyClientProvider>().Get());
36+
services.TryAddScoped<IFeatureService, LaunchDarklyFeatureService>();
37+
38+
return services;
39+
}
40+
1041
/// <summary>
1142
/// Adds known feature flags to the <see cref="FeatureFlagOptions"/>. This makes these flags
1243
/// show up in <see cref="IFeatureService.GetAll()"/>.
Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
#nullable enable
2-
31
using System.ComponentModel;
42
using System.Reflection;
5-
using Bitwarden.Server.Sdk.Utilities.Internal;
63
using Microsoft.Extensions.Hosting;
74

85
namespace Bitwarden.Server.Sdk.Utilities;
96

10-
11-
[EditorBrowsable(EditorBrowsableState.Never)]
12-
[Obsolete(InternalConstants.InternalMessage, DiagnosticId = InternalConstants.InternalId)]
137
internal static class HostEnvironmentExtensions
148
{
159
public static VersionInfo? GetVersionInfo(this IHostEnvironment hostEnvironment)

extensions/Bitwarden.Server.Sdk/src/Content/Features/IFeatureMetadata.cs renamed to extensions/Bitwarden.Server.Sdk.Features/src/IFeatureMetadata.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
#pragma warning disable BWSDK0001
2-
#nullable enable
3-
41
using System.ComponentModel;
5-
using Bitwarden.Server.Sdk.Utilities.Internal;
62

73
namespace Bitwarden.Server.Sdk.Features;
84

9-
10-
[EditorBrowsable(EditorBrowsableState.Never)]
11-
[Obsolete(InternalConstants.InternalMessage, DiagnosticId = InternalConstants.InternalId)]
125
internal interface IFeatureMetadata
136
{
147
/// <summary>

extensions/Bitwarden.Server.Sdk/src/Content/Features/IFeatureService.cs renamed to extensions/Bitwarden.Server.Sdk.Features/src/IFeatureService.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#nullable enable
2-
31
using System.Text.Json.Nodes;
42

53
namespace Bitwarden.Server.Sdk.Features;

0 commit comments

Comments
 (0)