15
15
*
16
16
*/
17
17
18
- import * as fs from 'fs/promises ' ;
18
+ import * as fs from 'fs' ;
19
19
import * as logging from './logging' ;
20
20
import { LogVerbosity } from './constants' ;
21
+ import { promisify } from 'util' ;
21
22
22
23
const TRACER_NAME = 'certificate_provider' ;
23
24
@@ -56,6 +57,8 @@ export interface FileWatcherCertificateProviderConfig {
56
57
refreshIntervalMs : number ;
57
58
}
58
59
60
+ const readFilePromise = promisify ( fs . readFile ) ;
61
+
59
62
export class FileWatcherCertificateProvider implements CertificateProvider {
60
63
private refreshTimer : NodeJS . Timeout | null = null ;
61
64
private fileResultPromise : Promise < [ PromiseSettledResult < Buffer > , PromiseSettledResult < Buffer > , PromiseSettledResult < Buffer > ] > | null = null ;
@@ -82,9 +85,9 @@ export class FileWatcherCertificateProvider implements CertificateProvider {
82
85
return ;
83
86
}
84
87
this . fileResultPromise = Promise . allSettled ( [
85
- this . config . certificateFile ? fs . readFile ( this . config . certificateFile ) : Promise . reject < Buffer > ( ) ,
86
- this . config . privateKeyFile ? fs . readFile ( this . config . privateKeyFile ) : Promise . reject < Buffer > ( ) ,
87
- this . config . caCertificateFile ? fs . readFile ( this . config . caCertificateFile ) : Promise . reject < Buffer > ( )
88
+ this . config . certificateFile ? readFilePromise ( this . config . certificateFile ) : Promise . reject < Buffer > ( ) ,
89
+ this . config . privateKeyFile ? readFilePromise ( this . config . privateKeyFile ) : Promise . reject < Buffer > ( ) ,
90
+ this . config . caCertificateFile ? readFilePromise ( this . config . caCertificateFile ) : Promise . reject < Buffer > ( )
88
91
] ) ;
89
92
this . fileResultPromise . then ( ( [ certificateResult , privateKeyResult , caCertificateResult ] ) => {
90
93
if ( ! this . refreshTimer ) {
0 commit comments