UNPKG

digitalocean

Version:
1,272 lines (1,128 loc) 2.18 MB
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.digitalocean = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ module.exports = { client: require('./digitalocean/client'), account: require('./digitalocean/account'), }; // // Reused type documnentation // /** * Every resource method accepts an optional callback as the last argument. * * @callback requestCallback * @param {object} error - An error or null if no error occurred. * @param {object} resource - The resource or null if error. * @param {object} headers - An object containing the response headers. * @param {string} body - The raw response body. */ /** * Every resource method accepts an optional callback as the last argument. * * @callback listRequestCallback * @param {object} error - An error or null if no error occurred. * @param {ListResponse} listResource - The list resource or null if error. * @param {object} headers - An object containing the response headers. * @param {string} body - The raw response body. */ },{"./digitalocean/account":2,"./digitalocean/client":5}],2:[function(require,module,exports){ (function() { var slice = [].slice, util = require('./util'); /** * Account resource * @class Account */ var Account = (function() { function Account(client) { this.client = client; } /** * Get the account object. * * @param {requestCallback} [callback] - callback that handles the response * @memberof Account */ Account.prototype.get = function(callback) { return this.client.get('/account', {}, 200, 'account', callback); }; /** * List ssh key objects. * * @param {(number|object)} [page or queryObject] - page number to retrieve or key value pairs of query parameters * @param {number} [perPage] - number of result per page to retrieve * @param {listRequestCallback} [callback] - callback that handles the response * @memberof Account */ Account.prototype.listSshKeys = function() { var args = util.extractListArguments(arguments, 0); return this.client.get.apply(this.client, ['/account/keys', {}].concat(slice.call(args.params), [200, 'ssh_keys', args.callback])); }; /** * Create a ssh key object. * * @param {object} attributes - The attributes with wich to create the ssh key. See the {@link https://developers.digitalocean.com/documentation/v2/#ssh-keys|official docs} for valid attributes. * @param {requestCallback} [callback] - callback that handles the response * @memberof Account */ Account.prototype.createSshKey = function(attributes, callback) { return this.client.post('/account/keys', attributes, 201, 'ssh_key', callback); }; /** * Get the identified ssh key object. * * @param {number} id - The id of the ssh key to retrieve * @param {requestCallback} [callback] - callback that handles the response * @memberof Account */ Account.prototype.getSshKey = function(id, callback) { var url = util.safeUrl('account', 'keys', id); return this.client.get(url, {}, 200, 'ssh_key', callback); }; /** * Update the identified ssh key object. * * @param {number} id - The id of the ssh key to update * @param {object} attributes - The attributes with which to update the ssh key. See the {@link https://developers.digitalocean.com/documentation/v2/#ssh-keys|official docs} for valid attributes. * @param {requestCallback} [callback] - callback that handles the response * @memberof Account */ Account.prototype.updateSshKey = function(id, attributes, callback) { var url = util.safeUrl('account', 'keys', id); return this.client.put(url, attributes, 200, 'ssh_key', callback); }; /** * Delete the identified ssh key object. * * @param {number} id - The id of the ssh key to delete * @param {requestCallback} [callback] - callback that handles the response * @memberof Account */ Account.prototype.deleteSshKey = function(id, callback) { var url = util.safeUrl('account', 'keys', id); return this.client.delete(url, {}, 204, [], callback); }; return Account; })(); module.exports = Account; }).call(this); },{"./util":17}],3:[function(require,module,exports){ (function() { var slice = [].slice, util = require('./util'); /** * Action resource * @class Action */ var Action = (function() { function Action(client) { this.client = client; } /** * List action objects. * * @param {(number|object)} [page or queryObject] - page number to retrieve or key value pairs of query parameters * @param {number} [perPage] - number of result per page to retrieve * @param {listRequestCallback} [callback] - callback that handles the response * @memberof Action */ Action.prototype.list = function() { var args = util.extractListArguments(arguments, 0); return this.client.get.apply(this.client, ['/actions', {}].concat(slice.call(args.params), [200, 'actions', args.callback])); }; /** * Get the identified action object. * * @param {number} id - The id of the action to retrieve * @param {requestCallback} [callback] - callback that handles the response * @memberof Action */ Action.prototype.get = function(id, callback) { var url = util.safeUrl('action', id); return this.client.get(url, {}, 200, 'action', callback); }; return Action; })(); module.exports = Action; }).call(this); },{"./util":17}],4:[function(require,module,exports){ (function() { var slice = [].slice, util = require('./util'); /** * Certificate resource * @class Certificate */ var Certificate = (function() { function Certificate(client) { this.client = client; } /** * List all SSL certificates. * * @param {(number|object)} [page or queryObject] - page number to retrieve or key value pairs of query parameters * @param {number} [perPage] - number of result per page to retrieve * @param {requestCallback} [callback] - callback that handles the response * @memberof Certificate */ Certificate.prototype.list = function() { var args = util.extractListArguments(arguments, 0); return this.client.get.apply(this.client, ['/certificates', {}].concat(slice.call(args.params), [200, 'certificates', args.callback])); }; /** * Create a certificate object. * * @param {object} attributes - The attributes with which to create the domain. See the {@link https://developers.digitalocean.com/documentation/v2/#certificates|official docs} for valid attributes. * @param {requestCallback} [callback] - callback that handles the response * @memberof Certificate */ Certificate.prototype.create = function(attributes, callback) { return this.client.post( '/certificates', attributes, 201, 'certificate', callback); }; /** * Get the identified certificate object. * * @param {string} id - The id of the domain to retrieve * @param {requestCallback} [callback] - callback that handles the response * @memberof Certificate */ Certificate.prototype.get = function(id, callback) { var url = util.safeUrl('certificates', id); return this.client.get(url, {}, 200, 'certificate', callback); }; /** * Delete the identified certificate object. * * @param {string} id - The id of the domain to delete * @param {requestCallback} [callback] - callback that handles the response * @memberof Certificate */ Certificate.prototype.delete = function(id, callback) { var url = util.safeUrl('certificates', id); return this.client.delete(url, {}, 204, [], callback); }; return Certificate; })(); module.exports = Certificate; }).call(this); },{"./util":17}],5:[function(require,module,exports){ (function() { // External Dependencies var url = require('url'), request = require('request'), Promise = require('bluebird'), deepExtend = require('deep-extend'); // API sections var Account = require('./account'), Action = require('./action'), Volume = require('./volume'), Certificate = require('./certificate'), Domain = require('./domain'), Droplet = require('./droplet'), FloatingIp = require('./floating_ip'), Firewall = require('./firewall'), Image = require('./image'), LoadBalancer = require('./load_balancer'), Region = require('./region'), Size = require('./size'), Snapshot = require('./snapshot'), Tag = require('./tag'); // Utilities var slice = [].slice, util = require('./util'), DigitalOceanError = require('./error'); /** * Client resource * @class Client */ var Client = (function() { /** * @typedef ClientOptions * @type {object} * @property {object} [request] - pass in a specific version of the request library. * @property {object} [promise] - pass in a specific version of promise library. * @property {object} [requestOptions] - a base set of options provided to Request, overridden by options passed to a specific API method. defaults to empty object. * @property {boolean} [decamelizeKeys] - whether to automagically translate query and JSON body keys to use underscore separated names. * @property {string} [protocol] - defaults to https. * @property {string} [hostname] - defaults to api.digitalocean.com. * @property {string} [port] - defaults to protocol default (e.g. with a protocol of https defaults to 443). */ /** * Create a new Client instance. * * @param {string} token - The DigitalOcean token used for authorization. * @param {ClientOptions} [options] - An object whose values are used to configure a client instance. * @memberof Client */ function Client(token, options) { this.token = token; this.options = options; this.requestOptions = this.options && this.options.requestOptions || {}; this.request = this.options && this.options.request || request; this.promise = this.options && this.options.promise || Promise; this.decamelizeKeys = this.options ? this.options.decamelizeKeys : true; var version = require('../../package.json').version; this.requestDefaults = { headers: { 'User-Agent': 'digitalocean-node/' + version, 'Content-Type': 'application/json' } }; this.version = 'v2'; this.host = 'api.digitalocean.com'; this.account = new Account(this); this.actions = new Action(this); this.volumes = new Volume(this); this.certificates = new Certificate(this); this.domains = new Domain(this); this.droplets = new Droplet(this); this.floatingIps = new FloatingIp(this); this.firewalls = new Firewall(this); this.images = new Image(this); this.loadBalancers = new LoadBalancer(this); this.regions = new Region(this); this.sizes = new Size(this); this.snapshots = new Snapshot(this); this.tags = new Tag(this); } /** @private */ Client.prototype._buildUrl = function(path, urlParams) { if (path == null) { path = '/'; } if (urlParams == null) { urlParams = {}; } var urlFromPath = url.parse(this.version + path); if (!!this.decamelizeKeys) { urlParams = util.decamelizeKeys(urlParams); } return url.format({ protocol: urlFromPath.protocol || this.options && this.options.protocol || "https:", auth: urlFromPath.auth || (this.token && this.token.username && this.token.password ? this.token.username + ":" + this.token.password : ''), hostname: urlFromPath.hostname || this.options && this.options.hostname || this.host, port: urlFromPath.port || this.options && this.options.port, pathname: urlFromPath.pathname, query: urlParams }); }; // Returns a function that curries the callback to handle the response from // `request`. The returned function has an interface of: `function(err, res, body)`. // // successStatuses, required, number or array of numbers // successRootKeys, required, string or array of strings // callback, required, function /** @private */ Client.prototype._buildRequestPromiseHandler = function(requestOptions, successStatuses, successRootKeys, resolve, reject) { if (typeof successStatuses === 'number') { successStatuses = [successStatuses]; } if (typeof successRootKeys === 'string') { successRootKeys = [successRootKeys]; } var self = this; var Promise = this.promise; return function(err, res, body) { if (err) { return reject(err); } // Handle errors on DO's side (5xx level) var statusCodeLevel = Math.floor(res.statusCode / 100); if (statusCodeLevel === 5) { return reject(new DigitalOceanError('Error ' + res.statusCode, res.statusCode, res.headers)); } // Handle improperly returned reponses (e.g. html or something else bizarre) if (typeof body === 'string') { try { body = JSON.parse(body || '{}'); } catch (jsonParseError) { return reject(jsonParseError); } } // Handle validation errors (4xx level) if (body.message && statusCodeLevel === 4) { return reject(new DigitalOceanError(body.message, res.statusCode, res.headers, body)); } // Handle an unexpcted response code if (successStatuses.indexOf(res.statusCode) < 0) { return reject(new Error('Unexpected reponse code: ' + res.statusCode)); } // Find the first key from the body object in successRootKeys var data = {}; for (var i = 0; i < successRootKeys.length; i++) { var key = successRootKeys[i]; if (body[key]) { data = body[key]; break; } } // If body.meta.total exists, then it's a paginated response var result; if (body.meta && body.meta.total) { result = new util.ListResponse(self, data, body.meta.total, requestOptions, successStatuses, successRootKeys, Promise); } else { result = data; } // Append response data under a special key in the object result._digitalOcean = { statusCode: res.statusCode, body: body, headers: res.headers }; return resolve(result); }; }; /** @private */ Client.prototype._callbackOrPromise = function(options, overrideOptions, successStatuses, successRootKeys, callback) { // Use a hierarchy of options to provide overrides: // 1. this.requestDefaults (specified by client) // 2. this.requestOptions (specified by user at client initialization) // 3. options (specfied by client per call type) // 4. overrideOptions (specified by user at call time) var requestOptions = deepExtend(this.requestDefaults, this.requestOptions, options, overrideOptions); var self = this; var deferred = new this.promise(function(resolve, reject) { self.request( requestOptions, self._buildRequestPromiseHandler.apply(self, [requestOptions, successStatuses, successRootKeys, resolve, reject]) ); }); if (callback) { // If a callback is provided, translate it to a Promise (to ensure // it's called outside of the promise stack, call via timeout) deferred .then(function(response) { setTimeout(function() { callback( null, response, response._digitalOcean.headers, response._digitalOcean.body ); }, 0); }) .catch(function(error) { setTimeout(function() { callback(error); }, 0); }); } return deferred; }; /** * Send a HTTP GET request with the specified parameters. * * @param {string} path - the URL escaped route * @param {object} options - an object passed to the request library See the {@link https://github.com/request/request#requestoptions-callback|request docs} for valid attributes, e.g. a proxy or user agent * @param {(number|object)} [page or queryObject] - page number to retrieve or key value pairs of query parameters * @param {number} [perPage] - number of result per page to retrieve * @param {number|number[]} successStatuses - number or array of numbers corresponding to successful HTTP status codes * @param {string|string[]} successRootKeys - string or array of strings corresponding to the root objects containing successful responses * @param {requestCallback} [callback] - callback that handles the response * @memberof Client */ Client.prototype.get = function() { var i; var path = arguments[0], options = arguments[1], params = 4 <= arguments.length ? slice.call(arguments, 2, i = arguments.length - 3) : (i = 2, []), successStatuses = arguments[i++], successRootKeys = arguments[i++], callback = arguments[i++]; var pageOrQuery = params[0], perPage = params[1], query = null; if ((pageOrQuery != null) && typeof pageOrQuery === 'object') { query = pageOrQuery; } else { query = {}; if (pageOrQuery != null) { query.page = pageOrQuery; } if (perPage != null) { query.per_page = perPage; } } return this._callbackOrPromise( { uri: this._buildUrl(path, query), method: 'GET', headers: { 'Authorization': 'Bearer ' + this.token }, query: query, path: path, }, options, successStatuses, successRootKeys, callback ); }; /** @private */ Client.prototype._makeRequestWithBody = function(type, path, content, options, successStatuses, successRootKeys, callback) { // if `options` isn't passed, shift arguments back by one and set // default hash for options if (callback == null && (successRootKeys == null || typeof successRootKeys === 'function')) { callback = successRootKeys; successRootKeys = successStatuses; successStatuses = options; options = {}; } if (!!this.decamelizeKeys) { content = util.decamelizeKeys(content); } return this._callbackOrPromise( { uri: this._buildUrl(path, options.query), method: type, headers: { 'Authorization': 'Bearer ' + this.token }, body: JSON.stringify(content) }, options, successStatuses, successRootKeys, callback ); }; /** * Send a HTTP POST request with the specified parameters. * * @param {string} path - the URL escaped route * @param {object} content - an object serialized to json * @param {object} options - an object passed to the request library See the {@link https://github.com/request/request#requestoptions-callback|request docs} for valid attributes, e.g. a proxy or user agent * @param {number|number[]} successStatuses - number or array of numbers corresponding to successful HTTP status codes * @param {string|string[]} successRootKeys - string or array of strings corresponding to the root objects containing successful responses * @param {requestCallback} [callback] - callback that handles the response * @memberof Client */ Client.prototype.post = function(path, content, options, successStatuses, successRootKeys, callback) { return this._makeRequestWithBody('POST', path, content, options, successStatuses, successRootKeys, callback); }; /** * Send a HTTP PATCH request with the specified parameters. * * @param {string} path - the URL escaped route * @param {object} content - an object serialized to json * @param {object} options - an object passed to the request library See the {@link https://github.com/request/request#requestoptions-callback|request docs} for valid attributes, e.g. a proxy or user agent * @param {number|number[]} successStatuses - number or array of numbers corresponding to successful HTTP status codes * @param {string|string[]} successRootKeys - string or array of strings corresponding to the root objects containing successful responses * @param {requestCallback} [callback] - callback that handles the response * @memberof Client */ Client.prototype.patch = function(path, content, options, successStatuses, successRootKeys, callback) { return this._makeRequestWithBody('PATCH', path, content, options, successStatuses, successRootKeys, callback); }; /** * Send a HTTP PUT request with the specified parameters. * * @param {string} path - the URL escaped route * @param {object} content - an object serialized to json * @param {object} options - an object passed to the request library See the {@link https://github.com/request/request#requestoptions-callback|request docs} for valid attributes, e.g. a proxy or user agent * @param {number|number[]} successStatuses - number or array of numbers corresponding to successful HTTP status codes * @param {string|string[]} successRootKeys - string or array of strings corresponding to the root objects containing successful responses * @param {requestCallback} [callback] - callback that handles the response * @memberof Client */ Client.prototype.put = function(path, content, options, successStatuses, successRootKeys, callback) { return this._makeRequestWithBody('PUT', path, content, options, successStatuses, successRootKeys, callback); }; /** * Send a HTTP DELETE request with the specified parameters. * * @param {string} path - the URL escaped route * @param {object} content - an object serialized to json * @param {object} options - an object passed to the request library See the {@link https://github.com/request/request#requestoptions-callback|request docs} for valid attributes, e.g. a proxy or user agent * @param {number|number[]} successStatuses - number or array of numbers corresponding to successful HTTP status codes * @param {string|string[]} successRootKeys - string or array of strings corresponding to the root objects containing successful responses * @param {requestCallback} [callback] - callback that handles the response * @memberof Client */ Client.prototype.delete = function(path, content, options, successStatuses, successRootKeys, callback) { return this._makeRequestWithBody('DELETE', path, content, options, successStatuses, successRootKeys, callback); }; return Client; })(); module.exports = function(token, options) { return new Client(token, options); }; }).call(this); },{"../../package.json":404,"./account":2,"./action":3,"./certificate":4,"./domain":6,"./droplet":7,"./error":8,"./firewall":9,"./floating_ip":10,"./image":11,"./load_balancer":12,"./region":13,"./size":14,"./snapshot":15,"./tag":16,"./util":17,"./volume":18,"bluebird":19,"deep-extend":275,"request":276,"url":267}],6:[function(require,module,exports){ (function() { var slice = [].slice, util = require('./util'); /** * Domain resource * @class Domain */ var Domain = (function() { function Domain(client) { this.client = client; } /** * List domain objects. * * @param {(number|object)} [page or queryObject] - page number to retrieve or key value pairs of query parameters * @param {number} [perPage] - number of result per page to retrieve * @param {listRequestCallback} [callback] - callback that handles the response * @memberof Domain */ Domain.prototype.list = function() { var args = util.extractListArguments(arguments, 0); return this.client.get.apply(this.client, ['/domains', {}].concat(slice.call(args.params), [200, 'domains', args.callback])); }; /** * Create a domain object. * * @param {object} attributes - The attributes with which to create the domain. See the {@link https://developers.digitalocean.com/documentation/v2/#domains|official docs} for valid attributes. * @param {requestCallback} [callback] - callback that handles the response * @memberof Domain */ Domain.prototype.create = function(attributes, callback) { return this.client.post('/domains', attributes, 201, 'domain', callback); }; /** * Get the identified domain object. * * @param {string} name - The name of the domain to retrieve * @param {requestCallback} [callback] - callback that handles the response * @memberof Domain */ Domain.prototype.get = function(name, callback) { var url = util.safeUrl('domains', name); return this.client.get(url, {}, 200, 'domain', callback); }; /** * Delete the identified domain object. * * @param {string} name - The name of the domain to delete * @param {requestCallback} [callback] - callback that handles the response * @memberof Domain */ Domain.prototype.delete = function(name, callback) { var url = util.safeUrl('domains', name); return this.client.delete(url, {}, 204, [], callback); }; /** * List domain record objects. * * @param {string} domainName - name of domain for which to retrieve records * @param {(number|object)} [page or queryObject] - page number to retrieve or key value pairs of query parameters * @param {number} [perPage] - number of result per page to retrieve * @param {listRequestCallback} [callback] - callback that handles the response * @memberof Domain */ Domain.prototype.listRecords = function() { var args = util.extractListArguments(arguments, 1); var url = util.safeUrl('domains', args.identifier, 'records'); return this.client.get.apply(this.client, [url, {}].concat(slice.call(args.params), [200, 'domain_records', args.callback])); }; /** * Get the identified domain record object. * * @param {string} domainName - The name of the domain for which to retrieve a record * @param {number} id - The id of the domain record to retrieve * @param {requestCallback} [callback] - callback that handles the response * @memberof Domain */ Domain.prototype.getRecord = function(domainName, id, callback) { var url = util.safeUrl('domains', domainName, 'records', id); return this.client.get(url, {}, 200, 'domain_record', callback); }; /** * Create a record object in a domain. * * @param {string} domainName - The name of the domain for which to create a record * @param {object} attributes - The attributes with which to create the domain record. See the {@link https://developers.digitalocean.com/documentation/v2/#domain-records|official docs} for valid attributes. * @param {requestCallback} [callback] - callback that handles the response * @memberof Domain */ Domain.prototype.createRecord = function(domainName, attributes, callback) { var url = util.safeUrl('domains', domainName, 'records'); return this.client.post(url, attributes, 201, 'domain_record', callback); }; /** * Update the identified record object in a domain. * * @param {string} domainName - The name of the domain for which to update the record * @param {number} id - The id of the domain record to retrieve * @param {object} attributes - The attributes with which to update the domain record. See the {@link https://developers.digitalocean.com/documentation/v2/#domain-records|official docs} for valid attributes. * @param {requestCallback} [callback] - callback that handles the response * @memberof Domain */ Domain.prototype.updateRecord = function(domainName, id, attributes, callback) { var url = util.safeUrl('domains', domainName, 'records', id); return this.client.put(url, attributes, 200, 'domain_record', callback); }; /** * Delete the identified domain record object. * * @param {string} domainName - The name of the domain for which to delete a record * @param {number} id - The id of the domain record to retrieve * @param {requestCallback} [callback] - callback that handles the response * @memberof Domain */ Domain.prototype.deleteRecord = function(domainName, id, callback) { var url = util.safeUrl('domains', domainName, 'records', id); return this.client.delete(url, {}, 204, [], callback); }; return Domain; })(); module.exports = Domain; }).call(this); },{"./util":17}],7:[function(require,module,exports){ (function() { var slice = [].slice, util = require('./util'); /** * Droplet resource * @class Droplet */ var Droplet = (function() { function Droplet(client) { this.client = client; } /** * List Droplet objects. * * @param {(number|object)} [page or queryObject] - page number to retrieve or key value pairs of query parameters * @param {number} [perPage] - number of result per page to retrieve * @param {listRequestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.list = function() { var args = util.extractListArguments(arguments, 0); return this.client.get.apply(this.client, ['/droplets', {}].concat(slice.call(args.params), [200, 'droplets', args.callback])); }; /** * Create a Droplet object. * * @param {object} attributes - The attributes with which to create the Droplet. See the {@link https://developers.digitalocean.com/documentation/v2/#droplets|official docs} for valid attributes. * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.create = function(attributes, callback) { return this.client.post('/droplets', attributes, 202, ['droplet', 'droplets'], callback); }; /** * Get the identified Droplet object. * * @param {number} id - The id of the Droplet to retrieve * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.get = function(id, callback) { var url = util.safeUrl('droplets', id); return this.client.get(url, {}, 200, 'droplet', callback); }; /** * List kernel objects. * * @param {number} id - ID of Droplet for which to retrieve kernels * @param {(number|object)} [page or queryObject] - page number to retrieve or key value pairs of query parameters * @param {number} [perPage] - number of result per page to retrieve * @param {listRequestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.kernels = function() { var args = util.extractListArguments(arguments, 1); var url = util.safeUrl('droplets', args.identifier, 'kernels'); return this.client.get.apply(this.client, [url, {}].concat(slice.call(args.params), [200, 'kernels', args.callback])); }; /** * List of image objects that are snapshots of the Droplet. * * @param {number} id - ID of Droplet for which to retrieve snapshots * @param {(number|object)} [page or queryObject] - page number to retrieve or key value pairs of query parameters * @param {number} [perPage] - number of result per page to retrieve * @param {listRequestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.snapshots = function() { var args = util.extractListArguments(arguments, 1); var url = util.safeUrl('droplets', args.identifier, 'snapshots'); return this.client.get.apply(this.client, [url, {}].concat(slice.call(args.params), [200, 'snapshots', args.callback])); }; /** * List backup objects that are backups of the Droplet. * * @param {number} id - ID of Droplet for which to retrieve backups * @param {(number|object)} [page or queryObject] - page number to retrieve or key value pairs of query parameters * @param {number} [perPage] - number of result per page to retrieve * @param {listRequestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.backups = function() { var args = util.extractListArguments(arguments, 1); var url = util.safeUrl('droplets', args.identifier, 'backups'); return this.client.get.apply(this.client, [url, {}].concat(slice.call(args.params), [200, 'backups', args.callback])); }; /** * List of Droplet objects that are physically co-located with the Droplet. * * @param {number} id - ID of Droplet for which to retrieve neighbors * @param {(number|object)} [page or queryObject] - page number to retrieve or key value pairs of query parameters * @param {number} [perPage] - number of result per page to retrieve * @param {listRequestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.neighbors = function() { var args = util.extractListArguments(arguments, 1); var url = util.safeUrl('droplets', args.identifier, 'neighbors'); return this.client.get.apply(this.client, [url, {}].concat(slice.call(args.params), [200, 'droplets', args.callback])); }; /** * Delete the identified Droplet object. * * @param {number} id - The id of the Droplet to retrieve * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.delete = function(id, callback) { var url = util.safeUrl('droplets', id); return this.client.delete(url, {}, 204, [], callback); }; /** * Delete the Droplets associated with the tag identified by the name. * * @param {string} name - The name of the tag for which to delete Droplets. * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.deleteByTag = function(name, callback) { var url = util.safeUrl('droplets'); var params = { tag_name: encodeURIComponent(name) }; return this.client.delete(url, params, 204, [], callback); }; /** * List of action objects. * * @param {number} id - ID of Droplet for which to retrieve actions * @param {(number|object)} [page or queryObject] - page number to retrieve or key value pairs of query parameters * @param {number} [perPage] - number of result per page to retrieve * @param {listRequestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.listActions = function() { var args = util.extractListArguments(arguments, 1); var url = util.safeUrl('droplets', args.identifier, 'actions'); return this.client.get.apply(this.client, [url, {}].concat(slice.call(args.params), [200, 'actions', args.callback])); }; /** * Get the identified action object. * * @param {number} dropletId - The id of the droplet for which to retrieve the action * @param {number} id - The id of the action to retrieve * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.getAction = function(dropletId, id, callback) { var url = util.safeUrl('droplets', dropletId, 'actions', id); return this.client.get(url, {}, 200, 'action', callback); }; /** * Create an action on the identified Droplet. * * @param {number} dropletId - The id of the droplet for which to create the action * @param {string|object} parametersOrType - The name of the action to create or an object with key value pairs of parameters. * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.action = function(dropletId, parametersOrType, callback) { var parameters; if(typeof parametersOrType === 'string') { parameters = { type: parametersOrType }; } else { parameters = parametersOrType; } var url = util.safeUrl('droplets', dropletId, 'actions'); return this.client.post(url, parameters, 201, 'action', callback); }; /** * Delete the Droplets associated with the tag identified by the name. * * @param {string} name - The name of the tag for which to delete Droplets. * @param {string} actionType - The type of action to perform. See the {@link https://developers.digitalocean.com/documentation/v2/#acting-on-tagged-droplets|official docs} for accepted actions. * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.actionByTag = function(tagName, actionType, callback) { var parameters = { tag_name: tagName, type: actionType }; return this.client.post('/droplets/actions', parameters, 201, 'actions', callback); }; /** * Shutdown the identified Droplet. * * @param {number} dropletId - The id of the droplet for which to create the action * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.shutdown = function(dropletId, callback) { return this.action(dropletId, 'shutdown', callback); }; /** * Power off the identified Droplet. * * @param {number} dropletId - The id of the droplet for which to create the action * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.powerOff = function(dropletId, callback) { return this.action(dropletId, 'power_off', callback); }; /** * Power on the identified Droplet. * * @param {number} dropletId - The id of the droplet for which to create the action * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.powerOn = function(dropletId, callback) { return this.action(dropletId, 'power_on', callback); }; /** * Power cycle the identified Droplet. * * @param {number} dropletId - The id of the droplet for which to create the action * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.powerCycle = function(dropletId, callback) { return this.action(dropletId, 'power_cycle', callback); }; /** * Reboot the identified Droplet. * * @param {number} dropletId - The id of the droplet for which to create the action * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.reboot = function(dropletId, callback) { return this.action(dropletId, 'reboot', callback); }; /** * Enable backups on the identified Droplet. * * @param {number} dropletId - The id of the droplet for which to create the action * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.enableBackups = function(dropletId, callback) { return this.action(dropletId, 'enable_backups', callback); }; /** * Disable backups on the identified Droplet. * * @param {number} dropletId - The id of the droplet for which to create the action * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.disableBackups = function(dropletId, callback) { return this.action(dropletId, 'disable_backups', callback); }; /** * Reset the root user's password on the identified Droplet. * * @param {number} dropletId - The id of the droplet for which to create the action * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.passwordReset = function(dropletId, callback) { return this.action(dropletId, 'password_reset', callback); }; /** * Enable IPv6 networking on the identified Droplet. * * @param {number} dropletId - The id of the droplet for which to create the action * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.enableIPv6 = function(dropletId, callback) { return this.action(dropletId, 'enable_ipv6', callback); }; /** * Enable private-to-the-datacenter networking on the identified Droplet. * * @param {number} dropletId - The id of the droplet for which to create the action * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.enablePrivateNetworking = function(dropletId, callback) { return this.action(dropletId, 'enable_private_networking', callback); }; /** * Change the available resources for the identified Droplet. * * @param {number} dropletId - The id of the droplet for which to create the action * @param {string|object} parametersOrSizeSlug - If a string, the name of the size to change the Droplet to. Otherwise, an object with required keys of `size`. See the {@link https://developers.digitalocean.com/documentation/v2/#resize-a-droplet|official docs} for valid attributes. * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.resize = function(dropletId, parametersOrSizeSlug, callback) { var parameters; if(typeof parametersOrSizeSlug !== 'object') { parameters = { size: parametersOrSizeSlug }; } else { parameters = parametersOrSizeSlug; } parameters.type = 'resize'; return this.action(dropletId, parameters, callback); }; /** * Change the hostname of the identified Droplet. * * @param {number} dropletId - The id of the droplet for which to create the action * @param {string|object} parametersOrHostname - If a string, the hostname to change the Droplet to. Otherwise, an object with required keys of `name`. See the {@link https://developers.digitalocean.com/documentation/v2/#rename-a-droplet|official docs} for valid attributes. * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.rename = function(dropletId, parametersOrHostname, callback) { var parameters; if(typeof parametersOrHostname !== 'object') { parameters = { name: parametersOrHostname }; } else { parameters = parametersOrHostname; } parameters.type = 'rename'; return this.action(dropletId, parameters, callback); }; /** * Create a snapshot image of the identified Droplet. * * @param {number} dropletId - The id of the droplet for which to create the action * @param {string|object} parametersOrName - If a string, the name of the created image. Otherwise, an object with required keys of `name`. See the {@link https://developers.digitalocean.com/documentation/v2/#snapshot-a-droplet|official docs} for valid attributes. * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.snapshot = function(dropletId, parametersOrName, callback) { var parameters; if(typeof parametersOrName !== 'object') { parameters = { name: parametersOrName }; } else { parameters = parametersOrName; } parameters.type = 'snapshot'; return this.action(dropletId, parameters, callback); }; /** * Recreate the Droplet from the identified image snapshot or backup. * * @param {number} dropletId - The id of the droplet for which to create the action * @param {number|object} parametersOrImageId - If a number, identifier of the image to use. Otherwise, an object with required keys of `image`. See the {@link https://developers.digitalocean.com/documentation/v2/#restore-a-droplet|official docs} for valid attributes. * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.restore = function(dropletId, parametersOrImageId, callback) { var parameters; if(typeof parametersOrImageId !== 'object') { parameters = { image: parametersOrImageId }; } else { parameters = parametersOrImageId; } parameters.type = 'restore'; return this.action(dropletId, parameters, callback); }; /** * Recreate the Droplet from the identified distribution image. * * @param {number} dropletId - The id of the droplet for which to create the action * @param {string|number|object} parametersOrImage - If a string, the slug of the distribution image to use. If a number, the identifier of the distribution image to use. Otherwise, an object with required keys of `image`. See the {@link https://developers.digitalocean.com/documentation/v2/#rebuild-a-droplet|official docs} for valid attributes. * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.rebuild = function(dropletId, parametersOrImage, callback) { var parameters; if(typeof parametersOrImage !== 'object') { parameters = { image: parametersOrImage }; } else { parameters = parametersOrImage; } parameters.type = 'rebuild'; return this.action(dropletId, parameters, callback); }; /** * Recreate the Droplet from the identified distribution image. * * @param {number} dropletId - The id of the droplet for which to create the action * @param {number|object} parametersOrKernelId - If a number, the identifier of the kernel to use. Otherwise, an object with required keys of `kernel`. See the {@link https://developers.digitalocean.com/documentation/v2/#change-the-kernel|official docs} for valid attributes. * @param {requestCallback} [callback] - callback that handles the response * @memberof Droplet */ Droplet.prototype.changeKernel = function(dropletId, parametersOrKernelId, callback) { var parameters; if(typeof parametersOrKernelId !== 'object') { parameters = { kernel: parametersOrKernelId }; } else { parameters = parametersOrKernelId; } parameters.type = 'change_kernel'; return this.action(dropletId, parameters, callback); }; return Droplet; })(); module.exports = Droplet; }).call(this); },{"./util":17}],8:[function(require,module,exports){ (function() { var extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) { child[key] = parent[key]; } } function Constructor() { this.constructor = child; } Constructor.prototype = parent.prototype; child.prototype = new Constructor(); child.__super__ = parent.prototype; return child; }, hasProp = {}.hasOwnProperty; var DigitalOceanError = (function(superClass) { extend(DigitalOceanError, superClass); function DigitalOceanError(message, statusCode, headers, body) { this.message = message; this.statusCode = statusCode; this.headers = headers; this.body = body; } return DigitalOceanError; })(Error); module.exports = DigitalOceanError; }).call(this); },{}],9:[function(require,module,exports){ (function() { var slice = [].slice, util = require('./util'); /** * Firewall resource * @class Firewall */ var Firewall = (function() { function Firewall(client) { this.client = client; } /** * List firewall objects. * * @param {(number|object)} [page or queryObject] - page number to retrieve or key value