cosmos-explorer/test/testExplorer/TestExplorer.ts

143 lines
4.9 KiB
TypeScript
Raw Normal View History

import "../../less/hostedexplorer.less";
import { TestExplorerParams } from "./TestExplorerParams";
import { CosmosDBManagementClient } from "@azure/arm-cosmosdb";
import * as msRest from "@azure/ms-rest-js";
import * as ViewModels from "../../src/Contracts/ViewModels";
import { Capability, DatabaseAccount } from "../../src/Contracts/DataModels";
class CustomSigner implements msRest.ServiceClientCredentials {
private token: string;
constructor(token: string) {
this.token = token;
}
async signRequest(webResource: msRest.WebResourceLike): Promise<msRest.WebResourceLike> {
webResource.headers.set("authorization", `bearer ${this.token}`);
return webResource;
}
}
const getDatabaseAccount = async (
token: string,
notebooksAccountSubscriptonId: string,
notebooksAccountResourceGroup: string,
notebooksAccountName: string
): Promise<DatabaseAccount> => {
const client = new CosmosDBManagementClient(new CustomSigner(token), notebooksAccountSubscriptonId);
const databaseAccountGetResponse = await client.databaseAccounts.get(
notebooksAccountResourceGroup,
notebooksAccountName
);
const databaseAccount: DatabaseAccount = {
id: databaseAccountGetResponse.id,
name: databaseAccountGetResponse.name,
location: databaseAccountGetResponse.location,
type: databaseAccountGetResponse.type,
kind: databaseAccountGetResponse.kind,
tags: databaseAccountGetResponse.tags,
properties: {
documentEndpoint: databaseAccountGetResponse.documentEndpoint,
tableEndpoint: undefined,
gremlinEndpoint: undefined,
cassandraEndpoint: undefined,
capabilities: databaseAccountGetResponse.capabilities.map((capability) => {
return { name: capability.name } as Capability;
}),
},
};
return databaseAccount;
};
const initTestExplorer = async (): Promise<void> => {
const urlSearchParams = new URLSearchParams(window.location.search);
const portalRunnerDatabaseAccount = decodeURIComponent(
urlSearchParams.get(TestExplorerParams.portalRunnerDatabaseAccount)
);
const portalRunnerDatabaseAccountKey = decodeURIComponent(
urlSearchParams.get(TestExplorerParams.portalRunnerDatabaseAccountKey)
);
const portalRunnerSubscripton = decodeURIComponent(urlSearchParams.get(TestExplorerParams.portalRunnerSubscripton));
const portalRunnerResourceGroup = decodeURIComponent(
urlSearchParams.get(TestExplorerParams.portalRunnerResourceGroup)
);
const selfServeType = urlSearchParams.get(TestExplorerParams.selfServeType);
const token = decodeURIComponent(urlSearchParams.get(TestExplorerParams.token));
const databaseAccount = await getDatabaseAccount(
token,
portalRunnerSubscripton,
portalRunnerResourceGroup,
portalRunnerDatabaseAccount
);
const initTestExplorerContent = {
inputs: {
databaseAccount: databaseAccount,
subscriptionId: portalRunnerSubscripton,
resourceGroup: portalRunnerResourceGroup,
authorizationToken: `Bearer ${token}`,
features: {},
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,
masterKey: portalRunnerDatabaseAccountKey,
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 },
},
// add UI test only when feature is not dependent on flights anymore
flights: [],
selfServeType,
2021-01-20 15:15:01 +00:00
} as ViewModels.DataExplorerInputsFrame,
};
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);
if (event.data?.data === "ready") {
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";
Created selfServe landing page (#444) * Portal changes for DedicatedGateway Changes to support creation and deletion of DedicatedGateway resource. Tested locally with various scenarios. * Portal changes for DedicatedGateway. CR feedback * Stylecop changes * created selfServe.html landing page * Removing TODO comments * exposed baselineValues * added getOnSaveNotification * disable UI when onSave is taking place * minro edits * made polling optional * added optional polling * added default * Added portal notifications * merged more changes * minor edits * added label for description * Added correlationids and polling of refresh * Added correlationids and polling of refresh * minor edit * added label tooltip * removed ClassInfo decorator * Added dynamic decription * added info and warninf types for description * more changes to promise retry * promise retry changes * added spinner on selfserve load * compile errors fixed * New changes * added operationstatus link * merged sqlxEdits * undid sqlx changes * added completed notification * passed retryInterval in notif options * more retry changes * more changes * added polling on landing on the page * edits for error display * added keys blade link * added link generation * added link to blade * Modified info and description * fixed format errors * added selfserve contract to output files * addressed PR comments Co-authored-by: Balaji Sridharan <fnbalaji@microsoft.com> Co-authored-by: fnbalaji <75445927+fnbalaji@users.noreply.github.com>
2021-03-10 21:55:05 +00:00
iframe.src = getIframeSrc(selfServeType);
document.body.appendChild(iframe);
};
Created selfServe landing page (#444) * Portal changes for DedicatedGateway Changes to support creation and deletion of DedicatedGateway resource. Tested locally with various scenarios. * Portal changes for DedicatedGateway. CR feedback * Stylecop changes * created selfServe.html landing page * Removing TODO comments * exposed baselineValues * added getOnSaveNotification * disable UI when onSave is taking place * minro edits * made polling optional * added optional polling * added default * Added portal notifications * merged more changes * minor edits * added label for description * Added correlationids and polling of refresh * Added correlationids and polling of refresh * minor edit * added label tooltip * removed ClassInfo decorator * Added dynamic decription * added info and warninf types for description * more changes to promise retry * promise retry changes * added spinner on selfserve load * compile errors fixed * New changes * added operationstatus link * merged sqlxEdits * undid sqlx changes * added completed notification * passed retryInterval in notif options * more retry changes * more changes * added polling on landing on the page * edits for error display * added keys blade link * added link generation * added link to blade * Modified info and description * fixed format errors * added selfserve contract to output files * addressed PR comments Co-authored-by: Balaji Sridharan <fnbalaji@microsoft.com> Co-authored-by: fnbalaji <75445927+fnbalaji@users.noreply.github.com>
2021-03-10 21:55:05 +00:00
const getIframeSrc = (selfServeType: string): string => {
let iframeSrc = "explorer.html?platform=Portal&disablePortalInitCache";
if (selfServeType) {
iframeSrc = `selfServe.html?selfServeType=${selfServeType}`;
}
return iframeSrc;
};
initTestExplorer();