Skip to content

Commit

Permalink
Add Bitwarden.Server.Sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
justindbaur committed Nov 14, 2024
1 parent 6cb9a52 commit 0a01210
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 0 deletions.
20 changes: 20 additions & 0 deletions bitwarden-dotnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ 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
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{D6DCF0A7-5FD8-499E-824C-0FF534DE53F6}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MinimalApi", "extensions\Bitwarden.Server.Sdk\tests\MinimalApi\MinimalApi.csproj", "{37636625-2DD3-465F-B4A1-7C1E91E25761}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -78,6 +86,14 @@ 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
{37636625-2DD3-465F-B4A1-7C1E91E25761}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{37636625-2DD3-465F-B4A1-7C1E91E25761}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37636625-2DD3-465F-B4A1-7C1E91E25761}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37636625-2DD3-465F-B4A1-7C1E91E25761}.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 +110,9 @@ 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}
{D6DCF0A7-5FD8-499E-824C-0FF534DE53F6} = {82253883-A5E2-4917-A690-A744C3855FAB}
{37636625-2DD3-465F-B4A1-7C1E91E25761} = {D6DCF0A7-5FD8-499E-824C-0FF534DE53F6}
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>
</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>
8 changes: 8 additions & 0 deletions extensions/Bitwarden.Server.Sdk/src/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# 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
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>
11 changes: 11 additions & 0 deletions extensions/Bitwarden.Server.Sdk/tests/MinimalApi/MinimalApi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<Sdk Name="Bitwarden.Server.Sdk" Version="0.1.10" />

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

</Project>
7 changes: 7 additions & 0 deletions extensions/Bitwarden.Server.Sdk/tests/MinimalApi/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var builder = WebApplication.CreateBuilder(args);

builder.UseBitwardenDefaults();

var app = builder.Build();

app.Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:33688",
"sslPort": 44324
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5079",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7263;http://localhost:5079",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

0 comments on commit 0a01210

Please sign in to comment.