-
-
Save Delivator/8f5f2c3c49c5561818f59d293a666efe to your computer and use it in GitHub Desktop.
Accompanying code for "Setting DNS Records" Namebase blog post
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
{ ttl: 10800, type: ‘NS’, host: ‘ns1’, value: ‘44.231.6.183’ } |
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
const credentials = Buffer.from(`${ACCESS_KEY}:${SECRET_KEY}`); | |
const encodedCredentials = credentials.toString('base64'); | |
const authorization = `Basic ${encodedCredentials}`; |
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
node namebaseApi.js put nameserver example ‘{ “records”: [], “deleteRecords”: [{ “type”: “TXT”, “host”: “foo” }] }’ |
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
const fetch = require('node-fetch'); | |
const ACCESS_KEY = ''; | |
const SECRET_KEY = ''; | |
const credentials = Buffer.from(`${ACCESS_KEY}:${SECRET_KEY}`); | |
const encodedCredentials = credentials.toString('base64'); | |
const authorization = `Basic ${encodedCredentials}`; | |
async function get(endpoint, body = null) { | |
const options = { | |
method: 'GET', | |
headers: { | |
Authorization: authorization, | |
Accept: 'application/json', | |
'Content-Type': 'application/json', | |
}, | |
}; | |
const url = `https://namebase.io${endpoint}`; | |
return fetch(url, options) | |
.then(res => res.json()) | |
.catch(err => err); | |
} | |
async function put(endpoint, body) { | |
const options = { | |
method: 'PUT', | |
body: body, | |
headers: { | |
Authorization: authorization, | |
Accept: 'application/json', | |
'Content-Type': 'application/json', | |
}, | |
}; | |
const url = `https://namebase.io${endpoint}`; | |
return fetch(url, options) | |
.then(res => res.json()) | |
.catch(err => err); | |
} | |
async function main() { | |
const args = process.argv.slice(2); | |
let func, path, data; | |
const domain = args[2]; | |
if (args[0] === 'get') { | |
func = get; | |
} else if (args[0] === 'put') { | |
func = put; | |
if (args.length < 4) throw new Error('Put requires 4 arguments'); | |
data = args[3]; | |
} else { | |
throw new Error("Method should be either 'get' or 'put'"); | |
} | |
if (args[1] === 'blockchain') { | |
path = `/api/v0/dns/domains/${domain}`; | |
} else if (args[1] === 'blockchain-advanced') { | |
path = `/api/v0/dns/domains/${domain}/advanced`; | |
} else if (args[1] === 'nameserver') { | |
path = `/api/v0/dns/domains/${domain}/nameserver`; | |
} else { | |
throw new Error("Service should be 'blockchain', 'blockchain-advanced' or 'nameserver'"); | |
} | |
return func(path, data); | |
} | |
main().then(res => { | |
console.log(res); | |
}); |
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
node ./namebaseApi.js get blockchain YOUR_DOMAIN |
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
node ./namebaseApi.js put blockchain YOUR_DOMAIN ‘{“records”: [{ “ttl”: 10800, “type”: “NS”, “host”: “ns1”, “value”: “44.231.6.183” }] }’ |
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
node namebaseApi.js put blockchain YOUR_DOMAIN ‘{ “records”: [{ “type”: “TXT”, “host”: “”, “value”: “[YOUR_SKYLINK]”, “ttl”: 0 }] }’ |
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
node namebaseApi.js put blockchain example ‘{ “records”: [{ “type”: “TXT”, “host”: “”, “value”: “[YOUR_SKYLINK]”, “ttl”: 0 }] }’ |
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
node ./namebaseApi.js METHOD SERVICE DOMAIN RECORD_DATA |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment