Commit 80fff711 by zCaesar

refractor code 1st time

parent 61bbce57
......@@ -7,9 +7,9 @@ var LRU = require("lru-cache"),
});
// for testing
function authCheck(client_id, username, topic, callback) {
callback(true);
}
// function authCheck(client_id, username, topic, callback) {
// callback(true);
// }
module.exports = function (options = {}) {
return function (req, res, next) {
......@@ -25,57 +25,24 @@ module.exports = function (options = {}) {
var cachekey = 'pub:' + req.body.client_id + ':' + req.body.username + ':' + topic;
var authstatus = cache.get(cachekey);
// checkRole
var checkRealDB = require('./checkClientRole').checkRealDB;
checkRealDB(req.body.username, (err, decoded) => {
if (err) {
// Set Response
var isShadow = require('./utils/getTopic').isShadow
if (isShadow(topic)) {
var output = {};
var getGroupID = require('./utils/getGroupID').getGroupID
getGroupID(req.body.username, req.body.client_id, (_id) => { // get groupID
var _ftopic = require('./utils/getTopic').rewriteTopic(topic, 'pub', _id, req.body.client_id, output); // get topic where concat with groupID
var response = {
'result': 'ok',
'modifiers': {
'topic': _ftopic,
'qos': 0,
'retain': false
}
if (typeof (authstatus) === 'undefined') {
cache.set(cachekey, true); // cache missed
}
if (output.verb == 'get' || output.verb == 'read') {
response.modifiers.payload = Buffer.from(req.body.client_id).toString('base64');
}
console.log(response);
var response
if (typeof (authstatus) == 'undefined') {
// cache missed
authCheck(req.body.client_id, req.body.username, topic, function (result) {
cache.set(cachekey, result);
var decoded = require('./checkClientRole').checkRealDB(req.body.username)
if (decoded) {
if (decoded.role === 'realtimedb') response = { 'result': 'ok' }
else response = { 'result': 'no' }
res.send(response);
});
}
else {
res.send(response);
}
next();
})
}
else {
var getGroupID = require('./utils/getGroupID').getGroupID
getGroupID(req.body.username, req.body.client_id, (_id) => { // get groupID
// console.log(_id)
var _ftopic = require('./utils/getTopic').rewriteTopic(topic, 'pub',_id, req.body.client_id) // get topic where concat with groupID
var response = {
var output = {};
var _id = require('./utils/getGroupID').getGroupID(req.body.username, req.body.client_id)
var _ftopic = require('./utils/getTopic').rewriteTopic(topic, 'pub', _id, req.body.client_id, output); // get topic where concat with groupID
response = {
'result': 'ok',
'modifiers': {
'topic': _ftopic,
......@@ -83,47 +50,15 @@ module.exports = function (options = {}) {
'retain': false
}
}
console.log(response)
if (typeof (authstatus) == 'undefined') {
// cache missed
authCheck(req.body.client_id, req.body.username, topic, function (result) {
cache.set(cachekey, result);
res.send(response);
});
}
else {
res.send(response);
}
next();
})
}
}
else {
console.log(decoded)
if (decoded.role === 'realtimedb') {
var response = {
'result': 'ok'
}
if (typeof (authstatus) == 'undefined') {
// cache missed
authCheck(req.body.client_id, req.body.username, topic, function (result) {
cache.set(cachekey, result);
res.send(response);
});
if (output.verb == 'get' || output.verb == 'read') {
response.modifiers.payload = Buffer.from(req.body.client_id).toString('base64');
}
else {
res.send(response);
}
next();
}
}
})
}
else {
res.send({
"result": "no"
});
res.send({ "result": "no" });
next();
}
}
......
var config = require('config');
var checkRealDB = require('./checkClientRole').checkRealDB
var getRole = require('./checkClientRole').getRole
// https://github.com/isaacs/node-lru-cache
var LRU = require("lru-cache"),
......@@ -10,23 +8,18 @@ var LRU = require("lru-cache"),
});
var debug = false;
var authclient = require('seneca')({log: 'silent'})
.client({port: config.get('authserv_port'), host: config.get('authserv_host')});
var authclient = require('seneca')({ log: 'silent' })
.client({ port: config.get('authserv_port'), host: config.get('authserv_host') });
function authCheck(client_id, token, password, callback) {
checkRealDB(token, (err, decoded) => {
/*
* decode.scope
* decode.iat
* decode.exp
*/
if (err) {
getRole(token, (role) => {
if (role === false) {
authclient.act({role:'auth',cmd:'token',action:'info',token: token}, function(err, res) {
if (require('./checkClientRole').checkRealDB(token)) { // auth realtimedb by token
callback(true)
}
else {
if (require('./checkClientRole').getRole(token)) callback(true) // auth client device by token
else {
authclient.act({ role: 'auth', cmd: 'token', action: 'info', token: token }, function (err, res) { // auth client device by query from db
if (debug) {
console.log("res ------>\n");
console.log(res);
......@@ -48,16 +41,8 @@ function authCheck(client_id, token, password, callback) {
callback(false);
}
});
}
else callback(true)
})
}
else {
callback(true)
}
})
}
module.exports = function (options = {}) {
......
......@@ -9,9 +9,9 @@ var LRU = require("lru-cache"),
var debug = false;
// for testing
function authCheck(client_id, token, topic, callback) {
callback(true);
}
// function authCheck(client_id, token, topic, callback) {
// callback(true);
// }
module.exports = function (options = {}) {
......@@ -30,99 +30,36 @@ module.exports = function (options = {}) {
var cachekey = 'sub:' + req.body.client_id + ':' + req.body.username + ':' + topic;
var authstatus = cache.get(cachekey);
// checkRole
var checkRealDB = require('./checkClientRole').checkRealDB
checkRealDB(req.body.username, (err, decoded) => {
if (err) {
// Set Response
var isShadow = require('./utils/getTopic').isShadow
if (isShadow(topic)) {
var getGroupID = require('./utils/getGroupID').getGroupID
getGroupID(req.body.username, req.body.client_id, (_id) => { // get groupID
var _ftopic = require('./utils/getTopic').rewriteTopic(topic, 'sub', _id, req.body.client_id) // get topic where concat with groupID
var _topic = [{ // setTopic for response
'topic': _ftopic,
'qos': 0
}]
var response = {
'result': 'ok',
'topics': _topic
}
console.log(response)
if (typeof (authstatus) == 'undefined') {
// cache missed
authCheck(req.body.client_id, req.body.username, topic, function (result) {
cache.set(cachekey, result);
res.send(response);
});
cache.set(cachekey, true); // cache missed
}
else {
var response
var decoded = require('./checkClientRole').checkRealDB(req.body.username)
if (decoded) {
if (decoded.role === 'realtimedb') response = { 'result': 'ok' }
else response = { 'result': 'no' }
res.send(response);
}
next();
})
}
else {
var getGroupID = require('./utils/getGroupID').getGroupID
getGroupID(req.body.username, req.body.client_id, (_id) => { // get groupID
// console.log(_id)
var _id = require('./utils/getGroupID').getGroupID(req.body.username, req.body.client_id)
var _ftopic = require('./utils/getTopic').rewriteTopic(topic, 'sub', _id, req.body.client_id) // get topic where concat with groupID
var _topic = [{ // setTopic for response
'topic': _ftopic,
'qos': 0
}]
var response = {
response = {
'result': 'ok',
'topics': _topic
}
console.log(response)
if (typeof (authstatus) == 'undefined') {
// cache missed
authCheck(req.body.client_id, req.body.username, topic, function (result) {
cache.set(cachekey, result);
res.send(response);
});
}
else {
res.send(response);
}
next();
})
}
}
else {
console.log(decoded)
if (decoded.role === 'realtimedb') {
var response = {
'result': 'ok'
}
if (typeof (authstatus) == 'undefined') {
// cache missed
authCheck(req.body.client_id, req.body.username, topic, function (result) {
cache.set(cachekey, result);
res.send(response);
});
}
else {
res.send(response);
}
next();
}
}
})
}
else {
res.send({
"result": "no"
});
res.send({ "result": "no" });
next();
}
}
}
var jwt = require('jsonwebtoken')
var config = require('config')
var getExp = require('./utils/getDates').getExp
function checkRealDB(token, cb) {
module.exports.checkRealDB = checkRealDB
module.exports.getRole = getRole
module.exports.signRole = signRole
function checkRealDB(token) {
const verifyOptions = {
algorithms: ['RS256']
};
jwt.verify(token, config.get('pubca'), verifyOptions, (err, decoded) => {
cb(err, decoded)
})
try {
return jwt.verify(token, config.get('pubca'), verifyOptions)
}
catch(e) {
return false
}
}
module.exports.checkRealDB = checkRealDB
function getRole(token, cb) {
function getRole(token) {
var secret = 'nexpie'
jwt.verify(token, secret, (err, decoded) => {
if (err) {
// console.log(err)
cb(false)
try {
return jwt.verify(token, secret)
}
else {
// console.log(decoded)
cb(decoded)
catch(e) {
return false
}
})
}
module.exports.getRole = getRole
function signRole(req, res) {
var secret = 'nexpie'
......@@ -40,44 +42,3 @@ function signRole(req, res) {
res.send('role not complete')
}
}
\ No newline at end of file
module.exports.signRole = signRole
function getExp(expires) {
var exp
if (expires.endsWith('y')) {
exp = getYears(expires.split('y')[0])
}
else if (expires.endsWith('m')) {
exp = getMonths(expires.split('m')[0])
}
else if (expires.endsWith('d')) {
exp = expires.split('d')[0] + 'd'
}
else if (expires.endsWith('h')) {
exp = expires.split('h')[0] + 'h'
}
else if (expires.endsWith('mi')) {
exp = getMinutes(expires.split('mi')[0])
}
else if (expires.endsWith('s')) {
exp = getSeconds(expires.split('s')[0])
}
else exp = getYears(10)
return exp
}
function getMonths(d) {
return (d * 30) + 'd'
}
function getYears(m) {
return (m * 30 * 12) + 'd'
}
function getMinutes(mi) {
return (mi * 1000 * 60) + 'ms'
}
function getSeconds(ms) {
return (ms * 1000) + 'ms'
}
\ No newline at end of file
......@@ -16,21 +16,6 @@ function on_deliver(req, res, next) {
}
module.exports.on_deliver = on_deliver
function hasGroup(topics) {
if (topics.indexOf('!') > -1) {
return true
}
else return false
}
module.exports.hasGroup = hasGroup
// function beDesireTopic(topics) {
// if (hasGroup(topics)) {
// return joinTopic(topics)
// }
// else return topics
// }
function joinTopic(topics) {
var topic = topics.split('/!')[1]
return topics.split('/!')[0] + topic.substring(topic.indexOf('/'), topic.length)
......
......@@ -2,33 +2,31 @@ function on_unsubscribe(req, res, next) {
console.log('------on unsubscribe-------')
console.log(req.body)
var topic = req.body.topics[0];
// checkRole
var checkRealDB = require('./checkClientRole').checkRealDB
checkRealDB(req.body.username, (err, decoded) => {
if (err) {
// Set Response
var getGroupID = require('./utils/getGroupID').getGroupID
getGroupID(req.body.username, req.body.client_id, (_id) => { // get groupID
// console.log(_id)
var _ftopic = require('./utils/getTopic').rewriteTopic(topic, 'unsub', _id, req.body.client_id) // get topic where concat with groupID
var response = {
"result": "ok",
"topics": [_ftopic]
var token = req.body.username
var client_id = req.body.client_id
var response
var decoded = require('./checkClientRole').checkRealDB(token)
if (decoded) {
if (decoded.role === 'realtimedb') {
response = { 'result': 'ok' }
}
console.log(response)
else response = { 'result': 'no' }
res.send(response);
})
next()
}
else {
console.log(decoded)
if (decoded.role === 'realtimedb') {
var response = {
'result': 'ok'
var _id = require('./utils/getGroupID').getGroupID(token, client_id)
if (_id) {
var _ftopic = require('./utils/getTopic').rewriteTopic(topic, 'unsub', _id, client_id)
response = {
"result": "ok",
"topics": [_ftopic]
}
console.log(response)
res.send(response);
}
else response = { 'result': 'no' }
res.send(response);
next()
}
})
}
module.exports.on_unsubscribe = on_unsubscribe
\ No newline at end of file
......@@ -14,7 +14,7 @@
"resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz",
"integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==",
"requires": {
"safer-buffer": "2.1.2"
"safer-buffer": "~2.1.0"
}
},
"assert-plus": {
......@@ -27,7 +27,7 @@
"resolved": "https://registry.npmjs.org/backoff/-/backoff-2.5.0.tgz",
"integrity": "sha1-9hbtqdPktmuMp/ynn2lXIsX44m8=",
"requires": {
"precond": "0.2.3"
"precond": "0.2"
}
},
"balanced-match": {
......@@ -41,7 +41,7 @@
"integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=",
"optional": true,
"requires": {
"tweetnacl": "0.14.5"
"tweetnacl": "^0.14.3"
}
},
"boom": {
......@@ -49,7 +49,7 @@
"resolved": "https://registry.npmjs.org/boom/-/boom-5.2.0.tgz",
"integrity": "sha512-Z5BTk6ZRe4tXXQlkqftmsAUANpXmuwlsF5Oov8ThoMbQRzdGTA1ngYRW160GexgOgjsFOKJz0LYhoNi+2AMBUw==",
"requires": {
"hoek": "4.2.1"
"hoek": "4.x.x"
}
},
"brace-expansion": {
......@@ -57,7 +57,7 @@
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
"integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
"requires": {
"balanced-match": "1.0.0",
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
}
},
......@@ -77,10 +77,10 @@
"resolved": "https://registry.npmjs.org/bunyan/-/bunyan-1.8.12.tgz",
"integrity": "sha1-8VDw9nSKvdcq6uhPBEA74u8RN5c=",
"requires": {
"dtrace-provider": "0.8.7",
"moment": "2.22.2",
"mv": "2.1.1",
"safe-json-stringify": "1.2.0"
"dtrace-provider": "~0.8",
"moment": "^2.10.6",
"mv": "~2",
"safe-json-stringify": "~1"
}
},
"commander": {
......@@ -99,7 +99,7 @@
"resolved": "https://registry.npmjs.org/config/-/config-1.31.0.tgz",
"integrity": "sha512-Ep/l9Rd1J9IPueztJfpbOqVzuKHQh4ZODMNt9xqTYdBBNRXbV4oTu34kCkkfdRVcDq0ohtpaeXGgb+c0LQxFRA==",
"requires": {
"json5": "1.0.1"
"json5": "^1.0.1"
}
},
"core-util-is": {
......@@ -112,10 +112,10 @@
"resolved": "https://registry.npmjs.org/csv/-/csv-1.2.1.tgz",
"integrity": "sha1-UjHt/BxxUlEuxFeBB2p6l/9SXAw=",
"requires": {
"csv-generate": "1.1.2",
"csv-parse": "1.3.3",
"csv-stringify": "1.1.2",
"stream-transform": "0.2.2"
"csv-generate": "^1.1.2",
"csv-parse": "^1.3.3",
"csv-stringify": "^1.1.2",
"stream-transform": "^0.2.2"
}
},
"csv-generate": {
......@@ -133,7 +133,7 @@
"resolved": "https://registry.npmjs.org/csv-stringify/-/csv-stringify-1.1.2.tgz",
"integrity": "sha1-d6QVJlgbzjOA8SsA18W7rHDIK1g=",
"requires": {
"lodash.get": "4.4.2"
"lodash.get": "~4.4.2"
}
},
"dashdash": {
......@@ -141,7 +141,7 @@
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
"integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=",
"requires": {
"assert-plus": "1.0.0"
"assert-plus": "^1.0.0"
}
},
"debug": {
......@@ -169,7 +169,7 @@
"integrity": "sha1-3JObTT4GIM/gwc2APQ0tftBP/QQ=",
"optional": true,
"requires": {
"nan": "2.11.0"
"nan": "^2.10.0"
}
},
"ecc-jsbn": {
......@@ -178,8 +178,8 @@
"integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=",
"optional": true,
"requires": {
"jsbn": "0.1.1",
"safer-buffer": "2.1.2"
"jsbn": "~0.1.0",
"safer-buffer": "^2.1.0"
}
},
"ecdsa-sig-formatter": {
......@@ -187,7 +187,7 @@
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.10.tgz",
"integrity": "sha1-HFlQAPBKiJffuFAAiSoPTDOvhsM=",
"requires": {
"safe-buffer": "5.1.2"
"safe-buffer": "^5.0.1"
}
},
"eraro": {
......@@ -195,7 +195,7 @@
"resolved": "https://registry.npmjs.org/eraro/-/eraro-1.0.0.tgz",
"integrity": "sha512-JeEqKyNgOxZNji2otWWDCDu1sWqGkrIBBhoGQH0LrPZObccQW8CoD94xkOtpmmlHeY/frG8IwR+jeCS8SQA/Xw==",
"requires": {
"lodash": "4.17.10"
"lodash": "4.17"
}
},
"escape-regexp-component": {
......@@ -214,7 +214,7 @@
"resolved": "https://registry.npmjs.org/ewma/-/ewma-2.0.1.tgz",
"integrity": "sha512-MYYK17A76cuuyvkR7MnqLW4iFYPEi5Isl2qb8rXiWpLiwFS9dxW/rncuNnjjgSENuVqZQkIuR4+DChVL4g1lnw==",
"requires": {
"assert-plus": "1.0.0"
"assert-plus": "^1.0.0"
}
},
"extsprintf": {
......@@ -232,9 +232,9 @@
"resolved": "https://registry.npmjs.org/find-my-way/-/find-my-way-1.15.2.tgz",
"integrity": "sha512-mngORPD+dxVhaZWB3nv2VE4J7ch1Mm4VcwNuYnixgZeHMfJujbOJ6CCWxDdI41WS4MykPYUA3aTCyux60sy4VQ==",
"requires": {
"fast-decode-uri-component": "1.0.0",
"safe-regex": "1.1.0",
"semver-store": "0.3.0"
"fast-decode-uri-component": "^1.0.0",
"safe-regex": "^1.1.0",
"semver-store": "^0.3.0"
}
},
"formidable": {
......@@ -258,7 +258,7 @@
"resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz",
"integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=",
"requires": {
"assert-plus": "1.0.0"
"assert-plus": "^1.0.0"
}
},
"gex": {
......@@ -266,7 +266,7 @@
"resolved": "https://registry.npmjs.org/gex/-/gex-0.3.0.tgz",
"integrity": "sha512-A1F2DMZUAnieFmVowt1QHcH7AJQZApRThR+z4C0GlzMGi6VYUAf9UvQdxODiCajGPGSRso86YJQ48E8+b5CBAQ==",
"requires": {
"lodash": "4.17.10"
"lodash": "4.17"
}
},
"glob": {
......@@ -275,11 +275,11 @@
"integrity": "sha1-DwiGD2oVUSey+t1PnOJLGqtuTSI=",
"optional": true,
"requires": {
"inflight": "1.0.6",
"inherits": "2.0.3",
"minimatch": "3.0.4",
"once": "1.4.0",
"path-is-absolute": "1.0.1"
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "2 || 3",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
},
"growl": {
......@@ -315,10 +315,10 @@
"resolved": "https://registry.npmjs.org/hpack.js/-/hpack.js-2.1.6.tgz",
"integrity": "sha1-h3dMCUnlE/QuhFdbPEVoH63ioLI=",
"requires": {
"inherits": "2.0.3",
"obuf": "1.1.2",
"readable-stream": "2.3.6",
"wbuf": "1.7.3"
"inherits": "^2.0.1",
"obuf": "^1.0.0",
"readable-stream": "^2.0.1",
"wbuf": "^1.1.0"
}
},
"http-deceiver": {
......@@ -331,9 +331,9 @@
"resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz",
"integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=",
"requires": {
"assert-plus": "1.0.0",
"jsprim": "1.4.1",
"sshpk": "1.14.2"
"assert-plus": "^1.0.0",
"jsprim": "^1.2.2",
"sshpk": "^1.7.0"
}
},
"inflight": {
......@@ -341,8 +341,8 @@
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
"requires": {
"once": "1.4.0",
"wrappy": "1.0.2"
"once": "^1.3.0",
"wrappy": "1"
}
},
"inherits": {
......@@ -376,7 +376,7 @@
"resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz",
"integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==",
"requires": {
"minimist": "1.2.0"
"minimist": "^1.2.0"
}
},
"jsonic": {
......@@ -389,15 +389,15 @@
"resolved": "https://registry.npmjs.org/jsonwebtoken/-/jsonwebtoken-8.3.0.tgz",
"integrity": "sha512-oge/hvlmeJCH+iIz1DwcO7vKPkNGJHhgkspk8OH3VKlw+mbi42WtD4ig1+VXRln765vxptAv+xT26Fd3cteqag==",
"requires": {
"jws": "3.1.5",
"lodash.includes": "4.3.0",
"lodash.isboolean": "3.0.3",
"lodash.isinteger": "4.0.4",
"lodash.isnumber": "3.0.3",
"lodash.isplainobject": "4.0.6",
"lodash.isstring": "4.0.1",
"lodash.once": "4.1.1",
"ms": "2.1.1"
"jws": "^3.1.5",
"lodash.includes": "^4.3.0",
"lodash.isboolean": "^3.0.3",
"lodash.isinteger": "^4.0.4",
"lodash.isnumber": "^3.0.3",
"lodash.isplainobject": "^4.0.6",
"lodash.isstring": "^4.0.1",
"lodash.once": "^4.0.0",
"ms": "^2.1.1"
},
"dependencies": {
"ms": {
......@@ -425,7 +425,7 @@
"requires": {
"buffer-equal-constant-time": "1.0.1",
"ecdsa-sig-formatter": "1.0.10",
"safe-buffer": "5.1.2"
"safe-buffer": "^5.0.1"
}
},
"jws": {
......@@ -433,8 +433,8 @@
"resolved": "https://registry.npmjs.org/jws/-/jws-3.1.5.tgz",
"integrity": "sha512-GsCSexFADNQUr8T5HPJvayTjvPIfoyJPtLQBwn5a4WZQchcrPMPMAWcC1AzJVRDKyD6ZPROPAxgv6rfHViO4uQ==",
"requires": {
"jwa": "1.1.6",
"safe-buffer": "5.1.2"
"jwa": "^1.1.5",
"safe-buffer": "^5.0.1"
}
},
"lodash": {
......@@ -487,8 +487,8 @@
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.3.tgz",
"integrity": "sha512-fFEhvcgzuIoJVUF8fYr5KR0YqxD238zgObTps31YdADwPPAp82a4M8TrckkWyx7ekNlf9aBcVn81cFwwXngrJA==",
"requires": {
"pseudomap": "1.0.2",
"yallist": "2.1.2"
"pseudomap": "^1.0.2",
"yallist": "^2.1.2"
}
},
"mime": {
......@@ -506,7 +506,7 @@
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
"integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
"requires": {
"brace-expansion": "1.1.11"
"brace-expansion": "^1.1.7"
}
},
"minimist": {
......@@ -563,12 +563,12 @@
"integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==",
"dev": true,
"requires": {
"fs.realpath": "1.0.0",
"inflight": "1.0.6",
"inherits": "2.0.3",
"minimatch": "3.0.4",
"once": "1.4.0",
"path-is-absolute": "1.0.1"
"fs.realpath": "^1.0.0",
"inflight": "^1.0.4",
"inherits": "2",
"minimatch": "^3.0.4",
"once": "^1.3.0",
"path-is-absolute": "^1.0.0"
}
}
}
......@@ -590,9 +590,9 @@
"integrity": "sha1-rmzg1vbV4KT32JN5jQPB6pVZtqI=",
"optional": true,
"requires": {
"mkdirp": "0.5.1",
"ncp": "2.0.0",
"rimraf": "2.4.5"
"mkdirp": "~0.5.1",
"ncp": "~2.0.0",
"rimraf": "~2.4.0"
}
},
"nan": {
......@@ -612,10 +612,10 @@
"resolved": "https://registry.npmjs.org/ndjson/-/ndjson-1.5.0.tgz",
"integrity": "sha1-rmA7NrE0vOw0e0UkIrC/mNWDLsg=",
"requires": {
"json-stringify-safe": "5.0.1",
"minimist": "1.2.0",
"split2": "2.2.0",
"through2": "2.0.3"
"json-stringify-safe": "^5.0.1",
"minimist": "^1.2.0",
"split2": "^2.1.0",
"through2": "^2.0.3"
}
},
"negotiator": {
......@@ -633,8 +633,8 @@
"resolved": "https://registry.npmjs.org/norma/-/norma-0.4.1.tgz",
"integrity": "sha512-BSnU+B35GzJgkEcNqiMIm79507Qg68O5L7gRVKATRSx17BHyDn0gVJsi3YzoANC1NbBoKRExwd3KsEZSUox63Q==",
"requires": {
"eraro": "1.0.0",
"lodash": "4.17.10"
"eraro": "1.0",
"lodash": "4.17"
}
},
"obuf": {
......@@ -647,7 +647,7 @@
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"requires": {
"wrappy": "1.0.2"
"wrappy": "1"
}
},
"ordu": {
......@@ -665,8 +665,8 @@
"resolved": "https://registry.npmjs.org/patrun/-/patrun-1.0.0.tgz",
"integrity": "sha512-oemWSuxjb27nPkREl88BxZ2EFDFUKSPace+zYZjFKj2xFn6w/LgDFGptgQvme384As2gpEFIv4WMVE1cb9lDXQ==",
"requires": {
"gex": "0.3.0",
"lodash": "4.17.10"
"gex": "0.3",
"lodash": "4.17"
}
},
"pidusage": {
......@@ -699,13 +699,13 @@
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz",
"integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==",
"requires": {
"core-util-is": "1.0.2",
"inherits": "2.0.3",
"isarray": "1.0.0",
"process-nextick-args": "2.0.0",
"safe-buffer": "5.1.2",
"string_decoder": "1.1.1",
"util-deprecate": "1.0.2"
"core-util-is": "~1.0.0",
"inherits": "~2.0.3",
"isarray": "~1.0.0",
"process-nextick-args": "~2.0.0",
"safe-buffer": "~5.1.1",
"string_decoder": "~1.1.1",
"util-deprecate": "~1.0.1"
}
},
"reconnect-core": {
......@@ -713,7 +713,7 @@
"resolved": "https://registry.npmjs.org/reconnect-core/-/reconnect-core-1.3.0.tgz",
"integrity": "sha1-+65SkZp4d9hE4yRtAaLyZwHIM8g=",
"requires": {
"backoff": "2.5.0"
"backoff": "~2.5.0"
}
},
"restify": {
......@@ -721,28 +721,28 @@
"resolved": "https://registry.npmjs.org/restify/-/restify-7.2.1.tgz",
"integrity": "sha512-xygVfQn/FiyzSPNIiOlzos6+RVcmTTK/bN0/m4z6vQwUY1yXntAsXM8ckq6hMxYfkhZfbPMM5hvBf75B8zLE1g==",
"requires": {
"assert-plus": "1.0.0",
"bunyan": "1.8.12",
"csv": "1.2.1",
"dtrace-provider": "0.8.7",
"escape-regexp-component": "1.0.2",
"ewma": "2.0.1",
"find-my-way": "1.15.2",
"formidable": "1.2.1",
"http-signature": "1.2.0",
"lodash": "4.17.10",
"lru-cache": "4.1.3",
"mime": "1.6.0",
"negotiator": "0.6.1",
"once": "1.4.0",
"pidusage": "1.2.0",
"qs": "6.5.2",
"restify-errors": "5.0.0",
"semver": "5.5.1",
"spdy": "3.4.7",
"uuid": "3.3.2",
"vasync": "1.6.4",
"verror": "1.10.0"
"assert-plus": "^1.0.0",
"bunyan": "^1.8.12",
"csv": "^1.1.1",
"dtrace-provider": "^0.8.1",
"escape-regexp-component": "^1.0.2",
"ewma": "^2.0.1",
"find-my-way": "^1.13.0",
"formidable": "^1.2.1",
"http-signature": "^1.2.0",
"lodash": "^4.17.10",
"lru-cache": "^4.1.3",
"mime": "^1.5.0",
"negotiator": "^0.6.1",
"once": "^1.4.0",
"pidusage": "^1.2.0",
"qs": "^6.5.2",
"restify-errors": "^5.0.0",
"semver": "^5.4.1",
"spdy": "^3.4.7",
"uuid": "^3.1.0",
"vasync": "^1.6.4",
"verror": "^1.10.0"
}
},
"restify-errors": {
......@@ -750,10 +750,10 @@
"resolved": "https://registry.npmjs.org/restify-errors/-/restify-errors-5.0.0.tgz",
"integrity": "sha512-+vby9Kxf7qlzvbZSTIEGkIixkeHG+pVCl34dk6eKnL+ua4pCezpdLT/1/eabzPZb65ADrgoc04jeWrrF1E1pvQ==",
"requires": {
"assert-plus": "1.0.0",
"lodash": "4.17.10",
"safe-json-stringify": "1.2.0",
"verror": "1.10.0"
"assert-plus": "^1.0.0",
"lodash": "^4.2.1",
"safe-json-stringify": "^1.0.3",
"verror": "^1.8.1"
}
},
"ret": {
......@@ -767,7 +767,7 @@
"integrity": "sha1-7nEM5dk6j9uFb7Xqj/Di11k0sto=",
"optional": true,
"requires": {
"glob": "6.0.4"
"glob": "^6.0.1"
}
},
"rolling-stats": {
......@@ -791,7 +791,7 @@
"resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz",
"integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=",
"requires": {
"ret": "0.1.15"
"ret": "~0.1.10"
}
},
"safer-buffer": {
......@@ -819,24 +819,24 @@
"resolved": "https://registry.npmjs.org/seneca/-/seneca-3.7.0.tgz",
"integrity": "sha512-Qr9vqmhvATmGvkRaNGiQPoL2YA/BaMp/6Hf4NUHoZU/z/GrP7I7truLp2BnEdPjYQcK/ucPWvly22+CVI7Rp2A==",
"requires": {
"archy": "1.0.0",
"eraro": "1.0.0",
"gate-executor": "1.1.1",
"gex": "0.3.0",
"json-stringify-safe": "5.0.1",
"jsonic": "0.3.0",
"lodash": "4.17.10",
"minimist": "1.2.0",
"nid": "0.3.2",
"norma": "0.4.1",
"ordu": "0.1.1",
"patrun": "1.0.0",
"qs": "6.5.2",
"rolling-stats": "0.1.1",
"semver": "5.5.1",
"seneca-transport": "2.3.0",
"use-plugin": "1.0.2",
"wreck": "12.5.1"
"archy": "1.0",
"eraro": "1.0",
"gate-executor": "1.1",
"gex": "0.3",
"json-stringify-safe": "5.0",
"jsonic": "0.3",
"lodash": "4.17",
"minimist": "1.2",
"nid": "0.3",
"norma": "0.4",
"ordu": "0.1",
"patrun": "1.0",
"qs": "6.5",
"rolling-stats": "0.1",
"semver": "5.5",
"seneca-transport": "2.3",
"use-plugin": "1.0",
"wreck": "12.5"
}
},
"seneca-transport": {
......@@ -844,17 +844,17 @@
"resolved": "https://registry.npmjs.org/seneca-transport/-/seneca-transport-2.3.0.tgz",
"integrity": "sha512-kocolZ+54fNbwVFloBnOyjeH4SFXFGyefeuqh2sNoQCycAGxBQpzFC8CIJkjL1YUQS8KczPxEs5sIFrKYIQdnA==",
"requires": {
"eraro": "1.0.0",
"gex": "0.3.0",
"jsonic": "0.3.0",
"lodash": "4.17.10",
"lru-cache": "4.1.3",
"ndjson": "1.5.0",
"nid": "0.3.2",
"patrun": "1.0.0",
"qs": "6.5.2",
"reconnect-core": "1.3.0",
"wreck": "12.5.1"
"eraro": "1.0",
"gex": "0.3",
"jsonic": "0.3",
"lodash": "4.17",
"lru-cache": "4.1",
"ndjson": "1.5",
"nid": "0.3",
"patrun": "1.0",
"qs": "6.5",
"reconnect-core": "1.3",
"wreck": "12.5"
}
},
"spdy": {
......@@ -862,12 +862,12 @@
"resolved": "https://registry.npmjs.org/spdy/-/spdy-3.4.7.tgz",
"integrity": "sha1-Qv9B7OXMD5mjpsKKq7c/XDsDrLw=",
"requires": {
"debug": "2.6.9",
"handle-thing": "1.2.5",
"http-deceiver": "1.2.7",
"safe-buffer": "5.1.2",
"select-hose": "2.0.0",
"spdy-transport": "2.1.0"
"debug": "^2.6.8",
"handle-thing": "^1.2.5",
"http-deceiver": "^1.2.7",
"safe-buffer": "^5.0.1",
"select-hose": "^2.0.0",
"spdy-transport": "^2.0.18"
}
},
"spdy-transport": {
......@@ -875,13 +875,13 @@
"resolved": "https://registry.npmjs.org/spdy-transport/-/spdy-transport-2.1.0.tgz",
"integrity": "sha512-bpUeGpZcmZ692rrTiqf9/2EUakI6/kXX1Rpe0ib/DyOzbiexVfXkw6GnvI9hVGvIwVaUhkaBojjCZwLNRGQg1g==",
"requires": {
"debug": "2.6.9",
"detect-node": "2.0.4",
"hpack.js": "2.1.6",
"obuf": "1.1.2",
"readable-stream": "2.3.6",
"safe-buffer": "5.1.2",
"wbuf": "1.7.3"
"debug": "^2.6.8",
"detect-node": "^2.0.3",
"hpack.js": "^2.1.6",
"obuf": "^1.1.1",
"readable-stream": "^2.2.9",
"safe-buffer": "^5.0.1",
"wbuf": "^1.7.2"
}
},
"split2": {
......@@ -889,7 +889,7 @@
"resolved": "https://registry.npmjs.org/split2/-/split2-2.2.0.tgz",
"integrity": "sha512-RAb22TG39LhI31MbreBgIuKiIKhVsawfTgEGqKHTK87aG+ul/PB8Sqoi3I7kVdRWiCfrKxK3uo4/YUkpNvhPbw==",
"requires": {
"through2": "2.0.3"
"through2": "^2.0.2"
}
},
"sshpk": {
......@@ -897,15 +897,15 @@
"resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.14.2.tgz",
"integrity": "sha1-xvxhZIo9nE52T9P8306hBeSSupg=",
"requires": {
"asn1": "0.2.4",
"assert-plus": "1.0.0",
"bcrypt-pbkdf": "1.0.2",
"dashdash": "1.14.1",
"ecc-jsbn": "0.1.2",
"getpass": "0.1.7",
"jsbn": "0.1.1",
"safer-buffer": "2.1.2",
"tweetnacl": "0.14.5"
"asn1": "~0.2.3",
"assert-plus": "^1.0.0",
"bcrypt-pbkdf": "^1.0.0",
"dashdash": "^1.12.0",
"ecc-jsbn": "~0.1.1",
"getpass": "^0.1.1",
"jsbn": "~0.1.0",
"safer-buffer": "^2.0.2",
"tweetnacl": "~0.14.0"
}
},
"stream-transform": {
......@@ -918,7 +918,7 @@
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz",
"integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==",
"requires": {
"safe-buffer": "5.1.2"
"safe-buffer": "~5.1.0"
}
},
"supports-color": {
......@@ -927,7 +927,7 @@
"integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==",
"dev": true,
"requires": {
"has-flag": "3.0.0"
"has-flag": "^3.0.0"
}
},
"through2": {
......@@ -935,8 +935,8 @@
"resolved": "https://registry.npmjs.org/through2/-/through2-2.0.3.tgz",
"integrity": "sha1-AARWmzfHx0ujnEPzzteNGtlBQL4=",
"requires": {
"readable-stream": "2.3.6",
"xtend": "4.0.1"
"readable-stream": "^2.1.5",
"xtend": "~4.0.1"
}
},
"tweetnacl": {
......@@ -950,9 +950,9 @@
"resolved": "https://registry.npmjs.org/use-plugin/-/use-plugin-1.0.2.tgz",
"integrity": "sha512-46ZNYmSDMgyCBsUIPwLFWzY45jIu4sHFKKq3/M63XCd/RxvliC4qRVWtUAWEexP7q8X1MHJ2Br1U5KLkVFcQCw==",
"requires": {
"eraro": "1.0.0",
"nid": "0.3.2",
"norma": "0.4.1"
"eraro": "1.0",
"nid": "0.3",
"norma": "0.4"
}
},
"util-deprecate": {
......@@ -993,9 +993,9 @@
"resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz",
"integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=",
"requires": {
"assert-plus": "1.0.0",
"assert-plus": "^1.0.0",
"core-util-is": "1.0.2",
"extsprintf": "1.3.0"
"extsprintf": "^1.2.0"
}
},
"wbuf": {
......@@ -1003,7 +1003,7 @@
"resolved": "https://registry.npmjs.org/wbuf/-/wbuf-1.7.3.tgz",
"integrity": "sha512-O84QOnr0icsbFGLS0O3bI5FswxzRr8/gHwWkDlQFskhSPryQXvrTMxjxGP4+iWYoauLoBvfDpkrOauZ+0iZpDA==",
"requires": {
"minimalistic-assert": "1.0.1"
"minimalistic-assert": "^1.0.0"
}
},
"wrappy": {
......@@ -1016,8 +1016,8 @@
"resolved": "https://registry.npmjs.org/wreck/-/wreck-12.5.1.tgz",
"integrity": "sha512-l5DUGrc+yDyIflpty1x9XuMj1ehVjC/dTbF3/BasOO77xk0EdEa4M/DuOY8W88MQDAD0fEDqyjc8bkIMHd2E9A==",
"requires": {
"boom": "5.2.0",
"hoek": "4.2.1"
"boom": "5.x.x",
"hoek": "4.x.x"
}
},
"xtend": {
......
module.exports.getExp = getExp
function getExp(expires) {
var exp
if (expires.endsWith('y')) {
exp = getYears(expires.split('y')[0])
}
else if (expires.endsWith('m')) {
exp = getMonths(expires.split('m')[0])
}
else if (expires.endsWith('d')) {
exp = expires.split('d')[0] + 'd'
}
else if (expires.endsWith('h')) {
exp = expires.split('h')[0] + 'h'
}
else if (expires.endsWith('mi')) {
exp = getMinutes(expires.split('mi')[0])
}
else if (expires.endsWith('s')) {
exp = getSeconds(expires.split('s')[0])
}
else exp = getYears(10)
return exp
}
function getMonths(d) {
return (d * 30) + 'd'
}
function getYears(m) {
return (m * 30 * 12) + 'd'
}
function getMinutes(mi) {
return (mi * 1000 * 60) + 'ms'
}
function getSeconds(ms) {
return (ms * 1000) + 'ms'
}
\ No newline at end of file
var getRole = require('../checkClientRole').getRole
function getGroupID(token, id, cb) {
checkID(token, id, (groupId) => {
// console.log(groupId)
cb(groupId)
})
}
module.exports.getGroupID = getGroupID
function checkID(token, id, cb) {
// console.log(token)
getRole(token, (role) => {
// console.log(role)
function getGroupID(token, client_id) {
var role = getRole(token)
if (role) {
if (role.hasOwnProperty('groupId')) {
cb(role.groupId)
return role.groupId
}
else {
doDB(id, (groupId) => {
// console.log(groupId)
cb(groupId)
})
return doDB(client_id)
}
})
}
else return role
}
module.exports.getGroupID = getGroupID
function doDB(id, cb) {
function doDB(client_id) {
var groupId = 'test'
cb(groupId)
return groupId
}
\ No newline at end of file
// function getTopic(topic, id) {
// //var _topic = classifiedTopic(topic) + '/!' + id + topic.split(classifiedTopic(topic))[1]
// var _topic = topicPrefix(topic) + id + topic.split(topicPrefix(topic))[1]
// return _topic
// }
// module.exports.getTopic = getTopic
// function topicPrefix(topic) {
// if (topic.indexOf('@msg') !== -1) {
// return '@msg/!'
// } else if (topic.indexOf('@shadow/updated') !== -1) {
// return '@shadow/updated/!'
// } else if (topic.indexOf('@shadow/update') !== -1) {
// return '@shadow/update/'
// } else if (topic.indexOf('@shadow/get') !== -1) {
// return '@shadow/get/!'
// } else if (topic.indexOf('@client') !== -1) {
// return '@client/'
// }
// }
var modify = require('./modify');
function rewriteTopic(topic, op, groupid, clientid, output) {
......@@ -64,12 +43,3 @@ function rewriteTopic(topic, op, groupid, clientid, output) {
}
module.exports.rewriteTopic = rewriteTopic
\ No newline at end of file
function isShadow(topic) {
if (topic.indexOf('@shadow') !== -1) {
return true
}
else return false
}
module.exports.isShadow = isShadow
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment