A client implementation for Rackspace Cloud DNS in node.js
An incomplete fork of nodejitsu's node-cloudfiles, ripped apart and refitted for Rackspace Cloud DNS API. WARNING: This could very well break your rackspace account, I am not responsible. Don't say I didn't warn you.
This module is not yet available via npm. (Comming soon)
The node-clouddns library is compliant with the Rackspace clouddns API. Using node-clouddns is easy for a variety of scenarios: authenticating, creating and working with both domains and DNS records.
Before we can do anything with clouddns, we have to create a client with valid credentials. clouddns will authenticate for you automatically:
var clouddns = require'clouddns';var config =auth :username: 'your-username'apiKey: 'your-api-key';var client = clouddnscreateClientconfig;
// AuthenticateclientsetAuth// Listing domains for your accountclientgetDomainsconsoledirdomainArray;;// Creating a new domainvar newDomain ="name" : "example.com""comment" : "Optional domain comment...""ttl" : 3600"emailAddress" : "firstname.lastname@example.org";clientcreateDomainnewDomainconsoledirdomainArray;;// Search by name or page through a long listvar searchOpts = limit: 3 offset: 9 name: "mydomainsearchstring" ;clientgetDomainssearchOptsconsoledirdomainArray;;;
All the expected CRUD methods that you would expect are available to the domain object We also have the ability to import and export BIND9 db files, check out the tests for more details
// AuthenticateclientsetAuth// Listing domains for your accountclientgetDomains// All domains returned are wrapped with our helper objectsdomainArray0getDetails//Domains returned from the client.getDomais() function are bare lists,// so we call getDetails() to also get the subdomains and domain recordsconsoledirdomainrecordsList;//Helper methods call getDetails() automatically on the domain first if the records are not cacheddomainArray0getSubDomainsconsoledirdomainsubdomainsdomains;//Subdomains are still domains, so all the same methods apply so:domainsubdomainsdomains0comment = "I'm updating this subdomain";domainsubdomainsdomains0updateDomain//Still the parent domainconsoledirdomain;;//Or pass bare object, we're crazy like thatdomainsubdomainsdomains0updateDomaincomment: "My fav domain"consoledirdomain;;//Change history for the domain, pass in an optional Date() to limit the "since" timedomaingetChangesconsoledirchanges;;//Delete the domaindomainremoveDomainif errconsole.log"Whoops can't delete" + err;;;;;
Updating and deleting can be done directly on the record objects, and bulk updates are done via the domain Again you should really run and read the tests, for more info
// AuthenticateclientsetAuth// Listing domains for your accountclientgetDomains// Get the recordsdomainArray0getRecords//Add a commentrecords0comment = "Bad MX record, I should just delete it";records0updateRecordif !err console.log"success";// Aww, just delete it alreadyrecords0removeRecordif !err console.log"success";;;;// Bulk record update, first parameter could be a Record Instance, or Array of records// Note all bulk updating functions can take either our Domain or Record instances, or just simple objects and arraysdomainArray1addRecords recordArrayconsoledirdomain;;;;
Use the 'host' key in the auth configuration to specify the url to use for authentication:
var clouddns = require'clouddns';var config =auth :username: 'your-username'apiKey: 'your-api-key'host : "lon.auth.api.rackspacecloud.com";var client = clouddnscreateClientconfig;
All of the node-clouddns tests are written in vows, and cover all of the use cases described above. You will need to add your Rackspace API username and API key to test/fixtures/test-config.json before running tests:
"auth":"username": "your-username""apiKey": "your-apikey"
Once you have valid Rackspace credentials you can run tests with npm and vows: