From 0366e860dac04dfca2101dd95b085d96b97d6a90 Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Wed, 21 Feb 2024 18:53:04 +0100 Subject: [PATCH] Rename ruby SDK to bitwarden-sdk-secrets (#618) ## Type of change ``` - [ ] Bug fix - [ ] New feature development - [x] Tech debt (refactoring, code cleanup, dependency upgrades, etc) - [ ] Build/deploy pipeline (DevOps) - [ ] Other ``` ## Objective Rename the ruby sdk to `bitwarden-sdk-secrets` to denote it's the secrets manager SDK. Updates the Also includes #565 since it won't run without that change. ## Before you submit - Please add **unit tests** where it makes sense to do so --------- Co-authored-by: Thomas Avery <43214426+Thomas-Avery@users.noreply.github.com> --- .github/workflows/generate_schemas.yml | 2 +- .github/workflows/publish-ruby.yml | 16 +++---- languages/ruby/.gitignore | 3 +- languages/ruby/README.md | 42 +++++++++++++++---- languages/ruby/bitwarden_sdk_secrets/Gemfile | 10 +++++ .../Rakefile | 3 ++ .../bitwarden-sdk-secrets.gemspec} | 6 +-- .../lib/bitwarden-sdk-secrets.rb} | 6 +-- .../lib/bitwarden_error.rb | 2 +- .../lib/bitwarden_lib.rb | 2 +- .../lib/command_runner.rb | 2 +- .../lib/extended_schemas/schemas.rb | 2 +- .../lib/projects.rb | 2 +- .../lib/secrets.rb | 2 +- .../lib/version.rb | 2 +- .../sig/bitwarden-sdk.rbs | 0 .../sig/bitwarden_settings.rbs | 0 .../sig/command_runner.rbs | 0 .../sig/projects_client.rbs | 0 .../sig/sdk.rbs | 0 .../sig/secrets_client.rbs | 0 .../spec/settings_spec.rb | 15 +++++++ languages/ruby/examples/example.rb | 6 +-- support/scripts/schemas.ts | 2 +- 24 files changed, 90 insertions(+), 35 deletions(-) create mode 100644 languages/ruby/bitwarden_sdk_secrets/Gemfile rename languages/ruby/{bitwarden_sdk => bitwarden_sdk_secrets}/Rakefile (69%) rename languages/ruby/{bitwarden_sdk/bitwarden-sdk.gemspec => bitwarden_sdk_secrets/bitwarden-sdk-secrets.gemspec} (93%) rename languages/ruby/{bitwarden_sdk/lib/bitwarden-sdk.rb => bitwarden_sdk_secrets/lib/bitwarden-sdk-secrets.rb} (91%) rename languages/ruby/{bitwarden_sdk => bitwarden_sdk_secrets}/lib/bitwarden_error.rb (85%) rename languages/ruby/{bitwarden_sdk => bitwarden_sdk_secrets}/lib/bitwarden_lib.rb (98%) rename languages/ruby/{bitwarden_sdk => bitwarden_sdk_secrets}/lib/command_runner.rb (91%) rename languages/ruby/{bitwarden_sdk => bitwarden_sdk_secrets}/lib/extended_schemas/schemas.rb (98%) rename languages/ruby/{bitwarden_sdk => bitwarden_sdk_secrets}/lib/projects.rb (99%) rename languages/ruby/{bitwarden_sdk => bitwarden_sdk_secrets}/lib/secrets.rb (99%) rename languages/ruby/{bitwarden_sdk => bitwarden_sdk_secrets}/lib/version.rb (67%) rename languages/ruby/{bitwarden_sdk => bitwarden_sdk_secrets}/sig/bitwarden-sdk.rbs (100%) rename languages/ruby/{bitwarden_sdk => bitwarden_sdk_secrets}/sig/bitwarden_settings.rbs (100%) rename languages/ruby/{bitwarden_sdk => bitwarden_sdk_secrets}/sig/command_runner.rbs (100%) rename languages/ruby/{bitwarden_sdk => bitwarden_sdk_secrets}/sig/projects_client.rbs (100%) rename languages/ruby/{bitwarden_sdk => bitwarden_sdk_secrets}/sig/sdk.rbs (100%) rename languages/ruby/{bitwarden_sdk => bitwarden_sdk_secrets}/sig/secrets_client.rbs (100%) create mode 100644 languages/ruby/bitwarden_sdk_secrets/spec/settings_spec.rb diff --git a/.github/workflows/generate_schemas.yml b/.github/workflows/generate_schemas.yml index 025b85105..301a9a805 100644 --- a/.github/workflows/generate_schemas.yml +++ b/.github/workflows/generate_schemas.yml @@ -61,7 +61,7 @@ jobs: uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # v4.3.1 with: name: schemas.rb - path: ${{ github.workspace }}/languages/ruby/bitwarden_sdk/lib/schemas.rb + path: ${{ github.workspace }}/languages/ruby/bitwarden_sdk_secrets/lib/schemas.rb if-no-files-found: error - name: Upload json schemas artifact diff --git a/.github/workflows/publish-ruby.yml b/.github/workflows/publish-ruby.yml index 3dce457b2..e8c2f8254 100644 --- a/.github/workflows/publish-ruby.yml +++ b/.github/workflows/publish-ruby.yml @@ -31,7 +31,7 @@ jobs: uses: actions/download-artifact@eaceaf801fd36c7dee90939fad912460b18a1ffe # v4.1.2 with: name: schemas.rb - path: languages/ruby/bitwarden_sdk/lib + path: languages/ruby/bitwarden_sdk_secrets/lib - name: Download x86_64-apple-darwin files uses: actions/download-artifact@eaceaf801fd36c7dee90939fad912460b18a1ffe # v4.1.2 @@ -59,22 +59,22 @@ jobs: - name: Copy lib files run: | - mkdir -p languages/ruby/bitwarden_sdk/lib/macos-arm64 - mkdir -p languages/ruby/bitwarden_sdk/lib/linux-x64 - mkdir -p languages/ruby/bitwarden_sdk/lib/macos-x64 - mkdir -p languages/ruby/bitwarden_sdk/lib/windows-x64 + mkdir -p languages/ruby/bitwarden_sdk_secrets/lib/macos-arm64 + mkdir -p languages/ruby/bitwarden_sdk_secrets/lib/linux-x64 + mkdir -p languages/ruby/bitwarden_sdk_secrets/lib/macos-x64 + mkdir -p languages/ruby/bitwarden_sdk_secrets/lib/windows-x64 platforms=("macos-arm64" "linux-x64" "macos-x64" "windows-x64") files=("libbitwarden_c.dylib" "libbitwarden_c.so" "libbitwarden_c.dylib" "bitwarden_c.dll") for ((i=0; i<${#platforms[@]}; i++)); do - cp "temp/${platforms[$i]}/${files[$i]}" "languages/ruby/bitwarden_sdk/lib/${platforms[$i]}/${files[$i]}" + cp "temp/${platforms[$i]}/${files[$i]}" "languages/ruby/bitwarden_sdk_secrets/lib/${platforms[$i]}/${files[$i]}" done shell: bash - name: Build gem run: gem build bitwarden-sdk.gemspec - working-directory: languages/ruby/bitwarden_sdk + working-directory: languages/ruby/bitwarden_sdk_secrets - name: Push gem to Rubygems run: | @@ -85,4 +85,4 @@ jobs: gem push *.gem env: GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }} - working-directory: languages/ruby/bitwarden_sdk + working-directory: languages/ruby/bitwarden_sdk_secrets diff --git a/languages/ruby/.gitignore b/languages/ruby/.gitignore index f0e7bd4c1..92b76b424 100644 --- a/languages/ruby/.gitignore +++ b/languages/ruby/.gitignore @@ -1,3 +1,4 @@ *.lock *.gem -bitwarden_sdk/lib/schemas.rb +bitwarden_sdk_secrets/lib/schemas.rb +bitwarden_sdk_secrets/pkg diff --git a/languages/ruby/README.md b/languages/ruby/README.md index d02d5c500..e9fb61e0c 100644 --- a/languages/ruby/README.md +++ b/languages/ruby/README.md @@ -1,24 +1,23 @@ # Bitwarden Secrets Manager SDK -Ruby bindings for interacting with the [Bitwarden Secrets Manager]. This is a beta release and might be missing some functionality. +Ruby bindings for interacting with the [Bitwarden Secrets Manager]. This is a beta release and might +be missing some functionality. ## Installation Requirements: Ruby >= 3.0 -Install gem: `gem install bitwarden-sdk` - -Import it: require 'bitwarden-sdk' +Install gem: `gem install bitwarden-sdk-secrets` +Import it: require 'bitwarden-sdk-secrets' ## Usage -To interact with client first you need to obtain access token from Bitwarden. -Client will be initialized with default client settings if they are not provided -via env variables. +To interact with client first you need to obtain access token from Bitwarden. Client will be +initialized with default client settings if they are not provided via env variables. ```ruby -require 'bitwarden-sdk' +require 'bitwarden-sdk-secrets' # then you can initialize BitwardenSettings: bitwarden_settings = BitwardenSDK::BitwardenSettings.new( @@ -34,6 +33,7 @@ puts response ``` After successful authorization you can interact with client to manage your projects and secrets. + ```ruby # CREATE project @@ -61,6 +61,7 @@ puts response ``` Similarly, you interact with secrets: + ```ruby # CREATE secret key = 'AWS-SES' @@ -92,4 +93,29 @@ puts response response = bw_client.secrets_client.delete_secret([secret_id]) puts response ``` + +## Development + +```bash +# Build and copy the bitwarden-c library +cargo build --package bitwarden-c +cp ../../target/debug/libbitwarden_c.dylib ./bitwarden_sdk_secrets/lib/macos-arm64/libbitwarden_c.dylib + +# Install ruby dependencies +cd ./bitwarden_sdk_secrets +bundle install + +# Install the gem +bundle exec rake install + +## Run example tests +cd .. +export ACCESS_TOKEN="" +export ORGANIZATION_ID="" + +export API_URL=https://localhost:8080/api +export IDENTITY_URL=https://localhost:8080/identity +ruby examples/example.rb +``` + [Bitwarden Secrets Manager]: https://bitwarden.com/products/secrets-manager/ diff --git a/languages/ruby/bitwarden_sdk_secrets/Gemfile b/languages/ruby/bitwarden_sdk_secrets/Gemfile new file mode 100644 index 000000000..0f3963489 --- /dev/null +++ b/languages/ruby/bitwarden_sdk_secrets/Gemfile @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +# Specify your gem's dependencies in exmp.gemspec +gemspec + +gem "rake", "~> 13.0" +gem "rspec", "~> 3.0" +gem "rubocop", "~> 1.21" diff --git a/languages/ruby/bitwarden_sdk/Rakefile b/languages/ruby/bitwarden_sdk_secrets/Rakefile similarity index 69% rename from languages/ruby/bitwarden_sdk/Rakefile rename to languages/ruby/bitwarden_sdk_secrets/Rakefile index 192414345..30550c5de 100644 --- a/languages/ruby/bitwarden_sdk/Rakefile +++ b/languages/ruby/bitwarden_sdk_secrets/Rakefile @@ -2,6 +2,9 @@ require "bundler/gem_tasks" require "rubocop/rake_task" +require 'rspec/core/rake_task' + +RSpec::Core::RakeTask.new RuboCop::RakeTask.new diff --git a/languages/ruby/bitwarden_sdk/bitwarden-sdk.gemspec b/languages/ruby/bitwarden_sdk_secrets/bitwarden-sdk-secrets.gemspec similarity index 93% rename from languages/ruby/bitwarden_sdk/bitwarden-sdk.gemspec rename to languages/ruby/bitwarden_sdk_secrets/bitwarden-sdk-secrets.gemspec index d11a57f38..457e60a3e 100644 --- a/languages/ruby/bitwarden_sdk/bitwarden-sdk.gemspec +++ b/languages/ruby/bitwarden_sdk_secrets/bitwarden-sdk-secrets.gemspec @@ -3,8 +3,8 @@ require_relative 'lib/version' Gem::Specification.new do |spec| - spec.name = 'bitwarden-sdk' - spec.version = BitwardenSDK::VERSION + spec.name = 'bitwarden-sdk-secrets' + spec.version = BitwardenSDKSecrets::VERSION spec.authors = ['Bitwarden Inc.'] spec.email = ['hello@bitwarden_sdk.com'] @@ -21,7 +21,7 @@ Gem::Specification.new do |spec| # The `git ls-files -z` loads the files in the RubyGem that have been added into git. spec.files = Dir.chdir(__dir__) do `git ls-files -z`.split("\x0").reject do |f| - (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor]) + (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git Gemfile]) end end diff --git a/languages/ruby/bitwarden_sdk/lib/bitwarden-sdk.rb b/languages/ruby/bitwarden_sdk_secrets/lib/bitwarden-sdk-secrets.rb similarity index 91% rename from languages/ruby/bitwarden_sdk/lib/bitwarden-sdk.rb rename to languages/ruby/bitwarden_sdk_secrets/lib/bitwarden-sdk-secrets.rb index b023402da..15cd115d1 100644 --- a/languages/ruby/bitwarden_sdk/lib/bitwarden-sdk.rb +++ b/languages/ruby/bitwarden_sdk_secrets/lib/bitwarden-sdk-secrets.rb @@ -11,7 +11,7 @@ require_relative 'projects' require_relative 'secrets' -module BitwardenSDK +module BitwardenSDKSecrets class BitwardenSettings attr_accessor :api_url, :identity_url @@ -43,8 +43,8 @@ def initialize(bitwarden_settings) @secrets_client = SecretsClient.new(@command_runner) end - def access_token_login(access_token) - access_token_request = AccessTokenLoginRequest.new(access_token: access_token) + def access_token_login(access_token, state_file = nil) + access_token_request = AccessTokenLoginRequest.new(access_token: access_token, state_file: state_file) @command_runner.run(SelectiveCommand.new(access_token_login: access_token_request)) nil end diff --git a/languages/ruby/bitwarden_sdk/lib/bitwarden_error.rb b/languages/ruby/bitwarden_sdk_secrets/lib/bitwarden_error.rb similarity index 85% rename from languages/ruby/bitwarden_sdk/lib/bitwarden_error.rb rename to languages/ruby/bitwarden_sdk_secrets/lib/bitwarden_error.rb index ec9adf932..b2239e29b 100644 --- a/languages/ruby/bitwarden_sdk/lib/bitwarden_error.rb +++ b/languages/ruby/bitwarden_sdk_secrets/lib/bitwarden_error.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module BitwardenSDK +module BitwardenSDKSecrets class BitwardenError < StandardError def initialize(message = 'Error getting response') super(message) diff --git a/languages/ruby/bitwarden_sdk/lib/bitwarden_lib.rb b/languages/ruby/bitwarden_sdk_secrets/lib/bitwarden_lib.rb similarity index 98% rename from languages/ruby/bitwarden_sdk/lib/bitwarden_lib.rb rename to languages/ruby/bitwarden_sdk_secrets/lib/bitwarden_lib.rb index 8217d87b0..05ab51421 100644 --- a/languages/ruby/bitwarden_sdk/lib/bitwarden_lib.rb +++ b/languages/ruby/bitwarden_sdk_secrets/lib/bitwarden_lib.rb @@ -2,7 +2,7 @@ require 'ffi' -module BitwardenSDK +module BitwardenSDKSecrets module BitwardenLib extend FFI::Library diff --git a/languages/ruby/bitwarden_sdk/lib/command_runner.rb b/languages/ruby/bitwarden_sdk_secrets/lib/command_runner.rb similarity index 91% rename from languages/ruby/bitwarden_sdk/lib/command_runner.rb rename to languages/ruby/bitwarden_sdk_secrets/lib/command_runner.rb index 7da2269b6..80e846a80 100644 --- a/languages/ruby/bitwarden_sdk/lib/command_runner.rb +++ b/languages/ruby/bitwarden_sdk_secrets/lib/command_runner.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module BitwardenSDK +module BitwardenSDKSecrets class CommandRunner def initialize(bitwarden_sdk, handle) @bitwarden_sdk = bitwarden_sdk diff --git a/languages/ruby/bitwarden_sdk/lib/extended_schemas/schemas.rb b/languages/ruby/bitwarden_sdk_secrets/lib/extended_schemas/schemas.rb similarity index 98% rename from languages/ruby/bitwarden_sdk/lib/extended_schemas/schemas.rb rename to languages/ruby/bitwarden_sdk_secrets/lib/extended_schemas/schemas.rb index be7ca2cbc..e2352237f 100644 --- a/languages/ruby/bitwarden_sdk/lib/extended_schemas/schemas.rb +++ b/languages/ruby/bitwarden_sdk_secrets/lib/extended_schemas/schemas.rb @@ -1,5 +1,5 @@ -module BitwardenSDK +module BitwardenSDKSecrets class SelectiveCommand < Command attribute :password_login, PasswordLoginRequest.optional.default(nil) attribute :api_key_login, APIKeyLoginRequest.optional.default(nil) diff --git a/languages/ruby/bitwarden_sdk/lib/projects.rb b/languages/ruby/bitwarden_sdk_secrets/lib/projects.rb similarity index 99% rename from languages/ruby/bitwarden_sdk/lib/projects.rb rename to languages/ruby/bitwarden_sdk_secrets/lib/projects.rb index 4363fcb9e..957a7d31d 100644 --- a/languages/ruby/bitwarden_sdk/lib/projects.rb +++ b/languages/ruby/bitwarden_sdk_secrets/lib/projects.rb @@ -2,7 +2,7 @@ require_relative 'bitwarden_error' -module BitwardenSDK +module BitwardenSDKSecrets class ProjectsClient def initialize(command_runner) @command_runner = command_runner diff --git a/languages/ruby/bitwarden_sdk/lib/secrets.rb b/languages/ruby/bitwarden_sdk_secrets/lib/secrets.rb similarity index 99% rename from languages/ruby/bitwarden_sdk/lib/secrets.rb rename to languages/ruby/bitwarden_sdk_secrets/lib/secrets.rb index 0eca98993..709d8f8b1 100644 --- a/languages/ruby/bitwarden_sdk/lib/secrets.rb +++ b/languages/ruby/bitwarden_sdk_secrets/lib/secrets.rb @@ -2,7 +2,7 @@ require 'json' -module BitwardenSDK +module BitwardenSDKSecrets class SecretsClient def initialize(command_runner) @command_runner = command_runner diff --git a/languages/ruby/bitwarden_sdk/lib/version.rb b/languages/ruby/bitwarden_sdk_secrets/lib/version.rb similarity index 67% rename from languages/ruby/bitwarden_sdk/lib/version.rb rename to languages/ruby/bitwarden_sdk_secrets/lib/version.rb index 1fd8c02c1..199ec8ca6 100644 --- a/languages/ruby/bitwarden_sdk/lib/version.rb +++ b/languages/ruby/bitwarden_sdk_secrets/lib/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -module BitwardenSDK +module BitwardenSDKSecrets VERSION = '0.0.0' end diff --git a/languages/ruby/bitwarden_sdk/sig/bitwarden-sdk.rbs b/languages/ruby/bitwarden_sdk_secrets/sig/bitwarden-sdk.rbs similarity index 100% rename from languages/ruby/bitwarden_sdk/sig/bitwarden-sdk.rbs rename to languages/ruby/bitwarden_sdk_secrets/sig/bitwarden-sdk.rbs diff --git a/languages/ruby/bitwarden_sdk/sig/bitwarden_settings.rbs b/languages/ruby/bitwarden_sdk_secrets/sig/bitwarden_settings.rbs similarity index 100% rename from languages/ruby/bitwarden_sdk/sig/bitwarden_settings.rbs rename to languages/ruby/bitwarden_sdk_secrets/sig/bitwarden_settings.rbs diff --git a/languages/ruby/bitwarden_sdk/sig/command_runner.rbs b/languages/ruby/bitwarden_sdk_secrets/sig/command_runner.rbs similarity index 100% rename from languages/ruby/bitwarden_sdk/sig/command_runner.rbs rename to languages/ruby/bitwarden_sdk_secrets/sig/command_runner.rbs diff --git a/languages/ruby/bitwarden_sdk/sig/projects_client.rbs b/languages/ruby/bitwarden_sdk_secrets/sig/projects_client.rbs similarity index 100% rename from languages/ruby/bitwarden_sdk/sig/projects_client.rbs rename to languages/ruby/bitwarden_sdk_secrets/sig/projects_client.rbs diff --git a/languages/ruby/bitwarden_sdk/sig/sdk.rbs b/languages/ruby/bitwarden_sdk_secrets/sig/sdk.rbs similarity index 100% rename from languages/ruby/bitwarden_sdk/sig/sdk.rbs rename to languages/ruby/bitwarden_sdk_secrets/sig/sdk.rbs diff --git a/languages/ruby/bitwarden_sdk/sig/secrets_client.rbs b/languages/ruby/bitwarden_sdk_secrets/sig/secrets_client.rbs similarity index 100% rename from languages/ruby/bitwarden_sdk/sig/secrets_client.rbs rename to languages/ruby/bitwarden_sdk_secrets/sig/secrets_client.rbs diff --git a/languages/ruby/bitwarden_sdk_secrets/spec/settings_spec.rb b/languages/ruby/bitwarden_sdk_secrets/spec/settings_spec.rb new file mode 100644 index 000000000..9db0e340d --- /dev/null +++ b/languages/ruby/bitwarden_sdk_secrets/spec/settings_spec.rb @@ -0,0 +1,15 @@ +require 'schemas' +require 'extended_schemas/schemas' + +describe ClientSettings do + it "test" do + client_settings = ClientSettings.new( + api_url: nil, + identity_url: nil, + user_agent: 'Bitwarden RUBY-SDK', + device_type: nil + ) + + expect(client_settings.to_dynamic.compact.to_json).to eq('{"userAgent":"Bitwarden RUBY-SDK"}') + end +end diff --git a/languages/ruby/examples/example.rb b/languages/ruby/examples/example.rb index 09192aa5d..3c8e2045d 100644 --- a/languages/ruby/examples/example.rb +++ b/languages/ruby/examples/example.rb @@ -1,5 +1,5 @@ # NOTE - for example purpose only - import gem instead -require 'bitwarden-sdk' +require 'bitwarden-sdk-secrets' token = ENV['ACCESS_TOKEN'] organization_id = ENV['ORGANIZATION_ID'] @@ -8,9 +8,9 @@ api_url = ENV['API_URL'] identity_url = ENV['IDENTITY_URL'] -bitwarden_settings = BitwardenSDK::BitwardenSettings.new(api_url, identity_url) +bitwarden_settings = BitwardenSDKSecrets::BitwardenSettings.new(api_url, identity_url) -bw_client = BitwardenSDK::BitwardenClient.new(bitwarden_settings) +bw_client = BitwardenSDKSecrets::BitwardenClient.new(bitwarden_settings) response = bw_client.access_token_login(token) puts response diff --git a/support/scripts/schemas.ts b/support/scripts/schemas.ts index f045b0f5a..757878334 100644 --- a/support/scripts/schemas.ts +++ b/support/scripts/schemas.ts @@ -60,7 +60,7 @@ async function main() { }, }); - writeToFile("./languages/ruby/bitwarden_sdk/lib/schemas.rb", ruby.lines); + writeToFile("./languages/ruby/bitwarden_sdk_secrets/lib/schemas.rb", ruby.lines); const csharp = await quicktype({ inputData,