Inserting A records using the PowerDNS REST api - powerdns

I have an issue with the web interface. I'm using powerdns v3.4.5 with mysql as the back-end.
I have followed instructions from here:
https://www.unixmen.com/how-to-install-powerdns-on-ubuntu-14-04/
I have successfully installed powerdns with mysql and got the web-api to work.
However I have trouble inserting A records using the REST api.
I have followed command from here:
https://doc.powerdns.com/md/httpapi/README/
This creates a new zone:
curl -X POST --data '{"name":"example.org.", "kind": "Native", "masters": [], "nameservers": ["ns1.example.org.", "ns2.example.org."]}' -v -H 'X-API-Key: changeme' http://127.0.0.1:8081/servers/localhost/zones | jq .
(note that I changed the url and removed /api/v1/)
However when I run the following command to add a new A record:
curl -X PATCH --data '{"rrsets": [ {"name": "test.example.org.", "type": "A", "ttl": 86400, "changetype": "REPLACE", "records": [ {"content": "192.0.5.4", "disabled": false } ] } ] }' -H 'X-API-Key: changeme' http://127.0.0.1:8081/servers/localhost/zones/example.org. | jq .
I get the following error:
"error": "RRset test.example.org. IN A: Name is out of zone"
is there anything that I'm missing?

It should be as follows:
curl -X POST --data '{"name":"example.org", "kind": "Master","dnssec":false,"soa-edit":"INCEPTION-INCREMENT","masters": [], "nameservers": ["ns1.example.org"]}' -v -H 'X-API-Key: changeme' http://127.0.0.1:8081/servers/localhost/zones | jq .
and then:
curl -X PATCH --data '{"rrsets": [ {"name": "test.example.org", "type": "A", "changetype": "REPLACE", "records": [ {"content": "192.168.9.9", "disabled": false, "name": "test.example.org", "ttl": 86400, "type": "A", "priority": 0 } ] } ] }' -H 'X-API-Key: changeme' http://127.0.0.1:8081/servers/localhost/zones/example.org | jq .

As time passes by, the API changed. The current json structure is a little bit different, also power-dns insists of getting canonical names ending with a dot.
# cat example_zone.json
{
"kind": "Native",
"masters": [],
"name": "example.com.",
"nameservers": [
"ns1.example.com.",
"ns2.example.com."
]
}
# curl -s -H 'X-API-Key: changeme' --data #example_zone.json http://127.0.0.1:8081/api/v1/servers/localhost/zones
# cat example_rrset.json
{
"rrsets":
[
{
"name": "test.example.com.",
"type": "A",
"changetype": "REPLACE",
"ttl": 86400,
"records":
[
{
"content": "192.168.9.9",
"disabled": false,
"name": "test.example.com.",
"type": "A",
"priority": 0
}
]
}
]
}
# curl -v -X PATCH -H 'X-API-Key: changeme' --data #example_rrset.json http://127.0.0.1:8081/api/v1/servers/localhost/zones/example.com.

Related

Not able to filter the record from Azure Search based on specific key within indexed json data

I have populated Azure search data using my application and this is what is present in Search Explorer in portal.azure.com.
{
"#odata.context": "https://demosearch.search.windows.net/indexes('<indexname>')/$metadata#docs(*)",
"value": [
{
"#search.score": 1,
"id": "31",
"code": "C001105",
"title": "Demo Course Title 1",
"creator": "FILE_UPLOAD",
"events": [
{
"eventId": 97,
"eventStatus": "PLANNING",
"evtSession": [
{
"postCode": "AB10 1AB",
"townOrCity": "Aberdeen City,",
"dates": {
"from": "2022-08-11T08:00:00Z",
"to": "2022-08-11T11:00:00Z"
}
}
]
}
]
},
{
"#search.score": 1,
"id": "45",
"code": "C001125",
"title": "Demo Course Title 2",
"creator": "FILE_UPLOAD",
"events": [
{
"eventId": 98,
"eventStatus": "IN_PROGRESS",
"evtSession": [
{
"postCode": "BA10 0AN",
"townOrCity": "Bruton",
"dates": {
"from": "2022-08-11T08:00:00Z",
"to": "2022-08-11T09:30:00Z"
}
}
]
}
]
}
],
"#odata.nextLink": "https://demosearch.search.windows.net/indexes('<indexname>')/docs?api-version=2019-05-06&search=%2A&$skip=50"
}
I'm trying below curl to get data where ["townOrCity": "Aberdeen City,"] from Azure search.
curl --location --request POST 'https://demosearch.search.windows.net/indexes/<indexname>/docs/search?api-version=2019-05-06' \
--header 'api-key: XXXX' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data-raw '{"count":false,"top":0,"skip":30,"search":"*","orderby":"search.score() desc","filter":"( events/any(evt: evt/evtSession/any(session: search.in(session/townOrCity, '\''Aberdeen City,'\'', '\'','\'') ) ) )","facets":["events/evtSession/townOrCity,count:10000"],"queryType":"full","searchMode":"any"}'
but I'm not getting expected response and value is coming as empty array :
RESPONSE
{
"#odata.context": "https://demosearch.search.windows.net/indexes('<indexname>')/$metadata#docs(*)",
"#search.facets": {
"events/evtSession/townOrCity": []
},
"value": []
}
Please help with the correct payload I should be using to filter out the record with "townOrCity" : "Aberdeen City," OR am I doing something wrong with indexing config or anything ?
"townOrCity" : "Aberdeen City,"
Edit 1:
NOTE: comma mentioned after Aberdeen City causes the issue. If I try same thing witout the comma everything works like a charm. But requirement is to support the comma.
$filter=( events/any(evt: evt/evtSession/any(session: search.in(session/townOrCity, 'Aberdeen City,', ',') ) ) )
there is data present in index but still its not applying filter properly, instead giving no record in response.
This works :
$filter=( events/any(evt: evt/evtSession/any(session: search.in(session/townOrCity, 'Aberdeen City,', '|') ) ) )
There are two overloads of the search.in function:
search.in(variable, valueList)
search.in(variable, valueList, delimiters)
Due to delimeters, comma inside my valueList was removed and hence actual value got changed. Apparently its an exact-match so empty response returned.
https://learn.microsoft.com/en-us/azure/search/search-query-odata-search-in-function

