CouchDB not "creating" new users - couchdb

I recently install CouchDB on my CentOS box ('yum install couchdb'). I set up an admin account and then set out to create my first non-admin user. I issue the command..
curl -X PUT http://admin:abc123#localhost:5984/_users/org.couchdb.user:brad \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-d '{"name": "brad", "password": "asdf", "roles": [], "type": "user"}'
The response looks good..
{"ok":true,"id":"org.couchdb.user:brad","rev":"3-078014aabce23da851ef243f92a7fc5c"}
Now, to verify the user data has been created properly I get the new user data..
curl -X GET http://admin:abc123#localhost:5984/_users/org.couchdb.user:brad/
.. and I get the following response which seems to be missing some things..
{"_id":"org.couchdb.user:brad","_rev":"3-078014aabce23da851ef243f92a7fc5c","name":"brad","password":"asdf","roles":[],"type":"user"}
... from everything I've read there should be some additional fields.. "password_scheme", "iterations", "derived_key", and "salt". Further, I've created a database in Futon and set "brad" as a reader for that database, but when I attempt to access the DB as brad from the CLI I get an error..
curl -X GET http://brad:asdf#localhost:5984/test_db
{"error":"unauthorized","reason":"Name or password is incorrect."}
Anyone have any idea why CouchDB isn't processing the new user properly?

It looks like your CouchDB is out of date; the new authentication stuff is in 1.3.0+. You may have better luck using build-couchdb: https://github.com/jhs/build-couchdb

Related

Using gitlab api, how do I get a list of active users?

Gitlab-CE v8.14.3
I'm reading the GitLAB API docs, and am trying to get the list of active users. I'm an admin and created a personal token. I do this
$ curl -XGET "Private-Token: kfjakjfkjkd" https://company.domain.com/api/v3/users?active=true
and keep getting 401 (Unauthorized) error. Like I said, I'm an admin. What gives?
You must specify the header using the -H option as noted in Bertrand Martel's answer. That will retrieve up to 20 users.
Above 20 users, you must get fancier. The JSON output is paginated, and each query is limited to 100 users per page. So to get 300 users, you must get three pages, 100 users at a time:
curl -H "Private-Token: kfjakjfkjkd" "https://company.domain.com/api/v4/users?active=true&per_page=100&page=1" > gitlabusers1.json
curl -H "Private-Token: kfjakjfkjkd" "https://company.domain.com/api/v4/users?active=true&per_page=100&page=2" > gitlabusers2.json
curl -H "Private-Token: kfjakjfkjkd" "https://company.domain.com/api/v4/users?active=true&per_page=100&page=3" > gitlabusers3.json
You need to specify that Private-Token: kfjakjfkjkd is an HTTP header with -H :
curl -H "Private-Token: kfjakjfkjkd" https://company.domain.com/api/v4/users?active=true

Whatever the username, Hyperledger Fabric Sample App, Balance Transfer, log in successfully

I am playing around with hyperledger fabric sample apps. In "Balance transfer" app, they have provided sample requests to login user, create channel and more.....
But whatever the username i provide, it logged it in successfully.
Request:
curl -s -X POST \
http://localhost:4000/users \
-H "content-type: application/x-www-form-urlencoded" \
-d 'username=Jim&orgName=org1'
Response
{
"success": true,
"secret": "GSHPwdfBQyzB",
"message": "Jim enrolled Successfully",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MTI0MjkxNzYsInVzZXJuYW1lIjoiSmltIiwib3JnTmFtZSI6Im9yZzIiLCJpYXQiOjE1MTIzOTMxNzZ9.AAH5A9V08QfMvPmsDpoHVkYsFNbQX-nRMU025NziZRc"
}
No matter what username i provide it log it in successfully.
Can anyone explain, what is actually going on.
The command
curl -s -X POST \
http://localhost:4000/users \
-H "content-type: application/x-www-form-urlencoded" \
-d 'username=Jim&orgName=org1'
registers and enrolls a user. You are sending the POST request as an admin with registration privileges.

Unable to replicate the couch db

