CouchDB Configuration

Leanback directly supports CouchDB’s configuration API.

First we login to CouchDB and generate the auth_session token for making requests.

hash = Couchdb.login(username = 'samson',password ='sam123') 
auth_session =  hash["AuthSession"]

Set Configuration
To change a CouchDB configuration setting, we use the set_config() method. For example to add an admin user to CouchDB.

 data = {:section => "admins",
              :key => "james",
                :value => "abc123"}
 Couchdb.set_config data,auth_session

This is similar to sending a

PUT http://127.0.0.1:5984/_config/admins/james,’”abc123″‘

If you check Futon’s Configuration section you would notice a new admin ‘james’ have been added to the admins section. The new admin’s username is ‘james’ and password is ‘abc123′. For more details on adding admin and non-admin users, see here.

To change couchDB’s bind_address

data = {:section => "httpd",
              :key => "bind_address",
                :value => "192.168.1.118"}
 
Couchdb.set_config(data, auth_session)

This only changes CouchDB’s bind_address, it doesn’t change the address used by Leanback to make http requests. Leanback uses ’127.0.0.1′ by default, to change leanback’s default address:

Couchdb.address = "192.168.1.118"

This is discussed in great detail here.

To change the ‘couch_httpd_auth’ timeout value:

data = {:section => "couch_httpd_auth",
              :key => "timeout",
                :value => "700"}
 
Couchdb.set_config(data, auth_session)

This changes the time it takes for the generated auth_session token to expire.

To add custom configuration settings:

data = {:section => "sample_config_section",
              :key => "sample_key",
                :value => "sample_value"}
    Couchdb.set_config data,auth_session

If you check Futon’s configuration page you will notice a new section called ‘sample_config_section’ with key ‘sample_key’ and value ‘sample_value’.

Get Configuration
To retrieve CouchDB’s configuration settings we use the get_config() method.
Example to retrieve couchDB’s port#

 data = {:section => "httpd",
              :key => "port"}
 
 Couchdb.get_config(data,auth_session)
 #=> "5984"

To retrieve CouchDB’s database dir

data = {:section => "couchdb",
              :key => "database_dir"}
 
Couchdb.get_config(data,auth_session)
#=> "/var/lib/couchdb/1.0.1"

Delete Configuration
To delete a configuration setting we the delete_config() method. Example to delete an admin:

data = {:section => "admins",
              :key => "james"}
 
Couchdb.delete_config(data,auth_session)
Premium Wordpress Plugin