Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

consul

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

consul - npm Package Compare versions

Comparing version 0.8.0 to 0.9.0

63

lib/agent.js

@@ -46,3 +46,3 @@ /**

Agent.prototype.members = function(opts, callback) {
if (typeof opts === 'function') {
if (!callback) {
callback = opts;

@@ -57,12 +57,10 @@ opts = {};

var req = {
name: 'agent.members',
path: '/agent/members',
query: {},
};
if (opts.wan) req.query.wan = '1';
utils.options(req, opts);
this.consul._get('/agent/members', req, function(err, res) {
if (err) return callback(err);
callback(null, res.body);
});
this.consul._get(req, utils.body, callback);
};

@@ -74,10 +72,18 @@

Agent.prototype.self = function(callback) {
Agent.prototype.self = function(opts, callback) {
if (!callback) {
callback = opts;
opts = {};
}
this.consul._log(['debug', 'agent', 'self']);
this.consul._get('/agent/self', function(err, res) {
if (err) return callback(err);
var req = {
name: 'agent.self',
path: '/agent/self',
};
callback(null, res.body);
});
utils.options(req, opts);
this.consul._get(req, utils.body, callback);
};

@@ -98,16 +104,16 @@

if (!opts.address) return callback(new Error('address required'));
var req = {
path: { address: opts.address },
name: 'agent.join',
path: '/agent/join/{address}',
params: { address: opts.address },
query: {},
};
if (opts.wan) req.query.wan = '1';
if (!opts.address) {
return callback(this.consul._err('address required', req));
}
this.consul._get('/agent/join/{address}', req, function(err) {
if (err) return callback(err);
utils.options(req, opts);
callback();
});
this.consul._get(req, utils.empty, callback);
};

@@ -128,14 +134,15 @@

if (!opts.node) return callback(new Error('node required'));
var req = {
method: 'GET',
path: { node: opts.node },
name: 'agent.forceLeave',
path: '/agent/force-leave/{node}',
params: { node: opts.node },
};
this.consul._get('/agent/force-leave/{node}', req, function(err) {
if (err) return callback(err);
if (!opts.node) {
return callback(this.consul._err('node required', req));
}
callback();
});
utils.options(req, opts);
this.consul._get(req, utils.empty, callback);
};

@@ -142,0 +149,0 @@

@@ -25,10 +25,18 @@ /**

AgentCheck.prototype.list = function(callback) {
AgentCheck.prototype.list = function(opts, callback) {
if (!callback) {
callback = opts;
opts = {};
}
this.consul._log(['debug', 'agentcheck', 'list']);
this.consul._get('/agent/checks', function(err, res) {
if (err) return callback(err);
var req = {
name: 'agent.check.list',
path: '/agent/checks',
};
callback(null, res.body);
});
utils.options(req, opts);
this.consul._get(req, utils.body, callback);
};

@@ -45,5 +53,5 @@

if (!opts.name) return callback(new Error('name required'));
var req = {
name: 'agent.check.register',
path: '/agent/check/register',
type: 'json',

@@ -53,2 +61,4 @@ body: {},

if (!opts.name) return callback(this.consul._err('name required', req));
if (opts.hasOwnProperty('id')) req.body.Id = opts.id;

@@ -62,11 +72,9 @@ if (opts.hasOwnProperty('name')) req.body.Name = opts.name;

} else {
return callback(new Error('script and interval, or ttl required'));
return callback(this.consul._err('script and interval, or ttl required', req));
}
if (opts.hasOwnProperty('notes')) req.body.Notes = opts.notes;
this.consul._put('/agent/check/register', req, function(err) {
if (err) return callback(err);
utils.options(req, opts);
callback();
});
this.consul._put(req, utils.empty, callback);
};

@@ -87,14 +95,13 @@

if (!opts.id) return callback(new Error('id required'));
var req = {
method: 'GET',
path: { id: opts.id },
name: 'agent.check.deregister',
path: '/agent/check/deregister/{id}',
params: { id: opts.id },
};
this.consul._get('/agent/check/deregister/{id}', req, function(err) {
if (err) return callback(err);
if (!opts.id) return callback(this.consul._err('id required', req));
callback();
});
utils.options(req, opts);
this.consul._get(req, utils.empty, callback);
};

@@ -115,16 +122,16 @@

if (!opts.id) return callback(new Error('id required'));
var req = {
path: { id: opts.id },
name: 'agent.check.pass',
path: '/agent/check/pass/{id}',
params: { id: opts.id },
query: {},
};
if (!opts.id) return callback(this.consul._err('id required', req));
if (opts.note) req.query.note = opts.note;
this.consul._get('/agent/check/pass/{id}', req, function(err) {
if (err) return callback(err);
utils.options(req, opts);
callback();
});
this.consul._get(req, utils.empty, callback);
};

@@ -145,16 +152,16 @@

if (!opts.id) return callback(new Error('id required'));
var req = {
path: { id: opts.id },
name: 'agent.check.warn',
path: '/agent/check/warn/{id}',
params: { id: opts.id },
query: {},
};
if (!opts.id) return callback(this.consul._err('id required', req));
if (opts.note) req.query.note = opts.note;
this.consul._get('/agent/check/warn/{id}', req, function(err) {
if (err) return callback(err);
utils.options(req, opts);
callback();
});
this.consul._get(req, utils.empty, callback);
};

@@ -175,16 +182,16 @@

if (!opts.id) return callback(new Error('id required'));
var req = {
path: { id: opts.id },
name: 'agent.check.fail',
path: '/agent/check/fail/{id}',
params: { id: opts.id },
query: {},
};
if (!opts.id) return callback(this.consul._err('id required', req));
if (opts.note) req.query.note = opts.note;
this.consul._get('/agent/check/fail/{id}', req, function(err) {
if (err) return callback(err);
utils.options(req, opts);
callback();
});
this.consul._get(req, utils.empty, callback);
};

@@ -191,0 +198,0 @@

@@ -25,10 +25,18 @@ /**

AgentService.prototype.list = function(callback) {
AgentService.prototype.list = function(opts, callback) {
if (!callback) {
callback = opts;
opts = {};
}
this.consul._log(['debug', 'agentservice', 'list']);
this.consul._get('/agent/services', function(err, res) {
if (err) return callback(err);
var req = {
name: 'agent.service.list',
path: '/agent/services',
};
callback(null, res.body);
});
utils.options(req, opts);
this.consul._get(req, utils.body, callback);
};

@@ -49,5 +57,5 @@

if (!opts.name) return callback(new Error('name required'));
var req = {
name: 'agent.service.register',
path: '/agent/service/register',
type: 'json',

@@ -57,2 +65,4 @@ body: {},

if (!opts.name) return callback(this.consul._err('name required', req));
req.body.Name = opts.name;

@@ -74,3 +84,3 @@ if (opts.id) req.body.ID = opts.id;

} else {
return callback(new Error('script and interval, or ttl required'));
return callback(this.consul._err('script and interval, or ttl required', req));
}

@@ -80,7 +90,5 @@ if (check.hasOwnProperty('notes')) req.body.Check.Notes = check.notes;

this.consul._put('/agent/service/register', req, function(err) {
if (err) return callback(err);
utils.options(req, opts);
callback();
});
this.consul._put(req, utils.empty, callback);
};

@@ -101,14 +109,13 @@

if (!opts.id) return callback(new Error('id required'));
var req = {
method: 'GET',
path: { id: opts.id },
name: 'agent.service.deregister',
path: '/agent/service/deregister/{id}',
params: { id: opts.id },
};
this.consul._get('/agent/service/deregister/{id}', req, function(err) {
if (err) return callback(err);
if (!opts.id) return callback(this.consul._err('id required', req));
callback();
});
utils.options(req, opts);
this.consul._get(req, utils.empty, callback);
};

@@ -115,0 +122,0 @@

@@ -13,2 +13,3 @@ /**

var CatalogService = require('./catalog/service').CatalogService;
var utils = require('./utils');

@@ -32,7 +33,8 @@ /**

this.consul._get('/catalog/datacenters', function(err, res) {
if (err) return callback(err);
var req = {
name: 'catalog.datacenters',
path: '/catalog/datacenters',
};
callback(null, res.body);
});
this.consul._get(req, utils.body, callback);
};

@@ -39,0 +41,0 @@

@@ -26,3 +26,3 @@ /**

CatalogNode.prototype.list = function(opts, callback) {
if (typeof opts === 'function') {
if (!callback) {
callback = opts;

@@ -39,12 +39,10 @@ opts = {};

var req = {
name: 'catalog.node.list',
path: '/catalog/nodes',
query: {},
};
if (opts.dc) req.query.dc = opts.dc;
utils.options(req, opts);
this.consul._get('/catalog/nodes', req, function(err, res) {
if (err) return callback(err);
callback(null, res.body);
});
this.consul._get(req, utils.body, callback);
};

@@ -57,3 +55,3 @@

CatalogNode.prototype.services = function(opts, callback) {
if (typeof opts === 'function') {
if (!callback) {
callback = opts;

@@ -70,13 +68,11 @@ opts = {};

var req = {
path: { node: opts.node },
name: 'catalog.node.services',
path: '/catalog/node/{node}',
params: { node: opts.node },
query: {},
};
if (opts.dc) req.query.dc = opts.dc;
utils.options(req, opts);
this.consul._get('/catalog/node/{node}', req, function(err, res) {
if (err) return callback(err);
callback(null, res.body);
});
this.consul._get(req, utils.body, callback);
};

@@ -83,0 +79,0 @@

@@ -26,3 +26,3 @@ /**

CatalogService.prototype.list = function(opts, callback) {
if (typeof opts === 'function') {
if (!callback) {
callback = opts;

@@ -39,12 +39,10 @@ opts = {};

var req = {
name: 'catalog.service.list',
path: '/catalog/services',
query: {},
};
if (opts.dc) req.query.dc = opts.dc;
utils.options(req, opts);
this.consul._get('/catalog/services', req, function(err, res) {
if (err) return callback(err);
callback(null, res.body);
});
this.consul._get(req, utils.body, callback);
};

@@ -57,3 +55,3 @@

CatalogService.prototype.nodes = function(opts, callback) {
if (typeof opts === 'function') {
if (!callback) {
callback = opts;

@@ -70,14 +68,13 @@ opts = {};

var req = {
path: { service: opts.service },
name: 'catalog.service.nodes',
path: '/catalog/service/{service}',
params: { service: opts.service },
query: {},
};
if (opts.dc) req.query.dc = opts.dc;
if (opts.tag) req.query.tag = opts.tag;
this.consul._get('/catalog/service/{service}', req, function(err, res) {
if (err) return callback(err);
utils.options(req, opts);
callback(null, res.body);
});
this.consul._get(req, utils.body, callback);
};

@@ -84,0 +81,0 @@

@@ -37,2 +37,3 @@ /**

}
opts.name = 'consul';
opts.type = 'json';

@@ -39,0 +40,0 @@

@@ -36,14 +36,11 @@ /**

var req = {
method: 'GET',
path: { node: opts.node },
name: 'health.node',
path: '/health/node/{node}',
params: { node: opts.node },
query: {},
};
if (opts.dc) req.query.dc = opts.dc;
utils.options(req, opts);
this.consul._get('/health/node/{node}', req, function(err, res) {
if (err) return callback(err);
callback(null, res.body);
});
this.consul._get(req, utils.body, callback);
};

@@ -65,13 +62,11 @@

var req = {
path: { service: opts.service },
name: 'health.checks',
path: '/health/checks/{service}',
params: { service: opts.service },
query: {},
};
if (opts.dc) req.query.dc = opts.dc;
utils.options(req, opts);
this.consul._get('/health/checks/{service}', req, function(err, res) {
if (err) return callback(err);
callback(null, res.body);
});
this.consul._get(req, utils.body, callback);
};

@@ -93,15 +88,14 @@

var req = {
path: { service: opts.service },
name: 'health.service',
path: '/health/service/{service}',
params: { service: opts.service },
query: {},
};
if (opts.dc) req.query.dc = opts.dc;
if (opts.tag) req.query.tag = opts.tag;
if (opts.passing) req.query.passing = 'true';
this.consul._get('/health/service/{service}', req, function(err, res) {
if (err) return callback(err);
utils.options(req, opts);
callback(null, res.body);
});
this.consul._get(req, utils.body, callback);
};

@@ -122,18 +116,15 @@

if (opts.state !== 'any' && constants.CHECK_STATE.indexOf(opts.state) < 0) {
return callback(new Error('Invalid state: ' + opts.state));
}
var req = {
path: { state: opts.state },
path: '/health/state/{state}',
params: { state: opts.state },
query: {},
};
if (opts.dc) req.query.dc = opts.dc;
if (opts.state !== 'any' && constants.CHECK_STATE.indexOf(opts.state) < 0) {
return callback(this.consul._err('Invalid state: ' + opts.state, req));
}
this.consul._get('/health/state/{state}', req, function(err, res) {
if (err) return callback(err);
utils.options(req, opts);
callback(null, res.body);
});
this.consul._get(req, utils.body, callback);
};

@@ -140,0 +131,0 @@

@@ -35,10 +35,9 @@ /**

var req = {
path: { key: (opts.key || '') },
name: 'kv.get',
path: '/kv/{key}',
params: { key: (opts.key || '') },
query: {},
};
if (opts.dc) req.query.dc = opts.dc;
if (opts.recurse) req.query.recurse = 'true';
if (opts.hasOwnProperty('index')) req.query.index = opts.index;
if (opts.hasOwnProperty('wait')) req.query.wait = opts.wait;
if (opts.raw) {

@@ -49,7 +48,9 @@ req.query.raw = 'true';

this.consul._get('/kv/{key}', req, function(err, res) {
if (res && res.statusCode === 404) return callback();
if (err) return callback(err);
if (opts.raw) return callback(null, res.body);
utils.options(req, opts);
this.consul._get(req, function(err, res) {
if (res && res.statusCode === 404) return callback(undefined, undefined, res);
if (err) return callback(err, undefined, res);
if (opts.raw) return callback(null, res.body, res);
if (res.body && Array.isArray(res.body)) {

@@ -63,7 +64,7 @@ res.body.forEach(function(item) {

if (!res.body.length) return callback();
if (!res.body.length) return callback(undefined, undefined, res);
if (!opts.recurse) return callback(null, res.body[0]);
if (!opts.recurse) return callback(null, res.body[0], res);
callback(null, res.body);
callback(null, res.body, res);
});

@@ -99,13 +100,14 @@ };

if (!opts.key) return callback(new Error('key required'));
if (!opts.hasOwnProperty('value')) return callback(new Error('value required'));
var req = {
path: { key: opts.key },
name: 'kv.set',
path: '/kv/{key}',
params: { key: opts.key },
query: {},
type: 'text',
body: opts.value,
body: opts.value || '',
};
if (opts.dc) req.query.dc = opts.dc;
if (!opts.key) return callback(this.consul._err('key required', req));
if (!opts.hasOwnProperty('value')) return callback(this.consul._err('value required', req));
if (opts.hasOwnProperty('cas')) req.query.cas = opts.cas;

@@ -116,7 +118,5 @@ if (opts.hasOwnProperty('flags')) req.query.flags = opts.flags;

this.consul._put('/kv/{key}', req, function(err, res) {
if (err) return callback(err);
utils.options(req, opts);
callback(null, res.body);
});
this.consul._put(req, utils.body, callback);
};

@@ -138,14 +138,13 @@

var req = {
path: { key: (opts.key || '') },
name: 'kv.del',
path: '/kv/{key}',
params: { key: (opts.key || '') },
query: {},
};
if (opts.dc) req.query.dc = opts.dc;
if (opts.recurse) req.query.recurse = 'true';
this.consul._delete('/kv/{key}', req, function(err) {
if (err) return callback(err);
utils.options(req, opts);
callback();
});
this.consul._delete(req, utils.empty, callback);
};

@@ -152,0 +151,0 @@

@@ -26,3 +26,3 @@ /**

Session.prototype.create = function(opts, callback) {
if (typeof opts === 'function') {
if (!callback) {
callback = opts;

@@ -37,2 +37,4 @@ opts = {};

var req = {
name: 'session.create',
path: '/session/create',
query: {},

@@ -43,3 +45,2 @@ type: 'json',

if (opts.dc) req.query.dc = opts.dc;
if (opts.lockdelay) req.body.LockDelay = opts.lockdelay;

@@ -50,7 +51,5 @@ if (opts.name) req.body.Name = opts.name;

this.consul._put('/session/create', req, function(err, res) {
if (err) return callback(err);
utils.options(req, opts);
callback(null, res.body);
});
this.consul._put(req, utils.body, callback);
};

@@ -72,13 +71,11 @@

var req = {
path: { id: opts.id },
name: 'session.destroy',
path: '/session/destroy/{id}',
params: { id: opts.id },
query: {},
};
if (opts.dc) req.query.dc = opts.dc;
utils.options(req, opts);
this.consul._delete('/session/destroy/{id}', req, function(err) {
if (err) return callback(err);
callback();
});
this.consul._delete(req, utils.empty, callback);
};

@@ -100,16 +97,18 @@

var req = {
path: { id: opts.id },
name: 'session.get',
path: '/session/info/{id}',
params: { id: opts.id },
query: {},
};
if (opts.dc) req.query.dc = opts.dc;
utils.options(req, opts);
this.consul._get('/session/info/{id}', req, function(err, res) {
if (err) return callback(err);
this.consul._get(req, function(err, res) {
if (err) return callback(err, undefined, res);
if (res.body && res.body.length) {
return callback(null, res.body[0]);
return callback(null, res.body[0], res);
}
callback();
callback(undefined, undefined, res);
});

@@ -134,13 +133,11 @@ };

var req = {
path: { node: opts.node },
name: 'session.node',
path: '/session/node/{node}',
params: { node: opts.node },
query: {},
};
if (opts.dc) req.query.dc = opts.dc;
utils.options(req, opts);
this.consul._get('/session/node/{node}', req, function(err, res) {
if (err) return callback(err);
callback(null, res.body);
});
this.consul._get(req, utils.body, callback);
};

@@ -153,3 +150,3 @@

Session.prototype.list = function(opts, callback) {
if (typeof opts === 'function') {
if (!callback) {
callback = opts;

@@ -164,12 +161,10 @@ opts = {};

var req = {
name: 'session.list',
path: '/session/list',
query: {},
};
if (opts.dc) req.query.dc = opts.dc;
utils.options(req, opts);
this.consul._get('/session/list', req, function(err, res) {
if (err) return callback(err);
callback(null, res.body);
});
this.consul._get(req, utils.body, callback);
};

@@ -176,0 +171,0 @@

@@ -8,2 +8,8 @@ /**

/**
* Module dependencies.
*/
var utils = require('./utils');
/**
* Initialize a new `Status` client.

@@ -20,10 +26,18 @@ */

