|
1 | | -# ruby-sdk |
| 1 | +<h1 align="center">Infisical Ruby SDK</h1> |
| 2 | + |
| 3 | +<h4 align="center"> |
| 4 | + <a href="https://infisical.com/docs/sdks/languages/ruby">Documentation</a> | |
| 5 | + <a href="https://www.infisical.com">Website</a> | |
| 6 | + <a href="https://infisical.com/slack">Slack</a> |
| 7 | +</h4> |
| 8 | + |
| 9 | +## Introduction |
| 10 | + |
| 11 | +**[Infisical](https://infisical.com)** is the open source secret management platform that teams use to centralize their secrets like API keys, database credentials, and configurations. |
| 12 | + |
| 13 | +This is the official native Ruby SDK — it talks directly to the Infisical REST API and has no Rust/FFI dependency. It replaces the deprecated `infisical-sdk` gem that was built on Infisical's legacy cross-language architecture, so it is **not** a drop-in replacement: the public API differs from the old gem. |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +```ruby |
| 18 | +gem "infisical-sdk" |
| 19 | +``` |
| 20 | + |
| 21 | +## Quick start |
| 22 | + |
| 23 | +```ruby |
| 24 | +require "infisical" |
| 25 | + |
| 26 | +client = Infisical::Client.new |
| 27 | + |
| 28 | +client.auth.universal_auth_login( |
| 29 | + client_id: ENV.fetch("INFISICAL_CLIENT_ID"), |
| 30 | + client_secret: ENV.fetch("INFISICAL_CLIENT_SECRET") |
| 31 | +) |
| 32 | + |
| 33 | +secrets = client.secrets.list( |
| 34 | + project_id: "<your-project-id>", |
| 35 | + environment: "dev" |
| 36 | +) |
| 37 | + |
| 38 | +secrets.each { |secret| puts "#{secret.secret_key}=#{secret.secret_value}" } |
| 39 | +``` |
| 40 | + |
| 41 | +### Authentication |
| 42 | + |
| 43 | +```ruby |
| 44 | +# Universal Auth (machine identity client id/secret). Returns the full |
| 45 | +# credential, so you can build your own token refresh on top of it. |
| 46 | +credential = client.auth.universal_auth_login(client_id: "...", client_secret: "...") |
| 47 | +credential.access_token # the token this client now uses |
| 48 | +credential.expires_in # seconds until it expires |
| 49 | +credential.access_token_max_ttl |
| 50 | +credential.token_type # "Bearer" |
| 51 | + |
| 52 | +# Or use a token you already have |
| 53 | +client.auth.access_token("existing-access-token") |
| 54 | +``` |
| 55 | + |
| 56 | +### Secrets |
| 57 | + |
| 58 | +```ruby |
| 59 | +client.secrets.list(project_id: "...", environment: "dev", secret_path: "/") |
| 60 | + |
| 61 | +# Imported secrets are folded in by default; pass include_imports: false to |
| 62 | +# opt out. Recursive mode collapses duplicate keys across folders to one |
| 63 | +# secret per key unless skip_unique_validation: true is passed. |
| 64 | +client.secrets.list(project_id: "...", environment: "dev", recursive: true) |
| 65 | + |
| 66 | +# Export fetched secrets into the process environment (never overrides |
| 67 | +# variables that already have a value): |
| 68 | +client.secrets.list(project_id: "...", environment: "dev", attach_to_process_env: true) |
| 69 | +ENV.fetch("DATABASE_URL") |
| 70 | + |
| 71 | +client.secrets.get("DATABASE_URL", project_id: "...", environment: "dev") |
| 72 | +client.secrets.create("DATABASE_URL", "postgres://...", project_id: "...", environment: "dev") |
| 73 | +client.secrets.update("DATABASE_URL", project_id: "...", environment: "dev", secret_value: "postgres://...") |
| 74 | +client.secrets.delete("DATABASE_URL", project_id: "...", environment: "dev") |
| 75 | + |
| 76 | +# create and update accept skip_multiline_encoding: true to disable the |
| 77 | +# API's encoding of multi-line values. |
| 78 | +``` |
| 79 | + |
| 80 | +Each returned secret exposes `secret_key`, `secret_value`, `secret_comment`, |
| 81 | +`secret_path`, `version`, `metadata` (an array of key/value entries), and |
| 82 | +`tags` (an array with `id`, `slug`, `name`, and `color`). |
| 83 | + |
| 84 | +### Error handling |
| 85 | + |
| 86 | +Every error raised by the SDK inherits from `Infisical::Error`. API failures |
| 87 | +raise `Infisical::APIError` (with `status`, `url`, `http_method`, and |
| 88 | +`request_id` readers), and well-known statuses raise a dedicated subclass: |
| 89 | + |
| 90 | +```ruby |
| 91 | +begin |
| 92 | + client.secrets.get("DATABASE_URL", project_id: "...", environment: "dev") |
| 93 | +rescue Infisical::NotFoundError # 404 |
| 94 | + # secret does not exist |
| 95 | +rescue Infisical::AuthenticationError # 401: bad or expired credentials |
| 96 | + # re-authenticate |
| 97 | +rescue Infisical::APIError => e # anything else the API rejected |
| 98 | + # e.status, e.url, e.http_method, e.request_id |
| 99 | +end |
| 100 | +``` |
| 101 | + |
| 102 | +Also available: `Infisical::PermissionError` (403), `Infisical::RateLimitError` |
| 103 | +(429, raised only after automatic retries are exhausted), and |
| 104 | +`Infisical::ServerError` (5xx). Network-level failures (timeouts, DNS, |
| 105 | +connection resets) raise `Infisical::RequestError` after retries. |
| 106 | + |
| 107 | +### Self-hosted instances |
| 108 | + |
| 109 | +```ruby |
| 110 | +client = Infisical::Client.new(site_url: "https://your-infisical-instance.com") |
| 111 | +``` |
| 112 | + |
| 113 | +A trailing `/api` on the site URL (as used with some other Infisical SDKs) is |
| 114 | +accepted and normalized away. |
| 115 | + |
| 116 | +## Documentation |
| 117 | + |
| 118 | +You can find the documentation for the Ruby SDK on our [SDK documentation page](https://infisical.com/docs/sdks/languages/ruby). |
| 119 | + |
| 120 | +## Development |
| 121 | + |
| 122 | +```bash |
| 123 | +bin/setup # bundle install |
| 124 | +bundle exec rspec |
| 125 | +bundle exec rubocop |
| 126 | +``` |
| 127 | + |
| 128 | +## Security |
| 129 | + |
| 130 | +Please do not file GitHub issues or post on our public forum for security vulnerabilities, as they are public! |
| 131 | + |
| 132 | +Infisical takes security issues very seriously. If you have any concerns about Infisical or believe you have uncovered a vulnerability, please get in touch via the e-mail address security@infisical.com. In the message, try to provide a description of the issue and ideally a way of reproducing it. The security team will get back to you as soon as possible. |
| 133 | + |
| 134 | +Note that this security address should be used only for undisclosed vulnerabilities. Please report any security problems to us before disclosing it publicly. |
0 commit comments