Doppler Ruby Library

image

The Doppler Ruby library provides convenient access to the Doppler API from applications written for only server-side code.

Installation

Install the gem with:

gem install doppler-client

Usage

The package needs to be configured with your account's api key which is available in your Doppler account, pipeline identifier and the environment name:

require "doppler-client"

doppler = Doppler::Client.new(
  api_key = ENV["API_KEY"],
  pipeline = ENV["PIPELINE_ID"],
  environment = ENV["ENVIRONMENT_NAME"]
)

# Rest of Application

Key Best Practices

So if Doppler stores my environment keys, where should I keep my Doppler API keys?

That is a great question! We recommend storing your API_KEY, PIPELINE_ID, and ENVIRONMENT_NAME in local environment. That means the only keys you should be storing in your local environment are the Doppler keys. All other keys should be be fetched by the Doppler client.

Fetch Environment Keys

You can fetch your environment keys from Doppler by calling the get(name) method.

doppler.get(KEY_NAME)

Here is an example:

config = {
  "segment_key" => doppler.get("SEGMENT_API_KEY"),
  "algolia_key" => doppler.get("ALGOLIA_API_KEY")
}

If there are differences between the values your local environment sets and the ones on Doppler, the client will use the ones provided by Doppler. You can override this behavior by passing in a second argument to the get(key_name, priority) method that sets the priority to favor your local environment.

For example:

# Local Enviroment
os.environ["MAGICAL_KEY"] = "123"

# Doppler
MAGICAL_KEY = "456"


# Default Behavior
doppler.get("MAGICAL_KEY") # => "456"

# Override to Local
doppler.get("MAGICAL_KEY", Doppler::Priority.local) # => "123"

You can also set the priority globally on initialization:

doppler = Doppler::Client.new(
  api_key = ENV["API_KEY"],
  pipeline = ENV["PIPELINE_ID"],
  environment = ENV["ENVIRONMENT_NAME"]
  priority = Doppler::Priority.local
)

Local Key Privacy

By default the Doppler client will send all your local environment keys on init. This is done for 2 reasons. Collecting your local keys helps us automatically setup your pipelines for immediate use. After setup we also use your keys to detect when your keys locally have changed from what is on Doppler. We then provide a way for you to adopt or reject those changes through our dashboard. This can help help when debugging silent bugs or build failures.

If you would like the Doppler client to not send your keys we provide 2 ways to do it.

Globally

To ensure all your local keys are not sent to Doppler, set the send_local_keys attribute to false.

doppler = Doppler::Client.new(
  # ...
  send_local_keys = false  # DEFAUTLS => True
)

Individual Key

You can also ignore specific local keys by adding them to the ignore_keys array.

doppler = Doppler::Client.new(
  # ...
  ignore_keys: [
    "SUPER_SECRET_KEY"
  ]
)

Extra Information