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

.NET wrapper for SDK #193

Merged
merged 114 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
b435ac8
Implemented .NET library that wraps native C library and exposed its…
Aug 26, 2023
5fc8570
add NuGet package configuration
Aug 28, 2023
e6b9943
Merge branch 'master' into feature/csharp_-wrapper
bbujak Aug 28, 2023
9bbf5d8
buidl on PR created
Aug 28, 2023
d2c0ba0
Merge remote-tracking branch 'origin/feature/csharp_-wrapper' into fe…
Aug 28, 2023
21053bd
check if the same version exists , and if it doesn't deploy
Aug 28, 2023
748b1eb
name fix
Aug 28, 2023
796a4ef
update github actions
Aug 29, 2023
1cdc73d
build rust added in gitflow actions
Aug 29, 2023
8addb59
run prettier and re-write part for schemas
Aug 29, 2023
6337f7f
deploy to nuget fix
Aug 29, 2023
66d5273
add version
Aug 29, 2023
c0f00ab
copy lib to output when package is used
Aug 29, 2023
4979bcb
Merge branch 'master' into feature/csharp_-wrapper
bbujak Aug 30, 2023
6d94e77
- added editorconfig, code reformated
Aug 30, 2023
634cc18
Merge remote-tracking branch 'origin/feature/csharp_-wrapper' into fe…
Aug 30, 2023
14f7deb
Merge branch 'master' into feature/csharp_-wrapper
bbujak Aug 31, 2023
d214391
Merge branch 'master' into feature/csharp_-wrapper
bbujak Aug 31, 2023
f00851f
Merge branch 'master' into feature/csharp_-wrapper
bbujak Sep 2, 2023
f6f8ca2
temporary add pull_request so git action is registered
Sep 2, 2023
18f213a
fix version
Sep 2, 2023
0001770
just run on PR
Sep 2, 2023
8a220cd
we want to build the package
Sep 2, 2023
bf926bf
pack with specific version and publish the package
Sep 2, 2023
ade9277
use test name for now
Sep 2, 2023
6bfe7e0
changed api access
Sep 2, 2023
11fb8c9
copy libs after cargo build and pack them
Sep 2, 2023
28fb2a4
copy libs after cargo build and pack them
Sep 2, 2023
54c6682
find all id: libbitwarden_c files
Sep 2, 2023
62fd39d
use libbitwarden_c files
Sep 2, 2023
f31a094
use separated folder
Sep 2, 2023
b1ab18b
use separated folder
Sep 2, 2023
5ebe0a9
use separated folder
Sep 2, 2023
e2f690f
use separated folder
Sep 2, 2023
0d8c439
use separated folder
Sep 2, 2023
c92299e
use separated folder
Sep 3, 2023
07c5d4a
list files
Sep 3, 2023
c3f0a1d
separate folders
Sep 3, 2023
67400af
separate folders
Sep 3, 2023
3e238f1
fixes
Sep 3, 2023
97c856c
fixes
Sep 3, 2023
23c9bd1
fixes
Sep 3, 2023
f40340f
fixes
Sep 3, 2023
0fc144e
fixes
Sep 3, 2023
0b0be5c
fixes
Sep 4, 2023
07ef431
fixes
Sep 4, 2023
6ffeb2d
fixes
Sep 4, 2023
b25e106
fixes
Sep 4, 2023
0f3524f
fixes
Sep 4, 2023
5d899fb
fixes
Sep 4, 2023
d145d7e
fixes
Sep 4, 2023
52614a9
fixes
Sep 4, 2023
c07d133
fixes
Sep 4, 2023
06dc693
fixes
Sep 4, 2023
11b7172
fixes
Sep 4, 2023
4999d8b
one package per arch and system
Sep 4, 2023
da7eda7
one package per arch and system
Sep 4, 2023
29a39f0
one package per arch and system
Sep 4, 2023
dc677c0
one package per arch and system
Sep 4, 2023
d469e1e
one package per arch and system
Sep 4, 2023
ac15608
one package per arch and system
Sep 4, 2023
08dfc18
one package per arch and system
Sep 4, 2023
0e9140a
remove id
Sep 4, 2023
e8f50c8
remove id
Sep 4, 2023
12b5f37
api key
Sep 4, 2023
2c50b2e
api key
Sep 4, 2023
bed17fc
api key
Sep 4, 2023
23cb857
api key
Sep 5, 2023
93e54be
open folder
Sep 5, 2023
ba97623
final check
Sep 5, 2023
954762c
run just on demand
Sep 5, 2023
c459a7e
use correct name
Sep 5, 2023
a6f1901
Merge branch 'master' into feature/csharp_-wrapper
bbujak Sep 5, 2023
9f31308
pack all in one package
Sep 7, 2023
a2ad083
Merge remote-tracking branch 'origin/feature/csharp_-wrapper' into fe…
Sep 7, 2023
79bf078
Merge branch 'master' into feature/csharp_-wrapper
bbujak Sep 7, 2023
781d5fc
fix lint
Sep 7, 2023
76bb33f
fix lint
Sep 7, 2023
9e7d717
fix pk name
Sep 7, 2023
21249f3
use correct folder for arm arch
Sep 7, 2023
b3ec3ad
PR comments addressed
Sep 8, 2023
a80d802
Did refactoring to address PR comments
Sep 9, 2023
cfd9297
use SafeHandleZeroOrMinusOneIsInvalid
Sep 9, 2023
1782057
removed ids
Sep 9, 2023
40e6f1d
Merge branch 'master' into feature/csharp_-wrapper
bbujak Sep 9, 2023
bd6ac8a
merged master branch
Sep 11, 2023
fa6fe0c
address PR comments
Sep 11, 2023
b00d525
change solution structure
Sep 11, 2023
f043f86
fix path for generating schemas
Sep 11, 2023
0e9d502
pack NuGet and upload artifact
Sep 11, 2023
e618079
change the way rust is build
Sep 12, 2023
badbd79
forgot --target
Sep 12, 2023
d084c6e
remove after error building OpenSSL
Sep 12, 2023
86fb604
Merge branch 'master' into feature/csharp_-wrapper
bbujak Sep 12, 2023
48d04f5
use IntPtr to free memory
Sep 12, 2023
5d16c7e
Merge remote-tracking branch 'origin/feature/csharp_-wrapper' into fe…
Sep 12, 2023
1d0fc9e
PR comments resolved
Sep 13, 2023
48e83d0
fixes
Sep 13, 2023
0c344f0
PR comments
Sep 13, 2023
e446d93
PR comments
Sep 13, 2023
2f2f404
reformat code
Sep 13, 2023
12eb511
small name fix
Sep 13, 2023
0890640
fixes
Sep 13, 2023
883b499
Merge branch 'master' into feature/csharp_-wrapper
bbujak Sep 13, 2023
c2becb7
make get only properties
Sep 15, 2023
466bccf
Merge branch 'master' into feature/csharp_-wrapper
bbujak Sep 15, 2023
0c433c3
Merge branch 'master' into feature/csharp_-wrapper
bbujak Sep 18, 2023
3d5f1e5
PR comments
Sep 18, 2023
2202db1
PR comments
Sep 19, 2023
34f8a36
PR comment fix
Sep 19, 2023
884e8dd
update readme
Sep 19, 2023
76039dd
reformat code
Sep 21, 2023
1717a56
Merge branch 'master' into feature/csharp_-wrapper
bbujak Sep 21, 2023
7eaf25c
Merge branch 'master' into feature/csharp_-wrapper
Hinton Sep 21, 2023
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
78 changes: 78 additions & 0 deletions .github/workflows/build-dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: Build .NET SDK

