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

worksmith_etcd

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

worksmith_etcd - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

4

package.json
{
"name": "worksmith_etcd",
"version": "0.1.0",
"version": "0.2.0",
"description": "Etcd activites for worksmith",

@@ -27,3 +27,3 @@ "main": "index.js",

"node-uuid": "^1.4.3",
"worksmith": "0.0.22"
"worksmith": "^0.1.0"
},

@@ -30,0 +30,0 @@ "devDependencies": {

@@ -7,18 +7,21 @@ var debug = require('debug')('worksmith:tasks:etcd:lock')

function execute(done) {
var etcd = context.get(definition.etcd) || context.etcd
var key = context.get(definition.key)
var value = context.get(definition.value) || uuid()
var ttl = context.get(definition.ttl)
execute.inject = ['etcd', 'key', 'value', 'ttl', 'errorOnExists']
if (!etcd) return done(new Error('No etcd client found in context'))
if (!key) return done(new Error('No key found in context'))
function execute(etcd, key, value, ttl, errorOnExists, done) {
etcd = etcd || context.etcd
value = value || uuid()
errorOnExists = errorOnExists !== undefined ? errorOnExists : true
if (!etcd) return done(new Error('No etcd client specified or found in context'))
if (!key) return done(new Error('No key specified'))
debug('Setting key: %s to value: %s with ttl: %d', key, value, ttl)
etcd.set(key, value, { prevExist: false, ttl: ttl }, function(err) {
done(err, value)
if (err && err.errorCode === 105 && !errorOnExists) return done()
if (err) return done(err)
done(null, { key: key, value: value })
})
}
return execute;
return execute
}
}

@@ -6,10 +6,10 @@ var debug = require('debug')('worksmith:tasks:etcd:unlock')

function execute(done) {
var etcd = context.get(definition.etcd) || context.etcd
var key = context.get(definition.key)
var value = context.get(definition.value)
execute.inject = ['etcd', 'key', 'value']
if (!etcd) return done(new Error('No etcd client found in context'))
if (!key) return done(new Error('No key found in context'))
function execute(etcd, key, value, done) {
etcd = etcd || context.etcd
if (!etcd) return done(new Error('No etcd client specified or found in context'))
if (!key) return done(new Error('No key specified'))
debug('Deleting key: %s with value: %s', key, value ? value : '<anything>')

@@ -16,0 +16,0 @@ etcd.del(key, { prevValue: value }, function(err) {

@@ -15,3 +15,3 @@ var worksmith = require('worksmith')

it('should error when no etcd client is available in the default location', function(done) {
it('should error when no etcd client is available in the context', function(done) {
var workflow = worksmith({

@@ -22,7 +22,7 @@ task: lock

workflow({}, function(err) {
assert.error(err, 'No etcd client found in context', done)
assert.error(err, 'No etcd client specified or found in context', done)
})
})
it('should error when no key is available', function(done) {
it('should error when no key is specified', function(done) {
var workflow = worksmith({

@@ -34,3 +34,3 @@ task: lock,

workflow({}, function(err) {
assert.error(err, 'No key found in context', done)
assert.error(err, 'No key specified', done)
})

@@ -97,4 +97,2 @@ })

var before = new Date().getTime()
workflow({}, function(err) {

@@ -132,2 +130,45 @@ assert.ifError(err)

it('should return the key and value', function(done) {
var workflow = worksmith({
task: lock,
etcd: etcd,
key: 'lock/me',
value: 'foo',
resultTo: 'lock'
})
var ctx = {}
workflow(ctx, function(err) {
assert.ifError(err)
assert.equal(ctx.lock.key, 'lock/me')
assert.equal(ctx.lock.value, 'foo')
done()
})
})
it('should supress errors when the lock is already taken and errorOnExists is false', function(done) {
var workflow = worksmith({
task: lock,
etcd: etcd,
key: 'lock/me',
errorOnExists: false,
resultTo: 'lock'
})
var ctx = {}
etcd.set('lock/me', this.title, function(err) {
assert.ifError(err)
workflow(ctx, function(err) {
assert.ifError(err)
assert.ok(!ctx.lock)
done()
})
})
})
})

@@ -20,3 +20,3 @@ var worksmith = require('worksmith')

workflow({}, function(err) {
assert.error(err, 'No etcd client found in context', done)
assert.error(err, 'No etcd client specified or found in context', done)
})

@@ -32,3 +32,3 @@ })

workflow({}, function(err) {
assert.error(err, 'No key found in context', done)
assert.error(err, 'No key specified', done)
})

@@ -54,3 +54,3 @@ })

it('should tollerate releasing a non existent lock', function(done) {
it('should tolerate releasing a non existent lock', function(done) {

@@ -57,0 +57,0 @@ var workflow = worksmith({

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