From 9633678de77fcd1728118998b896e60ec1261f90 Mon Sep 17 00:00:00 2001 From: rsercano Date: Tue, 27 Oct 2020 15:27:30 +0300 Subject: [PATCH] fix: tls certificate check on startup (#1510) --- lib/cli/command.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/cli/command.ts b/lib/cli/command.ts index b4787a486..1e2af8141 100644 --- a/lib/cli/command.ts +++ b/lib/cli/command.ts @@ -38,6 +38,18 @@ const loadXudConfig = async (argv: Arguments) => { } }; +const getTlsCert = (certPath: string) => { + try { + return fs.readFileSync(certPath); + } catch (err) { + if (err.code === 'ENOENT') { + throw `tls cert could not be found at ${certPath}, it may take several seconds to be created on xud's first run`; + } + + throw err; + } +}; + /** * A generic function to instantiate an XU client. * @param argv the command line arguments @@ -46,7 +58,7 @@ export const loadXudClient = async (argv: Arguments) => { await loadXudConfig(argv); const certPath = argv.tlscertpath || path.join(argv.xudir, 'tls.cert'); - const cert = fs.readFileSync(certPath); + const cert = getTlsCert(certPath); const credentials = grpc.credentials.createSsl(cert); return new XudClient(`${argv.rpchost}:${argv.rpcport}`, credentials); @@ -56,7 +68,7 @@ export const loadXudInitClient = async (argv: Arguments) => { await loadXudConfig(argv); const certPath = argv.tlscertpath || path.join(argv.xudir, 'tls.cert'); - const cert = fs.readFileSync(certPath); + const cert = getTlsCert(certPath); const credentials = grpc.credentials.createSsl(cert); return new XudInitClient(`${argv.rpchost}:${argv.rpcport}`, credentials);