diff --git a/src/Common/Constants.ts b/src/Common/Constants.ts index fe9c2672d..1eed03a4f 100644 --- a/src/Common/Constants.ts +++ b/src/Common/Constants.ts @@ -124,8 +124,9 @@ export enum MongoBackendEndpointType { remote, } -export enum BackendApi { - GenerateToken, +export class BackendApi { + public static readonly GenerateToken: string = "GenerateToken"; + public static readonly PortalSettings: string = "PortalSettings"; } export class PortalBackendEndpoints { diff --git a/src/ConfigContext.ts b/src/ConfigContext.ts index 3a8ef1cb5..435166b90 100644 --- a/src/ConfigContext.ts +++ b/src/ConfigContext.ts @@ -99,7 +99,6 @@ let configContext: Readonly = { JUNO_ENDPOINT: JunoEndpoints.Prod, BACKEND_ENDPOINT: "https://main.documentdb.ext.azure.com", PORTAL_BACKEND_ENDPOINT: PortalBackendEndpoints.Prod, - NEW_BACKEND_APIS: [BackendApi.GenerateToken], MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Prod, NEW_MONGO_APIS: [ "resourcelist", diff --git a/src/Explorer/QueryCopilot/Shared/QueryCopilotClient.ts b/src/Explorer/QueryCopilot/Shared/QueryCopilotClient.ts index 6d2cafdc5..59101cbb3 100644 --- a/src/Explorer/QueryCopilot/Shared/QueryCopilotClient.ts +++ b/src/Explorer/QueryCopilot/Shared/QueryCopilotClient.ts @@ -1,6 +1,7 @@ import { FeedOptions } from "@azure/cosmos"; import { Areas, + BackendApi, ConnectionStatusType, ContainerStatusType, HttpStatusCodes, @@ -30,6 +31,7 @@ import { Action } from "Shared/Telemetry/TelemetryConstants"; import { traceFailure, traceStart, traceSuccess } from "Shared/Telemetry/TelemetryProcessor"; import { userContext } from "UserContext"; import { getAuthorizationHeader } from "Utils/AuthorizationUtils"; +import { useNewPortalBackendEndpoint } from "Utils/EndpointUtils"; import { queryPagesUntilContentPresent } from "Utils/QueryUtils"; import { QueryCopilotState, useQueryCopilot } from "hooks/useQueryCopilot"; import { useTabs } from "hooks/useTabs"; @@ -80,7 +82,11 @@ export const isCopilotFeatureRegistered = async (subscriptionId: string): Promis }; export const getCopilotEnabled = async (): Promise => { - const url = `${configContext.BACKEND_ENDPOINT}/api/portalsettings/querycopilot`; + const backendEndpoint: string = useNewPortalBackendEndpoint(BackendApi.PortalSettings) + ? configContext.PORTAL_BACKEND_ENDPOINT + : configContext.BACKEND_ENDPOINT; + + const url = `${backendEndpoint}/api/portalsettings/querycopilot`; const authorizationHeader: AuthorizationTokenHeaderMetadata = getAuthorizationHeader(); const headers = { [authorizationHeader.header]: authorizationHeader.token }; diff --git a/src/Platform/Hosted/Components/ConnectExplorer.tsx b/src/Platform/Hosted/Components/ConnectExplorer.tsx index 6b33d021b..749f248ba 100644 --- a/src/Platform/Hosted/Components/ConnectExplorer.tsx +++ b/src/Platform/Hosted/Components/ConnectExplorer.tsx @@ -1,6 +1,6 @@ import { useBoolean } from "@fluentui/react-hooks"; import { userContext } from "UserContext"; -import { usePortalBackendEndpoint } from "Utils/EndpointUtils"; +import { useNewPortalBackendEndpoint } from "Utils/EndpointUtils"; import * as React from "react"; import ConnectImage from "../../../../images/HdeConnectCosmosDB.svg"; import ErrorImage from "../../../../images/error.svg"; @@ -19,7 +19,7 @@ interface Props { } export const fetchEncryptedToken = async (connectionString: string): Promise => { - if (!usePortalBackendEndpoint(BackendApi.GenerateToken)) { + if (!useNewPortalBackendEndpoint(BackendApi.GenerateToken)) { return await fetchEncryptedToken_ToBeDeprecated(connectionString); } diff --git a/src/Utils/EndpointUtils.ts b/src/Utils/EndpointUtils.ts index 4962c285b..c59db4205 100644 --- a/src/Utils/EndpointUtils.ts +++ b/src/Utils/EndpointUtils.ts @@ -145,8 +145,22 @@ export const allowedJunoOrigins: ReadonlyArray = [ export const allowedNotebookServerUrls: ReadonlyArray = []; -export function usePortalBackendEndpoint(backendApi: BackendApi): boolean { - const activePortalBackendEndpoints: string[] = [PortalBackendEndpoints.Development]; - const activeBackendApi: boolean = configContext.NEW_BACKEND_APIS?.includes(backendApi) || false; - return activeBackendApi && activePortalBackendEndpoints.includes(configContext.PORTAL_BACKEND_ENDPOINT as string); +// +// Temporary function to determine if a portal backend API is supported by the +// new backend in this environment. +// +// TODO: Remove this function once new backend migration is completed for all environments. +// +export function useNewPortalBackendEndpoint(backendApi: string): boolean { + // This maps backend APIs to the environments supported by the new backend. + const newBackendApiEnvironmentMap: { [key: string]: string[] } = { + [BackendApi.GenerateToken]: [PortalBackendEndpoints.Development], + [BackendApi.PortalSettings]: [PortalBackendEndpoints.Development, PortalBackendEndpoints.Mpac], + }; + + if (!newBackendApiEnvironmentMap[backendApi] || !configContext.PORTAL_BACKEND_ENDPOINT) { + return false; + } + + return newBackendApiEnvironmentMap[backendApi].includes(configContext.PORTAL_BACKEND_ENDPOINT); }