1- const Mservice = require ( '@microfleet/core' ) ;
1+ const { Microfleet , ConnectorsTypes } = require ( '@microfleet/core' ) ;
22const Mailer = require ( 'ms-mailer-client' ) ;
33const merge = require ( 'lodash/merge' ) ;
44const assert = require ( 'assert' ) ;
55const fsort = require ( 'redis-filtered-sort' ) ;
66const TokenManager = require ( 'ms-token' ) ;
77const LockManager = require ( 'dlock' ) ;
8- const get = require ( 'lodash/get' ) ;
98const RedisCluster = require ( 'ioredis' ) . Cluster ;
109const Flakeless = require ( 'ms-flakeless' ) ;
1110const conf = require ( './config' ) ;
11+ const get = require ( './utils/get-value' ) ;
1212
1313/**
1414 * @namespace Users
1515 */
16- module . exports = class Users extends Mservice {
16+ module . exports = class Users extends Microfleet {
1717 /**
1818 * Configuration options for the service
1919 * @type {Object }
@@ -63,11 +63,11 @@ module.exports = class Users extends Mservice {
6363 this . flake = new Flakeless ( config . flake ) ;
6464
6565 this . on ( 'plugin:connect:amqp' , ( amqp ) => {
66- this . _mailer = new Mailer ( amqp , config . mailer ) ;
66+ this . mailer = new Mailer ( amqp , config . mailer ) ;
6767 } ) ;
6868
6969 this . on ( 'plugin:close:amqp' , ( ) => {
70- this . _mailer = null ;
70+ this . mailer = null ;
7171 } ) ;
7272
7373 this . on ( `plugin:connect:${ this . redisType } ` , ( redis ) => {
@@ -80,16 +80,16 @@ module.exports = class Users extends Mservice {
8080
8181 this . on ( 'plugin:start:http' , ( server ) => {
8282 // if oAuth is enabled - initiate the strategy
83- if ( get ( config , 'oauth.enabled' , false ) === true ) {
83+ if ( get ( config , 'oauth.enabled' , { default : false } ) === true ) {
8484 assert . equal ( config . http . server . handler , 'hapi' , 'oAuth must be used with hapi.js webserver' ) ;
8585
8686 const OAuthStrategyHandler = require ( './auth/oauth/hapi' ) ;
87- this . _oauth = new OAuthStrategyHandler ( server , config ) ;
87+ this . oauth = new OAuthStrategyHandler ( server , config ) ;
8888 }
8989 } ) ;
9090
9191 this . on ( 'plugin:stop:http' , ( ) => {
92- this . _oauth = null ;
92+ this . oauth = null ;
9393 } ) ;
9494
9595 // cleanup connections
@@ -100,42 +100,39 @@ module.exports = class Users extends Mservice {
100100
101101 // add migration connector
102102 if ( config . migrations . enabled === true ) {
103- this . addConnector ( Mservice . ConnectorsTypes . migration , ( ) => (
103+ this . addConnector ( ConnectorsTypes . migration , ( ) => (
104104 this . migrate ( 'redis' , `${ __dirname } /migrations` )
105105 ) ) ;
106106 }
107107
108- // adds mailer connector
109- this . _defineGetter ( 'mailer' ) ;
110-
111108 // ensure we close connection when needed
112- this . addDestructor ( Mservice . ConnectorsTypes . database , ( ) => (
113- this . _pubsub . quit ( ) . reflect ( )
109+ this . addDestructor ( ConnectorsTypes . database , ( ) => (
110+ this . pubsub . quit ( ) . reflect ( )
114111 ) ) ;
115112
116113 // add lock manager
117- this . addConnector ( Mservice . ConnectorsTypes . migration , async ( ) => {
118- this . _pubsub = redisDuplicate ( this . redis ) ;
119- await this . _pubsub . connect ( ) ;
114+ this . addConnector ( ConnectorsTypes . migration , async ( ) => {
115+ this . pubsub = redisDuplicate ( this . redis ) ;
116+ await this . pubsub . connect ( ) ;
120117
121118 this . dlock = new LockManager ( {
122119 ...config . lockManager ,
123- client : this . _redis ,
124- pubsub : this . _pubsub ,
120+ client : this . redis ,
121+ pubsub : this . pubsub ,
125122 log : this . log ,
126123 } ) ;
127124
128125 return this . dlock ;
129126 } ) ;
130127
131128 // init account seed
132- this . addConnector ( Mservice . ConnectorsTypes . application , ( ) => (
129+ this . addConnector ( ConnectorsTypes . application , ( ) => (
133130 this . initAdminAccounts ( )
134131 ) ) ;
135132
136133 // fake accounts for development
137134 if ( process . env . NODE_ENV === 'development' ) {
138- this . addConnector ( Mservice . ConnectorsTypes . application , ( ) => (
135+ this . addConnector ( ConnectorsTypes . application , ( ) => (
139136 this . initFakeAccounts ( )
140137 ) ) ;
141138 }
0 commit comments