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)