Secrets Manager Ruby SDK

The Ruby language wrapper for interacting with the Bitwarden Secrets Manager. The SDK, like the Secrets Manager CLI built on-top of it, can be used to execute the following operations:

  • Authenticate using an access token.

  • Retrieve a single secret or all secrets in a project.

  • List all secrets, secrets in a project, or projects.

noot

This SDK is a beta release. Therefore, some functionality may be missing.

Requirements

Setting up a Secrets Manager account prior to using the Ruby SDK is recommended. This includes:

Dependencies

  • Ruby version 3.0 or newer

  • Install gem

    Bash
    gem install bitwarden-sdk-secrets
  • Import it: require 'bitwarden-sdk-secrets'

GitHub Repository

Locate the Ruby GitHub repository here.

Local Build

To interact with the client, you must first obtain an access token from Bitwarden. Client will be initialized with default client settings if they are not provided from env variables.

Bash
require 'bitwarden-sdk-secrets' # then you can initialize BitwardenSettings: bitwarden_settings = BitwardenSDK::BitwardenSettings.new( 'https://api.bitwarden.com', 'https://identity.bitwarden.com' ) # By passing these setting you can initialize BitwardenClient bw_client = BitwardenSDK::BitwardenClient.new(bitwarden_settings) response = bw_client.access_token_login(token) puts response

Once the Secrets Manager session has been authorized, you may interact with the client.

Secrets Manager operations

Once the Bitwarden client has been created and authorized, Secrets Manager CLI commands can be passed into the client.

Projects

The project command is used to access, manipulate, and create projects. The scope of access assigned to your machine account will determine what actions can be completed with the project command.

create project

Bash
project_name = 'Test project 1' response = bw_client.project_client.create_project(project_name, organization_id) puts response project_id = response['id']

get project

Bash
response = bw_client.project_client.get(project_id) puts response

list project

Bash
response = bw_client.project_client.get(project_id) puts response

list projects

Bash
response = bw_client.project_client.list_projects(organization_id) puts response

update project

Bash
name = 'Updated test project 1' response = bw_client.project_client.update_project(project_id, name, organization_id) puts response

delete project

Bash
response = bw_client.project_client.delete_projects([project_id]) puts response

Secrets

The secret command is used to access, manipulate and create secrets. As with all commands, secrets and projects outside your access token's scope of access cannot be read or written-to.

create project

Bash
key = 'AWS-SES' note = 'Private account' value = '8t27.dfj;' response = bw_client.secrets_client.create(key, note, organization_id, [project_id], value) puts response secret_id = response['id']

get secret

Bash
response = bw_client.secrets_client.get(secret_id) puts response

get secrets by ids

Bash
response = bw_client.secrets_client.get_by_ids([secret_id]) puts response

list secrets

Bash
response = bw_client.secrets_client.list(organization_id) puts response

update secret

Bash
note = 'updated password' value = '7I.ert10AjK' response = bw_client.secrets_client.update(secret_id, key, note,organization_id, [project_id], value) puts response

delete secret

Bash
response = bw_client.secrets_client.delete_secret([secret_id]) puts response

Development

Prerequisites:

  • Ruby version 3.0 or newer installed

  • Generate schemas:

    Bash
    npm run schemas

  1. Navigate to the Ruby language folder:

    Bash
    cd languages/ruby
  2. Create the binary folder if it does not already exist:

    Bash
    mkdir -p ./bitwarden_sdk_secrets/lib/macos-arm64
  3. Build and copy the bitwarden-c library:

    Bash
    cargo build --package bitwarden-c cp ../../target/debug/libbitwarden_c.dylib ./bitwarden_sdk_secrets/lib/macos-arm64/libbitwarden_c.dylib
  4. Install Ruby dependencies:

    Bash
    cd ./bitwarden_sdk_secrets bundle install
  5. Install the gem:

    Bash
    bundle exec rake install

Run example tests:

Bash
cd .. export ACCESS_TOKEN="" export ORGANIZATION_ID="" export API_URL=http://localhost:4000 export IDENTITY_URL=http://localhost:33656 ruby examples/example.rb

Make a suggestion to this page

Neem contact op met ons ondersteuningsteam

Voor technische, factuur- en productvragen.

Naam*
Bitwarden account e-mail*
Account e-mail verifiëren*
Product*
Ben je zelf hostend?*
Onderwerp*
Bericht...*

Wolkenstatus

Status controleren

© 2024 Bitwarden, Inc. Voorwaarden Privacy Cookie-instellingen Sitemap

Go to EnglishStay Here