1- import { join as joinPath , normalize as normalizePath , extname as pathExtension } from 'path' ;
1+ import { join as joinPath , normalize as normalizePath , extname as pathExtension } from 'path' ;
22import mkdirp from 'mkdirp' ;
33import tar from 'tar' ;
44import fs from 'fs-extra' ;
@@ -7,8 +7,10 @@ import FileSystem from '../../common/file_system';
77import config from '../../common/config' ;
88import Logger from '../../common/logger' ;
99import path from 'path' ;
10- import { RuleNotFoundError , RuleNotReadableError , RuleNotWritableError ,
11- RulesFolderNotFoundError , RulesRootFolderNotCreatableError } from '../../common/errors/rule_request_errors' ;
10+ import {
11+ RuleNotFoundError , RuleNotReadableError , RuleNotWritableError ,
12+ RulesFolderNotFoundError , RulesRootFolderNotCreatableError
13+ } from '../../common/errors/rule_request_errors' ;
1214
1315let logger = new Logger ( 'RulesController' ) ;
1416
@@ -21,26 +23,26 @@ export default class RulesController {
2123 getRules ( path ) {
2224 const self = this ;
2325 const fullPath = joinPath ( self . rulesFolder , path ) ;
24- return new Promise ( function ( resolve , reject ) {
26+ return new Promise ( function ( resolve , reject ) {
2527 self . _fileSystemController . readDirectory ( fullPath )
26- . then ( function ( directoryIndex ) {
28+ . then ( function ( directoryIndex ) {
2729
28- directoryIndex . rules = directoryIndex . files . filter ( function ( fileName ) {
30+ directoryIndex . rules = directoryIndex . files . filter ( function ( fileName ) {
2931 return pathExtension ( fileName ) . toLowerCase ( ) === '.yaml' ;
30- } ) . map ( function ( fileName ) {
32+ } ) . map ( function ( fileName ) {
3133 return fileName . slice ( 0 , - 5 ) ;
3234 } ) ;
3335
3436 delete directoryIndex . files ;
3537 resolve ( directoryIndex ) ;
3638 } )
37- . catch ( function ( error ) {
39+ . catch ( function ( error ) {
3840
3941 // Check if the requested folder is the rules root folder
4042 if ( normalizePath ( self . rulesFolder ) === fullPath ) {
4143
4244 // Try to create the root folder
43- mkdirp ( fullPath , function ( error ) {
45+ mkdirp ( fullPath , function ( error ) {
4446 if ( error ) {
4547 reject ( new RulesRootFolderNotCreatableError ( ) ) ;
4648 logger . warn ( `The rules root folder (${ fullPath } ) couldn't be found nor could it be created by the file system.` ) ;
@@ -58,29 +60,29 @@ export default class RulesController {
5860
5961 rule ( id ) {
6062 const self = this ;
61- return new Promise ( function ( resolve , reject ) {
63+ return new Promise ( function ( resolve , reject ) {
6264 self . _findRule ( id )
63- . then ( function ( access ) {
65+ . then ( function ( access ) {
6466 console . log ( 'rule resolved' ) ;
6567 resolve ( {
66- get : function ( ) {
68+ get : function ( ) {
6769 if ( access . read ) {
6870 return self . _getRule ( id ) ;
6971 }
7072 return self . _getErrorPromise ( new RuleNotReadableError ( id ) ) ;
7173 } ,
72- edit : function ( body ) {
74+ edit : function ( body ) {
7375 if ( access . write ) {
7476 return self . _editRule ( id , body ) ;
7577 }
7678 return self . _getErrorPromise ( new RuleNotWritableError ( id ) ) ;
7779 } ,
78- delete : function ( ) {
80+ delete : function ( ) {
7981 return self . _deleteRule ( id ) ;
8082 }
8183 } ) ;
8284 } )
83- . catch ( function ( ) {
85+ . catch ( function ( ) {
8486 console . log ( 'catched' ) ;
8587 reject ( new RuleNotFoundError ( id ) ) ;
8688 } ) ;
@@ -98,9 +100,9 @@ export default class RulesController {
98100 _findRule ( id ) {
99101 let fileName = id + '.yaml' ;
100102 const self = this ;
101- return new Promise ( function ( resolve , reject ) {
103+ return new Promise ( function ( resolve , reject ) {
102104 self . _fileSystemController . fileExists ( joinPath ( self . rulesFolder , fileName ) )
103- . then ( function ( exists ) {
105+ . then ( function ( exists ) {
104106 if ( ! exists ) {
105107 reject ( ) ;
106108 } else {
@@ -112,7 +114,7 @@ export default class RulesController {
112114 } ) ;
113115 }
114116 } )
115- . catch ( function ( error ) {
117+ . catch ( function ( error ) {
116118 reject ( error ) ;
117119 } ) ;
118120 } ) ;
@@ -133,21 +135,21 @@ export default class RulesController {
133135 return this . _fileSystemController . deleteFile ( path ) ;
134136 }
135137
136- _downloadRules ( URL ) {
138+ _downloadRules ( URL ) {
137139 const options = {
138140 uri : URL ,
139141 strictSSL : false
140142 } ;
141143 const filename = path . basename ( URL ) ;
142-
144+
143145 return rq . get ( options )
144146 . then ( buffer => fs . outputFile ( filename , buffer )
145- . then ( ( ) => this . _untarFile ( this . rulesFolder , filename ) )
147+ . then ( ( ) => this . _untarFile ( this . rulesFolder , filename ) )
146148 . then ( ( ) => fs . remove ( filename ) ) ) ;
147149 }
148150
149151 _getErrorPromise ( error ) {
150- return new Promise ( function ( resolve , reject ) {
152+ return new Promise ( function ( resolve , reject ) {
151153 reject ( error ) ;
152154 } ) ;
153155 }
@@ -162,12 +164,12 @@ export default class RulesController {
162164 }
163165 }
164166
165- _untarFile ( path_to_extract , archive ) {
167+ _untarFile ( path_to_extract , archive ) {
166168 return tar . extract (
167169 {
168170 cwd : path_to_extract ,
169171 file : archive
170172 }
171173 ) ;
172174 }
173- }
175+ }
0 commit comments