digitalocean
Version:
nodejs wrapper for digitalocean v2 api
223 lines (188 loc) • 8.87 kB
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: digitalocean/firewall.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: digitalocean/firewall.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>(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 pairs of query parameters
* @param {number} [perPage] - number of result per page to retrieve
* @param {listRequestCallback} [callback] - callback that handles the response
* @memberof Tag
*/
Firewall.prototype.list = function() {
var args = util.extractListArguments(arguments, 0);
return this.client.get.apply(this.client, ['/firewalls', {}].concat(slice.call(args.params), [200, 'firewalls', args.callback]));
};
/**
* Create a firewall object.
*
* @param {object} attributes - The attributes with which to create the firewall. See the {@link https://developers.digitalocean.com/documentation/v2/#firewalls|official docs} for valid attributes.
* @param {requestCallback} [callback] - callback that handles the response
* @memberof Firewall
*/
Firewall.prototype.create = function(attributes, callback) {
return this.client.post('/firewalls', attributes, 202, 'firewall', callback);
};
/**
* Get the identified firewall object.
*
* @param {string} id - The id of the firewall to retrieve
* @param {requestCallback} [callback] - callback that handles the response
* @memberof Firewall
*/
Firewall.prototype.get = function(id, callback) {
var url = util.safeUrl('firewalls', id);
return this.client.get(url, {}, 200, 'firewall', callback);
};
/**
* Delete the identified firewall object.
*
* @param {string} id - The id of the firewall to delete
* @param {requestCallback} [callback] - callback that handles the response
* @memberof Firewall
*/
Firewall.prototype.delete = function(id, callback) {
var url = util.safeUrl('firewalls', id);
return this.client.delete(url, {}, 204, [], callback);
};
/**
* Update the identified firewall object.
*
* @param {string} id - The id of the firewall to update
* @param {object} attributes - The attributes with which to create the firewall. See the {@link https://developers.digitalocean.com/documentation/v2/#firewalls|official docs} for valid attributes.
* @param {requestCallback} [callback] - callback that handles the response
* @memberof Firewall
*/
Firewall.prototype.update = function(id, attributes, callback) {
var url = util.safeUrl('firewalls', id);
return this.client.put(url, attributes, 200, [], callback);
};
/**
* Add droplets to a firewall.
*
* @param {string} firewallId - The id of the firewall to update
* @param {number|number[]} dropletIds - The ids of droplets to add. See the {@link https://developers.digitalocean.com/documentation/v2/#firewalls|official docs} for valid attributes.
* @param {requestCallback} [callback] - callback that handles the response
* @memberof Firewall
*/
Firewall.prototype.addDroplets = function(firewallId, dropletIds, callback) {
var dropletIdsObject = {
droplet_ids: Array.isArray(dropletIds) ? dropletIds : [dropletIds]
};
var url = util.safeUrl('firewalls', firewallId, 'droplets');
return this.client.post(url, dropletIdsObject, 204, [], callback);
};
/**
* Remove droplets from a firewall.
*
* @param {string} firewallId - The id of the firewall to update
* @param {number|number[]} dropletIds - The ids of droplets to remove. See the {@link https://developers.digitalocean.com/documentation/v2/#firewalls|official docs} for valid attributes.
* @param {requestCallback} [callback] - callback that handles the response
* @memberof Firewall
*/
Firewall.prototype.removeDroplets = function(firewallId, dropletIds, callback) {
var dropletIdsObject = {
droplet_ids: Array.isArray(dropletIds) ? dropletIds : [dropletIds]
};
var url = util.safeUrl('firewalls', firewallId, 'droplets');
return this.client.delete(url, dropletIdsObject, 204, [], callback);
};
/**
* Add tags to a firewall.
*
* @param {string} firewallId - The id of the firewall to update
* @param {string|string[]} tags - Tags to add. See the {@link https://developers.digitalocean.com/documentation/v2/#firewalls|official docs} for valid attributes.
* @param {requestCallback} [callback] - callback that handles the response
* @memberof Firewall
*/
Firewall.prototype.addTags = function(firewallId, tags, callback) {
var tagsObject = {
tags: Array.isArray(tags) ? tags : [tags]
};
var url = util.safeUrl('firewalls', firewallId, 'tags');
return this.client.post(url, tagsObject, 204, [], callback);
};
/**
* Remove tags from a firewall.
*
* @param {string} firewallId - The id of the firewall to update
* @param {string|string[]} tags - Tags to add. See the {@link https://developers.digitalocean.com/documentation/v2/#firewalls|official docs} for valid attributes.
* @param {requestCallback} [callback] - callback that handles the response
* @memberof Firewall
*/
Firewall.prototype.removeTags = function(firewallId, tags, callback) {
var tagsObject = {
tags: Array.isArray(tags) ? tags : [tags]
};
var url = util.safeUrl('firewalls', firewallId, 'tags');
return this.client.delete(url, tagsObject, 204, [], callback);
};
/**
* Add rules to a firewall.
*
* @param {string} firewallId - The id of the firewall to update
* @param {object} rules - The rule definition object. See the {@link https://developers.digitalocean.com/documentation/v2/#firewalls|official docs} for valid attributes.
* @param {requestCallback} [callback] - callback that handles the response
* @memberof Firewall
*/
Firewall.prototype.addRules = function(firewallId, rules, callback) {
var url = util.safeUrl('firewalls', firewallId, 'rules');
return this.client.post(url, rules, 204, [], callback);
};
/**
* Remove rules from a firewall.
*
* @param {string} firewallId - The id of the firewall to update
* @param {object} rules - The rule definition object. See the {@link https://developers.digitalocean.com/documentation/v2/#firewalls|official docs} for valid attributes.
* @param {requestCallback} [callback] - callback that handles the response
* @memberof Firewall
*/
Firewall.prototype.removeRules = function(firewallId, rules, callback) {
var url = util.safeUrl('firewalls', firewallId, 'rules');
return this.client.delete(url, rules, 204, [], callback);
};
return Firewall;
})();
module.exports = Firewall;
}).call(this);
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Account.html">Account</a></li><li><a href="Action.html">Action</a></li><li><a href="Certificate.html">Certificate</a></li><li><a href="Client.html">Client</a></li><li><a href="Domain.html">Domain</a></li><li><a href="Droplet.html">Droplet</a></li><li><a href="Firewall.html">Firewall</a></li><li><a href="FloatingIp.html">FloatingIp</a></li><li><a href="Image.html">Image</a></li><li><a href="ListResponse.html">ListResponse</a></li><li><a href="LoadBalancer.html">LoadBalancer</a></li><li><a href="Region.html">Region</a></li><li><a href="Size.html">Size</a></li><li><a href="Snapshot.html">Snapshot</a></li><li><a href="Tag.html">Tag</a></li><li><a href="Volume.html">Volume</a></li></ul><h3><a href="global.html">Global</a></h3>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.0</a>
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>