on:
pull_request:
branches:
- master

jobs:
generate_schemas:
uses: ./.github/workflows/generate_schemas.yml

build_rust:
uses: ./.github/workflows/build-rust-cross-platform.yml

build_dotnet:
name: Build .NET
runs-on: ubuntu-22.04
needs:
- generate_schemas
- build_rust

steps:
- name: Checkout Repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

- name: Download C# schemas artifact
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: schemas.cs
path: languages/csharp/Bitwarden.Sdk

- name: Set up .NET Core
uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0
with:
global-json-file: languages/csharp/global.json

- name: Download x86_64-apple-darwin files
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: libbitwarden_c_files-x86_64-apple-darwin
path: languages/csharp/Bitwarden.Sdk/macos-x64

- name: Download aarch64-apple-darwin files
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: libbitwarden_c_files-aarch64-apple-darwin
path: languages/csharp/Bitwarden.Sdk/macos-arm64

- name: Download x86_64-unknown-linux-gnu files
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: libbitwarden_c_files-x86_64-unknown-linux-gnu
path: languages/csharp/Bitwarden.Sdk/ubuntu-x64

- name: Download x86_64-pc-windows-msvc files
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: libbitwarden_c_files-x86_64-pc-windows-msvc
path: languages/csharp/Bitwarden.Sdk/windows-x64

