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.1.0 to 0.2.1

.travis.yml

16

lib/consul.js

@@ -8,5 +8,5 @@ 'use strict';

var debug = require('debug')('consul:consul');
var parseUrl = require('url').parse;
var Kv = require('./kv').Kv;
var Session = require('./session').Session;
var request = require('./request');

@@ -27,4 +27,7 @@

this.url = parseUrl(options.url || 'http://localhost:8500/v1');
this.host = options.host || 'localhost';
this.httpPort = options.httpPort || '8500';
this.kv = new Kv(this);
this.session = new Session(this);
}

@@ -37,7 +40,6 @@

Consul.prototype.request = function(options, callback) {
// url
options.protocol = this.url.protocol;
options.hostname = this.url.hostname;
if (this.url.port) options.port = this.url.port;
options.path = this.url.path + options.path;
options.protocol = 'http:';
options.hostname = this.host;
options.port = this.httpPort;
options.path = '/v1' + options.path;

@@ -44,0 +46,0 @@ request(options, callback);

'use strict';
/**
* Module dependencies.
*/
var Consul = require('./consul').Consul;
/**
* Module Exports.
*/
exports.Consul = require('./consul');
module.exports = Consul;

@@ -12,3 +12,3 @@ 'use strict';

/**
* Initialize a new `Consul` client.
* Initialize a new `Session` client.
*/

@@ -31,2 +31,4 @@

options = utils.normalizeKeys(options);
var req = {

@@ -36,3 +38,2 @@ method: 'GET',

query: {},
accept: 'json',
};

@@ -42,29 +43,20 @@

if (options.recurse) req.query.recurse = 'true';
if (options.hasOwnProperty('index')) req.query.index = options.index;
if (options.hasOwnProperty('wait')) req.query.wait = options.wait;
this.consul.request(req, function(err, res) {
if (res && res.statusCode === 404) return callback();
if (err) return callback(err);
if (res.statusCode === 404) return callback();
var data = [];
if (res && res.body && Array.isArray(res.body)) {
if (res.body && Array.isArray(res.body)) {
res.body.forEach(function(item) {
var newItem = {};
item.Value = new Buffer(item.Value, 'base64').toString();
Object.keys(item).forEach(function(key) {
newItem[utils.toLower(key)] = item[key];
});
data.push(newItem);
});
}
if (!data.length) return callback();
if (!res.body.length) return callback();
if (!options.recurse) return callback(null, data[0]);
if (!options.recurse) return callback(null, res.body[0]);
callback(null, data);
callback(null, res.body);
});

@@ -98,4 +90,6 @@ };

options = utils.normalizeKeys(options);
if (!options.key) return callback(new Error('key required'));
if (!options.value) return callback(new Error('value required'));
if (!options.hasOwnProperty('value')) return callback(new Error('value required'));

@@ -106,3 +100,2 @@ var req = {

query: {},
accept: 'text',
body: options.value,

@@ -114,2 +107,4 @@ };

if (options.hasOwnProperty('flags')) req.query.flags = options.flags;
if (options.hasOwnProperty('acquire')) req.query.acquire = options.acquire;
if (options.hasOwnProperty('release')) req.query.release = options.acrelease;

@@ -119,8 +114,3 @@ this.consul.request(req, function(err, res) {

var body = res.body.trim();
if (body === 'true') return callback(null, true);
if (body === 'false') return callback(null, false);
callback(new Error('unknown response: ' + res.body));
callback(null, res.body);
});

@@ -140,2 +130,4 @@ };

options = utils.normalizeKeys(options);
var req = {

@@ -142,0 +134,0 @@ method: 'DELETE',

@@ -119,19 +119,28 @@ 'use strict';

if (~['json', 'text'].indexOf(options.accept)) {
res.body = res.body.toString();
}
debug('res body', res.body);
if (options.accept === 'json') {
try {
res.body = JSON.parse(res.body);
} catch (err) {
return callback(err);
}
}
var contentType = (res.headers['content-type'] || '').split(';')[0];
if (!Buffer.isBuffer(res.body)) {
debug('res body', res.body);
switch (contentType.trim()) {
case 'application/json':
try {
res.body = JSON.parse(res.body.toString());
} catch (err) {
return callback(err);
}
break;
case 'text/plain':
res.body = res.body.toString();
break;
}
}
if (parseInt(res.statusCode / 100, 10) !== 2) {
return callback(new Error(
typeof res.body === 'string' ?
res.body :
http.STATUS_CODES[res.statusCode]
), res);
}
callback(null, res);

@@ -138,0 +147,0 @@ });

@@ -35,7 +35,15 @@ 'use strict';

/**
* Lowercase first character
* Normalize keys
*/
function toLower(value) {
return value[0].toLowerCase() + value.slice(1);
function normalizeKeys(obj) {
var result = {};
Object.keys(obj).forEach(function(name) {
if (obj.hasOwnProperty(name)) {
result[name.replace(/_/g, '').toLowerCase()] = obj[name];
}
});
return result;
}

@@ -48,3 +56,3 @@

exports.isEmpty = isEmpty;
exports.normalizeKeys = normalizeKeys;
exports.pick = pick;
exports.toLower = toLower;
{
"name": "consul",
"version": "0.1.0",
"version": "0.2.1",
"description": "Consul client",
"main": "lib/index.js",
"dependencies": {
"debug": "^0.8.0"
"debug": "^1.0.2"
},
"devDependencies": {
"async": "^0.7.0",
"jscs": "^1.3.0",
"jshint": "^2.5.0",
"mocha": "^1.18.2",
"should": "^3.3.1",
"async": "^0.9.0",
"jscs": "^1.5.4",
"jshint": "^2.5.1",
"mocha": "^1.20.1",
"should": "^4.0.4",
"uuid": "^1.4.1"
},
"scripts": {
"test": "./node_modules/.bin/jshint lib test && ./node_modules/.bin/jscs lib test && ./node_modules/.bin/mocha --recursive --require should -R spec"
"test": "./node_modules/.bin/jshint lib test && ./node_modules/.bin/jscs lib test && ./node_modules/.bin/mocha --recursive --require should -R spec",
"start": "./scripts/setup && ./tmp/consul agent -data-dir=./tmp/data -server -bootstrap -node=node1 -dc=dc1 -pid-file=./tmp/consul.pid &> ./tmp/consul.log &",
"stop": "if [[ -f ./tmp/consul.pid ]]; then kill $( cat ./tmp/consul.pid ) &>/dev/null; fi"
},

@@ -23,4 +25,5 @@ "keywords": [

],
"repository": "https://github.com/silas/node-consul.git",
"author": "Silas Sewell <silas@sewell.org>",
"license": "MIT"
}

@@ -5,2 +5,9 @@ # Consul

## Test
```
$ npm start # start consul server
$ npm test
```
## License

@@ -7,0 +14,0 @@

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