2021-03-15 03:53:16 +00:00
|
|
|
/* eslint-disable no-console */
|
|
|
|
import { ClientSecretCredential } from "@azure/identity";
|
2021-01-20 06:42:45 +00:00
|
|
|
import "../../less/hostedexplorer.less";
|
2021-03-15 03:53:16 +00:00
|
|
|
import { DataExplorerInputsFrame } from "../../src/Contracts/ViewModels";
|
|
|
|
import { updateUserContext } from "../../src/UserContext";
|
2021-05-21 02:34:29 +01:00
|
|
|
import { get, listKeys } from "../../src/Utils/arm/generatedClients/cosmos/databaseAccounts";
|
2020-11-19 17:29:38 +00:00
|
|
|
|
2021-03-15 03:53:16 +00:00
|
|
|
const resourceGroup = process.env.RESOURCE_GROUP || "";
|
|
|
|
const subscriptionId = process.env.SUBSCRIPTION_ID || "";
|
|
|
|
const urlSearchParams = new URLSearchParams(window.location.search);
|
2022-05-05 02:24:34 +01:00
|
|
|
const accountName = urlSearchParams.get("accountName") || "portal-sql-runner-west-us";
|
2021-03-15 03:53:16 +00:00
|
|
|
const selfServeType = urlSearchParams.get("selfServeType") || "example";
|
|
|
|
const iframeSrc = urlSearchParams.get("iframeSrc") || "explorer.html?platform=Portal&disablePortalInitCache";
|
2020-11-19 17:29:38 +00:00
|
|
|
|
2021-03-15 03:53:16 +00:00
|
|
|
if (!process.env.AZURE_CLIENT_SECRET) {
|
|
|
|
throw new Error(
|
|
|
|
"process.env.AZURE_CLIENT_SECRET was not set! Set it in your .env file and restart webpack dev server"
|
2021-02-08 17:42:16 +00:00
|
|
|
);
|
2021-03-15 03:53:16 +00:00
|
|
|
}
|
2021-02-08 17:42:16 +00:00
|
|
|
|
2021-03-15 03:53:16 +00:00
|
|
|
// Azure SDK clients accept the credential as a parameter
|
|
|
|
const credentials = new ClientSecretCredential(
|
|
|
|
process.env.AZURE_TENANT_ID,
|
|
|
|
process.env.AZURE_CLIENT_ID,
|
|
|
|
process.env.AZURE_CLIENT_SECRET,
|
|
|
|
{
|
|
|
|
authorityHost: "https://localhost:1234",
|
|
|
|
}
|
|
|
|
);
|
2021-02-08 17:42:16 +00:00
|
|
|
|
2021-03-15 03:53:16 +00:00
|
|
|
console.log("Resource Group:", resourceGroup);
|
|
|
|
console.log("Subcription: ", subscriptionId);
|
|
|
|
console.log("Account Name: ", accountName);
|
2020-11-19 17:29:38 +00:00
|
|
|
|
|
|
|
const initTestExplorer = async (): Promise<void> => {
|
2021-03-19 19:45:58 +00:00
|
|
|
const { token } = await credentials.getToken("https://management.azure.com//.default");
|
2021-03-15 03:53:16 +00:00
|
|
|
updateUserContext({
|
|
|
|
authorizationToken: `bearer ${token}`,
|
|
|
|
});
|
|
|
|
const databaseAccount = await get(subscriptionId, resourceGroup, accountName);
|
|
|
|
const keys = await listKeys(subscriptionId, resourceGroup, accountName);
|
2020-11-19 17:29:38 +00:00
|
|
|
|
|
|
|
const initTestExplorerContent = {
|
|
|
|
inputs: {
|
|
|
|
databaseAccount: databaseAccount,
|
2021-03-15 03:53:16 +00:00
|
|
|
subscriptionId,
|
|
|
|
resourceGroup,
|
2020-11-19 17:29:38 +00:00
|
|
|
authorizationToken: `Bearer ${token}`,
|
2021-02-17 20:52:47 +00:00
|
|
|
features: {},
|
2020-11-19 17:29:38 +00:00
|
|
|
hasWriteAccess: true,
|
|
|
|
csmEndpoint: "https://management.azure.com",
|
|
|
|
dnsSuffix: "documents.azure.com",
|
|
|
|
serverId: "prod1",
|
|
|
|
extensionEndpoint: "/proxy",
|
|
|
|
subscriptionType: 3,
|
|
|
|
quotaId: "Internal_2014-09-01",
|
|
|
|
addCollectionDefaultFlight: "2",
|
|
|
|
isTryCosmosDBSubscription: false,
|
2021-03-15 03:53:16 +00:00
|
|
|
masterKey: keys.primaryMasterKey,
|
2020-11-19 17:29:38 +00:00
|
|
|
loadDatabaseAccountTimestamp: 1604663109836,
|
|
|
|
dataExplorerVersion: "1.0.1",
|
|
|
|
sharedThroughputMinimum: 400,
|
|
|
|
sharedThroughputMaximum: 1000000,
|
|
|
|
sharedThroughputDefault: 400,
|
|
|
|
defaultCollectionThroughput: {
|
|
|
|
storage: "100",
|
2021-01-20 15:15:01 +00:00
|
|
|
throughput: { fixed: 400, unlimited: 400, unlimitedmax: 100000, unlimitedmin: 400, shared: 400 },
|
2020-11-19 17:29:38 +00:00
|
|
|
},
|
|
|
|
// add UI test only when feature is not dependent on flights anymore
|
2021-01-20 06:42:45 +00:00
|
|
|
flights: [],
|
2021-01-25 19:56:15 +00:00
|
|
|
selfServeType,
|
2021-03-15 03:53:16 +00:00
|
|
|
} as DataExplorerInputsFrame,
|
2020-11-19 17:29:38 +00:00
|
|
|
};
|
|
|
|
|
2021-01-25 19:56:15 +00:00
|
|
|
const iframe = document.createElement("iframe");
|
|
|
|
window.addEventListener(
|
|
|
|
"message",
|
|
|
|
(event) => {
|
|
|
|
// After we have received the "ready" message from the child iframe we can post configuration
|
|
|
|
// This simulates the same action that happens in the portal
|
|
|
|
console.dir(event.data);
|
2021-03-19 03:41:43 +00:00
|
|
|
if (event.data?.kind === "ready") {
|
2021-01-25 19:56:15 +00:00
|
|
|
iframe.contentWindow.postMessage(
|
|
|
|
{
|
|
|
|
signature: "pcIframe",
|
|
|
|
data: initTestExplorerContent,
|
|
|
|
},
|
|
|
|
iframe.contentDocument.referrer || window.location.href
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
false
|
|
|
|
);
|
|
|
|
iframe.id = "explorerMenu";
|
|
|
|
iframe.name = "explorer";
|
|
|
|
iframe.classList.add("iframe");
|
|
|
|
iframe.title = "explorer";
|
2021-03-15 03:53:16 +00:00
|
|
|
iframe.src = iframeSrc;
|
2021-01-25 19:56:15 +00:00
|
|
|
document.body.appendChild(iframe);
|
2020-11-19 17:29:38 +00:00
|
|
|
};
|
|
|
|
|
2021-01-25 19:56:15 +00:00
|
|
|
initTestExplorer();
|