diff --git a/controller/protocol/base/identify.js b/controller/protocol/base/identify.js index 2bf7bee..1b0d176 100644 --- a/controller/protocol/base/identify.js +++ b/controller/protocol/base/identify.js @@ -6,16 +6,18 @@ module.exports = function( options ) { var protocol_version = seneca.export( 'constants/protocol_version' ) function identify( args, response ) { - seneca.act( "role: 'crypt', decrypt: 'message'", {message: args.command}, function(err, decrypt){ + var that = this + + that.act( "role: 'crypt', decrypt: 'message'", {message: args.command}, function(err, decrypt){ var message try { message = JSON.parse( decrypt.message ) } catch ( err ) { - seneca.log.debug('Cannot parse message', decrypt.message) + that.log.debug('Cannot parse message', decrypt.message) return response( null, {err: true, msg: 'Received unexpected response: ' + decrypt.message} ) } - seneca.act( "role:'protocol', execute_command:'identify'", + that.act( "role:'protocol', execute_command:'identify'", { command: message.command }, @@ -23,7 +25,7 @@ module.exports = function( options ) { if (err){ return response(err) } - seneca.act( "role: 'crypt', encrypt: 'message'", {message: JSON.stringify(data)}, function(err, encrypt){ + that.act( "role: 'crypt', encrypt: 'message'", {message: JSON.stringify(data)}, function(err, encrypt){ response(err, {response: encrypt.message}) }) } diff --git a/controller/protocol/v1/command.js b/controller/protocol/v1/command.js index e5e5b26..f3f46bc 100644 --- a/controller/protocol/v1/command.js +++ b/controller/protocol/v1/command.js @@ -6,18 +6,19 @@ module.exports = function( options ) { var protocol_version = seneca.export( 'constants/protocol_version' ) function command( args, response ) { + var that = this var command = args.command - seneca.act( "role: 'crypt', decrypt: 'message'", {message: command}, function(err, decrypt){ + that.act( "role: 'crypt', decrypt: 'message'", {message: command}, function(err, decrypt){ var message try { message = JSON.parse( decrypt.message ) } catch ( err ) { - seneca.log.debug("Cannot parse message", decrypt.message) + that.log.debug("Cannot parse message", decrypt.message) return response( null, {err: true, msg: 'Received unexpected response: ' + decrypt.message} ) } - seneca.act( "role:'protocol_v1',generate:'response'", + that.act( "role:'protocol_v1',generate:'response'", { command: message.command }, @@ -25,7 +26,7 @@ module.exports = function( options ) { if (err){ return response(err) } - seneca.act( "role: 'crypt', encrypt: 'message'", {message: JSON.stringify(data)}, function(err, encrypt){ + that.act( "role: 'crypt', encrypt: 'message'", {message: JSON.stringify(data)}, function(err, encrypt){ response(err, {response: encrypt.message}) }) } diff --git a/mite.js b/mite.js index d31cd5a..6e4a4f5 100644 --- a/mite.js +++ b/mite.js @@ -7,6 +7,8 @@ var fs = require( 'fs' ) module.exports = function( options ) { var seneca = this; + options.key = options.key || '1233212##$#2131' + function loadModules( done ) { processInjectedFolders( ['constants', 'controller', 'protocol', 'service'], done ) } diff --git a/package.json b/package.json index 559acca..06b60c1 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "mite", + "name": "seneca-mite", "description": "Mite plugin for seneca-sentinel.", "version": "0.0.1", "keywords": [ @@ -32,7 +32,9 @@ "lodash": "^3.10.1", "macaddress": "^0.2.8", "node-uuid": "^1.4.3", - "seneca-crypt": "~0.0.1" + "seneca-auth": "0.4.0", + "seneca-crypt": "~0.0.1", + "seneca-user": "0.2.10" }, "repository": { "type": "git", diff --git a/protocol/base/identify.js b/protocol/base/identify.js index 899940e..088f419 100644 --- a/protocol/base/identify.js +++ b/protocol/base/identify.js @@ -8,10 +8,11 @@ module.exports = function( options ) { var error_codes = seneca.export( 'protocol_v1/error_codes' ) function execute_identify( args, done ) { + var that = this - seneca.log.debug('Received command identify') + that.log.debug('Received command identify') - seneca.act( "role: 'mite', create:'auth_token'", function( err, data ) { + that.act( "role: 'mite', create:'auth_token'", function( err, data ) { if( err ) { return done( null, { authorize: { diff --git a/protocol/v1/configuration.js b/protocol/v1/configuration.js index c6f648f..c9454b8 100644 --- a/protocol/v1/configuration.js +++ b/protocol/v1/configuration.js @@ -4,11 +4,13 @@ module.exports = function( options ) { var seneca = this; function execute_configuration( args, done ) { + var that = this + seneca.log.debug( 'Command configuration', args.command ) var cmd = args.command var command_payload = cmd.payload - seneca.act( "role: 'mite', set:'configuration'", { configuration: command_payload}, done ) + that.act( "role: 'mite', set:'configuration'", { configuration: command_payload}, done ) } seneca diff --git a/protocol/v1/get_status.js b/protocol/v1/get_status.js index 5f25c49..0213e0e 100644 --- a/protocol/v1/get_status.js +++ b/protocol/v1/get_status.js @@ -7,9 +7,11 @@ module.exports = function( options ) { function execute_get_status( args, done ) { - seneca.log.debug( 'Command get_status', args.command ) + var that = this - seneca.act( "role: 'mite', get: 'os_status'", function( err, system ) { + that.log.debug( 'Command get_status', args.command ) + + that.act( "role: 'mite', get: 'os_status'", function( err, system ) { if( err ) { return done( err, {ok: false} ) } @@ -17,14 +19,14 @@ module.exports = function( options ) { os: system } - seneca.act( "role: 'status', get: 'seneca'", function( err, stats ) { + that.act( "role: 'status', get: 'seneca'", function( err, stats ) { if( err ) { return done( err, {ok: false} ) } payload.seneca_stats = stats - seneca.act( "role: 'status', get: 'web'", function( err, webstats ) { + that.act( "role: 'status', get: 'web'", function( err, webstats ) { if( err ) { return done( err, {ok: false} ) } @@ -38,7 +40,9 @@ module.exports = function( options ) { function cmd_stats( done ) { - seneca.act( 'role:seneca,stats:true', function( err, senstats ) { + var that = this + + that.act( 'role:seneca,stats:true', function( err, senstats ) { senstats.date = new Date() done(err, senstats) } ) @@ -46,7 +50,9 @@ module.exports = function( options ) { function cmd_webstats( done ) { - seneca.act( 'role:web,stats:true', function( err, webstats ) { + var that = this + + that.act( 'role:web,stats:true', function( err, webstats ) { webstats.date = new Date() done(err, webstats) } ) diff --git a/protocol/v1/protocol.js b/protocol/v1/protocol.js index 4d0c188..c8eb9c5 100644 --- a/protocol/v1/protocol.js +++ b/protocol/v1/protocol.js @@ -4,6 +4,8 @@ module.exports = function( options ) { var seneca = this; function generate_response( args, done ) { + var that = this + var cmd = args.command var error_codes = seneca.export( 'protocol_v1/error_codes' ) @@ -28,7 +30,7 @@ module.exports = function( options ) { ) } - seneca.act( "role: 'mite', get:'auth_token'", function( err, data ) { + that.act( "role: 'mite', get:'auth_token'", function( err, data ) { if( err ) { return done( null, @@ -50,7 +52,7 @@ module.exports = function( options ) { } var token = data.token - seneca.act( "role: 'mite', authorize:'command'", cmd, function( err, auth ) { + that.act( "role: 'mite', authorize:'command'", cmd, function( err, auth ) { if( err || !auth.ok ) { return done( null, @@ -72,7 +74,7 @@ module.exports = function( options ) { } // execute command - seneca.act( + that.act( "protocol:1,execute_command:'" + cmd.command.type + "'", { command: cmd, diff --git a/service/monitor/monitor.js b/service/monitor/monitor.js index f0e6380..7b07245 100644 --- a/service/monitor/monitor.js +++ b/service/monitor/monitor.js @@ -10,7 +10,6 @@ module.exports = function () { } function set_configuration( args, done ) { - if ( !args.configuration.max_samples || !args.configuration.rate_interval ) { return done( null, {ok: false, msg: 'Cannot start monitoring, invalid configuration data'} ) } @@ -49,7 +48,9 @@ module.exports = function () { function monitorOS() { - seneca.act( "role: 'status', get: 'os'", function ( err, statusData ) { + var that = this + + that.act( "role: 'status', get: 'os'", function ( err, statusData ) { if ( err ) { seneca.log.debug( 'Error receiving os status', err ) return diff --git a/service/status/seneca.js b/service/status/seneca.js index 796a2b7..8e37762 100644 --- a/service/status/seneca.js +++ b/service/status/seneca.js @@ -4,7 +4,9 @@ module.exports = function( options ) { var seneca = this; function cmd_stats( args, done ) { - seneca.act( 'role:seneca,stats:true', function( err, senstats ) { + var that = this + + that.act( 'role:seneca,stats:true', function( err, senstats ) { senstats.date = new Date() done(err, senstats) } ) diff --git a/service/status/web.js b/service/status/web.js index 1868210..f055bfd 100644 --- a/service/status/web.js +++ b/service/status/web.js @@ -7,7 +7,9 @@ module.exports = function( options ) { function cmd_webstats( args, done ) { - seneca.act( 'role:web,stats:true', function( err, webstats ) { + var that = this + + that.act( 'role:web,stats:true', function( err, webstats ) { webstats.date = new Date() done(err, webstats) } )