mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-11-25 15:06:55 +00:00
Remove one indirection for ConfigContext
Things like ConfigContext.BACKEND_ENDPOINT are dynamically changed, and assigning them statically like this only bypasses that mechanism :( Co-authored-by: Steve Faulkner <471400+southpolesteve@users.noreply.github.com>
This commit is contained in:
parent
f5bbd52311
commit
0cc38868a6
@ -1,5 +1,4 @@
|
||||
import { AutopilotTier } from "../Contracts/DataModels";
|
||||
import { configContext } from "../ConfigContext";
|
||||
import { HashMap } from "./HashMap";
|
||||
|
||||
export class AuthorizationEndpoints {
|
||||
@ -13,12 +12,6 @@ export class CodeOfConductEndpoints {
|
||||
public static termsOfUse: string = "https://aka.ms/ms-terms-of-use";
|
||||
}
|
||||
|
||||
export class BackendEndpoints {
|
||||
public static localhost: string = "https://localhost:12900";
|
||||
public static dev: string = "https://ext.documents-dev.windows-int.net";
|
||||
public static productionPortal: string = configContext.BACKEND_ENDPOINT || "https://main.documentdb.ext.azure.com";
|
||||
}
|
||||
|
||||
export class EndpointsRegex {
|
||||
public static readonly cassandra = [
|
||||
"AccountEndpoint=(.*).cassandra.cosmosdb.azure.com",
|
||||
|
@ -14,7 +14,9 @@ describe("tokenProvider", () => {
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
window.dataExplorer = { extensionEndpoint: () => "https://main.documentdb.ext.azure.com" } as any;
|
||||
updateConfigContext({
|
||||
BACKEND_ENDPOINT: "https://main.documentdb.ext.azure.com"
|
||||
});
|
||||
window.fetch = jest.fn().mockImplementation(() => {
|
||||
return {
|
||||
json: () => "{}",
|
||||
@ -58,7 +60,9 @@ describe("getTokenFromAuthService", () => {
|
||||
});
|
||||
|
||||
it("builds the correct URL in production", () => {
|
||||
window.dataExplorer = { extensionEndpoint: () => "https://main.documentdb.ext.azure.com" } as any;
|
||||
updateConfigContext({
|
||||
BACKEND_ENDPOINT: "https://main.documentdb.ext.azure.com"
|
||||
});
|
||||
getTokenFromAuthService("GET", "dbs", "foo");
|
||||
expect(window.fetch).toHaveBeenCalledWith(
|
||||
"https://main.documentdb.ext.azure.com/api/guest/runtimeproxy/authorizationTokens",
|
||||
|
@ -52,7 +52,7 @@ export const endpoint = () => {
|
||||
|
||||
export async function getTokenFromAuthService(verb: string, resourceType: string, resourceId?: string): Promise<any> {
|
||||
try {
|
||||
const host = configContext.BACKEND_ENDPOINT || _global.dataExplorer.extensionEndpoint();
|
||||
const host = configContext.BACKEND_ENDPOINT;
|
||||
const response = await _global.fetch(host + "/api/guest/runtimeproxy/authorizationTokens", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
@ -85,8 +85,7 @@ export function client(): Cosmos.CosmosClient {
|
||||
userAgentSuffix: "Azure Portal"
|
||||
};
|
||||
|
||||
// In development we proxy requests to the backend via webpack. This is removed in production bundles.
|
||||
if (process.env.NODE_ENV === "development") {
|
||||
if (configContext.PROXY_PATH !== undefined) {
|
||||
(options as any).plugins = [{ on: "request", plugin: requestPlugin }];
|
||||
}
|
||||
return new Cosmos.CosmosClient(options);
|
||||
|
@ -63,10 +63,9 @@ describe("MongoProxyClient", () => {
|
||||
updateUserContext({
|
||||
databaseAccount
|
||||
});
|
||||
window.dataExplorer = {
|
||||
extensionEndpoint: () => "https://main.documentdb.ext.azure.com",
|
||||
serverId: () => ""
|
||||
} as any;
|
||||
updateConfigContext({
|
||||
BACKEND_ENDPOINT: "https://main.documentdb.ext.azure.com"
|
||||
});
|
||||
window.fetch = jest.fn().mockImplementation(fetchMock);
|
||||
});
|
||||
afterEach(() => {
|
||||
@ -96,10 +95,9 @@ describe("MongoProxyClient", () => {
|
||||
updateUserContext({
|
||||
databaseAccount
|
||||
});
|
||||
window.dataExplorer = {
|
||||
extensionEndpoint: () => "https://main.documentdb.ext.azure.com",
|
||||
serverId: () => ""
|
||||
} as any;
|
||||
updateConfigContext({
|
||||
BACKEND_ENDPOINT: "https://main.documentdb.ext.azure.com"
|
||||
});
|
||||
window.fetch = jest.fn().mockImplementation(fetchMock);
|
||||
});
|
||||
afterEach(() => {
|
||||
@ -129,10 +127,9 @@ describe("MongoProxyClient", () => {
|
||||
updateUserContext({
|
||||
databaseAccount
|
||||
});
|
||||
window.dataExplorer = {
|
||||
extensionEndpoint: () => "https://main.documentdb.ext.azure.com",
|
||||
serverId: () => ""
|
||||
} as any;
|
||||
updateConfigContext({
|
||||
BACKEND_ENDPOINT: "https://main.documentdb.ext.azure.com"
|
||||
});
|
||||
window.fetch = jest.fn().mockImplementation(fetchMock);
|
||||
});
|
||||
afterEach(() => {
|
||||
@ -162,10 +159,9 @@ describe("MongoProxyClient", () => {
|
||||
updateUserContext({
|
||||
databaseAccount
|
||||
});
|
||||
window.dataExplorer = {
|
||||
extensionEndpoint: () => "https://main.documentdb.ext.azure.com",
|
||||
serverId: () => ""
|
||||
} as any;
|
||||
updateConfigContext({
|
||||
BACKEND_ENDPOINT: "https://main.documentdb.ext.azure.com"
|
||||
});
|
||||
window.fetch = jest.fn().mockImplementation(fetchMock);
|
||||
});
|
||||
afterEach(() => {
|
||||
@ -195,10 +191,9 @@ describe("MongoProxyClient", () => {
|
||||
updateUserContext({
|
||||
databaseAccount
|
||||
});
|
||||
window.dataExplorer = {
|
||||
extensionEndpoint: () => "https://main.documentdb.ext.azure.com",
|
||||
serverId: () => ""
|
||||
} as any;
|
||||
updateConfigContext({
|
||||
BACKEND_ENDPOINT: "https://main.documentdb.ext.azure.com"
|
||||
});
|
||||
window.fetch = jest.fn().mockImplementation(fetchMock);
|
||||
});
|
||||
afterEach(() => {
|
||||
@ -229,10 +224,9 @@ describe("MongoProxyClient", () => {
|
||||
updateUserContext({
|
||||
databaseAccount
|
||||
});
|
||||
window.dataExplorer = {
|
||||
extensionEndpoint: () => "https://main.documentdb.ext.azure.com",
|
||||
serverId: () => ""
|
||||
} as any;
|
||||
updateConfigContext({
|
||||
BACKEND_ENDPOINT: "https://main.documentdb.ext.azure.com"
|
||||
});
|
||||
});
|
||||
|
||||
it("returns a production endpoint", () => {
|
||||
|
@ -327,8 +327,7 @@ export function createMongoCollectionWithProxy(
|
||||
}
|
||||
|
||||
export function getEndpoint(): string {
|
||||
const extensionEndpoint = window.dataExplorer.extensionEndpoint();
|
||||
let url = (configContext.MONGO_BACKEND_ENDPOINT || extensionEndpoint) + "/api/mongo/explorer";
|
||||
let url = (configContext.MONGO_BACKEND_ENDPOINT || configContext.BACKEND_ENDPOINT) + "/api/mongo/explorer";
|
||||
|
||||
if (window.authType === AuthType.EncryptedToken) {
|
||||
url = url.replace("api/mongo", "api/guest/mongo");
|
||||
|
@ -9,8 +9,7 @@ describe("updateOfferThroughputBeyondLimit", () => {
|
||||
});
|
||||
window.dataExplorer = {
|
||||
logConsoleData: jest.fn(),
|
||||
deleteInProgressConsoleDataWithId: jest.fn(),
|
||||
extensionEndpoint: jest.fn()
|
||||
deleteInProgressConsoleDataWithId: jest.fn()
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
} as any;
|
||||
await updateOfferThroughputBeyondLimit({
|
||||
|
@ -28,8 +28,7 @@ export async function updateOfferThroughputBeyondLimit(request: UpdateOfferThrou
|
||||
`Requesting increase in throughput to ${request.throughput} for ${resourceDescriptionInfo}`
|
||||
);
|
||||
|
||||
const explorer = window.dataExplorer;
|
||||
const url = `${explorer.extensionEndpoint()}/api/offerthroughputrequest/updatebeyondspecifiedlimit`;
|
||||
const url = `${configContext.BACKEND_ENDPOINT}/api/offerthroughputrequest/updatebeyondspecifiedlimit`;
|
||||
const authorizationHeader = getAuthorizationHeader();
|
||||
|
||||
const response = await fetch(url, {
|
||||
|
@ -953,7 +953,6 @@ exports[`SettingsComponent renders 1`] = `
|
||||
"validPartitionKeyValue": [Function],
|
||||
"visible": [Function],
|
||||
},
|
||||
"extensionEndpoint": [Function],
|
||||
"features": [Function],
|
||||
"flight": [Function],
|
||||
"graphStylingPane": GraphStylingPane {
|
||||
@ -2268,7 +2267,6 @@ exports[`SettingsComponent renders 1`] = `
|
||||
"validPartitionKeyValue": [Function],
|
||||
"visible": [Function],
|
||||
},
|
||||
"extensionEndpoint": [Function],
|
||||
"features": [Function],
|
||||
"flight": [Function],
|
||||
"graphStylingPane": GraphStylingPane {
|
||||
@ -3596,7 +3594,6 @@ exports[`SettingsComponent renders 1`] = `
|
||||
"validPartitionKeyValue": [Function],
|
||||
"visible": [Function],
|
||||
},
|
||||
"extensionEndpoint": [Function],
|
||||
"features": [Function],
|
||||
"flight": [Function],
|
||||
"graphStylingPane": GraphStylingPane {
|
||||
@ -4911,7 +4908,6 @@ exports[`SettingsComponent renders 1`] = `
|
||||
"validPartitionKeyValue": [Function],
|
||||
"visible": [Function],
|
||||
},
|
||||
"extensionEndpoint": [Function],
|
||||
"features": [Function],
|
||||
"flight": [Function],
|
||||
"graphStylingPane": GraphStylingPane {
|
||||
|
@ -140,7 +140,6 @@ export default class Explorer {
|
||||
public canSaveQueries: ko.Computed<boolean>;
|
||||
public features: ko.Observable<any>;
|
||||
public serverId: ko.Observable<string>;
|
||||
public extensionEndpoint: ko.Observable<string>;
|
||||
public armEndpoint: ko.Observable<string>;
|
||||
public isTryCosmosDBSubscription: ko.Observable<boolean>;
|
||||
public notificationsClient: NotificationsClientBase;
|
||||
@ -383,7 +382,6 @@ export default class Explorer {
|
||||
|
||||
this.features = ko.observable();
|
||||
this.serverId = ko.observable<string>();
|
||||
this.extensionEndpoint = ko.observable<string>(undefined);
|
||||
this.armEndpoint = ko.observable<string>(undefined);
|
||||
this.queriesClient = new QueriesClient(this);
|
||||
this.isTryCosmosDBSubscription = ko.observable<boolean>(false);
|
||||
@ -1912,9 +1910,8 @@ export default class Explorer {
|
||||
}
|
||||
this.features(inputs.features);
|
||||
this.serverId(inputs.serverId);
|
||||
this.extensionEndpoint(inputs.extensionEndpoint || "");
|
||||
this.armEndpoint(EnvironmentUtility.normalizeArmEndpointUri(inputs.csmEndpoint || configContext.ARM_ENDPOINT));
|
||||
this.notificationsClient.setExtensionEndpoint(this.extensionEndpoint());
|
||||
this.notificationsClient.setExtensionEndpoint(configContext.BACKEND_ENDPOINT);
|
||||
this.databaseAccount(databaseAccount);
|
||||
this.subscriptionType(inputs.subscriptionType);
|
||||
this.quotaId(inputs.quotaId);
|
||||
@ -1930,6 +1927,7 @@ export default class Explorer {
|
||||
this._importExplorerConfigComplete = true;
|
||||
|
||||
updateConfigContext({
|
||||
BACKEND_ENDPOINT: inputs.extensionEndpoint || "",
|
||||
ARM_ENDPOINT: this.armEndpoint()
|
||||
});
|
||||
|
||||
@ -2633,7 +2631,7 @@ export default class Explorer {
|
||||
|
||||
const databaseAccount = this.databaseAccount();
|
||||
const databaseAccountLocation = databaseAccount && databaseAccount.location.toLowerCase();
|
||||
const disallowedLocationsUri = `${this.extensionEndpoint()}/api/disallowedLocations`;
|
||||
const disallowedLocationsUri = `${configContext.BACKEND_ENDPOINT}/api/disallowedLocations`;
|
||||
const authorizationHeader = getAuthorizationHeader();
|
||||
try {
|
||||
const response = await fetch(disallowedLocationsUri, {
|
||||
|
@ -22,6 +22,7 @@ import {
|
||||
updateDocument,
|
||||
createDocument
|
||||
} from "../../Common/DocumentClientUtilityBase";
|
||||
import { configContext } from "../../ConfigContext";
|
||||
|
||||
export interface CassandraTableKeys {
|
||||
partitionKeys: CassandraTableKey[];
|
||||
@ -307,7 +308,7 @@ export class CassandraAPIDataClient extends TableDataClient {
|
||||
authType === AuthType.EncryptedToken
|
||||
? Constants.CassandraBackend.guestQueryApi
|
||||
: Constants.CassandraBackend.queryApi;
|
||||
$.ajax(`${collection.container.extensionEndpoint()}/${apiEndpoint}`, {
|
||||
$.ajax(`${configContext.BACKEND_ENDPOINT}/${apiEndpoint}`, {
|
||||
type: "POST",
|
||||
data: {
|
||||
accountName: collection && collection.container.databaseAccount && collection.container.databaseAccount().name,
|
||||
@ -558,7 +559,7 @@ export class CassandraAPIDataClient extends TableDataClient {
|
||||
authType === AuthType.EncryptedToken
|
||||
? Constants.CassandraBackend.guestKeysApi
|
||||
: Constants.CassandraBackend.keysApi;
|
||||
let endpoint = `${collection.container.extensionEndpoint()}/${apiEndpoint}`;
|
||||
let endpoint = `${configContext.BACKEND_ENDPOINT}/${apiEndpoint}`;
|
||||
const deferred = Q.defer<CassandraTableKeys>();
|
||||
$.ajax(endpoint, {
|
||||
type: "POST",
|
||||
@ -613,7 +614,7 @@ export class CassandraAPIDataClient extends TableDataClient {
|
||||
authType === AuthType.EncryptedToken
|
||||
? Constants.CassandraBackend.guestSchemaApi
|
||||
: Constants.CassandraBackend.schemaApi;
|
||||
let endpoint = `${collection.container.extensionEndpoint()}/${apiEndpoint}`;
|
||||
let endpoint = `${configContext.BACKEND_ENDPOINT}/${apiEndpoint}`;
|
||||
const deferred = Q.defer<CassandraTableKey[]>();
|
||||
$.ajax(endpoint, {
|
||||
type: "POST",
|
||||
@ -667,7 +668,7 @@ export class CassandraAPIDataClient extends TableDataClient {
|
||||
authType === AuthType.EncryptedToken
|
||||
? Constants.CassandraBackend.guestCreateOrDeleteApi
|
||||
: Constants.CassandraBackend.createOrDeleteApi;
|
||||
$.ajax(`${explorer.extensionEndpoint()}/${apiEndpoint}`, {
|
||||
$.ajax(`${configContext.BACKEND_ENDPOINT}/${apiEndpoint}`, {
|
||||
type: "POST",
|
||||
data: {
|
||||
accountName: explorer.databaseAccount() && explorer.databaseAccount().name,
|
||||
|
@ -13,6 +13,7 @@ import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils"
|
||||
import { PlatformType } from "../../PlatformType";
|
||||
import Explorer from "../Explorer";
|
||||
import { userContext } from "../../UserContext";
|
||||
import { configContext } from "../../ConfigContext";
|
||||
|
||||
export default class MongoShellTab extends TabsBase {
|
||||
public url: ko.Computed<string>;
|
||||
@ -30,9 +31,8 @@ export default class MongoShellTab extends TabsBase {
|
||||
const accountName = account && account.name;
|
||||
const mongoEndpoint = account && (account.properties.mongoEndpoint || account.properties.documentEndpoint);
|
||||
|
||||
this._runtimeEndpoint =
|
||||
window.dataExplorerPlatform == PlatformType.Hosted ? AuthHeadersUtil.extensionEndpoint : "";
|
||||
const extensionEndpoint: string = this._container.extensionEndpoint() || this._runtimeEndpoint || "";
|
||||
this._runtimeEndpoint = window.dataExplorerPlatform === PlatformType.Hosted ? configContext.BACKEND_ENDPOINT : "";
|
||||
const extensionEndpoint: string = configContext.BACKEND_ENDPOINT || this._runtimeEndpoint || "";
|
||||
let baseUrl = "/content/mongoshell/dist/";
|
||||
if (this._container.serverId() === "localhost") {
|
||||
baseUrl = "/content/mongoshell/";
|
||||
@ -108,7 +108,7 @@ export default class MongoShellTab extends TabsBase {
|
||||
) + Constants.MongoDBAccounts.defaultPort.toString();
|
||||
const databaseId = this.collection.databaseId;
|
||||
const collectionId = this.collection.id();
|
||||
const apiEndpoint = this._container.extensionEndpoint();
|
||||
const apiEndpoint = configContext.BACKEND_ENDPOINT;
|
||||
const encryptedAuthToken: string = userContext.accessToken;
|
||||
|
||||
shellIframe.contentWindow.postMessage(
|
||||
@ -125,7 +125,7 @@ export default class MongoShellTab extends TabsBase {
|
||||
apiEndpoint: apiEndpoint
|
||||
}
|
||||
},
|
||||
this._container.extensionEndpoint()
|
||||
configContext.BACKEND_ENDPOINT
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -12,8 +12,6 @@ import { configContext } from "../../ConfigContext";
|
||||
import { userContext } from "../../UserContext";
|
||||
|
||||
export default class AuthHeadersUtil {
|
||||
// TODO: Figure out a way to determine the extension endpoint and serverId at runtime
|
||||
public static extensionEndpoint: string = Constants.BackendEndpoints.productionPortal;
|
||||
public static serverId: string = Constants.ServerIds.productionPortal;
|
||||
|
||||
private static readonly _firstPartyAppId: string = "203f1145-856a-4232-83d4-a43568fba23d";
|
||||
@ -41,7 +39,7 @@ export default class AuthHeadersUtil {
|
||||
|
||||
public static getAccessInputMetadata(accessInput: string): Q.Promise<DataModels.AccessInputMetadata> {
|
||||
const deferred: Q.Deferred<DataModels.AccessInputMetadata> = Q.defer<DataModels.AccessInputMetadata>();
|
||||
const url: string = `${AuthHeadersUtil.extensionEndpoint}${Constants.ApiEndpoints.guestRuntimeProxy}/accessinputmetadata`;
|
||||
const url = `${configContext.BACKEND_ENDPOINT}${Constants.ApiEndpoints.guestRuntimeProxy}/accessinputmetadata`;
|
||||
const authType: string = (<any>window).authType;
|
||||
const headers: { [headerName: string]: string } = {};
|
||||
|
||||
@ -86,9 +84,7 @@ export default class AuthHeadersUtil {
|
||||
}
|
||||
|
||||
public static generateEncryptedToken(): Q.Promise<DataModels.GenerateTokenResponse> {
|
||||
const url: string = `${
|
||||
AuthHeadersUtil.extensionEndpoint
|
||||
}/api/tokens/generateToken${AuthHeadersUtil._generateResourceUrl()}`;
|
||||
const url = configContext.BACKEND_ENDPOINT + "/api/tokens/generateToken" + AuthHeadersUtil._generateResourceUrl();
|
||||
const explorer = window.dataExplorer;
|
||||
const headers: any = { authorization: userContext.authorizationToken };
|
||||
headers[Constants.HttpHeaders.getReadOnlyKey] = !explorer.hasWriteAccess();
|
||||
@ -109,7 +105,7 @@ export default class AuthHeadersUtil {
|
||||
return Q.reject("None or empty connection string specified");
|
||||
}
|
||||
|
||||
const url: string = `${AuthHeadersUtil.extensionEndpoint}/api/guest/tokens/generateToken`;
|
||||
const url = configContext.BACKEND_ENDPOINT + "/api/guest/tokens/generateToken";
|
||||
const headers: any = {};
|
||||
headers[Constants.HttpHeaders.connectionString] = connectionString;
|
||||
|
||||
|
@ -24,12 +24,12 @@ import { SubscriptionUtilMappings } from "../../Shared/Constants";
|
||||
import "../../Explorer/Tables/DataTable/DataTableBindingManager";
|
||||
import Explorer from "../../Explorer/Explorer";
|
||||
import { updateUserContext } from "../../UserContext";
|
||||
import { configContext } from "../../ConfigContext";
|
||||
|
||||
export default class Main {
|
||||
private static _databaseAccountId: string;
|
||||
private static _encryptedToken: string;
|
||||
private static _accessInputMetadata: AccessInputMetadata;
|
||||
private static _defaultSubscriptionType: ViewModels.SubscriptionType = ViewModels.SubscriptionType.Free;
|
||||
private static _features: { [key: string]: string };
|
||||
// For AAD, Need to post message to hosted frame to do the auth
|
||||
// Use local deferred variable as work around until we find better solution
|
||||
@ -315,7 +315,7 @@ export default class Main {
|
||||
csmEndpoint: undefined,
|
||||
dnsSuffix: null,
|
||||
serverId: serverId,
|
||||
extensionEndpoint: AuthHeadersUtil.extensionEndpoint,
|
||||
extensionEndpoint: configContext.BACKEND_ENDPOINT,
|
||||
subscriptionType: CollectionCreation.DefaultSubscriptionType,
|
||||
quotaId: undefined,
|
||||
addCollectionDefaultFlight: explorer.flight(),
|
||||
@ -335,7 +335,7 @@ export default class Main {
|
||||
csmEndpoint: undefined,
|
||||
dnsSuffix: null,
|
||||
serverId: serverId,
|
||||
extensionEndpoint: AuthHeadersUtil.extensionEndpoint,
|
||||
extensionEndpoint: configContext.BACKEND_ENDPOINT,
|
||||
subscriptionType: CollectionCreation.DefaultSubscriptionType,
|
||||
quotaId: undefined,
|
||||
addCollectionDefaultFlight: explorer.flight(),
|
||||
@ -365,7 +365,7 @@ export default class Main {
|
||||
csmEndpoint: undefined,
|
||||
dnsSuffix: null,
|
||||
serverId: serverId,
|
||||
extensionEndpoint: AuthHeadersUtil.extensionEndpoint,
|
||||
extensionEndpoint: configContext.BACKEND_ENDPOINT,
|
||||
subscriptionType: CollectionCreation.DefaultSubscriptionType,
|
||||
quotaId: undefined,
|
||||
addCollectionDefaultFlight: explorer.flight(),
|
||||
@ -453,11 +453,6 @@ export default class Main {
|
||||
return connectionString && connectionString.includes("type=resource");
|
||||
}
|
||||
|
||||
private static _getSubscriptionTypeFromQuotaId(quotaId: string): ViewModels.SubscriptionType {
|
||||
const subscriptionType: ViewModels.SubscriptionType = SubscriptionUtilMappings.SubscriptionTypeMap[quotaId];
|
||||
return subscriptionType || Main._defaultSubscriptionType;
|
||||
}
|
||||
|
||||
private static _renewExplorerAccessWithResourceToken = (
|
||||
explorer: Explorer,
|
||||
connectionString: string
|
||||
|
Loading…
Reference in New Issue
Block a user