From dcfa173fb0b59713b575364044631b3e653abdd5 Mon Sep 17 00:00:00 2001 From: Praphull Purohit Date: Tue, 19 Mar 2024 10:46:20 +0100 Subject: [PATCH] Use readFile from fs/promises Signed-off-by: Praphull Purohit --- .../src/ldap/client.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/plugins/catalog-backend-module-ldap/src/ldap/client.ts b/plugins/catalog-backend-module-ldap/src/ldap/client.ts index 47e8b1f397..56cc18e2de 100644 --- a/plugins/catalog-backend-module-ldap/src/ldap/client.ts +++ b/plugins/catalog-backend-module-ldap/src/ldap/client.ts @@ -15,7 +15,7 @@ */ import { ForwardedError, stringifyError } from '@backstage/errors'; -import { readFileSync } from 'fs'; +import { readFile } from 'fs/promises'; import ldap, { Client, SearchEntry, SearchOptions } from 'ldapjs'; import { cloneDeep } from 'lodash'; import tlsLib from 'tls'; @@ -46,13 +46,15 @@ export class LdapClient { bind?: BindConfig, tls?: TLSConfig, ): Promise { - const secureContext = - tls && tls.certs && tls.keys - ? tlsLib.createSecureContext({ - cert: readFileSync(tls.certs).toString(), - key: readFileSync(tls.keys).toString(), - }) - : undefined; + let secureContext; + if (tls && tls.certs && tls.keys) { + const cert = await readFile(tls.certs).then(f => f.toString()); + const key = await readFile(tls.keys).then(f => f.toString()); + secureContext = tlsLib.createSecureContext({ + cert: cert, + key: key, + }); + } const client = ldap.createClient({ url: target,