Skip to content

Commit 2730da7

Browse files
bogercraigAsier Isayas
and
Asier Isayas
authored
Backend Migration - Remove Use of Legacy Backend from DE (#2043)
* Default to new backend endpoint if the endpoint in current context does not match existing set in constants. * Remove some env references. * Added comments with reasoning for selecting new backend by default. * Update comment. * Remove all references to useNewPortalBackendEndpoint now that old backend is disabled in all environments. * Resolve lint issues. * Removed references to old backend from Cassandra and Mongo Apis * fix unit tests --------- Co-authored-by: Asier Isayas <[email protected]>
1 parent de2449e commit 2730da7

18 files changed

+42
-1048
lines changed

src/Common/CosmosClient.ts

+1-34
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import { getAuthorizationTokenUsingResourceTokens } from "Common/getAuthorizatio
33
import { AuthorizationToken } from "Contracts/FabricMessageTypes";
44
import { checkDatabaseResourceTokensValidity } from "Platform/Fabric/FabricUtil";
55
import { LocalStorageUtility, StorageKey } from "Shared/StorageUtility";
6-
import { useNewPortalBackendEndpoint } from "Utils/EndpointUtils";
76
import { AuthType } from "../AuthType";
8-
import { BackendApi, PriorityLevel } from "../Common/Constants";
7+
import { PriorityLevel } from "../Common/Constants";
98
import * as Logger from "../Common/Logger";
109
import { Platform, configContext } from "../ConfigContext";
1110
import { updateUserContext, userContext } from "../UserContext";
@@ -125,10 +124,6 @@ export async function getTokenFromAuthService(
125124
resourceType: string,
126125
resourceId?: string,
127126
): Promise<AuthorizationToken> {
128-
if (!useNewPortalBackendEndpoint(BackendApi.RuntimeProxy)) {
129-
return getTokenFromAuthService_ToBeDeprecated(verb, resourceType, resourceId);
130-
}
131-
132127
try {
133128
const host: string = configContext.PORTAL_BACKEND_ENDPOINT;
134129
const response: Response = await _global.fetch(host + "/api/connectionstring/runtimeproxy/authorizationtokens", {
@@ -151,34 +146,6 @@ export async function getTokenFromAuthService(
151146
}
152147
}
153148

154-
export async function getTokenFromAuthService_ToBeDeprecated(
155-
verb: string,
156-
resourceType: string,
157-
resourceId?: string,
158-
): Promise<AuthorizationToken> {
159-
try {
160-
const host = configContext.BACKEND_ENDPOINT;
161-
const response = await _global.fetch(host + "/api/guest/runtimeproxy/authorizationTokens", {
162-
method: "POST",
163-
headers: {
164-
"content-type": "application/json",
165-
"x-ms-encrypted-auth-token": userContext.accessToken,
166-
},
167-
body: JSON.stringify({
168-
verb,
169-
resourceType,
170-
resourceId,
171-
}),
172-
});
173-
//TODO I am not sure why we have to parse the JSON again here. fetch should do it for us when we call .json()
174-
const result = JSON.parse(await response.json());
175-
return result;
176-
} catch (error) {
177-
logConsoleError(`Failed to get authorization headers for ${resourceType}: ${getErrorMessage(error)}`);
178-
return Promise.reject(error);
179-
}
180-
}
181-
182149
// The Capability is a bitmap, which cosmosdb backend decodes as per the below enum
183150
enum SDKSupportedCapabilities {
184151
None = 0,

src/Common/MongoProxyClient.test.ts

+6-55
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,8 @@ import { configContext, resetConfigContext, updateConfigContext } from "../Confi
44
import { DatabaseAccount } from "../Contracts/DataModels";
55
import { Collection } from "../Contracts/ViewModels";
66
import DocumentId from "../Explorer/Tree/DocumentId";
7-
import { extractFeatures } from "../Platform/Hosted/extractFeatures";
87
import { updateUserContext } from "../UserContext";
9-
import {
10-
deleteDocument,
11-
getEndpoint,
12-
getFeatureEndpointOrDefault,
13-
queryDocuments,
14-
readDocument,
15-
updateDocument,
16-
} from "./MongoProxyClient";
8+
import { deleteDocuments, getEndpoint, queryDocuments, readDocument, updateDocument } from "./MongoProxyClient";
179

1810
const databaseId = "testDB";
1911

@@ -196,20 +188,8 @@ describe("MongoProxyClient", () => {
196188
expect.any(Object),
197189
);
198190
});
199-
200-
it("builds the correct proxy URL in development", () => {
201-
updateConfigContext({
202-
MONGO_BACKEND_ENDPOINT: "https://localhost:1234",
203-
globallyEnabledMongoAPIs: [],
204-
});
205-
updateDocument(databaseId, collection, documentId, "{}");
206-
expect(window.fetch).toHaveBeenCalledWith(
207-
`${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`,
208-
expect.any(Object),
209-
);
210-
});
211191
});
212-
describe("deleteDocument", () => {
192+
describe("deleteDocuments", () => {
213193
beforeEach(() => {
214194
resetConfigContext();
215195
updateUserContext({
@@ -226,9 +206,9 @@ describe("MongoProxyClient", () => {
226206
});
227207

228208
it("builds the correct URL", () => {
229-
deleteDocument(databaseId, collection, documentId);
209+
deleteDocuments(databaseId, collection, [documentId]);
230210
expect(window.fetch).toHaveBeenCalledWith(
231-
`${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`,
211+
`${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer/bulkdelete`,
232212
expect.any(Object),
233213
);
234214
});
@@ -238,9 +218,9 @@ describe("MongoProxyClient", () => {
238218
MONGO_PROXY_ENDPOINT: "https://localhost:1234",
239219
globallyEnabledMongoAPIs: [],
240220
});
241-
deleteDocument(databaseId, collection, documentId);
221+
deleteDocuments(databaseId, collection, [documentId]);
242222
expect(window.fetch).toHaveBeenCalledWith(
243-
`${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`,
223+
`${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer/bulkdelete`,
244224
expect.any(Object),
245225
);
246226
});
@@ -275,33 +255,4 @@ describe("MongoProxyClient", () => {
275255
expect(endpoint).toEqual(`${configContext.MONGO_PROXY_ENDPOINT}/api/connectionstring/mongo/explorer`);
276256
});
277257
});
278-
279-
describe("getFeatureEndpointOrDefault", () => {
280-
beforeEach(() => {
281-
resetConfigContext();
282-
updateConfigContext({
283-
MONGO_PROXY_ENDPOINT: MongoProxyEndpoints.Prod,
284-
globallyEnabledMongoAPIs: [],
285-
});
286-
const params = new URLSearchParams({
287-
"feature.mongoProxyEndpoint": MongoProxyEndpoints.Prod,
288-
"feature.mongoProxyAPIs": "readDocument|createDocument",
289-
});
290-
const features = extractFeatures(params);
291-
updateUserContext({
292-
authType: AuthType.AAD,
293-
features: features,
294-
});
295-
});
296-
297-
it("returns a local endpoint", () => {
298-
const endpoint = getFeatureEndpointOrDefault("readDocument");
299-
expect(endpoint).toEqual(`${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`);
300-
});
301-
302-
it("returns a production endpoint", () => {
303-
const endpoint = getFeatureEndpointOrDefault("DeleteDocument");
304-
expect(endpoint).toEqual(`${configContext.MONGO_PROXY_ENDPOINT}/api/mongo/explorer`);
305-
});
306-
});
307258
});

0 commit comments

Comments
 (0)