Reuse adb client in certificate provider
Summary: Avoid making duplicate clients, and this one uses a more reliable creation method. Reviewed By: passy Differential Revision: D14241448 fbshipit-source-id: 95846a373335818758c8c4a282ed4db26b62d986
This commit is contained in:
committed by
Facebook Github Bot
parent
99bb43fe32
commit
6dc2215753
@@ -9,7 +9,6 @@ import type {Logger} from '../fb-interfaces/Logger';
|
|||||||
import {RecurringError} from './errors';
|
import {RecurringError} from './errors';
|
||||||
import {promisify} from 'util';
|
import {promisify} from 'util';
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const adb = require('adbkit-fb');
|
|
||||||
import {
|
import {
|
||||||
openssl,
|
openssl,
|
||||||
isInstalled as opensslInstalled,
|
isInstalled as opensslInstalled,
|
||||||
@@ -20,7 +19,8 @@ const tmpFile = promisify(tmp.file);
|
|||||||
const tmpDir = promisify(tmp.dir);
|
const tmpDir = promisify(tmp.dir);
|
||||||
import iosUtil from '../fb-stubs/iOSContainerUtility';
|
import iosUtil from '../fb-stubs/iOSContainerUtility';
|
||||||
import {reportPlatformFailures} from './metrics';
|
import {reportPlatformFailures} from './metrics';
|
||||||
import adbConfig from './adbConfig';
|
import {getAdbClient} from './adbClient';
|
||||||
|
const adb = require('adbkit-fb');
|
||||||
|
|
||||||
// Desktop file paths
|
// Desktop file paths
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
@@ -71,13 +71,13 @@ export type SecureServerConfig = {|
|
|||||||
*/
|
*/
|
||||||
export default class CertificateProvider {
|
export default class CertificateProvider {
|
||||||
logger: Logger;
|
logger: Logger;
|
||||||
adb: any;
|
adb: Promise<any>;
|
||||||
certificateSetup: Promise<void>;
|
certificateSetup: Promise<void>;
|
||||||
server: Server;
|
server: Server;
|
||||||
|
|
||||||
constructor(server: Server, logger: Logger) {
|
constructor(server: Server, logger: Logger) {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
this.adb = adb.createClient(adbConfig());
|
this.adb = getAdbClient();
|
||||||
this.certificateSetup = reportPlatformFailures(
|
this.certificateSetup = reportPlatformFailures(
|
||||||
this.ensureServerCertExists(),
|
this.ensureServerCertExists(),
|
||||||
'ensureServerCertExists',
|
'ensureServerCertExists',
|
||||||
@@ -260,7 +260,9 @@ export default class CertificateProvider {
|
|||||||
deviceCsrFilePath: string,
|
deviceCsrFilePath: string,
|
||||||
csr: string,
|
csr: string,
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
return this.adb.listDevices().then((devices: Array<{id: string}>) => {
|
return this.adb
|
||||||
|
.then(client => client.listDevices())
|
||||||
|
.then((devices: Array<{id: string}>) => {
|
||||||
const deviceMatchList = devices.map(device =>
|
const deviceMatchList = devices.map(device =>
|
||||||
this.androidDeviceHasMatchingCSR(
|
this.androidDeviceHasMatchingCSR(
|
||||||
deviceCsrFilePath,
|
deviceCsrFilePath,
|
||||||
@@ -417,7 +419,9 @@ export default class CertificateProvider {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return this.adb
|
return this.adb
|
||||||
.shell(deviceId, `echo '${command}' | run-as '${user}'`)
|
.then(client =>
|
||||||
|
client.shell(deviceId, `echo '${command}' | run-as '${user}'`),
|
||||||
|
)
|
||||||
.then(adb.util.readAll)
|
.then(adb.util.readAll)
|
||||||
.then(buffer => buffer.toString())
|
.then(buffer => buffer.toString())
|
||||||
.then(output => {
|
.then(output => {
|
||||||
|
|||||||
Reference in New Issue
Block a user