From e4e602a81e7a80b14b683237d5ea5f6a59656cc1 Mon Sep 17 00:00:00 2001 From: artrejo Date: Tue, 20 Jul 2021 13:22:48 -0700 Subject: [PATCH] Add support for pseudo enum flags --- src/Common/MongoProxyClient.ts | 8 +++++++- src/Platform/Hosted/extractFeatures.ts | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Common/MongoProxyClient.ts b/src/Common/MongoProxyClient.ts index 2945f1288..c613ff9af 100644 --- a/src/Common/MongoProxyClient.ts +++ b/src/Common/MongoProxyClient.ts @@ -6,6 +6,7 @@ import * as DataModels from "../Contracts/DataModels"; import { MessageTypes } from "../Contracts/ExplorerContracts"; import { Collection } from "../Contracts/ViewModels"; import DocumentId from "../Explorer/Tree/DocumentId"; +import { hasFlag } from "../Platform/Hosted/extractFeatures"; import { userContext } from "../UserContext"; import { logConsoleError } from "../Utils/NotificationConsoleUtils"; import { ApiType, HttpHeaders, HttpStatusCodes } from "./Constants"; @@ -141,7 +142,8 @@ export function readDocument( : "", }; - const endpoint = getEndpoint(); + const endpoint = getFeatureEndpointOrDefault("readDocument"); + return window .fetch(`${endpoint}?${queryString.stringify(params)}`, { method: "GET", @@ -342,6 +344,10 @@ export function getEndpoint(): string { return url; } +function getFeatureEndpointOrDefault(feature: string): string { + return (hasFlag("mongoProxyFeatures", feature)) ? userContext.features.mongoProxyEndpoint : getEndpoint(); +} + // TODO: This function throws most of the time except on Forbidden which is a bit strange // It causes problems for TypeScript understanding the types async function errorHandling(response: Response, action: string, params: unknown): Promise { diff --git a/src/Platform/Hosted/extractFeatures.ts b/src/Platform/Hosted/extractFeatures.ts index 25c483c24..fe605683a 100644 --- a/src/Platform/Hosted/extractFeatures.ts +++ b/src/Platform/Hosted/extractFeatures.ts @@ -26,6 +26,8 @@ export type Features = { readonly pr?: string; readonly showMinRUSurvey: boolean; readonly ttl90Days: boolean; + readonly mongoProxyEndpoint: string; + readonly mongoProxyFeatures: string; }; export function extractFeatures(given = new URLSearchParams(window.location.search)): Features { @@ -58,6 +60,8 @@ export function extractFeatures(given = new URLSearchParams(window.location.sear enableTtl: "true" === get("enablettl"), executeSproc: "true" === get("dataexplorerexecutesproc"), hostedDataExplorer: "true" === get("hosteddataexplorerenabled"), + mongoProxyEndpoint: get("mongoProxyEndpoint"), + mongoProxyFeatures: get("mongoProxyFeatures"), junoEndpoint: get("junoendpoint"), livyEndpoint: get("livyendpoint"), notebookBasePath: get("notebookbasepath"), @@ -72,3 +76,7 @@ export function extractFeatures(given = new URLSearchParams(window.location.sear partitionKeyDefault: "true" === get("partitionkeytest"), }; } + +export function hasFlag(value: string, flag: string): boolean { + return true; +} \ No newline at end of file