mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-01-22 00:40:23 +00:00
Change websocket authentication from url token to getting token from payload (#1487)
* Change websocket authentication from url to message body * Add new message type * Validation checks * Remove flight and always send token in payload
This commit is contained in:
parent
1d6c0bbd1e
commit
cf0c51337f
@ -1,23 +1,23 @@
|
|||||||
import {
|
import {
|
||||||
actions,
|
|
||||||
AppState,
|
AppState,
|
||||||
castToSessionId,
|
|
||||||
ContentRef,
|
ContentRef,
|
||||||
createKernelRef,
|
|
||||||
JupyterHostRecordProps,
|
JupyterHostRecordProps,
|
||||||
|
ServerConfig as JupyterServerConfig,
|
||||||
KernelInfo,
|
KernelInfo,
|
||||||
KernelRef,
|
KernelRef,
|
||||||
RemoteKernelProps,
|
RemoteKernelProps,
|
||||||
|
actions,
|
||||||
|
castToSessionId,
|
||||||
|
createKernelRef,
|
||||||
selectors,
|
selectors,
|
||||||
ServerConfig as JupyterServerConfig,
|
|
||||||
} from "@nteract/core";
|
} from "@nteract/core";
|
||||||
import { Channels, childOf, createMessage, JupyterMessage, message, ofMessageType } from "@nteract/messaging";
|
import { Channels, childOf, createMessage, message, ofMessageType } from "@nteract/messaging";
|
||||||
import { defineConfigOption } from "@nteract/mythic-configuration";
|
import { defineConfigOption } from "@nteract/mythic-configuration";
|
||||||
import { RecordOf } from "immutable";
|
import { RecordOf } from "immutable";
|
||||||
import { Action, AnyAction } from "redux";
|
import { Action, AnyAction } from "redux";
|
||||||
import { ofType, StateObservable } from "redux-observable";
|
import { StateObservable, ofType } from "redux-observable";
|
||||||
import { kernels, sessions } from "rx-jupyter";
|
import { kernels, sessions } from "rx-jupyter";
|
||||||
import { concat, EMPTY, from, interval, merge, Observable, Observer, of, Subject, Subscriber, timer } from "rxjs";
|
import { EMPTY, Observable, Observer, Subject, Subscriber, concat, from, interval, merge, of, timer } from "rxjs";
|
||||||
import {
|
import {
|
||||||
catchError,
|
catchError,
|
||||||
concatMap,
|
concatMap,
|
||||||
@ -35,17 +35,17 @@ import {
|
|||||||
import { webSocket } from "rxjs/webSocket";
|
import { webSocket } from "rxjs/webSocket";
|
||||||
import * as Constants from "../../../Common/Constants";
|
import * as Constants from "../../../Common/Constants";
|
||||||
import { Areas } from "../../../Common/Constants";
|
import { Areas } from "../../../Common/Constants";
|
||||||
import { useTabs } from "../../../hooks/useTabs";
|
import { ActionModifiers, Action as TelemetryAction } from "../../../Shared/Telemetry/TelemetryConstants";
|
||||||
import { Action as TelemetryAction, ActionModifiers } from "../../../Shared/Telemetry/TelemetryConstants";
|
|
||||||
import * as TelemetryProcessor from "../../../Shared/Telemetry/TelemetryProcessor";
|
import * as TelemetryProcessor from "../../../Shared/Telemetry/TelemetryProcessor";
|
||||||
import { logConsoleError, logConsoleInfo } from "../../../Utils/NotificationConsoleUtils";
|
import { logConsoleError, logConsoleInfo } from "../../../Utils/NotificationConsoleUtils";
|
||||||
|
import { useTabs } from "../../../hooks/useTabs";
|
||||||
import { useDialog } from "../../Controls/Dialog";
|
import { useDialog } from "../../Controls/Dialog";
|
||||||
import * as FileSystemUtil from "../FileSystemUtil";
|
import * as FileSystemUtil from "../FileSystemUtil";
|
||||||
import * as cdbActions from "../NotebookComponent/actions";
|
import * as cdbActions from "../NotebookComponent/actions";
|
||||||
import { NotebookContentProviderType, NotebookUtil } from "../NotebookUtil";
|
import { NotebookContentProviderType, NotebookUtil } from "../NotebookUtil";
|
||||||
import * as CdbActions from "./actions";
|
import * as CdbActions from "./actions";
|
||||||
import * as TextFile from "./contents/file/text-file";
|
import * as TextFile from "./contents/file/text-file";
|
||||||
import { CdbAppState } from "./types";
|
import { CdbAppState, JupyterMessage } from "./types";
|
||||||
|
|
||||||
interface NotebookServiceConfig extends JupyterServerConfig {
|
interface NotebookServiceConfig extends JupyterServerConfig {
|
||||||
userPuid?: string;
|
userPuid?: string;
|
||||||
@ -106,10 +106,8 @@ const formWebSocketURL = (serverConfig: NotebookServiceConfig, kernelId: string,
|
|||||||
if (sessionId) {
|
if (sessionId) {
|
||||||
params.append("session_id", sessionId);
|
params.append("session_id", sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
const q = params.toString();
|
const q = params.toString();
|
||||||
const suffix = q !== "" ? `?${q}` : "";
|
const suffix = q !== "" ? `?${q}` : "";
|
||||||
|
|
||||||
const url = (serverConfig.endpoint.slice(0, -1) || "") + `api/kernels/${kernelId}/channels${suffix}`;
|
const url = (serverConfig.endpoint.slice(0, -1) || "") + `api/kernels/${kernelId}/channels${suffix}`;
|
||||||
|
|
||||||
return url.replace(/^http(s)?/, "ws$1");
|
return url.replace(/^http(s)?/, "ws$1");
|
||||||
@ -241,10 +239,10 @@ const connect = (serverConfig: NotebookServiceConfig, kernelID: string, sessionI
|
|||||||
...message,
|
...message,
|
||||||
header: {
|
header: {
|
||||||
session: sessionID,
|
session: sessionID,
|
||||||
|
token: serverConfig.token,
|
||||||
...message.header,
|
...message.header,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
wsSubject.next(sessionizedMessage);
|
wsSubject.next(sessionizedMessage);
|
||||||
} else {
|
} else {
|
||||||
console.error("Message must be an object, the app sent", message);
|
console.error("Message must be an object, the app sent", message);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { CellId } from "@nteract/commutable";
|
import { CellId } from "@nteract/commutable";
|
||||||
import { AppState } from "@nteract/core";
|
import { AppState } from "@nteract/core";
|
||||||
|
import { MessageType } from "@nteract/messaging";
|
||||||
import * as Immutable from "immutable";
|
import * as Immutable from "immutable";
|
||||||
import { Notebook } from "../../../Common/Constants";
|
import { Notebook } from "../../../Common/Constants";
|
||||||
|
|
||||||
@ -53,3 +54,26 @@ export const makeCdbRecord = Immutable.Record<CdbRecordProps>({
|
|||||||
pendingSnapshotRequest: undefined,
|
pendingSnapshotRequest: undefined,
|
||||||
notebookSnapshotError: undefined,
|
notebookSnapshotError: undefined,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export interface JupyterMessage<MT extends MessageType = MessageType, C = any> {
|
||||||
|
header: JupyterMessageHeader<MT>;
|
||||||
|
parent_header:
|
||||||
|
| JupyterMessageHeader<any>
|
||||||
|
| {
|
||||||
|
msg_id?: string;
|
||||||
|
};
|
||||||
|
metadata: object;
|
||||||
|
content: C;
|
||||||
|
channel: string;
|
||||||
|
buffers?: Uint8Array | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface JupyterMessageHeader<MT extends MessageType = MessageType> {
|
||||||
|
msg_id: string;
|
||||||
|
username: string;
|
||||||
|
date: string;
|
||||||
|
msg_type: MT;
|
||||||
|
version: string;
|
||||||
|
session: string;
|
||||||
|
token: string;
|
||||||
|
}
|
||||||
|
@ -47,6 +47,10 @@ export class JupyterLabAppFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async createTerminalApp(serverSettings: ServerConnection.ISettings): Promise<ITerminalConnection | undefined> {
|
public async createTerminalApp(serverSettings: ServerConnection.ISettings): Promise<ITerminalConnection | undefined> {
|
||||||
|
//Need to add this after we remove passing token through url
|
||||||
|
//const configurationSettings: Partial<ServerConnection.ISettings> = serverSettings;
|
||||||
|
//(configurationSettings.appendToken as boolean) = false;
|
||||||
|
//serverSettings = ServerConnection.makeSettings(configurationSettings);
|
||||||
const manager = new TerminalManager({
|
const manager = new TerminalManager({
|
||||||
serverSettings: serverSettings,
|
serverSettings: serverSettings,
|
||||||
});
|
});
|
||||||
@ -64,6 +68,11 @@ export class JupyterLabAppFactory {
|
|||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
|
let internalSend = session.send;
|
||||||
|
session.send = (message: IMessage) => {
|
||||||
|
message?.content?.push(serverSettings?.token);
|
||||||
|
internalSend.call(session, message);
|
||||||
|
};
|
||||||
const term = new Terminal(session, { theme: "dark", shutdownOnClose: true });
|
const term = new Terminal(session, { theme: "dark", shutdownOnClose: true });
|
||||||
|
|
||||||
if (!term) {
|
if (!term) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user