Unable to replicate the couch db - couchdb

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

Related

windows command prompt curl POST to run Azure DevOps pipeline

I am trying to run an Azure DevOps pipeline from the windows command prompt using curl.
Based on Microsoft documentation ( Runs - Run Pipeline ) I should be able to run a pipeline by posting:
https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1
I am able to GET using the command:
curl -u :<PAT> https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1
However, I can't figure out how to do a POST for DevOps using curl to run the pipeline.
I have tried the following:
curl -s -X POST -L https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1 -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Basic <PAT>"
But this returns the error
HTTP Error 411. The request must be chunked or have a content length
I managed to solve my problem which consisted of numerous steps:
Log the API call from the DevOps website to get the correct format of the json-body ( See this question ).
Format the json-body with extra double quotation signs.
Use the {project}-id instead of the ascii-name since it included a special character which the command prompt misinterpret.
Hence the complete curl command was:
curl -X POST -u :<PAT> "https://dev.azure.com/{organization}/{project}/_apis/pipelines/{pipelineId}/runs?api-version=6.0-preview.1" -H "Content-Type: application/json" -d "{""stagesToSkip"": ""[]"", ""resources"": {""repositories"": {""self"": {""refName"": ""refs/heads/master""}}}}"

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

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"}'

CouchDB not "creating" new users

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

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