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.26.0 to 0.27.0

lib/query.js

13

lib/consul.js

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

var Lock = require('./lock').Lock;
var Query = require('./query').Query;
var Session = require('./session').Session;

@@ -69,2 +70,3 @@ var Status = require('./status').Status;

this.kv = new Consul.Kv(this);
this.query = new Consul.Query(this);
this.session = new Consul.Session(this);

@@ -96,2 +98,3 @@ this.status = new Consul.Status(this);

Consul.Lock = Lock;
Consul.Query = Query;
Consul.Session = Session;

@@ -138,2 +141,12 @@ Consul.Status = Status;

/**
* Parse query meta
*/
Consul.meta.parseQueryMeta = { type: 'sync' };
Consul.parseQueryMeta = Consul.prototype.parseQueryMeta = function(res) {
return utils.parseQueryMeta(res);
};
/**
* Module exports.

@@ -140,0 +153,0 @@ */

10

lib/session.js

@@ -108,11 +108,3 @@ /**

this.consul._get(req, function(err, res) {
if (err) return callback(err, undefined, res);
if (res.body && Array.isArray(res.body) && res.body.length) {
return callback(null, res.body[0], res);
}
callback(undefined, undefined, res);
});
this.consul._get(req, utils.bodyItem, callback);
};

@@ -119,0 +111,0 @@

@@ -282,2 +282,27 @@ /**

/**
* Parse query meta
*/
function parseQueryMeta(res) {
var meta = {};
if (res && res.headers) {
if (res.headers['x-consul-index']) {
meta.LastIndex = res.headers['x-consul-index'];
}
if (res.headers['x-consul-lastcontact']) {
meta.LastContact = parseInt(res.headers['x-consul-lastcontact'], 10);
}
if (res.headers['x-consul-knownleader']) {
meta.KnownLeader = res.headers['x-consul-knownleader'] === 'true';
}
if (res.headers['x-consul-translate-addresses']) {
meta.AddressTranslationEnabled = res.headers['x-consul-translate-addresses'] === 'true';
}
}
return meta;
}
/**
* Module exports

@@ -300,1 +325,2 @@ */

