Skip to content

Commit

Permalink
Merge pull request #20 from mongodb-js/fix-linter-issues
Browse files Browse the repository at this point in the history
chore: Fixup linter issues and run ci
  • Loading branch information
imlucas committed Jan 8, 2020
1 parent a7cb747 commit 275487d
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 75 deletions.
8 changes: 4 additions & 4 deletions packages/storage-mixin/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ node_js:
env:
global:
- NO_AT_BRIDGE=1 # Needed for dbus to work.
- CC=clang
- CXX=clang++
- CC=clang
- CXX=clang++
- npm_config_clang=1

# matrix:
Expand All @@ -31,7 +31,7 @@ before_script:
eval $(/usr/bin/gnome-keyring-daemon --components=secrets --start);
/usr/bin/python -c "import gnomekeyring;gnomekeyring.create_sync('login', '');";
script:
- npm run test:electron
- npm run ci
# - if [ -n "$NODE" ]; then npm run test:node; fi
# - if [ -n "$ELECTRON" ]; then npm run test:electron; fi

Expand All @@ -41,7 +41,7 @@ addons:
- ubuntu-toolchain-r-test
packages:
- libsecret-1-dev
# TODO (@imlucas) Are all of these gnome keyring
# TODO (@imlucas) Are all of these gnome keyring
# packages really needed?
- gnome-keyring
- python-gnomekeyring
6 changes: 4 additions & 2 deletions packages/storage-mixin/lib/backends/errback.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const debug = require('debug')('mongodb-storage-mixin:backends:errback');

