diff --git a/.eslintignore b/.eslintignore index ce467ba..9c8d714 100755 --- a/.eslintignore +++ b/.eslintignore @@ -1,8 +1,7 @@ -/client/ -/coverage/ -/node_modules/ -server/dropdb.js -/lib/expression-language/expression-syntax-parser.js +build/ +client/ +coverage/ +node_modules/ +test/ drop.js -/test/ - +Gruntfile.js diff --git a/.eslintrc b/.eslintrc index 8f2f7cc..6edc78f 100755 --- a/.eslintrc +++ b/.eslintrc @@ -111,7 +111,7 @@ "no-undefined": 1, // http://eslint.org/docs/rules/no-undefined "no-with": 2, // http://eslint.org/docs/rules/no-with "handle-callback-err": 1, // http://eslint.org/docs/rules/handle-callback-err - "radix": 2, // http://eslint.org/docs/rules/radix + "radix": 0, // http://eslint.org/docs/rules/radix "wrap-iife": [2, "any"], // http://eslint.org/docs/rules/wrap-iife "yoda": 2, // http://eslint.org/docs/rules/yoda diff --git a/.gitignore b/.gitignore index 3bff760..7b1734a 100755 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,4 @@ out/ *.zip /common/models/test package-lock.json +oracle-user.sh diff --git a/Gruntfile.js b/Gruntfile.js index 0cb2a73..a6628dd 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -10,38 +10,6 @@ module.exports = function GruntConfig(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), - mkdir: { - all: { - options: { - create: ['dist'] - } - } - }, - - copy: { - main: { - files: [ - // includes files within path and its sub-directories - { - expand: true, - src: ['**', '!node_modules/**', '!coverage/**'], - dest: 'dist/' - } - ] - } - }, - - mochaTest: { - test: { - options: { - quiet: false, - clearRequireCache: true, - timeout: 100000 - }, - src: ['test/test.js'] - } - }, - clean: { coverage: { src: ['coverage/'] @@ -72,12 +40,8 @@ module.exports = function GruntConfig(grunt) { }); // Add the grunt-mocha-test tasks. - grunt.loadNpmTasks('grunt-mocha-test'); - grunt.loadNpmTasks('grunt-mocha-istanbul'); grunt.loadNpmTasks('grunt-contrib-clean'); - - grunt.loadNpmTasks('grunt-mkdir'); - grunt.loadNpmTasks('grunt-contrib-copy'); + grunt.loadNpmTasks('grunt-mocha-istanbul'); grunt.registerTask('test-with-coverage', ['clean:coverage', 'mocha_istanbul']); }; diff --git a/package.json b/package.json index b651d4e..e7f8a95 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "oe-node-red-nodes", - "version": "2.1.0", + "version": "2.2.0", "description": "Node-RED nodes for oeCloud based applications", "main": "node-red.js", "scripts": { @@ -47,26 +47,21 @@ "devDependencies": { "babel-eslint": "7.2.3", "chai": "3.4.1", - "chai-datetime": "1.4.0", "chai-things": "0.2.0", "chalk": "1.1.1", "eslint": "4.10.0", "grunt": "1.0.4", - "grunt-banner": "0.6.0", "grunt-cli": "1.3.2", "grunt-contrib-clean": "2.0.0", - "grunt-contrib-copy": "1.0.0", - "grunt-jsbeautifier": "0.2.13", - "grunt-mkdir": "1.0.0", "grunt-mocha-istanbul": "5.0.2", - "grunt-mocha-test": "0.13.3", "istanbul": "0.4.5", - "oe-node-red": "^2.0.0", + "mocha": "5.2.0", "oe-cloud": "^2.0.0", - "oe-multi-tenancy": "^2.0.0", - "loopback-connector-mongodb": "3.9.2", + "oe-connector-mongodb": "^2.0.0", + "oe-connector-oracle": "^2.0.0", "oe-connector-postgresql": "^2.0.0", - "mocha": "5.2.0", + "oe-multi-tenancy": "^2.0.0", + "oe-node-red": "^2.0.0", "superagent-defaults": "0.1.14", "supertest": "3.4.2" } diff --git a/postinstall.js b/postinstall.js index 88cc681..3419af3 100644 --- a/postinstall.js +++ b/postinstall.js @@ -1,11 +1,13 @@ var fs = require('fs'); -var deleteFolderRecursive = function(path) { - if( fs.existsSync(path) ) { - fs.readdirSync(path).forEach(function(file,index){ - var curPath = path + "/" + file; - if(fs.lstatSync(curPath).isDirectory()) { // recurse +var deleteFolderRecursive = function (path) { + if (fs.existsSync(path)) { + fs.readdirSync(path).forEach(function (file, index) { + var curPath = path + '/' + file; + // recurse + if (fs.lstatSync(curPath).isDirectory()) { deleteFolderRecursive(curPath); - } else { // delete file + } else { + // delete file fs.unlinkSync(curPath); } }); @@ -13,7 +15,8 @@ var deleteFolderRecursive = function(path) { } }; var initDir = process.env.INIT_CWD; -deleteFolderRecursive(initDir + "/node_modules/node-red-node-email"); -deleteFolderRecursive(initDir + "/node_modules/mailparser"); -deleteFolderRecursive(initDir + "/node_modules/mimelib"); -console.log("Removed node-red-node-email module"); +deleteFolderRecursive(initDir + '/node_modules/node-red-node-email'); +deleteFolderRecursive(initDir + '/node_modules/mailparser'); +deleteFolderRecursive(initDir + '/node_modules/mimelib'); +// eslint-disable-next-line no-console +console.log('Removed node-red-node-email module'); diff --git a/test/app-list.json b/test/app-list.json index c5de11b..beedf32 100755 --- a/test/app-list.json +++ b/test/app-list.json @@ -5,6 +5,7 @@ }, { "path": "oe-multi-tenancy", + "autoEnableMixins" : true, "enabled": true }, { diff --git a/test/datasources.json b/test/datasources.json index b7f31ca..3409e84 100755 --- a/test/datasources.json +++ b/test/datasources.json @@ -7,7 +7,6 @@ "name": "transient", "connector": "transient" }, - "db": { "host": "localhost", "port": 27017, @@ -15,7 +14,7 @@ "database": "oe-node-red-nodes-test", "password": "admin", "name": "db", - "connector": "mongodb", + "connector": "oe-connector-mongodb", "user": "admin", "connectionTimeout": 500000, "connectTimeoutMS": 500000, diff --git a/test/datasources.mongo.js b/test/datasources.mongo.js index ba17367..c6e3998 100755 --- a/test/datasources.mongo.js +++ b/test/datasources.mongo.js @@ -5,9 +5,9 @@ * */ var mongoHost = process.env.MONGO_HOST || 'localhost'; +var mongoPort = process.env.MONGO_PORT ? parseInt(process.env.MONGO_PORT) : 27017; var dbName = process.env.DB_NAME || 'oe-node-red-nodes-test'; -module.exports = -{ +module.exports = { 'memdb': { 'name': 'memdb', 'connector': 'memory' @@ -18,13 +18,11 @@ module.exports = }, 'db': { 'host': mongoHost, - 'port': 27017, - 'url': 'mongodb://' + mongoHost + ':27017/' + dbName, + 'port': mongoPort, + 'url': 'mongodb://' + mongoHost + ':' + mongoPort + '/' + dbName, 'database': dbName, - 'password': 'admin', 'name': 'db', - 'connector': 'mongodb', - 'user': 'admin', + 'connector': 'oe-connector-mongodb', 'connectionTimeout': 500000 } }; diff --git a/test/datasources.oracle.js b/test/datasources.oracle.js index 8792ffd..a5db290 100755 --- a/test/datasources.oracle.js +++ b/test/datasources.oracle.js @@ -4,16 +4,10 @@ * Bangalore, India. All Rights Reserved. * */ -/** - ** - ** ©2016-2017 EdgeVerve Systems Limited (a fully owned Infosys subsidiary), - ** Bangalore, India. All Rights Reserved. - ** - **/ -var oracleSID = process.env.ORACLE_SID || 'orclpdb.ad.infosys.com'; +var oracleSID = process.env.ORACLE_SID || 'ORCLCDB'; var oracleHost = process.env.ORACLE_HOST || 'localhost'; -var oraclePort = process.env.ORACLE_PORT || 1521; +var oraclePort = process.env.ORACLE_PORT ? parseInt(process.env.ORACLE_PORT) : 1521; var oracleUserName = process.env.ORACLE_USERNAME || 'oeadmin'; var oracleUserPassword = process.env.ORACLE_PASSWORD || 'oeadmin'; diff --git a/test/datasources.postgres.js b/test/datasources.postgres.js index 946a524..7339f67 100755 --- a/test/datasources.postgres.js +++ b/test/datasources.postgres.js @@ -5,9 +5,9 @@ * */ var postgresHost = process.env.POSTGRES_HOST || 'localhost'; +var postgresPort = process.env.POSTGRES_PORT ? parseInt(process.env.POSTGRES_PORT) : 5432; var dbName = process.env.DB_NAME || 'oe-node-red-nodes-test'; -module.exports = -{ +module.exports = { 'memdb': { 'name': 'memdb', 'connector': 'memory' @@ -16,11 +16,10 @@ module.exports = 'name': 'transient', 'connector': 'transient' }, - 'db': { 'host': postgresHost, - 'port': 5432, - 'url': 'postgres://postgres:postgres@' + postgresHost + ':5432/' + dbName, + 'port': postgresPort, + 'url': 'postgres://postgres:postgres@' + postgresHost + ':' + postgresPort + '/' + dbName, 'database': dbName, 'password': 'postgres', 'name': 'db', diff --git a/test/node-red-settings.js b/test/node-red-settings.js index b564aff..20d72c4 100755 --- a/test/node-red-settings.js +++ b/test/node-red-settings.js @@ -81,7 +81,7 @@ module.exports = { // Node-RED scans the `nodes` directory in the install directory to find nodes. // The following property can be used to specify an additional directory to scan. - nodesDir: './', + nodesDir: './' // By default, the Node-RED UI is available at http://localhost:1880/ // The following property can be used to specify a different root path. @@ -204,11 +204,11 @@ module.exports = { // context.global.os // functionGlobalContext: { - // os:require('os'), - // octalbonescript:require('octalbonescript'), - // jfive:require("johnny-five"), - // j5board:require("johnny-five").Board({repl:false}) - //} + // os:require('os'), + // octalbonescript:require('octalbonescript'), + // jfive:require("johnny-five"), + // j5board:require("johnny-five").Board({repl:false}) + // } // The following property can be used to order the categories in the editor // palette. If a node's category is not in the list, the category will get diff --git a/test/oracle-utility.js b/test/oracle-utility.js index 153da7f..40a1734 100755 --- a/test/oracle-utility.js +++ b/test/oracle-utility.js @@ -15,22 +15,29 @@ // ORACLE_SYSUSER // ORACLE_SYSPASSWORD // ORACLE_SID -// CI_PROJECT_NAME // CI_PROJECT_NAMESPACE +// CI_PROJECT_NAME var oracledb = require('oracledb'); var async = require('async'); +var fs = require('fs'); +var os = require('os'); + var oracleHost = process.env.ORACLE_HOST || 'localhost'; -var oraclePort = process.env.ORACLE_PORT || 1521; +var oraclePort = process.env.ORACLE_PORT ? parseInt(process.env.ORACLE_PORT) : 1521; +var oracleSID = process.env.ORACLE_SID || 'ORCLCDB'; var oracleConnectSettings = { 'password': process.env.ORACLE_SYSPASSWORD || 'manager1', 'user': process.env.ORACLE_SYSUSER || 'sys', - 'connectString': oracleHost + ':' + oraclePort + '/' + (process.env.ORACLE_SID || 'orclpdb.ad.infosys.com') + 'connectString': oracleHost + ':' + oraclePort + '/' + oracleSID }; -var userName = process.env.CI_PROJECT_NAMESPACE.toUpperCase() + '-' + (process.env.CI_PROJECT_NAME || 'oecloud').toUpperCase(); -var password = process.env.CI_PROJECT_NAMESPACE.toLowerCase(); +var namespace = process.env.CI_PROJECT_NAMESPACE ? process.env.CI_PROJECT_NAMESPACE.replace(/[^a-zA-Z0-9]/g, '') : 'oecloudio'; +var name = process.env.CI_PROJECT_NAME ? process.env.CI_PROJECT_NAME.replace(/[^a-zA-Z0-9]/g, '') : 'oecloud'; + +var userName = namespace.toUpperCase() + '_' + name.toUpperCase(); +var password = namespace.toLowerCase(); var grants = [ 'CREATE VIEW', @@ -44,30 +51,32 @@ var grants = [ ]; function createUser(connection, cb) { - var sql = 'alter session set "_ORACLE_SCRIPT"=true'; - connection.execute(sql, function (e, r) { - if (e) { - console.error('Ignoring error of alter session. UserName : ' + userName + ' Error :' + e); + var alterSQL = 'alter session set "_ORACLE_SCRIPT"=true'; + connection.execute(alterSQL, function (alterErr, alterRes) { + if (alterErr) { + console.error('Ignoring error of alter session. UserName : ' + userName + ' Error :' + alterErr); } - console.log(sql, ' ......... ok'); - var sql = 'CREATE USER "' + userName + '" IDENTIFIED BY ' + password; + console.log(alterSQL, ' ......... ok'); - connection.execute(sql, function (err, result) { - if (err) { - throw new Error('Unable to create user ' + userName + ' Error :' + err); + var createUserSQL = 'CREATE USER "' + userName + '" IDENTIFIED BY ' + password; + connection.execute(createUserSQL, function (createErr, createRes) { + if (createErr) { + console.error(createErr); + throw new Error('Unable to create user ' + userName); } - console.log(sql, ' ......... ok'); - async.each(grants, function (g, callback) { - var sql = 'GRANT ' + g + ' to "' + userName + '"'; + console.log(createUserSQL, ' ......... ok'); - connection.execute(sql, function (err2, result2) { - if (err2) { - throw new Error('Unable to execute grant ' + sql); + async.each(grants, function (g, callback) { + var grantSQL = 'GRANT ' + g + ' to "' + userName + '"'; + connection.execute(grantSQL, function (grantErr, grantRes) { + if (grantErr) { + console.error(grantErr); + throw new Error('Unable to execute grant ' + grantSQL); } - console.log(sql, ' ......... ok'); + console.log(grantSQL, ' ......... ok'); return callback(); }); - }, function (err) { + }, function (grantAsyncErr) { console.log('User ' + userName + ' Created successfully'); return cb(); }); @@ -75,78 +84,83 @@ function createUser(connection, cb) { }); } - function dropTables(cb) { - var oracleConnectSettings2 = Object.assign({}, oracleConnectSettings); - oracleConnectSettings2.user = userName; - oracleConnectSettings2.password = password; - - oracledb.getConnection( - oracleConnectSettings2, - function (err, connection) { - if (err) { - throw new Error('Unable to connect to Oracle Database ' + JSON.stringify(oracleConnectSettings)); + var oracleUserConnectSettings = { + 'password': password, + 'user': userName, + 'connectString': oracleHost + ':' + oraclePort + '/' + oracleSID + }; + + oracledb.getConnection(oracleUserConnectSettings, function (userConnectionErr, connection) { + if (userConnectionErr) { + console.error(userConnectionErr); + throw new Error('Unable to connect to Oracle Database ' + JSON.stringify(oracleUserConnectSettings)); + } + + var totalRows = 1000; + var selectDropTableSQL = "select 'drop table \"' || table_name || '\"' from all_tables where owner = '" + userName + "'"; + connection.execute(selectDropTableSQL, {}, { maxRows: totalRows }, function (selectDropErr, selectDropRes) { + if (selectDropErr) { + console.error(selectDropErr); + throw new Error('Unable to find tables ' + userName); } - var sql = "select 'drop table \"' || table_name || '\"' from all_tables where owner = '" + userName + "'"; - var totalRows = 1000; - connection.execute(sql, {}, {maxRows: totalRows}, function (err, result) { - if (err) { - throw new Error('Unable to find tables ' + userName + ' Error :' + err); - } - connection.execute(sql, {}, {maxRows: totalRows}, function (err2, result2) { - if (err2) { - throw new Error('Unable to execute droping of table ' + sql); - } - if (!result2 || !result2.rows || result2.rows.length === 0) { - return cb(); + if (!selectDropRes || !selectDropRes.rows || selectDropRes.rows.length === 0) { + return cb(); + } + + async.each(selectDropRes.rows, function (row, callback) { + var dropTableSQL = row[0]; + connection.execute(dropTableSQL, function (dropTableErr, dropTableRes) { + if (dropTableErr) { + console.error(dropTableErr); + throw new Error('Unable to drop table\nSQL: ' + sql); } - async.each(result2.rows, function (row, callback) { - var sql = row[0]; - connection.execute(sql, function (err2, result2) { - if (err2) { - throw new Error('Unable to drop table\nERROR : ' + err2 + '\nSQL : ' + sql); - } - console.log(sql, ' ......... ok'); - return callback(); - }); - }, function (err) { - console.log('Tables of user ' + userName + ' dropped successfully'); - return cb(); - }); + console.log(dropTableSQL, ' ......... ok'); + return callback(); }); + }, function (dropAsyncErr) { + console.log('Tables of user ' + userName + ' dropped successfully'); + return cb(); }); }); + }); } -oracledb.getConnection( - oracleConnectSettings, - function (err, connection) { +function generateUserBundle() { + console.log("Generating oracle user details shell script"); + fs.writeFileSync('./oracle-user.sh', '#!/bin/sh' + os.EOL); + fs.appendFileSync('./oracle-user.sh', 'export ORACLE_USERNAME=' + userName + os.EOL); + fs.appendFileSync('./oracle-user.sh', 'export ORACLE_PASSWORD=' + password + os.EOL); +} + +oracledb.getConnection(oracleConnectSettings, function (connectionErr, connection) { + if (connectionErr) { + console.error(connectionErr); + throw new Error('Unable to connect to Oracle Database ' + JSON.stringify(oracleConnectSettings)); + } + var sql = "select username, user_id from dba_users where username = '" + userName + "'"; + console.log(sql); + connection.execute(sql, function (err, result) { if (err) { - throw new Error('Unable to connect to Oracle Database ' + JSON.stringify(oracleConnectSettings)); + console.error(err); return; } - var sql = "select username, user_id from dba_users where username = '" + userName + "'"; - console.log(sql); - connection.execute(sql, - function (err, result) { + if (!result.rows || result.rows.length == 0) { + createUser(connection, function (err) { if (err) { - console.error(err); return; + return process.exit(1); } - if (!result.rows || result.rows.length == 0) { - createUser(connection, function (err) { - if (err) { - return process.exit(1); - } - return process.exit(); - }); - } else { - dropTables(function (err) { - if (err) { - return process.exit(1); - } - return process.exit(); - }); + generateUserBundle(); + return process.exit(); + }); + } else { + dropTables(function (err) { + if (err) { + return process.exit(1); } + generateUserBundle(); + return process.exit(); }); + } }); - +});