exports.hasIndexChanged = hasIndexChanged;
exports.parseQueryMeta = parseQueryMeta;
{
"name": "consul",
"version": "0.26.0",
"version": "0.27.0",
"description": "Consul client",

@@ -5,0 +5,0 @@ "main": "./lib",

@@ -27,2 +27,3 @@ # Consul [![Build Status](https://travis-ci.org/silas/node-consul.png?branch=master)](https://travis-ci.org/silas/node-consul)

* [Lock](#lock)
* [Query](#query)
* [Session](#session)

@@ -1322,2 +1323,334 @@ * [Status](#status)

<a name="query"></a>
### consul.query
* [list](#query-list)
* [create](#query-create)
* [update](#query-update)
* [get](#query-get)
* [destroy](#query-destroy)
* [execute](#query-execute)
* [explain](#query-explain)
<a name="query-list"></a>
### consul.query.list(callback)
List prepared query.
Usage
``` javascript
consul.query.list(function(err, result) {
if (err) throw err;
});
```
Result
``` json
[
{
"ID": "422b14b9-874b-4520-bd2e-e149a42b0066",
"Name": "redis",
"Session": "",
"Token": "",
"Template": {
"Type": "",
"Regexp":""
},
"Service": {
"Service": "redis",
"Failover": {
"NearestN": 3,
"Datacenters": [
"dc1",
"dc2"
]
},
"OnlyPassing": false,
"Tags": [
"master",
"!experimental"
]
},
"DNS": {
"TTL": "10s"
},
"RaftIndex": {
"CreateIndex": 23,
"ModifyIndex": 42
}
}
]
```
<a name="query-create"></a>
### consul.query.create(options, callback)
Create a new prepared query.
Options
* name (String, optional): name that can be used to execute a query instead of using its ID
* session (String, optional): provides a way to automatically remove a prepared query when the given session is invalidated
* token (String, optional): captured ACL Token that is reused as the ACL Token every time the query is executed
* near (String, optional): allows specifying a particular node to sort near based on distance sorting using Network Coordinates
* service.service (String, required): name of the service to query
* service.failover.nearestn (Number, optional): when set the query will be forwarded to up to nearest N other datacenters based on their estimated network round trip time using Network Coordinates from the WAN gossip pool
* service.failover.datacenters (String[], optional): fixed list of remote datacenters to forward the query to if there are no healthy nodes in the local datacenter
* service.onlypassing (Boolean, default: false): filter results to only nodes with a passing state
* service.tags (String[], optional): list of service tags to filter the query results
* ttl.dns (String, optional, ex: `10s`): controls how the TTL is set when query results are served over DNS
Usage
``` javascript
var opts = {
name: 'redis',
service: {
service: 'redis'
onlypassing: true
},
};
consul.query.create(opts, function(err, result) {
if (err) throw err;
});
```
Result
``` json
{
"ID": "422b14b9-874b-4520-bd2e-e149a42b0066"
}
```
<a name="query-update"></a>
### consul.query.update(options, callback)
Update existing prepared query.
Options
* query (String, required): ID of the query
And all [create options][query-create].
Usage
``` javascript
var opts = {
query: '422b14b9-874b-4520-bd2e-e149a42b0066',
name: 'redis',
service: {
service: 'redis'
onlypassing: false
},
};
consul.query.update(opts, function(err, result) {
if (err) throw err;
});
```
<a name="query-get"></a>
### consul.query.get(options, callback)
Get prepared query.
Options
* query (String, required): ID of the query
Usage
``` javascript
consul.query.get('6119cabf-c052-48fe-9f07-711762e52931', function(err, result) {
if (err) throw err;
});
```
Result
``` json
{
"ID": "6119cabf-c052-48fe-9f07-711762e52931",
"Name": "redis",
"Session": "",
"Token": "",
"Template": {
"Type": "",
"Regexp":""
},
"Service": {
"Service": "redis",
"Failover": {
"NearestN": 3,
"Datacenters": [
"dc1",
"dc2"
]
},
"OnlyPassing": false,
"Tags": [
"master",
"!experimental"
]
},
"DNS": {
"TTL": "10s"
},
"RaftIndex": {
"CreateIndex": 23,
"ModifyIndex": 42
}
}
```
<a name="query-destroy"></a>
### consul.query.destroy(options, callback)
Delete prepared query.
Options
* query (String, required): ID of the query
Usage
``` javascript
consul.query.destroy('422b14b9-874b-4520-bd2e-e149a42b0066', function(err) {
if (err) throw err;
});
```
<a name="query-execute"></a>
### consul.query.execute(options, callback)
Execute prepared query.
Options
* query (String, required): ID of the query
Usage
``` javascript
consul.query.execute('6119cabf-c052-48fe-9f07-711762e52931', function(err) {
if (err) throw err;
});
```
Result
``` json
{
"Service": "redis",
"Nodes": [
{
"Node": {
"Node": "foobar",
"Address": "10.1.10.12",
"TaggedAddresses": {
"lan": "10.1.10.12",
"wan": "10.1.10.12"
}
},
"Service": {
"ID": "redis",
"Service": "redis",
"Tags": null,
"Port": 8000
},
"Checks": [
{
"Node": "foobar",
"CheckID": "service:redis",
"Name": "Service 'redis' check",
"Status": "passing",
"Notes": "",
"Output": "",
"ServiceID": "redis",
"ServiceName": "redis"
},
{
"Node": "foobar",
"CheckID": "serfHealth",
"Name": "Serf Health Status",
"Status": "passing",
"Notes": "",
"Output": "",
"ServiceID": "",
"ServiceName": ""
}
],
"DNS": {
"TTL": "10s"
},
"Datacenter": "dc3",
"Failovers": 2
}
]
}
```
<a name="query-explain"></a>
### consul.query.explain(options, callback)
Explain prepared query.
Options
* query (String, required): ID of the query
Usage
``` javascript
consul.query.explain('422b14b9-874b-4520-bd2e-e149a42b0066', function(err, result) {
if (err) throw err;
console.log(result);
});
```
Result
``` json
{
"Query": {
"ID": "422b14b9-874b-4520-bd2e-e149a42b0066",
"Name": "redis",
"Session": "",
"Token": "",
"Template": {
"Type": "",
"Regexp":""
},
"Service": {
"Service": "redis",
"Failover": {
"NearestN": 3,
"Datacenters": [
"dc1",
"dc2"
]
},
"OnlyPassing": false,
"Tags": [
"master",
"!experimental"
]
},
"DNS": {
"TTL": "10s"
},
"RaftIndex": {
"CreateIndex": 23,
"ModifyIndex": 42
}
}
}
```
<a name="session"></a>

@@ -1662,4 +1995,8 @@ ### consul.session

Parts of the Documentation were copied from the official
[Consul website][consul-docs-api], see the NOTICE file for license
information.
[consul]: http://www.consul.io/
[consul-docs-api]: http://www.consul.io/docs/agent/http.html
[download]: http://www.consul.io/downloads.html
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