Skip to content

Commit

Permalink
Update oada deps etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
awlayton committed Feb 20, 2021
1 parent a18cfa6 commit be12192
Show file tree
Hide file tree
Showing 33 changed files with 183 additions and 1,085 deletions.
16 changes: 6 additions & 10 deletions oada/libs/oada-lib-arangodb/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const debug = require('debug');
const trace = debug('arango:init:trace');
const error = debug('arango:init:error');
const info = debug('arango:init:info');
const _ = require('lodash');
const equal = require('deep-equal');
const users = require('./libs/users.js');
const Bluebird = require('bluebird');

Expand All @@ -22,7 +22,7 @@ db.useDatabase('_system');
// First setup some shorter variable names:
const dbname = config.get('arangodb:database');
const cols = config.get('arangodb:collections');
const colsarr = _.values(cols);
const colsarr = Object.values(cols);

module.exports = {
run: () => {
Expand All @@ -39,7 +39,7 @@ module.exports = {
return (
Bluebird.resolve(db.listDatabases())
.then((dbs) => {
dbs = _.filter(dbs, (d) => d === dbname);
dbs = dbs.filter((d) => d === dbname);
if (dbs.length > 0) {
if (
(!config.get('isProduction') &&
Expand Down Expand Up @@ -79,7 +79,7 @@ module.exports = {
.then((dbcols) => {
trace('Found collections, looking for the ones we need');
return Bluebird.each(colsarr, (c) => {
if (_.find(dbcols, (d) => d.name === c.name)) {
if (dbcols.find((d) => d.name === c.name)) {
return trace('Collection ' + c.name + ' exists');
}
if (c.edgeCollection) {
Expand Down Expand Up @@ -112,11 +112,7 @@ module.exports = {
const indexname = typeof ci === 'string' ? ci : ci.name;
const unique = typeof ci === 'string' ? true : ci.unique;
const sparse = typeof ci === 'string' ? true : ci.sparse;
if (
_.find(dbindexes, (dbi) =>
_.isEqual(dbi.fields, [indexname])
)
) {
if (dbindexes.find((dbi) => equal(dbi.fields, [indexname]))) {
trace(
'Index ' + indexname + ' exists on collection ' + c.name
);
Expand Down Expand Up @@ -156,7 +152,7 @@ module.exports = {
//----------------------------------------------------------------------
// Finally, import default data if they want some:
)
.then(() => _.keys(config.get('arangodb:collections')))
.then(() => Object.keys(config.get('arangodb:collections')))
.map((colname) => {
const colinfo = config.get('arangodb:collections')[colname];
if (typeof colinfo.defaults !== 'string') {
Expand Down
4 changes: 2 additions & 2 deletions oada/libs/oada-lib-arangodb/libs/authorizations.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const config = require('../config');
const db = require('../db');
const _ = require('lodash');
const cloneDeep = require('clone-deep');
const { aql } = require('arangojs');
const util = require('../util');
const debug = require('debug');
Expand Down Expand Up @@ -69,7 +69,7 @@ function findByUser(user) {
}

function save(token) {
const t = _.cloneDeep(token);
const t = cloneDeep(token);
if (t.user) t.user = { _id: t.user._id }; // make sure nothing but id is in user info
// Have to get rid of illegal document handle _id
if (t._id) {
Expand Down
6 changes: 3 additions & 3 deletions oada/libs/oada-lib-arangodb/libs/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const db = require('../db');
const debug = require('debug');
const info = debug('arangodb#resources:info');
const trace = debug('arangodb#resources:trace');
const _ = require('lodash');
const cloneDeep = require('clone-deep');
const Bluebird = require('bluebird');
const { aql } = require('arangojs');
const pointer = require('json-pointer');
Expand Down Expand Up @@ -158,11 +158,11 @@ async function lookupFromUrl(url, userId) {
// If the desired url has more pieces than the longest path, the
// pathLeftover is the extra pieces
if (result.vertices.length - 1 < pieces.length) {
let revVertices = _.reverse(_.cloneDeep(result.vertices));
let revVertices = cloneDeep(result.vertices).reverse();
let lastResource =
result.vertices.length -
1 -
_.findIndex(revVertices, 'is_resource');
revVertices.findIndex((v) => v === 'is_resource');
// Slice a negative value to take the last n pieces of the array
path_leftover = pointer.compile(
pieces.slice(lastResource - pieces.length)
Expand Down
5 changes: 3 additions & 2 deletions oada/libs/oada-lib-arangodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
"arangojs": "^7.2.0",
"bcryptjs": "^2.4.3",
"bluebird": "^3.7.2",
"clone-deep": "^4.0.1",
"debug": "^4.3.2",
"deep-equal": "^2.0.5",
"flat": "^5.0.2",
"json-pointer": "^0.6.1",
"lodash": "^4.17.20"
"json-pointer": "^0.6.1"
}
}
1 change: 1 addition & 0 deletions oada/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"kafka-please": "^1.0.1",
"keypair": "^1.0.2",
"lerna": "^3.22.1",
"lodash": "^4.17.20",
"mocha": "^8.3.0",
"mocha-steps": "^1.3.0",
"mock-require": "^3.0.3",
Expand Down
8 changes: 4 additions & 4 deletions oada/services/auth/db/arango/codes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

'use strict';

var _ = require('lodash');
var trace = require('debug')('arango:codes:trace');
var oadaLib = require('@oada/lib-arangodb');
const cloneDeep = require('clone-deep');
const trace = require('debug')('arango:codes:trace');
const oadaLib = require('@oada/lib-arangodb');

function findByCode(code, cb) {
trace('findByCode: searching for code ', code);
Expand All @@ -35,7 +35,7 @@ function findByCode(code, cb) {
}

function save(in_code, cb) {
var code = _.cloneDeep(in_code);
var code = cloneDeep(in_code);
Object.assign(code, { _id: code.id, id: undefined });
// Link user
code.user = { _id: null };
Expand Down
14 changes: 6 additions & 8 deletions oada/services/auth/db/arango/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

const debug = require('debug')('arango/init');
const Database = require('arangojs').Database;
const _ = require('lodash');
const Promise = (global.Promise = require('bluebird'));
const bcrypt = require('bcryptjs');

Expand All @@ -18,9 +17,9 @@ module.exports = (config) => {
const db = new Database(config.get('arango:connectionString'));
const dbname = config.get('arango:database');
const cols = config.get('arango:collections');
const colnames = _.values(cols);
const colnames = Object.values(cols);
// Get users, hash passwords in case we need to save:
const defaultusers = _.map(config.get('arango:defaultusers'), (u) => {
const defaultusers = config.get('arango:defaultusers').map((u) => {
u.password = bcrypt.hashSync(u.password, config.get('server:passwordSalt'));
return u;
});
Expand All @@ -37,7 +36,7 @@ module.exports = (config) => {
.get()
.then(() => db.listDatabases())
.then((dbs) => {
dbs = _.filter(dbs, (d) => d === dbname);
dbs = dbs.filter((d) => d === dbname);
if (dbs.length > 0) return debug('database ' + dbname + ' exists');
debug('database ' + dbname + ' does not exist. Creating...');
return db
Expand All @@ -53,7 +52,7 @@ module.exports = (config) => {
})
.then((dbcols) => {
return Promise.each(colnames, (c) => {
if (_.find(dbcols, (d) => d.name === c)) {
if (dbcols.find((d) => d.name === c)) {
return debug('Collection ' + c + ' exists');
}
return db
Expand All @@ -70,9 +69,8 @@ module.exports = (config) => {
.map((dbindexes, i) => {
// dbindexes looks like [ { fields: [ 'token' ], sparse: true, unique: true },... ]
const index = indexes[i]; // { collection: 'tokens', index: 'index' }
const hasindex = _.find(
dbindexes,
(i) => _.includes(i.fields, index.index) && i.sparse && i.unique
const hasindex = dbindexes.find(
(i) => i.fields.includes(index.index) && i.sparse && i.unique
);
if (hasindex)
return debug(
Expand Down
8 changes: 4 additions & 4 deletions oada/services/auth/db/arango/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

'use strict';

var _ = require('lodash');
var trace = require('debug')('arango:token:trace');
var oadaLib = require('@oada/lib-arangodb');
const cloneDeep = require('clone-deep');
const trace = require('debug')('arango:token:trace');
const oadaLib = require('@oada/lib-arangodb');

function findByToken(token, cb) {
trace('findByToken: searching for token ', token);
Expand All @@ -36,7 +36,7 @@ function findByToken(token, cb) {
}

function save(token, cb) {
token = _.cloneDeep(token);
token = cloneDeep(token);
Object.assign(token, { _id: token.id, id: undefined });
// Link user
token.user = { _id: token.user._id };
Expand Down
8 changes: 4 additions & 4 deletions oada/services/auth/db/flat/clients.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
*/
'use strict';

var _ = require('lodash');
var clients = require('./clients.json');
const cloneDeep = require('clone-deep');
const clients = require('./clients.json');

function findById(id, cb) {
if (clients[id]) {
cb(null, _.cloneDeep(clients[id]));
cb(null, cloneDeep(clients[id]));
} else {
cb(null);
}
}

function save(client, cb) {
clients[client.clientId] = _.cloneDeep(client);
clients[client.clientId] = cloneDeep(client);

findById(client.clientId, cb);
}
Expand Down
6 changes: 3 additions & 3 deletions oada/services/auth/db/flat/codes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
*/
'use strict';

var _ = require('lodash');
var codes = require('./codes.json');
const cloneDeep = require('clone-deep');
const codes = require('./codes.json');

function findByCode(code, cb) {
cb(null, _.cloneDeep(codes[code]));
cb(null, cloneDeep(codes[code]));
}

function save(code, cb) {
Expand Down
6 changes: 3 additions & 3 deletions oada/services/auth/db/flat/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
*/
'use strict';

var _ = require('lodash');
var tokens = require('./tokens.json');
const cloneDeep = require('clone-deep');
const tokens = require('./tokens.json');

function findByToken(token, cb) {
cb(null, _.cloneDeep(tokens[token]));
cb(null, cloneDeep(tokens[token]));
}

function save(token, cb) {
Expand Down
8 changes: 4 additions & 4 deletions oada/services/auth/db/flat/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
*/
'use strict';

var _ = require('lodash');
var users = require('./users.json');
const cloneDeep = require('clone-deep');
const users = require('./users.json');

function findByUsername(username, cb) {
if (users[username]) {
return cb(null, _.cloneDeep(users[username]));
return cb(null, cloneDeep(users[username]));
}

return cb(null, false);
}

function findByUsernamePassword(username, password, cb) {
if (users[username] && users[username].password === password) {
return cb(null, _.cloneDeep(users[username]));
return cb(null, cloneDeep(users[username]));
}

return cb(null, false);
Expand Down
23 changes: 11 additions & 12 deletions oada/services/auth/dynReg.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@
*/
'use strict';

const _ = require('lodash');
var oadacerts = require('@oada/oada-certs');
var Promise = require('bluebird');
var clients = Promise.promisifyAll(require('./db/models/client'));
var config = require('./config');
var debug = require('debug');
const oadacerts = require('@oada/oada-certs');
const Bluebird = require('bluebird');
const clients = Bluebird.promisifyAll(require('./db/models/client'));
const config = require('./config');
const debug = require('debug');

const error = debug('oada-ref-auth#dynReg:error');
const info = debug('oada-ref-auth#dynReg:info');
const trace = debug('oada-ref-auth#dynReg:trace');

function dynReg(req, res) {
return Promise.try(function () {
return Bluebird.try(function () {
if (!req.body || !req.body.software_statement) {
info(
'request body does not have software_statement key. Did you remember content-type=application/json? Body = ',
Expand Down Expand Up @@ -82,12 +81,12 @@ function dynReg(req, res) {
// If scopes is listed in the body, check them to make sure they are in the software_statement, then
// replace the signed ones with the subset given in the body
if (req.body.scopes && typeof scopes === 'string') {
const possiblescopes = _.split(clientcert.scopes || '', ' ');
const subsetscopes = _.split(req.body.scopes);
const finalscopes = _.filter(subsetscopes, (s) =>
_.find(possiblescopes, s)
const possiblescopes = (clientcert.scopes || '').split(' ');
const subsetscopes = req.body.scopes.split();
const finalscopes = subsetscopes.filter((s) =>
possiblescopes.find(s)
);
clientcert.scopes = _.join(finalscopes, ' ');
clientcert.scopes = finalscopes.join(' ');
}

//------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions oada/services/auth/extendToken.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node

const argv = require('minimist')(process.argv.slice(2));
const _ = require('lodash');
const cloneDeep = require('clone-deep');
const chalk = require('chalk');

const { authorizations } = require('@oada/lib-arangodb');
Expand Down Expand Up @@ -38,7 +38,7 @@ const info = debug('extendToken:info');
const auth = await authorizations.findByToken(token);
trace('Found auth, it is ', auth);

const update = _.cloneDeep(auth);
const update = cloneDeep(auth);
update.expiresIn = expiresIn;
if (createTime) {
update.createTime = createTime;
Expand Down
Loading

0 comments on commit be12192

Please sign in to comment.