From 808faa9fa50d1b5a0d780b6712f99139120154a5 Mon Sep 17 00:00:00 2001 From: bogercraig <124094535+bogercraig@users.noreply.github.com> Date: Thu, 17 Oct 2024 13:41:22 -0700 Subject: [PATCH] CP and MP API Overrides from Config.json (#1992) * Force useMongoProxyEndpoint to always return true if valid endpoint provided. Enables new Mongo proxy in all environments. * Checking MP endpoint in config context. * Enabling cassandra proxy in all environments. Requires later cleanup. * Simplifying and removing endpoint validation since run when config context is generated. * Enabling one MP API at a time globally. * Revent to existing CP selection logic. * Creating list of globally enable CP apis. * Add list of mongo and cassandra APIs to config and only enable if environment outside existing list of environments. * Remove environment checks. If API globally enabled, return true. * Adding config initialization for mongo unit tests. * Default to empty enable list to minimize possible impact. Config.json overrides can be used for testing. --- src/Common/MongoProxyClient.test.ts | 32 ++++++++++++++++++++++---- src/Common/MongoProxyClient.ts | 12 ++++++---- src/ConfigContext.ts | 4 ++++ src/Explorer/Tables/TableDataClient.ts | 4 ++++ 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/src/Common/MongoProxyClient.test.ts b/src/Common/MongoProxyClient.test.ts index cda6eb882..a63190651 100644 --- a/src/Common/MongoProxyClient.test.ts +++ b/src/Common/MongoProxyClient.test.ts @@ -73,6 +73,7 @@ describe("MongoProxyClient", () => { }); updateConfigContext({ MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Prod, + globallyEnabledMongoAPIs: [], }); window.fetch = jest.fn().mockImplementation(fetchMock); }); @@ -89,7 +90,10 @@ describe("MongoProxyClient", () => { }); it("builds the correct proxy URL in development", () => { - updateConfigContext({ MONGO_PROXY_ENDPOINT: "https://localhost:1234" }); + updateConfigContext({ + MONGO_PROXY_ENDPOINT: "https://localhost:1234", + globallyEnabledMongoAPIs: [], + }); queryDocuments(databaseId, collection, true, "{}"); expect(window.fetch).toHaveBeenCalledWith( `${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer/resourcelist`, @@ -105,6 +109,7 @@ describe("MongoProxyClient", () => { }); updateConfigContext({ MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Prod, + globallyEnabledMongoAPIs: [], }); window.fetch = jest.fn().mockImplementation(fetchMock); }); @@ -121,7 +126,10 @@ describe("MongoProxyClient", () => { }); it("builds the correct proxy URL in development", () => { - updateConfigContext({ MONGO_PROXY_ENDPOINT: "https://localhost:1234" }); + updateConfigContext({ + MONGO_PROXY_ENDPOINT: "https://localhost:1234", + globallyEnabledMongoAPIs: [], + }); readDocument(databaseId, collection, documentId); expect(window.fetch).toHaveBeenCalledWith( `${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`, @@ -137,6 +145,7 @@ describe("MongoProxyClient", () => { }); updateConfigContext({ MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Prod, + globallyEnabledMongoAPIs: [], }); window.fetch = jest.fn().mockImplementation(fetchMock); }); @@ -153,7 +162,10 @@ describe("MongoProxyClient", () => { }); it("builds the correct proxy URL in development", () => { - updateConfigContext({ MONGO_PROXY_ENDPOINT: "https://localhost:1234" }); + updateConfigContext({ + MONGO_PROXY_ENDPOINT: "https://localhost:1234", + globallyEnabledMongoAPIs: [], + }); readDocument(databaseId, collection, documentId); expect(window.fetch).toHaveBeenCalledWith( `${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`, @@ -169,6 +181,7 @@ describe("MongoProxyClient", () => { }); updateConfigContext({ MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Prod, + globallyEnabledMongoAPIs: [], }); window.fetch = jest.fn().mockImplementation(fetchMock); }); @@ -185,7 +198,10 @@ describe("MongoProxyClient", () => { }); it("builds the correct proxy URL in development", () => { - updateConfigContext({ MONGO_BACKEND_ENDPOINT: "https://localhost:1234" }); + updateConfigContext({ + MONGO_BACKEND_ENDPOINT: "https://localhost:1234", + globallyEnabledMongoAPIs: [], + }); updateDocument(databaseId, collection, documentId, "{}"); expect(window.fetch).toHaveBeenCalledWith( `${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`, @@ -201,6 +217,7 @@ describe("MongoProxyClient", () => { }); updateConfigContext({ MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Prod, + globallyEnabledMongoAPIs: [], }); window.fetch = jest.fn().mockImplementation(fetchMock); }); @@ -217,7 +234,10 @@ describe("MongoProxyClient", () => { }); it("builds the correct proxy URL in development", () => { - updateConfigContext({ MONGO_PROXY_ENDPOINT: "https://localhost:1234" }); + updateConfigContext({ + MONGO_PROXY_ENDPOINT: "https://localhost:1234", + globallyEnabledMongoAPIs: [], + }); deleteDocument(databaseId, collection, documentId); expect(window.fetch).toHaveBeenCalledWith( `${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`, @@ -233,6 +253,7 @@ describe("MongoProxyClient", () => { }); updateConfigContext({ MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Prod, + globallyEnabledMongoAPIs: [], }); }); @@ -260,6 +281,7 @@ describe("MongoProxyClient", () => { resetConfigContext(); updateConfigContext({ MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Prod, + globallyEnabledMongoAPIs: [], }); const params = new URLSearchParams({ "feature.mongoProxyEndpoint": MongoProxyEndpoints.Prod, diff --git a/src/Common/MongoProxyClient.ts b/src/Common/MongoProxyClient.ts index c0e391e0f..0513d48cc 100644 --- a/src/Common/MongoProxyClient.ts +++ b/src/Common/MongoProxyClient.ts @@ -689,13 +689,13 @@ export function createMongoCollectionWithProxy_ToBeDeprecated( } export function getFeatureEndpointOrDefault(feature: string): string { let endpoint; - const allowedMongoProxyEndpoints = configContext.allowedMongoProxyEndpoints || [ - ...defaultAllowedMongoProxyEndpoints, - ...allowedMongoProxyEndpoints_ToBeDeprecated, - ]; if (useMongoProxyEndpoint(feature)) { endpoint = configContext.MONGO_PROXY_ENDPOINT; } else { + const allowedMongoProxyEndpoints = configContext.allowedMongoProxyEndpoints || [ + ...defaultAllowedMongoProxyEndpoints, + ...allowedMongoProxyEndpoints_ToBeDeprecated, + ]; endpoint = hasFlag(userContext.features.mongoProxyAPIs, feature) && validateEndpoint(userContext.features.mongoProxyEndpoint, allowedMongoProxyEndpoints) @@ -790,6 +790,10 @@ export function useMongoProxyEndpoint(mongoProxyApi: string): boolean { return false; } + if (configContext.globallyEnabledMongoAPIs.includes(mongoProxyApi)) { + return true; + } + return mongoProxyEnvironmentMap[mongoProxyApi].includes(configContext.MONGO_PROXY_ENDPOINT); } diff --git a/src/ConfigContext.ts b/src/ConfigContext.ts index 931893be4..113a6d5e5 100644 --- a/src/ConfigContext.ts +++ b/src/ConfigContext.ts @@ -67,6 +67,8 @@ export interface ConfigContext { hostedExplorerURL: string; armAPIVersion?: string; msalRedirectURI?: string; + globallyEnabledCassandraAPIs?: string[]; + globallyEnabledMongoAPIs?: string[]; } // Default configuration @@ -114,6 +116,8 @@ let configContext: Readonly = { NEW_CASSANDRA_APIS: ["postQuery", "createOrDelete", "getKeys", "getSchema"], isTerminalEnabled: false, isPhoenixEnabled: false, + globallyEnabledCassandraAPIs: [], + globallyEnabledMongoAPIs: [], }; export function resetConfigContext(): void { diff --git a/src/Explorer/Tables/TableDataClient.ts b/src/Explorer/Tables/TableDataClient.ts index 4e0859f95..8e652d6b0 100644 --- a/src/Explorer/Tables/TableDataClient.ts +++ b/src/Explorer/Tables/TableDataClient.ts @@ -757,6 +757,10 @@ export class CassandraAPIDataClient extends TableDataClient { CassandraProxyEndpoints.Mooncake, ]; + if (configContext.globallyEnabledCassandraAPIs.includes(api)) { + return true; + } + return ( configContext.NEW_CASSANDRA_APIS?.includes(api) && activeCassandraProxyEndpoints.includes(configContext.CASSANDRA_PROXY_ENDPOINT)