Comparing version 0.25.0 to 0.26.0
@@ -59,6 +59,2 @@ /** | ||
if (!opts.name) { | ||
return callback(this.consul._err(errors.Validation('name required'), req)); | ||
} | ||
try { | ||
@@ -65,0 +61,0 @@ req.body = utils.createCheck(opts); |
@@ -76,5 +76,5 @@ /** | ||
if (Array.isArray(opts.checks)) { | ||
req.body.Checks = opts.checks.map(utils.createCheck); | ||
req.body.Checks = opts.checks.map(utils.createServiceCheck); | ||
} else if (opts.check) { | ||
req.body.Check = utils.createCheck(opts.check); | ||
req.body.Check = utils.createServiceCheck(opts.check); | ||
} | ||
@@ -81,0 +81,0 @@ } catch (err) { |
@@ -36,3 +36,3 @@ /** | ||
opts = opts || {}; | ||
opts = utils.defaults({}, opts); | ||
@@ -39,0 +39,0 @@ if (!opts.baseUrl) { |
@@ -162,3 +162,3 @@ /** | ||
ctx: ctx, | ||
}, self.consul._defaults); | ||
}, ctx.session, self.consul._defaults); | ||
@@ -165,0 +165,0 @@ self.consul.session.create(opts, function(err, data, res) { |
@@ -69,9 +69,12 @@ /** | ||
function defaults(obj, src) { | ||
function defaults(obj) { | ||
if (!obj) obj = {}; | ||
if (!src) return obj; | ||
for (var p in src) { | ||
if (src.hasOwnProperty(p) && !obj.hasOwnProperty(p)) { | ||
obj[p] = src[p]; | ||
var src; | ||
for (var i = 0; i < arguments.length; i++) { | ||
src = arguments[i]; | ||
for (var p in src) { | ||
if (src.hasOwnProperty(p) && !obj.hasOwnProperty(p)) { | ||
obj[p] = src[p]; | ||
} | ||
} | ||
@@ -202,14 +205,14 @@ } | ||
/** | ||
* Create check object | ||
* Create node/server-level check object | ||
* Corresponds to CheckType in Consul Agent Endpoint: | ||
* https://github.com/hashicorp/consul/blob/master/command/agent/check.go#L43 | ||
* Corresponds to AgentServiceCheck in Consul Go API (which currently omits Notes): | ||
* https://github.com/hashicorp/consul/blob/master/api/agent.go#L66 | ||
* Currently omits ID and Name fields: | ||
* https://github.com/hashicorp/consul/issues/2223 | ||
*/ | ||
function createCheck(src) { | ||
src = normalizeKeys(src); | ||
function _createServiceCheck(src) { | ||
var dst = {}; | ||
if (src.hasOwnProperty('id')) dst.ID = src.id; | ||
if (src.hasOwnProperty('name')) dst.Name = src.name; | ||
if (src.hasOwnProperty('serviceid')) dst.ServiceID = src.serviceid; | ||
if ((src.http || src.script || src.tcp) && src.interval) { | ||
@@ -226,9 +229,13 @@ if (src.http) { | ||
dst.Interval = src.interval; | ||
if (src.hasOwnProperty('timeout')) dst.Timeout = src.timeout; | ||
} else if (src.ttl) { | ||
dst.TTL = src.ttl; | ||
} else { | ||
throw new Error('http or script and interval, or ttl required'); | ||
throw new Error('http/tcp/script and interval, or ttl required'); | ||
} | ||
if (src.hasOwnProperty('notes')) dst.Notes = src.notes; | ||
if (src.hasOwnProperty('status')) dst.Status = src.status; | ||
if (src.hasOwnProperty('deregistercriticalserviceafter')) { | ||
dst.DeregisterCriticalServiceAfter = src.deregistercriticalserviceafter; | ||
} | ||
@@ -238,3 +245,32 @@ return dst; | ||
function createServiceCheck(src) { | ||
return _createServiceCheck(normalizeKeys(src)); | ||
} | ||
/** | ||
* Create standalone check object | ||
* Corresponds to CheckDefinition in Consul Agent Endpoint: | ||
* https://github.com/hashicorp/consul/blob/master/command/agent/structs.go#L47 | ||
* Corresponds to AgentCheckRegistration in Consul Go API: | ||
* https://github.com/hashicorp/consul/blob/master/api/agent.go#L57 | ||
*/ | ||
function createCheck(src) { | ||
src = normalizeKeys(src); | ||
var dst = _createServiceCheck(src); | ||
if (src.name) { | ||
dst.Name = src.name; | ||
} else { | ||
throw new Error('name required'); | ||
} | ||
if (src.hasOwnProperty('id')) dst.ID = src.id; | ||
if (src.hasOwnProperty('serviceid')) dst.ServiceID = src.serviceid; | ||
return dst; | ||
} | ||
/** | ||
* Has the Consul index changed. | ||
@@ -264,3 +300,4 @@ */ | ||
exports.setIntervalContext = setIntervalContext; | ||
exports.createServiceCheck = createServiceCheck; | ||
exports.createCheck = createCheck; | ||
exports.hasIndexChanged = hasIndexChanged; |
{ | ||
"name": "consul", | ||
"version": "0.25.0", | ||
"version": "0.26.0", | ||
"description": "Consul client", | ||
"main": "./lib", | ||
"dependencies": { | ||
"papi": "^0.25.0" | ||
"papi": "^0.27.0" | ||
}, | ||
@@ -9,0 +9,0 @@ "devDependencies": { |
@@ -506,5 +506,8 @@ # Consul [![Build Status](https://travis-ci.org/silas/node-consul.png?branch=master)](https://travis-ci.org/silas/node-consul) | ||
* interval (String): interval to run check, requires script (ex: `15s`) | ||
* ttl (String): time to live before check must be updated, instead of script and interval (ex: `60s`) | ||
* timeout (String, optional): timeout for the check (ex: `10s`) | ||
* ttl (String): time to live before check must be updated, instead of http/tcp/script and interval (ex: `60s`) | ||
* notes (String, optional): human readable description of check | ||
* status (String, optional): initial service status | ||
* deregistercriticalserviceafter (String, optional, Consul 0.7+): timeout after | ||
which to automatically deregister service if check remains in critical state | ||
@@ -647,7 +650,13 @@ Usage | ||
* http (String): URL endpoint, requires interval | ||
* tcp (String): host:port to test, passes if connection is established, fails otherwise | ||
* script (String): path to check script, requires interval | ||
* dockercontainerid (String, optional): Docker container ID to run script | ||
* shell (String, optional): shell in which to run script (currently only supported with Docker) | ||
* interval (String): interval to run check, requires script (ex: `15s`) | ||
* ttl (String): time to live before check must be updated, instead of http/script and interval (ex: `60s`) | ||
* timeout (String, optional): timeout for the check (ex: `10s`) | ||
* ttl (String): time to live before check must be updated, instead of http/tcp/script and interval (ex: `60s`) | ||
* notes (String, optional): human readable description of check | ||
* status (String, optional): initial service status | ||
* deregistercriticalserviceafter (String, optional, Consul 0.7+): timeout after | ||
which to automatically deregister service if check remains in critical state | ||
* checks (Object[], optional): service checks (see `check` above) | ||
@@ -654,0 +663,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
103829
2097
1663
+ Addedpapi@0.27.0(transitive)
- Removedpapi@0.25.1(transitive)
Updatedpapi@^0.27.0