Skip to content

Commit

Permalink
Rename ruby SDK to bitwarden-sdk-secrets (#618)
Browse files Browse the repository at this point in the history
## Type of change

<!-- (mark with an `X`) -->

```
- [ ] Bug fix
- [ ] New feature development
- [x] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other
```

## Objective

<!--Describe what the purpose of this PR is. For example: what bug
you're fixing or what new feature you're adding-->

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 <[email protected]>
  • Loading branch information
Hinton and Thomas-Avery authored Feb 21, 2024
1 parent ff94313 commit 0366e86
Show file tree
Hide file tree
Showing 24 changed files with 90 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/generate_schemas.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/publish-ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: |
Expand All @@ -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
3 changes: 2 additions & 1 deletion languages/ruby/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.lock
*.gem
bitwarden_sdk/lib/schemas.rb
bitwarden_sdk_secrets/lib/schemas.rb
bitwarden_sdk_secrets/pkg
42 changes: 34 additions & 8 deletions languages/ruby/README.md
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -34,6 +33,7 @@ puts response
```

After successful authorization you can interact with client to manage your projects and secrets.

```ruby

# CREATE project
Expand Down Expand Up @@ -61,6 +61,7 @@ puts response
```

Similarly, you interact with secrets:

```ruby
# CREATE secret
key = 'AWS-SES'
Expand Down Expand Up @@ -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/
10 changes: 10 additions & 0 deletions languages/ruby/bitwarden_sdk_secrets/Gemfile
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

require "bundler/gem_tasks"
require "rubocop/rake_task"
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new

RuboCop::RakeTask.new

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
require_relative 'projects'
require_relative 'secrets'

module BitwardenSDK
module BitwardenSDKSecrets
class BitwardenSettings
attr_accessor :api_url, :identity_url

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module BitwardenSDK
module BitwardenSDKSecrets
class BitwardenError < StandardError
def initialize(message = 'Error getting response')
super(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'ffi'

module BitwardenSDK
module BitwardenSDKSecrets
module BitwardenLib
extend FFI::Library

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module BitwardenSDK
module BitwardenSDKSecrets
class CommandRunner
def initialize(bitwarden_sdk, handle)
@bitwarden_sdk = bitwarden_sdk
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require_relative 'bitwarden_error'

module BitwardenSDK
module BitwardenSDKSecrets
class ProjectsClient
def initialize(command_runner)
@command_runner = command_runner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'json'

module BitwardenSDK
module BitwardenSDKSecrets
class SecretsClient
def initialize(command_runner)
@command_runner = command_runner
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module BitwardenSDK
module BitwardenSDKSecrets
VERSION = '0.0.0'
end
File renamed without changes.
15 changes: 15 additions & 0 deletions languages/ruby/bitwarden_sdk_secrets/spec/settings_spec.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 3 additions & 3 deletions languages/ruby/examples/example.rb
Original file line number Diff line number Diff line change
@@ -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']
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion support/scripts/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 0366e86

Please sign in to comment.