newsdev/etcd-ruby

Name: etcd-ruby

Owner: NYT Newsroom Developers

Description: Bare minimal ruby client for etcd

Created: 2015-06-30 19:39:08.0

Updated: 2015-06-30 19:39:09.0

Pushed: 2015-06-30 20:27:19.0

Homepage: null

Size: 254

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Built on Travis

Etcd

A ruby client for etcd

Installation

Add this line to your application's Gemfile:

gem 'etcd'

And then execute:

$ bundle

Or install it yourself as:

$ gem install etcd
Usage
Create a client object
nt = Etcd.client # this will create a client against etcd server running on localhost on port 4001
nt = Etcd.client(port: 4002)
nt = Etcd.client(host: '127.0.0.1', port: 4003)
nt = Etcd.client(:user_name => 'test', :password => 'pwd') # populates the authentication header for basic HTTP auth with user name and password (useful for proxied connections)
nt = Etcd.client(host: '127.0.0.1', port: 4003, allow_redirect: false) # wont let you run sensitive commands on non-leader machines, default is true
Create a client object to connect to a SSL etcd instance

See Etcd config to setup etcd in SSL mode.

Assuming you have these:

If you were using self signed Certs and have your own CA, You would have set -ca-file in your etcd config also to use myca.crt.

nt=Etcd.client(
ost => "your-etcd-host",
ort => 443,
se_ssl => true,
a_file => "/pathto/myca.crt",
sl_cert => OpenSSL::X509::Certificate.new( File.read("/pathto/my-cert.crt") ),
sl_key => OpenSSL::PKey::RSA.new("/etc/ssl/my-cert.key",passphrase)

t passphrase if not set on your key.
Set a key
nt.set('/nodes/n1', value: 1)
th ttl
nt.set('/nodes/n2', value: 2, ttl: 4)  # sets the ttl to 4 seconds
Get a key
nt.get('/nodes/n2').value
Delete a key
nt.delete('/nodes/n1')
nt.delete('/nodes/', recursive: true)
Test and set
nt.test_and_set('/nodes/n2', 2, 4) # will set /nodes/n2 's value to 2 only if its previous value was 4
Watch a key
nt.watch('/nodes/n1') # will wait till the key is changed, and return once its changed
List sub keys
nt.get('/nodes')
Get machines in the cluster
nt.machines
Get leader of the cluster
nt.leader

More examples and api details can be found in the wiki

Contributors
Contributing
  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
  6. If applicable, update the README.md

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.