Session Id moved to server config

Summary:
Session Id should be shared between client and server, but it was defined deep in the client (redux store).

The proposed solution presented below is to move the session id to the server configuration. By doing this, it becomes available to both server and client VERY early in the application life-cycle for both Electron and non-Electron builds.

Reviewed By: LukeDefeo

Differential Revision: D48520367

fbshipit-source-id: ca959b27ab18b1a2e4cd2fac1d28545664f1b514
This commit is contained in:
Lorenzo Blasa
2023-08-22 05:16:20 -07:00
committed by Facebook GitHub Bot
parent 82e9277e64
commit 17cfa0e571
6 changed files with 9 additions and 4 deletions

View File

@@ -39,13 +39,13 @@ import {
Logger, Logger,
parseEnvironmentVariables, parseEnvironmentVariables,
setLoggerInstance, setLoggerInstance,
uuid,
wrapRequire, wrapRequire,
} from 'flipper-common'; } from 'flipper-common';
import constants from './fb-stubs/constants'; import constants from './fb-stubs/constants';
import {initializeElectron} from './electron/initializeElectron'; import {initializeElectron} from './electron/initializeElectron';
import path from 'path'; import path from 'path';
import fs from 'fs-extra'; import fs from 'fs-extra';
import os from 'os';
import {ElectronIpcClientRenderer} from './electronIpc'; import {ElectronIpcClientRenderer} from './electronIpc';
import {KeytarModule} from 'flipper-server-core/src/utils/keytar'; import {KeytarModule} from 'flipper-server-core/src/utils/keytar';
import {initCompanionEnv} from 'flipper-server-companion'; import {initCompanionEnv} from 'flipper-server-companion';
@@ -167,6 +167,7 @@ async function getFlipperServer(
const getEmbeddedServer = async () => { const getEmbeddedServer = async () => {
const server = new FlipperServerImpl( const server = new FlipperServerImpl(
{ {
sessionId: uuid(),
environmentInfo, environmentInfo,
env: parseEnvironmentVariables(env), env: parseEnvironmentVariables(env),
gatekeepers: gatekeepers, gatekeepers: gatekeepers,

View File

@@ -524,6 +524,7 @@ export type FlipperServerConfig = {
validWebSocketOrigins: string[]; validWebSocketOrigins: string[];
environmentInfo: EnvironmentInfo; environmentInfo: EnvironmentInfo;
type?: FlipperServerType; type?: FlipperServerType;
sessionId: string;
}; };
export interface FlipperServerExecOptions { export interface FlipperServerExecOptions {

View File

@@ -23,6 +23,7 @@ import {
DeviceDescription, DeviceDescription,
setLoggerInstance, setLoggerInstance,
parseEnvironmentVariables, parseEnvironmentVariables,
uuid,
} from 'flipper-common'; } from 'flipper-common';
import path from 'path'; import path from 'path';
import {stdout} from 'process'; import {stdout} from 'process';
@@ -94,6 +95,7 @@ async function start(deviceQuery: string, appName: string, pluginId: string) {
]); ]);
const server = new FlipperServerImpl( const server = new FlipperServerImpl(
{ {
sessionId: uuid(),
environmentInfo, environmentInfo,
env: parseEnvironmentVariables(process.env), env: parseEnvironmentVariables(process.env),
gatekeepers: {}, gatekeepers: {},

View File

@@ -13,6 +13,7 @@ import {
getLogger, getLogger,
FlipperServerType, FlipperServerType,
EnvironmentInfo, EnvironmentInfo,
uuid,
} from 'flipper-common'; } from 'flipper-common';
import path from 'path'; import path from 'path';
import fs from 'fs-extra'; import fs from 'fs-extra';
@@ -58,6 +59,7 @@ export async function startFlipperServer(
]); ]);
return new FlipperServerImpl( return new FlipperServerImpl(
{ {
sessionId: uuid(),
environmentInfo, environmentInfo,
env: parseEnvironmentVariables(process.env), env: parseEnvironmentVariables(process.env),
gatekeepers: getGatekeepers(environmentInfo.os.unixname), gatekeepers: getGatekeepers(environmentInfo.os.unixname),

View File

@@ -7,7 +7,6 @@
* @format * @format
*/ */
import {v1 as uuidv1} from 'uuid';
import {getRenderHostInstance} from 'flipper-frontend-core'; import {getRenderHostInstance} from 'flipper-frontend-core';
import {Actions} from './'; import {Actions} from './';
@@ -44,7 +43,6 @@ export type State = {
rightSidebarAvailable: boolean; rightSidebarAvailable: boolean;
windowIsFocused: boolean; windowIsFocused: boolean;
share: ShareType | null; share: ShareType | null;
sessionId: string | null;
launcherMsg: LauncherMsg; launcherMsg: LauncherMsg;
statusMessages: Array<string>; statusMessages: Array<string>;
}; };
@@ -95,7 +93,6 @@ export const initialState: () => State = () => ({
windowIsFocused: getRenderHostInstance().hasFocus(), windowIsFocused: getRenderHostInstance().hasFocus(),
activeSheet: null, activeSheet: null,
share: null, share: null,
sessionId: uuidv1(),
launcherMsg: { launcherMsg: {
severity: 'warning', severity: 'warning',
message: '', message: '',

View File

@@ -22,6 +22,7 @@ import {
ReleaseChannel, ReleaseChannel,
Tristate, Tristate,
parseEnvironmentVariables, parseEnvironmentVariables,
uuid,
} from 'flipper-common'; } from 'flipper-common';
// Only import the type! // Only import the type!
@@ -131,6 +132,7 @@ Object.defineProperty(global, 'matchMedia', {
function createStubRenderHost(): RenderHost { function createStubRenderHost(): RenderHost {
const rootPath = resolve(__dirname, '..'); const rootPath = resolve(__dirname, '..');
const stubConfig: FlipperServerConfig = { const stubConfig: FlipperServerConfig = {
sessionId: uuid(),
environmentInfo: { environmentInfo: {
processId: process.pid, processId: process.pid,
appVersion: '0.0.0', appVersion: '0.0.0',