can't create server-admin in couchdb - 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"}'

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

Collect the basic instace details from puppetdb like the hostname and IP based on some facts value

How can i develop a script which automatically runs and fetches the details from puppetdb ? I am a newbie to puppet .Basically I would like to collect the inventory from puppetdb based on factor values like "web server" ,"app server" etc. I use opensource puppet.
querying puppetdb is as easy as running curl.
For example, if you have a fact named $role and some nodes have the role "web server" you can get an inventory dump of all nodes with that role running:
curl -G -H "Accept: application/json" 'http://localhost:8080/pdb/query/v4/inventory' --data-urlencode 'query=["=",["fact","role"], "web server"]' |jq '.'
Now, maybe you only want to know the hostname of servers and send each inventory to another application, that would be something like this:
#!/bin/bash
# Iterate over nodes if $role 'web server'
curl -s -G -H "Accept: application/json" 'http://localhost:8080/pdb/query/v4/nodes' --data-urlencode 'query=["=",["fact","role"], "web server"]' | jq -r '.[]|[ .certname ]| #tsv' |
while IFS=$'\t' read -r host; do
echo "Do something with $host"
# Save one dump per host
curl -s -G -H "Accept: application/json" 'http://localhost:8080/pdb/query/v4/inventory' --data-urlencode 'query=["=","certname","'${host}'"]' > "node-${host}.inventory.log"
done
This are very basic examples, their api is very powerful and very simple to use, you can query anything (facts, resources, catalogs, inventories) and doing even complex queries like speaking to a MySQL server, check their tutorial here: https://puppet.com/docs/puppetdb/5.1/api/query/tutorial.html .

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

Fiware: How to create lazy attributes through IDAS UltraLight

I'm using the IoT Agent Ultra-Light module to communicate with the Orion context broker. I can create services and devices and I have checked that the observations reach the context broker too.
curl -X POST XXX.XXX.XXX.XXX:8090/iot/services \
-i \
-H "Content-Type: application/json" \
-H "Fiware-Service: sanitysrv " \
-H "Fiware-ServicePath: / sanitysspath " \
-d '{"services": [{"apikey": "", "cbroker": "http://127.0.0.1:1026", "entity_type": "Dispositivo_tmp", "resource": "/iot/d"}]}'
curl -X POST XXX.XXX.XXX.XXX:8090/iot/devices \
-i \
-H "Content-Type: application/json" \
-H "Fiware-Service: sanitysrv" \
-H "Fiware-ServicePath: /sanitysspath" \
-d '{"devices":[{"device_id":"CE_BDM_3","protocol":"PDI-IoTA-UltraLight", "commands": [], "attributes": [{"type":"int","name":"temperature","object_id":"t"}]}]}'
My problem is that I don´t know how to register a device that contains lazy attributes, and I haven´t found any documentation with related examples. The examples from other IoT Agents that I have tried are not working here.
¿How can it be done?
Lazy attributes are not supported in the UL2.0/MQTT Agent so far but in IoT Agents developed with node.js.
We'll let you know as soon as this feature is available.
Cheers,

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

Resources