2
2
require ( '@codefresh-io/cf-telemetry/init' ) ;
3
3
// ↓ Keep one blank line below to prevent automatic import reordering
4
4
5
+ const { Logger } = require ( '@codefresh-io/cf-telemetry/logs' ) ;
5
6
const { getServerAddress } = require ( './helpers' ) ;
6
7
8
+ const logger = new Logger ( 'codefresh:containerLogger:addNewMask' ) ;
9
+
7
10
const exitCodes = {
8
11
success : 0 ,
9
12
error : 1 ,
@@ -18,7 +21,7 @@ const exitCodes = {
18
21
let exitWithError = true ;
19
22
const exitHandler = ( exitCode ) => {
20
23
if ( ( ! exitCode || ! process . exitCode ) && exitWithError ) {
21
- console . warn ( `Unexpected exit with code 0. Exiting with ${ exitCodes . unexpectedSuccess } instead` ) ;
24
+ logger . warn ( `Unexpected exit with code 0. Exiting with ${ exitCodes . unexpectedSuccess } instead` ) ;
22
25
process . exitCode = exitCodes . unexpectedSuccess ;
23
26
}
24
27
} ;
@@ -27,7 +30,7 @@ process.on('exit', exitHandler);
27
30
async function updateMasks ( secret ) {
28
31
try {
29
32
const serverAddress = await getServerAddress ( ) ;
30
- console . debug ( `server address: ${ serverAddress } ` ) ;
33
+ logger . debug ( `server address: ${ serverAddress } ` ) ;
31
34
const url = new URL ( 'secrets' , serverAddress ) ;
32
35
33
36
// eslint-disable-next-line import/no-unresolved
@@ -38,23 +41,23 @@ async function updateMasks(secret) {
38
41
} ) ;
39
42
40
43
if ( response . statusCode === 201 ) {
41
- console . log ( `successfully updated masks with secret: ${ secret . key } ` ) ;
44
+ logger . log ( `successfully updated masks with secret: ${ secret . key } ` ) ;
42
45
exitWithError = false ;
43
46
process . exit ( exitCodes . success ) ;
44
47
} else {
45
- console . error ( `could not create mask for secret: ${ secret . key } . Server responded with: ${ response . statusCode } \n\n${ response . body } ` ) ;
48
+ logger . error ( `could not create mask for secret: ${ secret . key } . Server responded with: ${ response . statusCode } \n\n${ response . body } ` ) ;
46
49
process . exit ( exitCodes . error ) ;
47
50
}
48
51
} catch ( error ) {
49
- console . error ( `could not create mask for secret: ${ secret . key } . Error: ${ error } ` ) ;
52
+ logger . error ( `could not create mask for secret: ${ secret . key } . Error: ${ error } ` ) ;
50
53
process . exit ( exitCodes . error ) ;
51
54
}
52
55
}
53
56
54
57
if ( require . main === module ) {
55
58
// first argument is the secret key second argument is the secret value
56
59
if ( process . argv . length < 4 ) {
57
- console . log ( 'not enough arguments, need secret key and secret value' ) ;
60
+ logger . log ( 'not enough arguments, need secret key and secret value' ) ;
58
61
process . exit ( exitCodes . missingArguments ) ;
59
62
}
60
63
const key = process . argv [ 2 ] ;
0 commit comments