Skip to main content
If you’re working with Ruby, the official Infisical Ruby SDK package is the easiest way to fetch and work with secrets for your application.

Basic Usage

This example demonstrates how to use the Infisical Ruby SDK in a simple Ruby application. The application retrieves a secret named API_KEY from the dev environment of the YOUR_PROJECT_ID project.
We do not recommend hardcoding your Machine Identity Tokens. Setting it as an environment variable would be best.

Installation

The SDK requires Ruby 3.0.0 or higher.
Or add it to your Gemfile:

Configuration

Require the SDK and create a client instance. The require path is "infisical".

Configuration Options

object

Authentication

The SDK authenticates as a machine identity. The most common authentication method is Universal Auth, which uses a client ID and client secret. If you already have a valid access token, you can also set it on the client directly.

Universal Auth

Log in with a machine identity’s client ID and client secret. On success, the returned access token is stored on the client and used for all subsequent requests.
Parameters
object

Access Token

If you already have a valid access token, set it on the client directly instead of logging in. This does not make a network request.
Parameters
string
required
The access token to authenticate with. This should not include the Bearer prefix.

Secrets

List Secrets

client.secrets.list(options) Retrieve all secrets within a project and environment. Returns an array of secret objects sorted by key.
Parameters
object

Retrieve Secret

client.secrets.get(secret_name, options) Retrieve a single secret by name. Raises Infisical::NotFoundError if the secret does not exist.
Parameters
object

Create Secret

client.secrets.create(secret_name, secret_value, options) Create a new secret. Returns the created secret.
Parameters
object

Update Secret

client.secrets.update(secret_name, options) Update an existing secret’s value, rename it, or both. You must provide at least one of secret_value or new_secret_name, otherwise an ArgumentError is raised. Returns the updated secret.
Parameters
object

Delete Secret

client.secrets.delete(secret_name, options) Delete a secret by name. Raises Infisical::NotFoundError if the secret does not exist. Returns the deleted secret.
Parameters
object

The Secret object

Every secret operation returns an Infisical::Models::Secret with the following readers:
object