Make ClientQuery available to certificate provider
Summary: CertificateProvider is intrinsically related to a client query, make it available to it. This becomes the optional 'context' of shell executions. When these are recorded, the context is provider to the recorder which can then link an ongoing certificate exchange process with the success or failure of said command. Reviewed By: antonk52 Differential Revision: D47295894 fbshipit-source-id: 9469d18bda02793d71a6a8b29c93f4af1db23569
This commit is contained in:
committed by
Facebook GitHub Bot
parent
60b3ff99ce
commit
e20d723ac0
@@ -7,7 +7,12 @@
|
||||
* @format
|
||||
*/
|
||||
|
||||
import {ClientQuery} from 'flipper-common';
|
||||
import {
|
||||
ClientQuery,
|
||||
ConnectionRecordEntry,
|
||||
CommandRecordEntry,
|
||||
} from 'flipper-common';
|
||||
import {FlipperServerImpl} from './FlipperServerImpl';
|
||||
|
||||
type CommandEventPayload = {
|
||||
cmd: string;
|
||||
@@ -16,6 +21,7 @@ type CommandEventPayload = {
|
||||
stdout?: string;
|
||||
stderr?: string;
|
||||
troubleshoot?: string;
|
||||
context?: any;
|
||||
};
|
||||
|
||||
type ConnectionRecorderEvents = {
|
||||
@@ -23,11 +29,29 @@ type ConnectionRecorderEvents = {
|
||||
};
|
||||
|
||||
class Recorder {
|
||||
private flipperServer: FlipperServerImpl | undefined;
|
||||
|
||||
private handler_ = {
|
||||
cmd: (_payload: CommandEventPayload) => {
|
||||
// The output from logging the whole command can be quite
|
||||
// verbose. So, disable it as is.
|
||||
// this.rawLog(_payload);
|
||||
cmd: (payload: CommandEventPayload) => {
|
||||
if (this.flipperServer && payload.context) {
|
||||
const clientQuery = payload.context as ClientQuery;
|
||||
const entry: CommandRecordEntry = {
|
||||
time: new Date(),
|
||||
type: 'cmd',
|
||||
device: clientQuery.device,
|
||||
app: clientQuery.app,
|
||||
message: payload.cmd,
|
||||
medium: clientQuery.medium,
|
||||
cmd: payload.cmd,
|
||||
description: payload.description,
|
||||
success: payload.success,
|
||||
stdout: payload.stdout,
|
||||
stderr: payload.stderr,
|
||||
troubleshoot: payload.troubleshoot,
|
||||
};
|
||||
|
||||
this.flipperServer.emit('connectivity-troubleshoot-cmd', entry);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -42,11 +66,20 @@ class Recorder {
|
||||
handler(payload);
|
||||
}
|
||||
|
||||
rawLog(...args: any[]) {
|
||||
console.log('[conn]', ...args);
|
||||
}
|
||||
log(clientQuery: ClientQuery, ...args: any[]) {
|
||||
console.log('[conn]', ...args);
|
||||
if (this.flipperServer) {
|
||||
const entry: ConnectionRecordEntry = {
|
||||
time: new Date(),
|
||||
type: 'info',
|
||||
device: clientQuery.device,
|
||||
app: clientQuery.app,
|
||||
message: args.join(' '),
|
||||
medium: clientQuery.medium,
|
||||
};
|
||||
|
||||
this.flipperServer.emit('connectivity-troubleshoot-log', entry);
|
||||
}
|
||||
}
|
||||
rawError(...args: any[]) {
|
||||
console.error('[conn]', ...args);
|
||||
@@ -54,6 +87,10 @@ class Recorder {
|
||||
error(clientQuery: ClientQuery, ...args: any[]) {
|
||||
console.error('[conn]', ...args);
|
||||
}
|
||||
|
||||
enable(flipperServer: FlipperServerImpl) {
|
||||
this.flipperServer = flipperServer;
|
||||
}
|
||||
}
|
||||
|
||||
const recorder = new Recorder();
|
||||
|
||||
Reference in New Issue
Block a user