diff --git a/src/Contracts/DataModels.ts b/src/Contracts/DataModels.ts index 584f77e77..acf58baaf 100644 --- a/src/Contracts/DataModels.ts +++ b/src/Contracts/DataModels.ts @@ -481,6 +481,10 @@ export interface IMaxUsersPerDbAccountExceeded extends IPhoenixError { } export interface IPhoenixConnectionInfoResult { + readonly phoenixServiceInfo?: IPhoenixServiceInfo; +} + +export interface IPhoenixServiceInfo { readonly authToken?: string; readonly phoenixServiceUrl?: string; readonly forwardingId?: string; diff --git a/src/Explorer/Explorer.tsx b/src/Explorer/Explorer.tsx index 6bf9a581c..bc79c7da0 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -16,12 +16,7 @@ import { getErrorMessage, getErrorStack, handleError } from "../Common/ErrorHand import * as Logger from "../Common/Logger"; import { QueriesClient } from "../Common/QueriesClient"; import * as DataModels from "../Contracts/DataModels"; -import { - ContainerConnectionInfo, - IPhoenixConnectionInfoResult, - IProvisionData, - IResponse, -} from "../Contracts/DataModels"; +import { ContainerConnectionInfo, IPhoenixServiceInfo, IProvisionData, IResponse } from "../Contracts/DataModels"; import * as ViewModels from "../Contracts/ViewModels"; import { GitHubOAuthService } from "../GitHub/GitHubOAuthService"; import { useSidePanel } from "../hooks/useSidePanel"; @@ -407,7 +402,7 @@ export default class Explorer { } private async setNotebookInfo( - connectionInfo: IResponse, + connectionInfo: IResponse, connectionStatus: DataModels.ContainerConnectionInfo ) { const containerData = { diff --git a/src/Explorer/Notebook/NotebookContainerClient.ts b/src/Explorer/Notebook/NotebookContainerClient.ts index 53ddc44ff..030b05a88 100644 --- a/src/Explorer/Notebook/NotebookContainerClient.ts +++ b/src/Explorer/Notebook/NotebookContainerClient.ts @@ -9,7 +9,7 @@ import { ConnectionStatusType, HttpHeaders, HttpStatusCodes, Notebook, PoolIdTyp import { getErrorMessage } from "../../Common/ErrorHandlingUtils"; import * as Logger from "../../Common/Logger"; import * as DataModels from "../../Contracts/DataModels"; -import { IPhoenixConnectionInfoResult, IProvisionData, IResponse } from "../../Contracts/DataModels"; +import { IPhoenixServiceInfo, IProvisionData, IResponse } from "../../Contracts/DataModels"; import { userContext } from "../../UserContext"; import { getAuthorizationHeader } from "../../Utils/AuthorizationUtils"; import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; @@ -129,9 +129,9 @@ export class NotebookContainerClient { ); } - public async resetWorkspace(): Promise> { + public async resetWorkspace(): Promise> { this.isResettingWorkspace = true; - let response: IResponse; + let response: IResponse; try { response = await this._resetWorkspace(); } catch (error) { @@ -142,7 +142,7 @@ export class NotebookContainerClient { return response; } - private async _resetWorkspace(): Promise> { + private async _resetWorkspace(): Promise> { const notebookServerInfo = useNotebook.getState().notebookServerInfo; if (!notebookServerInfo || !notebookServerInfo.notebookServerEndpoint) { const error = "No server endpoint detected"; diff --git a/src/Phoenix/PhoenixClient.ts b/src/Phoenix/PhoenixClient.ts index 664e595eb..21d7ac612 100644 --- a/src/Phoenix/PhoenixClient.ts +++ b/src/Phoenix/PhoenixClient.ts @@ -21,6 +21,7 @@ import { IMaxAllocationTimeExceeded, IPhoenixConnectionInfoResult, IPhoenixError, + IPhoenixServiceInfo, IProvisionData, IResponse, PhoenixErrorType, @@ -38,30 +39,38 @@ export class PhoenixClient { minTimeout: Notebook.retryAttemptDelayMs, }; - public async allocateContainer(provisionData: IProvisionData): Promise> { + public async allocateContainer(provisionData: IProvisionData): Promise> { return this.executeContainerAssignmentOperation(provisionData, "allocate"); } - public async resetContainer(provisionData: IProvisionData): Promise> { + public async resetContainer(provisionData: IProvisionData): Promise> { return this.executeContainerAssignmentOperation(provisionData, "reset"); } private async executeContainerAssignmentOperation( provisionData: IProvisionData, operation: string - ): Promise> { + ): Promise> { let response; try { - response = await fetch(`${this.getPhoenixControlPlanePathPrefix()}/containerconnections`, { + response = await fetch(`${this.getPhoenixControlPlanePathPrefix()}/containerconnections/multicontainer`, { method: operation === "allocate" ? "POST" : "PATCH", headers: PhoenixClient.getHeaders(), body: JSON.stringify(provisionData), }); const responseJson = await response?.json(); if (response.ok) { + const phoenixConnectionInfoResult = responseJson as IPhoenixConnectionInfoResult[]; + if ( + !phoenixConnectionInfoResult || + phoenixConnectionInfoResult.length === 0 || + !phoenixConnectionInfoResult[0] + ) { + throw new Error("Received invalid phoenix connection response."); + } return { status: response.status, - data: responseJson, + data: phoenixConnectionInfoResult[0].phoenixServiceInfo, }; } const phoenixError = responseJson as IPhoenixError;