Skip to content
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

Add Bitwarden.Server.Sdk #43

Merged
merged 8 commits into from
Nov 19, 2024
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
10 changes: 10 additions & 0 deletions bitwarden-dotnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{1D
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
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -78,6 +82,10 @@ Global
{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
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5EC8B943-2E9E-437D-9FFC-D18B5DB4D7D0} = {695C76EF-1102-4805-970F-7C995EE54930}
Expand All @@ -94,5 +102,7 @@ Global
{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}
EndGlobalSection
EndGlobal
43 changes: 43 additions & 0 deletions extensions/Bitwarden.Server.Sdk/src/Bitwarden.Server.Sdk.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<!-- Not a true dependency, we just need one to make the CLI happy -->
<TargetFramework>netstandard2.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>
<NoWarn>$(NoWarn);NU5128</NoWarn>

<IncludeBuildOutput>false</IncludeBuildOutput>

<PackageReadmeFile>./README.md</PackageReadmeFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

<Version>0.1.10</Version>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๐ŸŽจ Need to get this working with CI so we can set it outside of code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will want it easily set in code. One of the downsides of SDKs is that they can only be consumed via nuget. So to test this I had to add a nuget source to the bin/Release directory of this project and had to make sure I incremented the version number in some way or I would have to clear my nuget cache everytime.

I do personally like the version being part of the source control though, I'm not a big fan of setting it in CI.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, well I can get behind the version in code but do appreciate when we can control it via something that isn't an engineer pushing a commit. Maybe we copy what server does with a workflow? Have to think about how tags are made too, as that's what I am doing here now where an engineer pushes a tag and then we make a GitHub release by hand -- really should be all streamlined to me and I really want this repo to showcase best practices.

</PropertyGroup>

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

<PropertyGroup>
<ExtensionsHostingRoot>../../Bitwarden.Extensions.Hosting/src/</ExtensionsHostingRoot>
</PropertyGroup>

<ItemGroup>
<None Include="README.md" Pack="true" PackagePath="/" />
<None Include="Sdk/**" Pack="true" PackagePath="Sdk/" />
</ItemGroup>

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

</Project>
18 changes: 18 additions & 0 deletions extensions/Bitwarden.Server.Sdk/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Bitwarden.Server.Sdk

The Bitwarden Server SDK is built for quickly getting started building
a Bitwarden-flavored service. The entrypoint for using it is adding `UseBitwardenSdk()`
on your web application and configuring MSBuild properties to configure the features you
want.

## Feature Flags
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

โ“ TODO?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, meant some brief documentation. Added it.


Feature flag support can be added by adding `<BitIncludeFeatures>true</BitIncludeFeatures>` to
your `csproj` file. The following APIs become available:

- `IFeatureService` for getting values of features.
- `RequireFeatureAttribute` for requiring a feature is enabled on controllers and controller actions.
- `IEndpointConventionBuilder.RequireFeature()` for requiring a feature is enabled on minimal APIs.
- `IApplicationBuilder.UseFeatureFlagChecks()` for adding the middleware to do the above checks.
- `IServiceCollection.AddKnownFeatureFlags()` for adding flags that will show up in `IFeatureService.GetAll()`
- `IServiceCollection.AddFeatureFlagValues()` for adding values for feature flags.
6 changes: 6 additions & 0 deletions extensions/Bitwarden.Server.Sdk/src/Sdk/Sdk.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<UsingBitwardenServerSdk>true</UsingBitwardenServerSdk>
</PropertyGroup>
</Project>
44 changes: 44 additions & 0 deletions extensions/Bitwarden.Server.Sdk/src/Sdk/Sdk.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
These properties are read in targets to allow the csproj file to customize the behavior
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Condition="'$(UsingBitwardenServerSdk)' == 'true'">
<Compile Include="$(MSBuildThisFileDirectory)../content/Bitwarden.Server.Sdk/**/*.cs" />
</ItemGroup>

<!-- TODO Use the constants in places to avoid any configuration that doesn't compile -->
<PropertyGroup>
<!-- Logging defaults to on -->
<BitIncludeLogging Condition="'$(BitIncludeLogging)' == ''">true</BitIncludeLogging>
<DefineConstants Condition="'$(BitIncludeLogging)' == 'true'">$(DefineConstants);BIT_INCLUDE_LOGGING</DefineConstants>
<!-- Telemetry defaults to on -->
<BitIncludeTelemetry Condition="'$(BitIncludeTelemetry)' == ''">true</BitIncludeTelemetry>
<DefineConstants Condition="'$(BitIncludeTelemetry)' == 'true'">$(DefineConstants);BIT_INCLUDE_TELEMETRY</DefineConstants>
<!-- Features defaults to on -->
<BitIncludeFeatures Condition="'$(BitIncludeFeatures)' == ''">true</BitIncludeFeatures>
<DefineConstants Condition="'$(BitIncludeFeatures)' == 'true'">$(DefineConstants);BIT_INCLUDE_FEATURES</DefineConstants>
</PropertyGroup>

<ItemGroup Condition="'$(UsingBitwardenServerSdk)' == 'true'">
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
</ItemGroup>

<!-- TODO: Allow for overriding specific package versions? -->
<ItemGroup Condition="'$(BitIncludeLogging)' == 'true'">
<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" />
</ItemGroup>

<ItemGroup Condition="'$(BitIncludeTelemetry)' == 'true'">
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0" />
</ItemGroup>

<ItemGroup Condition="'$(BitIncludeFeatures)' == 'true'">
<PackageReference Include="LaunchDarkly.ServerSdk" Version="8.6.0" />
</ItemGroup>
</Project>
Loading