Status.prototype.leader = function(callback) {
Status.prototype.leader = function(opts, callback) {
if (!callback) {
callback = opts;
opts = {};
}
this.consul._log(['debug', 'status', 'leader']);
this.consul._get('/status/leader', function(err, res) {
if (err) return callback(err);
var req = {
name: 'status.leader',
path: '/status/leader',
};
callback(null, res.body);
});
utils.options(req, opts);
this.consul._get(req, utils.body, callback);
};

@@ -35,10 +49,18 @@

Status.prototype.peers = function(callback) {
Status.prototype.peers = function(opts, callback) {
if (!callback) {
callback = opts;
opts = {};
}
this.consul._log(['debug', 'status', 'peers']);
this.consul._get('/status/peers', function(err, res) {
if (err) return callback(err);
var req = {
name: 'status.peers',
path: '/status/peers',
};
callback(null, res.body);
});
utils.options(req, opts);
this.consul._get(req, utils.body, callback);
};

@@ -45,0 +67,0 @@

@@ -8,2 +8,22 @@ /**

/**
* Body
*/
function body(ctx, next) {
if (ctx.err) return next(false, ctx.err, undefined, ctx.res);
next(false, null, ctx.res.body, ctx.res);
}
/**
* Empty
*/
function empty(ctx, next) {
if (ctx.err) return next(false, ctx.err, undefined, ctx.res);
next(false, undefined, undefined, ctx.res);
}
/**
* Normalize keys

@@ -25,5 +45,28 @@ */

/**
* Module exports.
* Common options
*/
function options(req, opts) {
if (!req.query) req.query = {};
if (opts.dc) req.query.dc = opts.dc;
if (opts.wan) req.query.wan = '1';
if (opts.consistent) {
req.query.consistent = '1';
} else if (opts.stale) {
req.query.stale = '1';
}
if (opts.hasOwnProperty('index')) req.query.index = opts.index;
if (opts.hasOwnProperty('wait')) req.query.wait = opts.wait;
}
/**
* Module exports
*/
exports.body = body;
exports.empty = empty;
exports.normalizeKeys = normalizeKeys;
exports.options = options;
{
"name": "consul",
"version": "0.8.0",
"version": "0.9.0",
"description": "Consul client",
"main": "lib/index.js",
"dependencies": {
"rapi": "^0.6.0"
"rapi": "^0.12.0"
},
"devDependencies": {
"async": "^0.9.0",
"debug": "^1.0.3",
"debug": "^1.0.4",
"istanbul": "^0.3.0",

@@ -16,3 +16,3 @@ "jscs": "^1.5.8",

"lodash": "^2.4.1",
"mocha": "^1.20.1",
"mocha": "^1.21.0",
"node-uuid": "^1.4.1",

@@ -24,3 +24,4 @@ "should": "^4.0.4",

"scripts": {
"test": "./node_modules/.bin/jshint lib test/*.js && ./node_modules/.bin/jscs lib test/*.js && ./node_modules/.bin/mocha --reporter spec --timeout 15000"
"cover": "./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --recursive --check-leaks --timeout 15000 && open coverage/lcov-report/index.html",
"test": "./node_modules/.bin/jshint lib test && ./node_modules/.bin/jscs lib test && ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha -- --recursive --check-leaks --timeout 15000"
},

@@ -27,0 +28,0 @@ "keywords": [

@@ -25,2 +25,11 @@ # Consul

<a name="callback"/>
### Callback
All callbacks having the following signature `function(err, data, res)`.
* err (Error, optional): set if there was an error, otherwise falsy
* data (Object, optional): response data if any, otherwise `undefined`
* res (http.IncomingMessage, optional): HTTP response object with additional `body` property. This might not exist when `err` is set. The `body` property can be a decoded object, string, or Buffer.
<a name="init"/>

@@ -27,0 +36,0 @@ ### consul([options])

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc