Make openssl check async

Summary:
This was the last eslint warning for `flipper-server-core` and the only call-site
was async already.

Reviewed By: mweststrate

Differential Revision: D32026626

fbshipit-source-id: 0d6f06086c33707b26f58f668ad533daca9de7dd
This commit is contained in:
Pascal Hartig
2021-11-03 05:38:56 -07:00
committed by Facebook GitHub Bot
parent 72ce759e61
commit dc6dd47a23
2 changed files with 11 additions and 6 deletions

View File

@@ -173,7 +173,7 @@ export default class CertificateProvider {
if (csr === '') { if (csr === '') {
return Promise.reject(new Error(`Received empty CSR from ${os} device`)); return Promise.reject(new Error(`Received empty CSR from ${os} device`));
} }
this.ensureOpenSSLIsAvailable(); await this.ensureOpenSSLIsAvailable();
const rootFolder = await promisify(tmp.dir)(); const rootFolder = await promisify(tmp.dir)();
const certFolder = rootFolder + '/FlipperCerts/'; const certFolder = rootFolder + '/FlipperCerts/';
const certsZipPath = rootFolder + '/certs.zip'; const certsZipPath = rootFolder + '/certs.zip';
@@ -249,8 +249,8 @@ export default class CertificateProvider {
return Promise.resolve('unknown'); return Promise.resolve('unknown');
} }
private ensureOpenSSLIsAvailable(): void { private async ensureOpenSSLIsAvailable(): Promise<void> {
if (!opensslInstalled()) { if (!(await opensslInstalled())) {
const e = Error( const e = Error(
"It looks like you don't have OpenSSL installed. Please install it to continue.", "It looks like you don't have OpenSSL installed. Please install it to continue.",
); );

View File

@@ -8,7 +8,7 @@
*/ */
import {exec as opensslWithCallback, Action} from 'openssl-wrapper'; import {exec as opensslWithCallback, Action} from 'openssl-wrapper';
import child_process from 'child_process'; import {spawn} from 'promisify-child-process';
export function openssl(action: Action, options: {}): Promise<string> { export function openssl(action: Action, options: {}): Promise<string> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@@ -22,6 +22,11 @@ export function openssl(action: Action, options: {}): Promise<string> {
}); });
} }
export function isInstalled(): boolean { export async function isInstalled(): Promise<boolean> {
return !child_process.spawnSync('openssl', ['version']).error; try {
const result = await spawn('openssl', ['version']);
return result.code === 0;
} catch (_e) {
return false;
}
} }