/**
* Helper so you can just use errbacks `function(err, res)`
* when calling ampersand sync methods instead of forgetting
Expand All @@ -14,13 +16,13 @@ function wrapOptions(method, model, options) {
if (options.error) {
return options.error(res, err);
}
console.error('An error ocurred with no handler specified!', err);
debug('An error ocurred with no handler specified!', err);
throw err;
}

if (options.success) {
return options.success(res);
}
}
};
}

Expand Down
8 changes: 3 additions & 5 deletions packages/storage-mixin/lib/backends/secure-ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ if (typeof window !== 'undefined') {
* @param {ampersand-model} model
* @param {Object} options
* @param {Function} done
* @return {None}
*
* @see http://ampersandjs.com/docs#ampersand-model-fetch
*/
Expand Down Expand Up @@ -139,7 +138,6 @@ if (typeof window !== 'undefined') {
* @param {ampersand-collection} collection
* @param {Object} options
* @param {Function} done
* @return {None}
*
* @see http://ampersandjs.com/docs#ampersand-collection-fetch
*/
Expand All @@ -150,8 +148,8 @@ if (typeof window !== 'undefined') {
if (result.namespace === this.namespace) {
const attributes = collection.reduce((attrs, model) => {
const modelId = model.getId();
const credential = result.credentials.find((credential) => {
return credential.account === modelId;
const credential = result.credentials.find((iteratee) => {
return iteratee.account === modelId;
});
const attr = {};
attr[model.idAttribute] = modelId;
Expand All @@ -170,7 +168,7 @@ if (typeof window !== 'undefined') {
ipc.on('storage-mixin:find:result', listener);

ipc.call('storage-mixin:find', {
namespace: this.namespace,
namespace: this.namespace
});
};
}
Expand Down
43 changes: 23 additions & 20 deletions packages/storage-mixin/lib/backends/secure-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,43 @@ if (process && process.type === 'browser') {
*/
ipc.respondTo('storage-mixin:clear', (evt, meta) => {
debug('Clearing all secure values for', meta.serviceName);

let promise;
try {
const promise = keytar.findCredentials(meta.serviceName);
} catch(e) {
console.error('Error calling findCredentials', e);
promise = keytar.findCredentials(meta.serviceName);
} catch (e) {
debug('Error calling findCredentials', e);
throw e;
}

promise.then(function(accounts) {
return Promise.all(
accounts.map(function(entry) {
const accountName = entry.account;
return keytar
.deletePassword(serviceName, accountName)
.deletePassword(meta.serviceName, accountName)
.then(function() {
debug('Deleted account %s successfully', accountName);
return accountName;
})
.catch(function(err) {
console.error('Failed to delete', accountName, err);
debug('Failed to delete', accountName, err);
throw err;
});
})
);
})
.then(function(accountNames) {
debug(
'Cleared %d accounts for serviceName %s',
accountNames.length,
meta.serviceName,
accountNames
);
})
.catch(function(err) {
console.error('Failed to clear credentials!', err);
});
.then(function(accountNames) {
debug(
'Cleared %d accounts for serviceName %s',
accountNames.length,
meta.serviceName,
accountNames
);
})
.catch(function(err) {
debug('Failed to clear credentials!', err);
});
});

/**
Expand Down Expand Up @@ -84,7 +87,7 @@ if (process && process.type === 'browser') {
});
})
.catch(function(err) {
debug('Error updating password', error);
debug('Error updating password', err);
});
});

Expand All @@ -104,7 +107,7 @@ if (process && process.type === 'browser') {
});
})
.catch(function(err) {
debug('Error creating password', error);
debug('Error creating password', err);
});
});

Expand All @@ -124,7 +127,7 @@ if (process && process.type === 'browser') {
});
})
.catch(function(err) {
debug('Error finding one', error);
debug('Error finding one', err);
});
});

Expand All @@ -144,7 +147,7 @@ if (process && process.type === 'browser') {
});
})
.catch(function(err) {
debug('Error finding', error);
debug('Error finding', err);
});
});
}
67 changes: 34 additions & 33 deletions packages/storage-mixin/lib/backends/secure.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,36 +27,39 @@ inherits(SecureBackend, BaseBackend);
SecureBackend.clear = function(namespace, done) {
var serviceName = `storage-mixin/${namespace}`;
debug('Clearing all secure values for', serviceName);

var promise;

try {
var promise = keytar.findCredentials(serviceName);
} catch(e) {
console.error('Error calling findCredentials', e);
promise = keytar.findCredentials(serviceName);
} catch (e) {
debug('Error calling findCredentials', e);
throw e;
}
promise.then(function(accounts) {
debug(
'Found credentials',
accounts.map(function(credential) {
return credential.account;
})
);
return Promise.all(
accounts.map(function(entry) {
var accountName = entry.account;
return keytar
.deletePassword(serviceName, accountName)
.then(function() {
debug('Deleted account %s successfully', accountName);
return accountName;
})
.catch(function(err) {
console.error('Failed to delete', accountName, err);
throw err;
});
})
);
})

promise.then(function(accounts) {
debug(
'Found credentials',
accounts.map(function(credential) {
return credential.account;
})
);
return Promise.all(
accounts.map(function(entry) {
var accountName = entry.account;
return keytar
.deletePassword(serviceName, accountName)
.then(function() {
debug('Deleted account %s successfully', accountName);
return accountName;
})
.catch(function(err) {
debug('Failed to delete', accountName, err);
throw err;
});
})
);
})
.then(function(accountNames) {
debug(
'Cleared %d accounts for serviceName %s',
Expand All @@ -67,7 +70,7 @@ SecureBackend.clear = function(namespace, done) {
done();
})
.catch(function(err) {
console.error('Failed to clear credentials!', err);
debug('Failed to clear credentials!', err);
done(err);
});
};
Expand Down Expand Up @@ -160,7 +163,6 @@ SecureBackend.prototype.create = function(model, options, done) {
* @param {ampersand-model} model
* @param {Object} options
* @param {Function} done
* @return {None}
*
* @see http://ampersandjs.com/docs#ampersand-model-fetch
*/
Expand Down Expand Up @@ -203,7 +205,6 @@ SecureBackend.prototype.findOne = function(model, options, done) {
* @param {ampersand-collection} collection
* @param {Object} options
* @param {Function} done
* @return {None}
*
* @see http://ampersandjs.com/docs#ampersand-collection-fetch
*/
Expand All @@ -214,8 +215,8 @@ SecureBackend.prototype.find = function(collection, options, done) {
.then(function(credentials) {
var attributes = collection.reduce(function(attrs, model) {
var modelId = model.getId();
var credential = credentials.find(function(credential) {
return credential.account === modelId;
var credential = credentials.find(function(iteratee) {
return iteratee.account === modelId;
});
var attr = {};
attr[model.idAttribute] = modelId;
Expand All @@ -226,7 +227,7 @@ SecureBackend.prototype.find = function(collection, options, done) {
attrs.push(attr);
return attrs;
}, []);
return(done(null, attributes));
return (done(null, attributes));
})
.catch(done);
};
Expand Down
3 changes: 1 addition & 2 deletions packages/storage-mixin/lib/backends/splice-disk-ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ var wrapOptions = require('./errback').wrapOptions;
var wrapErrback = require('./errback').wrapErrback;
var mergeSpliceResults = require('./util').mergeSpliceResults;
var inherits = require('util').inherits;
var assert = require('assert');

var debug = require('debug')('mongodb-storage-mixin:backends:splice-disk');

Expand Down Expand Up @@ -83,7 +82,7 @@ SpliceDiskIpcBackend.prototype.exec = function(method, model, options, done) {
if (!_.isEmpty(diskRes)) {
mergeSpliceResults(diskRes, res, model, cb);
} else {
cb(null, model.isCollection ? []: {});
return cb(null, model.isCollection ? [] : {});
}
})
);
Expand Down
3 changes: 1 addition & 2 deletions packages/storage-mixin/lib/backends/splice.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ var wrapOptions = require('./errback').wrapOptions;
var wrapErrback = require('./errback').wrapErrback;
var mergeSpliceResults = require('./util').mergeSpliceResults;
var inherits = require('util').inherits;
var assert = require('assert');

var debug = require('debug')('mongodb-storage-mixin:backends:splice');

Expand Down Expand Up @@ -82,7 +81,7 @@ SpliceBackend.prototype.exec = function(method, model, options, done) {
if (!_.isEmpty(localRes)) {
mergeSpliceResults(localRes, res, model, cb);
} else {
cb(null, model.isCollection ? []: {});
return cb(null, model.isCollection ? [] : {});
}
})
);
Expand Down
4 changes: 3 additions & 1 deletion packages/storage-mixin/lib/backends/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var _ = require('lodash');
* @param {Array} secureResults - The results from secure storage.
* @param {Model} model - The model.
* @param {Function} done - The done callback.
*
* @returns {Object} the return value of done callback.
*/
var mergeSpliceResults = function(nonSecureResults, secureResults, model, done) {
if (model.isCollection) {
Expand All @@ -20,6 +22,6 @@ var mergeSpliceResults = function(nonSecureResults, secureResults, model, done)
return done(null, merged);
}
done(null, _.merge(nonSecureResults, secureResults));
}
};

module.exports.mergeSpliceResults = mergeSpliceResults;
4 changes: 2 additions & 2 deletions packages/storage-mixin/lib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var backends = require('./backends');
// var debug = require('debug')('storage-mixin');
var debug = require('debug')('storage-mixin');

/**
* storage-mixin
Expand Down Expand Up @@ -38,7 +38,7 @@ module.exports = {
};

options.error = function(resp, err) {
console.error('WTF', {err: err, resp: resp});
debug('WTF', {err: err, resp: resp});
};
this.fetched = false;
this._storageBackend.exec(method, model, options);
Expand Down
4 changes: 3 additions & 1 deletion packages/storage-mixin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"pretest:node": "node-gyp rebuild --directory node_modules/keytar/ --verbose",
"test:node": "mocha",
"check": "mongodb-js-precommit",
"ci": "npm run check && npm run test",
"test": "npm run test:node && npm run test:electron"
},
"dependencies": {
Expand All @@ -53,6 +54,7 @@
"electron-mocha": "^6.0.4",
"electron-rebuild": "^1.8.2",
"eslint-config-mongodb-js": "^3.0.1",
"mocha": "^5.2.0"
"mocha": "^5.2.0",
"mongodb-js-precommit": "^2.0.0"
}
}
2 changes: 1 addition & 1 deletion packages/storage-mixin/test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var clearNamespaces = function(backendName, namespaces, done) {
});
async.parallel(tasks, function(err, res) {
if (err) {
console.error('Error clearing namespaces', err);
debug('Error clearing namespaces', err);
return done(err);
}
debug('Namespaces cleared for backend %s', backendName);
Expand Down
Loading

0 comments on commit 275487d

Please sign in to comment.