Add Databricks API to configure init script in existing bash script

I would like to add the Databricks init script API in my exsiting bash script. How can I do this? Here is the API provided by Databricks:
curl -n -X POST -H 'Content-Type: application/json' -d '{
"cluster_id": "",
"num_workers": 1,
"spark_version": "8.4.x-scala2.12",
"node_type_id": "$node_type",
"cluster_log_conf": {
"dbfs" : {
"destination": "dbfs:/cluster-logs"
}
},
"init_scripts": [ {
"dbfs": {
"destination": "dbfs:/FileStore/shared_uploads/kafka_keytabs/CopyKrbFiles.sh"
}
} ]
}' https://<databricks-instance>/api/2.0/clusters/edit

How change or delete A record by PowerDNS API?

I have pdns server 4.2.3. I want to change name of A record by api. Example:
test1 A ttl 60 192.168.1.2 -> test2 A ttl 60 192.168.1.2
From the powerdns host:
To delete record:
curl -X PATCH --data '{"rrsets": [{"changetype": "DELETE", "type": "A", "name": "test1.fqdn."}]}' -H 'X-API-Key: TURBOSECRET' http://127.0.0.1:8081/api/v1/servers/localhost/zones/zonename. -s | jq .
To add record:
curl -X PATCH --data '{"rrsets": [{"changetype": "REPLACE", "type": "A", "name": "test2.fqdn.", "ttl": "60", "records": [{"content": "test2.fqdn.", "disabled": false}]}]}' -H 'X-API-Key: TURBOSECRET' http://127.0.0.1:8081/api/v1/servers/localhost/zones/zonename. -s | jq .
Please adjust accordingly TURBOSECRET, fqdn and zonename.

Spotify API field filtering

I'm trying to use field filtering to pick out specific nested fields, and it seems to me like I'm hitting a limit for nesting.
Here's the filter I'm using: items(date_added, track(name, album(artists(name))))
and here's the curl command I'm trying (built with the new developer console):
curl -X "GET" "https://api.spotify.com/v1/users/<user_id>/playlists/<playlist_id>/tracks?fields=items(date_added%2C%20track(name%2C%20album(artists(name))))" -H "Accept: application/json" -H "Content-Type: application/json"
This call works and everything looks good until it gets to the artists field. It doesn't seem to be filtering down artist fields. I just want the artist name in this case. Here's a snippet of what I'm getting back:
"items": [
{
"track": {
"album": {
"artists": [
{
"external_urls": {
"spotify": "https://open.spotify.com/artist/3t69c5VItBx3GCrnkcYHEL"
},
"href": "https://api.spotify.com/v1/artists/3t69c5VItBx3GCrnkcYHEL",
"id": "3t69c5VItBx3GCrnkcYHEL",
"name": "Imagined Herbal Flows",
"type": "artist",
"uri": "spotify:artist:3t69c5VItBx3GCrnkcYHEL"
}
]
},
"name": "Floating"
}
}...
];
As you can see, I'm getting the full artist object. Can someone help me understand why I can't filter the fields for that?

Not able to copy multi line curl command in shell prompt

Am trying to run multiline curl command in shell but not able to run it
curl -XPUT 'elk.***.com:9200/_snapshot/my_backup' \
{
"type": "fs",
"settings": {
"location": "/elkprod_bak/elkback",
"compress": true
}
}
You need to use the -d switch on the command line like this:
curl -XPUT 'elk.***.com:9200/_snapshot/my_backup' -d '{
"type": "fs",
"settings": {
"location": "/elkprod_bak/elkback",
"compress": true
}
}'

Resources