22require ( '@codefresh-io/cf-telemetry/init' ) ;
33// ↓ Keep one blank line below to prevent automatic import reordering
44
5+ const { Logger } = require ( '@codefresh-io/cf-telemetry/logs' ) ;
56const { getServerAddress } = require ( './helpers' ) ;
67
8+ const logger = new Logger ( 'codefresh:containerLogger:addNewMask' ) ;
9+
710const exitCodes = {
811 success : 0 ,
912 error : 1 ,
@@ -18,7 +21,7 @@ const exitCodes = {
1821let exitWithError = true ;
1922const exitHandler = ( exitCode ) => {
2023 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` ) ;
2225 process . exitCode = exitCodes . unexpectedSuccess ;
2326 }
2427} ;
@@ -27,7 +30,7 @@ process.on('exit', exitHandler);
2730async function updateMasks ( secret ) {
2831 try {
2932 const serverAddress = await getServerAddress ( ) ;
30- console . debug ( `server address: ${ serverAddress } ` ) ;
33+ logger . debug ( `server address: ${ serverAddress } ` ) ;
3134 const url = new URL ( 'secrets' , serverAddress ) ;
3235
3336 // eslint-disable-next-line import/no-unresolved
@@ -38,23 +41,23 @@ async function updateMasks(secret) {
3841 } ) ;
3942
4043 if ( response . statusCode === 201 ) {
41- console . log ( `successfully updated masks with secret: ${ secret . key } ` ) ;
44+ logger . log ( `successfully updated masks with secret: ${ secret . key } ` ) ;
4245 exitWithError = false ;
4346 process . exit ( exitCodes . success ) ;
4447 } 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 } ` ) ;
4649 process . exit ( exitCodes . error ) ;
4750 }
4851 } 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 } ` ) ;
5053 process . exit ( exitCodes . error ) ;
5154 }
5255}
5356
5457if ( require . main === module ) {
5558 // first argument is the secret key second argument is the secret value
5659 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' ) ;
5861 process . exit ( exitCodes . missingArguments ) ;
5962 }
6063 const key = process . argv [ 2 ] ;
0 commit comments