Skip to content
/ consulkit Public

Ruby API for interacting with HashiCorp's Consul.

License

Notifications You must be signed in to change notification settings

etsy/consulkit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

90eeefd · Jun 6, 2024

History

24 Commits
Jul 6, 2023
Jul 4, 2023
Jun 6, 2024
Jun 6, 2024
Jun 29, 2023
Jun 29, 2023
Jul 4, 2023
Jun 6, 2024
Jul 5, 2023
Jun 6, 2024
Jun 29, 2023
Jul 6, 2023
Jul 4, 2023
Jul 5, 2023
Jul 4, 2023

Repository files navigation

consulkit

Ruby API for interacting with HashiCorp's Consul, heavily inspired by GitHub's Octokit.

Installation

gem "consulkit"

Usage

Get a client using the default options:

client = Consulkit::Client.new

...or provide customized options:

client = Consulkit.Client.new(http_addr: "https://consul.example.com", http_token: "token")

KV Store

Reading keys:

# Read a single key
client.kv_read_single("foo")
# => {"LockIndex"=>0, "Key"=>"foo", "Flags"=>1234, "Value"=>"bar", "CreateIndex"=>3532, "ModifyIndex"=>3914}

# Read key recursively
client.kv_read_recursive("foo")
# => [{"LockIndex"=>0, "Key"=>"foo", "Flags"=>1234, "Value"=>"bar", "CreateIndex"=>3532, "ModifyIndex"=>3914}, ...]

# Specify your own query parameters
client.kv_read("foo", raw: true)
# => "bar"

Writing keys:

# Write a key
client.kv_write("foo", "bar", flags: 1234)
# => true

# Write a key if it doesn't exist
client.kv_write_cas("foo", "bar", 0)
=> false

> client.kv_write_cas("bar", "baz", 0)
=> true

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.