11var os = require ( 'os' ) ,
22 send = require ( './sender' ) ,
3- access = require ( '.access' ) ,
43 logger = require ( './logger' ) ,
5- CONFIG = require ( './config' ) ,
4+ CONFIG = require ( '../config /config' ) ,
65 pkginfo = require ( 'pkginfo' ) ( module , 'name' ) ,
76
87 options = {
9- host : CONFIG . HOST ,
8+ hostname : CONFIG . HOST ,
109 port : CONFIG . PORT ,
1110 method : 'POST' ,
11+ secureProtocol : 'SSLv3_method' ,
1212 headers : {
13- Content - Type : 'application/json' ,
14- X- Stackify - Key : CONFIG . LICENSE_KEY ,
15- X - Stackify - PV : 'V1'
13+ ' Content-Type' : 'application/json' ,
14+ ' X-Stackify-Key' : CONFIG . LICENSE_KEY ,
15+ ' X-Stackify-PV' : 'V1'
1616 }
17- }
17+ } ;
1818
1919module . exports = {
2020
21- identifyApp : function identifyApp ( licenseKey ) {
22- var options = options ,
21+ identifyApp : function identifyApp ( settings ) {
22+ var opt = options ,
2323 data = {
2424 "DeviceName" : os . hostname ( ) ,
2525 "AppName" : module . exports . name
2626 } ,
27- callback = function ( data ) {
27+ callback = function ( data ) {
2828 CONFIG . APP_DETAILS = data . toJSON ( ) ;
29+ CONFIG . LICENSE_KEY = settings . license_key ;
2930 } ,
30- fail = function ( ) {
31- setTimeout ( function ( ) {
32- identifyApp ( licenseKey )
33- } , CONFIG . REQUEST_TIMER )
34- }
35-
36- options . path = CONFIG . IDENTIFY_PATH ;
31+ fail = function ( ) {
32+ setTimeout ( function ( ) {
33+ send ( options , data , callback , fail ) ;
34+ } , CONFIG . REQUEST_TIMER ) ;
35+ } ;
36+ opt . path = CONFIG . IDENTIFY_PATH ;
37+
38+ if ( typeof ( settings . license_key ) === 'string' ) {
39+ opt . headers [ 'X-Stackify-Key' ] = settings . license_key ;
40+ send ( options , data , callback , fail ) ;
41+ } else {
42+ throw new TypeError ( 'License key is not defined or has a wrong format' ) ;
43+ }
3744
38- send ( options , data , callback , fail ) ;
39- } ;
45+ } ,
4046
4147 postLogs : function postLogs ( messages , cb , fail ) {
42- var options = options ,
43- callback = cb || function ( data ) {
44- logger . storage = logger . storage . slice ( CONFIG . MSG_LIMIT )
45- } ,
46- fail = function ( ) {
47- setTimeout ( function ( ) {
48- postLogs ( messages , callback , fail )
49- } , CONFIG . REQUEST_TIMER )
50- } ,
48+ var opt = options ,
5149 data = CONFIG . APP_DETAILS ;
5250
5351 data . Msgs = messages ;
54- options . path = CONFIG . LOG_SAVE_PATH ;
52+ opt . path = CONFIG . LOG_SAVE_PATH ;
5553
56- send ( options , data , callback , fail ) ;
57- } ;
58- }
54+ send ( options , data , cb , fail ) ;
55+ }
56+ } ;
0 commit comments