Created
May 8, 2014 18:55
-
-
Save cromwellryan/a23423b8de72813678c4 to your computer and use it in GitHub Desktop.
Generate a CSV of all domain records on Dnsimple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https = require 'https' | |
p = console.log | |
email = process.argv[2] | |
token = process.argv[3] | |
dnsimple = (relative_url) -> | |
hostname: 'api.dnsimple.com' | |
port: 443 | |
path: "/v1#{relative_url}" | |
headers: { | |
'X-DNSimple-Token': "#{email}:#{token}" | |
} | |
crap = (e) -> | |
p "Something bad happened calling #{e.api}" | |
p e.body | |
get_dnsimple_api = (api, next, err) -> | |
https.get dnsimple(api), (res) -> | |
body = '' | |
res.on 'data', (chunk) -> body += chunk | |
res.on 'end', -> | |
json = JSON.parse(body) | |
err({ body: json, api: api }) if res.statusCode != 200 | |
next(json, err) if res.statusCode == 200 | |
res.on 'error', err | |
get_domains = (next,err) -> | |
get_dnsimple_api '/domains', next, err | |
for_each_domain = (domains, next) -> | |
domains.forEach (domain) -> | |
next(domain.domain) | |
get_domain_records = (domain, next, err) -> | |
composed_next = (records) -> | |
next(domain, records) | |
get_dnsimple_api("/domains/#{domain.id}/records", composed_next, err) | |
print_domain_records = (domain, records) -> | |
records.forEach (record) -> | |
record = record.record | |
p "#{domain.name},#{record.record_type},#{record.content}" | |
get_records = (domains, next) -> | |
for_each_domain(domains, (domain) -> | |
get_domain_records(domain, print_domain_records, crap)) | |
p "domain.name,record_type,record.content" | |
get_domains(get_records, crap) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Generates a CSV with something like: