Adds restarting vcore mongo shell if user enters wrong password (#1675)
* Adds restarting vcore mongo shell if user enters wrong password * Deleted unnecessary comment
This commit is contained in:
parent
f69cd4c495
commit
15e35eaa82
|
@ -10,9 +10,13 @@ import { userContext } from "UserContext";
|
||||||
export class JupyterLabAppFactory {
|
export class JupyterLabAppFactory {
|
||||||
private isShellStarted: boolean | undefined;
|
private isShellStarted: boolean | undefined;
|
||||||
private checkShellStarted: ((content: string | undefined) => void) | undefined;
|
private checkShellStarted: ((content: string | undefined) => void) | undefined;
|
||||||
private onShellExited: () => void;
|
private onShellExited: (restartShell: boolean) => void;
|
||||||
|
private restartShell: boolean;
|
||||||
|
|
||||||
private isShellExited(content: string | undefined) {
|
private isShellExited(content: string | undefined) {
|
||||||
|
if (userContext.apiType === "VCoreMongo" && content?.includes("MongoServerError: Invalid key")) {
|
||||||
|
this.restartShell = true;
|
||||||
|
}
|
||||||
return content?.includes("cosmosuser@");
|
return content?.includes("cosmosuser@");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,10 +36,11 @@ export class JupyterLabAppFactory {
|
||||||
this.isShellStarted = content?.includes("Enter password");
|
this.isShellStarted = content?.includes("Enter password");
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(closeTab: () => void) {
|
constructor(closeTab: (restartShell: boolean) => void) {
|
||||||
this.onShellExited = closeTab;
|
this.onShellExited = closeTab;
|
||||||
this.isShellStarted = false;
|
this.isShellStarted = false;
|
||||||
this.checkShellStarted = undefined;
|
this.checkShellStarted = undefined;
|
||||||
|
this.restartShell = false;
|
||||||
|
|
||||||
switch (userContext.apiType) {
|
switch (userContext.apiType) {
|
||||||
case "Mongo":
|
case "Mongo":
|
||||||
|
@ -69,7 +74,7 @@ export class JupyterLabAppFactory {
|
||||||
if (!this.isShellStarted) {
|
if (!this.isShellStarted) {
|
||||||
this.checkShellStarted(content);
|
this.checkShellStarted(content);
|
||||||
} else if (this.isShellExited(content)) {
|
} else if (this.isShellExited(content)) {
|
||||||
this.onShellExited();
|
this.onShellExited(this.restartShell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
|
|
|
@ -11,6 +11,8 @@ import { JupyterLabAppFactory } from "./JupyterLabAppFactory";
|
||||||
import { TerminalProps } from "./TerminalProps";
|
import { TerminalProps } from "./TerminalProps";
|
||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
|
||||||
|
let session: ITerminalConnection | undefined;
|
||||||
|
|
||||||
const createServerSettings = (props: TerminalProps): ServerConnection.ISettings => {
|
const createServerSettings = (props: TerminalProps): ServerConnection.ISettings => {
|
||||||
let body: BodyInit | undefined;
|
let body: BodyInit | undefined;
|
||||||
let headers: HeadersInit | undefined;
|
let headers: HeadersInit | undefined;
|
||||||
|
@ -49,7 +51,7 @@ const createServerSettings = (props: TerminalProps): ServerConnection.ISettings
|
||||||
return ServerConnection.makeSettings(options);
|
return ServerConnection.makeSettings(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
const initTerminal = async (props: TerminalProps): Promise<ITerminalConnection | undefined> => {
|
const initTerminal = async (props: TerminalProps): Promise<void> => {
|
||||||
// Initialize userContext (only properties which are needed by TelemetryProcessor)
|
// Initialize userContext (only properties which are needed by TelemetryProcessor)
|
||||||
updateUserContext({
|
updateUserContext({
|
||||||
subscriptionId: props.subscriptionId,
|
subscriptionId: props.subscriptionId,
|
||||||
|
@ -59,28 +61,37 @@ const initTerminal = async (props: TerminalProps): Promise<ITerminalConnection |
|
||||||
});
|
});
|
||||||
|
|
||||||
const serverSettings = createServerSettings(props);
|
const serverSettings = createServerSettings(props);
|
||||||
|
|
||||||
|
createTerminalApp(props, serverSettings);
|
||||||
|
};
|
||||||
|
|
||||||
|
const createTerminalApp = async (props: TerminalProps, serverSettings: ServerConnection.ISettings) => {
|
||||||
const data = { baseUrl: serverSettings.baseUrl };
|
const data = { baseUrl: serverSettings.baseUrl };
|
||||||
const startTime = TelemetryProcessor.traceStart(Action.OpenTerminal, data);
|
const startTime = TelemetryProcessor.traceStart(Action.OpenTerminal, data);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const session = await new JupyterLabAppFactory(() => closeTab(props.tabId)).createTerminalApp(serverSettings);
|
session = await new JupyterLabAppFactory((restartShell: boolean) =>
|
||||||
|
closeTab(props, serverSettings, restartShell),
|
||||||
|
).createTerminalApp(serverSettings);
|
||||||
TelemetryProcessor.traceSuccess(Action.OpenTerminal, data, startTime);
|
TelemetryProcessor.traceSuccess(Action.OpenTerminal, data, startTime);
|
||||||
return session;
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
TelemetryProcessor.traceFailure(Action.OpenTerminal, data, startTime);
|
TelemetryProcessor.traceFailure(Action.OpenTerminal, data, startTime);
|
||||||
return undefined;
|
session = undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const closeTab = (tabId: string): void => {
|
const closeTab = (props: TerminalProps, serverSettings: ServerConnection.ISettings, restartShell: boolean): void => {
|
||||||
window.parent.postMessage(
|
if (restartShell) {
|
||||||
{ type: MessageTypes.CloseTab, data: { tabId: tabId }, signature: "pcIframe" },
|
createTerminalApp(props, serverSettings);
|
||||||
window.document.referrer,
|
} else {
|
||||||
);
|
window.parent.postMessage(
|
||||||
|
{ type: MessageTypes.CloseTab, data: { tabId: props.tabId }, signature: "pcIframe" },
|
||||||
|
window.document.referrer,
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const main = async (): Promise<void> => {
|
const main = async (): Promise<void> => {
|
||||||
let session: ITerminalConnection | undefined;
|
|
||||||
postRobot.on(
|
postRobot.on(
|
||||||
"props",
|
"props",
|
||||||
{
|
{
|
||||||
|
@ -91,7 +102,7 @@ const main = async (): Promise<void> => {
|
||||||
// Typescript definition for event is wrong. So read props by casting to <any>
|
// Typescript definition for event is wrong. So read props by casting to <any>
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
const props = (event as any).data as TerminalProps;
|
const props = (event as any).data as TerminalProps;
|
||||||
session = await initTerminal(props);
|
await initTerminal(props);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue