From b435ac8676f0f7691fa5a6366080ab629471a6c3 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sat, 26 Aug 2023 21:24:35 +0200 Subject: [PATCH 01/94] Implemented .NET library that wraps native C library and exposed its commands through BitwardenClient class. --- .vscode/settings.json | 1 + languages/csharp/BitwardenClient.cs | 74 ++++++++++++++++++++++++ languages/csharp/BitwardenLibrary.cs | 15 +++++ languages/csharp/BitwardenSdk.cs | 75 ------------------------- languages/csharp/CommandRunner.cs | 17 ++++++ languages/csharp/Program.cs | 31 ++++++++-- languages/csharp/Projects.cs | 74 ++++++++++++++++++++++++ languages/csharp/Secrets.cs | 84 ++++++++++++++++++++++++++++ languages/csharp/Settings.cs | 15 +++++ languages/csharp/bitwardenSdk.csproj | 5 +- 10 files changed, 311 insertions(+), 80 deletions(-) create mode 100644 languages/csharp/BitwardenClient.cs create mode 100644 languages/csharp/BitwardenLibrary.cs delete mode 100644 languages/csharp/BitwardenSdk.cs create mode 100644 languages/csharp/CommandRunner.cs create mode 100644 languages/csharp/Projects.cs create mode 100644 languages/csharp/Secrets.cs create mode 100644 languages/csharp/Settings.cs diff --git a/.vscode/settings.json b/.vscode/settings.json index c31ddf8c4..b9d2d6835 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { "cSpell.words": [ "bindgen", + "Bitwarden", "Cdecl", "chrono", "cloc", diff --git a/languages/csharp/BitwardenClient.cs b/languages/csharp/BitwardenClient.cs new file mode 100644 index 000000000..e000a1d10 --- /dev/null +++ b/languages/csharp/BitwardenClient.cs @@ -0,0 +1,74 @@ +using Newtonsoft.Json; + +namespace Bit.Sdk +{ + public sealed class BitwardenClient : IDisposable + { + private readonly Projects _projects; + private readonly Secrets _secrets; + private readonly CommandRunner _commandRunner; + private readonly IntPtr _ptr; + private bool _disposedValue; + + public BitwardenClient(Settings? settings = null) + { + var clientSettings = new ClientSettings + { + ApiUrl = settings is { ApiUrl: not null } ? settings.ApiUrl : "https://api.bitwarden.com", + IdentityUrl = settings is { IdentityUrl: not null } ? settings.IdentityUrl : "https://identity.bitwarden.com", + DeviceType = DeviceType.Sdk, + UserAgent = "Bitwarden DOTNET-SDK" + }; + + _ptr = BitwardenLibrary.init(clientSettings.ToJson()); + _commandRunner = new CommandRunner(_ptr); + _projects = new Projects(_commandRunner); + _secrets = new Secrets(_commandRunner); + } + + public ResponseForApiKeyLoginResponse AccessTokenLogin(string accessToken) { + var command = new Command(); + var accessTokenLoginRequest = new AccessTokenLoginRequest + { + AccessToken = accessToken + }; + command.AccessTokenLogin = accessTokenLoginRequest; + return _commandRunner.RunCommand(command, JsonConvert.DeserializeObject); + } + + public Projects Projects() { + return _projects; + } + + public Secrets Secrets() { + return _secrets; + } + + private void Dispose(bool disposing) + { + if (!_disposedValue) + { + if (disposing) + { + // TODO: dispose managed state (managed objects) + } + + BitwardenLibrary.free_mem(_ptr); + _disposedValue = true; + } + } + + ~BitwardenClient() + { + // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method + Dispose(disposing: false); + } + + public void Dispose() + { + // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method + Dispose(disposing: true); + GC.SuppressFinalize(this); + } + } +} diff --git a/languages/csharp/BitwardenLibrary.cs b/languages/csharp/BitwardenLibrary.cs new file mode 100644 index 000000000..3efb9f28d --- /dev/null +++ b/languages/csharp/BitwardenLibrary.cs @@ -0,0 +1,15 @@ +using System.Runtime.InteropServices; + +namespace Bit.Sdk; + +internal static class BitwardenLibrary { + + [DllImport("bitwarden_c", CallingConvention = CallingConvention.Cdecl)] + internal static extern IntPtr init(string settings); + + [DllImport("bitwarden_c", CallingConvention = CallingConvention.Cdecl)] + internal static extern void free_mem(IntPtr clientPtr); + + [DllImport("bitwarden_c", CallingConvention = CallingConvention.Cdecl)] + internal static extern string run_command(string loginRequest, IntPtr clientPtr); +} diff --git a/languages/csharp/BitwardenSdk.cs b/languages/csharp/BitwardenSdk.cs deleted file mode 100644 index 286be75d5..000000000 --- a/languages/csharp/BitwardenSdk.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System.Runtime.InteropServices; - -namespace Bit.Sdk -{ - internal class BitwardenSdk : IDisposable - { - [DllImport("bitwarden_c", CallingConvention = CallingConvention.Cdecl)] - private static extern IntPtr init(string settings); - [DllImport("bitwarden_c", CallingConvention = CallingConvention.Cdecl)] - private static extern void free_mem(IntPtr clientPtr); - - [DllImport("bitwarden_c", CallingConvention = CallingConvention.Cdecl)] - private static extern string run_command(string loginRequest, IntPtr clientPtr); - - private readonly IntPtr _ptr; - private bool disposedValue; - - public BitwardenSdk(ClientSettings? settings = null) - { - _ptr = init(settings?.ToJson()); - } - - public ResponseForPasswordLoginResponse? PasswordLogin(string email, string password) => RunCommand(new Command - { - PasswordLogin = new PasswordLoginRequest { - Email = email, - Password = password - }, - }, ResponseForPasswordLoginResponse.FromJson); - - public ResponseForUserApiKeyResponse? UserApiKey(string password) => RunCommand(new Command - { - GetUserApiKey = new SecretVerificationRequest { - MasterPassword = password - }, - }, ResponseForUserApiKeyResponse.FromJson); - - private TReturn? RunCommand(Command input, Func deserializer) - { - var req = input.ToJson(); - - var json_result = run_command(req, _ptr); - Console.WriteLine(json_result); - return deserializer(json_result); - } - - protected virtual void Dispose(bool disposing) - { - if (!disposedValue) - { - if (disposing) - { - // TODO: dispose managed state (managed objects) - } - - free_mem(_ptr); - disposedValue = true; - } - } - - - ~BitwardenSdk() - { - // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - Dispose(disposing: false); - } - - public void Dispose() - { - // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - Dispose(disposing: true); - GC.SuppressFinalize(this); - } - } -} diff --git a/languages/csharp/CommandRunner.cs b/languages/csharp/CommandRunner.cs new file mode 100644 index 000000000..95020bd7a --- /dev/null +++ b/languages/csharp/CommandRunner.cs @@ -0,0 +1,17 @@ +namespace Bit.Sdk; + +internal class CommandRunner { + + private readonly IntPtr _client; + + internal CommandRunner(IntPtr client) { + _client = client; + } + + internal TReturn? RunCommand(Command command, Func deserializer) + { + var req = command.ToJson(); + var result = BitwardenLibrary.run_command(req, _client); + return deserializer(result); + } +} diff --git a/languages/csharp/Program.cs b/languages/csharp/Program.cs index 359454e32..b05abef00 100644 --- a/languages/csharp/Program.cs +++ b/languages/csharp/Program.cs @@ -1,6 +1,29 @@ using Bit.Sdk; -var sdk = new BitwardenSdk(); -sdk.PasswordLogin("test@bitwarden.com", "asdfasdf"); -var apiKey = sdk.UserApiKey("asdfasdf"); -Console.WriteLine(apiKey?.Data?.ApiKey ?? "api key was null"); + +const string accessToken = ""; +const string organizationIdStr = ""; + +var bitwardenClient = new BitwardenClient(); +var loginResponse = bitwardenClient.AccessTokenLogin(accessToken); +var organizationId = Guid.Parse(organizationIdStr); +var responseForProjectResponse = bitwardenClient.Projects().Create(organizationId, "NewTestProject"); +var projectId = responseForProjectResponse.Data.Id; +var responseForProjectsResponse = bitwardenClient.Projects().List(organizationId); +responseForProjectResponse = bitwardenClient.Projects().Get(projectId); +responseForProjectResponse = bitwardenClient.Projects().Update(projectId, organizationId, "NewTestProject2"); + +var key = "key"; +var value = "value"; +var note = "note"; +var responseForSecretResponse = bitwardenClient.Secrets().Create(key, value, note, organizationId, new Guid[]{projectId}); +var secretId = responseForSecretResponse.Data.Id; +var responseForSecretIdentifiersResponse = bitwardenClient.Secrets().List(organizationId); +responseForSecretResponse = bitwardenClient.Secrets().Get(secretId); +key = "key2"; +value = "value2"; +note = "note2"; +responseForSecretResponse = bitwardenClient.Secrets().Update(secretId, key, value, note, organizationId, new Guid[]{projectId}); + +var responseForSecretsDeleteResponse = bitwardenClient.Secrets().Delete(new Guid[]{secretId}); +var responseForProjectsDeleteResponse = bitwardenClient.Projects().Delete(new Guid[]{projectId}); diff --git a/languages/csharp/Projects.cs b/languages/csharp/Projects.cs new file mode 100644 index 000000000..44b73f5fe --- /dev/null +++ b/languages/csharp/Projects.cs @@ -0,0 +1,74 @@ +using Newtonsoft.Json; + +namespace Bit.Sdk; + + +public class Projects { + + private readonly CommandRunner _commandRunner; + + internal Projects(CommandRunner commandRunner) { + this._commandRunner = commandRunner; + } + + public ResponseForProjectResponse Get(Guid id) { + var command = new Command(); + var projectsCommand = new ProjectsCommand(); + var projectGetRequest = new ProjectGetRequest + { + Id = id + }; + projectsCommand.Get = projectGetRequest; + command.Projects = projectsCommand; + return _commandRunner.RunCommand(command, JsonConvert.DeserializeObject); + } + + public ResponseForProjectResponse Create(Guid organizationId, string name) { + var command = new Command(); + var projectsCommand = new ProjectsCommand(); + var projectCreateRequest = new ProjectCreateRequest + { + OrganizationId = organizationId, + Name = name + }; + projectsCommand.Create = projectCreateRequest; + command.Projects = projectsCommand; + return _commandRunner.RunCommand(command, JsonConvert.DeserializeObject); + } + + public ResponseForProjectResponse Update(Guid id, Guid organizationId, String name) { + var command = new Command(); + var projectsCommand = new ProjectsCommand(); + var projectPutRequest = new ProjectPutRequest + { + Id = id, + OrganizationId = organizationId, + Name = name + }; + projectsCommand.Update = projectPutRequest; + command.Projects = projectsCommand; + return _commandRunner.RunCommand(command, JsonConvert.DeserializeObject); + } + + public ResponseForProjectsDeleteResponse Delete(Guid[] ids) { + var command = new Command(); + var projectsCommand = new ProjectsCommand(); + var projectsDeleteRequest = new ProjectsDeleteRequest + { + Ids = ids + }; + projectsCommand.Delete = projectsDeleteRequest; + command.Projects = projectsCommand; + return _commandRunner.RunCommand(command, JsonConvert.DeserializeObject); + } + + public ResponseForProjectsResponse List(Guid organizationId) { + var command = new Command(); + var projectsCommand = new ProjectsCommand(); + var projectsListRequest = new ProjectsListRequest(); + projectsListRequest.OrganizationId = organizationId; + projectsCommand.List = projectsListRequest; + command.Projects = projectsCommand; + return _commandRunner.RunCommand(command, JsonConvert.DeserializeObject); + } +} diff --git a/languages/csharp/Secrets.cs b/languages/csharp/Secrets.cs new file mode 100644 index 000000000..5d203963b --- /dev/null +++ b/languages/csharp/Secrets.cs @@ -0,0 +1,84 @@ +using Newtonsoft.Json; + +namespace Bit.Sdk; + + +public class Secrets { + + private readonly CommandRunner _commandRunner; + + internal Secrets(CommandRunner commandRunner) { + _commandRunner = commandRunner; + } + + public ResponseForSecretResponse Get(Guid id) { + var command = new Command(); + var secretsCommand = new SecretsCommand(); + var secretGetRequest = new SecretGetRequest + { + Id = id + }; + secretsCommand.Get = secretGetRequest; + command.Secrets = secretsCommand; + return _commandRunner.RunCommand(command, JsonConvert.DeserializeObject); + } + + public ResponseForSecretResponse Create(string key, string value, string note, Guid organizationId, + Guid[] projectIds) { + var command = new Command(); + var secretsCommand = new SecretsCommand(); + var secretCreateRequest = new SecretCreateRequest + { + Key = key, + Value = value, + Note = note, + OrganizationId = organizationId, + ProjectIds = projectIds + }; + secretsCommand.Create = secretCreateRequest; + command.Secrets = secretsCommand; + return _commandRunner.RunCommand(command, JsonConvert.DeserializeObject); + } + + public ResponseForSecretResponse Update(Guid id, string key, string value, string note, Guid organizationId, + Guid[] projectIds) { + var command = new Command(); + var secretsCommand = new SecretsCommand(); + var secretPutRequest = new SecretPutRequest + { + Id = id, + Key = key, + Value = value, + Note = note, + OrganizationId = organizationId, + ProjectIds = projectIds + }; + secretsCommand.Update = secretPutRequest; + command.Secrets = secretsCommand; + return _commandRunner.RunCommand(command, JsonConvert.DeserializeObject); + } + + public ResponseForSecretsDeleteResponse Delete(Guid[] ids) { + var command = new Command(); + var secretsCommand = new SecretsCommand(); + var secretsDeleteRequest = new SecretsDeleteRequest + { + Ids = ids + }; + secretsCommand.Delete = secretsDeleteRequest; + command.Secrets = secretsCommand; + return _commandRunner.RunCommand(command, JsonConvert.DeserializeObject); + } + + public ResponseForSecretIdentifiersResponse List(Guid organizationId) { + var command = new Command(); + var secretsCommand = new SecretsCommand(); + var secretIdentifiersRequest = new SecretIdentifiersRequest + { + OrganizationId = organizationId + }; + secretsCommand.List = secretIdentifiersRequest; + command.Secrets = secretsCommand; + return _commandRunner.RunCommand(command, JsonConvert.DeserializeObject); + } +} diff --git a/languages/csharp/Settings.cs b/languages/csharp/Settings.cs new file mode 100644 index 000000000..34db4ab26 --- /dev/null +++ b/languages/csharp/Settings.cs @@ -0,0 +1,15 @@ +namespace Bit.Sdk; + +public class Settings +{ + /// + /// The api url of the targeted Bitwarden instance. Defaults to `https://api.bitwarden.com` + /// + public string? ApiUrl { get; set; } + + /// + /// The identity url of the targeted Bitwarden instance. Defaults to + /// `https://identity.bitwarden.com` + /// + public string? IdentityUrl { get; set; } +} diff --git a/languages/csharp/bitwardenSdk.csproj b/languages/csharp/bitwardenSdk.csproj index 10e89212e..7ec516d74 100644 --- a/languages/csharp/bitwardenSdk.csproj +++ b/languages/csharp/bitwardenSdk.csproj @@ -11,10 +11,13 @@ - + + + 4 + Always From 5fc857005b6524f4d77069ef50f6c408c34dec8a Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 28 Aug 2023 21:57:38 +0200 Subject: [PATCH 02/94] add NuGet package configuration --- .github/workflows/build-dotnet.yml | 25 ++++++++++++ .github/workflows/publish-dotnet.yml | 33 +++++++++++++++ languages/csharp/README.md | 2 +- languages/csharp/bitwarden.png | Bin 0 -> 878 bytes languages/csharp/bitwardenSdk.csproj | 15 ++++++- languages/csharp/docs/README.md | 58 +++++++++++++++++++++++++++ 6 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/build-dotnet.yml create mode 100644 .github/workflows/publish-dotnet.yml create mode 100644 languages/csharp/bitwarden.png create mode 100644 languages/csharp/docs/README.md diff --git a/.github/workflows/build-dotnet.yml b/.github/workflows/build-dotnet.yml new file mode 100644 index 000000000..cd0ddd128 --- /dev/null +++ b/.github/workflows/build-dotnet.yml @@ -0,0 +1,25 @@ +name: Build .NET 6 Project + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-22.04 + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Set up .NET Core + uses: actions/setup-dotnet@v2 + with: + dotnet-version: '6.0.21' + + - name: Build .NET 6 Project + working-directory: languages/csharp + run: | + dotnet restore + dotnet build --configuration Release diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml new file mode 100644 index 000000000..a095955f3 --- /dev/null +++ b/.github/workflows/publish-dotnet.yml @@ -0,0 +1,33 @@ +name: Deploy NuGet Package + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-22.04 + + steps: + - name: Checkout Repository + uses: actions/checkout@v2 + + - name: Set up .NET Core + uses: actions/setup-dotnet@v2 + with: + dotnet-version: '6.0.21' + + - name: Build and Pack NuGet Package + working-directory: languages/csharp + run: | + dotnet restore + dotnet build --configuration Release + dotnet pack --configuration Release --no-build --output ./nuget-output + + - name: Publish NuGet Package + uses: nuget/publish@v1 + with: + nuget-api-key: ${{ secrets.NUGET_API_KEY }} + nuget-package: ./languages/csharp/nuget-output/*.nupkg + nuget-endpoint: https://api.nuget.org/v3/index.json diff --git a/languages/csharp/README.md b/languages/csharp/README.md index e390a1ca1..199acaab8 100644 --- a/languages/csharp/README.md +++ b/languages/csharp/README.md @@ -1,6 +1,6 @@ # Requirements -- Dotnet +- Dotnet 6 # Installation diff --git a/languages/csharp/bitwarden.png b/languages/csharp/bitwarden.png new file mode 100644 index 0000000000000000000000000000000000000000..5b9d09d51d999275473c8f210437a424ea96d84d GIT binary patch literal 878 zcmV-!1CjiRP)}b0K@`U)%ZbFGQ8}Xs zClM_aEkwJZkYJ%HW0OKGy>=B+i4y$4Dqyxf3qi3+V@gdS9w^rZuQ-W?U@#zl1TSYu zqM*_F-_6Rg?(N;|%zh;E9xMyDEc@PX-q+r~>0&;z_tLw5ezN&7$d40jV@sJIMSeJ+ zA03|eUhMKQ{vJPFVVhGXIfSde0Jz~h`RT)gyB|Z}`|05! z3IPH@00;m9AOHk_01yBIKmZ5;0U!VbfB+Bx0zd!=00A%pKrWk!AHet3->CsGaI{;C zj#2YH zKp8+yC=dmNv60>EfxWM-@ioO~E58e%@z4nYO%7IlY-CqJOWrWPq9FveybS4rfFaE1 zcXENVKRS)q`ZfrK&R$;#l^ESbhat>XF7GBhJfos9`C?f5kIvZbnmb@RmA^%p%rHb8B&`QwQ*xC9q!z zAVyC&vj5bp<=71uQpR7a#Uud0;Dn5BmLjr}!^{=O65B~94KyCRNax+UbdxnU6PhAr zcMEMDfY?SlWC(<^u(eSIyjP9gJnezd&kWf<|5tzk0ALb5Vs4E8{{R3007*qoM6N<$ Eg66e@TL1t6 literal 0 HcmV?d00001 diff --git a/languages/csharp/bitwardenSdk.csproj b/languages/csharp/bitwardenSdk.csproj index 7ec516d74..6a65cda2d 100644 --- a/languages/csharp/bitwardenSdk.csproj +++ b/languages/csharp/bitwardenSdk.csproj @@ -3,19 +3,32 @@ Exe net6.0 + README.md enable enable + BitwardenSdk + BitwardenSdk + Bitwarden Sdk + Bitwarden + Bitwarden Sdk + Bitwarden + https://github.com/bitwarden/sdk/tree/master/languages/csharp + Bitwarden;Sdk;.NET + BitwardenSdk + bitwarden.png + + - + 4 diff --git a/languages/csharp/docs/README.md b/languages/csharp/docs/README.md new file mode 100644 index 000000000..6f5d7bcc2 --- /dev/null +++ b/languages/csharp/docs/README.md @@ -0,0 +1,58 @@ +# Bitwarden .NET SDK + +The Bitwarden SDK (Software Development Kit) is a set of programming tools, libraries, and resources provided by Bitwarden for developers to integrate Bitwarden's password management and security capabilities into their own applications, services, or platforms. The SDK facilitates the seamless integration of Bitwarden's functionality into third-party software, enabling users to securely manage their passwords, credentials, and sensitive information across various digital environments. + +## Create access token +- to create access token go to [access-tokens help page] + +## Usage code snippets + +### Create new Bitwarden client +``` +const string accessToken = ""; +var bitwardenClient = new BitwardenClient(); +var loginResponse = bitwardenClient.AccessTokenLogin(accessToken); +``` + +### Create new project +- Organization is created in the UI +``` +const string organizationIdStr = ""; +var organizationId = Guid.Parse(organizationIdStr); +var responseForProjectResponse = bitwardenClient.Projects().Create(organizationId, "TestProject"); +``` + +### List all projects +``` +var response = bitwardenClient.Projects().List(organizationId); +``` + +### Update project +``` +var projectId = responseForProjectResponse.Data.Id; +responseForProjectResponse = bitwardenClient.Projects().Get(projectId); +responseForProjectResponse = bitwardenClient.Projects().Update(projectId, organizationId, "TestProjectUpdated"); +``` + +### Add new secret +``` +var key = "key"; +var value = "value"; +var note = "note"; +var responseForSecretResponse = bitwardenClient.Secrets().Create(key, value, note, organizationId, new Guid[]{projectId}); +var secretId = responseForSecretResponse.Data.Id; +``` + +### List secrets +``` +var responseForSecretIdentifiersResponse = bitwardenClient.Secrets().List(organizationId); +``` + +# Delete secret or project + +``` +var responseForSecretsDeleteResponse = bitwardenClient.Secrets().Delete(new Guid[]{secretId}); +var responseForProjectsDeleteResponse = bitwardenClient.Projects().Delete(new Guid[]{projectId}); +``` + +[access-tokens help page]: https://bitwarden.com/help/access-tokens/ From 9bbf5d857c0837f393e2771cc2131f09c56849bc Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 28 Aug 2023 22:02:15 +0200 Subject: [PATCH 03/94] buidl on PR created --- .github/workflows/build-dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-dotnet.yml b/.github/workflows/build-dotnet.yml index cd0ddd128..3d85eb3bd 100644 --- a/.github/workflows/build-dotnet.yml +++ b/.github/workflows/build-dotnet.yml @@ -1,7 +1,7 @@ name: Build .NET 6 Project on: - push: + pull_request: branches: - master From 21053bd1a684bc6b984815c39a0eeb172a38dcd9 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 28 Aug 2023 22:08:51 +0200 Subject: [PATCH 04/94] check if the same version exists , and if it doesn't deploy --- .github/workflows/publish-dotnet.yml | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index a095955f3..b7bdc71d8 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -6,7 +6,7 @@ on: - master jobs: - build: + deploy: runs-on: ubuntu-22.04 steps: @@ -18,14 +18,29 @@ jobs: with: dotnet-version: '6.0.21' - - name: Build and Pack NuGet Package - working-directory: languages/csharp + - name: Get Package Version + id: version run: | - dotnet restore - dotnet build --configuration Release - dotnet pack --configuration Release --no-build --output ./nuget-output + cd languages/csharp + package_version=$(dotnet pack --configuration Release --no-build /property:Version=1.2.3 --output ./nuget-output /nologo /v:n) + echo "Package Version: $package_version" + echo "::set-output name=version::$package_version" + + - name: Check Existing Version on NuGet.org + id: check_version + run: | + existing_version=$(dotnet nuget list source-package-name -s https://api.nuget.org/v3/index.json --version ${{ steps.version.outputs.version }} | grep -oP '(?<=Version: )[^,]+') + echo "Existing Version: $existing_version" + if [ -n "$existing_version" ]; then + echo "Package version already exists on NuGet.org." + echo "::set-output name=exists::true" + else + echo "Package version does not exist on NuGet.org." + echo "::set-output name=exists::false" + fi - name: Publish NuGet Package + if: steps.check_version.outputs.exists == 'false' uses: nuget/publish@v1 with: nuget-api-key: ${{ secrets.NUGET_API_KEY }} From 748b1eb2477126fc0da0862b9731527b79454188 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 28 Aug 2023 22:11:06 +0200 Subject: [PATCH 05/94] name fix --- .github/workflows/build-dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-dotnet.yml b/.github/workflows/build-dotnet.yml index 3d85eb3bd..9b2f4c0db 100644 --- a/.github/workflows/build-dotnet.yml +++ b/.github/workflows/build-dotnet.yml @@ -1,4 +1,4 @@ -name: Build .NET 6 Project +name: Build .NET SDK on: pull_request: From 796a4ef851d61bd7b38a303a79794f34c266ae20 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Tue, 29 Aug 2023 08:16:24 +0200 Subject: [PATCH 06/94] update github actions --- .github/workflows/build-dotnet.yml | 11 ++++++++--- .github/workflows/publish-dotnet.yml | 22 +++++++++++----------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-dotnet.yml b/.github/workflows/build-dotnet.yml index 9b2f4c0db..cc2cd3e7f 100644 --- a/.github/workflows/build-dotnet.yml +++ b/.github/workflows/build-dotnet.yml @@ -6,17 +6,22 @@ on: - master jobs: + generate_schemas: + uses: ./.github/workflows/generate_schemas.yml + build_rust_crates: + uses: ./.github/workflows/build-rust-crates.yml + build: runs-on: ubuntu-22.04 steps: - name: Checkout Repository - uses: actions/checkout@v2 + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - name: Set up .NET Core - uses: actions/setup-dotnet@v2 + uses: actions/setup-dotnet@v3 with: - dotnet-version: '6.0.21' + dotnet-version: '6.0.x' - name: Build .NET 6 Project working-directory: languages/csharp diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index b7bdc71d8..2411d9f5b 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -1,22 +1,26 @@ name: Deploy NuGet Package on: - push: - branches: - - master + workflow_dispatch: + branches: [master] jobs: + generate_schemas: + uses: ./.github/workflows/generate_schemas.yml + build_rust_crates: + uses: ./.github/workflows/build-rust-crates.yml + deploy: runs-on: ubuntu-22.04 steps: - name: Checkout Repository - uses: actions/checkout@v2 + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - name: Set up .NET Core - uses: actions/setup-dotnet@v2 + uses: actions/setup-dotnet@v3 with: - dotnet-version: '6.0.21' + dotnet-version: '6.0.x' - name: Get Package Version id: version @@ -41,8 +45,4 @@ jobs: - name: Publish NuGet Package if: steps.check_version.outputs.exists == 'false' - uses: nuget/publish@v1 - with: - nuget-api-key: ${{ secrets.NUGET_API_KEY }} - nuget-package: ./languages/csharp/nuget-output/*.nupkg - nuget-endpoint: https://api.nuget.org/v3/index.json + run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json From 1cdc73d6d58cabe330eea637e6c4b98b5c5f4602 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Tue, 29 Aug 2023 08:34:50 +0200 Subject: [PATCH 07/94] build rust added in gitflow actions --- .github/workflows/build-dotnet.yml | 47 ++++++++++++++++++++++++++-- .github/workflows/publish-dotnet.yml | 45 ++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-dotnet.yml b/.github/workflows/build-dotnet.yml index cc2cd3e7f..ddf610435 100644 --- a/.github/workflows/build-dotnet.yml +++ b/.github/workflows/build-dotnet.yml @@ -8,11 +8,52 @@ on: jobs: generate_schemas: uses: ./.github/workflows/generate_schemas.yml - build_rust_crates: - uses: ./.github/workflows/build-rust-crates.yml - build: + build_rust: + name: Building ${{matrix.package}} for - ${{ matrix.os }} + + runs-on: ${{ matrix.settings.os || 'ubuntu-latest' }} + + strategy: + fail-fast: false + matrix: + os: + - macos-latest + - ubuntu-latest + - windows-latest + + package: + - bitwarden + - bitwarden-api-api + - bitwarden-api-identity + + steps: + - name: Checkout + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + + - name: Install rust + uses: dtolnay/rust-toolchain@f361669954a8ecfc00a3443f35f9ac8e610ffc06 # stable + with: + toolchain: stable + targets: ${{ matrix.settings.target }} + + - name: Cache cargo registry + uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 + + - name: Build + run: cargo build -p ${{ matrix.package }} --release + env: + RUSTFLAGS: "-D warnings" + + - name: Build Internal + if: ${{ matrix.package == 'bitwarden' }} + run: cargo build -p ${{ matrix.package }} --features internal --release + env: + RUSTFLAGS: "-D warnings" + + build_dotnet: runs-on: ubuntu-22.04 + needs: [generate_schemas, build_rust] steps: - name: Checkout Repository diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 2411d9f5b..067ad49a9 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -7,11 +7,52 @@ on: jobs: generate_schemas: uses: ./.github/workflows/generate_schemas.yml - build_rust_crates: - uses: ./.github/workflows/build-rust-crates.yml + + build_rust: + name: Building ${{matrix.package}} for - ${{ matrix.os }} + + runs-on: ${{ matrix.settings.os || 'ubuntu-latest' }} + + strategy: + fail-fast: false + matrix: + os: + - macos-latest + - ubuntu-latest + - windows-latest + + package: + - bitwarden + - bitwarden-api-api + - bitwarden-api-identity + + steps: + - name: Checkout + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + + - name: Install rust + uses: dtolnay/rust-toolchain@f361669954a8ecfc00a3443f35f9ac8e610ffc06 # stable + with: + toolchain: stable + targets: ${{ matrix.settings.target }} + + - name: Cache cargo registry + uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 + + - name: Build + run: cargo build -p ${{ matrix.package }} --release + env: + RUSTFLAGS: "-D warnings" + + - name: Build Internal + if: ${{ matrix.package == 'bitwarden' }} + run: cargo build -p ${{ matrix.package }} --features internal --release + env: + RUSTFLAGS: "-D warnings" deploy: runs-on: ubuntu-22.04 + needs: [ generate_schemas, build_rust ] steps: - name: Checkout Repository From 8addb59914dcd0c6d28bf5a4cd38ce79e74f1d34 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Tue, 29 Aug 2023 12:49:46 +0200 Subject: [PATCH 08/94] run prettier and re-write part for schemas --- .github/workflows/build-dotnet.yml | 8 +++++++- .github/workflows/publish-dotnet.yml | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-dotnet.yml b/.github/workflows/build-dotnet.yml index ddf610435..351d11e1d 100644 --- a/.github/workflows/build-dotnet.yml +++ b/.github/workflows/build-dotnet.yml @@ -59,10 +59,16 @@ jobs: - 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 + - name: Set up .NET Core uses: actions/setup-dotnet@v3 with: - dotnet-version: '6.0.x' + dotnet-version: "6.0.x" - name: Build .NET 6 Project working-directory: languages/csharp diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 067ad49a9..daf8c315b 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -52,7 +52,7 @@ jobs: deploy: runs-on: ubuntu-22.04 - needs: [ generate_schemas, build_rust ] + needs: [generate_schemas, build_rust] steps: - name: Checkout Repository @@ -61,7 +61,7 @@ jobs: - name: Set up .NET Core uses: actions/setup-dotnet@v3 with: - dotnet-version: '6.0.x' + dotnet-version: "6.0.x" - name: Get Package Version id: version From 6337f7fb583f2d3c2d5ed25f53a85be0294e2686 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Tue, 29 Aug 2023 13:07:22 +0200 Subject: [PATCH 09/94] deploy to nuget fix --- .github/workflows/publish-dotnet.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index daf8c315b..4a729e403 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -58,6 +58,12 @@ jobs: - 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 + - name: Set up .NET Core uses: actions/setup-dotnet@v3 with: From 66d5273824d21c0bdf303bc10dad4c0af0a336da Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Tue, 29 Aug 2023 13:26:26 +0200 Subject: [PATCH 10/94] add version --- .github/workflows/publish-dotnet.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 4a729e403..393c3afbf 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -2,7 +2,9 @@ name: Deploy NuGet Package on: workflow_dispatch: - branches: [master] + version_number: + description: "New Version" + required: true jobs: generate_schemas: @@ -71,9 +73,11 @@ jobs: - name: Get Package Version id: version + env: + VERSION: ${{ github.event.inputs.version_number }} run: | cd languages/csharp - package_version=$(dotnet pack --configuration Release --no-build /property:Version=1.2.3 --output ./nuget-output /nologo /v:n) + package_version=$(dotnet pack --configuration Release --no-build /property:Version=${VERSION} --output ./nuget-output /nologo /v:n) echo "Package Version: $package_version" echo "::set-output name=version::$package_version" From c0f00abb35b1b19988a6d80d5f02b684f92d84bd Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Tue, 29 Aug 2023 23:28:51 +0200 Subject: [PATCH 11/94] copy lib to output when package is used --- languages/csharp/bitwardenSdk.csproj | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/languages/csharp/bitwardenSdk.csproj b/languages/csharp/bitwardenSdk.csproj index 6a65cda2d..4f3830e31 100644 --- a/languages/csharp/bitwardenSdk.csproj +++ b/languages/csharp/bitwardenSdk.csproj @@ -9,13 +9,14 @@ BitwardenSdk BitwardenSdk Bitwarden Sdk - Bitwarden + Bitwarden Inc. Bitwarden Sdk - Bitwarden + Bitwarden Inc. https://github.com/bitwarden/sdk/tree/master/languages/csharp Bitwarden;Sdk;.NET BitwardenSdk bitwarden.png + Git @@ -34,24 +35,30 @@ Always + true Always + true Always + true Always + true Always + true Always + true From 6d94e77b47ceb557015240902de2e572491a28e1 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Wed, 30 Aug 2023 16:34:46 +0200 Subject: [PATCH 12/94] - added editorconfig, code reformated - created SafeHandle to be used - made BitwardenLibrary methods private and added wrapper - rename Settings to BitwardenSettings - rename Projects to ProjectsClient - rename Secrets to SecretsClient --- languages/csharp/.editorconfig | 125 ++++++++++++++++++ languages/csharp/BitwardenClient.cs | 106 ++++++--------- languages/csharp/BitwardenLibrary.cs | 27 +++- languages/csharp/BitwardenSafeHandle.cs | 22 +++ .../{Settings.cs => BitwardenSettings.cs} | 4 +- languages/csharp/CommandRunner.cs | 10 +- languages/csharp/Program.cs | 12 +- .../csharp/{Projects.cs => ProjectsClient.cs} | 23 ++-- .../csharp/{Secrets.cs => SecretsClient.cs} | 23 ++-- languages/csharp/docs/README.md | 2 +- 10 files changed, 257 insertions(+), 97 deletions(-) create mode 100644 languages/csharp/.editorconfig create mode 100644 languages/csharp/BitwardenSafeHandle.cs rename languages/csharp/{Settings.cs => BitwardenSettings.cs} (87%) rename languages/csharp/{Projects.cs => ProjectsClient.cs} (89%) rename languages/csharp/{Secrets.cs => SecretsClient.cs} (89%) diff --git a/languages/csharp/.editorconfig b/languages/csharp/.editorconfig new file mode 100644 index 000000000..21d7ac4a3 --- /dev/null +++ b/languages/csharp/.editorconfig @@ -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 diff --git a/languages/csharp/BitwardenClient.cs b/languages/csharp/BitwardenClient.cs index e000a1d10..2814b4d10 100644 --- a/languages/csharp/BitwardenClient.cs +++ b/languages/csharp/BitwardenClient.cs @@ -1,74 +1,54 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; -namespace Bit.Sdk +namespace Bit.Sdk; + +public sealed class BitwardenClient : IDisposable { - public sealed class BitwardenClient : IDisposable - { - private readonly Projects _projects; - private readonly Secrets _secrets; - private readonly CommandRunner _commandRunner; - private readonly IntPtr _ptr; - private bool _disposedValue; + private readonly ProjectsClient _projectsClient; + private readonly SecretsClient _secretsClient; + private readonly CommandRunner _commandRunner; + private readonly BitwardenSafeHandle _handle; - public BitwardenClient(Settings? settings = null) + public BitwardenClient(BitwardenSettings? settings = null) + { + var clientSettings = new ClientSettings { - var clientSettings = new ClientSettings - { - ApiUrl = settings is { ApiUrl: not null } ? settings.ApiUrl : "https://api.bitwarden.com", - IdentityUrl = settings is { IdentityUrl: not null } ? settings.IdentityUrl : "https://identity.bitwarden.com", - DeviceType = DeviceType.Sdk, - UserAgent = "Bitwarden DOTNET-SDK" - }; - - _ptr = BitwardenLibrary.init(clientSettings.ToJson()); - _commandRunner = new CommandRunner(_ptr); - _projects = new Projects(_commandRunner); - _secrets = new Secrets(_commandRunner); - } - - public ResponseForApiKeyLoginResponse AccessTokenLogin(string accessToken) { - var command = new Command(); - var accessTokenLoginRequest = new AccessTokenLoginRequest - { - AccessToken = accessToken - }; - command.AccessTokenLogin = accessTokenLoginRequest; - return _commandRunner.RunCommand(command, JsonConvert.DeserializeObject); - } - - public Projects Projects() { - return _projects; - } - - public Secrets Secrets() { - return _secrets; - } + ApiUrl = settings is { ApiUrl: not null } ? settings.ApiUrl : "https://api.bitwarden.com", + IdentityUrl = settings is { IdentityUrl: not null } ? settings.IdentityUrl : "https://identity.bitwarden.com", + DeviceType = DeviceType.Sdk, + UserAgent = "Bitwarden DOTNET-SDK" + }; + + var ptr = BitwardenLibrary.Init(clientSettings.ToJson()); + _handle = new BitwardenSafeHandle(ptr); + _commandRunner = new CommandRunner(ptr); + _projectsClient = new ProjectsClient(_commandRunner); + _secretsClient = new SecretsClient(_commandRunner); + } - private void Dispose(bool disposing) + public ResponseForApiKeyLoginResponse AccessTokenLogin(string accessToken) + { + var command = new Command(); + var accessTokenLoginRequest = new AccessTokenLoginRequest { - if (!_disposedValue) - { - if (disposing) - { - // TODO: dispose managed state (managed objects) - } + AccessToken = accessToken + }; + command.AccessTokenLogin = accessTokenLoginRequest; + return _commandRunner.RunCommand(command, JsonConvert.DeserializeObject); + } - BitwardenLibrary.free_mem(_ptr); - _disposedValue = true; - } - } + public ProjectsClient Projects() + { + return _projectsClient; + } - ~BitwardenClient() - { - // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - Dispose(disposing: false); - } + public SecretsClient Secrets() + { + return _secretsClient; + } - public void Dispose() - { - // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method - Dispose(disposing: true); - GC.SuppressFinalize(this); - } + public void Dispose() + { + _handle.Dispose(); } } diff --git a/languages/csharp/BitwardenLibrary.cs b/languages/csharp/BitwardenLibrary.cs index 3efb9f28d..8ca115658 100644 --- a/languages/csharp/BitwardenLibrary.cs +++ b/languages/csharp/BitwardenLibrary.cs @@ -1,15 +1,30 @@ -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; namespace Bit.Sdk; -internal static class BitwardenLibrary { - +internal static class BitwardenLibrary +{ [DllImport("bitwarden_c", CallingConvention = CallingConvention.Cdecl)] - internal static extern IntPtr init(string settings); + private static extern IntPtr init(string settings); [DllImport("bitwarden_c", CallingConvention = CallingConvention.Cdecl)] - internal static extern void free_mem(IntPtr clientPtr); + private static extern void free_mem(IntPtr clientPtr); [DllImport("bitwarden_c", CallingConvention = CallingConvention.Cdecl)] - internal static extern string run_command(string loginRequest, IntPtr clientPtr); + private static extern string run_command(string loginRequest, IntPtr clientPtr); + + internal static IntPtr Init(string settings) + { + return init(settings); + } + + internal static void FreeMemory(IntPtr clientPtr) + { + free_mem(clientPtr); + } + + internal static string RunCommand(string loginRequest, IntPtr clientPtr) + { + return run_command(loginRequest, clientPtr); + } } diff --git a/languages/csharp/BitwardenSafeHandle.cs b/languages/csharp/BitwardenSafeHandle.cs new file mode 100644 index 000000000..1f412d63a --- /dev/null +++ b/languages/csharp/BitwardenSafeHandle.cs @@ -0,0 +1,22 @@ +using System.Runtime.InteropServices; + +namespace Bit.Sdk; + +internal class BitwardenSafeHandle : SafeHandle +{ + public BitwardenSafeHandle(IntPtr handle) : base(IntPtr.Zero, true) + { + SetHandle(handle); + } + + public override bool IsInvalid + { + get { return handle == IntPtr.Zero; } + } + + protected override bool ReleaseHandle() + { + BitwardenLibrary.FreeMemory(handle); + return true; + } +} diff --git a/languages/csharp/Settings.cs b/languages/csharp/BitwardenSettings.cs similarity index 87% rename from languages/csharp/Settings.cs rename to languages/csharp/BitwardenSettings.cs index 34db4ab26..40c75905a 100644 --- a/languages/csharp/Settings.cs +++ b/languages/csharp/BitwardenSettings.cs @@ -1,6 +1,6 @@ -namespace Bit.Sdk; +namespace Bit.Sdk; -public class Settings +public class BitwardenSettings { /// /// The api url of the targeted Bitwarden instance. Defaults to `https://api.bitwarden.com` diff --git a/languages/csharp/CommandRunner.cs b/languages/csharp/CommandRunner.cs index 95020bd7a..6a69713c1 100644 --- a/languages/csharp/CommandRunner.cs +++ b/languages/csharp/CommandRunner.cs @@ -1,17 +1,19 @@ -namespace Bit.Sdk; +namespace Bit.Sdk; -internal class CommandRunner { +internal class CommandRunner +{ private readonly IntPtr _client; - internal CommandRunner(IntPtr client) { + internal CommandRunner(IntPtr client) + { _client = client; } internal TReturn? RunCommand(Command command, Func deserializer) { var req = command.ToJson(); - var result = BitwardenLibrary.run_command(req, _client); + var result = BitwardenLibrary.RunCommand(req, _client); return deserializer(result); } } diff --git a/languages/csharp/Program.cs b/languages/csharp/Program.cs index b05abef00..eed888ed0 100644 --- a/languages/csharp/Program.cs +++ b/languages/csharp/Program.cs @@ -4,7 +4,7 @@ const string accessToken = ""; const string organizationIdStr = ""; -var bitwardenClient = new BitwardenClient(); +using var bitwardenClient = new BitwardenClient(); var loginResponse = bitwardenClient.AccessTokenLogin(accessToken); var organizationId = Guid.Parse(organizationIdStr); var responseForProjectResponse = bitwardenClient.Projects().Create(organizationId, "NewTestProject"); @@ -16,14 +16,16 @@ var key = "key"; var value = "value"; var note = "note"; -var responseForSecretResponse = bitwardenClient.Secrets().Create(key, value, note, organizationId, new Guid[]{projectId}); +var responseForSecretResponse = + bitwardenClient.Secrets().Create(key, value, note, organizationId, new Guid[] { projectId }); var secretId = responseForSecretResponse.Data.Id; var responseForSecretIdentifiersResponse = bitwardenClient.Secrets().List(organizationId); responseForSecretResponse = bitwardenClient.Secrets().Get(secretId); key = "key2"; value = "value2"; note = "note2"; -responseForSecretResponse = bitwardenClient.Secrets().Update(secretId, key, value, note, organizationId, new Guid[]{projectId}); +responseForSecretResponse = bitwardenClient.Secrets() + .Update(secretId, key, value, note, organizationId, new Guid[] { projectId }); -var responseForSecretsDeleteResponse = bitwardenClient.Secrets().Delete(new Guid[]{secretId}); -var responseForProjectsDeleteResponse = bitwardenClient.Projects().Delete(new Guid[]{projectId}); +var responseForSecretsDeleteResponse = bitwardenClient.Secrets().Delete(new Guid[] { secretId }); +var responseForProjectsDeleteResponse = bitwardenClient.Projects().Delete(new Guid[] { projectId }); diff --git a/languages/csharp/Projects.cs b/languages/csharp/ProjectsClient.cs similarity index 89% rename from languages/csharp/Projects.cs rename to languages/csharp/ProjectsClient.cs index 44b73f5fe..4167a22d9 100644 --- a/languages/csharp/Projects.cs +++ b/languages/csharp/ProjectsClient.cs @@ -1,17 +1,20 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Bit.Sdk; -public class Projects { +public class ProjectsClient +{ private readonly CommandRunner _commandRunner; - internal Projects(CommandRunner commandRunner) { + internal ProjectsClient(CommandRunner commandRunner) + { this._commandRunner = commandRunner; } - public ResponseForProjectResponse Get(Guid id) { + public ResponseForProjectResponse Get(Guid id) + { var command = new Command(); var projectsCommand = new ProjectsCommand(); var projectGetRequest = new ProjectGetRequest @@ -23,7 +26,8 @@ public ResponseForProjectResponse Get(Guid id) { return _commandRunner.RunCommand(command, JsonConvert.DeserializeObject); } - public ResponseForProjectResponse Create(Guid organizationId, string name) { + public ResponseForProjectResponse Create(Guid organizationId, string name) + { var command = new Command(); var projectsCommand = new ProjectsCommand(); var projectCreateRequest = new ProjectCreateRequest @@ -36,7 +40,8 @@ public ResponseForProjectResponse Create(Guid organizationId, string name) { return _commandRunner.RunCommand(command, JsonConvert.DeserializeObject); } - public ResponseForProjectResponse Update(Guid id, Guid organizationId, String name) { + public ResponseForProjectResponse Update(Guid id, Guid organizationId, String name) + { var command = new Command(); var projectsCommand = new ProjectsCommand(); var projectPutRequest = new ProjectPutRequest @@ -50,7 +55,8 @@ public ResponseForProjectResponse Update(Guid id, Guid organizationId, String na return _commandRunner.RunCommand(command, JsonConvert.DeserializeObject); } - public ResponseForProjectsDeleteResponse Delete(Guid[] ids) { + public ResponseForProjectsDeleteResponse Delete(Guid[] ids) + { var command = new Command(); var projectsCommand = new ProjectsCommand(); var projectsDeleteRequest = new ProjectsDeleteRequest @@ -62,7 +68,8 @@ public ResponseForProjectsDeleteResponse Delete(Guid[] ids) { return _commandRunner.RunCommand(command, JsonConvert.DeserializeObject); } - public ResponseForProjectsResponse List(Guid organizationId) { + public ResponseForProjectsResponse List(Guid organizationId) + { var command = new Command(); var projectsCommand = new ProjectsCommand(); var projectsListRequest = new ProjectsListRequest(); diff --git a/languages/csharp/Secrets.cs b/languages/csharp/SecretsClient.cs similarity index 89% rename from languages/csharp/Secrets.cs rename to languages/csharp/SecretsClient.cs index 5d203963b..9f1834d7d 100644 --- a/languages/csharp/Secrets.cs +++ b/languages/csharp/SecretsClient.cs @@ -1,17 +1,20 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; namespace Bit.Sdk; -public class Secrets { +public class SecretsClient +{ private readonly CommandRunner _commandRunner; - internal Secrets(CommandRunner commandRunner) { + internal SecretsClient(CommandRunner commandRunner) + { _commandRunner = commandRunner; } - public ResponseForSecretResponse Get(Guid id) { + public ResponseForSecretResponse Get(Guid id) + { var command = new Command(); var secretsCommand = new SecretsCommand(); var secretGetRequest = new SecretGetRequest @@ -24,7 +27,8 @@ public ResponseForSecretResponse Get(Guid id) { } public ResponseForSecretResponse Create(string key, string value, string note, Guid organizationId, - Guid[] projectIds) { + Guid[] projectIds) + { var command = new Command(); var secretsCommand = new SecretsCommand(); var secretCreateRequest = new SecretCreateRequest @@ -41,7 +45,8 @@ public ResponseForSecretResponse Create(string key, string value, string note, G } public ResponseForSecretResponse Update(Guid id, string key, string value, string note, Guid organizationId, - Guid[] projectIds) { + Guid[] projectIds) + { var command = new Command(); var secretsCommand = new SecretsCommand(); var secretPutRequest = new SecretPutRequest @@ -58,7 +63,8 @@ public ResponseForSecretResponse Update(Guid id, string key, string value, strin return _commandRunner.RunCommand(command, JsonConvert.DeserializeObject); } - public ResponseForSecretsDeleteResponse Delete(Guid[] ids) { + public ResponseForSecretsDeleteResponse Delete(Guid[] ids) + { var command = new Command(); var secretsCommand = new SecretsCommand(); var secretsDeleteRequest = new SecretsDeleteRequest @@ -70,7 +76,8 @@ public ResponseForSecretsDeleteResponse Delete(Guid[] ids) { return _commandRunner.RunCommand(command, JsonConvert.DeserializeObject); } - public ResponseForSecretIdentifiersResponse List(Guid organizationId) { + public ResponseForSecretIdentifiersResponse List(Guid organizationId) + { var command = new Command(); var secretsCommand = new SecretsCommand(); var secretIdentifiersRequest = new SecretIdentifiersRequest diff --git a/languages/csharp/docs/README.md b/languages/csharp/docs/README.md index 6f5d7bcc2..1d2509d7a 100644 --- a/languages/csharp/docs/README.md +++ b/languages/csharp/docs/README.md @@ -10,7 +10,7 @@ The Bitwarden SDK (Software Development Kit) is a set of programming tools, libr ### Create new Bitwarden client ``` const string accessToken = ""; -var bitwardenClient = new BitwardenClient(); +using var bitwardenClient = new BitwardenClient(); var loginResponse = bitwardenClient.AccessTokenLogin(accessToken); ``` From f6f8ca27cd4f995920692e23cf1ce001448ffb4a Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sat, 2 Sep 2023 14:04:59 +0200 Subject: [PATCH 13/94] temporary add pull_request so git action is registered --- .github/workflows/publish-dotnet.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 393c3afbf..1019e31ef 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -1,6 +1,7 @@ name: Deploy NuGet Package on: + pull_request: workflow_dispatch: version_number: description: "New Version" From 18f213a3fee656fe95ac3711557a099680f2bb7f Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sat, 2 Sep 2023 14:17:03 +0200 Subject: [PATCH 14/94] fix version --- .github/workflows/publish-dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 1019e31ef..96625db4c 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -75,7 +75,7 @@ jobs: - name: Get Package Version id: version env: - VERSION: ${{ github.event.inputs.version_number }} + VERSION: 1.0.0 run: | cd languages/csharp package_version=$(dotnet pack --configuration Release --no-build /property:Version=${VERSION} --output ./nuget-output /nologo /v:n) From 0001770970b4e13400ea8f9b87f853d338c028ec Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sat, 2 Sep 2023 14:22:54 +0200 Subject: [PATCH 15/94] just run on PR --- .github/workflows/publish-dotnet.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 96625db4c..3a7feeee4 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -2,10 +2,6 @@ name: Deploy NuGet Package on: pull_request: - workflow_dispatch: - version_number: - description: "New Version" - required: true jobs: generate_schemas: From 8a220cd2908f2418bd48bf9f985703efb4789261 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sat, 2 Sep 2023 14:31:42 +0200 Subject: [PATCH 16/94] we want to build the package --- .github/workflows/publish-dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 3a7feeee4..cc8578be1 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -74,7 +74,7 @@ jobs: VERSION: 1.0.0 run: | cd languages/csharp - package_version=$(dotnet pack --configuration Release --no-build /property:Version=${VERSION} --output ./nuget-output /nologo /v:n) + package_version=$(dotnet pack --configuration Release /property:Version=${VERSION} --output ./nuget-output /nologo /v:n) echo "Package Version: $package_version" echo "::set-output name=version::$package_version" From bf926bfe66e2d77d9e291fef49ac8a4533f6186b Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sat, 2 Sep 2023 15:14:46 +0200 Subject: [PATCH 17/94] pack with specific version and publish the package --- .github/workflows/publish-dotnet.yml | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index cc8578be1..515d7e932 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -74,23 +74,7 @@ jobs: VERSION: 1.0.0 run: | cd languages/csharp - package_version=$(dotnet pack --configuration Release /property:Version=${VERSION} --output ./nuget-output /nologo /v:n) - echo "Package Version: $package_version" - echo "::set-output name=version::$package_version" - - - name: Check Existing Version on NuGet.org - id: check_version - run: | - existing_version=$(dotnet nuget list source-package-name -s https://api.nuget.org/v3/index.json --version ${{ steps.version.outputs.version }} | grep -oP '(?<=Version: )[^,]+') - echo "Existing Version: $existing_version" - if [ -n "$existing_version" ]; then - echo "Package version already exists on NuGet.org." - echo "::set-output name=exists::true" - else - echo "Package version does not exist on NuGet.org." - echo "::set-output name=exists::false" - fi + dotnet pack --configuration Release /property:Version=${VERSION} --output ./nuget-output /nologo /v:n - name: Publish NuGet Package - if: steps.check_version.outputs.exists == 'false' run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json From ade927715af3eb07497c23e86a397cde46898f74 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sat, 2 Sep 2023 15:40:49 +0200 Subject: [PATCH 18/94] use test name for now --- languages/csharp/bitwardenSdk.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages/csharp/bitwardenSdk.csproj b/languages/csharp/bitwardenSdk.csproj index 4f3830e31..019f12d4d 100644 --- a/languages/csharp/bitwardenSdk.csproj +++ b/languages/csharp/bitwardenSdk.csproj @@ -7,7 +7,7 @@ enable enable BitwardenSdk - BitwardenSdk + TestPkg Bitwarden Sdk Bitwarden Inc. Bitwarden Sdk From 6bfe7e0c49a381b57d4e34207d5fc397ba4daa2c Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sat, 2 Sep 2023 15:55:25 +0200 Subject: [PATCH 19/94] changed api access --- languages/csharp/bitwardenSdk.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages/csharp/bitwardenSdk.csproj b/languages/csharp/bitwardenSdk.csproj index 019f12d4d..441d01497 100644 --- a/languages/csharp/bitwardenSdk.csproj +++ b/languages/csharp/bitwardenSdk.csproj @@ -7,7 +7,7 @@ enable enable BitwardenSdk - TestPkg + TestPackageId Bitwarden Sdk Bitwarden Inc. Bitwarden Sdk From 11fb8c950a7df9afc194153654035285a2b6053f Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sat, 2 Sep 2023 18:55:07 +0200 Subject: [PATCH 20/94] copy libs after cargo build and pack them --- .github/workflows/publish-dotnet.yml | 16 +++++++++++----- languages/csharp/bitwardenSdk.csproj | 6 +++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 515d7e932..deac8b2fd 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -43,11 +43,11 @@ jobs: env: RUSTFLAGS: "-D warnings" - - name: Build Internal - if: ${{ matrix.package == 'bitwarden' }} - run: cargo build -p ${{ matrix.package }} --features internal --release - env: - RUSTFLAGS: "-D warnings" + - name: Upload Artifact + uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 + with: + name: libbitwarden_c_files + path: target/release deploy: runs-on: ubuntu-22.04 @@ -63,6 +63,12 @@ jobs: name: schemas.cs path: languages/csharp + - name: Download libbitwarden_c files + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: libbitwarden_c_files + path: languages/csharp + - name: Set up .NET Core uses: actions/setup-dotnet@v3 with: diff --git a/languages/csharp/bitwardenSdk.csproj b/languages/csharp/bitwardenSdk.csproj index 441d01497..c337ee338 100644 --- a/languages/csharp/bitwardenSdk.csproj +++ b/languages/csharp/bitwardenSdk.csproj @@ -48,15 +48,15 @@ - + Always true - + Always true - + Always true From 28fb2a41402de3c85e767c18152f0e4af424562c Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sat, 2 Sep 2023 18:55:20 +0200 Subject: [PATCH 21/94] copy libs after cargo build and pack them --- .github/workflows/publish-dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index deac8b2fd..5d3307885 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -77,7 +77,7 @@ jobs: - name: Get Package Version id: version env: - VERSION: 1.0.0 + VERSION: 1.0.1 run: | cd languages/csharp dotnet pack --configuration Release /property:Version=${VERSION} --output ./nuget-output /nologo /v:n From 54c6682802d3864a1e4940aa2718803313d12133 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sat, 2 Sep 2023 19:24:23 +0200 Subject: [PATCH 22/94] find all id: libbitwarden_c files --- .github/workflows/publish-dotnet.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 5d3307885..232a5db58 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -43,6 +43,11 @@ jobs: env: RUSTFLAGS: "-D warnings" + - name: Find and Upload libbitwarden_c Files + run: | + find target/release -type f -name '*libbitwarden_c*' -exec cp {} $GITHUB_WORKSPACE/ \; + shell: bash + - name: Upload Artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: @@ -77,7 +82,7 @@ jobs: - name: Get Package Version id: version env: - VERSION: 1.0.1 + VERSION: 1.0.2 run: | cd languages/csharp dotnet pack --configuration Release /property:Version=${VERSION} --output ./nuget-output /nologo /v:n From 62fd39d2f591930d82792beeecc5fffde9602b60 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sat, 2 Sep 2023 19:35:32 +0200 Subject: [PATCH 23/94] use libbitwarden_c files --- .github/workflows/publish-dotnet.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 232a5db58..27322458a 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -52,7 +52,7 @@ jobs: uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: name: libbitwarden_c_files - path: target/release + path: $GITHUB_WORKSPACE deploy: runs-on: ubuntu-22.04 @@ -82,7 +82,7 @@ jobs: - name: Get Package Version id: version env: - VERSION: 1.0.2 + VERSION: 1.0.3 run: | cd languages/csharp dotnet pack --configuration Release /property:Version=${VERSION} --output ./nuget-output /nologo /v:n From f31a094beb8486df640a28a277f29f7353993be5 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sat, 2 Sep 2023 19:45:39 +0200 Subject: [PATCH 24/94] use separated folder --- .github/workflows/publish-dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 27322458a..4d2ac0666 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -52,7 +52,7 @@ jobs: uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: name: libbitwarden_c_files - path: $GITHUB_WORKSPACE + path: $GITHUB_WORKSPACE/artifacts deploy: runs-on: ubuntu-22.04 From b1ab18bb4f72d42d070c13ca56b75b856f9f80b0 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sat, 2 Sep 2023 20:02:36 +0200 Subject: [PATCH 25/94] use separated folder --- .github/workflows/publish-dotnet.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 4d2ac0666..3d0d54caf 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -19,12 +19,6 @@ jobs: - macos-latest - ubuntu-latest - windows-latest - - package: - - bitwarden - - bitwarden-api-api - - bitwarden-api-identity - steps: - name: Checkout uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 @@ -39,7 +33,7 @@ jobs: uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 - name: Build - run: cargo build -p ${{ matrix.package }} --release + run: cargo build --release env: RUSTFLAGS: "-D warnings" From 5ebe0a99811ad0da0f4afc3a4b93c074019c04d8 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sat, 2 Sep 2023 20:18:35 +0200 Subject: [PATCH 26/94] use separated folder --- .github/workflows/publish-dotnet.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 3d0d54caf..1fea950c6 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -39,14 +39,14 @@ jobs: - name: Find and Upload libbitwarden_c Files run: | - find target/release -type f -name '*libbitwarden_c*' -exec cp {} $GITHUB_WORKSPACE/ \; + find target/release -type f -name '*bitwarden_c*' -exec cp {} $GITHUB_WORKSPACE/ \; shell: bash - name: Upload Artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: name: libbitwarden_c_files - path: $GITHUB_WORKSPACE/artifacts + path: $GITHUB_WORKSPACE deploy: runs-on: ubuntu-22.04 From e2f690f131d1df9c87aa036c01b338187fba4a60 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sat, 2 Sep 2023 20:35:44 +0200 Subject: [PATCH 27/94] use separated folder --- .github/workflows/publish-dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 1fea950c6..f2e6bdd25 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -39,7 +39,7 @@ jobs: - name: Find and Upload libbitwarden_c Files run: | - find target/release -type f -name '*bitwarden_c*' -exec cp {} $GITHUB_WORKSPACE/ \; + find ./target/release -type f -name '*bitwarden_c*' -exec cp {} $GITHUB_WORKSPACE/ \; shell: bash - name: Upload Artifact From 0d8c439d57d95dc0cbbff3d8c216788a4a8931b9 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sat, 2 Sep 2023 21:03:37 +0200 Subject: [PATCH 28/94] use separated folder --- .github/workflows/publish-dotnet.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index f2e6bdd25..867110807 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -39,14 +39,14 @@ jobs: - name: Find and Upload libbitwarden_c Files run: | - find ./target/release -type f -name '*bitwarden_c*' -exec cp {} $GITHUB_WORKSPACE/ \; + find ./target/release -type f -name '*bitwarden_c*' -exec cp {} ${{ github.workspace }}/ \; shell: bash - name: Upload Artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: name: libbitwarden_c_files - path: $GITHUB_WORKSPACE + path: ${{ github.workspace }} deploy: runs-on: ubuntu-22.04 From c92299e50dfb2d21531a24e2f9b5865485bbc433 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sun, 3 Sep 2023 09:41:40 +0200 Subject: [PATCH 29/94] use separated folder --- .github/workflows/publish-dotnet.yml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 867110807..32fe628d6 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -37,16 +37,12 @@ jobs: env: RUSTFLAGS: "-D warnings" - - name: Find and Upload libbitwarden_c Files - run: | - find ./target/release -type f -name '*bitwarden_c*' -exec cp {} ${{ github.workspace }}/ \; - shell: bash - - name: Upload Artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: name: libbitwarden_c_files - path: ${{ github.workspace }} + path: | + target/release/*bitwarden_c* deploy: runs-on: ubuntu-22.04 From 07c5d4a766d67db7693bced2028bd088ac34d1d5 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sun, 3 Sep 2023 10:24:59 +0200 Subject: [PATCH 30/94] list files --- .github/workflows/publish-dotnet.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 32fe628d6..2c7edf6c9 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -64,6 +64,10 @@ jobs: name: libbitwarden_c_files path: languages/csharp + - name: List libbitwarden_c_files + run: | + ls -1 languages/csharp # one per line + - name: Set up .NET Core uses: actions/setup-dotnet@v3 with: From c3f0a1ddd41d82b0823fc671b2a72882f562859f Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sun, 3 Sep 2023 11:05:09 +0200 Subject: [PATCH 31/94] separate folders --- .github/workflows/publish-dotnet.yml | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 2c7edf6c9..530dbd430 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -40,7 +40,7 @@ jobs: - name: Upload Artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: - name: libbitwarden_c_files + name: libbitwarden_c_files-${{ matrix.os }} path: | target/release/*bitwarden_c* @@ -58,10 +58,22 @@ jobs: name: schemas.cs path: languages/csharp - - name: Download libbitwarden_c files + - name: Download libbitwarden_c files macos-latest uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files + name: libbitwarden_c_files-macos-latest + path: languages/csharp + + - name: Download libbitwarden_c files ubuntu-latest + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: libbitwarden_c_files-ubuntu-latest + path: languages/csharp + + - name: Download libbitwarden_c files windows-latest + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: libbitwarden_c_files-windows-latest path: languages/csharp - name: List libbitwarden_c_files From 67400af6e92f55434b7c970d1984aec0b93dec19 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sun, 3 Sep 2023 12:33:11 +0200 Subject: [PATCH 32/94] separate folders --- .github/workflows/publish-dotnet.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 530dbd430..a7b849df7 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -37,6 +37,10 @@ jobs: env: RUSTFLAGS: "-D warnings" + - name: List release files + run: | + ls -1 target/release # one per line + - name: Upload Artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: From 3e238f175bff48a7a7737df76251c9a194355523 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sun, 3 Sep 2023 12:59:40 +0200 Subject: [PATCH 33/94] fixes --- .github/workflows/publish-dotnet.yml | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index a7b849df7..9c49c98a6 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -8,17 +8,15 @@ jobs: uses: ./.github/workflows/generate_schemas.yml build_rust: - name: Building ${{matrix.package}} for - ${{ matrix.os }} - - runs-on: ${{ matrix.settings.os || 'ubuntu-latest' }} - strategy: fail-fast: false matrix: - os: - - macos-latest - - ubuntu-latest - - windows-latest + os: [ macos-latest, ubuntu-latest, windows-latest ] + + runs-on: ${{ matrix.os }} + + name: Building for ${{ matrix.os }} + steps: - name: Checkout uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 @@ -27,7 +25,6 @@ jobs: uses: dtolnay/rust-toolchain@f361669954a8ecfc00a3443f35f9ac8e610ffc06 # stable with: toolchain: stable - targets: ${{ matrix.settings.target }} - name: Cache cargo registry uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 @@ -92,7 +89,7 @@ jobs: - name: Get Package Version id: version env: - VERSION: 1.0.3 + VERSION: 1.0.4 run: | cd languages/csharp dotnet pack --configuration Release /property:Version=${VERSION} --output ./nuget-output /nologo /v:n From 97c856c766a585dc52038a30a8fdd60547fe057e Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sun, 3 Sep 2023 13:14:53 +0200 Subject: [PATCH 34/94] fixes --- .github/workflows/publish-dotnet.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 9c49c98a6..95178f6f3 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -11,7 +11,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ macos-latest, ubuntu-latest, windows-latest ] + os: [macos-latest, ubuntu-latest, windows-latest] runs-on: ${{ matrix.os }} @@ -34,10 +34,6 @@ jobs: env: RUSTFLAGS: "-D warnings" - - name: List release files - run: | - ls -1 target/release # one per line - - name: Upload Artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: From 23c9bd15150aa7318a4072d9c676c87266896027 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sun, 3 Sep 2023 23:27:41 +0200 Subject: [PATCH 35/94] fixes --- .github/workflows/publish-dotnet.yml | 32 ++++++++----------- languages/csharp/bitwardenSdk.csproj | 46 +++++++++++++++++++++++----- 2 files changed, 52 insertions(+), 26 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 95178f6f3..5d2928faa 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -12,10 +12,11 @@ jobs: fail-fast: false matrix: os: [macos-latest, ubuntu-latest, windows-latest] + arch: [x86, x64, arm64] runs-on: ${{ matrix.os }} - name: Building for ${{ matrix.os }} + name: Build for ${{ matrix.os }} ${{ matrix.arch }} steps: - name: Checkout @@ -30,14 +31,19 @@ jobs: uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 - name: Build - run: cargo build --release - env: - RUSTFLAGS: "-D warnings" + run: | + if [[ ${{ matrix.os }} == 'windows-latest' ]]; then + cargo build --release --target ${{ matrix.architecture }}-pc-windows-msvc + elif [[ ${{ matrix.os }} == 'macos-latest' ]]; then + cargo build --release --target ${{ matrix.architecture }}-apple-darwin + else + cargo build --release --target ${{ matrix.architecture }}-unknown-linux-gnu + fi - name: Upload Artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: - name: libbitwarden_c_files-${{ matrix.os }} + name: libbitwarden_c_files/${{ matrix.os }}-${{ matrix.arch }} path: | target/release/*bitwarden_c* @@ -55,22 +61,10 @@ jobs: name: schemas.cs path: languages/csharp - - name: Download libbitwarden_c files macos-latest - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - with: - name: libbitwarden_c_files-macos-latest - path: languages/csharp - - - name: Download libbitwarden_c files ubuntu-latest - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - with: - name: libbitwarden_c_files-ubuntu-latest - path: languages/csharp - - - name: Download libbitwarden_c files windows-latest + - name: Download libbitwarden_c files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files-windows-latest + name: libbitwarden_c_files path: languages/csharp - name: List libbitwarden_c_files diff --git a/languages/csharp/bitwardenSdk.csproj b/languages/csharp/bitwardenSdk.csproj index c337ee338..38dd4728f 100644 --- a/languages/csharp/bitwardenSdk.csproj +++ b/languages/csharp/bitwardenSdk.csproj @@ -46,19 +46,51 @@ true - - + Always - true + true + contentFiles/any/net6.0/x86 - - Always + + Always true - - + contentFiles/any/net6.0/x64 + + + Always + true + contentFiles/any/net6.0/arm64 + + Always + true + contentFiles/any/net6.0/x86 + + + Always + true + contentFiles/any/net6.0/x64 + + + Always true + contentFiles/any/net6.0/arm64 + + + Always + true + contentFiles/any/net6.0/x86 + + Always + true + contentFiles/any/net6.0/x64 + + + Always + true + contentFiles/any/net6.0/arm64 + From f40340f4010a7d53cf954b6b2d74fd5b8e2112ad Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sun, 3 Sep 2023 23:42:34 +0200 Subject: [PATCH 36/94] fixes --- .github/workflows/publish-dotnet.yml | 60 +++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 5d2928faa..5d4459c73 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -33,11 +33,11 @@ jobs: - name: Build run: | if [[ ${{ matrix.os }} == 'windows-latest' ]]; then - cargo build --release --target ${{ matrix.architecture }}-pc-windows-msvc + cargo build --release --target ${{ matrix.arch }}-pc-windows-msvc elif [[ ${{ matrix.os }} == 'macos-latest' ]]; then - cargo build --release --target ${{ matrix.architecture }}-apple-darwin + cargo build --release --target ${{ matrix.arch }}-apple-darwin else - cargo build --release --target ${{ matrix.architecture }}-unknown-linux-gnu + cargo build --release --target ${{ matrix.arch }}-unknown-linux-gnu fi - name: Upload Artifact @@ -61,11 +61,59 @@ jobs: name: schemas.cs path: languages/csharp - - name: Download libbitwarden_c files + - name: Download libbitwarden_c_files/macos-latest-x86 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files - path: languages/csharp + name: libbitwarden_c_files/macos-latest-x86 + path: languages/csharp/macos-latest-x86 + + - name: Download libbitwarden_c_files/macos-latest-x64 files + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: libbitwarden_c_files/macos-latest-x64 + path: languages/csharp/macos-latest-x64 + + - name: Download libbitwarden_c_files/macos-latest-arm64 files + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: libbitwarden_c_files/macos-latest-arm64 + path: languages/csharp/macos-latest-arm64 + + - name: Download libbitwarden_c_files/ubuntu-latest-x86 files + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: libbitwarden_c_files/ubuntu-latest-x86 + path: languages/csharp/ubuntu-latest-x86 + + - name: Download libbitwarden_c_files/ubuntu-latest-x64 files + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: libbitwarden_c_files/ubuntu-latest-x64 + path: languages/csharp/ubuntu-latest-x64 + + - name: Download libbitwarden_c_files/ubuntu-latest-arm64 files + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: libbitwarden_c_files/ubuntu-latest-arm64 + path: languages/csharp/ubuntu-latest-arm64 + + - name: Download libbitwarden_c_files/windows-latest-x86 files + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: libbitwarden_c_files/windows-latest-x86 + path: languages/csharp/windows-latest-x86 + + - name: Download libbitwarden_c_files/windows-latest-x64 files + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: libbitwarden_c_files/windows-latest-x64 + path: languages/csharp/windows-latest-x64 + + - name: Download libbitwarden_c_files/windows-latest-arm64 files + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: libbitwarden_c_files/windows-latest-arm64 + path: languages/csharp/windows-latest-arm64 - name: List libbitwarden_c_files run: | From 0fc144ef3b1f5c09e7bdbd03a2db2a1af8bd9c0c Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sun, 3 Sep 2023 23:47:39 +0200 Subject: [PATCH 37/94] fixes --- .github/workflows/publish-dotnet.yml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 5d4459c73..0699ecb4a 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -32,14 +32,24 @@ jobs: - name: Build run: | - if [[ ${{ matrix.os }} == 'windows-latest' ]]; then - cargo build --release --target ${{ matrix.arch }}-pc-windows-msvc - elif [[ ${{ matrix.os }} == 'macos-latest' ]]; then - cargo build --release --target ${{ matrix.arch }}-apple-darwin + if [[ ${{ matrix.os }} == "windows-latest" ]]; then + target_os="windows" + elif [[ ${{ matrix.os }} == "macos-latest" ]]; then + target_os="macos" else - cargo build --release --target ${{ matrix.arch }}-unknown-linux-gnu + target_os="linux" fi + if [[ ${{ matrix.arch }} == "x86" ]]; then + target_arch="i686" + elif [[ ${{ matrix.arch }} == "x64" ]]; then + target_arch="x86_64" + else + target_arch="aarch64" + fi + + cargo build --release --target $target_arch-unknown-$target_os + - name: Upload Artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: From 0b0be5ce01a3e6305da0c46fa28e1ac0dd30a75a Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 07:10:58 +0200 Subject: [PATCH 38/94] fixes --- .github/workflows/publish-dotnet.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 0699ecb4a..886adbe87 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -12,7 +12,7 @@ jobs: fail-fast: false matrix: os: [macos-latest, ubuntu-latest, windows-latest] - arch: [x86, x64, arm64] + arch: [x64, arm64] runs-on: ${{ matrix.os }} @@ -33,11 +33,11 @@ jobs: - name: Build run: | if [[ ${{ matrix.os }} == "windows-latest" ]]; then - target_os="windows" + target_os="pc-windows-msvc" elif [[ ${{ matrix.os }} == "macos-latest" ]]; then - target_os="macos" + target_os="apple-darwin" else - target_os="linux" + target_os="unknown-linux-gnu" fi if [[ ${{ matrix.arch }} == "x86" ]]; then @@ -48,7 +48,7 @@ jobs: target_arch="aarch64" fi - cargo build --release --target $target_arch-unknown-$target_os + cargo build --release --target $target_arch-$target_os - name: Upload Artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 From 07ef4315fe06e881781cfe7519f0c78fbb7c5d0f Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 07:26:59 +0200 Subject: [PATCH 39/94] fixes --- .github/workflows/publish-dotnet.yml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 886adbe87..d481ee518 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -30,7 +30,27 @@ jobs: - name: Cache cargo registry uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 - - name: Build + - name: Install target for ${{ matrix.os }} ${{ matrix.arch }} + run: | + if [[ ${{ matrix.os }} == "windows-latest" ]]; then + target_os="pc-windows-msvc" + elif [[ ${{ matrix.os }} == "macos-latest" ]]; then + target_os="apple-darwin" + else + target_os="unknown-linux-gnu" + fi + + if [[ ${{ matrix.arch }} == "x86" ]]; then + target_arch="i686" + elif [[ ${{ matrix.arch }} == "x64" ]]; then + target_arch="x86_64" + else + target_arch="aarch64" + fi + + rustup target add $target_arch-$target_os + + - name: Build Rust run: | if [[ ${{ matrix.os }} == "windows-latest" ]]; then target_os="pc-windows-msvc" From 6ffeb2d9a59e238fa41d2b77fc9a850dddb25f33 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 07:56:39 +0200 Subject: [PATCH 40/94] fixes --- .github/workflows/publish-dotnet.yml | 56 +++++++++++----------------- 1 file changed, 21 insertions(+), 35 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index d481ee518..de3fef203 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -30,45 +30,31 @@ jobs: - name: Cache cargo registry uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 - - name: Install target for ${{ matrix.os }} ${{ matrix.arch }} - run: | - if [[ ${{ matrix.os }} == "windows-latest" ]]; then - target_os="pc-windows-msvc" - elif [[ ${{ matrix.os }} == "macos-latest" ]]; then - target_os="apple-darwin" - else - target_os="unknown-linux-gnu" - fi - - if [[ ${{ matrix.arch }} == "x86" ]]; then - target_arch="i686" - elif [[ ${{ matrix.arch }} == "x64" ]]; then - target_arch="x86_64" - else - target_arch="aarch64" - fi - - rustup target add $target_arch-$target_os - - name: Build Rust run: | - if [[ ${{ matrix.os }} == "windows-latest" ]]; then - target_os="pc-windows-msvc" - elif [[ ${{ matrix.os }} == "macos-latest" ]]; then - target_os="apple-darwin" - else - target_os="unknown-linux-gnu" - fi - - if [[ ${{ matrix.arch }} == "x86" ]]; then - target_arch="i686" - elif [[ ${{ matrix.arch }} == "x64" ]]; then - target_arch="x86_64" - else - target_arch="aarch64" + if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then + if [ "${{ matrix.arch }}" == "x86_64" ]; then + cargo build --release + elif [ "${{ matrix.arch }}" == "arm64" ]; then + rustup target add aarch64-unknown-linux-gnu + cargo build --target aarch64-unknown-linux-gnu --release + fi + elif [ "${{ matrix.os }}" == "windows-latest" ]; then + if [ "${{ matrix.arch }}" == "x86_64" ]; then + cargo build --target x86_64-pc-windows-msvc --release + fi + elif [ "${{ matrix.os }}" == "macos-latest" ]; then + if [ "${{ matrix.arch }}" == "x86_64" ]; then + cargo build --release + elif [ "${{ matrix.arch }}" == "arm64" ]; then + rustup target add aarch64-apple-darwin + cargo build --target aarch64-apple-darwin --release + fi fi - cargo build --release --target $target_arch-$target_os + - name: List libbitwarden_c_files + run: | + ls -1 target/release # one per line - name: Upload Artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 From b25e106726b577f3fa41590a8f501c6358076f44 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 09:50:16 +0200 Subject: [PATCH 41/94] fixes --- .github/workflows/publish-dotnet.yml | 45 +++++++++++++--------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index de3fef203..d767f3c29 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -12,7 +12,7 @@ jobs: fail-fast: false matrix: os: [macos-latest, ubuntu-latest, windows-latest] - arch: [x64, arm64] + arch: [x86_64, arm64] runs-on: ${{ matrix.os }} @@ -30,38 +30,35 @@ jobs: - name: Cache cargo registry uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 - - name: Build Rust + - name: Set build architecture + if: ${{ matrix.os != "windows-latest" }} run: | - if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then - if [ "${{ matrix.arch }}" == "x86_64" ]; then - cargo build --release - elif [ "${{ matrix.arch }}" == "arm64" ]; then - rustup target add aarch64-unknown-linux-gnu - cargo build --target aarch64-unknown-linux-gnu --release - fi - elif [ "${{ matrix.os }}" == "windows-latest" ]; then - if [ "${{ matrix.arch }}" == "x86_64" ]; then - cargo build --target x86_64-pc-windows-msvc --release - fi - elif [ "${{ matrix.os }}" == "macos-latest" ]; then - if [ "${{ matrix.arch }}" == "x86_64" ]; then - cargo build --release - elif [ "${{ matrix.arch }}" == "arm64" ]; then - rustup target add aarch64-apple-darwin - cargo build --target aarch64-apple-darwin --release - fi + if [[ "${{ matrix.arch }}" == "x86_64" ]]; then + echo "TARGET_ARCH=" >> $GITHUB_ENV + echo "TARGET_FOLDER=target/release/" >> $GITHUB_ENV + elif [[ "${{ matrix.arch }}" == "arm64" ]]; then + echo "TARGET_ARCH=aarch64-apple-darwin" >> $GITHUB_ENV + echo "TARGET_FOLDER=target/aarch64-apple-darwin/release/" >> $GITHUB_ENV fi - - name: List libbitwarden_c_files - run: | - ls -1 target/release # one per line + - name: Build Rust + if: ${{ matrix.os != "windows-latest" }} + run: cargo build --target ${{ env.TARGET_ARCH }} --release + env: + RUSTFLAGS: "-D warnings" + + - name: Build Rust + if: ${{ matrix.os == "windows-latest"}} && ${{ matrix.arch == "x86_64"}} + run: cargo build --release + env: + RUSTFLAGS: "-D warnings" - name: Upload Artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: name: libbitwarden_c_files/${{ matrix.os }}-${{ matrix.arch }} path: | - target/release/*bitwarden_c* + ${{ env.TARGET_FOLDER }}/*bitwarden_c* deploy: runs-on: ubuntu-22.04 From 0f3524f27d942bf4aa2ea3688bd02b2f98991408 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 09:59:37 +0200 Subject: [PATCH 42/94] fixes --- .github/workflows/publish-dotnet.yml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index d767f3c29..4033c3395 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -13,6 +13,11 @@ jobs: matrix: os: [macos-latest, ubuntu-latest, windows-latest] arch: [x86_64, arm64] + exclude: + - os: windows-latest + arch: arm64 + - os: ubuntu-latest + arch: arm64 runs-on: ${{ matrix.os }} @@ -31,7 +36,6 @@ jobs: uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 - name: Set build architecture - if: ${{ matrix.os != "windows-latest" }} run: | if [[ "${{ matrix.arch }}" == "x86_64" ]]; then echo "TARGET_ARCH=" >> $GITHUB_ENV @@ -42,17 +46,10 @@ jobs: fi - name: Build Rust - if: ${{ matrix.os != "windows-latest" }} run: cargo build --target ${{ env.TARGET_ARCH }} --release env: RUSTFLAGS: "-D warnings" - - name: Build Rust - if: ${{ matrix.os == "windows-latest"}} && ${{ matrix.arch == "x86_64"}} - run: cargo build --release - env: - RUSTFLAGS: "-D warnings" - - name: Upload Artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: From 5d899fb6939e0c5eee3c2984b2934ecb2b1f4489 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 10:29:17 +0200 Subject: [PATCH 43/94] fixes --- .github/workflows/publish-dotnet.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 4033c3395..dc23799df 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -35,18 +35,25 @@ jobs: - name: Cache cargo registry uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 - - name: Set build architecture + - name: Set build architecture, ios, linux + if: ${{ matrix.os }}" != "windows-latest" run: | if [[ "${{ matrix.arch }}" == "x86_64" ]]; then echo "TARGET_ARCH=" >> $GITHUB_ENV echo "TARGET_FOLDER=target/release/" >> $GITHUB_ENV elif [[ "${{ matrix.arch }}" == "arm64" ]]; then - echo "TARGET_ARCH=aarch64-apple-darwin" >> $GITHUB_ENV + echo "TARGET_ARCH=--target aarch64-apple-darwin" >> $GITHUB_ENV echo "TARGET_FOLDER=target/aarch64-apple-darwin/release/" >> $GITHUB_ENV fi + - name: Set build architecture, windows + if: ${{ matrix.os }}" == "windows-latest" + run: | + echo "TARGET_ARCH=" >> $GITHUB_ENV + echo "TARGET_FOLDER=target/release/" >> $GITHUB_ENV + - name: Build Rust - run: cargo build --target ${{ env.TARGET_ARCH }} --release + run: cargo build ${{ env.TARGET_ARCH }} --release env: RUSTFLAGS: "-D warnings" From d145d7e0597ca9a933554c6b8f4099169f01eb08 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 10:38:07 +0200 Subject: [PATCH 44/94] fixes --- .github/workflows/publish-dotnet.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index dc23799df..57aec433e 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -36,7 +36,7 @@ jobs: uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 - name: Set build architecture, ios, linux - if: ${{ matrix.os }}" != "windows-latest" + if: matrix.os != 'windows-latest' run: | if [[ "${{ matrix.arch }}" == "x86_64" ]]; then echo "TARGET_ARCH=" >> $GITHUB_ENV @@ -47,7 +47,7 @@ jobs: fi - name: Set build architecture, windows - if: ${{ matrix.os }}" == "windows-latest" + if: matrix.os == 'windows-latest' run: | echo "TARGET_ARCH=" >> $GITHUB_ENV echo "TARGET_FOLDER=target/release/" >> $GITHUB_ENV From 52614a98dd3329bd157bea335d34a2f65d5637f7 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 10:40:32 +0200 Subject: [PATCH 45/94] fixes --- .github/workflows/publish-dotnet.yml | 38 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 57aec433e..4b7082f93 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -60,7 +60,7 @@ jobs: - name: Upload Artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: - name: libbitwarden_c_files/${{ matrix.os }}-${{ matrix.arch }} + name: libbitwarden_c_files-${{ matrix.os }}-${{ matrix.arch }} path: | ${{ env.TARGET_FOLDER }}/*bitwarden_c* @@ -78,58 +78,58 @@ jobs: name: schemas.cs path: languages/csharp - - name: Download libbitwarden_c_files/macos-latest-x86 files + - name: Download libbitwarden_c_files-macos-latest-x86 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files/macos-latest-x86 + name: libbitwarden_c_files-macos-latest-x86 path: languages/csharp/macos-latest-x86 - - name: Download libbitwarden_c_files/macos-latest-x64 files + - name: Download libbitwarden_c_files-macos-latest-x64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files/macos-latest-x64 + name: libbitwarden_c_files-macos-latest-x64 path: languages/csharp/macos-latest-x64 - - name: Download libbitwarden_c_files/macos-latest-arm64 files + - name: Download libbitwarden_c_files-macos-latest-arm64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files/macos-latest-arm64 + name: libbitwarden_c_files-macos-latest-arm64 path: languages/csharp/macos-latest-arm64 - - name: Download libbitwarden_c_files/ubuntu-latest-x86 files + - name: Download libbitwarden_c_files-ubuntu-latest-x86 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files/ubuntu-latest-x86 + name: libbitwarden_c_files-ubuntu-latest-x86 path: languages/csharp/ubuntu-latest-x86 - - name: Download libbitwarden_c_files/ubuntu-latest-x64 files + - name: Download libbitwarden_c_files-ubuntu-latest-x64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files/ubuntu-latest-x64 + name: libbitwarden_c_files-ubuntu-latest-x64 path: languages/csharp/ubuntu-latest-x64 - - name: Download libbitwarden_c_files/ubuntu-latest-arm64 files + - name: Download libbitwarden_c_files-ubuntu-latest-arm64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files/ubuntu-latest-arm64 + name: libbitwarden_c_files-ubuntu-latest-arm64 path: languages/csharp/ubuntu-latest-arm64 - - name: Download libbitwarden_c_files/windows-latest-x86 files + - name: Download libbitwarden_c_files-windows-latest-x86 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files/windows-latest-x86 + name: libbitwarden_c_files-windows-latest-x86 path: languages/csharp/windows-latest-x86 - - name: Download libbitwarden_c_files/windows-latest-x64 files + - name: Download libbitwarden_c_files-windows-latest-x64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files/windows-latest-x64 + name: libbitwarden_c_files-windows-latest-x64 path: languages/csharp/windows-latest-x64 - - name: Download libbitwarden_c_files/windows-latest-arm64 files + - name: Download libbitwarden_c_files-windows-latest-arm64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files/windows-latest-arm64 + name: libbitwarden_c_files-windows-latest-arm64 path: languages/csharp/windows-latest-arm64 - name: List libbitwarden_c_files From c07d13308cd295e66a67a32e710a62a5cf6660ed Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 10:51:40 +0200 Subject: [PATCH 46/94] fixes --- .github/workflows/publish-dotnet.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 4b7082f93..4515e383e 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -44,6 +44,7 @@ jobs: elif [[ "${{ matrix.arch }}" == "arm64" ]]; then echo "TARGET_ARCH=--target aarch64-apple-darwin" >> $GITHUB_ENV echo "TARGET_FOLDER=target/aarch64-apple-darwin/release/" >> $GITHUB_ENV + rustup target add aarch64-apple-darwin fi - name: Set build architecture, windows From 06dc693190ebd4e65e7eca0081064148680cc6a7 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 10:55:24 +0200 Subject: [PATCH 47/94] fixes --- .github/workflows/publish-dotnet.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 4515e383e..4595d4529 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -50,8 +50,8 @@ jobs: - name: Set build architecture, windows if: matrix.os == 'windows-latest' run: | - echo "TARGET_ARCH=" >> $GITHUB_ENV - echo "TARGET_FOLDER=target/release/" >> $GITHUB_ENV + echo "TARGET_ARCH=" | Out-File -FilePath $env:GITHUB_ENV + echo "TARGET_FOLDER=target/release/" | Out-File -FilePath $env:GITHUB_ENV - name: Build Rust run: cargo build ${{ env.TARGET_ARCH }} --release From 11b71725d50200b6d157f3750856b62a68a66801 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 11:14:24 +0200 Subject: [PATCH 48/94] fixes --- .github/workflows/publish-dotnet.yml | 36 +++------------------------- 1 file changed, 3 insertions(+), 33 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 4595d4529..42a48bfc1 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -12,7 +12,7 @@ jobs: fail-fast: false matrix: os: [macos-latest, ubuntu-latest, windows-latest] - arch: [x86_64, arm64] + arch: [x64, arm64] exclude: - os: windows-latest arch: arm64 @@ -38,7 +38,7 @@ jobs: - name: Set build architecture, ios, linux if: matrix.os != 'windows-latest' run: | - if [[ "${{ matrix.arch }}" == "x86_64" ]]; then + if [[ "${{ matrix.arch }}" == "x64" ]]; then echo "TARGET_ARCH=" >> $GITHUB_ENV echo "TARGET_FOLDER=target/release/" >> $GITHUB_ENV elif [[ "${{ matrix.arch }}" == "arm64" ]]; then @@ -79,12 +79,6 @@ jobs: name: schemas.cs path: languages/csharp - - name: Download libbitwarden_c_files-macos-latest-x86 files - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - with: - name: libbitwarden_c_files-macos-latest-x86 - path: languages/csharp/macos-latest-x86 - - name: Download libbitwarden_c_files-macos-latest-x64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: @@ -97,42 +91,18 @@ jobs: name: libbitwarden_c_files-macos-latest-arm64 path: languages/csharp/macos-latest-arm64 - - name: Download libbitwarden_c_files-ubuntu-latest-x86 files - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - with: - name: libbitwarden_c_files-ubuntu-latest-x86 - path: languages/csharp/ubuntu-latest-x86 - - name: Download libbitwarden_c_files-ubuntu-latest-x64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: name: libbitwarden_c_files-ubuntu-latest-x64 path: languages/csharp/ubuntu-latest-x64 - - name: Download libbitwarden_c_files-ubuntu-latest-arm64 files - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - with: - name: libbitwarden_c_files-ubuntu-latest-arm64 - path: languages/csharp/ubuntu-latest-arm64 - - - name: Download libbitwarden_c_files-windows-latest-x86 files - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - with: - name: libbitwarden_c_files-windows-latest-x86 - path: languages/csharp/windows-latest-x86 - - name: Download libbitwarden_c_files-windows-latest-x64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: name: libbitwarden_c_files-windows-latest-x64 path: languages/csharp/windows-latest-x64 - - name: Download libbitwarden_c_files-windows-latest-arm64 files - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - with: - name: libbitwarden_c_files-windows-latest-arm64 - path: languages/csharp/windows-latest-arm64 - - name: List libbitwarden_c_files run: | ls -1 languages/csharp # one per line @@ -145,7 +115,7 @@ jobs: - name: Get Package Version id: version env: - VERSION: 1.0.4 + VERSION: 1.0.5 run: | cd languages/csharp dotnet pack --configuration Release /property:Version=${VERSION} --output ./nuget-output /nologo /v:n From 4999d8b853893af4978af83d0b2c98ca46accdb0 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 15:26:59 +0200 Subject: [PATCH 49/94] one package per arch and system --- .github/workflows/publish-dotnet.yml | 50 ++++++---------------------- languages/csharp/bitwardenSdk.csproj | 41 +++-------------------- 2 files changed, 15 insertions(+), 76 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 42a48bfc1..796d55eea 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -7,7 +7,7 @@ jobs: generate_schemas: uses: ./.github/workflows/generate_schemas.yml - build_rust: + build_and_deploy: strategy: fail-fast: false matrix: @@ -21,6 +21,8 @@ jobs: runs-on: ${{ matrix.os }} + needs: [generate_schemas] + name: Build for ${{ matrix.os }} ${{ matrix.arch }} steps: @@ -50,8 +52,8 @@ jobs: - name: Set build architecture, windows if: matrix.os == 'windows-latest' run: | - echo "TARGET_ARCH=" | Out-File -FilePath $env:GITHUB_ENV - echo "TARGET_FOLDER=target/release/" | Out-File -FilePath $env:GITHUB_ENV + echo "TARGET_ARCH=" | Out-File -FilePath $env:GITHUB_ENV + echo "TARGET_FOLDER=target/release/" | Out-File -FilePath $env:GITHUB_ENV - name: Build Rust run: cargo build ${{ env.TARGET_ARCH }} --release @@ -61,51 +63,21 @@ jobs: - name: Upload Artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: - name: libbitwarden_c_files-${{ matrix.os }}-${{ matrix.arch }} + name: libbitwarden_c_files path: | ${{ env.TARGET_FOLDER }}/*bitwarden_c* - 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 - - name: Download libbitwarden_c_files-macos-latest-x64 files + - name: Download libbitwarden_c_files files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files-macos-latest-x64 - path: languages/csharp/macos-latest-x64 - - - name: Download libbitwarden_c_files-macos-latest-arm64 files - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - with: - name: libbitwarden_c_files-macos-latest-arm64 - path: languages/csharp/macos-latest-arm64 - - - name: Download libbitwarden_c_files-ubuntu-latest-x64 files - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - with: - name: libbitwarden_c_files-ubuntu-latest-x64 - path: languages/csharp/ubuntu-latest-x64 - - - name: Download libbitwarden_c_files-windows-latest-x64 files - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - with: - name: libbitwarden_c_files-windows-latest-x64 - path: languages/csharp/windows-latest-x64 - - - name: List libbitwarden_c_files - run: | - ls -1 languages/csharp # one per line + name: libbitwarden_c_files + path: languages/csharp - name: Set up .NET Core uses: actions/setup-dotnet@v3 @@ -115,10 +87,10 @@ jobs: - name: Get Package Version id: version env: - VERSION: 1.0.5 + VERSION: 1.0.0 run: | cd languages/csharp - dotnet pack --configuration Release /property:Version=${VERSION} --output ./nuget-output /nologo /v:n + dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }}. -p:Platform=${{ matrix.arch }} -p:Version=${VERSION} --output ./nuget-output /nologo /v:n - name: Publish NuGet Package run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json diff --git a/languages/csharp/bitwardenSdk.csproj b/languages/csharp/bitwardenSdk.csproj index 38dd4728f..334cd162b 100644 --- a/languages/csharp/bitwardenSdk.csproj +++ b/languages/csharp/bitwardenSdk.csproj @@ -46,51 +46,18 @@ true - - + + Always true - contentFiles/any/net6.0/x86 - - Always - true - contentFiles/any/net6.0/x64 - - - Always - true - contentFiles/any/net6.0/arm64 - - + Always true - contentFiles/any/net6.0/x86 - - Always - true - contentFiles/any/net6.0/x64 - - - Always - true - contentFiles/any/net6.0/arm64 - - + Always true - contentFiles/any/net6.0/x86 - - Always - true - contentFiles/any/net6.0/x64 - - - Always - true - contentFiles/any/net6.0/arm64 - From da7eda7a6c4f0fa7ba4fd5b2a55db01367acfffe Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 15:41:57 +0200 Subject: [PATCH 50/94] one package per arch and system --- .github/workflows/publish-dotnet.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 796d55eea..810efac6e 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -84,13 +84,13 @@ jobs: with: dotnet-version: "6.0.x" - - name: Get Package Version + - name: Pack NuGet Package id: version env: VERSION: 1.0.0 run: | cd languages/csharp - dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }}. -p:Platform=${{ matrix.arch }} -p:Version=${VERSION} --output ./nuget-output /nologo /v:n + dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=${VERSION} --output ./nuget-output /nologo /v:n - name: Publish NuGet Package run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json From 29a39f0dde42935d4499bb027c1b83f016930525 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 18:18:31 +0200 Subject: [PATCH 51/94] one package per arch and system --- .github/workflows/publish-dotnet.yml | 4 ++-- languages/csharp/bitwardenSdk.csproj | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 810efac6e..78a43bc96 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -87,10 +87,10 @@ jobs: - name: Pack NuGet Package id: version env: - VERSION: 1.0.0 + VERSION: 1.0.1 run: | cd languages/csharp - dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=${VERSION} --output ./nuget-output /nologo /v:n + dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=${VERSION} -p:NugetVersion=1.6.1 --output ./nuget-output /nologo /v:n - name: Publish NuGet Package run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json diff --git a/languages/csharp/bitwardenSdk.csproj b/languages/csharp/bitwardenSdk.csproj index 334cd162b..0c87cd8d3 100644 --- a/languages/csharp/bitwardenSdk.csproj +++ b/languages/csharp/bitwardenSdk.csproj @@ -7,7 +7,7 @@ enable enable BitwardenSdk - TestPackageId + BitwardenSdk Bitwarden Sdk Bitwarden Inc. Bitwarden Sdk From dc677c0894d271a204119708ba31bc8716804ec9 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 18:44:54 +0200 Subject: [PATCH 52/94] one package per arch and system --- .github/workflows/build-dotnet.yml | 44 +--------------------------- .github/workflows/publish-dotnet.yml | 4 +-- 2 files changed, 3 insertions(+), 45 deletions(-) diff --git a/.github/workflows/build-dotnet.yml b/.github/workflows/build-dotnet.yml index 351d11e1d..5eca7f005 100644 --- a/.github/workflows/build-dotnet.yml +++ b/.github/workflows/build-dotnet.yml @@ -9,51 +9,9 @@ jobs: generate_schemas: uses: ./.github/workflows/generate_schemas.yml - build_rust: - name: Building ${{matrix.package}} for - ${{ matrix.os }} - - runs-on: ${{ matrix.settings.os || 'ubuntu-latest' }} - - strategy: - fail-fast: false - matrix: - os: - - macos-latest - - ubuntu-latest - - windows-latest - - package: - - bitwarden - - bitwarden-api-api - - bitwarden-api-identity - - steps: - - name: Checkout - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - - - name: Install rust - uses: dtolnay/rust-toolchain@f361669954a8ecfc00a3443f35f9ac8e610ffc06 # stable - with: - toolchain: stable - targets: ${{ matrix.settings.target }} - - - name: Cache cargo registry - uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 - - - name: Build - run: cargo build -p ${{ matrix.package }} --release - env: - RUSTFLAGS: "-D warnings" - - - name: Build Internal - if: ${{ matrix.package == 'bitwarden' }} - run: cargo build -p ${{ matrix.package }} --features internal --release - env: - RUSTFLAGS: "-D warnings" - build_dotnet: runs-on: ubuntu-22.04 - needs: [generate_schemas, build_rust] + needs: [generate_schemas] steps: - name: Checkout Repository diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 78a43bc96..de6210c0b 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -87,10 +87,10 @@ jobs: - name: Pack NuGet Package id: version env: - VERSION: 1.0.1 + VERSION: 1.0.2 run: | cd languages/csharp - dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=${VERSION} -p:NugetVersion=1.6.1 --output ./nuget-output /nologo /v:n + dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=${env.VERSION} --output ./nuget-output /nologo /v:n - name: Publish NuGet Package run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json From d469e1e72190b45b5d5a983269a1add25a76454a Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 21:24:06 +0200 Subject: [PATCH 53/94] one package per arch and system --- .github/workflows/publish-dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index de6210c0b..c980f651b 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -90,7 +90,7 @@ jobs: VERSION: 1.0.2 run: | cd languages/csharp - dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=${env.VERSION} --output ./nuget-output /nologo /v:n + dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=1.0.2 --output ./nuget-output /nologo /v:n - name: Publish NuGet Package run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json From ac1560814f760b93a90533f5b562612700fc76c8 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 21:55:32 +0200 Subject: [PATCH 54/94] one package per arch and system --- .github/workflows/publish-dotnet.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index c980f651b..0d87d6ba9 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -85,12 +85,27 @@ jobs: dotnet-version: "6.0.x" - name: Pack NuGet Package + if: matrix.os != 'windows-latest' id: version env: - VERSION: 1.0.2 + VERSION: 1.0.3 run: | cd languages/csharp - dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=1.0.2 --output ./nuget-output /nologo /v:n + dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=${VERSION} --output ./nuget-output /nologo /v:n - name: Publish NuGet Package + if: matrix.os != 'windows-latest' run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json + + - name: Pack NuGet Package + if: matrix.os == 'windows-latest' + id: version + env: + VERSION: 1.0.3 + run: | + cd languages/csharp + dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=$env:VERSION --output ./nuget-output /nologo /v:n + + - name: Publish NuGet Package + if: matrix.os == 'windows-latest' + run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k $env:NUGET_API_KEY -s https://api.nuget.org/v3/index.json From 08dfc1800c2d9fcdd45ddbe6bf6940e986210ed5 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 21:57:38 +0200 Subject: [PATCH 55/94] one package per arch and system --- .github/workflows/publish-dotnet.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 0d87d6ba9..a8b06e5fd 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -101,10 +101,10 @@ jobs: if: matrix.os == 'windows-latest' id: version env: - VERSION: 1.0.3 + DOTNET_VERSION: 1.0.3 run: | cd languages/csharp - dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=$env:VERSION --output ./nuget-output /nologo /v:n + dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=$env:DOTNET_VERSION --output ./nuget-output /nologo /v:n - name: Publish NuGet Package if: matrix.os == 'windows-latest' From 0e9140a521454a92fbe44202b8837b4f5e3d08d5 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 21:59:07 +0200 Subject: [PATCH 56/94] remove id --- .github/workflows/publish-dotnet.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index a8b06e5fd..71b43f6d5 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -86,7 +86,6 @@ jobs: - name: Pack NuGet Package if: matrix.os != 'windows-latest' - id: version env: VERSION: 1.0.3 run: | @@ -99,12 +98,11 @@ jobs: - name: Pack NuGet Package if: matrix.os == 'windows-latest' - id: version env: - DOTNET_VERSION: 1.0.3 + VERSION: 1.0.3 run: | cd languages/csharp - dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=$env:DOTNET_VERSION --output ./nuget-output /nologo /v:n + dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=$env:VERSION --output ./nuget-output /nologo /v:n - name: Publish NuGet Package if: matrix.os == 'windows-latest' From e8f50c8f900679dffcc219623c70dc726a576a98 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 22:31:07 +0200 Subject: [PATCH 57/94] remove id --- .github/workflows/publish-dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 71b43f6d5..8e2073bc7 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -106,4 +106,4 @@ jobs: - name: Publish NuGet Package if: matrix.os == 'windows-latest' - run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k $env:NUGET_API_KEY -s https://api.nuget.org/v3/index.json + run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k $env:NUGET_API_KEY --source https://api.nuget.org/v3/index.json From 12b5f378fb4a6340b664c136f18a5a15c0f905ce Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 22:32:24 +0200 Subject: [PATCH 58/94] api key --- .github/workflows/publish-dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 8e2073bc7..6d0698cdd 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -106,4 +106,4 @@ jobs: - name: Publish NuGet Package if: matrix.os == 'windows-latest' - run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k $env:NUGET_API_KEY --source https://api.nuget.org/v3/index.json + run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg --api-key $env:NUGET_API_KEY --source https://api.nuget.org/v3/index.json From 2c50b2e6bf9ffa1183371d1d25c29f285d018195 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 23:14:52 +0200 Subject: [PATCH 59/94] api key --- .github/workflows/publish-dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 6d0698cdd..3e1aeac9b 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -106,4 +106,4 @@ jobs: - name: Publish NuGet Package if: matrix.os == 'windows-latest' - run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg --api-key $env:NUGET_API_KEY --source https://api.nuget.org/v3/index.json + run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg --api-key $env:NUGET_API_KEY -Source https://api.nuget.org/v3/index.json From bed17fc87e9abf8ecd7697c21bd471e755654bb3 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 4 Sep 2023 23:24:18 +0200 Subject: [PATCH 60/94] api key --- .github/workflows/publish-dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 3e1aeac9b..71b43f6d5 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -106,4 +106,4 @@ jobs: - name: Publish NuGet Package if: matrix.os == 'windows-latest' - run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg --api-key $env:NUGET_API_KEY -Source https://api.nuget.org/v3/index.json + run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k $env:NUGET_API_KEY -s https://api.nuget.org/v3/index.json From 23cb857d284270c09af38bc8e070e0aa12ae00b5 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Tue, 5 Sep 2023 07:11:43 +0200 Subject: [PATCH 61/94] api key --- .github/workflows/publish-dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 71b43f6d5..8fdcac799 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -106,4 +106,4 @@ jobs: - name: Publish NuGet Package if: matrix.os == 'windows-latest' - run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k $env:NUGET_API_KEY -s https://api.nuget.org/v3/index.json + run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json From 93e54be383f85ec2ceaa78200150e1b0bafe3e9f Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Tue, 5 Sep 2023 07:33:21 +0200 Subject: [PATCH 62/94] open folder --- .github/workflows/publish-dotnet.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 8fdcac799..b0b551364 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -106,4 +106,6 @@ jobs: - name: Publish NuGet Package if: matrix.os == 'windows-latest' - run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json + run: | + cd languages/csharp/nuget-output + dotnet nuget push *.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json From ba976239e72d59fbe4e55ca31563ff3d1d5d161e Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Tue, 5 Sep 2023 08:06:39 +0200 Subject: [PATCH 63/94] final check --- .github/workflows/publish-dotnet.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index b0b551364..56c72b141 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -63,7 +63,7 @@ jobs: - name: Upload Artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: - name: libbitwarden_c_files + name: libbitwarden_c_files-${{ matrix.os }}-${{ matrix.arch }} path: | ${{ env.TARGET_FOLDER }}/*bitwarden_c* @@ -76,7 +76,7 @@ jobs: - name: Download libbitwarden_c_files files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files + name: libbitwarden_c_files-${{ matrix.os }}-${{ matrix.arch }} path: languages/csharp - name: Set up .NET Core @@ -87,7 +87,7 @@ jobs: - name: Pack NuGet Package if: matrix.os != 'windows-latest' env: - VERSION: 1.0.3 + VERSION: 1.0.4 run: | cd languages/csharp dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=${VERSION} --output ./nuget-output /nologo /v:n @@ -99,7 +99,7 @@ jobs: - name: Pack NuGet Package if: matrix.os == 'windows-latest' env: - VERSION: 1.0.3 + VERSION: 1.0.4 run: | cd languages/csharp dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=$env:VERSION --output ./nuget-output /nologo /v:n From 954762c5b46dad14800554d78bdd8b20831debad Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Tue, 5 Sep 2023 08:26:25 +0200 Subject: [PATCH 64/94] run just on demand --- .github/workflows/publish-dotnet.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 56c72b141..582c37b25 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -1,7 +1,10 @@ name: Deploy NuGet Package on: - pull_request: + workflow_dispatch: + version_number: + description: "New Version" + required: true jobs: generate_schemas: @@ -87,7 +90,7 @@ jobs: - name: Pack NuGet Package if: matrix.os != 'windows-latest' env: - VERSION: 1.0.4 + VERSION: ${{ github.event.inputs.version_number }} run: | cd languages/csharp dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=${VERSION} --output ./nuget-output /nologo /v:n @@ -99,7 +102,7 @@ jobs: - name: Pack NuGet Package if: matrix.os == 'windows-latest' env: - VERSION: 1.0.4 + VERSION: ${{ github.event.inputs.version_number }} run: | cd languages/csharp dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=$env:VERSION --output ./nuget-output /nologo /v:n From c459a7edc85bdc8886836636006115bc3cfa60e2 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Tue, 5 Sep 2023 08:30:20 +0200 Subject: [PATCH 65/94] use correct name --- .github/workflows/publish-dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 582c37b25..563f1b9d5 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -105,7 +105,7 @@ jobs: VERSION: ${{ github.event.inputs.version_number }} run: | cd languages/csharp - dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=$env:VERSION --output ./nuget-output /nologo /v:n + dotnet pack --configuration Release -p:PackageID=BitwardenSdk.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=$env:VERSION --output ./nuget-output /nologo /v:n - name: Publish NuGet Package if: matrix.os == 'windows-latest' From 9f31308dcb71ad488304bdfc790a6a681e609747 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Thu, 7 Sep 2023 15:39:15 +0200 Subject: [PATCH 66/94] pack all in one package --- .github/workflows/publish-dotnet.yml | 66 +++++++++++++++------------- languages/csharp/bitwardenSdk.csproj | 14 ++++-- 2 files changed, 47 insertions(+), 33 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 563f1b9d5..8781f79aa 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -1,16 +1,13 @@ name: Deploy NuGet Package on: - workflow_dispatch: - version_number: - description: "New Version" - required: true + pull_request: jobs: generate_schemas: uses: ./.github/workflows/generate_schemas.yml - build_and_deploy: + build_rust: strategy: fail-fast: false matrix: @@ -24,8 +21,6 @@ jobs: runs-on: ${{ matrix.os }} - needs: [generate_schemas] - name: Build for ${{ matrix.os }} ${{ matrix.arch }} steps: @@ -70,45 +65,56 @@ jobs: path: | ${{ env.TARGET_FOLDER }}/*bitwarden_c* + 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 - - name: Download libbitwarden_c_files files - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - with: - name: libbitwarden_c_files-${{ matrix.os }}-${{ matrix.arch }} - path: languages/csharp - - name: Set up .NET Core uses: actions/setup-dotnet@v3 with: dotnet-version: "6.0.x" - - name: Pack NuGet Package - if: matrix.os != 'windows-latest' - env: - VERSION: ${{ github.event.inputs.version_number }} - run: | - cd languages/csharp - dotnet pack --configuration Release -p:PackageID=TestSDK.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=${VERSION} --output ./nuget-output /nologo /v:n + - name: Download macos-latest-x64 files + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: libbitwarden_c_files-macos-latest-x64 + path: languages/csharp/macos-latest-x64 - - name: Publish NuGet Package - if: matrix.os != 'windows-latest' - run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json + - name: Download macos-latest-arm64 files + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: libbitwarden_c_files-macos-latest-arm64 + path: languages/csharp/macos-latest-arm64 + + - name: Download ubuntu-latest-x64 files + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: libbitwarden_c_files-ubuntu-latest-x64 + path: languages/csharp/ubuntu-latest-x64 + + - name: Download windows-latest-x64 files + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: libbitwarden_c_files-windows-latest-x64 + path: languages/csharp/windows-latest-x64 - name: Pack NuGet Package - if: matrix.os == 'windows-latest' env: - VERSION: ${{ github.event.inputs.version_number }} + VERSION: 1.0.5 run: | cd languages/csharp - dotnet pack --configuration Release -p:PackageID=BitwardenSdk.${{ matrix.os }}.${{ matrix.arch }} -p:Platform=${{ matrix.arch }} -p:Version=$env:VERSION --output ./nuget-output /nologo /v:n + dotnet pack --configuration Release -p:PackageID=TestSDK -p:Version=${VERSION} --output ./nuget-output /nologo /v:n - name: Publish NuGet Package - if: matrix.os == 'windows-latest' - run: | - cd languages/csharp/nuget-output - dotnet nuget push *.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json + run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json + diff --git a/languages/csharp/bitwardenSdk.csproj b/languages/csharp/bitwardenSdk.csproj index 0c87cd8d3..b8f29e4d9 100644 --- a/languages/csharp/bitwardenSdk.csproj +++ b/languages/csharp/bitwardenSdk.csproj @@ -47,17 +47,25 @@ - + Always true + runtimes/osx-x64/native - + Always true + runtimes/osx-arm/native - + Always true + runtimes/linux-x64/native + + + Always + true + runtimes/win-x64/native From 781d5fc048157038de84f17985b240d7bd2e0697 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Thu, 7 Sep 2023 16:27:33 +0200 Subject: [PATCH 67/94] fix lint --- .github/workflows/publish-dotnet.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 8781f79aa..ae7f574a4 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -117,4 +117,3 @@ jobs: - name: Publish NuGet Package run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json - From 76bb33faa7b05f1748e2a1f8505dd6dc85dc7bf4 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Thu, 7 Sep 2023 16:48:41 +0200 Subject: [PATCH 68/94] fix lint --- .github/workflows/publish-dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index ae7f574a4..dbb9b8022 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -113,7 +113,7 @@ jobs: VERSION: 1.0.5 run: | cd languages/csharp - dotnet pack --configuration Release -p:PackageID=TestSDK -p:Version=${VERSION} --output ./nuget-output /nologo /v:n + dotnet pack --configuration Release -p:PackageID=TestS -p:Version=${VERSION} --output ./nuget-output /nologo /v:n - name: Publish NuGet Package run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json From 9e7d717838fb21d14d910043baec030f9e88d323 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Thu, 7 Sep 2023 17:04:08 +0200 Subject: [PATCH 69/94] fix pk name --- .github/workflows/publish-dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index dbb9b8022..7c4f1fbb6 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -113,7 +113,7 @@ jobs: VERSION: 1.0.5 run: | cd languages/csharp - dotnet pack --configuration Release -p:PackageID=TestS -p:Version=${VERSION} --output ./nuget-output /nologo /v:n + dotnet pack --configuration Release -p:PackageID=BBSDK -p:Version=${VERSION} --output ./nuget-output /nologo /v:n - name: Publish NuGet Package run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json From 21249f36421353c1d16e0ec938281a1096591277 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Thu, 7 Sep 2023 19:15:02 +0200 Subject: [PATCH 70/94] use correct folder for arm arch --- .github/workflows/publish-dotnet.yml | 9 ++++++--- languages/csharp/bitwardenSdk.csproj | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 7c4f1fbb6..cc9e66bbd 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -1,7 +1,10 @@ name: Deploy NuGet Package on: - pull_request: + workflow_dispatch: + version_number: + description: "New Version" + required: true jobs: generate_schemas: @@ -110,10 +113,10 @@ jobs: - name: Pack NuGet Package env: - VERSION: 1.0.5 + VERSION: ${{ github.event.inputs.version_number }} run: | cd languages/csharp - dotnet pack --configuration Release -p:PackageID=BBSDK -p:Version=${VERSION} --output ./nuget-output /nologo /v:n + dotnet pack --configuration Release -p:PackageID=BitwardenSdk -p:Version=${VERSION} --output ./nuget-output /nologo /v:n - name: Publish NuGet Package run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json diff --git a/languages/csharp/bitwardenSdk.csproj b/languages/csharp/bitwardenSdk.csproj index b8f29e4d9..befa52a06 100644 --- a/languages/csharp/bitwardenSdk.csproj +++ b/languages/csharp/bitwardenSdk.csproj @@ -55,7 +55,7 @@ Always true - runtimes/osx-arm/native + runtimes/osx-arm64/native Always From b3ec3adb6f6911fc376690a129aeb909708ee482 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Fri, 8 Sep 2023 12:40:04 +0200 Subject: [PATCH 71/94] PR comments addressed --- .github/workflows/build-dotnet.yml | 4 ++-- .github/workflows/publish-dotnet.yml | 4 ++-- languages/csharp/{ => examples}/Program.cs | 0 languages/csharp/global.json | 6 ++++++ 4 files changed, 10 insertions(+), 4 deletions(-) rename languages/csharp/{ => examples}/Program.cs (100%) create mode 100644 languages/csharp/global.json diff --git a/.github/workflows/build-dotnet.yml b/.github/workflows/build-dotnet.yml index 5eca7f005..836eb099f 100644 --- a/.github/workflows/build-dotnet.yml +++ b/.github/workflows/build-dotnet.yml @@ -24,9 +24,9 @@ jobs: path: languages/csharp - name: Set up .NET Core - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0 with: - dotnet-version: "6.0.x" + global-json-file: languages/csharp/global.json - name: Build .NET 6 Project working-directory: languages/csharp diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index cc9e66bbd..0cb078ee3 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -83,9 +83,9 @@ jobs: path: languages/csharp - name: Set up .NET Core - uses: actions/setup-dotnet@v3 + uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0 with: - dotnet-version: "6.0.x" + global-json-file: languages/csharp/global.json - name: Download macos-latest-x64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 diff --git a/languages/csharp/Program.cs b/languages/csharp/examples/Program.cs similarity index 100% rename from languages/csharp/Program.cs rename to languages/csharp/examples/Program.cs diff --git a/languages/csharp/global.json b/languages/csharp/global.json new file mode 100644 index 000000000..527fd31d3 --- /dev/null +++ b/languages/csharp/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "version": "6.0.413", + "rollForward": "latestFeature" + } +} From cfd9297b8df679d3ab5145fd0a09428169be5769 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sat, 9 Sep 2023 13:15:44 +0200 Subject: [PATCH 72/94] use SafeHandleZeroOrMinusOneIsInvalid --- languages/csharp/BitwardenSafeHandle.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/languages/csharp/BitwardenSafeHandle.cs b/languages/csharp/BitwardenSafeHandle.cs index 2fe6cef2a..7e6c001b1 100644 --- a/languages/csharp/BitwardenSafeHandle.cs +++ b/languages/csharp/BitwardenSafeHandle.cs @@ -1,19 +1,14 @@ -using System.Runtime.InteropServices; +using Microsoft.Win32.SafeHandles; namespace Bitwarden.Sdk; -internal class BitwardenSafeHandle : SafeHandle +internal class BitwardenSafeHandle : SafeHandleZeroOrMinusOneIsInvalid { - public BitwardenSafeHandle() : base(IntPtr.Zero, true) + public BitwardenSafeHandle() : base(true) { SetHandle(handle); } - public override bool IsInvalid - { - get { return handle == IntPtr.Zero; } - } - protected override bool ReleaseHandle() { if (IsClosed) return false; From 178205766c0ecd0695c8e129b7da1d52d6ef2304 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Sat, 9 Sep 2023 19:17:31 +0200 Subject: [PATCH 73/94] removed ids --- languages/csharp/examples/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/languages/csharp/examples/Program.cs b/languages/csharp/examples/Program.cs index b78ab5759..b71a593f2 100644 --- a/languages/csharp/examples/Program.cs +++ b/languages/csharp/examples/Program.cs @@ -1,8 +1,8 @@ using Bitwarden.Sdk; -const string accessToken = "0.d37c384a-e70b-4239-bf2b-b06a0100efc8.1zxKrHPvHFzxaZ9XdI3UbUHu9jAvv2:MFWrA5ztEIJaKnKO2quJKw=="; -const string organizationIdStr = "dd06fcdd-2834-4b66-98b8-b06a00fd6051"; +const string accessToken = ""; +const string organizationIdStr = ""; using var bitwardenClient = new BitwardenClient(); var loginResponse = bitwardenClient.AccessTokenLogin(accessToken); From fa6fe0c095ab966d9bd1c9f2e0e73ca05a13bf8b Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 11 Sep 2023 21:36:14 +0200 Subject: [PATCH 74/94] address PR comments - changed AccessTokenLogin - replaced readme file - use Converter.Settings --- languages/csharp/BitwardenClient.cs | 7 +--- languages/csharp/CommandRunner.cs | 4 +- languages/csharp/README.md | 59 +++++++++++++++++++++++----- languages/csharp/bitwardenSdk.csproj | 5 ++- languages/csharp/docs/README.md | 58 --------------------------- 5 files changed, 57 insertions(+), 76 deletions(-) delete mode 100644 languages/csharp/docs/README.md diff --git a/languages/csharp/BitwardenClient.cs b/languages/csharp/BitwardenClient.cs index d90e89118..b29b7f8ce 100644 --- a/languages/csharp/BitwardenClient.cs +++ b/languages/csharp/BitwardenClient.cs @@ -25,12 +25,7 @@ public BitwardenClient(BitwardenSettings? settings = null) public ResponseForApiKeyLoginResponse? AccessTokenLogin(string accessToken) { - var command = new Command(); - var accessTokenLoginRequest = new AccessTokenLoginRequest - { - AccessToken = accessToken - }; - command.AccessTokenLogin = accessTokenLoginRequest; + var command = new Command() { AccessTokenLogin = new AccessTokenLoginRequest { AccessToken = accessToken } }; return _commandRunner.RunCommand(command); } diff --git a/languages/csharp/CommandRunner.cs b/languages/csharp/CommandRunner.cs index e78829750..d797e9ece 100644 --- a/languages/csharp/CommandRunner.cs +++ b/languages/csharp/CommandRunner.cs @@ -13,8 +13,8 @@ internal CommandRunner(BitwardenSafeHandle handle) internal T? RunCommand(Command command) { - var req = command.ToJson(); + var req = JsonSerializer.Serialize(command, Converter.Settings); var result = BitwardenLibrary.RunCommand(req, _handle); - return JsonSerializer.Deserialize(result); + return JsonSerializer.Deserialize(result, Converter.Settings); } } diff --git a/languages/csharp/README.md b/languages/csharp/README.md index 199acaab8..1d2509d7a 100644 --- a/languages/csharp/README.md +++ b/languages/csharp/README.md @@ -1,17 +1,58 @@ -# Requirements +# Bitwarden .NET SDK -- Dotnet 6 +The Bitwarden SDK (Software Development Kit) is a set of programming tools, libraries, and resources provided by Bitwarden for developers to integrate Bitwarden's password management and security capabilities into their own applications, services, or platforms. The SDK facilitates the seamless integration of Bitwarden's functionality into third-party software, enabling users to securely manage their passwords, credentials, and sensitive information across various digital environments. -# Installation +## Create access token +- to create access token go to [access-tokens help page] -From the `languages/csharp/` directory, +## Usage code snippets -```bash -dotnet restore +### Create new Bitwarden client +``` +const string accessToken = ""; +using var bitwardenClient = new BitwardenClient(); +var loginResponse = bitwardenClient.AccessTokenLogin(accessToken); +``` + +### Create new project +- Organization is created in the UI +``` +const string organizationIdStr = ""; +var organizationId = Guid.Parse(organizationIdStr); +var responseForProjectResponse = bitwardenClient.Projects().Create(organizationId, "TestProject"); +``` + +### List all projects +``` +var response = bitwardenClient.Projects().List(organizationId); +``` + +### Update project +``` +var projectId = responseForProjectResponse.Data.Id; +responseForProjectResponse = bitwardenClient.Projects().Get(projectId); +responseForProjectResponse = bitwardenClient.Projects().Update(projectId, organizationId, "TestProjectUpdated"); ``` -# Run +### Add new secret +``` +var key = "key"; +var value = "value"; +var note = "note"; +var responseForSecretResponse = bitwardenClient.Secrets().Create(key, value, note, organizationId, new Guid[]{projectId}); +var secretId = responseForSecretResponse.Data.Id; +``` -```bash -dotnet run +### List secrets ``` +var responseForSecretIdentifiersResponse = bitwardenClient.Secrets().List(organizationId); +``` + +# Delete secret or project + +``` +var responseForSecretsDeleteResponse = bitwardenClient.Secrets().Delete(new Guid[]{secretId}); +var responseForProjectsDeleteResponse = bitwardenClient.Projects().Delete(new Guid[]{projectId}); +``` + +[access-tokens help page]: https://bitwarden.com/help/access-tokens/ diff --git a/languages/csharp/bitwardenSdk.csproj b/languages/csharp/bitwardenSdk.csproj index 5354142f3..6bb463791 100644 --- a/languages/csharp/bitwardenSdk.csproj +++ b/languages/csharp/bitwardenSdk.csproj @@ -23,7 +23,10 @@ - + + true + / + diff --git a/languages/csharp/docs/README.md b/languages/csharp/docs/README.md deleted file mode 100644 index 1d2509d7a..000000000 --- a/languages/csharp/docs/README.md +++ /dev/null @@ -1,58 +0,0 @@ -# Bitwarden .NET SDK - -The Bitwarden SDK (Software Development Kit) is a set of programming tools, libraries, and resources provided by Bitwarden for developers to integrate Bitwarden's password management and security capabilities into their own applications, services, or platforms. The SDK facilitates the seamless integration of Bitwarden's functionality into third-party software, enabling users to securely manage their passwords, credentials, and sensitive information across various digital environments. - -## Create access token -- to create access token go to [access-tokens help page] - -## Usage code snippets - -### Create new Bitwarden client -``` -const string accessToken = ""; -using var bitwardenClient = new BitwardenClient(); -var loginResponse = bitwardenClient.AccessTokenLogin(accessToken); -``` - -### Create new project -- Organization is created in the UI -``` -const string organizationIdStr = ""; -var organizationId = Guid.Parse(organizationIdStr); -var responseForProjectResponse = bitwardenClient.Projects().Create(organizationId, "TestProject"); -``` - -### List all projects -``` -var response = bitwardenClient.Projects().List(organizationId); -``` - -### Update project -``` -var projectId = responseForProjectResponse.Data.Id; -responseForProjectResponse = bitwardenClient.Projects().Get(projectId); -responseForProjectResponse = bitwardenClient.Projects().Update(projectId, organizationId, "TestProjectUpdated"); -``` - -### Add new secret -``` -var key = "key"; -var value = "value"; -var note = "note"; -var responseForSecretResponse = bitwardenClient.Secrets().Create(key, value, note, organizationId, new Guid[]{projectId}); -var secretId = responseForSecretResponse.Data.Id; -``` - -### List secrets -``` -var responseForSecretIdentifiersResponse = bitwardenClient.Secrets().List(organizationId); -``` - -# Delete secret or project - -``` -var responseForSecretsDeleteResponse = bitwardenClient.Secrets().Delete(new Guid[]{secretId}); -var responseForProjectsDeleteResponse = bitwardenClient.Projects().Delete(new Guid[]{projectId}); -``` - -[access-tokens help page]: https://bitwarden.com/help/access-tokens/ From b00d525f338c7b4817cb8736b2f3708dfa8133a0 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 11 Sep 2023 23:11:35 +0200 Subject: [PATCH 75/94] change solution structure --- .github/workflows/build-dotnet.yml | 12 +-- .github/workflows/publish-dotnet.yml | 14 ++-- .gitignore | 2 +- .vscode/launch.json | 2 +- .vscode/tasks.json | 2 +- .../Bitwarden.Sdk.Samples.csproj | 14 ++++ .../Program.cs | 4 +- .../csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj | 71 +++++++++++++++++ .../{ => Bitwarden.Sdk}/BitwardenClient.cs | 1 - .../{ => Bitwarden.Sdk}/BitwardenLibrary.cs | 0 .../BitwardenSafeHandle.cs | 1 - .../{ => Bitwarden.Sdk}/BitwardenSettings.cs | 0 .../{ => Bitwarden.Sdk}/CommandRunner.cs | 0 .../{ => Bitwarden.Sdk}/ProjectsClient.cs | 4 +- .../csharp/{ => Bitwarden.Sdk}/README.md | 0 .../{ => Bitwarden.Sdk}/SecretsClient.cs | 0 .../csharp/{ => Bitwarden.Sdk}/bitwarden.png | Bin languages/csharp/Bitwarden.sln | 22 +++++ languages/csharp/bitwardenSdk.csproj | 75 ------------------ support/scripts/schemas.ts | 2 +- 20 files changed, 129 insertions(+), 97 deletions(-) create mode 100644 languages/csharp/Bitwarden.Sdk.Samples/Bitwarden.Sdk.Samples.csproj rename languages/csharp/{examples => Bitwarden.Sdk.Samples}/Program.cs (90%) create mode 100644 languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj rename languages/csharp/{ => Bitwarden.Sdk}/BitwardenClient.cs (97%) rename languages/csharp/{ => Bitwarden.Sdk}/BitwardenLibrary.cs (100%) rename languages/csharp/{ => Bitwarden.Sdk}/BitwardenSafeHandle.cs (90%) rename languages/csharp/{ => Bitwarden.Sdk}/BitwardenSettings.cs (100%) rename languages/csharp/{ => Bitwarden.Sdk}/CommandRunner.cs (100%) rename languages/csharp/{ => Bitwarden.Sdk}/ProjectsClient.cs (98%) rename languages/csharp/{ => Bitwarden.Sdk}/README.md (100%) rename languages/csharp/{ => Bitwarden.Sdk}/SecretsClient.cs (100%) rename languages/csharp/{ => Bitwarden.Sdk}/bitwarden.png (100%) create mode 100644 languages/csharp/Bitwarden.sln delete mode 100644 languages/csharp/bitwardenSdk.csproj diff --git a/.github/workflows/build-dotnet.yml b/.github/workflows/build-dotnet.yml index df88cc133..debf57c90 100644 --- a/.github/workflows/build-dotnet.yml +++ b/.github/workflows/build-dotnet.yml @@ -24,7 +24,7 @@ jobs: uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: name: schemas.cs - path: languages/csharp + path: languages/csharp/Bitwarden.Sdk - name: Set up .NET Core uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0 @@ -35,28 +35,28 @@ jobs: uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: name: libbitwarden_c_files-macos-latest-x64 - path: languages/csharp/macos-latest-x64 + path: languages/csharp/Bitwarden.Sdk/macos-latest-x64 - name: Download macos-latest-arm64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: name: libbitwarden_c_files-macos-latest-arm64 - path: languages/csharp/macos-latest-arm64 + path: languages/csharp/Bitwarden.Sdk/macos-latest-arm64 - name: Download ubuntu-latest-x64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: name: libbitwarden_c_files-ubuntu-latest-x64 - path: languages/csharp/ubuntu-latest-x64 + path: languages/csharp/Bitwarden.Sdk/ubuntu-latest-x64 - name: Download windows-latest-x64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: name: libbitwarden_c_files-windows-latest-x64 - path: languages/csharp/windows-latest-x64 + path: languages/csharp/Bitwarden.Sdk/windows-latest-x64 - name: Build .NET 6 Project - working-directory: languages/csharp + working-directory: languages/csharp/Bitwarden.Sdk run: | dotnet restore dotnet build --configuration Release diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index d615f4984..73cca7b8c 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -25,7 +25,7 @@ jobs: uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: name: schemas.cs - path: languages/csharp + path: languages/csharp/Bitwarden.Sdk - name: Set up .NET Core uses: actions/setup-dotnet@3447fd6a9f9e57506b15f895c5b76d3b197dc7c2 # v3.2.0 @@ -36,32 +36,32 @@ jobs: uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: name: libbitwarden_c_files-macos-latest-x64 - path: languages/csharp/macos-latest-x64 + path: languages/csharp/Bitwarden.Sdk/macos-latest-x64 - name: Download macos-latest-arm64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: name: libbitwarden_c_files-macos-latest-arm64 - path: languages/csharp/macos-latest-arm64 + path: languages/csharp/Bitwarden.Sdk/macos-latest-arm64 - name: Download ubuntu-latest-x64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: name: libbitwarden_c_files-ubuntu-latest-x64 - path: languages/csharp/ubuntu-latest-x64 + path: languages/csharp/Bitwarden.Sdk/ubuntu-latest-x64 - name: Download windows-latest-x64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: name: libbitwarden_c_files-windows-latest-x64 - path: languages/csharp/windows-latest-x64 + path: languages/csharp/Bitwarden.Sdk/windows-latest-x64 - name: Pack NuGet Package env: VERSION: ${{ github.event.inputs.version_number }} run: | - cd languages/csharp + cd languages/csharp/Bitwarden.Sdk dotnet pack --configuration Release -p:PackageID=BitwardenSdk -p:Version=${VERSION} --output ./nuget-output /nologo /v:n - name: Publish NuGet Package - run: dotnet nuget push ./languages/csharp/nuget-output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json + run: dotnet nuget push ./languages/csharp/Bitwarden.Sdk/nuget-output/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json diff --git a/.gitignore b/.gitignore index 9e450f9ab..3f459493b 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/.vscode/launch.json b/.vscode/launch.json index cb99bc8e0..7da474a22 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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" diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 491d770c9..55dc10eb2 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -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" ], diff --git a/languages/csharp/Bitwarden.Sdk.Samples/Bitwarden.Sdk.Samples.csproj b/languages/csharp/Bitwarden.Sdk.Samples/Bitwarden.Sdk.Samples.csproj new file mode 100644 index 000000000..5b189d8ca --- /dev/null +++ b/languages/csharp/Bitwarden.Sdk.Samples/Bitwarden.Sdk.Samples.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + diff --git a/languages/csharp/examples/Program.cs b/languages/csharp/Bitwarden.Sdk.Samples/Program.cs similarity index 90% rename from languages/csharp/examples/Program.cs rename to languages/csharp/Bitwarden.Sdk.Samples/Program.cs index b71a593f2..7bb2e91b0 100644 --- a/languages/csharp/examples/Program.cs +++ b/languages/csharp/Bitwarden.Sdk.Samples/Program.cs @@ -1,8 +1,8 @@ using Bitwarden.Sdk; -const string accessToken = ""; -const string organizationIdStr = ""; +var accessToken = Environment.GetEnvironmentVariable("ACCESS_TOKEN"); +var organizationIdStr = Environment.GetEnvironmentVariable("ORGANIZATION_ID"); using var bitwardenClient = new BitwardenClient(); var loginResponse = bitwardenClient.AccessTokenLogin(accessToken); diff --git a/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj b/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj new file mode 100644 index 000000000..f7def3963 --- /dev/null +++ b/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj @@ -0,0 +1,71 @@ + + + + net6.0 + README.md + enable + enable + BitwardenSdk + BitwardenSdk + Bitwarden Sdk + Bitwarden Inc. + Bitwarden Sdk + Bitwarden Inc. + https://github.com/bitwarden/sdk/tree/master/languages/csharp + Bitwarden;Sdk;.NET + BitwardenSdk + bitwarden.png + Git + Bitwarden.Sdk + + + + + + + + + + + + + + 4 + + + + Always + true + + + Always + true + + + Always + true + + + + + Always + true + runtimes/osx-x64/native + + + Always + true + runtimes/osx-arm64/native + + + Always + true + runtimes/linux-x64/native + + + Always + true + runtimes/win-x64/native + + + diff --git a/languages/csharp/BitwardenClient.cs b/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs similarity index 97% rename from languages/csharp/BitwardenClient.cs rename to languages/csharp/Bitwarden.Sdk/BitwardenClient.cs index b29b7f8ce..48ed225c9 100644 --- a/languages/csharp/BitwardenClient.cs +++ b/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs @@ -41,7 +41,6 @@ public SecretsClient Secrets() public void Dispose() { - BitwardenLibrary.FreeMemory(_handle); _handle.Dispose(); } } diff --git a/languages/csharp/BitwardenLibrary.cs b/languages/csharp/Bitwarden.Sdk/BitwardenLibrary.cs similarity index 100% rename from languages/csharp/BitwardenLibrary.cs rename to languages/csharp/Bitwarden.Sdk/BitwardenLibrary.cs diff --git a/languages/csharp/BitwardenSafeHandle.cs b/languages/csharp/Bitwarden.Sdk/BitwardenSafeHandle.cs similarity index 90% rename from languages/csharp/BitwardenSafeHandle.cs rename to languages/csharp/Bitwarden.Sdk/BitwardenSafeHandle.cs index 7e6c001b1..e39216377 100644 --- a/languages/csharp/BitwardenSafeHandle.cs +++ b/languages/csharp/Bitwarden.Sdk/BitwardenSafeHandle.cs @@ -11,7 +11,6 @@ public BitwardenSafeHandle() : base(true) protected override bool ReleaseHandle() { - if (IsClosed) return false; BitwardenLibrary.FreeMemory(this); return true; } diff --git a/languages/csharp/BitwardenSettings.cs b/languages/csharp/Bitwarden.Sdk/BitwardenSettings.cs similarity index 100% rename from languages/csharp/BitwardenSettings.cs rename to languages/csharp/Bitwarden.Sdk/BitwardenSettings.cs diff --git a/languages/csharp/CommandRunner.cs b/languages/csharp/Bitwarden.Sdk/CommandRunner.cs similarity index 100% rename from languages/csharp/CommandRunner.cs rename to languages/csharp/Bitwarden.Sdk/CommandRunner.cs diff --git a/languages/csharp/ProjectsClient.cs b/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs similarity index 98% rename from languages/csharp/ProjectsClient.cs rename to languages/csharp/Bitwarden.Sdk/ProjectsClient.cs index 34b990be7..a21348827 100644 --- a/languages/csharp/ProjectsClient.cs +++ b/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs @@ -1,4 +1,6 @@ -namespace Bitwarden.Sdk; +using System; + +namespace Bitwarden.Sdk; public class ProjectsClient diff --git a/languages/csharp/README.md b/languages/csharp/Bitwarden.Sdk/README.md similarity index 100% rename from languages/csharp/README.md rename to languages/csharp/Bitwarden.Sdk/README.md diff --git a/languages/csharp/SecretsClient.cs b/languages/csharp/Bitwarden.Sdk/SecretsClient.cs similarity index 100% rename from languages/csharp/SecretsClient.cs rename to languages/csharp/Bitwarden.Sdk/SecretsClient.cs diff --git a/languages/csharp/bitwarden.png b/languages/csharp/Bitwarden.Sdk/bitwarden.png similarity index 100% rename from languages/csharp/bitwarden.png rename to languages/csharp/Bitwarden.Sdk/bitwarden.png diff --git a/languages/csharp/Bitwarden.sln b/languages/csharp/Bitwarden.sln new file mode 100644 index 000000000..4cf8d147f --- /dev/null +++ b/languages/csharp/Bitwarden.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bitwarden.Sdk", "Bitwarden.Sdk\Bitwarden.Sdk.csproj", "{DADE59E5-E573-430A-8EB2-BC21D8E8C1D3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bitwarden.Sdk.Samples", "Bitwarden.Sdk.Samples\Bitwarden.Sdk.Samples.csproj", "{CA9F8EDC-643F-4624-AC00-F741E1F30CA4}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {DADE59E5-E573-430A-8EB2-BC21D8E8C1D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DADE59E5-E573-430A-8EB2-BC21D8E8C1D3}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DADE59E5-E573-430A-8EB2-BC21D8E8C1D3}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DADE59E5-E573-430A-8EB2-BC21D8E8C1D3}.Release|Any CPU.Build.0 = Release|Any CPU + {CA9F8EDC-643F-4624-AC00-F741E1F30CA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CA9F8EDC-643F-4624-AC00-F741E1F30CA4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CA9F8EDC-643F-4624-AC00-F741E1F30CA4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CA9F8EDC-643F-4624-AC00-F741E1F30CA4}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/languages/csharp/bitwardenSdk.csproj b/languages/csharp/bitwardenSdk.csproj deleted file mode 100644 index 6bb463791..000000000 --- a/languages/csharp/bitwardenSdk.csproj +++ /dev/null @@ -1,75 +0,0 @@ - - - - Exe - net6.0 - README.md - enable - enable - BitwardenSdk - BitwardenSdk - Bitwarden Sdk - Bitwarden Inc. - Bitwarden Sdk - Bitwarden Inc. - https://github.com/bitwarden/sdk/tree/master/languages/csharp - Bitwarden;Sdk;.NET - BitwardenSdk - bitwarden.png - Git - Bitwarden.Sdk - - - - - - - true - / - - - - - - - - - 4 - - - - Always - true - - - Always - true - - - Always - true - - - - - Always - true - runtimes/osx-x64/native - - - Always - true - runtimes/osx-arm64/native - - - Always - true - runtimes/linux-x64/native - - - Always - true - runtimes/win-x64/native - - - diff --git a/support/scripts/schemas.ts b/support/scripts/schemas.ts index e08661017..148b089e6 100644 --- a/support/scripts/schemas.ts +++ b/support/scripts/schemas.ts @@ -62,7 +62,7 @@ async function main() { }, }); - writeToFile("./languages/csharp/schemas.cs", csharp.lines); + writeToFile("./languages/csharp/Bitwarden.Sdk/schemas.cs", csharp.lines); } main(); From f043f86cff1f48459726d0c9616d7b09aef8bd52 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 11 Sep 2023 23:21:19 +0200 Subject: [PATCH 76/94] fix path for generating schemas --- .github/workflows/generate_schemas.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/generate_schemas.yml b/.github/workflows/generate_schemas.yml index 98eb2ce9c..a3829dccb 100644 --- a/.github/workflows/generate_schemas.yml +++ b/.github/workflows/generate_schemas.yml @@ -47,7 +47,7 @@ jobs: uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 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 From 0e9d50278111ed367ae54de4f60016c0b3ed2e91 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 11 Sep 2023 23:40:05 +0200 Subject: [PATCH 77/94] pack NuGet and upload artifact --- .github/workflows/build-dotnet.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/build-dotnet.yml b/.github/workflows/build-dotnet.yml index debf57c90..81c94926d 100644 --- a/.github/workflows/build-dotnet.yml +++ b/.github/workflows/build-dotnet.yml @@ -60,3 +60,17 @@ jobs: run: | dotnet restore dotnet build --configuration Release + + - name: Pack NuGet Package + env: + VERSION: 0.0.1 + run: | + cd languages/csharp/Bitwarden.Sdk + dotnet pack --configuration Release -p:PackageID=BitwardenSdk -p:Version=${VERSION} --output ./nuget-output /nologo /v:n + + - name: Upload NuGet package + uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 + with: + name: BitwardenSdk.0.0.1.nupkg + path: | + ./languages/csharp/Bitwarden.Sdk/nuget-output/*.nupkg From e6180798a65725975e74b88a9cfa7561dac557cb Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Tue, 12 Sep 2023 09:54:29 +0200 Subject: [PATCH 78/94] change the way rust is build --- .github/workflows/build-dotnet.yml | 36 +++++++---- .../workflows/build-rust-cross-platform.yml | 61 +++++++++++-------- .github/workflows/publish-dotnet.yml | 36 +++++++---- .../csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj | 18 ++++-- 4 files changed, 97 insertions(+), 54 deletions(-) diff --git a/.github/workflows/build-dotnet.yml b/.github/workflows/build-dotnet.yml index 81c94926d..13930ac32 100644 --- a/.github/workflows/build-dotnet.yml +++ b/.github/workflows/build-dotnet.yml @@ -31,29 +31,41 @@ jobs: with: global-json-file: languages/csharp/global.json - - name: Download macos-latest-x64 files + - name: Download macos-x64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files-macos-latest-x64 - path: languages/csharp/Bitwarden.Sdk/macos-latest-x64 + name: libbitwarden_c_files-macos-x64 + path: languages/csharp/Bitwarden.Sdk/macos-x64 - - name: Download macos-latest-arm64 files + - name: Download macos-arm64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files-macos-latest-arm64 - path: languages/csharp/Bitwarden.Sdk/macos-latest-arm64 + name: libbitwarden_c_files-macos-arm64 + path: languages/csharp/Bitwarden.Sdk/macos-arm64 - - name: Download ubuntu-latest-x64 files + - name: Download ubuntu-arm64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files-ubuntu-latest-x64 - path: languages/csharp/Bitwarden.Sdk/ubuntu-latest-x64 + name: libbitwarden_c_files-ubuntu-arm64 + path: languages/csharp/Bitwarden.Sdk/ubuntu-arm64 - - name: Download windows-latest-x64 files + - name: Download ubuntu-x64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files-windows-latest-x64 - path: languages/csharp/Bitwarden.Sdk/windows-latest-x64 + name: libbitwarden_c_files-ubuntu-x64 + path: languages/csharp/Bitwarden.Sdk/ubuntu-x64 + + - name: Download windows-arm64 files + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: libbitwarden_c_files-windows-arm64 + path: languages/csharp/Bitwarden.Sdk/windows-arm64 + + - name: Download windows-x64 files + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: libbitwarden_c_files-windows-x64 + path: languages/csharp/Bitwarden.Sdk/windows-x64 - name: Build .NET 6 Project working-directory: languages/csharp/Bitwarden.Sdk diff --git a/.github/workflows/build-rust-cross-platform.yml b/.github/workflows/build-rust-cross-platform.yml index f6bdb79a5..b331697de 100644 --- a/.github/workflows/build-rust-cross-platform.yml +++ b/.github/workflows/build-rust-cross-platform.yml @@ -8,17 +8,40 @@ jobs: strategy: fail-fast: false matrix: - os: [macos-latest, ubuntu-latest, windows-latest] - arch: [x64, arm64] - exclude: - - os: windows-latest + settings: + - os: macos-12 + target: x86_64-apple-darwin + arch: x64 + folder_name: macos-x64 + + - os: macos-12 + target: aarch64-apple-darwin arch: arm64 - - os: ubuntu-latest + folder_name: macos-arm64 + + - os: windows-2022 + target: x86_64-pc-windows-msvc + arch: x64 + folder_name: windows-x64 + + - os: windows-2022 + target: aarch64-pc-windows-msvc arch: arm64 + folder_name: windows-arm64 - runs-on: ${{ matrix.os }} + - os: ubuntu-22.04 + target: x86_64-unknown-linux-gnu + arch: x64 + folder_name: ubuntu-x64 - name: Build for ${{ matrix.os }} ${{ matrix.arch }} + - os: ubuntu-22.04 + target: aarch64-unknown-linux-gnu + arch: arm64 + folder_name: ubuntu-arm64 + + runs-on: ${{ matrix.settings.os }} + + name: Build for ${{ matrix.settings.os }} ${{ matrix.settings.target }} steps: - name: Checkout @@ -32,32 +55,18 @@ jobs: - name: Cache cargo registry uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 - - name: Set build architecture, ios, linux - if: matrix.os != 'windows-latest' - run: | - if [[ "${{ matrix.arch }}" == "x64" ]]; then - echo "TARGET_ARCH=" >> $GITHUB_ENV - echo "TARGET_FOLDER=target/release/" >> $GITHUB_ENV - elif [[ "${{ matrix.arch }}" == "arm64" ]]; then - echo "TARGET_ARCH=--target aarch64-apple-darwin" >> $GITHUB_ENV - echo "TARGET_FOLDER=target/aarch64-apple-darwin/release/" >> $GITHUB_ENV - rustup target add aarch64-apple-darwin - fi - - - name: Set build architecture, windows - if: matrix.os == 'windows-latest' + - name: Add build architecture run: | - echo "TARGET_ARCH=" | Out-File -FilePath $env:GITHUB_ENV - echo "TARGET_FOLDER=target/release/" | Out-File -FilePath $env:GITHUB_ENV + rustup target add ${{ matrix.settings.target }} - name: Build Rust - run: cargo build ${{ env.TARGET_ARCH }} --release + run: cargo build ${{ matrix.settings.target }} --release env: RUSTFLAGS: "-D warnings" - name: Upload Artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: - name: libbitwarden_c_files-${{ matrix.os }}-${{ matrix.arch }} + name: libbitwarden_c_files-${{ matrix.settings.folder_name }} path: | - ${{ env.TARGET_FOLDER }}/*bitwarden_c* + target/${{ matrix.settings.target }}/release/*bitwarden_c* diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 73cca7b8c..c74b53b1e 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -32,29 +32,41 @@ jobs: with: global-json-file: languages/csharp/global.json - - name: Download macos-latest-x64 files + - name: Download macos-x64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files-macos-latest-x64 - path: languages/csharp/Bitwarden.Sdk/macos-latest-x64 + name: libbitwarden_c_files-macos-x64 + path: languages/csharp/Bitwarden.Sdk/macos-x64 - - name: Download macos-latest-arm64 files + - name: Download macos-arm64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files-macos-latest-arm64 - path: languages/csharp/Bitwarden.Sdk/macos-latest-arm64 + name: libbitwarden_c_files-macos-arm64 + path: languages/csharp/Bitwarden.Sdk/macos-arm64 - - name: Download ubuntu-latest-x64 files + - name: Download ubuntu-arm64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files-ubuntu-latest-x64 - path: languages/csharp/Bitwarden.Sdk/ubuntu-latest-x64 + name: libbitwarden_c_files-ubuntu-arm64 + path: languages/csharp/Bitwarden.Sdk/ubuntu-arm64 - - name: Download windows-latest-x64 files + - name: Download ubuntu-x64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files-windows-latest-x64 - path: languages/csharp/Bitwarden.Sdk/windows-latest-x64 + name: libbitwarden_c_files-ubuntu-x64 + path: languages/csharp/Bitwarden.Sdk/ubuntu-x64 + + - name: Download windows-arm64 files + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: libbitwarden_c_files-windows-arm64 + path: languages/csharp/Bitwarden.Sdk/windows-arm64 + + - name: Download windows-x64 files + uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 + with: + name: libbitwarden_c_files-windows-x64 + path: languages/csharp/Bitwarden.Sdk/windows-x64 - name: Pack NuGet Package env: diff --git a/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj b/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj index f7def3963..f29759dcd 100644 --- a/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj +++ b/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj @@ -47,25 +47,35 @@ - + Always true runtimes/osx-x64/native - + Always true runtimes/osx-arm64/native - + Always true runtimes/linux-x64/native - + + Always + true + runtimes/linux-arm64/native + + Always true runtimes/win-x64/native + + Always + true + runtimes/win-arm64/native + From badbd79eef14c78e64e6c429105dd6ae0e47943a Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Tue, 12 Sep 2023 09:58:13 +0200 Subject: [PATCH 79/94] forgot --target --- .github/workflows/build-rust-cross-platform.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-rust-cross-platform.yml b/.github/workflows/build-rust-cross-platform.yml index b331697de..3116d7932 100644 --- a/.github/workflows/build-rust-cross-platform.yml +++ b/.github/workflows/build-rust-cross-platform.yml @@ -60,7 +60,7 @@ jobs: rustup target add ${{ matrix.settings.target }} - name: Build Rust - run: cargo build ${{ matrix.settings.target }} --release + run: cargo build --target ${{ matrix.settings.target }} --release env: RUSTFLAGS: "-D warnings" From d084c6efaa41b7b637dac415f436422570193939 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Tue, 12 Sep 2023 11:05:17 +0200 Subject: [PATCH 80/94] remove after error building OpenSSL --- .github/workflows/build-dotnet.yml | 12 ------------ .github/workflows/build-rust-cross-platform.yml | 10 ---------- .github/workflows/publish-dotnet.yml | 12 ------------ languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj | 10 ---------- 4 files changed, 44 deletions(-) diff --git a/.github/workflows/build-dotnet.yml b/.github/workflows/build-dotnet.yml index 13930ac32..9878e18ee 100644 --- a/.github/workflows/build-dotnet.yml +++ b/.github/workflows/build-dotnet.yml @@ -43,24 +43,12 @@ jobs: name: libbitwarden_c_files-macos-arm64 path: languages/csharp/Bitwarden.Sdk/macos-arm64 - - name: Download ubuntu-arm64 files - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - with: - name: libbitwarden_c_files-ubuntu-arm64 - path: languages/csharp/Bitwarden.Sdk/ubuntu-arm64 - - name: Download ubuntu-x64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: name: libbitwarden_c_files-ubuntu-x64 path: languages/csharp/Bitwarden.Sdk/ubuntu-x64 - - name: Download windows-arm64 files - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - with: - name: libbitwarden_c_files-windows-arm64 - path: languages/csharp/Bitwarden.Sdk/windows-arm64 - - name: Download windows-x64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: diff --git a/.github/workflows/build-rust-cross-platform.yml b/.github/workflows/build-rust-cross-platform.yml index 3116d7932..5bc26bd11 100644 --- a/.github/workflows/build-rust-cross-platform.yml +++ b/.github/workflows/build-rust-cross-platform.yml @@ -24,21 +24,11 @@ jobs: arch: x64 folder_name: windows-x64 - - os: windows-2022 - target: aarch64-pc-windows-msvc - arch: arm64 - folder_name: windows-arm64 - - os: ubuntu-22.04 target: x86_64-unknown-linux-gnu arch: x64 folder_name: ubuntu-x64 - - os: ubuntu-22.04 - target: aarch64-unknown-linux-gnu - arch: arm64 - folder_name: ubuntu-arm64 - runs-on: ${{ matrix.settings.os }} name: Build for ${{ matrix.settings.os }} ${{ matrix.settings.target }} diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index c74b53b1e..22c9b439a 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -44,24 +44,12 @@ jobs: name: libbitwarden_c_files-macos-arm64 path: languages/csharp/Bitwarden.Sdk/macos-arm64 - - name: Download ubuntu-arm64 files - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - with: - name: libbitwarden_c_files-ubuntu-arm64 - path: languages/csharp/Bitwarden.Sdk/ubuntu-arm64 - - name: Download ubuntu-x64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: name: libbitwarden_c_files-ubuntu-x64 path: languages/csharp/Bitwarden.Sdk/ubuntu-x64 - - name: Download windows-arm64 files - uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 - with: - name: libbitwarden_c_files-windows-arm64 - path: languages/csharp/Bitwarden.Sdk/windows-arm64 - - name: Download windows-x64 files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: diff --git a/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj b/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj index f29759dcd..0e91c8cb6 100644 --- a/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj +++ b/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj @@ -62,20 +62,10 @@ true runtimes/linux-x64/native - - Always - true - runtimes/linux-arm64/native - Always true runtimes/win-x64/native - - Always - true - runtimes/win-arm64/native - From 48d04f5100b7f27cc08de3c35a3c1cc877390054 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Tue, 12 Sep 2023 22:26:40 +0200 Subject: [PATCH 81/94] use IntPtr to free memory --- languages/csharp/Bitwarden.Sdk/BitwardenLibrary.cs | 7 ++++--- languages/csharp/Bitwarden.Sdk/BitwardenSafeHandle.cs | 2 +- languages/csharp/Bitwarden.Sdk/ProjectsClient.cs | 4 +--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/languages/csharp/Bitwarden.Sdk/BitwardenLibrary.cs b/languages/csharp/Bitwarden.Sdk/BitwardenLibrary.cs index ce9eb6f6f..76a35ed5b 100644 --- a/languages/csharp/Bitwarden.Sdk/BitwardenLibrary.cs +++ b/languages/csharp/Bitwarden.Sdk/BitwardenLibrary.cs @@ -1,4 +1,5 @@ -using System.Runtime.InteropServices; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; namespace Bitwarden.Sdk; @@ -8,7 +9,7 @@ internal static class BitwardenLibrary private static extern BitwardenSafeHandle init(string settings); [DllImport("bitwarden_c", CallingConvention = CallingConvention.Cdecl)] - private static extern void free_mem(BitwardenSafeHandle handle); + private static extern void free_mem(IntPtr handle); [DllImport("bitwarden_c", CallingConvention = CallingConvention.Cdecl)] private static extern string run_command(string json, BitwardenSafeHandle handle); @@ -18,7 +19,7 @@ internal static BitwardenSafeHandle Init(string settings) return init(settings); } - internal static void FreeMemory(BitwardenSafeHandle handle) + internal static void FreeMemory(IntPtr handle) { free_mem(handle); } diff --git a/languages/csharp/Bitwarden.Sdk/BitwardenSafeHandle.cs b/languages/csharp/Bitwarden.Sdk/BitwardenSafeHandle.cs index e39216377..7939aab67 100644 --- a/languages/csharp/Bitwarden.Sdk/BitwardenSafeHandle.cs +++ b/languages/csharp/Bitwarden.Sdk/BitwardenSafeHandle.cs @@ -11,7 +11,7 @@ public BitwardenSafeHandle() : base(true) protected override bool ReleaseHandle() { - BitwardenLibrary.FreeMemory(this); + BitwardenLibrary.FreeMemory(handle); return true; } } diff --git a/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs b/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs index a21348827..34b990be7 100644 --- a/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs +++ b/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs @@ -1,6 +1,4 @@ -using System; - -namespace Bitwarden.Sdk; +namespace Bitwarden.Sdk; public class ProjectsClient From 1d0fc9e71946231acaa64b71d4df24ccd33c4d47 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Wed, 13 Sep 2023 15:10:06 +0200 Subject: [PATCH 82/94] PR comments resolved --- .../csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj | 9 +- languages/csharp/Bitwarden.Sdk/LICENSE.txt | 295 ++++++++++++++++++ languages/csharp/Bitwarden.Sdk/README.md | 18 +- 3 files changed, 312 insertions(+), 10 deletions(-) create mode 100644 languages/csharp/Bitwarden.Sdk/LICENSE.txt diff --git a/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj b/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj index 0e91c8cb6..fbb2aa4ec 100644 --- a/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj +++ b/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj @@ -7,22 +7,25 @@ enable BitwardenSdk BitwardenSdk - Bitwarden Sdk + Bitwarden Secrets Manager SDK Bitwarden Inc. - Bitwarden Sdk + .NET bindings for interacting with the Bitwarden Secrets Manager Bitwarden Inc. https://github.com/bitwarden/sdk/tree/master/languages/csharp Bitwarden;Sdk;.NET - BitwardenSdk + SDK bitwarden.png Git Bitwarden.Sdk + https://bitwarden.com/products/secrets-manager/ + https://github.com/bitwarden/sdk/blob/master/LICENSE + diff --git a/languages/csharp/Bitwarden.Sdk/LICENSE.txt b/languages/csharp/Bitwarden.Sdk/LICENSE.txt new file mode 100644 index 000000000..e9d496ff7 --- /dev/null +++ b/languages/csharp/Bitwarden.Sdk/LICENSE.txt @@ -0,0 +1,295 @@ +BITWARDEN SOFTWARE DEVELOPMENT KIT LICENSE AGREEMENT +Version 1, 17 March 2023 + +1. Introduction + +1.1 The Bitwarden Software Development Kit (referred to in the License Agreement +as the "SDK" and available for download at the following URL +https://github.com/bitwarden/sdk) is licensed to you subject to the terms of +this License Agreement. The License Agreement forms a legally binding contract +between you and the Company in relation to your use of the SDK. + +1.2 "Bitwarden" means the Bitwarden software made available by the Company, +available for download at the following URL, as updated from time to time. + +1.3 A "Compatible Application" means any software program or service that (i) +connects to and interoperates with a current version of the Bitwarden server +products distributed by the Company; and (ii) complies with the Company’s +acceptable use policy available at the following URL: +https://bitwarden.com/terms/#acceptable_use. + +1.4 "Company" means Bitwarden Inc., organized under the laws of the State of +Delaware. + +2. Accepting this License Agreement + +2.1 In order to access or use the SDK, you must first agree to the License +Agreement. You may not access or use the SDK if you do not accept the License +Agreement. + +2.2 By clicking to accept and/or accessing or using the SDK, you hereby agree to +the terms of the License Agreement. + +2.3 You may not access or use the SDK and may not accept the License Agreement +if you are a person barred from receiving the SDK under the laws of the United +States or other countries, including the country in which you are resident or +from which you access or use the SDK. + +2.4 If you are agreeing to be bound by the License Agreement on behalf of your +employer or any other entity, you represent and warrant that you have full legal +authority to bind your employer or such other entity to the License Agreement. +If you do not have the requisite authority, you may not accept the License +Agreement or you may not access or use the SDK on behalf of your employer or +other entity. + +3. SDK License from Bitwarden + +3.1 Subject to the terms of this License Agreement, Bitwarden grants you a +limited, worldwide, royalty-free, non-assignable, non-exclusive, and +non-sublicensable license to use the SDK solely (a) to develop, test, and +demonstrate a Compatible Application; (b) to develop, test, and run a Compatible +Application for personal use by your family; or (c) to to develop, test, and run +a Compatible Application for the internal business operations of your +organization in connection with a paid license for a Bitwarden server product, +provided that in no case above may the Compatible Application be offered, +licensed, or sold to a third party. + +3.2 You agree that Bitwarden or third parties own all legal right, title and +interest in and to the SDK, including any Intellectual Property Rights that +subsist in the SDK. "Intellectual Property Rights" means any and all rights +under patent law, copyright law, trade secret law, trademark law, and any and +all other proprietary rights. Bitwarden reserves all rights not expressly +granted to you. + +3.3 You may not use this SDK to develop applications for use with software other +than Bitwarden (including non-compatible implementations of Bitwarden) or to +develop another SDK. + +3.4 You may not use the SDK for any purpose not expressly permitted by the +License Agreement. Except for contributions to Bitwarden pursuant to the +Contribution License Agreement available at this URL: +https://cla-assistant.io/bitwarden/clients, or to the extent required by +applicable third party licenses, you may not copy modify, adapt, redistribute, +decompile, reverse engineer, disassemble, or create derivative works of the SDK +or any part of the SDK. + +3.5 Use, reproduction, and distribution of a component of the SDK licensed under +an open source software license are governed solely by the terms of that open +source software license and not the License Agreement. + +3.6 You agree that the form and nature of the SDK that the Company provides may +change without prior notice to you and that future versions of the SDK may be +incompatible with applications developed on previous versions of the SDK. You +agree that the Company may stop (permanently or temporarily) providing the SDK +or any features within the SDK to you or to users generally at the Company’s +sole discretion, without prior notice to you. + +3.7 Nothing in the License Agreement gives you a right to use any of the +Company’s trade names, trademarks, service marks, logos, domain names, or other +distinctive brand features. + +3.8 You agree that you will not remove, obscure, or alter any proprietary rights +notices (including copyright and trademark notices) that may be affixed to or +contained within the SDK. + +4. Use of the SDK by You + +4.1 The Company agrees that it obtains no right, title, or interest from you (or +your licensors) under the License Agreement in or to any software applications +that you develop using the SDK, including any Intellectual Property Rights that +subsist in those applications. + +4.2 You agree to use the SDK and write applications only for purposes that are +permitted by (a) the License Agreement and (b) any applicable law, regulation or +generally accepted practices or guidelines in the relevant jurisdictions +(including any laws regarding the export of data or software to and from the +United States or other relevant countries). + +4.3 You agree that if you use the SDK to develop applications for other users, +you will protect the privacy and legal rights of those users. If the users +provide you with user names, passwords, or other login information or personal +information, you must make the users aware that the information will be +available to your application, and you must provide legally adequate privacy +notice and protection for those users. If your application stores personal or +sensitive information provided by users, it must do so securely. If the user +provides your application with Bitwarden Account information, your application +may only use that information to access the user's Bitwarden Account when, and +for the limited purposes for which, the user has given you permission to do so. + +4.4 You agree that you will not engage in any activity with the SDK, including +the development or distribution of an application, that interferes with, +disrupts, damages, or accesses in an unauthorized manner the servers, networks, +or other properties or services of any third party including, but not limited +to, the Company, or any mobile communications carrier or public cloud service. + +4.5 If you use the SDK to retrieve a user's data from Bitwarden, you acknowledge +and agree that you shall retrieve data only with the user's explicit consent and +only when, and for the limited purposes for which, the user has given you +permission to do so. + +4.6 You agree that you are solely responsible for, and that the Company has no +responsibility to you or to any third party for, any data, content, or resources +that you create, transmit or display through Bitwarden and/or applications for +Bitwarden, and for the consequences of your actions (including any loss or +damage which Bitwarden may suffer) by doing so. + +4.7 You agree that you are solely responsible for, and that the Company has no +responsibility to you or to any third party for, any breach of your obligations +under the License Agreement, any applicable third party contract or Terms of +Service, or any applicable law or regulation, and for the consequences +(including any loss or damage which the Company or any third party may suffer) +of any such breach. + +5. Third Party Applications + +5.1 If you use the SDK to integrate or run applications developed by a third +party or that access data, content or resources provided by a third party, you +agree that the Company is not responsible for those applications, data, content, +or resources. You understand that all data, content or resources which you may +access through such third party applications are the sole responsibility of the +person from which they originated and that the Company is not liable for any +loss or damage that you may experience as a result of the use or access of any +of those third party applications, data, content, or resources. + +5.2 You should be aware that the data, content, and resources presented to you +through such a third party application may be protected by intellectual property +rights which are owned by the providers (or by other persons or companies on +their behalf). You acknowledge that your use of such third party applications, +data, content, or resources may be subject to separate terms between you and the +relevant third party. In that case, the License Agreement does not affect your +legal relationship with these third parties. + +6. Use of Bitwarden Server + +You acknowledge and agree that the Bitwarden server products to which any +Compatible Application must connect is protected by intellectual property rights +which are owned by the Company and your use of the Bitwarden server products is +subject to additional terms not set forth in this License Agreement. + +7. Terminating this License Agreement + +7.1 The License Agreement will continue to apply until terminated by either you +or the Company as set out below. + +7.2 If you want to terminate the License Agreement, you may do so by ceasing +your use of the SDK and any relevant developer credentials. + +7.3 The Company may at any time, terminate the License Agreement with you if: + +(a) you have breached any provision of the License Agreement; or + +(b) the Company is required to do so by law; or + +(c) a third party with whom the Company offered certain parts of the SDK to you +has terminated its relationship with the Company or ceased to offer certain +parts of the SDK to either the Company or to you; or + +(d) the Company decides to no longer provide the SDK or certain parts of the SDK +to users in the country in which you are resident or from which you use the +service, or the provision of the SDK or certain SDK services to you by the +Company is, in the Company’'s sole discretion, no longer commercially viable or +technically practicable. + +7.4 When the License Agreement comes to an end, all of the legal rights, +obligations and liabilities that you and the Company have benefited from, been +subject to (or which have accrued over time whilst the License Agreement has +been in force) or which are expressed to continue indefinitely, shall be +unaffected by this cessation, and the provisions of paragraph 12.8 shall +continue to apply to such rights, obligations and liabilities indefinitely. + +8. NO SUPPORT + +The Company is not obligated under this License Agreement to provide you any +support services for the SDK. Any support provided is at the Company’s sole +discretion and provided on an "as is" basis and without warranty of any kind. + +9. DISCLAIMER OF WARRANTIES + +9.1 YOU EXPRESSLY UNDERSTAND AND AGREE THAT YOUR USE OF THE SDK IS AT YOUR SOLE +RISK AND THAT THE SDK IS PROVIDED "AS IS" AND "AS AVAILABLE" WITHOUT WARRANTY OF +ANY KIND FROM Bitwarden. + +9.2 YOUR USE OF THE SDK AND ANY MATERIAL DOWNLOADED OR OTHERWISE OBTAINED +THROUGH THE USE OF THE SDK IS AT YOUR OWN DISCRETION AND RISK AND YOU ARE SOLELY +RESPONSIBLE FOR ANY DAMAGE TO YOUR COMPUTER SYSTEM OR OTHER DEVICE OR LOSS OF +DATA THAT RESULTS FROM SUCH USE. + +9.3 THE COMPANY FURTHER EXPRESSLY DISCLAIMS ALL WARRANTIES AND CONDITIONS OF ANY +KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE IMPLIED +WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE +AND NON-INFRINGEMENT. + +10. LIMITATION OF LIABILITY + +YOU EXPRESSLY UNDERSTAND AND AGREE THAT THE COMPANY, ITS SUBSIDIARIES AND +AFFILIATES, AND ITS LICENSORS SHALL NOT BE LIABLE TO YOU UNDER ANY THEORY OF +LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL, +STATUTORY, OR EXEMPLARY DAMAGES THAT MAY BE INCURRED BY YOU, INCLUDING ANY LOSS +OF DATA, WHETHER OR NOT THE COMPANY OR ITS REPRESENTATIVES HAVE BEEN ADVISED OF +OR SHOULD HAVE BEEN AWARE OF THE POSSIBILITY OF ANY SUCH LOSSES ARISING. + +11. Indemnification + +To the maximum extent permitted by law, you agree to defend, indemnify and hold +harmless the Company, its affiliates and their respective directors, officers, +employees and agents from and against any and all claims, actions, suits or +proceedings, as well as any and all losses, liabilities, damages, costs and +expenses (including reasonable attorneys fees) arising out of or accruing from +(a) your use of the SDK, (b) any application you develop on the SDK that +infringes any copyright, trademark, trade secret, trade dress, patent or other +intellectual property right of any person or defames any person or violates +their rights of publicity or privacy, and (c) any non-compliance by you with the +License Agreement. + +12. General Legal Terms + +12.1 The Company may make changes to the License Agreement as it distributes new +versions of the SDK. When these changes are made, the Company will make a new +version of the License Agreement available on the website where the SDK is made +available. + +12.2 The License Agreement constitutes the whole legal agreement between you and +the Company and governs your use of the SDK (excluding any services or software +which the Company may provide to you under a separate written agreement), and +completely replaces any prior agreements between you and the Company in relation +to the SDK. + +12.3 You agree that if the Company does not exercise or enforce any legal right +or remedy which is contained in the License Agreement (or which the Company has +the benefit of under any applicable law), this will not be taken to be a formal +waiver of the Company's rights and that those rights or remedies will still be +available to the Company. + +12.4 If any court of law, having the jurisdiction to decide on this matter, +rules that any provision of the License Agreement is invalid, then that +provision will be removed from the License Agreement without affecting the rest +of the License Agreement. The remaining provisions of the License Agreement will +continue to be valid and enforceable. + +12.5 You acknowledge and agree that each member of the group of companies of +which the Company is the parent shall be third party beneficiaries to the +License Agreement and that such other companies shall be entitled to directly +enforce, and rely upon, any provision of the License Agreement that confers a +benefit on them or rights in favor of them. Other than this, no other person or +company shall be third party beneficiaries to the License Agreement. + +12.6 EXPORT RESTRICTIONS. THE SDK IS SUBJECT TO UNITED STATES EXPORT LAWS AND +REGULATIONS. YOU MUST COMPLY WITH ALL DOMESTIC AND INTERNATIONAL EXPORT LAWS AND +REGULATIONS THAT APPLY TO THE SDK. THESE LAWS INCLUDE RESTRICTIONS ON +DESTINATIONS, END USERS, AND END USE. + +12.7 The rights granted in the License Agreement may not be assigned or +transferred by either you or the Company without the prior written approval of +the other party, provided that the Company may assign this License Agreement +upon notice to you in connection with an acquisition, merger, sale of assets, or +similar corporate change in control for the Company or the Intellectual Property +Rights in the SDK. + +12.8 The License Agreement, and any dispute relating to or arising out of this +License Agreement, shall be governed by the laws of the State of California +without regard to its conflict of laws provisions. You and the Company agree to +submit to the exclusive jurisdiction of the courts located within the county of +Los Angeles, California to resolve any dispute or legal matter arising from the +License Agreement. Notwithstanding this, you agree that the Company shall be +allowed to apply for injunctive remedies, or any equivalent type of urgent legal +relief, in any forum or jurisdiction. diff --git a/languages/csharp/Bitwarden.Sdk/README.md b/languages/csharp/Bitwarden.Sdk/README.md index 1d2509d7a..3ae1015a3 100644 --- a/languages/csharp/Bitwarden.Sdk/README.md +++ b/languages/csharp/Bitwarden.Sdk/README.md @@ -1,9 +1,10 @@ -# Bitwarden .NET SDK +# Bitwarden Secrets Manager SDK -The Bitwarden SDK (Software Development Kit) is a set of programming tools, libraries, and resources provided by Bitwarden for developers to integrate Bitwarden's password management and security capabilities into their own applications, services, or platforms. The SDK facilitates the seamless integration of Bitwarden's functionality into third-party software, enabling users to securely manage their passwords, credentials, and sensitive information across various digital environments. +.NET bindings for interacting with the [Bitwarden Secrets Manager]. This is a beta release and might be missing some functionality. ## Create access token -- to create access token go to [access-tokens help page] + +Review the help documentation on [Access Tokens] ## Usage code snippets @@ -35,24 +36,27 @@ responseForProjectResponse = bitwardenClient.Projects().Update(projectId, organi ``` ### Add new secret + ``` var key = "key"; var value = "value"; var note = "note"; var responseForSecretResponse = bitwardenClient.Secrets().Create(key, value, note, organizationId, new Guid[]{projectId}); var secretId = responseForSecretResponse.Data.Id; -``` +```csharp ### List secrets + ``` var responseForSecretIdentifiersResponse = bitwardenClient.Secrets().List(organizationId); -``` +```csharp # Delete secret or project ``` var responseForSecretsDeleteResponse = bitwardenClient.Secrets().Delete(new Guid[]{secretId}); var responseForProjectsDeleteResponse = bitwardenClient.Projects().Delete(new Guid[]{projectId}); -``` +```csharp -[access-tokens help page]: https://bitwarden.com/help/access-tokens/ +[Access Tokens]: https://bitwarden.com/help/access-tokens/ +[Bitwarden Secrets Manager]: https://bitwarden.com/products/secrets-manager/ From 48e83d08cc36b4eca7e0becbd27ca94d04165f6d Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Wed, 13 Sep 2023 15:18:47 +0200 Subject: [PATCH 83/94] fixes --- .../workflows/build-rust-cross-platform.yml | 4 --- languages/csharp/Bitwarden.Sdk/README.md | 25 +++++++++++-------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/.github/workflows/build-rust-cross-platform.yml b/.github/workflows/build-rust-cross-platform.yml index 5bc26bd11..dc008e0ff 100644 --- a/.github/workflows/build-rust-cross-platform.yml +++ b/.github/workflows/build-rust-cross-platform.yml @@ -11,22 +11,18 @@ jobs: settings: - os: macos-12 target: x86_64-apple-darwin - arch: x64 folder_name: macos-x64 - os: macos-12 target: aarch64-apple-darwin - arch: arm64 folder_name: macos-arm64 - os: windows-2022 target: x86_64-pc-windows-msvc - arch: x64 folder_name: windows-x64 - os: ubuntu-22.04 target: x86_64-unknown-linux-gnu - arch: x64 folder_name: ubuntu-x64 runs-on: ${{ matrix.settings.os }} diff --git a/languages/csharp/Bitwarden.Sdk/README.md b/languages/csharp/Bitwarden.Sdk/README.md index 3ae1015a3..7cf276e46 100644 --- a/languages/csharp/Bitwarden.Sdk/README.md +++ b/languages/csharp/Bitwarden.Sdk/README.md @@ -9,27 +9,30 @@ Review the help documentation on [Access Tokens] ## Usage code snippets ### Create new Bitwarden client -``` + +```csharp const string accessToken = ""; using var bitwardenClient = new BitwardenClient(); var loginResponse = bitwardenClient.AccessTokenLogin(accessToken); ``` ### Create new project -- Organization is created in the UI -``` + +```csharp const string organizationIdStr = ""; var organizationId = Guid.Parse(organizationIdStr); var responseForProjectResponse = bitwardenClient.Projects().Create(organizationId, "TestProject"); ``` ### List all projects -``` + +```csharp var response = bitwardenClient.Projects().List(organizationId); ``` ### Update project -``` + +```csharp var projectId = responseForProjectResponse.Data.Id; responseForProjectResponse = bitwardenClient.Projects().Get(projectId); responseForProjectResponse = bitwardenClient.Projects().Update(projectId, organizationId, "TestProjectUpdated"); @@ -37,26 +40,26 @@ responseForProjectResponse = bitwardenClient.Projects().Update(projectId, organi ### Add new secret -``` +```csharp var key = "key"; var value = "value"; var note = "note"; var responseForSecretResponse = bitwardenClient.Secrets().Create(key, value, note, organizationId, new Guid[]{projectId}); var secretId = responseForSecretResponse.Data.Id; -```csharp +``` ### List secrets -``` -var responseForSecretIdentifiersResponse = bitwardenClient.Secrets().List(organizationId); ```csharp +var responseForSecretIdentifiersResponse = bitwardenClient.Secrets().List(organizationId); +``` # Delete secret or project -``` +```csharp var responseForSecretsDeleteResponse = bitwardenClient.Secrets().Delete(new Guid[]{secretId}); var responseForProjectsDeleteResponse = bitwardenClient.Projects().Delete(new Guid[]{projectId}); -```csharp +``` [Access Tokens]: https://bitwarden.com/help/access-tokens/ [Bitwarden Secrets Manager]: https://bitwarden.com/products/secrets-manager/ From 0c344f0d87d4a77cad901360a4d050e059319c21 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Wed, 13 Sep 2023 15:37:03 +0200 Subject: [PATCH 84/94] PR comments --- .github/workflows/build-dotnet.yml | 18 +++++++++--------- .../workflows/build-rust-cross-platform.yml | 6 +----- .github/workflows/publish-dotnet.yml | 18 +++++++++--------- .../csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj | 3 +-- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/.github/workflows/build-dotnet.yml b/.github/workflows/build-dotnet.yml index 9878e18ee..8d7cf9b1e 100644 --- a/.github/workflows/build-dotnet.yml +++ b/.github/workflows/build-dotnet.yml @@ -31,28 +31,28 @@ jobs: with: global-json-file: languages/csharp/global.json - - name: Download macos-x64 files + - name: Download x86_64-apple-darwin files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files-macos-x64 + name: libbitwarden_c_files-x86_64-apple-darwin path: languages/csharp/Bitwarden.Sdk/macos-x64 - - name: Download macos-arm64 files + - name: Download aarch64-apple-darwin files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files-macos-arm64 + name: libbitwarden_c_files-aarch64-apple-darwin path: languages/csharp/Bitwarden.Sdk/macos-arm64 - - name: Download ubuntu-x64 files + - name: Download x86_64-unknown-linux-gnu files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files-ubuntu-x64 + name: libbitwarden_c_files-x86_64-unknown-linux-gnu path: languages/csharp/Bitwarden.Sdk/ubuntu-x64 - - name: Download windows-x64 files + - name: Download x86_64-pc-windows-msvc files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files-windows-x64 + name: libbitwarden_c_files-x86_64-pc-windows-msvc path: languages/csharp/Bitwarden.Sdk/windows-x64 - name: Build .NET 6 Project @@ -71,6 +71,6 @@ jobs: - name: Upload NuGet package uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: - name: BitwardenSdk.0.0.1.nupkg + name: Bitwarden.Sdk.0.0.1.nupkg path: | ./languages/csharp/Bitwarden.Sdk/nuget-output/*.nupkg diff --git a/.github/workflows/build-rust-cross-platform.yml b/.github/workflows/build-rust-cross-platform.yml index dc008e0ff..f7207f264 100644 --- a/.github/workflows/build-rust-cross-platform.yml +++ b/.github/workflows/build-rust-cross-platform.yml @@ -11,19 +11,15 @@ jobs: settings: - os: macos-12 target: x86_64-apple-darwin - folder_name: macos-x64 - os: macos-12 target: aarch64-apple-darwin - folder_name: macos-arm64 - os: windows-2022 target: x86_64-pc-windows-msvc - folder_name: windows-x64 - os: ubuntu-22.04 target: x86_64-unknown-linux-gnu - folder_name: ubuntu-x64 runs-on: ${{ matrix.settings.os }} @@ -53,6 +49,6 @@ jobs: - name: Upload Artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 with: - name: libbitwarden_c_files-${{ matrix.settings.folder_name }} + name: libbitwarden_c_files-${{ matrix.settings.target }} path: | target/${{ matrix.settings.target }}/release/*bitwarden_c* diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 22c9b439a..98d7f67bf 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -32,28 +32,28 @@ jobs: with: global-json-file: languages/csharp/global.json - - name: Download macos-x64 files + - name: Download x86_64-apple-darwin files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files-macos-x64 + name: libbitwarden_c_files-x86_64-apple-darwin path: languages/csharp/Bitwarden.Sdk/macos-x64 - - name: Download macos-arm64 files + - name: Download aarch64-apple-darwin files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files-macos-arm64 + name: libbitwarden_c_files-aarch64-apple-darwin path: languages/csharp/Bitwarden.Sdk/macos-arm64 - - name: Download ubuntu-x64 files + - name: Download x86_64-unknown-linux-gnu files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files-ubuntu-x64 + name: libbitwarden_c_files-x86_64-unknown-linux-gnu path: languages/csharp/Bitwarden.Sdk/ubuntu-x64 - - name: Download windows-x64 files + - name: Download x86_64-pc-windows-msvc files uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: - name: libbitwarden_c_files-windows-x64 + name: libbitwarden_c_files-x86_64-pc-windows-msvc path: languages/csharp/Bitwarden.Sdk/windows-x64 - name: Pack NuGet Package @@ -61,7 +61,7 @@ jobs: VERSION: ${{ github.event.inputs.version_number }} run: | cd languages/csharp/Bitwarden.Sdk - dotnet pack --configuration Release -p:PackageID=BitwardenSdk -p:Version=${VERSION} --output ./nuget-output /nologo /v:n + dotnet pack --configuration Release -p:PackageID=Bitwarden.Sdk -p:Version=${VERSION} --output ./nuget-output /nologo /v:n - 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 diff --git a/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj b/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj index fbb2aa4ec..eff7671e8 100644 --- a/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj +++ b/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj @@ -5,8 +5,7 @@ README.md enable enable - BitwardenSdk - BitwardenSdk + Bitwarden.Sdk Bitwarden Secrets Manager SDK Bitwarden Inc. .NET bindings for interacting with the Bitwarden Secrets Manager From e446d93192174a88c458cdf80ad0e8ba2b4c8b0d Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Wed, 13 Sep 2023 16:08:35 +0200 Subject: [PATCH 85/94] PR comments --- languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj | 4 ++-- languages/csharp/{Bitwarden.Sdk => }/LICENSE.txt | 0 languages/csharp/{Bitwarden.Sdk => }/README.md | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename languages/csharp/{Bitwarden.Sdk => }/LICENSE.txt (100%) rename languages/csharp/{Bitwarden.Sdk => }/README.md (100%) diff --git a/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj b/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj index eff7671e8..97f850211 100644 --- a/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj +++ b/languages/csharp/Bitwarden.Sdk/Bitwarden.Sdk.csproj @@ -23,8 +23,8 @@ - - + + diff --git a/languages/csharp/Bitwarden.Sdk/LICENSE.txt b/languages/csharp/LICENSE.txt similarity index 100% rename from languages/csharp/Bitwarden.Sdk/LICENSE.txt rename to languages/csharp/LICENSE.txt diff --git a/languages/csharp/Bitwarden.Sdk/README.md b/languages/csharp/README.md similarity index 100% rename from languages/csharp/Bitwarden.Sdk/README.md rename to languages/csharp/README.md From 2f2f4042d57f00b35a5cd16e61628416a4967a00 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Wed, 13 Sep 2023 16:35:47 +0200 Subject: [PATCH 86/94] reformat code --- .../csharp/Bitwarden.Sdk/BitwardenClient.cs | 3 +- .../csharp/Bitwarden.Sdk/ProjectsClient.cs | 53 +++++-------- .../csharp/Bitwarden.Sdk/SecretsClient.cs | 75 ++++++++----------- 3 files changed, 51 insertions(+), 80 deletions(-) diff --git a/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs b/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs index 48ed225c9..b2f052485 100644 --- a/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs +++ b/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs @@ -12,7 +12,8 @@ public BitwardenClient(BitwardenSettings? settings = null) var clientSettings = new ClientSettings { ApiUrl = settings is { ApiUrl: not null } ? settings.ApiUrl : "https://api.bitwarden.com", - IdentityUrl = settings is { IdentityUrl: not null } ? settings.IdentityUrl : "https://identity.bitwarden.com", + IdentityUrl = + settings is { IdentityUrl: not null } ? settings.IdentityUrl : "https://identity.bitwarden.com", DeviceType = DeviceType.Sdk, UserAgent = "Bitwarden DOTNET-SDK" }; diff --git a/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs b/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs index 34b990be7..904ec454c 100644 --- a/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs +++ b/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs @@ -1,9 +1,7 @@ namespace Bitwarden.Sdk; - public class ProjectsClient { - private readonly CommandRunner _commandRunner; internal ProjectsClient(CommandRunner commandRunner) @@ -13,66 +11,49 @@ internal ProjectsClient(CommandRunner commandRunner) public ResponseForProjectResponse? Get(Guid id) { - var command = new Command(); - var projectsCommand = new ProjectsCommand(); - var projectGetRequest = new ProjectGetRequest - { - Id = id - }; - projectsCommand.Get = projectGetRequest; - command.Projects = projectsCommand; + var command = new Command() { Projects = new ProjectsCommand { Get = new ProjectGetRequest { Id = id } } }; return _commandRunner.RunCommand(command); } public ResponseForProjectResponse? Create(Guid organizationId, string name) { - var command = new Command(); - var projectsCommand = new ProjectsCommand(); - var projectCreateRequest = new ProjectCreateRequest + var command = new Command() { - OrganizationId = organizationId, - Name = name + Projects = new ProjectsCommand + { + Create = new ProjectCreateRequest { OrganizationId = organizationId, Name = name } + } }; - projectsCommand.Create = projectCreateRequest; - command.Projects = projectsCommand; return _commandRunner.RunCommand(command); } public ResponseForProjectResponse? Update(Guid id, Guid organizationId, string name) { - var command = new Command(); - var projectsCommand = new ProjectsCommand(); - var projectPutRequest = new ProjectPutRequest + var command = new Command() { - Id = id, - OrganizationId = organizationId, - Name = name + Projects = new ProjectsCommand + { + Update = new ProjectPutRequest { Id = id, OrganizationId = organizationId, Name = name } + } }; - projectsCommand.Update = projectPutRequest; - command.Projects = projectsCommand; return _commandRunner.RunCommand(command); } public ResponseForProjectsDeleteResponse? Delete(Guid[] ids) { - var command = new Command(); - var projectsCommand = new ProjectsCommand(); - var projectsDeleteRequest = new ProjectsDeleteRequest + var command = new Command() { - Ids = ids + Projects = new ProjectsCommand { Delete = new ProjectsDeleteRequest { Ids = ids } } }; - projectsCommand.Delete = projectsDeleteRequest; - command.Projects = projectsCommand; return _commandRunner.RunCommand(command); } public ResponseForProjectsResponse? List(Guid organizationId) { - var command = new Command(); - var projectsCommand = new ProjectsCommand(); - var projectsListRequest = new ProjectsListRequest { OrganizationId = organizationId }; - projectsCommand.List = projectsListRequest; - command.Projects = projectsCommand; + var command = new Command() + { + Projects = new ProjectsCommand { List = new ProjectsListRequest { OrganizationId = organizationId } } + }; return _commandRunner.RunCommand(command); } } diff --git a/languages/csharp/Bitwarden.Sdk/SecretsClient.cs b/languages/csharp/Bitwarden.Sdk/SecretsClient.cs index c0d9400c9..f84e2f3f2 100644 --- a/languages/csharp/Bitwarden.Sdk/SecretsClient.cs +++ b/languages/csharp/Bitwarden.Sdk/SecretsClient.cs @@ -1,9 +1,7 @@ namespace Bitwarden.Sdk; - public class SecretsClient { - private readonly CommandRunner _commandRunner; internal SecretsClient(CommandRunner commandRunner) @@ -13,77 +11,68 @@ internal SecretsClient(CommandRunner commandRunner) public ResponseForSecretResponse? Get(Guid id) { - var command = new Command(); - var secretsCommand = new SecretsCommand(); - var secretGetRequest = new SecretGetRequest - { - Id = id - }; - secretsCommand.Get = secretGetRequest; - command.Secrets = secretsCommand; + var command = new Command() { Secrets = new SecretsCommand { Get = new SecretGetRequest { Id = id } } }; return _commandRunner.RunCommand(command); } public ResponseForSecretResponse? Create(string key, string value, string note, Guid organizationId, Guid[] projectIds) { - var command = new Command(); - var secretsCommand = new SecretsCommand(); - var secretCreateRequest = new SecretCreateRequest + var command = new Command() { - Key = key, - Value = value, - Note = note, - OrganizationId = organizationId, - ProjectIds = projectIds + Secrets = new SecretsCommand + { + Create = new SecretCreateRequest + { + Key = key, + Value = value, + Note = note, + OrganizationId = organizationId, + ProjectIds = projectIds + } + } }; - secretsCommand.Create = secretCreateRequest; - command.Secrets = secretsCommand; + return _commandRunner.RunCommand(command); } public ResponseForSecretResponse? Update(Guid id, string key, string value, string note, Guid organizationId, Guid[] projectIds) { - var command = new Command(); - var secretsCommand = new SecretsCommand(); - var secretPutRequest = new SecretPutRequest + var command = new Command() { - Id = id, - Key = key, - Value = value, - Note = note, - OrganizationId = organizationId, - ProjectIds = projectIds + Secrets = new SecretsCommand + { + Update = new SecretPutRequest + { + Id = id, + Key = key, + Value = value, + Note = note, + OrganizationId = organizationId, + ProjectIds = projectIds + } + } }; - secretsCommand.Update = secretPutRequest; - command.Secrets = secretsCommand; + return _commandRunner.RunCommand(command); } public ResponseForSecretsDeleteResponse? Delete(Guid[] ids) { - var command = new Command(); - var secretsCommand = new SecretsCommand(); - var secretsDeleteRequest = new SecretsDeleteRequest + var command = new Command() { - Ids = ids + Secrets = new SecretsCommand { Delete = new SecretsDeleteRequest { Ids = ids } } }; - secretsCommand.Delete = secretsDeleteRequest; - command.Secrets = secretsCommand; return _commandRunner.RunCommand(command); } public ResponseForSecretIdentifiersResponse? List(Guid organizationId) { - var command = new Command(); - var secretsCommand = new SecretsCommand(); - var secretIdentifiersRequest = new SecretIdentifiersRequest + var command = new Command() { - OrganizationId = organizationId + Secrets = new SecretsCommand { List = new SecretIdentifiersRequest { OrganizationId = organizationId } } }; - secretsCommand.List = secretIdentifiersRequest; - command.Secrets = secretsCommand; return _commandRunner.RunCommand(command); } } From 12eb51157c07e38ee0f2ca59e78ef5667dccc712 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Wed, 13 Sep 2023 16:56:10 +0200 Subject: [PATCH 87/94] small name fix --- .github/workflows/build-dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-dotnet.yml b/.github/workflows/build-dotnet.yml index 8d7cf9b1e..f18728f45 100644 --- a/.github/workflows/build-dotnet.yml +++ b/.github/workflows/build-dotnet.yml @@ -66,7 +66,7 @@ jobs: VERSION: 0.0.1 run: | cd languages/csharp/Bitwarden.Sdk - dotnet pack --configuration Release -p:PackageID=BitwardenSdk -p:Version=${VERSION} --output ./nuget-output /nologo /v:n + dotnet pack --configuration Release -p:PackageID=Bitwarden.Sdk -p:Version=${VERSION} --output ./nuget-output /nologo /v:n - name: Upload NuGet package uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 From 08906407b7fda28f5194778b586d16bb4bf39e43 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Wed, 13 Sep 2023 21:34:50 +0200 Subject: [PATCH 88/94] fixes --- .github/workflows/build-dotnet.yml | 12 +++++++----- .github/workflows/build-rust-cross-platform.yml | 14 ++++---------- .github/workflows/publish-dotnet.yml | 12 +++++++----- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build-dotnet.yml b/.github/workflows/build-dotnet.yml index f18728f45..9d0ab1dce 100644 --- a/.github/workflows/build-dotnet.yml +++ b/.github/workflows/build-dotnet.yml @@ -13,14 +13,17 @@ jobs: uses: ./.github/workflows/build-rust-cross-platform.yml build_dotnet: + name: Build .NET runs-on: ubuntu-22.04 - needs: [generate_schemas, build_rust] + needs: + - generate_schemas + - build_rust steps: - name: Checkout Repository uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - - name: Download c# schemas artifact + - name: Download C# schemas artifact uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: name: schemas.cs @@ -64,9 +67,8 @@ jobs: - name: Pack NuGet Package env: VERSION: 0.0.1 - run: | - cd languages/csharp/Bitwarden.Sdk - dotnet pack --configuration Release -p:PackageID=Bitwarden.Sdk -p:Version=${VERSION} --output ./nuget-output /nologo /v:n + 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 diff --git a/.github/workflows/build-rust-cross-platform.yml b/.github/workflows/build-rust-cross-platform.yml index f7207f264..d287cf061 100644 --- a/.github/workflows/build-rust-cross-platform.yml +++ b/.github/workflows/build-rust-cross-platform.yml @@ -5,26 +5,21 @@ on: 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 - runs-on: ${{ matrix.settings.os }} - - name: Build for ${{ matrix.settings.os }} ${{ matrix.settings.target }} - steps: - name: Checkout uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 @@ -38,13 +33,12 @@ jobs: uses: Swatinem/rust-cache@e207df5d269b42b69c8bc5101da26f7d31feddb4 # v2.6.2 - name: Add build architecture - run: | - rustup target add ${{ matrix.settings.target }} + run: rustup target add ${{ matrix.settings.target }} - name: Build Rust - run: cargo build --target ${{ matrix.settings.target }} --release env: RUSTFLAGS: "-D warnings" + run: cargo build --target ${{ matrix.settings.target }} --release - name: Upload Artifact uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 diff --git a/.github/workflows/publish-dotnet.yml b/.github/workflows/publish-dotnet.yml index 98d7f67bf..a37266f69 100644 --- a/.github/workflows/publish-dotnet.yml +++ b/.github/workflows/publish-dotnet.yml @@ -14,14 +14,17 @@ jobs: uses: ./.github/workflows/build-rust-cross-platform.yml deploy: + name: Deploy runs-on: ubuntu-22.04 - needs: [generate_schemas, build_rust] + needs: + - generate_schemas + - build_rust steps: - name: Checkout Repository uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - - name: Download c# schemas artifact + - name: Download C# schemas artifact uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2 with: name: schemas.cs @@ -59,9 +62,8 @@ jobs: - name: Pack NuGet Package env: VERSION: ${{ github.event.inputs.version_number }} - run: | - cd languages/csharp/Bitwarden.Sdk - dotnet pack --configuration Release -p:PackageID=Bitwarden.Sdk -p:Version=${VERSION} --output ./nuget-output /nologo /v:n + 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 From c2becb72ba2031ddb108115cf3e7c12b966b85d7 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Fri, 15 Sep 2023 20:50:35 +0200 Subject: [PATCH 89/94] make get only properties --- .../csharp/Bitwarden.Sdk.Samples/Program.cs | 20 +++++++++---------- .../csharp/Bitwarden.Sdk/BitwardenClient.cs | 16 ++++----------- languages/csharp/README.md | 14 ++++++------- 3 files changed, 21 insertions(+), 29 deletions(-) diff --git a/languages/csharp/Bitwarden.Sdk.Samples/Program.cs b/languages/csharp/Bitwarden.Sdk.Samples/Program.cs index 7bb2e91b0..889bd0625 100644 --- a/languages/csharp/Bitwarden.Sdk.Samples/Program.cs +++ b/languages/csharp/Bitwarden.Sdk.Samples/Program.cs @@ -7,25 +7,25 @@ using var bitwardenClient = new BitwardenClient(); var loginResponse = bitwardenClient.AccessTokenLogin(accessToken); var organizationId = Guid.Parse(organizationIdStr); -var responseForProjectResponse = bitwardenClient.Projects().Create(organizationId, "NewTestProject"); +var responseForProjectResponse = bitwardenClient.Projects.Create(organizationId, "NewTestProject"); var projectId = responseForProjectResponse.Data.Id; -var responseForProjectsResponse = bitwardenClient.Projects().List(organizationId); -responseForProjectResponse = bitwardenClient.Projects().Get(projectId); -responseForProjectResponse = bitwardenClient.Projects().Update(projectId, organizationId, "NewTestProject2"); +var responseForProjectsResponse = bitwardenClient.Projects.List(organizationId); +responseForProjectResponse = bitwardenClient.Projects.Get(projectId); +responseForProjectResponse = bitwardenClient.Projects.Update(projectId, organizationId, "NewTestProject2"); var key = "key"; var value = "value"; var note = "note"; var responseForSecretResponse = - bitwardenClient.Secrets().Create(key, value, note, organizationId, new Guid[] { projectId }); + bitwardenClient.Secrets.Create(key, value, note, organizationId, new Guid[] { projectId }); var secretId = responseForSecretResponse.Data.Id; -var responseForSecretIdentifiersResponse = bitwardenClient.Secrets().List(organizationId); -responseForSecretResponse = bitwardenClient.Secrets().Get(secretId); +var responseForSecretIdentifiersResponse = bitwardenClient.Secrets.List(organizationId); +responseForSecretResponse = bitwardenClient.Secrets.Get(secretId); key = "key2"; value = "value2"; note = "note2"; -responseForSecretResponse = bitwardenClient.Secrets() +responseForSecretResponse = bitwardenClient.Secrets .Update(secretId, key, value, note, organizationId, new Guid[] { projectId }); -var responseForSecretsDeleteResponse = bitwardenClient.Secrets().Delete(new Guid[] { secretId }); -var responseForProjectsDeleteResponse = bitwardenClient.Projects().Delete(new Guid[] { projectId }); +var responseForSecretsDeleteResponse = bitwardenClient.Secrets.Delete(new Guid[] { secretId }); +var responseForProjectsDeleteResponse = bitwardenClient.Projects.Delete(new Guid[] { projectId }); diff --git a/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs b/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs index b2f052485..47db67737 100644 --- a/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs +++ b/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs @@ -2,8 +2,6 @@ public sealed class BitwardenClient : IDisposable { - private readonly ProjectsClient _projectsClient; - private readonly SecretsClient _secretsClient; private readonly CommandRunner _commandRunner; private readonly BitwardenSafeHandle _handle; @@ -20,8 +18,8 @@ public BitwardenClient(BitwardenSettings? settings = null) _handle = BitwardenLibrary.Init(clientSettings.ToJson()); _commandRunner = new CommandRunner(_handle); - _projectsClient = new ProjectsClient(_commandRunner); - _secretsClient = new SecretsClient(_commandRunner); + Projects = new ProjectsClient(_commandRunner); + Secrets = new SecretsClient(_commandRunner); } public ResponseForApiKeyLoginResponse? AccessTokenLogin(string accessToken) @@ -30,15 +28,9 @@ public BitwardenClient(BitwardenSettings? settings = null) return _commandRunner.RunCommand(command); } - public ProjectsClient Projects() - { - return _projectsClient; - } + public ProjectsClient Projects { get; } - public SecretsClient Secrets() - { - return _secretsClient; - } + public SecretsClient Secrets { get; } public void Dispose() { diff --git a/languages/csharp/README.md b/languages/csharp/README.md index 7cf276e46..84b0e0cd4 100644 --- a/languages/csharp/README.md +++ b/languages/csharp/README.md @@ -27,15 +27,15 @@ var responseForProjectResponse = bitwardenClient.Projects().Create(organizationI ### List all projects ```csharp -var response = bitwardenClient.Projects().List(organizationId); +var response = bitwardenClient.Projects.List(organizationId); ``` ### Update project ```csharp var projectId = responseForProjectResponse.Data.Id; -responseForProjectResponse = bitwardenClient.Projects().Get(projectId); -responseForProjectResponse = bitwardenClient.Projects().Update(projectId, organizationId, "TestProjectUpdated"); +responseForProjectResponse = bitwardenClient.Projects.Get(projectId); +responseForProjectResponse = bitwardenClient.Projects.Update(projectId, organizationId, "TestProjectUpdated"); ``` ### Add new secret @@ -44,21 +44,21 @@ responseForProjectResponse = bitwardenClient.Projects().Update(projectId, organi var key = "key"; var value = "value"; var note = "note"; -var responseForSecretResponse = bitwardenClient.Secrets().Create(key, value, note, organizationId, new Guid[]{projectId}); +var responseForSecretResponse = bitwardenClient.Secrets.Create(key, value, note, organizationId, new Guid[]{projectId}); var secretId = responseForSecretResponse.Data.Id; ``` ### List secrets ```csharp -var responseForSecretIdentifiersResponse = bitwardenClient.Secrets().List(organizationId); +var responseForSecretIdentifiersResponse = bitwardenClient.Secrets.List(organizationId); ``` # Delete secret or project ```csharp -var responseForSecretsDeleteResponse = bitwardenClient.Secrets().Delete(new Guid[]{secretId}); -var responseForProjectsDeleteResponse = bitwardenClient.Projects().Delete(new Guid[]{projectId}); +var responseForSecretsDeleteResponse = bitwardenClient.Secrets.Delete(new Guid[]{secretId}); +var responseForProjectsDeleteResponse = bitwardenClient.Projects.Delete(new Guid[]{projectId}); ``` [Access Tokens]: https://bitwarden.com/help/access-tokens/ From 3d5f1e517a2640317ee8360d6d574e65395c46fc Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Mon, 18 Sep 2023 21:56:30 +0200 Subject: [PATCH 90/94] PR comments --- .../csharp/Bitwarden.Sdk.Samples/Program.cs | 20 +++++------ .../csharp/Bitwarden.Sdk/BitwardenClient.cs | 14 ++++---- .../Bitwarden.Sdk/BitwardenException.cs | 8 +++++ .../csharp/Bitwarden.Sdk/ProjectsClient.cs | 35 +++++++++++++------ .../csharp/Bitwarden.Sdk/SecretsClient.cs | 35 +++++++++++++------ languages/csharp/README.md | 20 +++++------ 6 files changed, 86 insertions(+), 46 deletions(-) create mode 100644 languages/csharp/Bitwarden.Sdk/BitwardenException.cs diff --git a/languages/csharp/Bitwarden.Sdk.Samples/Program.cs b/languages/csharp/Bitwarden.Sdk.Samples/Program.cs index 889bd0625..a2edc3e9b 100644 --- a/languages/csharp/Bitwarden.Sdk.Samples/Program.cs +++ b/languages/csharp/Bitwarden.Sdk.Samples/Program.cs @@ -5,26 +5,26 @@ var organizationIdStr = Environment.GetEnvironmentVariable("ORGANIZATION_ID"); using var bitwardenClient = new BitwardenClient(); -var loginResponse = bitwardenClient.AccessTokenLogin(accessToken); +bitwardenClient.AccessTokenLogin(accessToken); var organizationId = Guid.Parse(organizationIdStr); -var responseForProjectResponse = bitwardenClient.Projects.Create(organizationId, "NewTestProject"); -var projectId = responseForProjectResponse.Data.Id; -var responseForProjectsResponse = bitwardenClient.Projects.List(organizationId); -responseForProjectResponse = bitwardenClient.Projects.Get(projectId); -responseForProjectResponse = bitwardenClient.Projects.Update(projectId, organizationId, "NewTestProject2"); +var projectResponse = bitwardenClient.Projects.Create(organizationId, "NewTestProject"); +var projectId = projectResponse.Id; +var projectsResponse = bitwardenClient.Projects.List(organizationId); +projectResponse = bitwardenClient.Projects.Get(projectId); +projectResponse = bitwardenClient.Projects.Update(projectId, organizationId, "NewTestProject2"); var key = "key"; var value = "value"; var note = "note"; -var responseForSecretResponse = +var secretResponse = bitwardenClient.Secrets.Create(key, value, note, organizationId, new Guid[] { projectId }); -var secretId = responseForSecretResponse.Data.Id; +var secretId = secretResponse.Id; var responseForSecretIdentifiersResponse = bitwardenClient.Secrets.List(organizationId); -responseForSecretResponse = bitwardenClient.Secrets.Get(secretId); +secretResponse = bitwardenClient.Secrets.Get(secretId); key = "key2"; value = "value2"; note = "note2"; -responseForSecretResponse = bitwardenClient.Secrets +secretResponse = bitwardenClient.Secrets .Update(secretId, key, value, note, organizationId, new Guid[] { projectId }); var responseForSecretsDeleteResponse = bitwardenClient.Secrets.Delete(new Guid[] { secretId }); diff --git a/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs b/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs index 47db67737..317016ed3 100644 --- a/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs +++ b/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs @@ -9,10 +9,8 @@ public BitwardenClient(BitwardenSettings? settings = null) { var clientSettings = new ClientSettings { - ApiUrl = settings is { ApiUrl: not null } ? settings.ApiUrl : "https://api.bitwarden.com", - IdentityUrl = - settings is { IdentityUrl: not null } ? settings.IdentityUrl : "https://identity.bitwarden.com", - DeviceType = DeviceType.Sdk, + ApiUrl = settings?.ApiUrl!, + IdentityUrl = settings?.IdentityUrl!, UserAgent = "Bitwarden DOTNET-SDK" }; @@ -22,10 +20,14 @@ public BitwardenClient(BitwardenSettings? settings = null) Secrets = new SecretsClient(_commandRunner); } - public ResponseForApiKeyLoginResponse? AccessTokenLogin(string accessToken) + public void AccessTokenLogin(string accessToken) { var command = new Command() { AccessTokenLogin = new AccessTokenLoginRequest { AccessToken = accessToken } }; - return _commandRunner.RunCommand(command); + var response = _commandRunner.RunCommand(command); + if (response is not { Success: true }) + { + throw new BitwardenException("Login failed"); + } } public ProjectsClient Projects { get; } diff --git a/languages/csharp/Bitwarden.Sdk/BitwardenException.cs b/languages/csharp/Bitwarden.Sdk/BitwardenException.cs new file mode 100644 index 000000000..94db47740 --- /dev/null +++ b/languages/csharp/Bitwarden.Sdk/BitwardenException.cs @@ -0,0 +1,8 @@ +namespace Bitwarden.Sdk; + +public class BitwardenException: Exception +{ + public BitwardenException(string message) : base(message) { } + public BitwardenException(string message, System.Exception innerException) + : base(message, innerException) { } +} diff --git a/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs b/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs index 904ec454c..fae5ef361 100644 --- a/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs +++ b/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs @@ -9,13 +9,16 @@ internal ProjectsClient(CommandRunner commandRunner) _commandRunner = commandRunner; } - public ResponseForProjectResponse? Get(Guid id) + public ProjectResponse Get(Guid id) { var command = new Command() { Projects = new ProjectsCommand { Get = new ProjectGetRequest { Id = id } } }; - return _commandRunner.RunCommand(command); + var result = _commandRunner.RunCommand(command); + + if (result is { Success: true }) return result.Data; + throw new BitwardenException(result != null ? result.ErrorMessage : "Project not found"); } - public ResponseForProjectResponse? Create(Guid organizationId, string name) + public ProjectResponse Create(Guid organizationId, string name) { var command = new Command() { @@ -24,10 +27,13 @@ internal ProjectsClient(CommandRunner commandRunner) Create = new ProjectCreateRequest { OrganizationId = organizationId, Name = name } } }; - return _commandRunner.RunCommand(command); + var result = _commandRunner.RunCommand(command); + + if (result is { Success: true }) return result.Data; + throw new BitwardenException(result != null ? result.ErrorMessage : "Project create failed"); } - public ResponseForProjectResponse? Update(Guid id, Guid organizationId, string name) + public ProjectResponse Update(Guid id, Guid organizationId, string name) { var command = new Command() { @@ -36,24 +42,33 @@ internal ProjectsClient(CommandRunner commandRunner) Update = new ProjectPutRequest { Id = id, OrganizationId = organizationId, Name = name } } }; - return _commandRunner.RunCommand(command); + var result = _commandRunner.RunCommand(command); + + if (result is { Success: true }) return result.Data; + throw new BitwardenException(result != null ? result.ErrorMessage : "Project update failed"); } - public ResponseForProjectsDeleteResponse? Delete(Guid[] ids) + public ProjectsDeleteResponse Delete(Guid[] ids) { var command = new Command() { Projects = new ProjectsCommand { Delete = new ProjectsDeleteRequest { Ids = ids } } }; - return _commandRunner.RunCommand(command); + var result = _commandRunner.RunCommand(command); + + if (result is { Success: true }) return result.Data; + throw new BitwardenException(result != null ? result.ErrorMessage : "Project delete failed"); } - public ResponseForProjectsResponse? List(Guid organizationId) + public ProjectsResponse List(Guid organizationId) { var command = new Command() { Projects = new ProjectsCommand { List = new ProjectsListRequest { OrganizationId = organizationId } } }; - return _commandRunner.RunCommand(command); + var result = _commandRunner.RunCommand(command); + + if (result is { Success: true }) return result.Data; + throw new BitwardenException(result != null ? result.ErrorMessage : "No projects for given organization"); } } diff --git a/languages/csharp/Bitwarden.Sdk/SecretsClient.cs b/languages/csharp/Bitwarden.Sdk/SecretsClient.cs index f84e2f3f2..e55b95727 100644 --- a/languages/csharp/Bitwarden.Sdk/SecretsClient.cs +++ b/languages/csharp/Bitwarden.Sdk/SecretsClient.cs @@ -9,13 +9,16 @@ internal SecretsClient(CommandRunner commandRunner) _commandRunner = commandRunner; } - public ResponseForSecretResponse? Get(Guid id) + public SecretResponse Get(Guid id) { var command = new Command() { Secrets = new SecretsCommand { Get = new SecretGetRequest { Id = id } } }; - return _commandRunner.RunCommand(command); + var result = _commandRunner.RunCommand(command); + + if (result is { Success: true }) return result.Data; + throw new BitwardenException(result != null ? result.ErrorMessage : "Secret not found"); } - public ResponseForSecretResponse? Create(string key, string value, string note, Guid organizationId, + public SecretResponse Create(string key, string value, string note, Guid organizationId, Guid[] projectIds) { var command = new Command() @@ -33,10 +36,13 @@ internal SecretsClient(CommandRunner commandRunner) } }; - return _commandRunner.RunCommand(command); + var result = _commandRunner.RunCommand(command); + + if (result is { Success: true }) return result.Data; + throw new BitwardenException(result != null ? result.ErrorMessage : "Secret create failed"); } - public ResponseForSecretResponse? Update(Guid id, string key, string value, string note, Guid organizationId, + public SecretResponse Update(Guid id, string key, string value, string note, Guid organizationId, Guid[] projectIds) { var command = new Command() @@ -55,24 +61,33 @@ internal SecretsClient(CommandRunner commandRunner) } }; - return _commandRunner.RunCommand(command); + var result = _commandRunner.RunCommand(command); + + if (result is { Success: true }) return result.Data; + throw new BitwardenException(result != null ? result.ErrorMessage : "Secret update failed"); } - public ResponseForSecretsDeleteResponse? Delete(Guid[] ids) + public SecretsDeleteResponse Delete(Guid[] ids) { var command = new Command() { Secrets = new SecretsCommand { Delete = new SecretsDeleteRequest { Ids = ids } } }; - return _commandRunner.RunCommand(command); + var result = _commandRunner.RunCommand(command); + + if (result is { Success: true }) return result.Data; + throw new BitwardenException(result != null ? result.ErrorMessage : "Secrets delete failed"); } - public ResponseForSecretIdentifiersResponse? List(Guid organizationId) + public SecretIdentifiersResponse List(Guid organizationId) { var command = new Command() { Secrets = new SecretsCommand { List = new SecretIdentifiersRequest { OrganizationId = organizationId } } }; - return _commandRunner.RunCommand(command); + var result = _commandRunner.RunCommand(command); + + if (result is { Success: true }) return result.Data; + throw new BitwardenException(result != null ? result.ErrorMessage : "No secret for given organization"); } } diff --git a/languages/csharp/README.md b/languages/csharp/README.md index 84b0e0cd4..4b6f48e60 100644 --- a/languages/csharp/README.md +++ b/languages/csharp/README.md @@ -13,7 +13,7 @@ Review the help documentation on [Access Tokens] ```csharp const string accessToken = ""; using var bitwardenClient = new BitwardenClient(); -var loginResponse = bitwardenClient.AccessTokenLogin(accessToken); +bitwardenClient.AccessTokenLogin(accessToken); ``` ### Create new project @@ -21,7 +21,7 @@ var loginResponse = bitwardenClient.AccessTokenLogin(accessToken); ```csharp const string organizationIdStr = ""; var organizationId = Guid.Parse(organizationIdStr); -var responseForProjectResponse = bitwardenClient.Projects().Create(organizationId, "TestProject"); +var projectResponse = bitwardenClient.Projects().Create(organizationId, "TestProject"); ``` ### List all projects @@ -33,9 +33,9 @@ var response = bitwardenClient.Projects.List(organizationId); ### Update project ```csharp -var projectId = responseForProjectResponse.Data.Id; -responseForProjectResponse = bitwardenClient.Projects.Get(projectId); -responseForProjectResponse = bitwardenClient.Projects.Update(projectId, organizationId, "TestProjectUpdated"); +var projectId = projectResponse.Id; +projectResponse = bitwardenClient.Projects.Get(projectId); +projectResponse = bitwardenClient.Projects.Update(projectId, organizationId, "TestProjectUpdated"); ``` ### Add new secret @@ -44,21 +44,21 @@ responseForProjectResponse = bitwardenClient.Projects.Update(projectId, organiza var key = "key"; var value = "value"; var note = "note"; -var responseForSecretResponse = bitwardenClient.Secrets.Create(key, value, note, organizationId, new Guid[]{projectId}); -var secretId = responseForSecretResponse.Data.Id; +var secretResponse = bitwardenClient.Secrets.Create(key, value, note, organizationId, new Guid[]{projectId}); +var secretId = secretResponse.Id; ``` ### List secrets ```csharp -var responseForSecretIdentifiersResponse = bitwardenClient.Secrets.List(organizationId); +var secretIdentifiersResponse = bitwardenClient.Secrets.List(organizationId); ``` # Delete secret or project ```csharp -var responseForSecretsDeleteResponse = bitwardenClient.Secrets.Delete(new Guid[]{secretId}); -var responseForProjectsDeleteResponse = bitwardenClient.Projects.Delete(new Guid[]{projectId}); +var secretsDeleteResponse = bitwardenClient.Secrets.Delete(new Guid[]{secretId}); +var projectsDeleteResponse = bitwardenClient.Projects.Delete(new Guid[]{projectId}); ``` [Access Tokens]: https://bitwarden.com/help/access-tokens/ From 2202db1ee6c665b64900f9c4607c08b931d0621a Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Tue, 19 Sep 2023 16:16:09 +0200 Subject: [PATCH 91/94] PR comments --- .../csharp/Bitwarden.Sdk/BitwardenAuthException.cs | 8 ++++++++ languages/csharp/Bitwarden.Sdk/BitwardenClient.cs | 2 +- languages/csharp/Bitwarden.Sdk/ProjectsClient.cs | 10 +++++----- languages/csharp/Bitwarden.Sdk/SecretsClient.cs | 12 ++++++------ 4 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 languages/csharp/Bitwarden.Sdk/BitwardenAuthException.cs diff --git a/languages/csharp/Bitwarden.Sdk/BitwardenAuthException.cs b/languages/csharp/Bitwarden.Sdk/BitwardenAuthException.cs new file mode 100644 index 000000000..be88bdc6b --- /dev/null +++ b/languages/csharp/Bitwarden.Sdk/BitwardenAuthException.cs @@ -0,0 +1,8 @@ +namespace Bitwarden.Sdk; + +public class BitwardenAuthException: Exception +{ + public BitwardenAuthException(string message) : base(message) { } + public BitwardenAuthException(string message, System.Exception innerException) + : base(message, innerException) { } +} diff --git a/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs b/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs index 317016ed3..acb59b4a3 100644 --- a/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs +++ b/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs @@ -26,7 +26,7 @@ public void AccessTokenLogin(string accessToken) var response = _commandRunner.RunCommand(command); if (response is not { Success: true }) { - throw new BitwardenException("Login failed"); + throw new BitwardenAuthException(response != null ? response.ErrorMessage : "Login failed"); } } diff --git a/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs b/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs index fae5ef361..fc989ab4d 100644 --- a/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs +++ b/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs @@ -14,7 +14,7 @@ public ProjectResponse Get(Guid id) var command = new Command() { Projects = new ProjectsCommand { Get = new ProjectGetRequest { Id = id } } }; var result = _commandRunner.RunCommand(command); - if (result is { Success: true }) return result.Data; + if (result is { Success: true }) { return result.Data; } throw new BitwardenException(result != null ? result.ErrorMessage : "Project not found"); } @@ -29,7 +29,7 @@ public ProjectResponse Create(Guid organizationId, string name) }; var result = _commandRunner.RunCommand(command); - if (result is { Success: true }) return result.Data; + if (result is { Success: true }) { return result.Data; } throw new BitwardenException(result != null ? result.ErrorMessage : "Project create failed"); } @@ -44,7 +44,7 @@ public ProjectResponse Update(Guid id, Guid organizationId, string name) }; var result = _commandRunner.RunCommand(command); - if (result is { Success: true }) return result.Data; + if (result is { Success: true }) { return result.Data; } throw new BitwardenException(result != null ? result.ErrorMessage : "Project update failed"); } @@ -56,7 +56,7 @@ public ProjectsDeleteResponse Delete(Guid[] ids) }; var result = _commandRunner.RunCommand(command); - if (result is { Success: true }) return result.Data; + if (result is { Success: true }) { return result.Data; } throw new BitwardenException(result != null ? result.ErrorMessage : "Project delete failed"); } @@ -68,7 +68,7 @@ public ProjectsResponse List(Guid organizationId) }; var result = _commandRunner.RunCommand(command); - if (result is { Success: true }) return result.Data; + if (result is { Success: true }) { return result.Data; } throw new BitwardenException(result != null ? result.ErrorMessage : "No projects for given organization"); } } diff --git a/languages/csharp/Bitwarden.Sdk/SecretsClient.cs b/languages/csharp/Bitwarden.Sdk/SecretsClient.cs index e55b95727..9aa968634 100644 --- a/languages/csharp/Bitwarden.Sdk/SecretsClient.cs +++ b/languages/csharp/Bitwarden.Sdk/SecretsClient.cs @@ -14,7 +14,7 @@ public SecretResponse Get(Guid id) var command = new Command() { Secrets = new SecretsCommand { Get = new SecretGetRequest { Id = id } } }; var result = _commandRunner.RunCommand(command); - if (result is { Success: true }) return result.Data; + if (result is { Success: true }) { return result.Data; } throw new BitwardenException(result != null ? result.ErrorMessage : "Secret not found"); } @@ -38,7 +38,7 @@ public SecretResponse Create(string key, string value, string note, Guid organiz var result = _commandRunner.RunCommand(command); - if (result is { Success: true }) return result.Data; + if (result is { Success: true }) { return result.Data; } throw new BitwardenException(result != null ? result.ErrorMessage : "Secret create failed"); } @@ -63,7 +63,7 @@ public SecretResponse Update(Guid id, string key, string value, string note, Gui var result = _commandRunner.RunCommand(command); - if (result is { Success: true }) return result.Data; + if (result is { Success: true }) { return result.Data; } throw new BitwardenException(result != null ? result.ErrorMessage : "Secret update failed"); } @@ -75,7 +75,7 @@ public SecretsDeleteResponse Delete(Guid[] ids) }; var result = _commandRunner.RunCommand(command); - if (result is { Success: true }) return result.Data; + if (result is { Success: true }) { return result.Data; } throw new BitwardenException(result != null ? result.ErrorMessage : "Secrets delete failed"); } @@ -87,7 +87,7 @@ public SecretIdentifiersResponse List(Guid organizationId) }; var result = _commandRunner.RunCommand(command); - if (result is { Success: true }) return result.Data; - throw new BitwardenException(result != null ? result.ErrorMessage : "No secret for given organization"); + if (result is { Success: true }) { return result.Data; } + throw new BitwardenException(result != null ? result.ErrorMessage : "No secrets for given organization"); } } From 34f8a36df29f9888df8d2eee2546f02679985b5a Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Tue, 19 Sep 2023 22:00:12 +0200 Subject: [PATCH 92/94] PR comment fix --- .../csharp/Bitwarden.Sdk.Samples/Program.cs | 33 +++++++++---------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/languages/csharp/Bitwarden.Sdk.Samples/Program.cs b/languages/csharp/Bitwarden.Sdk.Samples/Program.cs index a2edc3e9b..ee6834979 100644 --- a/languages/csharp/Bitwarden.Sdk.Samples/Program.cs +++ b/languages/csharp/Bitwarden.Sdk.Samples/Program.cs @@ -1,31 +1,30 @@ using Bitwarden.Sdk; +// Configure secrets +var accessToken = Environment.GetEnvironmentVariable("ACCESS_TOKEN")!; +var organizationIdString = Environment.GetEnvironmentVariable("ORGANIZATION_ID")!; +var organizationId = Guid.Parse(organizationIdString); -var accessToken = Environment.GetEnvironmentVariable("ACCESS_TOKEN"); -var organizationIdStr = Environment.GetEnvironmentVariable("ORGANIZATION_ID"); - +// Create SDK Client using var bitwardenClient = new BitwardenClient(); + +// Authenticate bitwardenClient.AccessTokenLogin(accessToken); -var organizationId = Guid.Parse(organizationIdStr); + +// Project operations var projectResponse = bitwardenClient.Projects.Create(organizationId, "NewTestProject"); -var projectId = projectResponse.Id; var projectsResponse = bitwardenClient.Projects.List(organizationId); +var projectId = projectResponse.Id; projectResponse = bitwardenClient.Projects.Get(projectId); projectResponse = bitwardenClient.Projects.Update(projectId, organizationId, "NewTestProject2"); -var key = "key"; -var value = "value"; -var note = "note"; +// Secret operations var secretResponse = - bitwardenClient.Secrets.Create(key, value, note, organizationId, new Guid[] { projectId }); + bitwardenClient.Secrets.Create("key", "value", "note", organizationId, new[] { projectId }); var secretId = secretResponse.Id; -var responseForSecretIdentifiersResponse = bitwardenClient.Secrets.List(organizationId); +var secretIdentifiersResponse = bitwardenClient.Secrets.List(organizationId); secretResponse = bitwardenClient.Secrets.Get(secretId); -key = "key2"; -value = "value2"; -note = "note2"; secretResponse = bitwardenClient.Secrets - .Update(secretId, key, value, note, organizationId, new Guid[] { projectId }); - -var responseForSecretsDeleteResponse = bitwardenClient.Secrets.Delete(new Guid[] { secretId }); -var responseForProjectsDeleteResponse = bitwardenClient.Projects.Delete(new Guid[] { projectId }); + .Update(secretId, "key2", "value2", "note2", organizationId, new[] { projectId }); +bitwardenClient.Secrets.Delete(new[] { secretId }); +bitwardenClient.Projects.Delete(new[] { projectId }); From 884e8dd2e7edc10aec8556ea58994a8f3af42277 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Tue, 19 Sep 2023 22:06:27 +0200 Subject: [PATCH 93/94] update readme --- languages/csharp/README.md | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/languages/csharp/README.md b/languages/csharp/README.md index 4b6f48e60..dea2d1d22 100644 --- a/languages/csharp/README.md +++ b/languages/csharp/README.md @@ -19,8 +19,7 @@ bitwardenClient.AccessTokenLogin(accessToken); ### Create new project ```csharp -const string organizationIdStr = ""; -var organizationId = Guid.Parse(organizationIdStr); +var organizationId = Guid.Parse(""); var projectResponse = bitwardenClient.Projects().Create(organizationId, "TestProject"); ``` @@ -44,10 +43,16 @@ projectResponse = bitwardenClient.Projects.Update(projectId, organizationId, "Te var key = "key"; var value = "value"; var note = "note"; -var secretResponse = bitwardenClient.Secrets.Create(key, value, note, organizationId, new Guid[]{projectId}); +var secretResponse = bitwardenClient.Secrets.Create(key, value, note, organizationId, new[] { projectId }); var secretId = secretResponse.Id; ``` +### Update secret +```csharp +secretResponse = bitwardenClient.Secrets + .Update(secretId, "key2", "value2", "note2", organizationId, new[] { projectId }); +``` + ### List secrets ```csharp @@ -57,8 +62,8 @@ var secretIdentifiersResponse = bitwardenClient.Secrets.List(organizationId); # Delete secret or project ```csharp -var secretsDeleteResponse = bitwardenClient.Secrets.Delete(new Guid[]{secretId}); -var projectsDeleteResponse = bitwardenClient.Projects.Delete(new Guid[]{projectId}); +bitwardenClient.Secrets.Delete(new [] { secretId }); +bitwardenClient.Projects.Delete(new [] { projectId }); ``` [Access Tokens]: https://bitwarden.com/help/access-tokens/ From 76039dd67741d1a04d08caacf23d4262d55be963 Mon Sep 17 00:00:00 2001 From: Boris Bujak Date: Thu, 21 Sep 2023 10:40:25 +0200 Subject: [PATCH 94/94] reformat code --- .../Bitwarden.Sdk/BitwardenAuthException.cs | 11 ++++-- .../csharp/Bitwarden.Sdk/BitwardenClient.cs | 6 ++-- .../Bitwarden.Sdk/BitwardenException.cs | 11 ++++-- .../csharp/Bitwarden.Sdk/ProjectsClient.cs | 36 ++++++++++++++----- .../csharp/Bitwarden.Sdk/SecretsClient.cs | 30 +++++++++++++--- 5 files changed, 71 insertions(+), 23 deletions(-) diff --git a/languages/csharp/Bitwarden.Sdk/BitwardenAuthException.cs b/languages/csharp/Bitwarden.Sdk/BitwardenAuthException.cs index be88bdc6b..8a2b480de 100644 --- a/languages/csharp/Bitwarden.Sdk/BitwardenAuthException.cs +++ b/languages/csharp/Bitwarden.Sdk/BitwardenAuthException.cs @@ -1,8 +1,13 @@ namespace Bitwarden.Sdk; -public class BitwardenAuthException: Exception +public class BitwardenAuthException : Exception { - public BitwardenAuthException(string message) : base(message) { } + public BitwardenAuthException(string message) : base(message) + { + } + public BitwardenAuthException(string message, System.Exception innerException) - : base(message, innerException) { } + : base(message, innerException) + { + } } diff --git a/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs b/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs index acb59b4a3..617a3d00b 100644 --- a/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs +++ b/languages/csharp/Bitwarden.Sdk/BitwardenClient.cs @@ -9,9 +9,7 @@ public BitwardenClient(BitwardenSettings? settings = null) { var clientSettings = new ClientSettings { - ApiUrl = settings?.ApiUrl!, - IdentityUrl = settings?.IdentityUrl!, - UserAgent = "Bitwarden DOTNET-SDK" + ApiUrl = settings?.ApiUrl!, IdentityUrl = settings?.IdentityUrl!, UserAgent = "Bitwarden DOTNET-SDK" }; _handle = BitwardenLibrary.Init(clientSettings.ToJson()); @@ -23,7 +21,7 @@ public BitwardenClient(BitwardenSettings? settings = null) public void AccessTokenLogin(string accessToken) { var command = new Command() { AccessTokenLogin = new AccessTokenLoginRequest { AccessToken = accessToken } }; - var response = _commandRunner.RunCommand(command); + var response = _commandRunner.RunCommand(command); if (response is not { Success: true }) { throw new BitwardenAuthException(response != null ? response.ErrorMessage : "Login failed"); diff --git a/languages/csharp/Bitwarden.Sdk/BitwardenException.cs b/languages/csharp/Bitwarden.Sdk/BitwardenException.cs index 94db47740..539656bf4 100644 --- a/languages/csharp/Bitwarden.Sdk/BitwardenException.cs +++ b/languages/csharp/Bitwarden.Sdk/BitwardenException.cs @@ -1,8 +1,13 @@ namespace Bitwarden.Sdk; -public class BitwardenException: Exception +public class BitwardenException : Exception { - public BitwardenException(string message) : base(message) { } + public BitwardenException(string message) : base(message) + { + } + public BitwardenException(string message, System.Exception innerException) - : base(message, innerException) { } + : base(message, innerException) + { + } } diff --git a/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs b/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs index fc989ab4d..da22e2d7f 100644 --- a/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs +++ b/languages/csharp/Bitwarden.Sdk/ProjectsClient.cs @@ -14,7 +14,11 @@ public ProjectResponse Get(Guid id) var command = new Command() { Projects = new ProjectsCommand { Get = new ProjectGetRequest { Id = id } } }; var result = _commandRunner.RunCommand(command); - if (result is { Success: true }) { return result.Data; } + if (result is { Success: true }) + { + return result.Data; + } + throw new BitwardenException(result != null ? result.ErrorMessage : "Project not found"); } @@ -27,9 +31,13 @@ public ProjectResponse Create(Guid organizationId, string name) Create = new ProjectCreateRequest { OrganizationId = organizationId, Name = name } } }; - var result = _commandRunner.RunCommand(command); + var result = _commandRunner.RunCommand(command); + + if (result is { Success: true }) + { + return result.Data; + } - if (result is { Success: true }) { return result.Data; } throw new BitwardenException(result != null ? result.ErrorMessage : "Project create failed"); } @@ -42,9 +50,13 @@ public ProjectResponse Update(Guid id, Guid organizationId, string name) Update = new ProjectPutRequest { Id = id, OrganizationId = organizationId, Name = name } } }; - var result = _commandRunner.RunCommand(command); + var result = _commandRunner.RunCommand(command); + + if (result is { Success: true }) + { + return result.Data; + } - if (result is { Success: true }) { return result.Data; } throw new BitwardenException(result != null ? result.ErrorMessage : "Project update failed"); } @@ -56,7 +68,11 @@ public ProjectsDeleteResponse Delete(Guid[] ids) }; var result = _commandRunner.RunCommand(command); - if (result is { Success: true }) { return result.Data; } + if (result is { Success: true }) + { + return result.Data; + } + throw new BitwardenException(result != null ? result.ErrorMessage : "Project delete failed"); } @@ -66,9 +82,13 @@ public ProjectsResponse List(Guid organizationId) { Projects = new ProjectsCommand { List = new ProjectsListRequest { OrganizationId = organizationId } } }; - var result = _commandRunner.RunCommand(command); + var result = _commandRunner.RunCommand(command); + + if (result is { Success: true }) + { + return result.Data; + } - if (result is { Success: true }) { return result.Data; } throw new BitwardenException(result != null ? result.ErrorMessage : "No projects for given organization"); } } diff --git a/languages/csharp/Bitwarden.Sdk/SecretsClient.cs b/languages/csharp/Bitwarden.Sdk/SecretsClient.cs index 9aa968634..cf6cd36b1 100644 --- a/languages/csharp/Bitwarden.Sdk/SecretsClient.cs +++ b/languages/csharp/Bitwarden.Sdk/SecretsClient.cs @@ -14,7 +14,11 @@ public SecretResponse Get(Guid id) var command = new Command() { Secrets = new SecretsCommand { Get = new SecretGetRequest { Id = id } } }; var result = _commandRunner.RunCommand(command); - if (result is { Success: true }) { return result.Data; } + if (result is { Success: true }) + { + return result.Data; + } + throw new BitwardenException(result != null ? result.ErrorMessage : "Secret not found"); } @@ -38,7 +42,11 @@ public SecretResponse Create(string key, string value, string note, Guid organiz var result = _commandRunner.RunCommand(command); - if (result is { Success: true }) { return result.Data; } + if (result is { Success: true }) + { + return result.Data; + } + throw new BitwardenException(result != null ? result.ErrorMessage : "Secret create failed"); } @@ -63,7 +71,11 @@ public SecretResponse Update(Guid id, string key, string value, string note, Gui var result = _commandRunner.RunCommand(command); - if (result is { Success: true }) { return result.Data; } + if (result is { Success: true }) + { + return result.Data; + } + throw new BitwardenException(result != null ? result.ErrorMessage : "Secret update failed"); } @@ -75,7 +87,11 @@ public SecretsDeleteResponse Delete(Guid[] ids) }; var result = _commandRunner.RunCommand(command); - if (result is { Success: true }) { return result.Data; } + if (result is { Success: true }) + { + return result.Data; + } + throw new BitwardenException(result != null ? result.ErrorMessage : "Secrets delete failed"); } @@ -87,7 +103,11 @@ public SecretIdentifiersResponse List(Guid organizationId) }; var result = _commandRunner.RunCommand(command); - if (result is { Success: true }) { return result.Data; } + if (result is { Success: true }) + { + return result.Data; + } + throw new BitwardenException(result != null ? result.ErrorMessage : "No secrets for given organization"); } }