Generate auth token
Summary: Generate auth token on whenever we load the secure server config, and add more logs. Reviewed By: antonk52 Differential Revision: D49272857 fbshipit-source-id: 1e549a8bfd7926e9a44b9480432e92ee3c0162b2
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1cf7160b2c
commit
8062e2c9e5
@@ -82,6 +82,7 @@ export const loadSecureServerConfig = async (): Promise<SecureServerConfig> => {
|
|||||||
|
|
||||||
await ensureOpenSSLIsAvailable();
|
await ensureOpenSSLIsAvailable();
|
||||||
await certificateSetup();
|
await certificateSetup();
|
||||||
|
await generateAuthToken();
|
||||||
|
|
||||||
const [key, cert, ca] = await Promise.all([
|
const [key, cert, ca] = await Promise.all([
|
||||||
fs.readFile(serverKey),
|
fs.readFile(serverKey),
|
||||||
@@ -171,6 +172,7 @@ const ensureServerCertExists = async (): Promise<void> => {
|
|||||||
await checkCertIsValid(serverCert);
|
await checkCertIsValid(serverCert);
|
||||||
console.info('Checking certificate was issued by current CA');
|
console.info('Checking certificate was issued by current CA');
|
||||||
await verifyServerCertWasIssuedByCA();
|
await verifyServerCertWasIssuedByCA();
|
||||||
|
console.info('Current certificates are valid');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('Not all certificates are valid, generating new ones', e);
|
console.warn('Not all certificates are valid, generating new ones', e);
|
||||||
await generateServerCertificate();
|
await generateServerCertificate();
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import {initCompanionEnv} from 'flipper-server-companion';
|
|||||||
import {
|
import {
|
||||||
checkPortInUse,
|
checkPortInUse,
|
||||||
getEnvironmentInfo,
|
getEnvironmentInfo,
|
||||||
hasAuthToken,
|
|
||||||
startFlipperServer,
|
startFlipperServer,
|
||||||
startServer,
|
startServer,
|
||||||
tracker,
|
tracker,
|
||||||
@@ -107,7 +106,6 @@ const staticPath = path.join(rootPath, 'static');
|
|||||||
|
|
||||||
async function connectToRunningServer(url: URL) {
|
async function connectToRunningServer(url: URL) {
|
||||||
console.info(`[flipper-server] Obtain connection to existing server.`);
|
console.info(`[flipper-server] Obtain connection to existing server.`);
|
||||||
console.info(`[flipper-server] URL: ${url}`);
|
|
||||||
const options = {
|
const options = {
|
||||||
WebSocket: class WSWithUnixDomainSocketSupport extends WS {
|
WebSocket: class WSWithUnixDomainSocketSupport extends WS {
|
||||||
constructor(url: string, protocols: string | string[]) {
|
constructor(url: string, protocols: string | string[]) {
|
||||||
@@ -128,13 +126,11 @@ async function connectToRunningServer(url: URL) {
|
|||||||
async function shutdown() {
|
async function shutdown() {
|
||||||
console.info('[flipper-server] Attempt to shutdown.');
|
console.info('[flipper-server] Attempt to shutdown.');
|
||||||
|
|
||||||
let token: string | undefined;
|
const token = await getAuthToken();
|
||||||
if (await hasAuthToken()) {
|
|
||||||
token = await getAuthToken();
|
|
||||||
}
|
|
||||||
|
|
||||||
const searchParams = new URLSearchParams(token ? {token} : {});
|
const searchParams = new URLSearchParams(token ? {token} : {});
|
||||||
const url = new URL(`ws://localhost:${argv.port}?${searchParams}`);
|
const url = new URL(`ws://localhost:${argv.port}?${searchParams}`);
|
||||||
|
|
||||||
const server = await connectToRunningServer(url);
|
const server = await connectToRunningServer(url);
|
||||||
await server.exec('shutdown').catch(() => {
|
await server.exec('shutdown').catch(() => {
|
||||||
/** shutdown will ultimately make this request fail, ignore error. */
|
/** shutdown will ultimately make this request fail, ignore error. */
|
||||||
@@ -307,6 +303,13 @@ async function start() {
|
|||||||
|
|
||||||
async function launch() {
|
async function launch() {
|
||||||
console.info('[flipper-server] Launch UI');
|
console.info('[flipper-server] Launch UI');
|
||||||
|
|
||||||
|
if (!argv.open) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const openInBrowser = async () => {
|
||||||
|
console.info('[flipper-server] Open in browser');
|
||||||
const token = await getAuthToken();
|
const token = await getAuthToken();
|
||||||
|
|
||||||
console.info('[flipper-server] Token is available: ' + token !== undefined);
|
console.info('[flipper-server] Token is available: ' + token !== undefined);
|
||||||
@@ -314,24 +317,21 @@ async function launch() {
|
|||||||
const searchParams = new URLSearchParams({token: token ?? ''});
|
const searchParams = new URLSearchParams({token: token ?? ''});
|
||||||
const url = new URL(`http://localhost:${argv.port}?${searchParams}`);
|
const url = new URL(`http://localhost:${argv.port}?${searchParams}`);
|
||||||
|
|
||||||
if (!argv.open) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const openInBrowser = () => {
|
|
||||||
open(url.toString(), {app: {name: open.apps.chrome}});
|
open(url.toString(), {app: {name: open.apps.chrome}});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (argv.bundler) {
|
if (argv.bundler) {
|
||||||
openInBrowser();
|
await openInBrowser();
|
||||||
} else {
|
} else {
|
||||||
const path = await findInstallation();
|
const path = await findInstallation();
|
||||||
if (path) {
|
if (path) {
|
||||||
open(path);
|
open(path);
|
||||||
} else {
|
} else {
|
||||||
openInBrowser();
|
await openInBrowser();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.info('[flipper-server] Launch UI completed');
|
||||||
}
|
}
|
||||||
|
|
||||||
process.on('uncaughtException', (error) => {
|
process.on('uncaughtException', (error) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user