-
Notifications
You must be signed in to change notification settings - Fork 62
Description
When running a record search (Client.RecordSearch.Search("domain=something.com")
), it assumes that the API returns a list of Records.
The REST API does not return Record JSON with the same fields as normal Record lookup calls.
For example:
An api request for a particular record using the zone URI:
curl -X GET -H "X-NSONE-Key: $nsone_key" https://api.nsone.net/v1/zones/<zone>/<fqdn>/CNAME
will return
{
"answers": [
{
"answer": [
"somewhere.com"
],
"id": "<id>"
}
],
"created_at": 1692284943,
"domain": "<fqdn>",
"filters": [],
"meta": {},
"networks": [ 0 ],
"regions": {},
"tier": 1,
"ttl": 3600,
"type": "CNAME",
"updated_at": 1738793446,
"use_client_subnet": true,
"zone": "<zone>",
"zone_name": "<zone>",
"customer": 999
"feeds": [],
"id": "<id>"
}
This matches what a Record struct expects.
A call to the Search endpoint returns a JSON array of records in a different format:
curl -X GET -H "X-NSONE-Key: $nsone_key" https://api.nsone.net/v1/dns/record/search\?domain=<domain>
which has limited data, and different zone field names:
{
"limit": 50,
"next": "",
"results": [
{
"answers": [
{
"answer": [
"somewhere.com"
]
}
],
"domain": "<domain>",
"ttl": 3600,
"type": "CNAME",
"zone_fqdn": "<zone>",
"zone_handle": "<zone>"
}
],
"total_results": 1
}
Problem
The Search function returns type *dns.SearchResult,
, which makes the assumption that the list of Results are the same as regular Records, which is incorrect. The Records struct is not what the search API returns, so search for records with this go library results in objects with very little and not useful data:
possibleRecords, _, _ := Client.RecordSearch.Search(fmt.Sprintf("domain=%s", domain))
logger.Debug().Msgf("%+v", possibleRecords)
// prints &{Next: Limit:50 TotalResults:1 Results:[<domain> CNAME]}
And since the body of the http.Response
is closed after it's read, I'm unable to parse the raw JSON and marshal it into correct objects.
Possible solutions
- Create a new, correct type for search result records
- Expand the current Record format to allow marshal both responses correctly (zone and search)
- Have NS1 update their API with consistent responses (outside the scope of this library)