I have two machines lets say 156 and 157
I have a db in 156 machine which i want to replicate to 157 machine for that i am using the following command
curl -X POST -d '{"source":"http://couch_user:couch_password#XX.XX.XX.156:5984/root_openwhisk-156_whisks","target":"http://couch_user:couch_password#XX.XX.XX.157:5984/root_openwhisk-156_whisks"}' http://couch_user:couch_password#XX.XX.XX.156:5984/_replicate -H "Content-Type: application/json"
also i tried without password
curl -X POST -d '{"source":"http://XX.XX.XX.156:5984/root_openwhisk-156_whisks","target":"http://XX.XX.XX.157:5984/root_openwhisk-156_whisks"}' http://XX.XX.XX.156:5984/_replicate -H "Content-Type: application/json"
but i am getting below error
{"error":"db_not_found","reason":"could not open http://XX.XX.XX.156:5984/root_openwhisk-156_whisks/"}
I have also tried the replicator utility in futon but that also doesn't work
In the Futon i can see root_openwhisk-156_whisks along with _replicator and _user in both machine
Kindly help
The source should be just root_openwhisk-156_whisks without the http protocol, IP and login credentials. Example from the official documents: http://guide.couchdb.org/draft/replication.html

can't create server-admin in couchdb

I'm following the couchdb security documentation (http://docs.couchdb.org/en/1.6.1/intro/security.html) to try to create a server-admin using cURL: curl -X PUT $HOST/_config/admins/anna -d '"secret"'
When I do this, I get an error:
{"error":"not_found","reason":"Database does not exist."}
I'm on v2.0 so I don't known if something has changed since the 1.6 version of the documentation. I can create server-admins just fine using fauxton. Any ideas?
To anybody else running into this issue, it's an easy answer: in couchdb 2.0 some of the APIs moved to using port 5986 ... I had been using port 5984 (which is still used a lot in v2.0, but apparently not for the _config endpoint).
The following works:
curl -X PUT http://localhost:5986/_config/admins/admin1 -d '"password"'
The Couchdb2 way of adding a user is
curl -X PUT http://localhost:5984/_node/nodename/_config/admins/admin1 -d '"password"'
In the GUI, you can find out that you need to set up a single node cluster, and when you do that you specify the admin username and password.
And you can do the same thing using an API endpoint that you can POST to:
http://docs.couchdb.org/en/2.1.0/api/server/common.html#post--_cluster_setup
With 2.0 using enable_single_node returned {"error":"bad_request","reason":"Invalid Action'"} so I reverted to doing:
j=$(cat <<EOF
{
"action": "enable_cluster",
"bind_address": "0.0.0.0",
"username": "admin",
"password": "$PASS",
"port": "5984",
"node_count":"1"
}
EOF
)
curl -s -X POST -H "Content-Type: application/json" http://$IP/_cluster_setup -d "$j"
curl -s -X POST -H "Content-Type: application/json" $URI/_cluster_setup -d '{"action": "finish_cluster"}'

How can I replicate a CouchDB database?

I would like to replicate the CouchDB database https://github.com/kirel/detexify-data
Sadly, I get an error:
$ curl -X POST -H "Content-Type:application/json" -d '{"source":"https://kirelabs.cloudant.com/detexify","target":"detexify"}' http://localhost:5984/_replicate
{"error":"checkpoint_commit_failure","reason":"Failure on source commit: {error,<<\"unauthorized\">>}"}
This seems to be the following error: https://issues.apache.org/jira/browse/COUCHDB-1524
Can anybody please tell me if there is a work-around? How can I get the data?
Failed tries
$ curl -X POST -H "Content-Type:application/json" \
-d '{"source":"https://kirelabs.cloudant.com/detexify",
"target":"detexify",
"use_checkpoints":false}'
http://localhost:5984/_replicate
{"error":"checkpoint_commit_failure",
"reason":"Failure on source commit: {error,<<\"unauthorized\">>}"}
Well a quick easy solution is to not use checkpoints.
{"source":"https://kirelabs.cloudant.com/detexify","target":"detexify","use_checkpoints":false}
I tried it with this request and managed to replicate your data.
Update
Well I tried it again and replication seems to be working fine for me. I replicated 22.7 mb of data before cancelling the replication. I have attached a screenshot.
curl -X POST -H "Content-Type:application/json" -d '{"source":"https://kirelabs.cloudant.com/detexify",
"target":"detexify",
"use_checkpoints":false,"create_target":true}' http://ABBA:dancing-queen#localhost:5984/_replicate
The replication command was copied verbatim from your updated example except for the "create_target" option and admin basic authentication on my local database.

Resources