- name: Build .NET 6 Project
working-directory: languages/csharp/Bitwarden.Sdk
run: |
dotnet restore
dotnet build --configuration Release

- name: Pack NuGet Package
env:
VERSION: 0.0.1
run: dotnet pack --configuration Release -p:PackageID=Bitwarden.Sdk -p:Version=${VERSION} --output ./nuget-output /nologo /v:n
working-directory: languages/csharp/Bitwarden.Sdk

- name: Upload NuGet package
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: Bitwarden.Sdk.0.0.1.nupkg
path: |
./languages/csharp/Bitwarden.Sdk/nuget-output/*.nupkg
48 changes: 48 additions & 0 deletions .github/workflows/build-rust-cross-platform.yml
Hinton marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build Rust Cross Platform

on:
workflow_call:

jobs:
build_rust:
name: Build for ${{ matrix.settings.os }} ${{ matrix.settings.target }}
runs-on: ${{ matrix.settings.os }}
strategy:
fail-fast: false
matrix:
settings:
- os: macos-12
target: x86_64-apple-darwin
- os: macos-12
target: aarch64-apple-darwin
- os: windows-2022
target: x86_64-pc-windows-msvc
- os: ubuntu-22.04
target: x86_64-unknown-linux-gnu

steps:
- name: Checkout
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

- name: Install rust
uses: dtolnay/rust-toolchain@f361669954a8ecfc00a3443f35f9ac8e610ffc06 # stable
with:
toolchain: stable

- name: Cache cargo registry
uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2

- name: Add build architecture
run: rustup target add ${{ matrix.settings.target }}

- name: Build Rust
env:
RUSTFLAGS: "-D warnings"
run: cargo build --target ${{ matrix.settings.target }} --release

- name: Upload Artifact
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2
with:
name: libbitwarden_c_files-${{ matrix.settings.target }}
path: |
target/${{ matrix.settings.target }}/release/*bitwarden_c*
2 changes: 1 addition & 1 deletion .github/workflows/generate_schemas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: schemas.cs
path: ${{ github.workspace }}/languages/csharp/schemas.cs
path: ${{ github.workspace }}/languages/csharp/Bitwarden.Sdk/schemas.cs
if-no-files-found: error

- name: Upload python schemas artifact
Expand Down
69 changes: 69 additions & 0 deletions .github/workflows/publish-dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Deploy NuGet Package

on:
workflow_dispatch:
version_number:
description: "New Version"
required: true

jobs:
generate_schemas:
uses: ./.github/workflows/generate_schemas.yml

build_rust:
uses: ./.github/workflows/build-rust-cross-platform.yml

deploy:
name: Deploy
runs-on: ubuntu-22.04
needs:
- generate_schemas
- build_rust

steps:
- name: Checkout Repository
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3

- name: Download C# schemas artifact
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: schemas.cs
path: languages/csharp/Bitwarden.Sdk

- name: Set up .NET Core
uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0
with:
global-json-file: languages/csharp/global.json

- name: Download x86_64-apple-darwin files
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: libbitwarden_c_files-x86_64-apple-darwin
path: languages/csharp/Bitwarden.Sdk/macos-x64

- name: Download aarch64-apple-darwin files
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: libbitwarden_c_files-aarch64-apple-darwin
path: languages/csharp/Bitwarden.Sdk/macos-arm64

- name: Download x86_64-unknown-linux-gnu files
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: libbitwarden_c_files-x86_64-unknown-linux-gnu
path: languages/csharp/Bitwarden.Sdk/ubuntu-x64

- name: Download x86_64-pc-windows-msvc files
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
with:
name: libbitwarden_c_files-x86_64-pc-windows-msvc
path: languages/csharp/Bitwarden.Sdk/windows-x64

- name: Pack NuGet Package
env:
VERSION: ${{ github.event.inputs.version_number }}
run: dotnet pack --configuration Release -p:PackageID=Bitwarden.Sdk -p:Version=${VERSION} --output ./nuget-output /nologo /v:n
working-directory: languages/csharp/Bitwarden.Sdk

- name: Publish NuGet Package
run: dotnet nuget push ./languages/csharp/Bitwarden.Sdk/nuget-output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ languages/kotlin/sdk/src/main/java/com/bitwarden/core/bitwarden.kt
# Schemas
support/schemas
crates/bitwarden-napi/src-ts/bitwarden_client/schemas.ts
languages/csharp/schemas.cs
languages/csharp/Bitwarden.Sdk/schemas.cs
languages/js_webassembly/bitwarden_client/schemas.ts
languages/python/BitwardenClient/schemas.py
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "buildCsharp",
"program": "${workspaceFolder}/languages/csharp/bin/Debug/net6.0/bitwardenSdk.dll",
"program": "${workspaceFolder}/languages/csharp/Bitwarden.Sdk/bin/Debug/net6.0/BitwardenSdk.dll",
"args": [],
"env": {
"RUST_LOG": "debug"
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cSpell.words": [
"bindgen",
"Bitwarden",
"Cdecl",
"chrono",
"cloc",
Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"type": "process",
"args": [
"build",
"${workspaceFolder}/languages/csharp/bitwardenSdk.csproj",
"${workspaceFolder}/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
Expand Down
125 changes: 125 additions & 0 deletions languages/csharp/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# EditorConfig is awesome: http://EditorConfig.org

# top-most EditorConfig file
root = true

# Don't use tabs for indentation.
[*]
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
guidelines = 120
# (Please don't specify an indent_size here; that has too many unintended consequences.)

# Code files
[*.{cs,csx,vb,vbx}]
indent_size = 4
charset = utf-8-bom

# Xml project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
indent_size = 2

# Xml config files
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
indent_size = 2

# JSON files
[*.json]
indent_size = 2

# Dotnet code style settings:
[*.{cs,vb}]
# Sort using and Import directives with System.* appearing first
dotnet_sort_system_directives_first = true
# Avoid "this." and "Me." if not necessary
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion

# Use language keywords instead of framework type names for type references
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion

# Suggest more modern language features when available
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion

# Prefix private members with underscore
dotnet_naming_rule.private_members_with_underscore.symbols = private_fields
dotnet_naming_rule.private_members_with_underscore.style = prefix_underscore
dotnet_naming_rule.private_members_with_underscore.severity = suggestion

dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private

dotnet_naming_style.prefix_underscore.capitalization = camel_case
dotnet_naming_style.prefix_underscore.required_prefix = _

# Async methods should have "Async" suffix
dotnet_naming_rule.async_methods_end_in_async.symbols = any_async_methods
dotnet_naming_rule.async_methods_end_in_async.style = end_in_async
dotnet_naming_rule.async_methods_end_in_async.severity = suggestion

dotnet_naming_symbols.any_async_methods.applicable_kinds = method
dotnet_naming_symbols.any_async_methods.applicable_accessibilities = *
dotnet_naming_symbols.any_async_methods.required_modifiers = async

dotnet_naming_style.end_in_async.required_prefix =
dotnet_naming_style.end_in_async.required_suffix = Async
dotnet_naming_style.end_in_async.capitalization = pascal_case
dotnet_naming_style.end_in_async.word_separator =

# Obsolete warnings, this should be removed or changed to warning once we address some of the obsolete items.
dotnet_diagnostic.CS0618.severity = suggestion

# Obsolete warnings, this should be removed or changed to warning once we address some of the obsolete items.
dotnet_diagnostic.CS0612.severity = suggestion

# Remove unnecessary using directives https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0005
dotnet_diagnostic.IDE0005.severity = warning

# CSharp code style settings:
[*.cs]
# Prefer "var" everywhere
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = true:suggestion

# Prefer method-like constructs to have a expression-body
csharp_style_expression_bodied_methods = true:none
csharp_style_expression_bodied_constructors = true:none
csharp_style_expression_bodied_operators = true:none

# Prefer property-like constructs to have an expression-body
csharp_style_expression_bodied_properties = true:none
csharp_style_expression_bodied_indexers = true:none
csharp_style_expression_bodied_accessors = true:none

# Suggest more modern language features when available
csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion
csharp_style_pattern_matching_over_as_with_null_check = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = true:suggestion

# Newline settings
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true

# Namespace settings
csharp_style_namespace_declarations = file_scoped:warning

# Switch expression
dotnet_diagnostic.CS8509.severity = error # missing switch case for named enum value
dotnet_diagnostic.CS8524.severity = none # missing switch case for unnamed enum value
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Bitwarden.Sdk\Bitwarden.Sdk.csproj" />
</ItemGroup>

</Project>
Loading
Loading