mirror of
https://github.com/bitwarden/server
synced 2025-12-16 00:03:54 +00:00
SDK integration in db seeder
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -225,3 +225,5 @@ src/Notifications/Notifications.zip
|
|||||||
bitwarden_license/src/Portal/Portal.zip
|
bitwarden_license/src/Portal/Portal.zip
|
||||||
bitwarden_license/src/Sso/Sso.zip
|
bitwarden_license/src/Sso/Sso.zip
|
||||||
**/src/**/flags.json
|
**/src/**/flags.json
|
||||||
|
NativeMethods.g.cs
|
||||||
|
util/RustSdk/rust/target
|
||||||
|
|||||||
@@ -133,6 +133,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Seeder", "util\Seeder\Seede
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbSeederUtility", "util\DbSeederUtility\DbSeederUtility.csproj", "{17A89266-260A-4A03-81AE-C0468C6EE06E}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbSeederUtility", "util\DbSeederUtility\DbSeederUtility.csproj", "{17A89266-260A-4A03-81AE-C0468C6EE06E}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RustSdk", "util\RustSdk\RustSdk.csproj", "{D1513D90-E4F5-44A9-9121-5E46E3E4A3F7}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -337,6 +339,10 @@ Global
|
|||||||
{17A89266-260A-4A03-81AE-C0468C6EE06E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{17A89266-260A-4A03-81AE-C0468C6EE06E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{17A89266-260A-4A03-81AE-C0468C6EE06E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{17A89266-260A-4A03-81AE-C0468C6EE06E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{17A89266-260A-4A03-81AE-C0468C6EE06E}.Release|Any CPU.Build.0 = Release|Any CPU
|
{17A89266-260A-4A03-81AE-C0468C6EE06E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{D1513D90-E4F5-44A9-9121-5E46E3E4A3F7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D1513D90-E4F5-44A9-9121-5E46E3E4A3F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D1513D90-E4F5-44A9-9121-5E46E3E4A3F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D1513D90-E4F5-44A9-9121-5E46E3E4A3F7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@@ -391,6 +397,7 @@ Global
|
|||||||
{3631BA42-6731-4118-A917-DAA43C5032B9} = {DD5BD056-4AAE-43EF-BBD2-0B569B8DA84F}
|
{3631BA42-6731-4118-A917-DAA43C5032B9} = {DD5BD056-4AAE-43EF-BBD2-0B569B8DA84F}
|
||||||
{9A612EBA-1C0E-42B8-982B-62F0EE81000A} = {DD5BD056-4AAE-43EF-BBD2-0B569B8DA84E}
|
{9A612EBA-1C0E-42B8-982B-62F0EE81000A} = {DD5BD056-4AAE-43EF-BBD2-0B569B8DA84E}
|
||||||
{17A89266-260A-4A03-81AE-C0468C6EE06E} = {DD5BD056-4AAE-43EF-BBD2-0B569B8DA84E}
|
{17A89266-260A-4A03-81AE-C0468C6EE06E} = {DD5BD056-4AAE-43EF-BBD2-0B569B8DA84E}
|
||||||
|
{D1513D90-E4F5-44A9-9121-5E46E3E4A3F7} = {DD5BD056-4AAE-43EF-BBD2-0B569B8DA84E}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {E01CBF68-2E20-425F-9EDB-E0A6510CA92F}
|
SolutionGuid = {E01CBF68-2E20-425F-9EDB-E0A6510CA92F}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace Bit.Api.IntegrationTest.AdminConsole.Controllers;
|
|||||||
|
|
||||||
public class OrganizationUsersControllerPerformanceTest(ITestOutputHelper testOutputHelper)
|
public class OrganizationUsersControllerPerformanceTest(ITestOutputHelper testOutputHelper)
|
||||||
{
|
{
|
||||||
[Theory(Skip = "Performance test")]
|
[Theory()]
|
||||||
[InlineData(100)]
|
[InlineData(100)]
|
||||||
[InlineData(60000)]
|
[InlineData(60000)]
|
||||||
public async Task GetAsync(int seats)
|
public async Task GetAsync(int seats)
|
||||||
|
|||||||
58
util/RustSdk/NativeMethods.cs
Normal file
58
util/RustSdk/NativeMethods.cs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace Bit.RustSDK;
|
||||||
|
|
||||||
|
public static partial class NativeMethods
|
||||||
|
{
|
||||||
|
// https://docs.microsoft.com/en-us/dotnet/standard/native-interop/cross-platform
|
||||||
|
// Library path will search
|
||||||
|
// win => __DllName, __DllName.dll
|
||||||
|
// linux, osx => __DllName.so, __DllName.dylib
|
||||||
|
|
||||||
|
static NativeMethods()
|
||||||
|
{
|
||||||
|
NativeLibrary.SetDllImportResolver(typeof(NativeMethods).Assembly, DllImportResolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
static IntPtr DllImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
|
||||||
|
{
|
||||||
|
if (libraryName != __DllName) return IntPtr.Zero;
|
||||||
|
|
||||||
|
var path = "runtimes/";
|
||||||
|
var extension = "";
|
||||||
|
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
|
{
|
||||||
|
path += "win-";
|
||||||
|
extension = ".dll";
|
||||||
|
}
|
||||||
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||||
|
{
|
||||||
|
path += "osx-";
|
||||||
|
extension = ".dylib";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
path += "linux-";
|
||||||
|
extension = ".so";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RuntimeInformation.ProcessArchitecture == Architecture.X86)
|
||||||
|
{
|
||||||
|
path += "x86";
|
||||||
|
}
|
||||||
|
else if (RuntimeInformation.ProcessArchitecture == Architecture.X64)
|
||||||
|
{
|
||||||
|
path += "x64";
|
||||||
|
}
|
||||||
|
else if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
|
||||||
|
{
|
||||||
|
path += "arm64";
|
||||||
|
}
|
||||||
|
|
||||||
|
path += "/native/" + __DllName + extension;
|
||||||
|
|
||||||
|
return NativeLibrary.Load(Path.Combine(AppContext.BaseDirectory, path), assembly, searchPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
26
util/RustSdk/RustSdk.csproj
Normal file
26
util/RustSdk/RustSdk.csproj
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<RootNamespace>Bit.RustSDK</RootNamespace>
|
||||||
|
<UserSecretsId>Bit.RustSDK</UserSecretsId>
|
||||||
|
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="rust/target/debug/libsdk.dylib">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
<PackageCopyToOutput>true</PackageCopyToOutput>
|
||||||
|
<Link>runtimes/osx-arm64/native/libsdk.dylib</Link>
|
||||||
|
</Content>
|
||||||
|
<Content Include="./rust/target/debug/libsdk.so">
|
||||||
|
<PackageCopyToOutput>true</PackageCopyToOutput>
|
||||||
|
</Content>
|
||||||
|
<Content Include="./rust/target/debug/libsdk.dll">
|
||||||
|
<PackageCopyToOutput>true</PackageCopyToOutput>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
2933
util/RustSdk/rust/Cargo.lock
generated
Normal file
2933
util/RustSdk/rust/Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
19
util/RustSdk/rust/Cargo.toml
Normal file
19
util/RustSdk/rust/Cargo.toml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
[package]
|
||||||
|
name = "sdk"
|
||||||
|
publish = false
|
||||||
|
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Bitwarden Inc"]
|
||||||
|
edition = "2021"
|
||||||
|
homepage = "https://bitwarden.com"
|
||||||
|
repository = "https://github.com/bitwarden/server"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
bitwarden-core = { git = "https://github.com/bitwarden/sdk-internal.git", rev = "b0c950dad701bc419c76e8a7d37bf5c17a6909d6" }
|
||||||
|
bitwarden-crypto = { git = "https://github.com/bitwarden/sdk-internal.git", rev = "b0c950dad701bc419c76e8a7d37bf5c17a6909d6" }
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
csbindgen = "=1.9.3"
|
||||||
9
util/RustSdk/rust/build.rs
Normal file
9
util/RustSdk/rust/build.rs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
fn main() {
|
||||||
|
csbindgen::Builder::default()
|
||||||
|
.input_extern_file("src/lib.rs")
|
||||||
|
.csharp_dll_name("libsdk")
|
||||||
|
.csharp_namespace("Bit.RustSDK")
|
||||||
|
.csharp_class_accessibility("public")
|
||||||
|
.generate_csharp_file("../NativeMethods.g.cs")
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
4
util/RustSdk/rust/src/lib.rs
Normal file
4
util/RustSdk/rust/src/lib.rs
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn my_add(x: i32, y: i32) -> i32 {
|
||||||
|
x + y
|
||||||
|
}
|
||||||
56
util/Sdk2/dotnet/NativeMethods.cs
Normal file
56
util/Sdk2/dotnet/NativeMethods.cs
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
internal static unsafe partial class NativeMethods
|
||||||
|
{
|
||||||
|
// https://docs.microsoft.com/en-us/dotnet/standard/native-interop/cross-platform
|
||||||
|
// Library path will search
|
||||||
|
// win => __DllName, __DllName.dll
|
||||||
|
// linux, osx => __DllName.so, __DllName.dylib
|
||||||
|
|
||||||
|
static NativeMethods()
|
||||||
|
{
|
||||||
|
NativeLibrary.SetDllImportResolver(typeof(NativeMethods).Assembly, DllImportResolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
static IntPtr DllImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
|
||||||
|
{
|
||||||
|
if (libraryName == __DllName)
|
||||||
|
{
|
||||||
|
var path = "runtimes/";
|
||||||
|
var extension = "";
|
||||||
|
|
||||||
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
|
{
|
||||||
|
path += "win-";
|
||||||
|
extension = ".dll";
|
||||||
|
}
|
||||||
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
|
||||||
|
{
|
||||||
|
path += "osx-";
|
||||||
|
extension = ".dylib";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
path += "linux-";
|
||||||
|
extension = ".so";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RuntimeInformation.ProcessArchitecture == Architecture.X86)
|
||||||
|
{
|
||||||
|
path += "x86";
|
||||||
|
}
|
||||||
|
else if (RuntimeInformation.ProcessArchitecture == Architecture.X64)
|
||||||
|
{
|
||||||
|
path += "x64";
|
||||||
|
}
|
||||||
|
else if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64)
|
||||||
|
{
|
||||||
|
path += "arm64";
|
||||||
|
}
|
||||||
|
|
||||||
|
path += "/native/" + __DllName + extension;
|
||||||
|
|
||||||
|
return NativeLibrary.Load(Path.Combine(AppContext.BaseDirectory, path), assembly, searchPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
return IntPtr.Zero;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using Bit.Infrastructure.EntityFramework.Models;
|
using Bit.Infrastructure.EntityFramework.Models;
|
||||||
|
using Bit.RustSDK;
|
||||||
|
|
||||||
namespace Bit.Seeder.Factories;
|
namespace Bit.Seeder.Factories;
|
||||||
|
|
||||||
@@ -7,6 +8,7 @@ public class UserSeeder
|
|||||||
{
|
{
|
||||||
public static User CreateUser(string email)
|
public static User CreateUser(string email)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine(NativeMethods.my_add(2, 3));
|
||||||
return new User
|
return new User
|
||||||
{
|
{
|
||||||
Id = Guid.NewGuid(),
|
Id = Guid.NewGuid(),
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
<ProjectReference Include="..\..\src\Core\Core.csproj" />
|
<ProjectReference Include="..\..\src\Core\Core.csproj" />
|
||||||
<ProjectReference Include="..\..\src\Infrastructure.EntityFramework\Infrastructure.EntityFramework.csproj" />
|
<ProjectReference Include="..\..\src\Infrastructure.EntityFramework\Infrastructure.EntityFramework.csproj" />
|
||||||
<ProjectReference Include="..\..\src\SharedWeb\SharedWeb.csproj" />
|
<ProjectReference Include="..\..\src\SharedWeb\SharedWeb.csproj" />
|
||||||
|
<ProjectReference Include="..\RustSdk\RustSdk.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user