clouddns

A client implementation for Rackspace Cloud DNS in node.js

node-clouddns

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)

Getting Rackspace Account

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 = clouddns.createClient(config);
  // Authenticate 
  client.setAuth(function () {
  
  // Listing domains for your account 
    client.getDomains(function (errdomainArray) {
       console.dir(domainArray);
    });
    
  // Creating a new domain 
    var newDomain = {
     "name" : "example.com",
      "comment" : "Optional domain comment...",
      "ttl" : 3600,
      "emailAddress" : "sample@rackspace.com"
    };
    
    client.createDomain(newDomain, function(errdomainArray){
      console.dir(domainArray);
    });
    
    // Search by name or page through a long list 
    var searchOpts = {limit: 3, offset: 9, name: "mydomainsearchstring" };
    
    client.getDomains(searchOpts, function (errdomainArray) {
       console.dir(domainArray);
    });
    
  });

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

  // Authenticate 
  client.setAuth(function () {
  
  // Listing domains for your account 
    client.getDomains(function (errdomainArray) {
    
      // All domains returned are wrapped with our helper objects 
      domainArray[0].getDetails(function(errdomain) {
       //Domains returned from the client.getDomais() function are bare lists,  
       //  so we call getDetails() to also get the subdomains and domain records 
       console.dir(domain.recordsList);
      }
      
      //Helper methods call getDetails() automatically on the domain first if the records are not cached 
      
      domainArray[0].getSubDomains(function(errdomain) {
       console.dir(domain.subdomains.domains);
      
       //Subdomains are still domains, so all the same methods apply so: 
       domain.subdomains.domains[0].comment = "I'm updating this subdomain";
       domain.subdomains.domains[0].updateDomain(function(errdomain){
       //Still the parent domain 
       console.dir(domain);
       });
      
       //Or pass bare object, we're crazy like that 
       domain.subdomains.domains[0].updateDomain({comment: "My fav domain", ... }function(errdomain){
       console.dir(domain);
       });
      
       //Change history for the domain, pass in an optional Date() to limit the "since" time 
       domain.getChanges(function(errchanges){
       console.dir(changes);
       });
      
      
       //Delete the domain 
       domain.removeDomain(function(err){
         if (err) {
          console.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

  // Authenticate 
  client.setAuth(function () {
  
  // Listing domains for your account 
    client.getDomains(function (errdomainArray) {
    
      // Get the records 
      domainArray[0].getRecords(function(errrecords) {
      
       //Add a comment 
        records[0].comment = "Bad MX record, I should just delete it";
       records[0].updateRecord(function(){
       if (!err) console.log("success");
      
       // Aww, just delete it already 
       records[0].removeRecord(function(){
       if (!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 arrays 
      domainArray[1].addRecords( recordArray, function(errdomain) {
        console.dir(domain);
      });  
      
      
    });
    
  });

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 = clouddns.createClient(config);

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:

  npm test

Author: Andrew Cope

Based on the node-cloudfiles library by the following

Author: Charlie Robbins

Contributors: Fedor Indutny, aaronds