2022-01-24 21:06:43 +00:00
|
|
|
import {
|
|
|
|
allowedAadEndpoints,
|
|
|
|
allowedArcadiaEndpoints,
|
|
|
|
allowedEmulatorEndpoints,
|
|
|
|
allowedGraphEndpoints,
|
|
|
|
allowedHostedExplorerEndpoints,
|
|
|
|
allowedJunoOrigins,
|
|
|
|
allowedMongoBackendEndpoints,
|
|
|
|
allowedMsalRedirectEndpoints,
|
2023-08-03 19:47:50 +01:00
|
|
|
defaultAllowedArmEndpoints,
|
|
|
|
defaultAllowedBackendEndpoints,
|
2022-01-24 21:06:43 +00:00
|
|
|
validateEndpoint,
|
|
|
|
} from "Utils/EndpointValidation";
|
2021-11-30 22:08:38 +00:00
|
|
|
|
2020-05-26 03:30:55 +01:00
|
|
|
export enum Platform {
|
|
|
|
Portal = "Portal",
|
|
|
|
Hosted = "Hosted",
|
2021-01-20 15:15:01 +00:00
|
|
|
Emulator = "Emulator",
|
2023-09-15 16:33:27 +01:00
|
|
|
Fabric = "Fabric",
|
2020-05-26 03:30:55 +01:00
|
|
|
}
|
|
|
|
|
2021-01-25 19:56:15 +00:00
|
|
|
export interface ConfigContext {
|
2020-05-26 03:30:55 +01:00
|
|
|
platform: Platform;
|
2023-08-03 19:47:50 +01:00
|
|
|
allowedArmEndpoints: ReadonlyArray<string>;
|
|
|
|
allowedBackendEndpoints: ReadonlyArray<string>;
|
2022-01-24 21:06:43 +00:00
|
|
|
allowedParentFrameOrigins: ReadonlyArray<string>;
|
2020-05-26 03:30:55 +01:00
|
|
|
gitSha?: string;
|
|
|
|
proxyPath?: string;
|
|
|
|
AAD_ENDPOINT: string;
|
|
|
|
ARM_AUTH_AREA: string;
|
|
|
|
ARM_ENDPOINT: string;
|
|
|
|
EMULATOR_ENDPOINT?: string;
|
|
|
|
ARM_API_VERSION: string;
|
|
|
|
GRAPH_ENDPOINT: string;
|
|
|
|
GRAPH_API_VERSION: string;
|
|
|
|
ARCADIA_ENDPOINT: string;
|
|
|
|
ARCADIA_LIVY_ENDPOINT_DNS_ZONE: string;
|
|
|
|
BACKEND_ENDPOINT?: string;
|
|
|
|
MONGO_BACKEND_ENDPOINT?: string;
|
|
|
|
PROXY_PATH?: string;
|
|
|
|
JUNO_ENDPOINT: string;
|
|
|
|
GITHUB_CLIENT_ID: string;
|
2021-11-30 22:08:38 +00:00
|
|
|
GITHUB_TEST_ENV_CLIENT_ID: string;
|
2020-05-26 03:30:55 +01:00
|
|
|
GITHUB_CLIENT_SECRET?: string; // No need to inject secret for prod. Juno already knows it.
|
2021-12-13 14:23:33 +00:00
|
|
|
isTerminalEnabled: boolean;
|
2022-03-01 18:38:30 +00:00
|
|
|
isPhoenixEnabled: boolean;
|
2020-05-26 03:30:55 +01:00
|
|
|
hostedExplorerURL: string;
|
2020-10-02 16:45:32 +01:00
|
|
|
armAPIVersion?: string;
|
2021-05-28 04:13:18 +01:00
|
|
|
msalRedirectURI?: string;
|
2020-05-26 03:30:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Default configuration
|
2020-08-06 20:03:46 +01:00
|
|
|
let configContext: Readonly<ConfigContext> = {
|
2020-05-26 03:30:55 +01:00
|
|
|
platform: Platform.Portal,
|
2023-08-03 19:47:50 +01:00
|
|
|
allowedArmEndpoints: defaultAllowedArmEndpoints,
|
|
|
|
allowedBackendEndpoints: defaultAllowedBackendEndpoints,
|
2020-09-17 22:13:22 +01:00
|
|
|
allowedParentFrameOrigins: [
|
2020-09-30 00:09:11 +01:00
|
|
|
`^https:\\/\\/cosmos\\.azure\\.(com|cn|us)$`,
|
|
|
|
`^https:\\/\\/[\\.\\w]*portal\\.azure\\.(com|cn|us)$`,
|
2022-03-25 19:59:18 +00:00
|
|
|
`^https:\\/\\/[\\.\\w]*portal\\.microsoftazure\\.de$`,
|
2020-09-30 00:09:11 +01:00
|
|
|
`^https:\\/\\/[\\.\\w]*ext\\.azure\\.(com|cn|us)$`,
|
|
|
|
`^https:\\/\\/[\\.\\w]*\\.ext\\.microsoftazure\\.de$`,
|
2022-03-25 19:59:18 +00:00
|
|
|
`^https:\\/\\/cosmos-db-dataexplorer-germanycentral\\.azurewebsites\\.de$`,
|
2023-09-28 16:26:50 +01:00
|
|
|
`^https:\\/\\/.*\\.fabric\\.microsoft\\.com$`,
|
|
|
|
`^https:\\/\\/.*\\.powerbi\\.com$`,
|
|
|
|
`^https:\\/\\/.*\\.analysis-df\\.net$`,
|
2023-10-19 22:12:52 +01:00
|
|
|
`^https:\\/\\/.*\\.analysis-df\\.windows\\.net$`,
|
2022-01-24 21:06:43 +00:00
|
|
|
], // Webpack injects this at build time
|
2020-05-26 03:30:55 +01:00
|
|
|
gitSha: process.env.GIT_SHA,
|
|
|
|
hostedExplorerURL: "https://cosmos.azure.com/",
|
|
|
|
AAD_ENDPOINT: "https://login.microsoftonline.com/",
|
|
|
|
ARM_AUTH_AREA: "https://management.azure.com/",
|
|
|
|
ARM_ENDPOINT: "https://management.azure.com/",
|
|
|
|
ARM_API_VERSION: "2016-06-01",
|
2023-09-28 19:42:40 +01:00
|
|
|
GRAPH_ENDPOINT: "https://graph.microsoft.com",
|
2020-05-26 03:30:55 +01:00
|
|
|
GRAPH_API_VERSION: "1.6",
|
|
|
|
ARCADIA_ENDPOINT: "https://workspaceartifacts.projectarcadia.net",
|
|
|
|
ARCADIA_LIVY_ENDPOINT_DNS_ZONE: "dev.azuresynapse.net",
|
2021-11-30 22:08:38 +00:00
|
|
|
GITHUB_CLIENT_ID: "6cb2f63cf6f7b5cbdeca", // Registered OAuth app: https://github.com/organizations/AzureCosmosDBNotebooks/settings/applications/1189306
|
|
|
|
GITHUB_TEST_ENV_CLIENT_ID: "b63fc8cbf87fd3c6e2eb", // Registered OAuth app: https://github.com/organizations/AzureCosmosDBNotebooks/settings/applications/1777772
|
2020-10-12 15:23:57 +01:00
|
|
|
JUNO_ENDPOINT: "https://tools.cosmos.azure.com",
|
2021-01-20 15:15:01 +00:00
|
|
|
BACKEND_ENDPOINT: "https://main.documentdb.ext.azure.com",
|
2021-12-13 14:23:33 +00:00
|
|
|
isTerminalEnabled: false,
|
2022-03-01 18:38:30 +00:00
|
|
|
isPhoenixEnabled: false,
|
2020-05-26 03:30:55 +01:00
|
|
|
};
|
|
|
|
|
2020-08-06 20:03:46 +01:00
|
|
|
export function resetConfigContext(): void {
|
|
|
|
if (process.env.NODE_ENV !== "test") {
|
2023-08-03 19:47:50 +01:00
|
|
|
throw new Error("resetConfigContext can only be called in a test environment");
|
2020-08-06 20:03:46 +01:00
|
|
|
}
|
|
|
|
configContext = {} as ConfigContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function updateConfigContext(newContext: Partial<ConfigContext>): void {
|
2022-01-24 21:06:43 +00:00
|
|
|
if (!newContext) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-03 19:47:50 +01:00
|
|
|
if (!validateEndpoint(newContext.ARM_ENDPOINT, configContext.allowedArmEndpoints || defaultAllowedArmEndpoints)) {
|
2022-01-24 21:06:43 +00:00
|
|
|
delete newContext.ARM_ENDPOINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validateEndpoint(newContext.AAD_ENDPOINT, allowedAadEndpoints)) {
|
|
|
|
delete newContext.AAD_ENDPOINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validateEndpoint(newContext.EMULATOR_ENDPOINT, allowedEmulatorEndpoints)) {
|
|
|
|
delete newContext.EMULATOR_ENDPOINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validateEndpoint(newContext.GRAPH_ENDPOINT, allowedGraphEndpoints)) {
|
|
|
|
delete newContext.GRAPH_ENDPOINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validateEndpoint(newContext.ARCADIA_ENDPOINT, allowedArcadiaEndpoints)) {
|
|
|
|
delete newContext.ARCADIA_ENDPOINT;
|
|
|
|
}
|
|
|
|
|
2023-08-03 19:47:50 +01:00
|
|
|
if (
|
|
|
|
!validateEndpoint(
|
|
|
|
newContext.BACKEND_ENDPOINT,
|
2023-10-03 16:13:24 +01:00
|
|
|
configContext.allowedBackendEndpoints || defaultAllowedBackendEndpoints,
|
2023-08-03 19:47:50 +01:00
|
|
|
)
|
|
|
|
) {
|
2022-01-24 21:06:43 +00:00
|
|
|
delete newContext.BACKEND_ENDPOINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validateEndpoint(newContext.MONGO_BACKEND_ENDPOINT, allowedMongoBackendEndpoints)) {
|
|
|
|
delete newContext.MONGO_BACKEND_ENDPOINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validateEndpoint(newContext.JUNO_ENDPOINT, allowedJunoOrigins)) {
|
|
|
|
delete newContext.JUNO_ENDPOINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validateEndpoint(newContext.hostedExplorerURL, allowedHostedExplorerEndpoints)) {
|
|
|
|
delete newContext.hostedExplorerURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!validateEndpoint(newContext.msalRedirectURI, allowedMsalRedirectEndpoints)) {
|
|
|
|
delete newContext.msalRedirectURI;
|
|
|
|
}
|
|
|
|
|
2020-08-06 20:03:46 +01:00
|
|
|
Object.assign(configContext, newContext);
|
|
|
|
}
|
|
|
|
|
2023-08-03 19:47:50 +01:00
|
|
|
// Injected for local development. These will be removed in the production bundle by webpack
|
2020-05-26 03:30:55 +01:00
|
|
|
if (process.env.NODE_ENV === "development") {
|
|
|
|
const port: string = process.env.PORT || "1234";
|
2020-08-06 20:03:46 +01:00
|
|
|
updateConfigContext({
|
|
|
|
BACKEND_ENDPOINT: "https://localhost:" + port,
|
|
|
|
MONGO_BACKEND_ENDPOINT: "https://localhost:" + port,
|
|
|
|
PROXY_PATH: "/proxy",
|
2021-01-20 15:15:01 +00:00
|
|
|
EMULATOR_ENDPOINT: "https://localhost:8081",
|
2020-08-06 20:03:46 +01:00
|
|
|
});
|
2020-05-26 03:30:55 +01:00
|
|
|
}
|
|
|
|
|
2020-08-06 20:03:46 +01:00
|
|
|
export async function initializeConfiguration(): Promise<ConfigContext> {
|
2020-05-26 03:30:55 +01:00
|
|
|
try {
|
2021-02-04 09:55:13 +00:00
|
|
|
const response = await fetch("./config.json", {
|
|
|
|
headers: {
|
|
|
|
"If-None-Match": "", // disable client side cache
|
|
|
|
},
|
|
|
|
});
|
2020-05-26 03:30:55 +01:00
|
|
|
if (response.status === 200) {
|
|
|
|
try {
|
2022-01-24 21:06:43 +00:00
|
|
|
const { ...externalConfig } = await response.json();
|
|
|
|
updateConfigContext(externalConfig);
|
2020-05-26 03:30:55 +01:00
|
|
|
} catch (error) {
|
|
|
|
console.error("Unable to parse json in config file");
|
|
|
|
console.error(error);
|
|
|
|
}
|
|
|
|
}
|
2020-08-26 06:48:58 +01:00
|
|
|
// Allow override of platform value with URL query parameter
|
2020-05-26 03:30:55 +01:00
|
|
|
const params = new URLSearchParams(window.location.search);
|
2020-10-02 16:45:32 +01:00
|
|
|
if (params.has("armAPIVersion")) {
|
|
|
|
const armAPIVersion = params.get("armAPIVersion") || "";
|
|
|
|
updateConfigContext({ armAPIVersion });
|
|
|
|
}
|
2021-06-16 15:13:11 +01:00
|
|
|
if (params.has("armEndpoint")) {
|
|
|
|
const ARM_ENDPOINT = params.get("armEndpoint") || "";
|
|
|
|
updateConfigContext({ ARM_ENDPOINT });
|
|
|
|
}
|
|
|
|
if (params.has("aadEndpoint")) {
|
|
|
|
const AAD_ENDPOINT = params.get("aadEndpoint") || "";
|
|
|
|
updateConfigContext({ AAD_ENDPOINT });
|
|
|
|
}
|
2020-08-26 06:48:58 +01:00
|
|
|
if (params.has("platform")) {
|
|
|
|
const platform = params.get("platform");
|
|
|
|
switch (platform) {
|
|
|
|
default:
|
2021-01-19 22:31:55 +00:00
|
|
|
console.error(`Invalid platform query parameter: ${platform}`);
|
2020-08-26 06:48:58 +01:00
|
|
|
break;
|
|
|
|
case Platform.Portal:
|
2023-09-15 16:33:27 +01:00
|
|
|
case Platform.Fabric:
|
2020-08-26 06:48:58 +01:00
|
|
|
case Platform.Hosted:
|
|
|
|
case Platform.Emulator:
|
|
|
|
updateConfigContext({ platform });
|
|
|
|
}
|
|
|
|
}
|
2020-05-26 03:30:55 +01:00
|
|
|
} catch (error) {
|
2021-01-19 22:31:55 +00:00
|
|
|
console.error("No configuration file found using defaults");
|
2020-05-26 03:30:55 +01:00
|
|
|
}
|
2020-08-06 20:03:46 +01:00
|
|
|
return configContext;
|
2020-05-26 03:30:55 +01:00
|
|
|
}
|
|
|
|
|
2020-08-06 20:03:46 +01:00
|
|
|
export { configContext };
|