From 8f4d7fc4989c67bb963558bf42c1ca123cf867dd Mon Sep 17 00:00:00 2001 From: "Craig Boger (from Dev Box)" Date: Thu, 23 Jan 2025 14:15:22 -0800 Subject: [PATCH] Rough implementation of configuring regional endpoint when DE is loaded in portal or hosted with AAD/Entra auth. --- src/hooks/useKnockoutExplorer.ts | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/hooks/useKnockoutExplorer.ts b/src/hooks/useKnockoutExplorer.ts index 3c59baadf..25a5e4177 100644 --- a/src/hooks/useKnockoutExplorer.ts +++ b/src/hooks/useKnockoutExplorer.ts @@ -298,6 +298,25 @@ async function configureHostedWithAAD(config: AAD): Promise { `Configuring Data Explorer for ${userContext.apiType} account ${account.name}`, "Explorer/configureHostedWithAAD", ); + // TODO: Somewhere in here need to configure regional endpoint selection in the user context for the client to pull from. + // Essentially, if the value exists in local storage, then grab the regional endpoint and load it. Only if data plane RBAC is enabled. + // For now, just loading up setting from storage if it exists. If we limit to data plane rbac accounts, then we limit other client APIs besides nosql. + // TODO: Maybe just load up the regional endpoint if it exists in the local storage? Loading here makes sense since we are configuring + // user context, but introduces a lot of repetitive code. + if ( + (userContext.apiType === "SQL" || userContext.apiType === "Tables" || userContext.apiType === "Gremlin") && + LocalStorageUtility.hasItem(StorageKey.SelectedRegion) + ) { + const storedRegion = LocalStorageUtility.getEntryString(StorageKey.SelectedRegion); + const location = userContext.databaseAccount?.properties?.readLocations?.find( + (loc) => loc.locationName === storedRegion, + ); + updateUserContext({ + // TODO: Can possible make this process better by just storing the selected region endpoint. + selectedRegionalEndpoint: location?.documentEndpoint, + refreshCosmosClient: true, + }); + } if (!userContext.features.enableAadDataPlane) { Logger.logInfo(`AAD Feature flag is not enabled for account ${account.name}`, "Explorer/configureHostedWithAAD"); if (isDataplaneRbacSupported(userContext.apiType)) { @@ -551,6 +570,23 @@ async function configurePortal(): Promise { updateContextsFromPortalMessage(inputs); const { databaseAccount: account, subscriptionId, resourceGroup } = userContext; + // TODO: Somewhere in here need to configure regional endpoint selection in the user context for the client to pull from. + // Essentially, if the value exists in local storage, then grab the regional endpoint and load it. Only if data plane RBAC is enabled. + // For now, just loading up setting from storage if it exists. If we limit to data plane rbac accounts, then we limit other client APIs besides nosql. + if ( + (userContext.apiType === "SQL" || userContext.apiType === "Tables" || userContext.apiType === "Gremlin") && + LocalStorageUtility.hasItem(StorageKey.SelectedRegion) + ) { + const storedRegion = LocalStorageUtility.getEntryString(StorageKey.SelectedRegion); + const location = userContext.databaseAccount?.properties?.readLocations?.find( + (loc) => loc.locationName === storedRegion, + ); + updateUserContext({ + // TODO: Can possible make this process better by just storing the selected region endpoint. + selectedRegionalEndpoint: location?.documentEndpoint, + refreshCosmosClient: true, + }); + } let dataPlaneRbacEnabled; if (isDataplaneRbacSupported(userContext.apiType)) {