diff --git a/README.md b/README.md index f82af79ee..797ab6c2b 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Run `npm start` to start the development server and automatically rebuild on cha ### Hosted Development (https://cosmos.azure.com) - Visit: `https://localhost:1234/hostedExplorer.html` -- The default webpack dev server configuration will proxy requests to the production portal backend: `https://main.documentdb.ext.azure.com`. This will allow you to use production connection strings on your local machine. +- The default webpack dev server configuration will proxy requests to the production portal backend: `https://cdb-ms-mpac-pbe.cosmos.azure.com`. This will allow you to use production connection strings on your local machine. ### Emulator Development diff --git a/docs/index.html b/docs/index.html index f62e4c4f2..7f71f301d 100644 --- a/docs/index.html +++ b/docs/index.html @@ -82,7 +82,7 @@

Emulator Development

diff --git a/preview/index.js b/preview/index.js index c205600a9..f38fae27c 100644 --- a/preview/index.js +++ b/preview/index.js @@ -4,7 +4,7 @@ const port = process.env.PORT || 3000; const fetch = require("node-fetch"); const api = createProxyMiddleware("/api", { - target: "https://main.documentdb.ext.azure.com", + target: "https://cdb-ms-mpac-pbe.cosmos.azure.com", changeOrigin: true, logLevel: "debug", bypass: (req, res) => { @@ -16,7 +16,7 @@ const api = createProxyMiddleware("/api", { }); const proxy = createProxyMiddleware("/proxy", { - target: "https://main.documentdb.ext.azure.com", + target: "https://cdb-ms-mpac-pbe.cosmos.azure.com", changeOrigin: true, secure: false, logLevel: "debug", diff --git a/src/Common/Constants.ts b/src/Common/Constants.ts index d0d3837c2..23155cbdf 100644 --- a/src/Common/Constants.ts +++ b/src/Common/Constants.ts @@ -155,6 +155,18 @@ export class MongoProxyEndpoints { public static readonly Mooncake: string = "https://cdb-mc-prod-mp.cosmos.azure.cn"; } +export class MongoProxyApi { + public static readonly ResourceList: string = "ResourceList"; + public static readonly QueryDocuments: string = "QueryDocuments"; + public static readonly CreateDocument: string = "CreateDocumen"; + public static readonly ReadDocument: string = "ReadDocument"; + public static readonly UpdateDocument: string = "UpdateDocument"; + public static readonly DeleteDocument: string = "DeleteDocument"; + public static readonly CreateCollectionWithProxy: string = "CreateCollectionWithProxy"; + public static readonly LegacyMongoShell: string = "LegacyMongoShell"; + public static readonly BulkDelete: string = "BulkDelete"; +} + export class CassandraProxyEndpoints { public static readonly Development: string = "https://localhost:7240"; public static readonly Mpac: string = "https://cdb-ms-mpac-cp.cosmos.azure.com"; diff --git a/src/Common/CosmosClient.test.ts b/src/Common/CosmosClient.test.ts index 3f5ff9f2a..c5c067f6c 100644 --- a/src/Common/CosmosClient.test.ts +++ b/src/Common/CosmosClient.test.ts @@ -1,4 +1,5 @@ -import { Platform, resetConfigContext, updateConfigContext } from "../ConfigContext"; +import { PortalBackendEndpoints } from "Common/Constants"; +import { configContext, Platform, resetConfigContext, updateConfigContext } from "../ConfigContext"; import { updateUserContext } from "../UserContext"; import { endpoint, getTokenFromAuthService, requestPlugin } from "./CosmosClient"; @@ -20,22 +21,22 @@ describe("getTokenFromAuthService", () => { it("builds the correct URL in production", () => { updateConfigContext({ - BACKEND_ENDPOINT: "https://main.documentdb.ext.azure.com", + PORTAL_BACKEND_ENDPOINT: PortalBackendEndpoints.Prod, }); getTokenFromAuthService("GET", "dbs", "foo"); expect(window.fetch).toHaveBeenCalledWith( - "https://main.documentdb.ext.azure.com/api/guest/runtimeproxy/authorizationTokens", + `${configContext.PORTAL_BACKEND_ENDPOINT}/api/connectionstring/runtimeproxy/authorizationtokens`, expect.any(Object), ); }); it("builds the correct URL in dev", () => { updateConfigContext({ - BACKEND_ENDPOINT: "https://localhost:1234", + PORTAL_BACKEND_ENDPOINT: PortalBackendEndpoints.Development, }); getTokenFromAuthService("GET", "dbs", "foo"); expect(window.fetch).toHaveBeenCalledWith( - "https://localhost:1234/api/guest/runtimeproxy/authorizationTokens", + `${configContext.PORTAL_BACKEND_ENDPOINT}/api/connectionstring/runtimeproxy/authorizationtokens`, expect.any(Object), ); }); @@ -78,7 +79,7 @@ describe("requestPlugin", () => { const next = jest.fn(); updateConfigContext({ platform: Platform.Hosted, - BACKEND_ENDPOINT: "https://localhost:1234", + PORTAL_BACKEND_ENDPOINT: "https://localhost:1234", PROXY_PATH: "/proxy", }); const headers = {}; diff --git a/src/Common/MongoProxyClient.test.ts b/src/Common/MongoProxyClient.test.ts index a4c75a344..cda6eb882 100644 --- a/src/Common/MongoProxyClient.test.ts +++ b/src/Common/MongoProxyClient.test.ts @@ -1,5 +1,6 @@ +import { MongoProxyEndpoints } from "Common/Constants"; import { AuthType } from "../AuthType"; -import { resetConfigContext, updateConfigContext } from "../ConfigContext"; +import { configContext, resetConfigContext, updateConfigContext } from "../ConfigContext"; import { DatabaseAccount } from "../Contracts/DataModels"; import { Collection } from "../Contracts/ViewModels"; import DocumentId from "../Explorer/Tree/DocumentId"; @@ -71,7 +72,7 @@ describe("MongoProxyClient", () => { databaseAccount, }); updateConfigContext({ - BACKEND_ENDPOINT: "https://main.documentdb.ext.azure.com", + MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Prod, }); window.fetch = jest.fn().mockImplementation(fetchMock); }); @@ -82,16 +83,16 @@ describe("MongoProxyClient", () => { it("builds the correct URL", () => { queryDocuments(databaseId, collection, true, "{}"); expect(window.fetch).toHaveBeenCalledWith( - "https://main.documentdb.ext.azure.com/api/mongo/explorer/resourcelist?db=testDB&coll=testCollection&resourceUrl=bardbs%2FtestDB%2Fcolls%2FtestCollection%2Fdocs%2F&rid=testCollectionrid&rtype=docs&sid=&rg=&dba=foo&pk=pk", + `${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer/resourcelist`, expect.any(Object), ); }); it("builds the correct proxy URL in development", () => { - updateConfigContext({ MONGO_BACKEND_ENDPOINT: "https://localhost:1234" }); + updateConfigContext({ MONGO_PROXY_ENDPOINT: "https://localhost:1234" }); queryDocuments(databaseId, collection, true, "{}"); expect(window.fetch).toHaveBeenCalledWith( - "https://localhost:1234/api/mongo/explorer/resourcelist?db=testDB&coll=testCollection&resourceUrl=bardbs%2FtestDB%2Fcolls%2FtestCollection%2Fdocs%2F&rid=testCollectionrid&rtype=docs&sid=&rg=&dba=foo&pk=pk", + `${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer/resourcelist`, expect.any(Object), ); }); @@ -103,7 +104,7 @@ describe("MongoProxyClient", () => { databaseAccount, }); updateConfigContext({ - BACKEND_ENDPOINT: "https://main.documentdb.ext.azure.com", + MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Prod, }); window.fetch = jest.fn().mockImplementation(fetchMock); }); @@ -114,16 +115,16 @@ describe("MongoProxyClient", () => { it("builds the correct URL", () => { readDocument(databaseId, collection, documentId); expect(window.fetch).toHaveBeenCalledWith( - "https://main.documentdb.ext.azure.com/api/mongo/explorer?db=testDB&coll=testCollection&resourceUrl=bardb%2FtestDB%2Fdb%2FtestCollection%2FtestId&rid=testId&rtype=docs&sid=&rg=&dba=foo&pk=pk", + `${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`, expect.any(Object), ); }); it("builds the correct proxy URL in development", () => { - updateConfigContext({ MONGO_BACKEND_ENDPOINT: "https://localhost:1234" }); + updateConfigContext({ MONGO_PROXY_ENDPOINT: "https://localhost:1234" }); readDocument(databaseId, collection, documentId); expect(window.fetch).toHaveBeenCalledWith( - "https://localhost:1234/api/mongo/explorer?db=testDB&coll=testCollection&resourceUrl=bardb%2FtestDB%2Fdb%2FtestCollection%2FtestId&rid=testId&rtype=docs&sid=&rg=&dba=foo&pk=pk", + `${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`, expect.any(Object), ); }); @@ -135,7 +136,7 @@ describe("MongoProxyClient", () => { databaseAccount, }); updateConfigContext({ - BACKEND_ENDPOINT: "https://main.documentdb.ext.azure.com", + MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Prod, }); window.fetch = jest.fn().mockImplementation(fetchMock); }); @@ -146,16 +147,16 @@ describe("MongoProxyClient", () => { it("builds the correct URL", () => { readDocument(databaseId, collection, documentId); expect(window.fetch).toHaveBeenCalledWith( - "https://main.documentdb.ext.azure.com/api/mongo/explorer?db=testDB&coll=testCollection&resourceUrl=bardb%2FtestDB%2Fdb%2FtestCollection%2FtestId&rid=testId&rtype=docs&sid=&rg=&dba=foo&pk=pk", + `${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`, expect.any(Object), ); }); it("builds the correct proxy URL in development", () => { - updateConfigContext({ MONGO_BACKEND_ENDPOINT: "https://localhost:1234" }); + updateConfigContext({ MONGO_PROXY_ENDPOINT: "https://localhost:1234" }); readDocument(databaseId, collection, documentId); expect(window.fetch).toHaveBeenCalledWith( - "https://localhost:1234/api/mongo/explorer?db=testDB&coll=testCollection&resourceUrl=bardb%2FtestDB%2Fdb%2FtestCollection%2FtestId&rid=testId&rtype=docs&sid=&rg=&dba=foo&pk=pk", + `${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`, expect.any(Object), ); }); @@ -167,7 +168,7 @@ describe("MongoProxyClient", () => { databaseAccount, }); updateConfigContext({ - BACKEND_ENDPOINT: "https://main.documentdb.ext.azure.com", + MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Prod, }); window.fetch = jest.fn().mockImplementation(fetchMock); }); @@ -178,7 +179,7 @@ describe("MongoProxyClient", () => { it("builds the correct URL", () => { updateDocument(databaseId, collection, documentId, "{}"); expect(window.fetch).toHaveBeenCalledWith( - "https://main.documentdb.ext.azure.com/api/mongo/explorer?db=testDB&coll=testCollection&resourceUrl=bardb%2FtestDB%2Fdb%2FtestCollection%2Fdocs%2FtestId&rid=testId&rtype=docs&sid=&rg=&dba=foo&pk=pk", + `${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`, expect.any(Object), ); }); @@ -187,7 +188,7 @@ describe("MongoProxyClient", () => { updateConfigContext({ MONGO_BACKEND_ENDPOINT: "https://localhost:1234" }); updateDocument(databaseId, collection, documentId, "{}"); expect(window.fetch).toHaveBeenCalledWith( - "https://localhost:1234/api/mongo/explorer?db=testDB&coll=testCollection&resourceUrl=bardb%2FtestDB%2Fdb%2FtestCollection%2Fdocs%2FtestId&rid=testId&rtype=docs&sid=&rg=&dba=foo&pk=pk", + `${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`, expect.any(Object), ); }); @@ -199,7 +200,7 @@ describe("MongoProxyClient", () => { databaseAccount, }); updateConfigContext({ - BACKEND_ENDPOINT: "https://main.documentdb.ext.azure.com", + MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Prod, }); window.fetch = jest.fn().mockImplementation(fetchMock); }); @@ -210,16 +211,16 @@ describe("MongoProxyClient", () => { it("builds the correct URL", () => { deleteDocument(databaseId, collection, documentId); expect(window.fetch).toHaveBeenCalledWith( - "https://main.documentdb.ext.azure.com/api/mongo/explorer?db=testDB&coll=testCollection&resourceUrl=bardb%2FtestDB%2Fdb%2FtestCollection%2Fdocs%2FtestId&rid=testId&rtype=docs&sid=&rg=&dba=foo&pk=pk", + `${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`, expect.any(Object), ); }); it("builds the correct proxy URL in development", () => { - updateConfigContext({ MONGO_BACKEND_ENDPOINT: "https://localhost:1234" }); + updateConfigContext({ MONGO_PROXY_ENDPOINT: "https://localhost:1234" }); deleteDocument(databaseId, collection, documentId); expect(window.fetch).toHaveBeenCalledWith( - "https://localhost:1234/api/mongo/explorer?db=testDB&coll=testCollection&resourceUrl=bardb%2FtestDB%2Fdb%2FtestCollection%2Fdocs%2FtestId&rid=testId&rtype=docs&sid=&rg=&dba=foo&pk=pk", + `${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`, expect.any(Object), ); }); @@ -231,13 +232,13 @@ describe("MongoProxyClient", () => { databaseAccount, }); updateConfigContext({ - BACKEND_ENDPOINT: "https://main.documentdb.ext.azure.com", + MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Prod, }); }); it("returns a production endpoint", () => { - const endpoint = getEndpoint("https://main.documentdb.ext.azure.com"); - expect(endpoint).toEqual("https://main.documentdb.ext.azure.com/api/mongo/explorer"); + const endpoint = getEndpoint(configContext.MONGO_PROXY_ENDPOINT); + expect(endpoint).toEqual(`${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`); }); it("returns a development endpoint", () => { @@ -249,18 +250,19 @@ describe("MongoProxyClient", () => { updateUserContext({ authType: AuthType.EncryptedToken, }); - const endpoint = getEndpoint("https://main.documentdb.ext.azure.com"); - expect(endpoint).toEqual("https://main.documentdb.ext.azure.com/api/guest/mongo/explorer"); + const endpoint = getEndpoint(configContext.MONGO_PROXY_ENDPOINT); + expect(endpoint).toEqual(`${configContext.MONGO_PROXY_ENDPOINT}/api/connectionstring/mongo/explorer`); }); }); + describe("getFeatureEndpointOrDefault", () => { beforeEach(() => { resetConfigContext(); updateConfigContext({ - BACKEND_ENDPOINT: "https://main.documentdb.ext.azure.com", + MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Prod, }); const params = new URLSearchParams({ - "feature.mongoProxyEndpoint": "https://localhost:12901", + "feature.mongoProxyEndpoint": MongoProxyEndpoints.Prod, "feature.mongoProxyAPIs": "readDocument|createDocument", }); const features = extractFeatures(params); @@ -272,12 +274,12 @@ describe("MongoProxyClient", () => { it("returns a local endpoint", () => { const endpoint = getFeatureEndpointOrDefault("readDocument"); - expect(endpoint).toEqual("https://localhost:12901/api/mongo/explorer"); + expect(endpoint).toEqual(`${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`); }); it("returns a production endpoint", () => { - const endpoint = getFeatureEndpointOrDefault("deleteDocument"); - expect(endpoint).toEqual("https://main.documentdb.ext.azure.com/api/mongo/explorer"); + const endpoint = getFeatureEndpointOrDefault("DeleteDocument"); + expect(endpoint).toEqual(`${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`); }); }); }); diff --git a/src/Common/MongoProxyClient.ts b/src/Common/MongoProxyClient.ts index 552d9f08d..775ac9b18 100644 --- a/src/Common/MongoProxyClient.ts +++ b/src/Common/MongoProxyClient.ts @@ -14,7 +14,7 @@ import DocumentId from "../Explorer/Tree/DocumentId"; import { hasFlag } from "../Platform/Hosted/extractFeatures"; import { userContext } from "../UserContext"; import { logConsoleError } from "../Utils/NotificationConsoleUtils"; -import { ApiType, ContentType, HttpHeaders, HttpStatusCodes, MongoProxyEndpoints } from "./Constants"; +import { ApiType, ContentType, HttpHeaders, HttpStatusCodes, MongoProxyApi, MongoProxyEndpoints } from "./Constants"; import { MinimalQueryIterator } from "./IteratorUtilities"; import { sendMessage } from "./MessageHandler"; @@ -67,7 +67,7 @@ export function queryDocuments( query: string, continuationToken?: string, ): Promise { - if (!useMongoProxyEndpoint("resourcelist") || !useMongoProxyEndpoint("queryDocuments")) { + if (!useMongoProxyEndpoint(MongoProxyApi.ResourceList) || !useMongoProxyEndpoint(MongoProxyApi.QueryDocuments)) { return queryDocuments_ToBeDeprecated(databaseId, collection, isResourceList, query, continuationToken); } @@ -89,7 +89,7 @@ export function queryDocuments( query, }; - const endpoint = getFeatureEndpointOrDefault("resourcelist") || ""; + const endpoint = getFeatureEndpointOrDefault(MongoProxyApi.ResourceList) || ""; const headers = { ...defaultHeaders, @@ -194,7 +194,7 @@ export function readDocument( collection: Collection, documentId: DocumentId, ): Promise { - if (!useMongoProxyEndpoint("readDocument")) { + if (!useMongoProxyEndpoint(MongoProxyApi.ReadDocument)) { return readDocument_ToBeDeprecated(databaseId, collection, documentId); } const { databaseAccount } = userContext; @@ -217,7 +217,7 @@ export function readDocument( : "", }; - const endpoint = getFeatureEndpointOrDefault("readDocument"); + const endpoint = getFeatureEndpointOrDefault(MongoProxyApi.ReadDocument); return window .fetch(endpoint, { @@ -289,7 +289,7 @@ export function createDocument( partitionKeyProperty: string, documentContent: unknown, ): Promise { - if (!useMongoProxyEndpoint("createDocument")) { + if (!useMongoProxyEndpoint(MongoProxyApi.CreateDocument)) { return createDocument_ToBeDeprecated(databaseId, collection, partitionKeyProperty, documentContent); } const { databaseAccount } = userContext; @@ -308,7 +308,7 @@ export function createDocument( documentContent: JSON.stringify(documentContent), }; - const endpoint = getFeatureEndpointOrDefault("createDocument"); + const endpoint = getFeatureEndpointOrDefault(MongoProxyApi.CreateDocument); return window .fetch(`${endpoint}/createDocument`, { @@ -373,7 +373,7 @@ export function updateDocument( documentId: DocumentId, documentContent: string, ): Promise { - if (!useMongoProxyEndpoint("updateDocument")) { + if (!useMongoProxyEndpoint(MongoProxyApi.UpdateDocument)) { return updateDocument_ToBeDeprecated(databaseId, collection, documentId, documentContent); } const { databaseAccount } = userContext; @@ -396,7 +396,7 @@ export function updateDocument( : "", documentContent, }; - const endpoint = getFeatureEndpointOrDefault("updateDocument"); + const endpoint = getFeatureEndpointOrDefault(MongoProxyApi.UpdateDocument); return window .fetch(endpoint, { @@ -464,7 +464,7 @@ export function updateDocument_ToBeDeprecated( } export function deleteDocument(databaseId: string, collection: Collection, documentId: DocumentId): Promise { - if (!useMongoProxyEndpoint("deleteDocument")) { + if (!useMongoProxyEndpoint(MongoProxyApi.DeleteDocument)) { return deleteDocument_ToBeDeprecated(databaseId, collection, documentId); } const { databaseAccount } = userContext; @@ -486,7 +486,7 @@ export function deleteDocument(databaseId: string, collection: Collection, docum ? documentId.partitionKeyProperties?.[0] : "", }; - const endpoint = getFeatureEndpointOrDefault("deleteDocument"); + const endpoint = getFeatureEndpointOrDefault(MongoProxyApi.DeleteDocument); return window .fetch(endpoint, { @@ -575,7 +575,7 @@ export function deleteDocuments( resourceGroup: userContext.resourceGroup, databaseAccountName: databaseAccount.name, }; - const endpoint = getFeatureEndpointOrDefault("bulkdelete"); + const endpoint = getFeatureEndpointOrDefault(MongoProxyApi.BulkDelete); return window .fetch(`${endpoint}/bulkdelete`, { @@ -599,7 +599,7 @@ export function deleteDocuments( export function createMongoCollectionWithProxy( params: DataModels.CreateCollectionParams, ): Promise { - if (!useMongoProxyEndpoint("createCollectionWithProxy")) { + if (!useMongoProxyEndpoint(MongoProxyApi.CreateCollectionWithProxy)) { return createMongoCollectionWithProxy_ToBeDeprecated(params); } const { databaseAccount } = userContext; @@ -622,7 +622,7 @@ export function createMongoCollectionWithProxy( isSharded: !!shardKey, }; - const endpoint = getFeatureEndpointOrDefault("createCollectionWithProxy"); + const endpoint = getFeatureEndpointOrDefault(MongoProxyApi.CreateCollectionWithProxy); return window .fetch(`${endpoint}/createCollection`, { @@ -718,19 +718,78 @@ export function getEndpoint(endpoint: string): string { return url; } -export function useMongoProxyEndpoint(api: string): boolean { - const activeMongoProxyEndpoints: string[] = [ - MongoProxyEndpoints.Local, - MongoProxyEndpoints.Mpac, - MongoProxyEndpoints.Prod, - MongoProxyEndpoints.Fairfax, - MongoProxyEndpoints.Mooncake, - ]; +export function useMongoProxyEndpoint(mongoProxyApi: string): boolean { + const mongoProxyEnvironmentMap: { [key: string]: string[] } = { + [MongoProxyApi.ResourceList]: [ + MongoProxyEndpoints.Local, + MongoProxyEndpoints.Mpac, + MongoProxyEndpoints.Prod, + MongoProxyEndpoints.Fairfax, + MongoProxyEndpoints.Mooncake, + ], + [MongoProxyApi.QueryDocuments]: [ + MongoProxyEndpoints.Local, + MongoProxyEndpoints.Mpac, + MongoProxyEndpoints.Prod, + MongoProxyEndpoints.Fairfax, + MongoProxyEndpoints.Mooncake, + ], + [MongoProxyApi.CreateDocument]: [ + MongoProxyEndpoints.Local, + MongoProxyEndpoints.Mpac, + MongoProxyEndpoints.Prod, + MongoProxyEndpoints.Fairfax, + MongoProxyEndpoints.Mooncake, + ], + [MongoProxyApi.ReadDocument]: [ + MongoProxyEndpoints.Local, + MongoProxyEndpoints.Mpac, + MongoProxyEndpoints.Prod, + MongoProxyEndpoints.Fairfax, + MongoProxyEndpoints.Mooncake, + ], + [MongoProxyApi.UpdateDocument]: [ + MongoProxyEndpoints.Local, + MongoProxyEndpoints.Mpac, + MongoProxyEndpoints.Prod, + MongoProxyEndpoints.Fairfax, + MongoProxyEndpoints.Mooncake, + ], + [MongoProxyApi.DeleteDocument]: [ + MongoProxyEndpoints.Local, + MongoProxyEndpoints.Mpac, + MongoProxyEndpoints.Prod, + MongoProxyEndpoints.Fairfax, + MongoProxyEndpoints.Mooncake, + ], + [MongoProxyApi.CreateCollectionWithProxy]: [ + MongoProxyEndpoints.Local, + MongoProxyEndpoints.Mpac, + MongoProxyEndpoints.Prod, + MongoProxyEndpoints.Fairfax, + MongoProxyEndpoints.Mooncake, + ], + [MongoProxyApi.LegacyMongoShell]: [ + MongoProxyEndpoints.Local, + MongoProxyEndpoints.Mpac, + MongoProxyEndpoints.Prod, + MongoProxyEndpoints.Fairfax, + MongoProxyEndpoints.Mooncake, + ], + [MongoProxyApi.BulkDelete]: [ + MongoProxyEndpoints.Local, + MongoProxyEndpoints.Mpac, + MongoProxyEndpoints.Prod, + MongoProxyEndpoints.Fairfax, + MongoProxyEndpoints.Mooncake, + ], + }; - return ( - configContext.NEW_MONGO_APIS?.includes(api) && - activeMongoProxyEndpoints.includes(configContext.MONGO_PROXY_ENDPOINT) - ); + if (!mongoProxyEnvironmentMap[mongoProxyApi] || !configContext.MONGO_PROXY_ENDPOINT) { + return false; + } + + return mongoProxyEnvironmentMap[mongoProxyApi].includes(configContext.MONGO_PROXY_ENDPOINT); } export class ThrottlingError extends Error { diff --git a/src/ConfigContext.ts b/src/ConfigContext.ts index 86fd92586..86a024263 100644 --- a/src/ConfigContext.ts +++ b/src/ConfigContext.ts @@ -53,7 +53,6 @@ export interface ConfigContext { NEW_BACKEND_APIS?: BackendApi[]; MONGO_BACKEND_ENDPOINT?: string; MONGO_PROXY_ENDPOINT: string; - NEW_MONGO_APIS?: string[]; CASSANDRA_PROXY_ENDPOINT: string; NEW_CASSANDRA_APIS?: string[]; PROXY_PATH?: string; @@ -76,6 +75,7 @@ let configContext: Readonly = { allowedParentFrameOrigins: [ `^https:\\/\\/cosmos\\.azure\\.(com|cn|us)$`, `^https:\\/\\/[\\.\\w]*portal\\.azure\\.(com|cn|us)$`, + `^https:\\/\\/cdb-(ms|ff|mc)-prod-pbe\\.cosmos\\.azure\\.(com|us|cn)$`, `^https:\\/\\/[\\.\\w]*portal\\.microsoftazure\\.de$`, `^https:\\/\\/[\\.\\w]*ext\\.azure\\.(com|cn|us)$`, `^https:\\/\\/[\\.\\w]*\\.ext\\.microsoftazure\\.de$`, @@ -106,17 +106,6 @@ let configContext: Readonly = { BACKEND_ENDPOINT: "https://main.documentdb.ext.azure.com", PORTAL_BACKEND_ENDPOINT: PortalBackendEndpoints.Prod, MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Prod, - NEW_MONGO_APIS: [ - "resourcelist", - "queryDocuments", - "createDocument", - "readDocument", - "updateDocument", - "deleteDocument", - "createCollectionWithProxy", - "legacyMongoShell", - "bulkdelete", - ], CASSANDRA_PROXY_ENDPOINT: CassandraProxyEndpoints.Prod, NEW_CASSANDRA_APIS: ["postQuery", "createOrDelete", "getKeys", "getSchema"], isTerminalEnabled: false, diff --git a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx index c5445c2f9..8bcb35aa1 100644 --- a/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx +++ b/src/Explorer/Tabs/DocumentsTabV2/DocumentsTabV2.tsx @@ -2115,7 +2115,7 @@ export const DocumentsTabComponent: React.FunctionComponent { ${"https://subdomain.portal.azure.com"} | ${false} ${"https://subdomain.portal.azure.us"} | ${false} ${"https://subdomain.portal.azure.cn"} | ${false} - ${"https://main.documentdb.ext.azure.com"} | ${false} - ${"https://main.documentdb.ext.azure.us"} | ${false} - ${"https://main.documentdb.ext.azure.cn"} | ${false} + ${"https://cdb-ms-prod-pbe.cosmos.azure.com"} | ${false} + ${"https://cdb-ff-prod-pbe.cosmos.azure.us"} | ${false} + ${"https://cdb-mc-prod-pbe.cosmos.azure.cn"} | ${false} ${"https://cosmos-db-dataexplorer-germanycentral.azurewebsites.de"} | ${false} ${"https://main.documentdb.ext.microsoftazure.de"} | ${false} ${"https://random.domain"} | ${true} diff --git a/src/Utils/NetworkUtility.test.ts b/src/Utils/NetworkUtility.test.ts index ba2eb2c67..b27c8db50 100644 --- a/src/Utils/NetworkUtility.test.ts +++ b/src/Utils/NetworkUtility.test.ts @@ -2,12 +2,11 @@ import { MongoProxyEndpoints, PortalBackendEndpoints } from "Common/Constants"; import { resetConfigContext, updateConfigContext } from "ConfigContext"; import { DatabaseAccount, IpRule } from "Contracts/DataModels"; import { updateUserContext } from "UserContext"; -import { MongoProxyOutboundIPs, PortalBackendIPs, PortalBackendOutboundIPs } from "Utils/EndpointUtils"; +import { MongoProxyOutboundIPs, PortalBackendOutboundIPs } from "Utils/EndpointUtils"; import { getNetworkSettingsWarningMessage } from "./NetworkUtility"; describe("NetworkUtility tests", () => { describe("getNetworkSettingsWarningMessage", () => { - const legacyBackendEndpoint: string = "https://main.documentdb.ext.azure.com"; const publicAccessMessagePart = "Please enable public access to proceed"; const accessMessagePart = "Please allow access from Azure Portal to proceed"; let warningMessageResult: string; @@ -48,25 +47,23 @@ describe("NetworkUtility tests", () => { }); it(`should return no message when the appropriate ip rules are added to mongo/cassandra account per endpoint`, async () => { - const portalBackendOutboundIPsWithLegacyIPs: string[] = [ + const portalBackendOutboundIPs: string[] = [ ...PortalBackendOutboundIPs[PortalBackendEndpoints.Mpac], ...PortalBackendOutboundIPs[PortalBackendEndpoints.Prod], ...MongoProxyOutboundIPs[MongoProxyEndpoints.Mpac], ...MongoProxyOutboundIPs[MongoProxyEndpoints.Prod], - ...PortalBackendIPs["https://main.documentdb.ext.azure.com"], ]; updateUserContext({ databaseAccount: { kind: "MongoDB", properties: { - ipRules: portalBackendOutboundIPsWithLegacyIPs.map((ip: string) => ({ ipAddressOrRange: ip }) as IpRule), + ipRules: portalBackendOutboundIPs.map((ip: string) => ({ ipAddressOrRange: ip }) as IpRule), publicNetworkAccess: "Enabled", }, } as DatabaseAccount, }); updateConfigContext({ - BACKEND_ENDPOINT: legacyBackendEndpoint, PORTAL_BACKEND_ENDPOINT: PortalBackendEndpoints.Mpac, MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Mpac, }); @@ -90,7 +87,6 @@ describe("NetworkUtility tests", () => { }); updateConfigContext({ - BACKEND_ENDPOINT: legacyBackendEndpoint, PORTAL_BACKEND_ENDPOINT: PortalBackendEndpoints.Mpac, MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Mpac, }); diff --git a/src/Utils/NetworkUtility.ts b/src/Utils/NetworkUtility.ts index 40f663624..8c3b02e20 100644 --- a/src/Utils/NetworkUtility.ts +++ b/src/Utils/NetworkUtility.ts @@ -2,12 +2,7 @@ import { CassandraProxyEndpoints, MongoProxyEndpoints, PortalBackendEndpoints } import { configContext } from "ConfigContext"; import { checkFirewallRules } from "Explorer/Tabs/Shared/CheckFirewallRules"; import { userContext } from "UserContext"; -import { - CassandraProxyOutboundIPs, - MongoProxyOutboundIPs, - PortalBackendIPs, - PortalBackendOutboundIPs, -} from "Utils/EndpointUtils"; +import { CassandraProxyOutboundIPs, MongoProxyOutboundIPs, PortalBackendOutboundIPs } from "Utils/EndpointUtils"; export const getNetworkSettingsWarningMessage = async ( setStateFunc: (warningMessage: string) => void, @@ -61,7 +56,7 @@ export const getNetworkSettingsWarningMessage = async ( ...PortalBackendOutboundIPs[PortalBackendEndpoints.Prod], ] : PortalBackendOutboundIPs[configContext.PORTAL_BACKEND_ENDPOINT]; - let portalIPs: string[] = [...portalBackendOutboundIPs, ...PortalBackendIPs[configContext.BACKEND_ENDPOINT]]; + let portalIPs: string[] = [...portalBackendOutboundIPs]; if (userContext.apiType === "Mongo") { const isProdOrMpacMongoProxyEndpoint: boolean = [MongoProxyEndpoints.Mpac, MongoProxyEndpoints.Prod].includes( diff --git a/webpack.config.js b/webpack.config.js index 043188275..c21baf3ef 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -301,7 +301,7 @@ module.exports = function (_env = {}, argv = {}) { }, proxy: { "/api": { - target: "https://main.documentdb.ext.azure.com", + target: "https://cdb-ms-mpac-pbe.cosmos.azure.com", changeOrigin: true, logLevel: "debug", bypass: (req, res) => { @@ -312,7 +312,7 @@ module.exports = function (_env = {}, argv = {}) { }, }, "/proxy": { - target: "https://main.documentdb.ext.azure.com", + target: "https://cdb-ms-mpac-pbe.cosmos.azure.com", changeOrigin: true, secure: false, logLevel: "debug",