mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-05-10 18:33:52 +01:00
Merge branch 'master' into users/justinkolasa/open-vs-code-in-de
This commit is contained in:
commit
6fe849ee42
18
.github/workflows/ci.yml
vendored
18
.github/workflows/ci.yml
vendored
@ -164,24 +164,24 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
shardIndex: [1, 2, 3, 4, 5, 6, 7, 8]
|
||||
shardTotal: [8]
|
||||
shardIndex: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
|
||||
shardTotal: [16]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: "Az CLI login"
|
||||
uses: azure/login@v1
|
||||
with:
|
||||
client-id: ${{ secrets.AZURE_CLIENT_ID }}
|
||||
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
|
||||
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
|
||||
- name: Use Node.js 18.x
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18.x
|
||||
- run: npm ci
|
||||
- run: npx playwright install --with-deps
|
||||
- name: "Az CLI login"
|
||||
uses: Azure/login@v2
|
||||
with:
|
||||
client-id: ${{ secrets.AZURE_CLIENT_ID }}
|
||||
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
|
||||
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
|
||||
- name: Run test shard ${{ matrix['shardIndex'] }} of ${{ matrix['shardTotal']}}
|
||||
run: npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
|
||||
run: npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }} --workers=3
|
||||
- name: Upload blob report to GitHub Actions Artifacts
|
||||
if: ${{ !cancelled() }}
|
||||
uses: actions/upload-artifact@v4
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 2.1 KiB |
8
images/golang.svg
Normal file
8
images/golang.svg
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||
<svg width="800px" height="800px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
|
||||
<g fill="none">
|
||||
<path fill="#8CC5E7" d="M21.4679537,3.20617761 C22.1814672,4.67953668 20.0131274,4.83706564 20.1243243,5.49498069 C20.3281853,6.68108108 20.1891892,8.44169884 20.0316602,10.1745174 C19.7629344,13.1119691 21.9590734,20.1451737 17.3814672,22.9714286 C16.5196911,23.5088803 14.4718147,23.8054054 12.4517375,23.8517375 C12.4517375,23.8517375 12.442471,23.8517375 12.442471,23.8517375 C12.442471,23.8517375 12.4332046,23.8517375 12.4332046,23.8517375 C10.4131274,23.8054054 8.08725869,23.5088803 7.22548263,22.9714286 C2.65714286,20.1451737 4.85328185,13.1119691 4.59382239,10.1745174 C4.42702703,8.44169884 4.28803089,6.68108108 4.5011583,5.49498069 C4.61235521,4.83706564 2.44401544,4.68880309 3.15752896,3.20617761 C3.76911197,1.93667954 5.27953668,3.05791506 5.65945946,2.65945946 C7.596139,0.648648649 9.94980695,0.111196911 11.8030888,0.0648648649 C11.988417,0.0648648649 12.8223938,0.0648648649 12.8223938,0.0648648649 C14.6664093,0.157528958 17.0200772,0.657915058 18.9660232,2.65945946 C19.3459459,3.05791506 20.8471042,1.93667954 21.4679537,3.20617761 Z M11.4324324,10.9065637 C11.3490347,10.9436293 11.2100386,11.8517375 11.6362934,11.8980695 C11.9235521,11.9258687 12.7111969,12.0185328 12.8965251,11.8980695 C13.2579151,11.6664093 13.2208494,11.1104247 13.0169884,10.9714286 C12.6741313,10.7490347 11.5250965,10.8602317 11.4324324,10.9065637 Z M9.07876448,4.10501931 C8.12432432,3.99382239 6.52123552,4.88339768 6.28030888,6.77374517 C6.02084942,8.73822394 8.33745174,10.6841699 10.56139,8.73822394 C11.7567568,7.69111969 12.1737452,4.46640927 9.07876448,4.10501931 Z M15.5281853,4.10501931 C12.4332046,4.46640927 12.8501931,7.69111969 14.0455598,8.73822394 C16.2694981,10.6841699 18.5861004,8.73822394 18.3266409,6.77374517 C18.0949807,4.88339768 16.4918919,3.99382239 15.5281853,4.10501931 Z"/>
|
||||
<path fill="#B8937F" d="M12.3127413,8.98841699 C12.8965251,8.90501931 14.2957529,9.57220077 14.2030888,10.3598456 C14.0918919,11.2772201 10.5984556,11.3976834 10.4131274,10.3042471 C10.3019305,9.63706564 10.8301158,9.21081081 12.3127413,8.98841699 Z M20.1984556,16.3737452 C19.9111969,16.3644788 19.7258687,15.984556 19.7258687,15.7528958 C19.7258687,15.3359073 19.7814672,14.8447876 20.0872587,14.6316602 C20.7173745,14.196139 21.2177606,16.3830116 20.1984556,16.3737452 Z M4.41776062,16.3737452 C3.3984556,16.3830116 3.8988417,14.196139 4.52895753,14.6316602 C4.83474903,14.8447876 4.89034749,15.3359073 4.89034749,15.7528958 C4.89034749,15.984556 4.70501931,16.3644788 4.41776062,16.3737452 Z M18.2617761,23.0918919 C18.4471042,23.3606178 18.4563707,23.5459459 18.1598456,23.6849421 C17.0293436,24.203861 16.019305,23.5088803 16.3992278,23.3142857 C17.2054054,22.9065637 17.7057915,22.2671815 18.2617761,23.0918919 Z M6.35444015,23.184556 C6.91042471,22.3598456 7.41081081,22.9992278 8.21698842,23.4069498 C8.5969112,23.6015444 7.58687259,24.2965251 6.45637066,23.7776062 C6.15984556,23.63861 6.16911197,23.4532819 6.35444015,23.184556 Z"/>
|
||||
<path fill="#000000" d="M19.7351351,3.42857143 C19.7814672,3.23397683 20.2633205,3.14131274 20.5320463,3.47490347 C20.8563707,3.87335907 20.0594595,4.42007722 20.0223938,4.1976834 C19.9297297,3.5953668 19.6795367,3.62316602 19.7351351,3.42857143 Z M4.88108108,3.42857143 C4.93667954,3.62316602 4.68648649,3.5953668 4.59382239,4.1976834 C4.55675676,4.42007722 3.75984556,3.87335907 4.08416988,3.47490347 C4.34362934,3.14131274 4.82548263,3.23397683 4.88108108,3.42857143 Z M15.7413127,7.94131274 C15.1578953,7.94131274 14.6849421,7.46835949 14.6849421,6.88494208 C14.6849421,6.30152468 15.1578953,5.82857143 15.7413127,5.82857143 C16.3247301,5.82857143 16.7976834,6.30152468 16.7976834,6.88494208 C16.7976834,7.46835949 16.3247301,7.94131274 15.7413127,7.94131274 Z M15.4633205,6.76447876 C15.6475575,6.76447876 15.7969112,6.61512511 15.7969112,6.43088803 C15.7969112,6.24665096 15.6475575,6.0972973 15.4633205,6.0972973 C15.2790834,6.0972973 15.1297297,6.24665096 15.1297297,6.43088803 C15.1297297,6.61512511 15.2790834,6.76447876 15.4633205,6.76447876 Z M11.3583012,9.43320463 C11.4694981,9.00694981 11.8586873,8.86795367 12.1737452,8.85868726 C12.9799228,8.84015444 13.2857143,9.27567568 13.3135135,9.61853282 C13.369112,10.2023166 11.1081081,10.3413127 11.3583012,9.43320463 Z M8.87490347,7.94131274 C8.29148607,7.94131274 7.81853282,7.46835949 7.81853282,6.88494208 C7.81853282,6.30152468 8.29148607,5.82857143 8.87490347,5.82857143 C9.45832088,5.82857143 9.93127413,6.30152468 9.93127413,6.88494208 C9.93127413,7.46835949 9.45832088,7.94131274 8.87490347,7.94131274 Z M9.15289575,6.76447876 C9.33713283,6.76447876 9.48648649,6.61512511 9.48648649,6.43088803 C9.48648649,6.24665096 9.33713283,6.0972973 9.15289575,6.0972973 C8.96865868,6.0972973 8.81930502,6.24665096 8.81930502,6.43088803 C8.81930502,6.61512511 8.96865868,6.76447876 9.15289575,6.76447876 Z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 4.9 KiB |
10
images/springboot.svg
Normal file
10
images/springboot.svg
Normal file
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||
<svg width="800px" height="800px" viewBox="0 0 256 256" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid">
|
||||
<g>
|
||||
<path d="M38.9437824,35.879008 C89.5234256,-13.1200214 170.398168,-11.8028432 219.397197,39.0402357 C224.929346,31.6640377 229.671187,23.4975328 233.095851,15.0675923 C249.165425,64.0666217 258.912543,105.162582 255.224444,137.038295 C253.380395,163.90873 242.842969,189.725423 225.456217,210.273403 C180.145286,264.014274 99.53398,270.863601 45.7931091,225.55267 L45.7931091,225.55267 L44.765,224.638 L44.7103323,224.601984 C44.5420247,224.484832 44.376007,224.362668 44.2124952,224.235492 C43.7219599,223.853965 43.2765312,223.438607 42.8762093,222.995252 L42.732,222.831 L41.0512675,221.3377 C39.4121124,219.93271 37.7729573,218.52772 36.3188215,216.93771 L35.7825547,216.332423 C-13.2164747,165.752779 -11.6358609,84.8780374 38.9437824,35.879008 Z M57.9111486,207.375611 C53.169307,203.687512 46.3199803,204.214383 42.6318814,208.956225 C39.3888978,213.125775 39.4048731,218.924805 42.6798072,222.771269 L42.732,222.831 L44.765,224.638 L44.9644841,224.773953 C49.5691585,227.80174 55.7644273,227.175885 59.2982065,222.896387 L59.4917624,222.654878 C63.1798614,217.913037 62.3895545,211.06371 57.9111486,207.375611 Z M231.778672,28.2393744 C218.60689,55.9001168 185.940871,76.9749681 157.753257,83.5608592 C131.146257,89.8833146 107.963921,84.6146018 83.4644059,94.0982849 C27.6160498,115.436572 28.6697923,181.822354 59.2283268,196.838185 L59.2283268,196.838185 L61.0723763,197.891928 C61.0723763,197.891928 83.1456487,193.50309 104.973663,187.707242 L106.843514,187.207079 C115.561826,184.857554 124.138869,182.296538 131.146257,179.714869 C167.500376,166.279651 207.542593,133.08676 220.714375,94.6251562 C213.865049,134.667374 179.35498,173.392413 144.84491,191.042601 C126.404416,200.526284 112.178891,202.633769 81.883792,213.171195 C78.195693,214.488373 75.297901,215.805551 75.297901,215.805551 C75.6675607,215.754564 76.0372203,215.70481 76.4060145,215.65629 L77.1421925,215.560893 L77.1421925,215.560893 L77.8745239,215.468787 C84.5652297,214.639554 90.5771682,214.224938 90.5771682,214.224938 C133.517178,212.117452 200.956702,226.342977 232.305544,184.45671 C264.444692,141.780136 246.531068,72.7599979 231.778672,28.2393744 Z" fill="#6DB33F">
|
||||
</path>
|
||||
<path d="M57.9111486,207.375611 C62.3895545,211.06371 63.1798614,217.913037 59.4917624,222.654878 C55.8036635,227.39672 48.9543368,227.923591 44.2124952,224.235492 C39.4706537,220.547393 38.9437824,213.698066 42.6318814,208.956225 C46.3199803,204.214383 53.169307,203.687512 57.9111486,207.375611 Z M231.778672,28.2393744 C246.531068,72.7599979 264.444692,141.780136 232.305544,184.45671 C200.956702,226.342977 133.517178,212.117452 90.5771682,214.224938 C90.5771682,214.224938 84.5652297,214.639554 77.8745239,215.468787 L77.1421925,215.560893 C76.5300999,215.63902 75.9140004,215.720572 75.297901,215.805551 C75.297901,215.805551 78.195693,214.488373 81.883792,213.171195 C112.178891,202.633769 126.404416,200.526284 144.84491,191.042601 C179.35498,173.392413 213.865049,134.667374 220.714375,94.6251562 C207.542593,133.08676 167.500376,166.279651 131.146257,179.714869 C106.119871,188.935116 61.0723763,197.891928 61.0723763,197.891928 L59.2283268,196.838185 C28.6697923,181.822354 27.6160498,115.436572 83.4644059,94.0982849 C107.963921,84.6146018 131.146257,89.8833146 157.753257,83.5608592 C185.940871,76.9749681 218.60689,55.9001168 231.778672,28.2393744 Z" fill="#FFFFFF">
|
||||
</path>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 3.6 KiB |
1322
less/quickstart.less
1322
less/quickstart.less
File diff suppressed because it is too large
Load Diff
15
package-lock.json
generated
15
package-lock.json
generated
@ -51,6 +51,8 @@
|
||||
"@types/mkdirp": "1.0.1",
|
||||
"@types/node-fetch": "2.5.7",
|
||||
"@xmldom/xmldom": "0.7.13",
|
||||
"@xterm/addon-fit": "0.10.0",
|
||||
"@xterm/xterm": "5.5.0",
|
||||
"allotment": "1.20.2",
|
||||
"applicationinsights": "1.8.0",
|
||||
"bootstrap": "3.4.1",
|
||||
@ -13240,6 +13242,19 @@
|
||||
"node": ">=10.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@xterm/addon-fit": {
|
||||
"version": "0.10.0",
|
||||
"resolved": "https://registry.npmjs.org/@xterm/addon-fit/-/addon-fit-0.10.0.tgz",
|
||||
"integrity": "sha512-UFYkDm4HUahf2lnEyHvio51TNGiLK66mqP2JoATy7hRZeXaGMRDr00JiSF7m63vR5WKATF605yEggJKsw0JpMQ==",
|
||||
"peerDependencies": {
|
||||
"@xterm/xterm": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@xterm/xterm": {
|
||||
"version": "5.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@xterm/xterm/-/xterm-5.5.0.tgz",
|
||||
"integrity": "sha512-hqJHYaQb5OptNunnyAnkHyM8aCjZ1MEIDTQu1iIbbTD/xops91NB5yq1ZK/dC2JDbVWtF23zUtl9JE2NqwT87A=="
|
||||
},
|
||||
"node_modules/@xtuc/ieee754": {
|
||||
"version": "1.2.0",
|
||||
"license": "BSD-3-Clause"
|
||||
|
@ -46,6 +46,8 @@
|
||||
"@types/mkdirp": "1.0.1",
|
||||
"@types/node-fetch": "2.5.7",
|
||||
"@xmldom/xmldom": "0.7.13",
|
||||
"@xterm/xterm": "5.5.0",
|
||||
"@xterm/addon-fit": "0.10.0",
|
||||
"allotment": "1.20.2",
|
||||
"applicationinsights": "1.8.0",
|
||||
"bootstrap": "3.4.1",
|
||||
|
@ -37,20 +37,51 @@ export default defineConfig({
|
||||
},
|
||||
{
|
||||
name: "firefox",
|
||||
use: { ...devices["Desktop Firefox"] },
|
||||
use: {
|
||||
...devices["Desktop Firefox"],
|
||||
launchOptions: {
|
||||
firefoxUserPrefs: {
|
||||
"security.fileuri.strict_origin_policy": false,
|
||||
"network.http.referer.XOriginPolicy": 0,
|
||||
"network.http.referer.trimmingPolicy": 0,
|
||||
"privacy.file_unique_origin": false,
|
||||
"security.csp.enable": false,
|
||||
"network.cors_preflight.allow_client_cert": true,
|
||||
"dom.security.https_first": false,
|
||||
"network.http.cross-origin-embedder-policy": false,
|
||||
"network.http.cross-origin-opener-policy": false,
|
||||
"browser.tabs.remote.useCrossOriginPolicy": false,
|
||||
"browser.tabs.remote.useCORP": false,
|
||||
},
|
||||
args: ["--disable-web-security"],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "webkit",
|
||||
use: { ...devices["Desktop Safari"] },
|
||||
use: {
|
||||
...devices["Desktop Safari"],
|
||||
},
|
||||
},
|
||||
/* Test against branded browsers. */
|
||||
{
|
||||
name: "Google Chrome",
|
||||
use: { ...devices["Desktop Chrome"], channel: "chrome" }, // or 'chrome-beta'
|
||||
use: {
|
||||
...devices["Desktop Chrome"],
|
||||
channel: "chrome",
|
||||
launchOptions: {
|
||||
args: ["--disable-web-security", "--disable-features=IsolateOrigins,site-per-process"],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Microsoft Edge",
|
||||
use: { ...devices["Desktop Edge"], channel: "msedge" }, // or 'msedge-dev'
|
||||
use: {
|
||||
...devices["Desktop Edge"],
|
||||
channel: "msedge",
|
||||
launchOptions: {
|
||||
args: ["--disable-web-security", "--disable-features=IsolateOrigins,site-per-process"],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
|
@ -257,6 +257,7 @@ export class Areas {
|
||||
public static ShareDialog: string = "Share Access Dialog";
|
||||
public static Notebook: string = "Notebook";
|
||||
public static Copilot: string = "Copilot";
|
||||
public static CloudShell: string = "Cloud Shell";
|
||||
}
|
||||
|
||||
export class HttpHeaders {
|
||||
|
@ -18,10 +18,13 @@ export type DataExploreMessageV3 =
|
||||
| {
|
||||
type: FabricMessageTypes.GetAllResourceTokens;
|
||||
id: string;
|
||||
}
|
||||
| {
|
||||
type: FabricMessageTypes.OpenSettings;
|
||||
settingsId: string;
|
||||
};
|
||||
|
||||
export type GetCosmosTokenMessageOptions = {
|
||||
export interface GetCosmosTokenMessageOptions {
|
||||
verb: "connect" | "delete" | "get" | "head" | "options" | "patch" | "post" | "put" | "trace";
|
||||
resourceType: "" | "dbs" | "colls" | "docs" | "sprocs" | "pkranges";
|
||||
resourceId: string;
|
||||
};
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ export enum FabricMessageTypes {
|
||||
GetAllResourceTokens = "GetAllResourceTokens",
|
||||
GetAccessToken = "GetAccessToken",
|
||||
Ready = "Ready",
|
||||
OpenSettings = "OpenSettings",
|
||||
}
|
||||
|
||||
export interface AuthorizationToken {
|
||||
|
@ -103,17 +103,23 @@ export const createCollectionContextMenuButton = (
|
||||
iconSrc: HostedTerminalIcon,
|
||||
onClick: () => {
|
||||
const selectedCollection: ViewModels.Collection = useSelectedNode.getState().findSelectedCollection();
|
||||
if (useNotebook.getState().isShellEnabled) {
|
||||
if (useNotebook.getState().isShellEnabled || userContext.features.enableCloudShell) {
|
||||
container.openNotebookTerminal(ViewModels.TerminalKind.Mongo);
|
||||
} else {
|
||||
selectedCollection && selectedCollection.onNewMongoShellClick();
|
||||
}
|
||||
},
|
||||
label: useNotebook.getState().isShellEnabled ? "Open Mongo Shell" : "New Shell",
|
||||
label:
|
||||
useNotebook.getState().isShellEnabled || userContext.features.enableCloudShell
|
||||
? "Open Mongo Shell"
|
||||
: "New Shell",
|
||||
});
|
||||
}
|
||||
|
||||
if (useNotebook.getState().isShellEnabled && userContext.apiType === "Cassandra") {
|
||||
if (
|
||||
(useNotebook.getState().isShellEnabled || userContext.features.enableCloudShell) &&
|
||||
userContext.apiType === "Cassandra"
|
||||
) {
|
||||
items.push({
|
||||
iconSrc: HostedTerminalIcon,
|
||||
onClick: () => {
|
||||
|
@ -193,6 +193,7 @@ export const InputDataList: FC<InputDataListProps> = ({
|
||||
<>
|
||||
<Input
|
||||
id="filterInput"
|
||||
data-test={"DocumentsTab/FilterInput"}
|
||||
ref={inputRef}
|
||||
type="text"
|
||||
size="small"
|
||||
|
@ -0,0 +1,41 @@
|
||||
import { shallow } from "enzyme";
|
||||
import {
|
||||
PartitionKeyComponent,
|
||||
PartitionKeyComponentProps,
|
||||
} from "Explorer/Controls/Settings/SettingsSubComponents/PartitionKeyComponent";
|
||||
import Explorer from "Explorer/Explorer";
|
||||
import React from "react";
|
||||
|
||||
describe("PartitionKeyComponent", () => {
|
||||
// Create a test setup function to get fresh instances for each test
|
||||
const setupTest = () => {
|
||||
// Create an instance of the mocked Explorer
|
||||
const explorer = new Explorer();
|
||||
// Create minimal mock objects for database and collection
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const mockDatabase = {} as any as import("../../../../Contracts/ViewModels").Database;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const mockCollection = {} as any as import("../../../../Contracts/ViewModels").Collection;
|
||||
|
||||
// Create props with the mocked Explorer instance
|
||||
const props: PartitionKeyComponentProps = {
|
||||
database: mockDatabase,
|
||||
collection: mockCollection,
|
||||
explorer,
|
||||
};
|
||||
|
||||
return { explorer, props };
|
||||
};
|
||||
|
||||
it("renders default component and matches snapshot", () => {
|
||||
const { props } = setupTest();
|
||||
const wrapper = shallow(<PartitionKeyComponent {...props} />);
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
|
||||
it("renders read-only component and matches snapshot", () => {
|
||||
const { props } = setupTest();
|
||||
const wrapper = shallow(<PartitionKeyComponent {...props} isReadOnly={true} />);
|
||||
expect(wrapper).toMatchSnapshot();
|
||||
});
|
||||
});
|
@ -161,7 +161,7 @@ export const PartitionKeyComponent: React.FC<PartitionKeyComponentProps> = ({
|
||||
return (
|
||||
<Stack tokens={{ childrenGap: 20 }} styles={{ root: { maxWidth: 600 } }}>
|
||||
<Stack tokens={{ childrenGap: 10 }}>
|
||||
<Text styles={textHeadingStyle}>Change {partitionKeyName.toLowerCase()}</Text>
|
||||
{!isReadOnly && <Text styles={textHeadingStyle}>Change {partitionKeyName.toLowerCase()}</Text>}
|
||||
<Stack horizontal tokens={{ childrenGap: 20 }}>
|
||||
<Stack tokens={{ childrenGap: 5 }}>
|
||||
<Text styles={textSubHeadingStyle}>Current {partitionKeyName.toLowerCase()}</Text>
|
||||
|
@ -0,0 +1,196 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`PartitionKeyComponent renders default component and matches snapshot 1`] = `
|
||||
<Stack
|
||||
styles={
|
||||
{
|
||||
"root": {
|
||||
"maxWidth": 600,
|
||||
},
|
||||
}
|
||||
}
|
||||
tokens={
|
||||
{
|
||||
"childrenGap": 20,
|
||||
}
|
||||
}
|
||||
>
|
||||
<Stack
|
||||
tokens={
|
||||
{
|
||||
"childrenGap": 10,
|
||||
}
|
||||
}
|
||||
>
|
||||
<Text
|
||||
styles={
|
||||
{
|
||||
"root": {
|
||||
"fontSize": 16,
|
||||
"fontWeight": 600,
|
||||
},
|
||||
}
|
||||
}
|
||||
>
|
||||
Change
|
||||
partition key
|
||||
</Text>
|
||||
<Stack
|
||||
horizontal={true}
|
||||
tokens={
|
||||
{
|
||||
"childrenGap": 20,
|
||||
}
|
||||
}
|
||||
>
|
||||
<Stack
|
||||
tokens={
|
||||
{
|
||||
"childrenGap": 5,
|
||||
}
|
||||
}
|
||||
>
|
||||
<Text
|
||||
styles={
|
||||
{
|
||||
"root": {
|
||||
"fontWeight": 600,
|
||||
},
|
||||
}
|
||||
}
|
||||
>
|
||||
Current
|
||||
partition key
|
||||
</Text>
|
||||
<Text
|
||||
styles={
|
||||
{
|
||||
"root": {
|
||||
"fontWeight": 600,
|
||||
},
|
||||
}
|
||||
}
|
||||
>
|
||||
Partitioning
|
||||
</Text>
|
||||
</Stack>
|
||||
<Stack
|
||||
tokens={
|
||||
{
|
||||
"childrenGap": 5,
|
||||
}
|
||||
}
|
||||
>
|
||||
<Text />
|
||||
<Text>
|
||||
Non-hierarchical
|
||||
</Text>
|
||||
</Stack>
|
||||
</Stack>
|
||||
</Stack>
|
||||
<StyledMessageBar
|
||||
messageBarType={5}
|
||||
>
|
||||
To safeguard the integrity of the data being copied to the new container, ensure that no updates are made to the source container for the entire duration of the partition key change process.
|
||||
<StyledLinkBase
|
||||
href="https://learn.microsoft.com/azure/cosmos-db/container-copy#how-does-container-copy-work"
|
||||
target="_blank"
|
||||
underline={true}
|
||||
>
|
||||
Learn more
|
||||
</StyledLinkBase>
|
||||
</StyledMessageBar>
|
||||
<Text>
|
||||
To change the partition key, a new destination container must be created or an existing destination container selected. Data will then be copied to the destination container.
|
||||
</Text>
|
||||
<CustomizedPrimaryButton
|
||||
onClick={[Function]}
|
||||
styles={
|
||||
{
|
||||
"root": {
|
||||
"width": "fit-content",
|
||||
},
|
||||
}
|
||||
}
|
||||
text="Change"
|
||||
/>
|
||||
</Stack>
|
||||
`;
|
||||
|
||||
exports[`PartitionKeyComponent renders read-only component and matches snapshot 1`] = `
|
||||
<Stack
|
||||
styles={
|
||||
{
|
||||
"root": {
|
||||
"maxWidth": 600,
|
||||
},
|
||||
}
|
||||
}
|
||||
tokens={
|
||||
{
|
||||
"childrenGap": 20,
|
||||
}
|
||||
}
|
||||
>
|
||||
<Stack
|
||||
tokens={
|
||||
{
|
||||
"childrenGap": 10,
|
||||
}
|
||||
}
|
||||
>
|
||||
<Stack
|
||||
horizontal={true}
|
||||
tokens={
|
||||
{
|
||||
"childrenGap": 20,
|
||||
}
|
||||
}
|
||||
>
|
||||
<Stack
|
||||
tokens={
|
||||
{
|
||||
"childrenGap": 5,
|
||||
}
|
||||
}
|
||||
>
|
||||
<Text
|
||||
styles={
|
||||
{
|
||||
"root": {
|
||||
"fontWeight": 600,
|
||||
},
|
||||
}
|
||||
}
|
||||
>
|
||||
Current
|
||||
partition key
|
||||
</Text>
|
||||
<Text
|
||||
styles={
|
||||
{
|
||||
"root": {
|
||||
"fontWeight": 600,
|
||||
},
|
||||
}
|
||||
}
|
||||
>
|
||||
Partitioning
|
||||
</Text>
|
||||
</Stack>
|
||||
<Stack
|
||||
tokens={
|
||||
{
|
||||
"childrenGap": 5,
|
||||
}
|
||||
}
|
||||
>
|
||||
<Text />
|
||||
<Text>
|
||||
Non-hierarchical
|
||||
</Text>
|
||||
</Stack>
|
||||
</Stack>
|
||||
</Stack>
|
||||
</Stack>
|
||||
`;
|
@ -1,6 +1,7 @@
|
||||
import * as Constants from "../../../Common/Constants";
|
||||
import * as DataModels from "../../../Contracts/DataModels";
|
||||
import * as ViewModels from "../../../Contracts/ViewModels";
|
||||
import { isFabricNative } from "../../../Platform/Fabric/FabricUtil";
|
||||
import { MongoIndex } from "../../../Utils/arm/generatedClients/cosmos/types";
|
||||
|
||||
const zeroValue = 0;
|
||||
@ -165,7 +166,7 @@ export const getTabTitle = (tab: SettingsV2TabTypes): string => {
|
||||
case SettingsV2TabTypes.IndexingPolicyTab:
|
||||
return "Indexing Policy";
|
||||
case SettingsV2TabTypes.PartitionKeyTab:
|
||||
return "Partition Keys (preview)";
|
||||
return isFabricNative() ? "Partition Keys" : "Partition Keys (preview)";
|
||||
case SettingsV2TabTypes.ComputedPropertiesTab:
|
||||
return "Computed Properties";
|
||||
case SettingsV2TabTypes.ContainerVectorPolicyTab:
|
||||
|
@ -967,7 +967,9 @@ export default class Explorer {
|
||||
}
|
||||
|
||||
public async openNotebookTerminal(kind: ViewModels.TerminalKind): Promise<void> {
|
||||
if (useNotebook.getState().isPhoenixFeatures) {
|
||||
if (userContext.features.enableCloudShell) {
|
||||
this.connectToNotebookTerminal(kind);
|
||||
} else if (useNotebook.getState().isPhoenixFeatures) {
|
||||
await this.allocateContainer(PoolIdType.DefaultPoolId);
|
||||
const notebookServerInfo = useNotebook.getState().notebookServerInfo;
|
||||
if (notebookServerInfo && notebookServerInfo.notebookServerEndpoint !== undefined) {
|
||||
|
@ -129,13 +129,14 @@ export function createContextCommandBarButtons(
|
||||
const buttons: CommandButtonComponentProps[] = [];
|
||||
|
||||
if (!selectedNodeState.isDatabaseNodeOrNoneSelected() && userContext.apiType === "Mongo") {
|
||||
const label = useNotebook.getState().isShellEnabled ? "Open Mongo Shell" : "New Shell";
|
||||
const label =
|
||||
useNotebook.getState().isShellEnabled || userContext.features.enableCloudShell ? "Open Mongo Shell" : "New Shell";
|
||||
const newMongoShellBtn: CommandButtonComponentProps = {
|
||||
iconSrc: HostedTerminalIcon,
|
||||
iconAlt: label,
|
||||
onCommandClick: () => {
|
||||
const selectedCollection: ViewModels.Collection = selectedNodeState.findSelectedCollection();
|
||||
if (useNotebook.getState().isShellEnabled) {
|
||||
if (useNotebook.getState().isShellEnabled || userContext.features.enableCloudShell) {
|
||||
container.openNotebookTerminal(ViewModels.TerminalKind.Mongo);
|
||||
} else {
|
||||
selectedCollection && selectedCollection.onNewMongoShellClick();
|
||||
@ -149,7 +150,7 @@ export function createContextCommandBarButtons(
|
||||
}
|
||||
|
||||
if (
|
||||
useNotebook.getState().isShellEnabled &&
|
||||
(useNotebook.getState().isShellEnabled || userContext.features.enableCloudShell) &&
|
||||
!selectedNodeState.isDatabaseNodeOrNoneSelected() &&
|
||||
userContext.apiType === "Cassandra"
|
||||
) {
|
||||
@ -470,7 +471,7 @@ function createOpenTerminalButtonByKind(
|
||||
iconSrc: HostedTerminalIcon,
|
||||
iconAlt: label,
|
||||
onCommandClick: () => {
|
||||
if (useNotebook.getState().isNotebookEnabled) {
|
||||
if (useNotebook.getState().isNotebookEnabled || userContext.features.enableCloudShell) {
|
||||
container.openNotebookTerminal(terminalKind);
|
||||
}
|
||||
},
|
||||
|
@ -23,7 +23,7 @@ import { InfoTooltip } from "Common/Tooltip/InfoTooltip";
|
||||
import { Platform, configContext } from "ConfigContext";
|
||||
import { useDialog } from "Explorer/Controls/Dialog";
|
||||
import { useDatabases } from "Explorer/useDatabases";
|
||||
import { isFabric } from "Platform/Fabric/FabricUtil";
|
||||
import { isFabric, isFabricNative } from "Platform/Fabric/FabricUtil";
|
||||
import {
|
||||
AppStateComponentNames,
|
||||
deleteAllStates,
|
||||
@ -607,441 +607,447 @@ export const SettingsPane: FunctionComponent<{ explorer: Explorer }> = ({
|
||||
return (
|
||||
<RightPaneForm {...genericPaneProps}>
|
||||
<div className={`paneMainContent ${styles.container}`}>
|
||||
<Accordion className={`customAccordion ${styles.firstItem}`}>
|
||||
{shouldShowQueryPageOptions && (
|
||||
<AccordionItem value="1">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Page Options</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Choose Custom to specify a fixed amount of query results to show, or choose Unlimited to show as
|
||||
many query results per page.
|
||||
</div>
|
||||
<ChoiceGroup
|
||||
ariaLabelledBy="pageOptions"
|
||||
selectedKey={pageOption}
|
||||
options={pageOptionList}
|
||||
styles={choiceButtonStyles}
|
||||
onChange={handleOnPageOptionChange}
|
||||
/>
|
||||
</div>
|
||||
<div className={`tabs ${styles.settingsSectionContainer}`}>
|
||||
{isCustomPageOptionSelected() && (
|
||||
<div className="tabcontent">
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Query results per page{" "}
|
||||
<InfoTooltip className={styles.headerIcon}>
|
||||
Enter the number of query results that should be shown per page.
|
||||
</InfoTooltip>
|
||||
</div>
|
||||
|
||||
<SpinButton
|
||||
ariaLabel="Custom query items per page"
|
||||
value={"" + customItemPerPage}
|
||||
onIncrement={(newValue) => {
|
||||
setCustomItemPerPage(parseInt(newValue) + 1 || customItemPerPage);
|
||||
}}
|
||||
onDecrement={(newValue) => setCustomItemPerPage(parseInt(newValue) - 1 || customItemPerPage)}
|
||||
onValidate={(newValue) => setCustomItemPerPage(parseInt(newValue) || customItemPerPage)}
|
||||
min={1}
|
||||
step={1}
|
||||
className="textfontclr"
|
||||
incrementButtonAriaLabel="Increase value by 1"
|
||||
decrementButtonAriaLabel="Decrease value by 1"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
)}
|
||||
{showEnableEntraIdRbac && (
|
||||
<AccordionItem value="2">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Enable Entra ID RBAC</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Choose Automatic to enable Entra ID RBAC automatically. True/False to force enable/disable Entra ID
|
||||
RBAC.
|
||||
<a
|
||||
href="https://learn.microsoft.com/en-us/azure/cosmos-db/how-to-setup-rbac#use-data-explorer"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{" "}
|
||||
Learn more{" "}
|
||||
</a>
|
||||
</div>
|
||||
<ChoiceGroup
|
||||
ariaLabelledBy="enableDataPlaneRBACOptions"
|
||||
options={dataPlaneRBACOptionsList}
|
||||
styles={choiceButtonStyles}
|
||||
selectedKey={enableDataPlaneRBACOption}
|
||||
onChange={handleOnDataPlaneRBACOptionChange}
|
||||
/>
|
||||
</div>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
)}
|
||||
{userContext.apiType === "SQL" && userContext.authType === AuthType.AAD && !isFabric() && (
|
||||
<AccordionItem value="3">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Region Selection</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Changes region the Cosmos Client uses to access account.
|
||||
</div>
|
||||
<div>
|
||||
<span className={styles.subHeader}>Select Region</span>
|
||||
<InfoTooltip className={styles.headerIcon}>
|
||||
Changes the account endpoint used to perform client operations.
|
||||
</InfoTooltip>
|
||||
</div>
|
||||
<Dropdown
|
||||
placeholder={
|
||||
selectedRegionalEndpoint
|
||||
? regionOptions.find((option) => option.key === selectedRegionalEndpoint)?.text
|
||||
: regionOptions[0]?.text
|
||||
}
|
||||
onChange={handleOnSelectedRegionOptionChange}
|
||||
options={regionOptions}
|
||||
styles={{ root: { marginBottom: "10px" } }}
|
||||
/>
|
||||
</div>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
)}
|
||||
{userContext.apiType === "SQL" && !isEmulator && (
|
||||
<>
|
||||
<AccordionItem value="4">
|
||||
{!isFabricNative() && (
|
||||
<Accordion className={`customAccordion ${styles.firstItem}`}>
|
||||
{shouldShowQueryPageOptions && (
|
||||
<AccordionItem value="1">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Query Timeout</div>
|
||||
<div className={styles.header}>Page Options</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
When a query reaches a specified time limit, a popup with an option to cancel the query will show
|
||||
unless automatic cancellation has been enabled.
|
||||
</div>
|
||||
<Toggle
|
||||
styles={toggleStyles}
|
||||
label="Enable query timeout"
|
||||
onChange={handleOnQueryTimeoutToggleChange}
|
||||
defaultChecked={queryTimeoutEnabled}
|
||||
/>
|
||||
</div>
|
||||
{queryTimeoutEnabled && (
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<SpinButton
|
||||
label="Query timeout (ms)"
|
||||
labelPosition={Position.top}
|
||||
defaultValue={(queryTimeout || 5000).toString()}
|
||||
min={100}
|
||||
step={1000}
|
||||
onChange={handleOnQueryTimeoutSpinButtonChange}
|
||||
incrementButtonAriaLabel="Increase value by 1000"
|
||||
decrementButtonAriaLabel="Decrease value by 1000"
|
||||
styles={spinButtonStyles}
|
||||
/>
|
||||
<Toggle
|
||||
label="Automatically cancel query after timeout"
|
||||
styles={toggleStyles}
|
||||
onChange={handleOnAutomaticallyCancelQueryToggleChange}
|
||||
defaultChecked={automaticallyCancelQueryAfterTimeout}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
|
||||
<AccordionItem value="5">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>RU Limit</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
If a query exceeds a configured RU limit, the query will be aborted.
|
||||
</div>
|
||||
<Toggle
|
||||
styles={toggleStyles}
|
||||
label="Enable RU limit"
|
||||
onChange={handleOnRUThresholdToggleChange}
|
||||
defaultChecked={ruThresholdEnabled}
|
||||
/>
|
||||
</div>
|
||||
{ruThresholdEnabled && (
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<SpinButton
|
||||
label="RU Limit (RU)"
|
||||
labelPosition={Position.top}
|
||||
defaultValue={(ruThreshold || DefaultRUThreshold).toString()}
|
||||
min={1}
|
||||
step={1000}
|
||||
onChange={handleOnRUThresholdSpinButtonChange}
|
||||
incrementButtonAriaLabel="Increase value by 1000"
|
||||
decrementButtonAriaLabel="Decrease value by 1000"
|
||||
styles={spinButtonStyles}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
|
||||
<AccordionItem value="6">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Default Query Results View</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Select the default view to use when displaying query results.
|
||||
Choose Custom to specify a fixed amount of query results to show, or choose Unlimited to show as
|
||||
many query results per page.
|
||||
</div>
|
||||
<ChoiceGroup
|
||||
ariaLabelledBy="defaultQueryResultsView"
|
||||
selectedKey={defaultQueryResultsView}
|
||||
options={defaultQueryResultsViewOptionList}
|
||||
ariaLabelledBy="pageOptions"
|
||||
selectedKey={pageOption}
|
||||
options={pageOptionList}
|
||||
styles={choiceButtonStyles}
|
||||
onChange={handleOnDefaultQueryResultsViewChange}
|
||||
onChange={handleOnPageOptionChange}
|
||||
/>
|
||||
</div>
|
||||
<div className={`tabs ${styles.settingsSectionContainer}`}>
|
||||
{isCustomPageOptionSelected() && (
|
||||
<div className="tabcontent">
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Query results per page{" "}
|
||||
<InfoTooltip className={styles.headerIcon}>
|
||||
Enter the number of query results that should be shown per page.
|
||||
</InfoTooltip>
|
||||
</div>
|
||||
|
||||
<SpinButton
|
||||
ariaLabel="Custom query items per page"
|
||||
value={"" + customItemPerPage}
|
||||
onIncrement={(newValue) => {
|
||||
setCustomItemPerPage(parseInt(newValue) + 1 || customItemPerPage);
|
||||
}}
|
||||
onDecrement={(newValue) => setCustomItemPerPage(parseInt(newValue) - 1 || customItemPerPage)}
|
||||
onValidate={(newValue) => setCustomItemPerPage(parseInt(newValue) || customItemPerPage)}
|
||||
min={1}
|
||||
step={1}
|
||||
className="textfontclr"
|
||||
incrementButtonAriaLabel="Increase value by 1"
|
||||
decrementButtonAriaLabel="Decrease value by 1"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
)}
|
||||
{showEnableEntraIdRbac && (
|
||||
<AccordionItem value="2">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Enable Entra ID RBAC</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Choose Automatic to enable Entra ID RBAC automatically. True/False to force enable/disable Entra
|
||||
ID RBAC.
|
||||
<a
|
||||
href="https://learn.microsoft.com/en-us/azure/cosmos-db/how-to-setup-rbac#use-data-explorer"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
{" "}
|
||||
Learn more{" "}
|
||||
</a>
|
||||
</div>
|
||||
<ChoiceGroup
|
||||
ariaLabelledBy="enableDataPlaneRBACOptions"
|
||||
options={dataPlaneRBACOptionsList}
|
||||
styles={choiceButtonStyles}
|
||||
selectedKey={enableDataPlaneRBACOption}
|
||||
onChange={handleOnDataPlaneRBACOptionChange}
|
||||
/>
|
||||
</div>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
</>
|
||||
)}
|
||||
)}
|
||||
{userContext.apiType === "SQL" && userContext.authType === AuthType.AAD && !isFabric() && (
|
||||
<AccordionItem value="3">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Region Selection</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Changes region the Cosmos Client uses to access account.
|
||||
</div>
|
||||
<div>
|
||||
<span className={styles.subHeader}>Select Region</span>
|
||||
<InfoTooltip className={styles.headerIcon}>
|
||||
Changes the account endpoint used to perform client operations.
|
||||
</InfoTooltip>
|
||||
</div>
|
||||
<Dropdown
|
||||
placeholder={
|
||||
selectedRegionalEndpoint
|
||||
? regionOptions.find((option) => option.key === selectedRegionalEndpoint)?.text
|
||||
: regionOptions[0]?.text
|
||||
}
|
||||
onChange={handleOnSelectedRegionOptionChange}
|
||||
options={regionOptions}
|
||||
styles={{ root: { marginBottom: "10px" } }}
|
||||
/>
|
||||
</div>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
)}
|
||||
{userContext.apiType === "SQL" && !isEmulator && (
|
||||
<>
|
||||
<AccordionItem value="4">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Query Timeout</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
When a query reaches a specified time limit, a popup with an option to cancel the query will
|
||||
show unless automatic cancellation has been enabled.
|
||||
</div>
|
||||
<Toggle
|
||||
styles={toggleStyles}
|
||||
label="Enable query timeout"
|
||||
onChange={handleOnQueryTimeoutToggleChange}
|
||||
defaultChecked={queryTimeoutEnabled}
|
||||
/>
|
||||
</div>
|
||||
{queryTimeoutEnabled && (
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<SpinButton
|
||||
label="Query timeout (ms)"
|
||||
labelPosition={Position.top}
|
||||
defaultValue={(queryTimeout || 5000).toString()}
|
||||
min={100}
|
||||
step={1000}
|
||||
onChange={handleOnQueryTimeoutSpinButtonChange}
|
||||
incrementButtonAriaLabel="Increase value by 1000"
|
||||
decrementButtonAriaLabel="Decrease value by 1000"
|
||||
styles={spinButtonStyles}
|
||||
/>
|
||||
<Toggle
|
||||
label="Automatically cancel query after timeout"
|
||||
styles={toggleStyles}
|
||||
onChange={handleOnAutomaticallyCancelQueryToggleChange}
|
||||
defaultChecked={automaticallyCancelQueryAfterTimeout}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
|
||||
{showRetrySettings && (
|
||||
<AccordionItem value="7">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Retry Settings</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Retry policy associated with throttled requests during CosmosDB queries.
|
||||
<AccordionItem value="5">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>RU Limit</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
If a query exceeds a configured RU limit, the query will be aborted.
|
||||
</div>
|
||||
<Toggle
|
||||
styles={toggleStyles}
|
||||
label="Enable RU limit"
|
||||
onChange={handleOnRUThresholdToggleChange}
|
||||
defaultChecked={ruThresholdEnabled}
|
||||
/>
|
||||
</div>
|
||||
{ruThresholdEnabled && (
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<SpinButton
|
||||
label="RU Limit (RU)"
|
||||
labelPosition={Position.top}
|
||||
defaultValue={(ruThreshold || DefaultRUThreshold).toString()}
|
||||
min={1}
|
||||
step={1000}
|
||||
onChange={handleOnRUThresholdSpinButtonChange}
|
||||
incrementButtonAriaLabel="Increase value by 1000"
|
||||
decrementButtonAriaLabel="Decrease value by 1000"
|
||||
styles={spinButtonStyles}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
|
||||
<AccordionItem value="6">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Default Query Results View</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Select the default view to use when displaying query results.
|
||||
</div>
|
||||
<ChoiceGroup
|
||||
ariaLabelledBy="defaultQueryResultsView"
|
||||
selectedKey={defaultQueryResultsView}
|
||||
options={defaultQueryResultsViewOptionList}
|
||||
styles={choiceButtonStyles}
|
||||
onChange={handleOnDefaultQueryResultsViewChange}
|
||||
/>
|
||||
</div>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
</>
|
||||
)}
|
||||
|
||||
{showRetrySettings && (
|
||||
<AccordionItem value="7">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Retry Settings</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Retry policy associated with throttled requests during CosmosDB queries.
|
||||
</div>
|
||||
<div>
|
||||
<span className={styles.subHeader}>Max retry attempts</span>
|
||||
<InfoTooltip className={styles.headerIcon}>
|
||||
Max number of retries to be performed for a request. Default value 9.
|
||||
</InfoTooltip>
|
||||
</div>
|
||||
<SpinButton
|
||||
labelPosition={Position.top}
|
||||
min={1}
|
||||
step={1}
|
||||
value={"" + retryAttempts}
|
||||
onChange={handleOnQueryRetryAttemptsSpinButtonChange}
|
||||
incrementButtonAriaLabel="Increase value by 1"
|
||||
decrementButtonAriaLabel="Decrease value by 1"
|
||||
onIncrement={(newValue) => setRetryAttempts(parseInt(newValue) + 1 || retryAttempts)}
|
||||
onDecrement={(newValue) => setRetryAttempts(parseInt(newValue) - 1 || retryAttempts)}
|
||||
onValidate={(newValue) => setRetryAttempts(parseInt(newValue) || retryAttempts)}
|
||||
styles={spinButtonStyles}
|
||||
/>
|
||||
<div>
|
||||
<span className={styles.subHeader}>Fixed retry interval (ms)</span>
|
||||
<InfoTooltip className={styles.headerIcon}>
|
||||
Fixed retry interval in milliseconds to wait between each retry ignoring the retryAfter returned
|
||||
as part of the response. Default value is 0 milliseconds.
|
||||
</InfoTooltip>
|
||||
</div>
|
||||
<SpinButton
|
||||
labelPosition={Position.top}
|
||||
min={1000}
|
||||
step={1000}
|
||||
value={"" + retryInterval}
|
||||
onChange={handleOnRetryIntervalSpinButtonChange}
|
||||
incrementButtonAriaLabel="Increase value by 1000"
|
||||
decrementButtonAriaLabel="Decrease value by 1000"
|
||||
onIncrement={(newValue) => setRetryInterval(parseInt(newValue) + 1000 || retryInterval)}
|
||||
onDecrement={(newValue) => setRetryInterval(parseInt(newValue) - 1000 || retryInterval)}
|
||||
onValidate={(newValue) => setRetryInterval(parseInt(newValue) || retryInterval)}
|
||||
styles={spinButtonStyles}
|
||||
/>
|
||||
<div>
|
||||
<span className={styles.subHeader}>Max wait time (s)</span>
|
||||
<InfoTooltip className={styles.headerIcon}>
|
||||
Max wait time in seconds to wait for a request while the retries are happening. Default value 30
|
||||
seconds.
|
||||
</InfoTooltip>
|
||||
</div>
|
||||
<SpinButton
|
||||
labelPosition={Position.top}
|
||||
min={1}
|
||||
step={1}
|
||||
value={"" + MaxWaitTimeInSeconds}
|
||||
onChange={handleOnMaxWaitTimeSpinButtonChange}
|
||||
incrementButtonAriaLabel="Increase value by 1"
|
||||
decrementButtonAriaLabel="Decrease value by 1"
|
||||
onIncrement={(newValue) =>
|
||||
setMaxWaitTimeInSeconds(parseInt(newValue) + 1 || MaxWaitTimeInSeconds)
|
||||
}
|
||||
onDecrement={(newValue) =>
|
||||
setMaxWaitTimeInSeconds(parseInt(newValue) - 1 || MaxWaitTimeInSeconds)
|
||||
}
|
||||
onValidate={(newValue) => setMaxWaitTimeInSeconds(parseInt(newValue) || MaxWaitTimeInSeconds)}
|
||||
styles={spinButtonStyles}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<span className={styles.subHeader}>Max retry attempts</span>
|
||||
<InfoTooltip className={styles.headerIcon}>
|
||||
Max number of retries to be performed for a request. Default value 9.
|
||||
</InfoTooltip>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
)}
|
||||
{!isEmulator && (
|
||||
<AccordionItem value="8">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Enable container pagination</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Load 50 containers at a time. Currently, containers are not pulled in alphanumeric order.
|
||||
</div>
|
||||
<Checkbox
|
||||
styles={{
|
||||
label: { padding: 0 },
|
||||
}}
|
||||
className="padding"
|
||||
ariaLabel="Enable container pagination"
|
||||
checked={containerPaginationEnabled}
|
||||
onChange={() => setContainerPaginationEnabled(!containerPaginationEnabled)}
|
||||
label="Enable container pagination"
|
||||
/>
|
||||
</div>
|
||||
<SpinButton
|
||||
labelPosition={Position.top}
|
||||
min={1}
|
||||
step={1}
|
||||
value={"" + retryAttempts}
|
||||
onChange={handleOnQueryRetryAttemptsSpinButtonChange}
|
||||
incrementButtonAriaLabel="Increase value by 1"
|
||||
decrementButtonAriaLabel="Decrease value by 1"
|
||||
onIncrement={(newValue) => setRetryAttempts(parseInt(newValue) + 1 || retryAttempts)}
|
||||
onDecrement={(newValue) => setRetryAttempts(parseInt(newValue) - 1 || retryAttempts)}
|
||||
onValidate={(newValue) => setRetryAttempts(parseInt(newValue) || retryAttempts)}
|
||||
styles={spinButtonStyles}
|
||||
/>
|
||||
<div>
|
||||
<span className={styles.subHeader}>Fixed retry interval (ms)</span>
|
||||
<InfoTooltip className={styles.headerIcon}>
|
||||
Fixed retry interval in milliseconds to wait between each retry ignoring the retryAfter returned
|
||||
as part of the response. Default value is 0 milliseconds.
|
||||
</InfoTooltip>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
)}
|
||||
{shouldShowCrossPartitionOption && (
|
||||
<AccordionItem value="9">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Enable cross-partition query</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Send more than one request while executing a query. More than one request is necessary if the
|
||||
query is not scoped to single partition key value.
|
||||
</div>
|
||||
<Checkbox
|
||||
styles={{
|
||||
label: { padding: 0 },
|
||||
}}
|
||||
className="padding"
|
||||
ariaLabel="Enable cross partition query"
|
||||
checked={crossPartitionQueryEnabled}
|
||||
onChange={() => setCrossPartitionQueryEnabled(!crossPartitionQueryEnabled)}
|
||||
label="Enable cross-partition query"
|
||||
/>
|
||||
</div>
|
||||
<SpinButton
|
||||
labelPosition={Position.top}
|
||||
min={1000}
|
||||
step={1000}
|
||||
value={"" + retryInterval}
|
||||
onChange={handleOnRetryIntervalSpinButtonChange}
|
||||
incrementButtonAriaLabel="Increase value by 1000"
|
||||
decrementButtonAriaLabel="Decrease value by 1000"
|
||||
onIncrement={(newValue) => setRetryInterval(parseInt(newValue) + 1000 || retryInterval)}
|
||||
onDecrement={(newValue) => setRetryInterval(parseInt(newValue) - 1000 || retryInterval)}
|
||||
onValidate={(newValue) => setRetryInterval(parseInt(newValue) || retryInterval)}
|
||||
styles={spinButtonStyles}
|
||||
/>
|
||||
<div>
|
||||
<span className={styles.subHeader}>Max wait time (s)</span>
|
||||
<InfoTooltip className={styles.headerIcon}>
|
||||
Max wait time in seconds to wait for a request while the retries are happening. Default value 30
|
||||
seconds.
|
||||
</InfoTooltip>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
)}
|
||||
{shouldShowParallelismOption && (
|
||||
<AccordionItem value="10">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Max degree of parallelism</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Gets or sets the number of concurrent operations run client side during parallel query execution.
|
||||
A positive property value limits the number of concurrent operations to the set value. If it is
|
||||
set to less than 0, the system automatically decides the number of concurrent operations to run.
|
||||
</div>
|
||||
<SpinButton
|
||||
min={-1}
|
||||
step={1}
|
||||
className="textfontclr"
|
||||
role="textbox"
|
||||
id="max-degree"
|
||||
value={"" + maxDegreeOfParallelism}
|
||||
onIncrement={(newValue) =>
|
||||
setMaxDegreeOfParallelism(parseInt(newValue) + 1 || maxDegreeOfParallelism)
|
||||
}
|
||||
onDecrement={(newValue) =>
|
||||
setMaxDegreeOfParallelism(parseInt(newValue) - 1 || maxDegreeOfParallelism)
|
||||
}
|
||||
onValidate={(newValue) => setMaxDegreeOfParallelism(parseInt(newValue) || maxDegreeOfParallelism)}
|
||||
ariaLabel="Max degree of parallelism"
|
||||
label="Max degree of parallelism"
|
||||
/>
|
||||
</div>
|
||||
<SpinButton
|
||||
labelPosition={Position.top}
|
||||
min={1}
|
||||
step={1}
|
||||
value={"" + MaxWaitTimeInSeconds}
|
||||
onChange={handleOnMaxWaitTimeSpinButtonChange}
|
||||
incrementButtonAriaLabel="Increase value by 1"
|
||||
decrementButtonAriaLabel="Decrease value by 1"
|
||||
onIncrement={(newValue) => setMaxWaitTimeInSeconds(parseInt(newValue) + 1 || MaxWaitTimeInSeconds)}
|
||||
onDecrement={(newValue) => setMaxWaitTimeInSeconds(parseInt(newValue) - 1 || MaxWaitTimeInSeconds)}
|
||||
onValidate={(newValue) => setMaxWaitTimeInSeconds(parseInt(newValue) || MaxWaitTimeInSeconds)}
|
||||
styles={spinButtonStyles}
|
||||
/>
|
||||
</div>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
)}
|
||||
{!isEmulator && (
|
||||
<AccordionItem value="8">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Enable container pagination</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Load 50 containers at a time. Currently, containers are not pulled in alphanumeric order.
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
)}
|
||||
{shouldShowPriorityLevelOption && (
|
||||
<AccordionItem value="11">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Priority Level</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Sets the priority level for data-plane requests from Data Explorer when using Priority-Based
|
||||
Execution. If "None" is selected, Data Explorer will not specify priority level, and the
|
||||
server-side default priority level will be used.
|
||||
</div>
|
||||
<ChoiceGroup
|
||||
ariaLabelledBy="priorityLevel"
|
||||
selectedKey={priorityLevel}
|
||||
options={priorityLevelOptionList}
|
||||
styles={choiceButtonStyles}
|
||||
onChange={handleOnPriorityLevelOptionChange}
|
||||
/>
|
||||
</div>
|
||||
<Checkbox
|
||||
styles={{
|
||||
label: { padding: 0 },
|
||||
}}
|
||||
className="padding"
|
||||
ariaLabel="Enable container pagination"
|
||||
checked={containerPaginationEnabled}
|
||||
onChange={() => setContainerPaginationEnabled(!containerPaginationEnabled)}
|
||||
label="Enable container pagination"
|
||||
/>
|
||||
</div>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
)}
|
||||
{shouldShowCrossPartitionOption && (
|
||||
<AccordionItem value="9">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Enable cross-partition query</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Send more than one request while executing a query. More than one request is necessary if the query
|
||||
is not scoped to single partition key value.
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
)}
|
||||
{shouldShowGraphAutoVizOption && (
|
||||
<AccordionItem value="12">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Display Gremlin query results as: </div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Select Graph to automatically visualize the query results as a Graph or JSON to display the
|
||||
results as JSON.
|
||||
</div>
|
||||
<ChoiceGroup
|
||||
selectedKey={graphAutoVizDisabled}
|
||||
options={graphAutoOptionList}
|
||||
onChange={handleOnGremlinChange}
|
||||
aria-label="Graph Auto-visualization"
|
||||
/>
|
||||
</div>
|
||||
<Checkbox
|
||||
styles={{
|
||||
label: { padding: 0 },
|
||||
}}
|
||||
className="padding"
|
||||
ariaLabel="Enable cross partition query"
|
||||
checked={crossPartitionQueryEnabled}
|
||||
onChange={() => setCrossPartitionQueryEnabled(!crossPartitionQueryEnabled)}
|
||||
label="Enable cross-partition query"
|
||||
/>
|
||||
</div>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
)}
|
||||
{shouldShowParallelismOption && (
|
||||
<AccordionItem value="10">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Max degree of parallelism</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Gets or sets the number of concurrent operations run client side during parallel query execution. A
|
||||
positive property value limits the number of concurrent operations to the set value. If it is set to
|
||||
less than 0, the system automatically decides the number of concurrent operations to run.
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
)}
|
||||
{shouldShowCopilotSampleDBOption && (
|
||||
<AccordionItem value="13">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Enable sample database</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
This is a sample database and collection with synthetic product data you can use to explore using
|
||||
NoSQL queries and Query Advisor. This will appear as another database in the Data Explorer UI, and
|
||||
is created by, and maintained by Microsoft at no cost to you.
|
||||
</div>
|
||||
<Checkbox
|
||||
styles={{
|
||||
label: { padding: 0 },
|
||||
}}
|
||||
className="padding"
|
||||
ariaLabel="Enable sample db for Query Advisor"
|
||||
checked={copilotSampleDBEnabled}
|
||||
onChange={handleSampleDatabaseChange}
|
||||
label="Enable sample database"
|
||||
/>
|
||||
</div>
|
||||
<SpinButton
|
||||
min={-1}
|
||||
step={1}
|
||||
className="textfontclr"
|
||||
role="textbox"
|
||||
id="max-degree"
|
||||
value={"" + maxDegreeOfParallelism}
|
||||
onIncrement={(newValue) =>
|
||||
setMaxDegreeOfParallelism(parseInt(newValue) + 1 || maxDegreeOfParallelism)
|
||||
}
|
||||
onDecrement={(newValue) =>
|
||||
setMaxDegreeOfParallelism(parseInt(newValue) - 1 || maxDegreeOfParallelism)
|
||||
}
|
||||
onValidate={(newValue) => setMaxDegreeOfParallelism(parseInt(newValue) || maxDegreeOfParallelism)}
|
||||
ariaLabel="Max degree of parallelism"
|
||||
label="Max degree of parallelism"
|
||||
/>
|
||||
</div>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
)}
|
||||
{shouldShowPriorityLevelOption && (
|
||||
<AccordionItem value="11">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Priority Level</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Sets the priority level for data-plane requests from Data Explorer when using Priority-Based
|
||||
Execution. If "None" is selected, Data Explorer will not specify priority level, and the
|
||||
server-side default priority level will be used.
|
||||
</div>
|
||||
<ChoiceGroup
|
||||
ariaLabelledBy="priorityLevel"
|
||||
selectedKey={priorityLevel}
|
||||
options={priorityLevelOptionList}
|
||||
styles={choiceButtonStyles}
|
||||
onChange={handleOnPriorityLevelOptionChange}
|
||||
/>
|
||||
</div>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
)}
|
||||
{shouldShowGraphAutoVizOption && (
|
||||
<AccordionItem value="12">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Display Gremlin query results as: </div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
Select Graph to automatically visualize the query results as a Graph or JSON to display the results
|
||||
as JSON.
|
||||
</div>
|
||||
<ChoiceGroup
|
||||
selectedKey={graphAutoVizDisabled}
|
||||
options={graphAutoOptionList}
|
||||
onChange={handleOnGremlinChange}
|
||||
aria-label="Graph Auto-visualization"
|
||||
/>
|
||||
</div>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
)}
|
||||
{shouldShowCopilotSampleDBOption && (
|
||||
<AccordionItem value="13">
|
||||
<AccordionHeader>
|
||||
<div className={styles.header}>Enable sample database</div>
|
||||
</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className={styles.settingsSectionContainer}>
|
||||
<div className={styles.settingsSectionDescription}>
|
||||
This is a sample database and collection with synthetic product data you can use to explore using
|
||||
NoSQL queries and Query Advisor. This will appear as another database in the Data Explorer UI, and
|
||||
is created by, and maintained by Microsoft at no cost to you.
|
||||
</div>
|
||||
<Checkbox
|
||||
styles={{
|
||||
label: { padding: 0 },
|
||||
}}
|
||||
className="padding"
|
||||
ariaLabel="Enable sample db for Query Advisor"
|
||||
checked={copilotSampleDBEnabled}
|
||||
onChange={handleSampleDatabaseChange}
|
||||
label="Enable sample database"
|
||||
/>
|
||||
</div>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
)}
|
||||
</Accordion>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
)}
|
||||
</Accordion>
|
||||
)}
|
||||
|
||||
<div className="settingsSection">
|
||||
<div className="settingsSectionPart">
|
||||
|
@ -22,12 +22,17 @@ export const DeletePopup = ({
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal isOpen={showDeletePopup} styles={{ main: { minHeight: "122px", minWidth: "880px" } }}>
|
||||
<Modal
|
||||
isOpen={showDeletePopup}
|
||||
styles={{ main: { minHeight: "122px", minWidth: "880px" } }}
|
||||
titleAriaId="deleteDialogTitle"
|
||||
subtitleAriaId="deleteDialogSubTitle"
|
||||
>
|
||||
<Stack style={{ padding: "16px 24px", height: "auto" }}>
|
||||
<Text style={{ height: 24, fontSize: "18px" }}>
|
||||
<Text id="deleteDialogTitle" style={{ height: 24, fontSize: "18px" }}>
|
||||
<b>Delete code?</b>
|
||||
</Text>
|
||||
<Text style={{ marginTop: 10, marginBottom: 20 }}>
|
||||
<Text id="deleteDialogSubTitle" style={{ marginTop: 10, marginBottom: 20 }}>
|
||||
This will clear the query from the query builder pane along with all comments and also reset the prompt pane
|
||||
</Text>
|
||||
<Stack horizontal tokens={{ childrenGap: 10 }} horizontalAlign="start">
|
||||
|
@ -11,6 +11,8 @@ exports[`Delete Popup snapshot test should not render when showDeletePopup is fa
|
||||
},
|
||||
}
|
||||
}
|
||||
subtitleAriaId="deleteDialogSubTitle"
|
||||
titleAriaId="deleteDialogTitle"
|
||||
>
|
||||
<Stack
|
||||
style={
|
||||
@ -21,6 +23,7 @@ exports[`Delete Popup snapshot test should not render when showDeletePopup is fa
|
||||
}
|
||||
>
|
||||
<Text
|
||||
id="deleteDialogTitle"
|
||||
style={
|
||||
{
|
||||
"fontSize": "18px",
|
||||
@ -33,6 +36,7 @@ exports[`Delete Popup snapshot test should not render when showDeletePopup is fa
|
||||
</b>
|
||||
</Text>
|
||||
<Text
|
||||
id="deleteDialogSubTitle"
|
||||
style={
|
||||
{
|
||||
"marginBottom": 20,
|
||||
@ -89,6 +93,8 @@ exports[`Delete Popup snapshot test should render when showDeletePopup is true 1
|
||||
},
|
||||
}
|
||||
}
|
||||
subtitleAriaId="deleteDialogSubTitle"
|
||||
titleAriaId="deleteDialogTitle"
|
||||
>
|
||||
<Stack
|
||||
style={
|
||||
@ -99,6 +105,7 @@ exports[`Delete Popup snapshot test should render when showDeletePopup is true 1
|
||||
}
|
||||
>
|
||||
<Text
|
||||
id="deleteDialogTitle"
|
||||
style={
|
||||
{
|
||||
"fontSize": "18px",
|
||||
@ -111,6 +118,7 @@ exports[`Delete Popup snapshot test should render when showDeletePopup is true 1
|
||||
</b>
|
||||
</Text>
|
||||
<Text
|
||||
id="deleteDialogSubTitle"
|
||||
style={
|
||||
{
|
||||
"marginBottom": 20,
|
||||
|
@ -27,7 +27,7 @@ import { CosmosFluentProvider, cosmosShorthands, tokens } from "Explorer/Theme/T
|
||||
import { ResourceTree } from "Explorer/Tree/ResourceTree";
|
||||
import { useDatabases } from "Explorer/useDatabases";
|
||||
import { KeyboardAction, KeyboardActionGroup, KeyboardActionHandler, useKeyboardActionGroup } from "KeyboardShortcuts";
|
||||
import { isFabric, isFabricMirrored, isFabricNative } from "Platform/Fabric/FabricUtil";
|
||||
import { isFabric, isFabricMirrored, isFabricNative, isFabricNativeReadOnly } from "Platform/Fabric/FabricUtil";
|
||||
import { userContext } from "UserContext";
|
||||
import { getCollectionName, getDatabaseName } from "Utils/APITypeUtils";
|
||||
import { Allotment, AllotmentHandle } from "allotment";
|
||||
@ -318,6 +318,7 @@ export const SidebarContainer: React.FC<SidebarProps> = ({ explorer }) => {
|
||||
|
||||
const hasGlobalCommands = !(
|
||||
isFabricMirrored() ||
|
||||
isFabricNativeReadOnly() ||
|
||||
userContext.apiType === "Postgres" ||
|
||||
userContext.apiType === "VCoreMongo"
|
||||
);
|
||||
|
@ -5,7 +5,7 @@ import { Link, makeStyles, tokens } from "@fluentui/react-components";
|
||||
import { DocumentAddRegular, LinkMultipleRegular } from "@fluentui/react-icons";
|
||||
import { SampleDataImportDialog } from "Explorer/SplashScreen/SampleDataImportDialog";
|
||||
import { CosmosFluentProvider } from "Explorer/Theme/ThemeUtil";
|
||||
import { isFabricNative } from "Platform/Fabric/FabricUtil";
|
||||
import { isFabricNative, isFabricNativeReadOnly } from "Platform/Fabric/FabricUtil";
|
||||
import * as React from "react";
|
||||
import { userContext } from "UserContext";
|
||||
import CosmosDbBlackIcon from "../../../images/CosmosDB_black.svg";
|
||||
@ -62,6 +62,15 @@ const useStyles = makeStyles({
|
||||
margin: "auto",
|
||||
},
|
||||
},
|
||||
single: {
|
||||
gridColumn: "1 / 4",
|
||||
gridRow: "1 / 3",
|
||||
"& svg": {
|
||||
width: "64px",
|
||||
height: "64px",
|
||||
margin: "auto",
|
||||
},
|
||||
},
|
||||
buttonContainer: {
|
||||
height: "100%",
|
||||
display: "flex",
|
||||
@ -150,7 +159,11 @@ export const FabricHomeScreen: React.FC<SplashScreenProps> = (props: SplashScree
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
return isFabricNativeReadOnly() ? (
|
||||
<div className={styles.buttonsContainer}>
|
||||
<FabricHomeScreenButton className={styles.single} {...buttons[2]} />
|
||||
</div>
|
||||
) : (
|
||||
<div className={styles.buttonsContainer}>
|
||||
<FabricHomeScreenButton className={styles.one} {...buttons[0]} />
|
||||
<FabricHomeScreenButton className={styles.two} {...buttons[1]} />
|
||||
@ -159,7 +172,7 @@ export const FabricHomeScreen: React.FC<SplashScreenProps> = (props: SplashScree
|
||||
);
|
||||
};
|
||||
|
||||
const title = "Build your database";
|
||||
const title = isFabricNativeReadOnly() ? "Use your database" : "Build your database";
|
||||
return (
|
||||
<>
|
||||
<CosmosFluentProvider className={styles.homeContainer}>
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { BackendDefaults } from "Common/Constants";
|
||||
import { createCollection } from "Common/dataAccess/createCollection";
|
||||
import Explorer from "Explorer/Explorer";
|
||||
import { useDatabases } from "Explorer/useDatabases";
|
||||
@ -35,6 +36,11 @@ export const createContainer = async (
|
||||
collectionId: containerName,
|
||||
databaseId: databaseName,
|
||||
databaseLevelThroughput: false,
|
||||
partitionKey: {
|
||||
paths: [`/${SAMPLE_DATA_PARTITION_KEY}`],
|
||||
kind: "Hash",
|
||||
version: BackendDefaults.partitionKeyVersion,
|
||||
},
|
||||
};
|
||||
await createCollection(createRequest);
|
||||
await explorer.refreshAllDatabases();
|
||||
@ -47,6 +53,8 @@ export const createContainer = async (
|
||||
return newCollection;
|
||||
};
|
||||
|
||||
const SAMPLE_DATA_PARTITION_KEY = "category"; // This pkey is specifically set for queryCopilotSampleData.json below
|
||||
|
||||
export const importData = async (collection: ViewModels.Collection): Promise<void> => {
|
||||
// TODO: keep same chunk as ContainerSampleGenerator
|
||||
const dataFileContent = await import(
|
||||
|
@ -817,7 +817,7 @@ export class SplashScreen extends React.Component<SplashScreenProps> {
|
||||
|
||||
private vcoreMongoNextStepItems: { link: string; title: string; description: string }[] = [
|
||||
{
|
||||
link: "https://learn.microsoft.com/en-us/azure/cosmos-db/mongodb/vcore/how-to-migrate-native-tools?tabs=export-import",
|
||||
link: "https://learn.microsoft.com/azure/cosmos-db/mongodb/vcore/migration-options",
|
||||
title: "Migrate Data",
|
||||
description: "",
|
||||
},
|
||||
|
@ -0,0 +1,80 @@
|
||||
import { FitAddon } from "@xterm/addon-fit";
|
||||
import { Terminal } from "@xterm/xterm";
|
||||
import React, { useEffect, useRef } from "react";
|
||||
import "xterm/css/xterm.css";
|
||||
import { DatabaseAccount } from "../../../Contracts/DataModels";
|
||||
import { TerminalKind } from "../../../Contracts/ViewModels";
|
||||
import { startCloudShellTerminal } from "./CloudShellTerminalCore";
|
||||
|
||||
export interface CloudShellTerminalComponentProps {
|
||||
databaseAccount: DatabaseAccount;
|
||||
tabId: string;
|
||||
username?: string;
|
||||
shellType?: TerminalKind;
|
||||
}
|
||||
|
||||
export const CloudShellTerminalComponent: React.FC<CloudShellTerminalComponentProps> = (props) => {
|
||||
const terminalRef = useRef(null); // Reference for terminal container
|
||||
const xtermRef = useRef(null); // Reference for XTerm instance
|
||||
const socketRef = useRef(null); // Reference for WebSocket
|
||||
|
||||
useEffect(() => {
|
||||
// Initialize XTerm instance
|
||||
const terminal = new Terminal({
|
||||
cursorBlink: true,
|
||||
cursorStyle: "bar",
|
||||
fontFamily: "monospace",
|
||||
fontSize: 11,
|
||||
theme: {
|
||||
background: "#1e1e1e",
|
||||
foreground: "#d4d4d4",
|
||||
cursor: "#ffcc00",
|
||||
},
|
||||
scrollback: 1000,
|
||||
});
|
||||
|
||||
const fitAddon = new FitAddon();
|
||||
terminal.loadAddon(fitAddon);
|
||||
// Attach terminal to the DOM
|
||||
if (terminalRef.current) {
|
||||
terminal.open(terminalRef.current);
|
||||
xtermRef.current = terminal;
|
||||
}
|
||||
|
||||
// Defer terminal sizing until after DOM rendering is complete
|
||||
setTimeout(() => {
|
||||
fitAddon.fit();
|
||||
}, 0);
|
||||
|
||||
// Use ResizeObserver instead of window resize
|
||||
const resizeObserver = new ResizeObserver(() => {
|
||||
const container = terminalRef.current;
|
||||
if (container && container.offsetWidth > 0 && container.offsetHeight > 0) {
|
||||
try {
|
||||
fitAddon.fit();
|
||||
} catch (e) {
|
||||
console.warn("Fit failed on resize:", e);
|
||||
}
|
||||
}
|
||||
});
|
||||
resizeObserver.observe(terminalRef.current);
|
||||
|
||||
socketRef.current = startCloudShellTerminal(terminal, props.shellType);
|
||||
|
||||
// Cleanup function to close WebSocket and dispose terminal
|
||||
return () => {
|
||||
if (!socketRef.current) {
|
||||
return;
|
||||
}
|
||||
if (socketRef.current && socketRef.current.readyState && socketRef.current.readyState === WebSocket.OPEN) {
|
||||
socketRef.current.close(); // Close WebSocket connection
|
||||
}
|
||||
if (resizeObserver && terminalRef.current) {
|
||||
resizeObserver.unobserve(terminalRef.current);
|
||||
}
|
||||
terminal.dispose(); // Clean up XTerm instance
|
||||
};
|
||||
}, []);
|
||||
|
||||
return <div ref={terminalRef} style={{ width: "100%", height: "500px" }} />;
|
||||
};
|
290
src/Explorer/Tabs/CloudShellTab/CloudShellTerminalCore.tsx
Normal file
290
src/Explorer/Tabs/CloudShellTab/CloudShellTerminalCore.tsx
Normal file
@ -0,0 +1,290 @@
|
||||
import { Terminal } from "@xterm/xterm";
|
||||
import { Areas } from "../../../Common/Constants";
|
||||
import { getErrorMessage, getErrorStack } from "../../../Common/ErrorHandlingUtils";
|
||||
import { TerminalKind } from "../../../Contracts/ViewModels";
|
||||
import { Action, ActionModifiers } from "../../../Shared/Telemetry/TelemetryConstants";
|
||||
import * as TelemetryProcessor from "../../../Shared/Telemetry/TelemetryProcessor";
|
||||
import { userContext } from "../../../UserContext";
|
||||
import {
|
||||
connectTerminal,
|
||||
provisionConsole,
|
||||
putEphemeralUserSettings,
|
||||
registerCloudShellProvider,
|
||||
verifyCloudShellProviderRegistration,
|
||||
} from "./Data/CloudShellClient";
|
||||
import { CloudShellProviderInfo, ProvisionConsoleResponse } from "./Models/DataModels";
|
||||
import { AbstractShellHandler, START_MARKER } from "./ShellTypes/AbstractShellHandler";
|
||||
import { getHandler } from "./ShellTypes/ShellTypeFactory";
|
||||
import { AttachAddon } from "./Utils/AttachAddOn";
|
||||
import { askConfirmation, wait } from "./Utils/CommonUtils";
|
||||
import { getNormalizedRegion } from "./Utils/RegionUtils";
|
||||
import { formatErrorMessage, formatInfoMessage, formatWarningMessage } from "./Utils/TerminalLogFormats";
|
||||
|
||||
// Constants
|
||||
const DEFAULT_CLOUDSHELL_REGION = "westus";
|
||||
const POLLING_INTERVAL_MS = 2000;
|
||||
const MAX_RETRY_COUNT = 10;
|
||||
const MAX_PING_COUNT = 120 * 60; // 120 minutes (60 seconds/minute)
|
||||
|
||||
let pingCount = 0;
|
||||
let keepAliveID: NodeJS.Timeout = null;
|
||||
|
||||
/**
|
||||
* Main function to start a CloudShell terminal
|
||||
*/
|
||||
export const startCloudShellTerminal = async (terminal: Terminal, shellType: TerminalKind): Promise<WebSocket> => {
|
||||
const startKey = TelemetryProcessor.traceStart(Action.CloudShellTerminalSession, {
|
||||
shellType: TerminalKind[shellType],
|
||||
dataExplorerArea: Areas.CloudShell,
|
||||
});
|
||||
|
||||
let resolvedRegion: string;
|
||||
try {
|
||||
await ensureCloudShellProviderRegistered();
|
||||
|
||||
resolvedRegion = determineCloudShellRegion();
|
||||
// Ask for user consent for region
|
||||
const consentGranted = await askConfirmation(
|
||||
terminal,
|
||||
formatWarningMessage(
|
||||
"The shell environment may be operating in a region different from that of the database, which could impact performance or data compliance. Do you wish to proceed?",
|
||||
),
|
||||
);
|
||||
|
||||
// Track user decision
|
||||
TelemetryProcessor.trace(
|
||||
Action.CloudShellUserConsent,
|
||||
consentGranted ? ActionModifiers.Success : ActionModifiers.Cancel,
|
||||
{ dataExplorerArea: Areas.CloudShell },
|
||||
);
|
||||
|
||||
if (!consentGranted) {
|
||||
TelemetryProcessor.traceCancel(
|
||||
Action.CloudShellTerminalSession,
|
||||
{
|
||||
shellType: TerminalKind[shellType],
|
||||
dataExplorerArea: Areas.CloudShell,
|
||||
region: resolvedRegion,
|
||||
isConsent: false,
|
||||
},
|
||||
startKey,
|
||||
);
|
||||
terminal.writeln(
|
||||
formatErrorMessage("Session ended. Please close this tab and initiate a new shell session if needed."),
|
||||
);
|
||||
return null; // Exit if user declined
|
||||
}
|
||||
|
||||
terminal.writeln(formatInfoMessage("Connecting to CloudShell. This may take a moment. Please wait..."));
|
||||
|
||||
const sessionDetails: {
|
||||
socketUri?: string;
|
||||
provisionConsoleResponse?: ProvisionConsoleResponse;
|
||||
targetUri?: string;
|
||||
} = await provisionCloudShellSession(resolvedRegion, terminal);
|
||||
|
||||
if (!sessionDetails.socketUri) {
|
||||
terminal.writeln(formatErrorMessage("Failed to establish a connection. Please try again later."));
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get the shell handler for this type
|
||||
const shellHandler = await getHandler(shellType);
|
||||
// Configure WebSocket connection with shell-specific commands
|
||||
const socket = await establishTerminalConnection(terminal, shellHandler, sessionDetails.socketUri);
|
||||
|
||||
TelemetryProcessor.traceSuccess(
|
||||
Action.CloudShellTerminalSession,
|
||||
{
|
||||
shellType: TerminalKind[shellType],
|
||||
dataExplorerArea: Areas.CloudShell,
|
||||
region: resolvedRegion,
|
||||
socketUri: sessionDetails.socketUri,
|
||||
},
|
||||
startKey,
|
||||
);
|
||||
|
||||
return socket;
|
||||
} catch (err) {
|
||||
TelemetryProcessor.traceFailure(
|
||||
Action.CloudShellTerminalSession,
|
||||
{
|
||||
shellType: TerminalKind[shellType],
|
||||
dataExplorerArea: Areas.CloudShell,
|
||||
region: resolvedRegion,
|
||||
error: getErrorMessage(err),
|
||||
errorStack: getErrorStack(err),
|
||||
},
|
||||
startKey,
|
||||
);
|
||||
|
||||
terminal.writeln(formatErrorMessage(`Failed with error.${getErrorMessage(err)}`));
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Ensures that the CloudShell provider is registered for the current subscription
|
||||
*/
|
||||
export const ensureCloudShellProviderRegistered = async (): Promise<void> => {
|
||||
const response: CloudShellProviderInfo = await verifyCloudShellProviderRegistration(userContext.subscriptionId);
|
||||
|
||||
if (response.registrationState !== "Registered") {
|
||||
await registerCloudShellProvider(userContext.subscriptionId);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Determines the appropriate CloudShell region
|
||||
*/
|
||||
export const determineCloudShellRegion = (): string => {
|
||||
return getNormalizedRegion(userContext.databaseAccount?.location, DEFAULT_CLOUDSHELL_REGION);
|
||||
};
|
||||
|
||||
/**
|
||||
* Provisions a CloudShell session
|
||||
*/
|
||||
export const provisionCloudShellSession = async (
|
||||
resolvedRegion: string,
|
||||
terminal: Terminal,
|
||||
): Promise<{ socketUri?: string; provisionConsoleResponse?: ProvisionConsoleResponse; targetUri?: string }> => {
|
||||
// Apply user settings
|
||||
await putEphemeralUserSettings(userContext.subscriptionId, resolvedRegion);
|
||||
|
||||
// Provision console
|
||||
let provisionConsoleResponse;
|
||||
let attemptCounter = 0;
|
||||
|
||||
do {
|
||||
provisionConsoleResponse = await provisionConsole(resolvedRegion);
|
||||
attemptCounter++;
|
||||
|
||||
if (provisionConsoleResponse.properties.provisioningState === "Failed") {
|
||||
break;
|
||||
}
|
||||
|
||||
if (provisionConsoleResponse.properties.provisioningState !== "Succeeded") {
|
||||
await wait(POLLING_INTERVAL_MS);
|
||||
}
|
||||
} while (provisionConsoleResponse.properties.provisioningState !== "Succeeded" && attemptCounter < MAX_RETRY_COUNT);
|
||||
|
||||
if (provisionConsoleResponse.properties.provisioningState !== "Succeeded") {
|
||||
throw new Error(`Provisioning failed: ${provisionConsoleResponse.properties.provisioningState}`);
|
||||
}
|
||||
|
||||
// Connect terminal
|
||||
const connectTerminalResponse = await connectTerminal(provisionConsoleResponse.properties.uri, {
|
||||
rows: terminal.rows,
|
||||
cols: terminal.cols,
|
||||
});
|
||||
|
||||
const targetUri = `${provisionConsoleResponse.properties.uri}/terminals?cols=${terminal.cols}&rows=${terminal.rows}&version=2019-01-01&shell=bash`;
|
||||
const termId = connectTerminalResponse.id;
|
||||
|
||||
// Determine socket URI
|
||||
let socketUri = connectTerminalResponse.socketUri.replace(":443/", "");
|
||||
const targetUriBody = targetUri.replace("https://", "").split("?")[0];
|
||||
|
||||
// This socket URI transformation logic handles different Azure service endpoint formats.
|
||||
// If the returned socketUri doesn't contain the expected host, we construct it manually.
|
||||
// This ensures compatibility across different Azure regions and deployment configurations.
|
||||
if (socketUri.indexOf(targetUriBody) === -1) {
|
||||
socketUri = `wss://${targetUriBody}/${termId}`;
|
||||
}
|
||||
|
||||
// Special handling for ServiceBus-based endpoints which require a specific URI format
|
||||
// with the hierarchical connection ($hc) path segment for terminal connections
|
||||
if (targetUriBody.includes("servicebus")) {
|
||||
const targetUriBodyArr = targetUriBody.split("/");
|
||||
socketUri = `wss://${targetUriBodyArr[0]}/$hc/${targetUriBodyArr[1]}/terminals/${termId}`;
|
||||
}
|
||||
|
||||
return { socketUri, provisionConsoleResponse, targetUri };
|
||||
};
|
||||
|
||||
/**
|
||||
* Establishes a terminal connection via WebSocket
|
||||
*/
|
||||
export const establishTerminalConnection = async (
|
||||
terminal: Terminal,
|
||||
shellHandler: AbstractShellHandler,
|
||||
socketUri: string,
|
||||
): Promise<WebSocket> => {
|
||||
let socket = new WebSocket(socketUri);
|
||||
|
||||
// Get shell-specific initial commands
|
||||
const initCommands = shellHandler.getInitialCommands();
|
||||
|
||||
// Configure the socket
|
||||
socket = await configureSocketConnection(socket, socketUri, terminal, initCommands, 0);
|
||||
|
||||
const options = {
|
||||
startMarker: START_MARKER,
|
||||
shellHandler: shellHandler,
|
||||
};
|
||||
|
||||
// Attach the terminal addon
|
||||
const attachAddon = new AttachAddon(socket, options);
|
||||
terminal.loadAddon(attachAddon);
|
||||
|
||||
return socket;
|
||||
};
|
||||
|
||||
/**
|
||||
* Configures a WebSocket connection for the terminal
|
||||
*/
|
||||
export const configureSocketConnection = async (
|
||||
socket: WebSocket,
|
||||
uri: string,
|
||||
terminal: Terminal,
|
||||
initCommands: string,
|
||||
socketRetryCount: number,
|
||||
): Promise<WebSocket> => {
|
||||
sendTerminalStartupCommands(socket, initCommands);
|
||||
|
||||
socket.onerror = async () => {
|
||||
if (socketRetryCount < MAX_RETRY_COUNT && socket.readyState !== WebSocket.CLOSED) {
|
||||
await configureSocketConnection(socket, uri, terminal, initCommands, socketRetryCount + 1);
|
||||
} else {
|
||||
socket.close();
|
||||
}
|
||||
};
|
||||
|
||||
socket.onclose = () => {
|
||||
if (keepAliveID) {
|
||||
clearTimeout(keepAliveID);
|
||||
pingCount = 0;
|
||||
}
|
||||
};
|
||||
|
||||
return socket;
|
||||
};
|
||||
|
||||
export const sendTerminalStartupCommands = (socket: WebSocket, initCommands: string): void => {
|
||||
if (socket && socket.readyState === WebSocket.OPEN) {
|
||||
socket.send(initCommands);
|
||||
} else {
|
||||
socket.onopen = () => {
|
||||
socket.send(initCommands);
|
||||
|
||||
// ensures connections don't remain open indefinitely by implementing an automatic timeout after 20 minutes.
|
||||
const keepSocketAlive = (socket: WebSocket) => {
|
||||
if (socket.readyState === WebSocket.OPEN) {
|
||||
if (pingCount >= MAX_PING_COUNT) {
|
||||
socket.close();
|
||||
} else {
|
||||
socket.send("");
|
||||
pingCount++;
|
||||
// The code uses a recursive setTimeout pattern rather than setInterval,
|
||||
// which ensures each new ping only happens after the previous one completes
|
||||
// and naturally stops if the socket closes.
|
||||
keepAliveID = setTimeout(() => keepSocketAlive(socket), 1000);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
keepSocketAlive(socket);
|
||||
};
|
||||
}
|
||||
};
|
337
src/Explorer/Tabs/CloudShellTab/Data/CloudShellClient.test.tsx
Normal file
337
src/Explorer/Tabs/CloudShellTab/Data/CloudShellClient.test.tsx
Normal file
@ -0,0 +1,337 @@
|
||||
import { armRequest } from "../../../../Utils/arm/request";
|
||||
import { NetworkType, OsType, SessionType, ShellType } from "../Models/DataModels";
|
||||
import {
|
||||
connectTerminal,
|
||||
getUserSettings,
|
||||
provisionConsole,
|
||||
putEphemeralUserSettings,
|
||||
registerCloudShellProvider,
|
||||
verifyCloudShellProviderRegistration,
|
||||
} from "./CloudShellClient";
|
||||
|
||||
// Instead of redeclaring fetch, modify the global context
|
||||
/* eslint-disable @typescript-eslint/no-namespace */
|
||||
declare global {
|
||||
namespace NodeJS {
|
||||
interface Global {
|
||||
fetch: jest.Mock;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* eslint-enable @typescript-eslint/no-namespace */
|
||||
|
||||
// Define mock endpoint
|
||||
const MOCK_ARM_ENDPOINT = "https://mock-management.azure.com";
|
||||
|
||||
// Mock dependencies
|
||||
jest.mock("uuid", () => ({
|
||||
v4: jest.fn().mockReturnValue("mocked-uuid"),
|
||||
}));
|
||||
|
||||
jest.mock("../../../../ConfigContext", () => ({
|
||||
configContext: {
|
||||
ARM_ENDPOINT: "https://mock-management.azure.com",
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock("../../../../UserContext", () => ({
|
||||
userContext: {
|
||||
authorizationToken: "Bearer mock-token",
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock("../../../../Utils/arm/request");
|
||||
|
||||
jest.mock("../Utils/CommonUtils", () => ({
|
||||
getLocale: jest.fn().mockReturnValue("en-US"),
|
||||
}));
|
||||
|
||||
// Properly mock fetch with correct typings
|
||||
const mockJsonPromise = jest.fn();
|
||||
global.fetch = jest.fn().mockImplementationOnce(() => {
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
json: mockJsonPromise,
|
||||
text: jest.fn().mockResolvedValue(""),
|
||||
headers: new Headers(),
|
||||
} as unknown as Promise<Response>;
|
||||
}) as jest.Mock;
|
||||
|
||||
describe("CloudShellClient", () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
mockJsonPromise.mockClear();
|
||||
});
|
||||
|
||||
// Reset all mocks after all tests
|
||||
afterAll(() => {
|
||||
jest.resetAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
if (global.fetch) {
|
||||
delete global.fetch;
|
||||
}
|
||||
});
|
||||
|
||||
describe("getUserSettings", () => {
|
||||
it("should call armRequest with correct parameters and return settings", async () => {
|
||||
const mockSettings = { properties: { preferredLocation: "eastus" } };
|
||||
(armRequest as jest.Mock).mockResolvedValueOnce(mockSettings);
|
||||
|
||||
const result = await getUserSettings();
|
||||
|
||||
expect(armRequest).toHaveBeenCalledWith({
|
||||
host: MOCK_ARM_ENDPOINT,
|
||||
path: "/providers/Microsoft.Portal/userSettings/cloudconsole",
|
||||
method: "GET",
|
||||
apiVersion: "2023-02-01-preview",
|
||||
});
|
||||
expect(result).toEqual(mockSettings);
|
||||
});
|
||||
|
||||
it("should handle errors when settings retrieval fails", async () => {
|
||||
const mockError = new Error("Failed to get user settings");
|
||||
(armRequest as jest.Mock).mockRejectedValueOnce(mockError);
|
||||
|
||||
await expect(getUserSettings()).rejects.toThrow("Failed to get user settings");
|
||||
|
||||
expect(armRequest).toHaveBeenCalledWith({
|
||||
host: MOCK_ARM_ENDPOINT,
|
||||
path: "/providers/Microsoft.Portal/userSettings/cloudconsole",
|
||||
method: "GET",
|
||||
apiVersion: "2023-02-01-preview",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("putEphemeralUserSettings", () => {
|
||||
it("should call armRequest with default network settings", async () => {
|
||||
const mockResponse = { id: "settings-id" };
|
||||
(armRequest as jest.Mock).mockResolvedValueOnce(mockResponse);
|
||||
|
||||
const result = await putEphemeralUserSettings("sub-id", "eastus");
|
||||
|
||||
expect(armRequest).toHaveBeenCalledWith({
|
||||
host: MOCK_ARM_ENDPOINT,
|
||||
path: "/providers/Microsoft.Portal/userSettings/cloudconsole",
|
||||
method: "PUT",
|
||||
apiVersion: "2023-02-01-preview",
|
||||
body: {
|
||||
properties: {
|
||||
preferredOsType: OsType.Linux,
|
||||
preferredShellType: ShellType.Bash,
|
||||
preferredLocation: "eastus",
|
||||
networkType: NetworkType.Default,
|
||||
sessionType: SessionType.Ephemeral,
|
||||
userSubscription: "sub-id",
|
||||
vnetSettings: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
|
||||
it("should call armRequest with isolated network settings", async () => {
|
||||
const mockVNetSettings = { subnetId: "test-subnet" };
|
||||
const mockResponse = { id: "settings-id" };
|
||||
(armRequest as jest.Mock).mockResolvedValueOnce(mockResponse);
|
||||
|
||||
await putEphemeralUserSettings("sub-id", "eastus", mockVNetSettings);
|
||||
|
||||
expect(armRequest).toHaveBeenCalledWith({
|
||||
host: MOCK_ARM_ENDPOINT,
|
||||
path: "/providers/Microsoft.Portal/userSettings/cloudconsole",
|
||||
method: "PUT",
|
||||
apiVersion: "2023-02-01-preview",
|
||||
body: {
|
||||
properties: {
|
||||
preferredOsType: OsType.Linux,
|
||||
preferredShellType: ShellType.Bash,
|
||||
preferredLocation: "eastus",
|
||||
networkType: NetworkType.Isolated,
|
||||
sessionType: SessionType.Ephemeral,
|
||||
userSubscription: "sub-id",
|
||||
vnetSettings: mockVNetSettings,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle errors when updating settings fails", async () => {
|
||||
const mockError = new Error("Failed to update user settings");
|
||||
(armRequest as jest.Mock).mockRejectedValueOnce(mockError);
|
||||
|
||||
await expect(putEphemeralUserSettings("sub-id", "eastus")).rejects.toThrow("Failed to update user settings");
|
||||
|
||||
expect(armRequest).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("verifyCloudShellProviderRegistration", () => {
|
||||
it("should call armRequest with correct parameters", async () => {
|
||||
const mockResponse = { registrationState: "Registered" };
|
||||
(armRequest as jest.Mock).mockResolvedValueOnce(mockResponse);
|
||||
|
||||
const result = await verifyCloudShellProviderRegistration("sub-id");
|
||||
|
||||
expect(armRequest).toHaveBeenCalledWith({
|
||||
host: MOCK_ARM_ENDPOINT,
|
||||
path: "/subscriptions/sub-id/providers/Microsoft.CloudShell",
|
||||
method: "GET",
|
||||
apiVersion: "2022-12-01",
|
||||
});
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
|
||||
it("should handle errors when verification fails", async () => {
|
||||
const mockError = new Error("Failed to verify provider registration");
|
||||
(armRequest as jest.Mock).mockRejectedValueOnce(mockError);
|
||||
|
||||
await expect(verifyCloudShellProviderRegistration("sub-id")).rejects.toThrow(
|
||||
"Failed to verify provider registration",
|
||||
);
|
||||
|
||||
expect(armRequest).toHaveBeenCalledWith({
|
||||
host: MOCK_ARM_ENDPOINT,
|
||||
path: "/subscriptions/sub-id/providers/Microsoft.CloudShell",
|
||||
method: "GET",
|
||||
apiVersion: "2022-12-01",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("registerCloudShellProvider", () => {
|
||||
it("should call armRequest with correct parameters", async () => {
|
||||
const mockResponse = { operationId: "op-id" };
|
||||
(armRequest as jest.Mock).mockResolvedValueOnce(mockResponse);
|
||||
|
||||
const result = await registerCloudShellProvider("sub-id");
|
||||
|
||||
expect(armRequest).toHaveBeenCalledWith({
|
||||
host: MOCK_ARM_ENDPOINT,
|
||||
path: "/subscriptions/sub-id/providers/Microsoft.CloudShell/register",
|
||||
method: "POST",
|
||||
apiVersion: "2022-12-01",
|
||||
});
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
|
||||
it("should handle errors when registration fails", async () => {
|
||||
const mockError = new Error("Failed to register provider");
|
||||
(armRequest as jest.Mock).mockRejectedValueOnce(mockError);
|
||||
|
||||
await expect(registerCloudShellProvider("sub-id")).rejects.toThrow("Failed to register provider");
|
||||
|
||||
expect(armRequest).toHaveBeenCalledWith({
|
||||
host: MOCK_ARM_ENDPOINT,
|
||||
path: "/subscriptions/sub-id/providers/Microsoft.CloudShell/register",
|
||||
method: "POST",
|
||||
apiVersion: "2022-12-01",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("provisionConsole", () => {
|
||||
it("should call armRequest with correct parameters", async () => {
|
||||
const mockResponse = { uri: "https://shell.azure.com/console123" };
|
||||
(armRequest as jest.Mock).mockResolvedValueOnce(mockResponse);
|
||||
|
||||
const result = await provisionConsole("eastus");
|
||||
|
||||
expect(armRequest).toHaveBeenCalledWith({
|
||||
host: MOCK_ARM_ENDPOINT,
|
||||
path: "providers/Microsoft.Portal/consoles/default",
|
||||
method: "PUT",
|
||||
apiVersion: "2023-02-01-preview",
|
||||
customHeaders: {
|
||||
"x-ms-console-preferred-location": "eastus",
|
||||
},
|
||||
body: {
|
||||
properties: {
|
||||
osType: OsType.Linux,
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(result).toEqual(mockResponse);
|
||||
});
|
||||
|
||||
it("should handle errors when console provisioning fails", async () => {
|
||||
const mockError = new Error("Failed to provision console");
|
||||
(armRequest as jest.Mock).mockRejectedValueOnce(mockError);
|
||||
|
||||
await expect(provisionConsole("eastus")).rejects.toThrow("Failed to provision console");
|
||||
|
||||
expect(armRequest).toHaveBeenCalledWith({
|
||||
host: MOCK_ARM_ENDPOINT,
|
||||
path: "providers/Microsoft.Portal/consoles/default",
|
||||
method: "PUT",
|
||||
apiVersion: "2023-02-01-preview",
|
||||
customHeaders: {
|
||||
"x-ms-console-preferred-location": "eastus",
|
||||
},
|
||||
body: {
|
||||
properties: {
|
||||
osType: OsType.Linux,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("connectTerminal", () => {
|
||||
it("should call fetch with correct parameters", async () => {
|
||||
const consoleUri = "https://shell.azure.com/console123";
|
||||
const size = { rows: 24, cols: 80 };
|
||||
const mockTerminalResponse = { id: "terminal-id", socketUri: "wss://shell.azure.com/socket" };
|
||||
|
||||
// Setup the mock response
|
||||
mockJsonPromise.mockResolvedValueOnce(mockTerminalResponse);
|
||||
|
||||
const result = await connectTerminal(consoleUri, size);
|
||||
|
||||
expect(global.fetch).toHaveBeenCalledWith(
|
||||
"https://shell.azure.com/console123/terminals?cols=80&rows=24&version=2019-01-01&shell=bash",
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"Content-Length": "2",
|
||||
Authorization: "Bearer mock-token",
|
||||
"x-ms-client-request-id": "mocked-uuid",
|
||||
"Accept-Language": "en-US",
|
||||
},
|
||||
body: "{}",
|
||||
},
|
||||
);
|
||||
expect(mockJsonPromise).toHaveBeenCalled();
|
||||
expect(result).toEqual(mockTerminalResponse);
|
||||
});
|
||||
|
||||
it("should handle errors when terminal connection fails", async () => {
|
||||
const consoleUri = "https://shell.azure.com/console123";
|
||||
const size = { rows: 24, cols: 80 };
|
||||
|
||||
// Mock fetch to return a failed response
|
||||
global.fetch = jest.fn().mockImplementationOnce(() => {
|
||||
return {
|
||||
ok: false,
|
||||
status: 500,
|
||||
statusText: "Internal Server Error",
|
||||
json: jest.fn().mockRejectedValue(new Error("Failed to parse JSON")),
|
||||
text: jest.fn().mockResolvedValue("Server Error"),
|
||||
headers: new Headers(),
|
||||
} as unknown as Promise<Response>;
|
||||
});
|
||||
|
||||
await expect(connectTerminal(consoleUri, size)).rejects.toThrow(
|
||||
"Failed to connect to terminal: 500 Internal Server Error",
|
||||
);
|
||||
|
||||
expect(global.fetch).toHaveBeenCalledWith(
|
||||
"https://shell.azure.com/console123/terminals?cols=80&rows=24&version=2019-01-01&shell=bash",
|
||||
expect.any(Object),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
117
src/Explorer/Tabs/CloudShellTab/Data/CloudShellClient.tsx
Normal file
117
src/Explorer/Tabs/CloudShellTab/Data/CloudShellClient.tsx
Normal file
@ -0,0 +1,117 @@
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { configContext } from "../../../../ConfigContext";
|
||||
import { userContext } from "../../../../UserContext";
|
||||
import { armRequest } from "../../../../Utils/arm/request";
|
||||
import {
|
||||
CloudShellProviderInfo,
|
||||
CloudShellSettings,
|
||||
ConnectTerminalResponse,
|
||||
NetworkType,
|
||||
OsType,
|
||||
ProvisionConsoleResponse,
|
||||
SessionType,
|
||||
ShellType,
|
||||
} from "../Models/DataModels";
|
||||
import { getLocale } from "../Utils/CommonUtils";
|
||||
|
||||
export const getUserSettings = async (): Promise<CloudShellSettings> => {
|
||||
return await armRequest<CloudShellSettings>({
|
||||
host: configContext.ARM_ENDPOINT,
|
||||
path: `/providers/Microsoft.Portal/userSettings/cloudconsole`,
|
||||
method: "GET",
|
||||
apiVersion: "2023-02-01-preview",
|
||||
});
|
||||
};
|
||||
|
||||
export const putEphemeralUserSettings = async (
|
||||
userSubscriptionId: string,
|
||||
userRegion: string,
|
||||
vNetSettings?: object,
|
||||
) => {
|
||||
const ephemeralSettings: CloudShellSettings = {
|
||||
properties: {
|
||||
preferredOsType: OsType.Linux,
|
||||
preferredShellType: ShellType.Bash,
|
||||
preferredLocation: userRegion,
|
||||
networkType:
|
||||
!vNetSettings || Object.keys(vNetSettings).length === 0
|
||||
? NetworkType.Default
|
||||
: vNetSettings
|
||||
? NetworkType.Isolated
|
||||
: NetworkType.Default,
|
||||
sessionType: SessionType.Ephemeral,
|
||||
userSubscription: userSubscriptionId,
|
||||
vnetSettings: vNetSettings ?? {},
|
||||
},
|
||||
};
|
||||
|
||||
return await armRequest({
|
||||
host: configContext.ARM_ENDPOINT,
|
||||
path: `/providers/Microsoft.Portal/userSettings/cloudconsole`,
|
||||
method: "PUT",
|
||||
apiVersion: "2023-02-01-preview",
|
||||
body: ephemeralSettings,
|
||||
});
|
||||
};
|
||||
|
||||
export const verifyCloudShellProviderRegistration = async (subscriptionId: string): Promise<CloudShellProviderInfo> => {
|
||||
return await armRequest({
|
||||
host: configContext.ARM_ENDPOINT,
|
||||
path: `/subscriptions/${subscriptionId}/providers/Microsoft.CloudShell`,
|
||||
method: "GET",
|
||||
apiVersion: "2022-12-01",
|
||||
});
|
||||
};
|
||||
|
||||
export const registerCloudShellProvider = async (subscriptionId: string) => {
|
||||
return await armRequest({
|
||||
host: configContext.ARM_ENDPOINT,
|
||||
path: `/subscriptions/${subscriptionId}/providers/Microsoft.CloudShell/register`,
|
||||
method: "POST",
|
||||
apiVersion: "2022-12-01",
|
||||
});
|
||||
};
|
||||
|
||||
export const provisionConsole = async (consoleLocation: string): Promise<ProvisionConsoleResponse> => {
|
||||
const data = {
|
||||
properties: {
|
||||
osType: OsType.Linux,
|
||||
},
|
||||
};
|
||||
|
||||
return await armRequest<ProvisionConsoleResponse>({
|
||||
host: configContext.ARM_ENDPOINT,
|
||||
path: `providers/Microsoft.Portal/consoles/default`,
|
||||
method: "PUT",
|
||||
apiVersion: "2023-02-01-preview",
|
||||
customHeaders: {
|
||||
"x-ms-console-preferred-location": consoleLocation,
|
||||
},
|
||||
body: data,
|
||||
});
|
||||
};
|
||||
|
||||
export const connectTerminal = async (
|
||||
consoleUri: string,
|
||||
size: { rows: number; cols: number },
|
||||
): Promise<ConnectTerminalResponse> => {
|
||||
const targetUri = consoleUri + `/terminals?cols=${size.cols}&rows=${size.rows}&version=2019-01-01&shell=bash`;
|
||||
const resp = await fetch(targetUri, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Accept: "application/json",
|
||||
"Content-Type": "application/json",
|
||||
"Content-Length": "2",
|
||||
Authorization: userContext.authorizationToken,
|
||||
"x-ms-client-request-id": uuidv4(),
|
||||
"Accept-Language": getLocale(),
|
||||
},
|
||||
body: "{}", // empty body is necessary
|
||||
});
|
||||
|
||||
if (!resp.ok) {
|
||||
throw new Error(`Failed to connect to terminal: ${resp.status} ${resp.statusText}`);
|
||||
}
|
||||
|
||||
return resp.json();
|
||||
};
|
91
src/Explorer/Tabs/CloudShellTab/Models/DataModels.tsx
Normal file
91
src/Explorer/Tabs/CloudShellTab/Models/DataModels.tsx
Normal file
@ -0,0 +1,91 @@
|
||||
export const enum OsType {
|
||||
Linux = "linux",
|
||||
Windows = "windows",
|
||||
}
|
||||
|
||||
export const enum ShellType {
|
||||
Bash = "bash",
|
||||
PowerShellCore = "pwsh",
|
||||
}
|
||||
|
||||
export const enum NetworkType {
|
||||
Default = "Default",
|
||||
Isolated = "Isolated",
|
||||
}
|
||||
|
||||
/**
|
||||
* Azure CloudShell session types:
|
||||
* - Mounted: Sessions with persistent storage via an Azure File Share mount.
|
||||
* Files and configurations are preserved between sessions, allowing for
|
||||
* continuity of work across multiple CloudShell sessions.
|
||||
*
|
||||
* - Ephemeral: Temporary sessions without persistent storage.
|
||||
* All files and changes are discarded when the session ends.
|
||||
* These sessions start faster but don't retain user data.
|
||||
*
|
||||
* The session type affects resource allocation, startup time,
|
||||
* and whether user files/configurations persist between sessions.
|
||||
*/
|
||||
export const enum SessionType {
|
||||
Mounted = "Mounted",
|
||||
Ephemeral = "Ephemeral",
|
||||
}
|
||||
|
||||
export type CloudShellSettings = {
|
||||
properties: UserSettingProperties;
|
||||
};
|
||||
|
||||
export type UserSettingProperties = {
|
||||
networkType: string;
|
||||
preferredLocation: string;
|
||||
preferredOsType: OsType;
|
||||
preferredShellType: ShellType;
|
||||
userSubscription: string;
|
||||
sessionType: SessionType;
|
||||
vnetSettings: object;
|
||||
};
|
||||
|
||||
export type ProvisionConsoleResponse = {
|
||||
properties: {
|
||||
osType: OsType;
|
||||
provisioningState: string;
|
||||
uri: string;
|
||||
};
|
||||
};
|
||||
|
||||
export type Authorization = {
|
||||
token: string;
|
||||
};
|
||||
|
||||
export type ConnectTerminalResponse = {
|
||||
id: string;
|
||||
idleTimeout: string;
|
||||
rootDirectory: string;
|
||||
socketUri: string;
|
||||
tokenUpdated: boolean;
|
||||
};
|
||||
|
||||
export type ProviderAuthorization = {
|
||||
applicationId: string;
|
||||
roleDefinitionId: string;
|
||||
};
|
||||
|
||||
export type ProviderResourceType = {
|
||||
resourceType: string;
|
||||
locations: string[];
|
||||
apiVersions: string[];
|
||||
defaultApiVersion?: string;
|
||||
capabilities?: string;
|
||||
};
|
||||
|
||||
export type RegistrationState = "Registered" | "NotRegistered" | "Registering" | "Unregistering";
|
||||
export type RegistrationPolicy = "RegistrationRequired" | "RegistrationOptional";
|
||||
|
||||
export type CloudShellProviderInfo = {
|
||||
id: string;
|
||||
namespace: string;
|
||||
authorizations?: ProviderAuthorization[];
|
||||
resourceTypes: ProviderResourceType[];
|
||||
registrationState: RegistrationState;
|
||||
registrationPolicy: RegistrationPolicy;
|
||||
};
|
282
src/Explorer/Tabs/CloudShellTab/README.md
Normal file
282
src/Explorer/Tabs/CloudShellTab/README.md
Normal file
@ -0,0 +1,282 @@
|
||||
# Migrate Mongo(RU/vCore)/Postgres/Cassandra shell to CloudShell Design
|
||||
|
||||
## CloudShell Overview
|
||||
Cloud Shell provides an integrated terminal experience directly within Cosmos Explorer, allowing users to interact with different database engines using their native command-line interfaces.
|
||||
|
||||
## Component Architecture
|
||||
|
||||
```mermaid
|
||||
classDiagram
|
||||
|
||||
class FeatureRegistration {
|
||||
<<Registers a new flag for switching shell to CloudShell>>
|
||||
+enableCloudShell: boolean
|
||||
}
|
||||
|
||||
class ShellTypeHandlerFactory {
|
||||
<<Initialize corresponding handler based on the type of shell>>
|
||||
+getHandler(terminalKind: TerminalKind): ShellTypeHandler
|
||||
+getKey(): string
|
||||
}
|
||||
|
||||
class AbstractShellHandler {
|
||||
<<interface>>
|
||||
+getShellName(): string
|
||||
+getSetUpCommands(): string[]
|
||||
+getConnectionCommand(): string
|
||||
+getEndpoint(): string
|
||||
+getTerminalSuppressedData(): string[]
|
||||
+getInitialCommands(): string
|
||||
}
|
||||
|
||||
class CloudShellTerminalComponent {
|
||||
<<React Component to Render CloudShell>>
|
||||
-terminalKind: TerminalKind
|
||||
-shellHandler: AbstractShellHandler
|
||||
+render(): ReactElement
|
||||
}
|
||||
|
||||
class CloudShellTerminalCore {
|
||||
<<Initialize CloudShell>>
|
||||
+startCloudShellTerminal()
|
||||
}
|
||||
|
||||
class CloudShellClient {
|
||||
<Initialize CloudShell APIs>
|
||||
+getUserSettings(): Promise
|
||||
+putEphemeralUserSettings(): void
|
||||
+verifyCloudShellProviderRegistration: void
|
||||
+registerCloudShellProvider(): void
|
||||
+provisionConsole(): ProvisionConsoleResponse
|
||||
+connectTerminal(): ConnectTerminalResponse
|
||||
+authorizeSession(): Authorization
|
||||
}
|
||||
|
||||
class CloudShellTerminalComponentAdapter {
|
||||
+getDatabaseAccount: DataModels.DatabaseAccount,
|
||||
+getTabId: string,
|
||||
+getUsername: string,
|
||||
+isAllPublicIPAddressesEnabled: ko.Observable<boolean>,
|
||||
+kind: ViewModels.TerminalKind,
|
||||
}
|
||||
|
||||
class TerminalTab {
|
||||
-cloudShellTerminalComponentAdapter: CloudShellTerminalComponentAdapter
|
||||
}
|
||||
|
||||
class ContextMenuButtonFactory {
|
||||
+getCloudShellButton(): ReactElement
|
||||
+isCloudShellEnabled(): boolean
|
||||
}
|
||||
|
||||
UserContext --> FeatureRegistration : contains
|
||||
FeatureRegistration ..> ContextMenuButtonFactory : controls UI visibility
|
||||
FeatureRegistration ..> CloudShellTerminalComponentAdapter : enables tab creation
|
||||
FeatureRegistration ..> CloudShellClient : permits API calls
|
||||
|
||||
TerminalTab --> CloudShellTerminalComponentAdapter : manages
|
||||
ContextMenuButtonFactory --> TerminalTab : creates
|
||||
TerminalTab --> CloudShellTerminalComponent : renders
|
||||
CloudShellTerminalComponent --> CloudShellTerminalCore : contains
|
||||
CloudShellTerminalComponent --> ShellTypeHandlerFactory : uses
|
||||
CloudShellTerminalCore --> CloudShellClient : communicates with
|
||||
CloudShellTerminalCore --> AbstractShellHandler : uses configuration from
|
||||
|
||||
ShellTypeHandlerFactory --> AbstractShellHandler : creates
|
||||
|
||||
class MongoShellHandler {
|
||||
-key: string
|
||||
+getShellName(): string
|
||||
+getSetUpCommands(): string[]
|
||||
+getConnectionCommand(): string
|
||||
+getEndpoint(): string
|
||||
+getTerminalSuppressedData(): string[]
|
||||
+getInitialCommands(): string
|
||||
|
||||
class VCoreMongoShellHandler {
|
||||
+getShellName(): string
|
||||
+getSetUpCommands(): string[]
|
||||
+getConnectionCommand(): string
|
||||
+getEndpoint(): string
|
||||
+getTerminalSuppressedData(): string[]
|
||||
+getInitialCommands(): string
|
||||
}
|
||||
|
||||
class CassandraShellHandler {
|
||||
-key: string
|
||||
+getShellName(): string
|
||||
+getSetUpCommands(): string[]
|
||||
+getConnectionCommand(): string
|
||||
+getEndpoint(): string
|
||||
+getTerminalSuppressedData(): string[]
|
||||
+getInitialCommands(): string
|
||||
}
|
||||
|
||||
class PostgresShellHandler {
|
||||
+getShellName(): string
|
||||
+getSetUpCommands(): string[]
|
||||
+getConnectionCommand(): string
|
||||
+getEndpoint(): string
|
||||
+getTerminalSuppressedData(): string[]
|
||||
+getInitialCommands(): string
|
||||
}
|
||||
|
||||
AbstractShellHandler <|.. MongoShellHandler
|
||||
AbstractShellHandler <|.. VCoreMongoShellHandler
|
||||
AbstractShellHandler <|.. CassandraShellHandler
|
||||
AbstractShellHandler <|.. PostgresShellHandler
|
||||
```
|
||||
|
||||
## Changes
|
||||
|
||||
The CloudShell functionality is controlled by the feature flag `userContext.features.enableCloudShell`. When this flag is **enabled** (set to true), the following occurs in the application:
|
||||
|
||||
1. **UI Components Become Available:** There is "Open Mongo Shell" or similar button appears on data explorer or quick start window.
|
||||
|
||||
2. **Service Capabilities Are Activated:**
|
||||
- Backend API calls to CloudShell services are permitted
|
||||
- Terminal connection endpoints become accessible
|
||||
|
||||
3. **Database-Specific Features Are Unlocked:**
|
||||
- Terminal experiences tailored to each database type become available
|
||||
- Shell handlers are instantiated based on the database type
|
||||
|
||||
4. **Telemetry Collection Begins:**
|
||||
- When CloudShell Starts
|
||||
- User Consent to access shell out of the region
|
||||
- When shell is connected
|
||||
- When there is an error during CloudShell initialization
|
||||
|
||||
The feature can be enabled by putting `feature.enableCloudShell=true` in url.
|
||||
When disabled, all CloudShell functionality is hidden and inaccessible, ensuring a consistent user experience regardless of the feature's state. These shell would be talking to tools federation.
|
||||
|
||||
## Supported Shell Types
|
||||
|
||||
| Terminal Kind | Handler Class | Description |
|
||||
|---------------|--------------|-------------|
|
||||
| Mongo | MongoShellHandler | Handles MongoDB RU shell connections |
|
||||
| VCoreMongo | VCoreMongoShellHandler | Handles for VCore MongoDB shell connections |
|
||||
| Cassandra | CassandraShellHandler | Handles Cassandra shell connections |
|
||||
| Postgres | PostgresShellHandler | Handles PostgreSQL shell connections |
|
||||
|
||||
## Implementation Details
|
||||
|
||||
The CloudShell implementation uses the Factory pattern to create appropriate shell handlers based on the database type. Each handler implements the common interface but provides specialized behavior for connecting to different database engines.
|
||||
|
||||
### Key Components
|
||||
|
||||
1. **ShellTypeHandlerFactory**: Creates the appropriate handler based on terminal kind
|
||||
- Retrieves authentication keys from Azure Resource Manager
|
||||
- Instantiates specialized handlers with configuration
|
||||
|
||||
2. **ShellTypeHandler Interface i.e. AbstractShellHandler**: Defines the contract for all shell handlers
|
||||
- `getConnectionCommand()`: Returns shell command to connect to database
|
||||
- `getSetUpCommands()`: Returns list of scripts required to set up the environment
|
||||
- `getEndpoint()`: Returns database connection end point
|
||||
- `getTerminalSuppressedData()`: Returns a string which needs to be suppressed
|
||||
|
||||
3. **Specialized Handlers**: Implement specific connection logic for each database type
|
||||
- Handle authentication differences
|
||||
- Provide appropriate shell arguments
|
||||
- Format connection strings correctly
|
||||
|
||||
4. **CloudShellTerminalComponent**: React component that renders the terminal interface
|
||||
- Receives the terminal type as a property
|
||||
- Uses ShellTypeHandlerFactory to get the appropriate handler
|
||||
- Renders the CloudShellTerminalCore with the handler's configuration
|
||||
- Manages component lifecycle and state
|
||||
|
||||
5. **CloudShellTerminalCore**: Core terminal implementation
|
||||
- Handles low-level terminal operations
|
||||
- Uses the configuration from ShellTypeHandler to initialize the terminal
|
||||
- Manages input/output streams between the user interface and the shell process
|
||||
- Handles terminal events (resize, data, etc.)
|
||||
- Implements terminal UI and styling
|
||||
|
||||
6. **CloudShellClient**: Client for interacting with CloudShell backend services
|
||||
- Initializes the terminal session with backend services
|
||||
- Manages communication between the terminal UI and the backend shell process
|
||||
- Handles authentication and security for the terminal session
|
||||
|
||||
7. **ContextMenuButtonFactory**: Creates CloudShell UI entry points
|
||||
- Checks if CloudShell is enabled via `userContext.features.enableCloudShell`
|
||||
- Generates appropriate terminal buttons based on database type
|
||||
- Handles conditional rendering of CloudShell options
|
||||
|
||||
8. **TerminalTab**: Container component for terminal experiences
|
||||
- Renders appropriate terminal type based on the selected database
|
||||
- Manages terminal tab state and lifecycle
|
||||
- Provides the integration point between the terminal and the rest of the Cosmos Explorer UI
|
||||
|
||||
## Telemetry Collection
|
||||
|
||||
CloudShell components utilize `TelemetryProcessor.trace` to collect usage data and diagnostics information that help improve the service and troubleshoot issues.
|
||||
|
||||
### Telemetry Events
|
||||
- When CloudShell Starts
|
||||
- User Consent to access shell out of the region
|
||||
- When shell is connected
|
||||
- When there is an error during CloudShell initialization
|
||||
|
||||
| Action Name | Description | Collected Data |
|
||||
|------------|------------|----------------|
|
||||
| CloudShellTerminalSession/Start | Triggered when user starts a CloudShell session | Shell Type, dataExplorerArea as <i>CloudShell</i>|
|
||||
| CloudShellUserConsent/(Success/Failure) | Records user consent to get cloudshell in other region | |
|
||||
| CloudShellTerminalSession/Success | Records if Terminal creation is successful | Shell Type, Shell Region |
|
||||
| CloudShellTerminalSession/Failure | Records of terminal creation is failed | Shell Type, Shell region (if available), error message |
|
||||
|
||||
### Real-time Use Cases
|
||||
|
||||
1. **Performance Monitoring**:
|
||||
- Track shell initialization times across different regions and database types
|
||||
|
||||
2. **Error Detection and Resolution**:
|
||||
- Detect increased error rates in real-time
|
||||
- Identify patterns in failures
|
||||
- Correlate errors with specific client configurations
|
||||
|
||||
3. **Feature Adoption Analysis**:
|
||||
- Measure adoption rates of different terminal types
|
||||
|
||||
4. **User Experience Optimization**:
|
||||
- Analyze session duration to understand engagement
|
||||
- Identify abandoned sessions and potential pain points
|
||||
- Measure the impact of new features on usage patterns
|
||||
- Track command completion rates and error recovery
|
||||
|
||||
## Limitations and Regional Availability
|
||||
|
||||
### Network Isolation
|
||||
|
||||
Network isolation (such as private endpoints, service endpoints, and VNet integration) is not currently supported for CloudShell connections. All connections to database instances through CloudShell require the database to be accessible through public endpoints.
|
||||
|
||||
Key limitations:
|
||||
- Cannot connect to databases with public network access disabled
|
||||
- No support for private link resources
|
||||
- No integration with Azure Virtual Networks
|
||||
- IP-based firewall rules must include CloudShell service IPs
|
||||
|
||||
### Data Residency
|
||||
|
||||
Data residency requirements may not be fully satisfied when using CloudShell due to limited regional availability. CloudShell services are currently available in the following regions:
|
||||
|
||||
| Geography | Regions |
|
||||
|-----------|---------|
|
||||
| Americas | East US, West US 2, South Central US, West Central US |
|
||||
| Europe | West Europe, North Europe |
|
||||
| Asia Pacific | Southeast Asia, Japan East, Australia East |
|
||||
| Middle East | UAE North |
|
||||
|
||||
**Note:** For up-to-date supported regions, refer to the region configuration in:
|
||||
`src/Explorer/CloudShell/Configuration/RegionConfig.ts`
|
||||
|
||||
### Implications for Compliance
|
||||
|
||||
Organizations with strict data residency or network isolation requirements should be aware of these limitations:
|
||||
|
||||
1. Data may transit through regions different from the database region
|
||||
2. Terminal session data is processed in CloudShell regions, not necessarily the database region
|
||||
3. Commands and queries are executed through CloudShell services, not directly against the database
|
||||
4. Connection strings contain database endpoints and are processed by CloudShell services
|
||||
|
||||
These limitations are important considerations for workloads with specific compliance or regulatory requirements.
|
@ -0,0 +1,96 @@
|
||||
import { AbstractShellHandler, DISABLE_HISTORY, START_MARKER, EXIT_COMMAND } from "./AbstractShellHandler";
|
||||
|
||||
// Mock implementation for testing
|
||||
class MockShellHandler extends AbstractShellHandler {
|
||||
getShellName(): string {
|
||||
return "MockShell";
|
||||
}
|
||||
|
||||
getSetUpCommands(): string[] {
|
||||
return ["setup-command-1", "setup-command-2"];
|
||||
}
|
||||
|
||||
getConnectionCommand(): string {
|
||||
return "mock-connection-command";
|
||||
}
|
||||
|
||||
getEndpoint(): string {
|
||||
return "mock-endpoint";
|
||||
}
|
||||
|
||||
getTerminalSuppressedData(): string {
|
||||
return "suppressed-data";
|
||||
}
|
||||
}
|
||||
|
||||
describe("AbstractShellHandler", () => {
|
||||
let shellHandler: MockShellHandler;
|
||||
|
||||
// Reset all mocks and spies before each test
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
shellHandler = new MockShellHandler();
|
||||
});
|
||||
|
||||
// Reset everything after all tests
|
||||
afterAll(() => {
|
||||
jest.resetAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
jest.resetModules();
|
||||
});
|
||||
|
||||
// Cleanup after each test
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe("getInitialCommands", () => {
|
||||
it("should combine commands in the correct order", () => {
|
||||
// Spy on abstract methods to ensure they're called
|
||||
const getSetUpCommandsSpy = jest.spyOn(shellHandler, "getSetUpCommands");
|
||||
const getConnectionCommandSpy = jest.spyOn(shellHandler, "getConnectionCommand");
|
||||
|
||||
const result = shellHandler.getInitialCommands();
|
||||
|
||||
// Verify abstract methods were called
|
||||
expect(getSetUpCommandsSpy).toHaveBeenCalled();
|
||||
expect(getConnectionCommandSpy).toHaveBeenCalled();
|
||||
|
||||
// Verify output format and content
|
||||
const expectedOutput = [
|
||||
START_MARKER,
|
||||
DISABLE_HISTORY,
|
||||
"setup-command-1",
|
||||
"setup-command-2",
|
||||
`{ mock-connection-command; } || true;${EXIT_COMMAND}`,
|
||||
]
|
||||
.join("\n")
|
||||
.concat("\n");
|
||||
|
||||
expect(result).toBe(expectedOutput);
|
||||
});
|
||||
});
|
||||
|
||||
describe("abstract methods implementation", () => {
|
||||
it("should return the correct shell name", () => {
|
||||
expect(shellHandler.getShellName()).toBe("MockShell");
|
||||
});
|
||||
|
||||
it("should return the setup commands", () => {
|
||||
expect(shellHandler.getSetUpCommands()).toEqual(["setup-command-1", "setup-command-2"]);
|
||||
});
|
||||
|
||||
it("should return the connection command", () => {
|
||||
expect(shellHandler.getConnectionCommand()).toBe("mock-connection-command");
|
||||
});
|
||||
|
||||
it("should return the endpoint", () => {
|
||||
expect(shellHandler.getEndpoint()).toBe("mock-endpoint");
|
||||
});
|
||||
|
||||
it("should return the terminal suppressed data", () => {
|
||||
expect(shellHandler.getTerminalSuppressedData()).toBe("suppressed-data");
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Command that serves as a marker to indicate the start of shell initialization.
|
||||
* Outputs to /dev/null to prevent displaying in the terminal.
|
||||
*/
|
||||
export const START_MARKER = `echo "START INITIALIZATION" > /dev/null`;
|
||||
|
||||
/**
|
||||
* Command to disable command history recording in the shell.
|
||||
* Prevents initialization commands from appearing in history.
|
||||
*/
|
||||
export const DISABLE_HISTORY = `set +o history`;
|
||||
/**
|
||||
* Command that displays an error message and exits the shell session.
|
||||
* Used when shell initialization or connection fails.
|
||||
*/
|
||||
export const EXIT_COMMAND = ` printf "\\033[1;31mSession ended. Please close this tab and initiate a new shell session if needed.\\033[0m\\n" && exit`;
|
||||
|
||||
/**
|
||||
* Abstract class that defines the interface for shell-specific handlers
|
||||
* in the CloudShell terminal implementation. Each supported shell type
|
||||
* (Mongo, PG, etc.) should extend this class and implement
|
||||
* the required methods.
|
||||
*/
|
||||
export abstract class AbstractShellHandler {
|
||||
abstract getShellName(): string;
|
||||
abstract getSetUpCommands(): string[];
|
||||
abstract getConnectionCommand(): string;
|
||||
abstract getTerminalSuppressedData(): string;
|
||||
|
||||
/**
|
||||
* Constructs the complete initialization command sequence for the shell.
|
||||
*
|
||||
* This method:
|
||||
* 1. Starts with the initialization marker
|
||||
* 2. Disables command history
|
||||
* 3. Adds shell-specific setup commands
|
||||
* 4. Adds the connection command with error handling
|
||||
* 5. Adds a fallback exit command if connection fails
|
||||
*
|
||||
* The connection command is wrapped in a construct that prevents
|
||||
* errors from terminating the entire session immediately, allowing
|
||||
* the friendly exit message to be displayed.
|
||||
*
|
||||
* @returns {string} Complete initialization command sequence with newlines
|
||||
*/
|
||||
public getInitialCommands(): string {
|
||||
const setupCommands = this.getSetUpCommands();
|
||||
const connectionCommand = this.getConnectionCommand();
|
||||
|
||||
const allCommands = [
|
||||
START_MARKER,
|
||||
DISABLE_HISTORY,
|
||||
...setupCommands,
|
||||
`{ ${connectionCommand}; } || true;${EXIT_COMMAND}`,
|
||||
];
|
||||
|
||||
return allCommands.join("\n").concat("\n");
|
||||
}
|
||||
}
|
@ -0,0 +1,148 @@
|
||||
import * as CommonUtils from "../Utils/CommonUtils";
|
||||
import { CassandraShellHandler } from "./CassandraShellHandler";
|
||||
|
||||
// Define interfaces for the database account structure
|
||||
interface DatabaseAccountProperties {
|
||||
cassandraEndpoint?: string;
|
||||
}
|
||||
|
||||
interface DatabaseAccount {
|
||||
name?: string;
|
||||
properties?: DatabaseAccountProperties;
|
||||
}
|
||||
|
||||
// Define mock state that can be modified by tests
|
||||
const mockState = {
|
||||
databaseAccount: {
|
||||
name: "test-account",
|
||||
properties: {
|
||||
cassandraEndpoint: "https://test-endpoint.cassandra.cosmos.azure.com:443/",
|
||||
},
|
||||
} as DatabaseAccount,
|
||||
};
|
||||
|
||||
// Mock dependencies using factory functions
|
||||
jest.mock("../../../../UserContext", () => ({
|
||||
get userContext() {
|
||||
return {
|
||||
get databaseAccount() {
|
||||
return mockState.databaseAccount;
|
||||
},
|
||||
};
|
||||
},
|
||||
}));
|
||||
|
||||
// Reset all modules before running tests
|
||||
beforeAll(() => {
|
||||
jest.resetModules();
|
||||
});
|
||||
|
||||
jest.mock("../Utils/CommonUtils", () => ({
|
||||
getHostFromUrl: jest.fn().mockReturnValue("test-endpoint.cassandra.cosmos.azure.com"),
|
||||
}));
|
||||
|
||||
describe("CassandraShellHandler", () => {
|
||||
const testKey = "test-key";
|
||||
let handler: CassandraShellHandler;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
handler = new CassandraShellHandler(testKey);
|
||||
|
||||
// Reset mock state before each test
|
||||
mockState.databaseAccount = {
|
||||
name: "test-account",
|
||||
properties: {
|
||||
cassandraEndpoint: "https://test-endpoint.cassandra.cosmos.azure.com:443/",
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
// Clean up after all tests
|
||||
afterAll(() => {
|
||||
jest.resetAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
jest.resetModules();
|
||||
});
|
||||
|
||||
describe("Positive test cases", () => {
|
||||
test("should return 'Cassandra' as shell name", () => {
|
||||
expect(handler.getShellName()).toBe("Cassandra");
|
||||
});
|
||||
|
||||
test("should return an array of setup commands", () => {
|
||||
const commands = handler.getSetUpCommands();
|
||||
|
||||
expect(Array.isArray(commands)).toBe(true);
|
||||
expect(commands.length).toBe(5);
|
||||
expect(commands).toContain("source ~/.bashrc");
|
||||
expect(
|
||||
commands.some((cmd) =>
|
||||
cmd.includes("if ! command -v cqlsh &> /dev/null; then echo '⚠️ cqlsh not found. Installing...'; fi"),
|
||||
),
|
||||
).toBe(true);
|
||||
expect(commands.some((cmd) => cmd.includes("pip3 install --user cqlsh==6.2.0"))).toBe(true);
|
||||
expect(commands.some((cmd) => cmd.includes("export SSL_VERSION=TLSv1_2"))).toBe(true);
|
||||
expect(commands.some((cmd) => cmd.includes("export SSL_VALIDATE=false"))).toBe(true);
|
||||
});
|
||||
|
||||
test("should return correct connection command", () => {
|
||||
const expectedCommand = "cqlsh test-endpoint.cassandra.cosmos.azure.com 10350 -u test-account -p test-key --ssl";
|
||||
|
||||
expect(handler.getConnectionCommand()).toBe(expectedCommand);
|
||||
expect(CommonUtils.getHostFromUrl).toHaveBeenCalledWith("https://test-endpoint.cassandra.cosmos.azure.com:443/");
|
||||
});
|
||||
|
||||
test("should return the correct terminal suppressed data", () => {
|
||||
expect(handler.getTerminalSuppressedData()).toBe("");
|
||||
});
|
||||
|
||||
test("should include the correct package version in setup commands", () => {
|
||||
const commands = handler.getSetUpCommands();
|
||||
const hasCorrectPackageVersion = commands.some((cmd) => cmd.includes("cqlsh==6.2.0"));
|
||||
|
||||
expect(hasCorrectPackageVersion).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Negative test cases", () => {
|
||||
test("should handle empty host from URL", () => {
|
||||
(CommonUtils.getHostFromUrl as jest.Mock).mockReturnValueOnce("");
|
||||
|
||||
const command = handler.getConnectionCommand();
|
||||
|
||||
expect(command).toBe("cqlsh 10350 -u test-account -p test-key --ssl");
|
||||
});
|
||||
|
||||
test("should handle empty key", () => {
|
||||
const emptyKeyHandler = new CassandraShellHandler("");
|
||||
|
||||
expect(emptyKeyHandler.getConnectionCommand()).toBe(
|
||||
"cqlsh test-endpoint.cassandra.cosmos.azure.com 10350 -u test-account -p --ssl",
|
||||
);
|
||||
});
|
||||
|
||||
test("should handle undefined account name", () => {
|
||||
mockState.databaseAccount = {
|
||||
properties: { cassandraEndpoint: "https://test-endpoint.cassandra.cosmos.azure.com:443/" },
|
||||
};
|
||||
|
||||
expect(handler.getConnectionCommand()).toBe("echo 'Database name not found.'");
|
||||
});
|
||||
|
||||
test("should handle undefined database account", () => {
|
||||
mockState.databaseAccount = undefined;
|
||||
|
||||
expect(handler.getConnectionCommand()).toBe("echo 'Database name not found.'");
|
||||
});
|
||||
|
||||
test("should handle missing cassandra endpoint", () => {
|
||||
mockState.databaseAccount = {
|
||||
name: "test-account",
|
||||
properties: {},
|
||||
};
|
||||
|
||||
expect(handler.getConnectionCommand()).toBe("echo 'Cassandra endpoint not found.'");
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,47 @@
|
||||
import { userContext } from "../../../../UserContext";
|
||||
import { getHostFromUrl } from "../Utils/CommonUtils";
|
||||
import { AbstractShellHandler } from "./AbstractShellHandler";
|
||||
|
||||
const PACKAGE_VERSION: string = "6.2.0";
|
||||
|
||||
export class CassandraShellHandler extends AbstractShellHandler {
|
||||
private _key: string;
|
||||
private _endpoint: string | undefined;
|
||||
|
||||
constructor(private key: string) {
|
||||
super();
|
||||
this._key = key;
|
||||
this._endpoint = userContext?.databaseAccount?.properties?.cassandraEndpoint;
|
||||
}
|
||||
|
||||
public getShellName(): string {
|
||||
return "Cassandra";
|
||||
}
|
||||
|
||||
public getSetUpCommands(): string[] {
|
||||
return [
|
||||
"if ! command -v cqlsh &> /dev/null; then echo '⚠️ cqlsh not found. Installing...'; fi",
|
||||
`if ! command -v cqlsh &> /dev/null; then pip3 install --user cqlsh==${PACKAGE_VERSION} ; fi`,
|
||||
"echo 'export SSL_VERSION=TLSv1_2' >> ~/.bashrc",
|
||||
"echo 'export SSL_VALIDATE=false' >> ~/.bashrc",
|
||||
"source ~/.bashrc",
|
||||
];
|
||||
}
|
||||
|
||||
public getConnectionCommand(): string {
|
||||
if (!this._endpoint) {
|
||||
return `echo '${this.getShellName()} endpoint not found.'`;
|
||||
}
|
||||
|
||||
const dbName = userContext?.databaseAccount?.name;
|
||||
if (!dbName) {
|
||||
return "echo 'Database name not found.'";
|
||||
}
|
||||
|
||||
return `cqlsh ${getHostFromUrl(this._endpoint)} 10350 -u ${dbName} -p ${this._key} --ssl`;
|
||||
}
|
||||
|
||||
public getTerminalSuppressedData(): string {
|
||||
return "";
|
||||
}
|
||||
}
|
@ -0,0 +1,130 @@
|
||||
import { userContext } from "../../../../UserContext";
|
||||
import * as CommonUtils from "../Utils/CommonUtils";
|
||||
import { MongoShellHandler } from "./MongoShellHandler";
|
||||
|
||||
// Define interfaces for type safety
|
||||
interface DatabaseAccountProperties {
|
||||
mongoEndpoint?: string;
|
||||
}
|
||||
|
||||
interface DatabaseAccount {
|
||||
id?: string;
|
||||
name: string;
|
||||
location?: string;
|
||||
type?: string;
|
||||
kind?: string;
|
||||
properties: DatabaseAccountProperties;
|
||||
}
|
||||
|
||||
interface UserContextType {
|
||||
databaseAccount: DatabaseAccount;
|
||||
}
|
||||
|
||||
// Mock dependencies
|
||||
jest.mock("../../../../UserContext", () => ({
|
||||
userContext: {
|
||||
databaseAccount: {
|
||||
name: "test-account",
|
||||
properties: {
|
||||
mongoEndpoint: "https://test-mongo.documents.azure.com:443/",
|
||||
},
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock("../Utils/CommonUtils", () => ({
|
||||
getHostFromUrl: jest.fn().mockReturnValue("test-mongo.documents.azure.com"),
|
||||
}));
|
||||
|
||||
describe("MongoShellHandler", () => {
|
||||
const testKey = "test-key";
|
||||
let mongoShellHandler: MongoShellHandler;
|
||||
|
||||
beforeEach(() => {
|
||||
mongoShellHandler = new MongoShellHandler(testKey);
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
// Clean up after each test
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
// Clean up after all tests
|
||||
afterAll(() => {
|
||||
jest.resetAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
jest.resetModules();
|
||||
});
|
||||
|
||||
describe("getShellName", () => {
|
||||
it("should return MongoDB", () => {
|
||||
expect(mongoShellHandler.getShellName()).toBe("MongoDB");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getSetUpCommands", () => {
|
||||
it("should return an array of setup commands", () => {
|
||||
const commands = mongoShellHandler.getSetUpCommands();
|
||||
|
||||
expect(Array.isArray(commands)).toBe(true);
|
||||
expect(commands.length).toBe(6);
|
||||
expect(commands[1]).toContain("mongosh-2.5.0-linux-x64.tgz");
|
||||
});
|
||||
});
|
||||
|
||||
describe("getConnectionCommand", () => {
|
||||
it("should return the correct connection command", () => {
|
||||
// Save original databaseAccount
|
||||
const originalDatabaseAccount = userContext.databaseAccount;
|
||||
|
||||
// Directly assign the modified databaseAccount
|
||||
(userContext as UserContextType).databaseAccount = {
|
||||
id: "test-id",
|
||||
name: "test-account",
|
||||
location: "test-location",
|
||||
type: "test-type",
|
||||
kind: "test-kind",
|
||||
properties: { mongoEndpoint: "https://test-mongo.documents.azure.com:443/" },
|
||||
};
|
||||
|
||||
const command = mongoShellHandler.getConnectionCommand();
|
||||
|
||||
expect(command).toBe(
|
||||
"mongosh --host test-mongo.documents.azure.com --port 10255 --username test-account --password test-key --tls --tlsAllowInvalidCertificates",
|
||||
);
|
||||
expect(CommonUtils.getHostFromUrl).toHaveBeenCalledWith("https://test-mongo.documents.azure.com:443/");
|
||||
|
||||
// Restore original
|
||||
(userContext as UserContextType).databaseAccount = originalDatabaseAccount;
|
||||
});
|
||||
|
||||
it("should handle missing database account name", () => {
|
||||
// Save original databaseAccount
|
||||
const originalDatabaseAccount = userContext.databaseAccount;
|
||||
|
||||
// Directly assign the modified databaseAccount
|
||||
(userContext as UserContextType).databaseAccount = {
|
||||
id: "test-id",
|
||||
name: "", // Empty name to simulate missing name
|
||||
location: "test-location",
|
||||
type: "test-type",
|
||||
kind: "test-kind",
|
||||
properties: { mongoEndpoint: "https://test.com" },
|
||||
};
|
||||
|
||||
const command = mongoShellHandler.getConnectionCommand();
|
||||
|
||||
expect(command).toBe("echo 'Database name not found.'");
|
||||
|
||||
// Restore original
|
||||
(userContext as UserContextType).databaseAccount = originalDatabaseAccount;
|
||||
});
|
||||
});
|
||||
|
||||
describe("getTerminalSuppressedData", () => {
|
||||
it("should return the correct warning message", () => {
|
||||
expect(mongoShellHandler.getTerminalSuppressedData()).toBe("Warning: Non-Genuine MongoDB Detected");
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,48 @@
|
||||
import { userContext } from "../../../../UserContext";
|
||||
import { getHostFromUrl } from "../Utils/CommonUtils";
|
||||
import { AbstractShellHandler } from "./AbstractShellHandler";
|
||||
|
||||
const PACKAGE_VERSION: string = "2.5.0";
|
||||
|
||||
export class MongoShellHandler extends AbstractShellHandler {
|
||||
private _key: string;
|
||||
private _endpoint: string | undefined;
|
||||
constructor(private key: string) {
|
||||
super();
|
||||
this._key = key;
|
||||
this._endpoint = userContext?.databaseAccount?.properties?.mongoEndpoint;
|
||||
}
|
||||
|
||||
public getShellName(): string {
|
||||
return "MongoDB";
|
||||
}
|
||||
|
||||
public getSetUpCommands(): string[] {
|
||||
return [
|
||||
"if ! command -v mongosh &> /dev/null; then echo '⚠️ mongosh not found. Installing...'; fi",
|
||||
`if ! command -v mongosh &> /dev/null; then curl -LO https://downloads.mongodb.com/compass/mongosh-${PACKAGE_VERSION}-linux-x64.tgz; fi`,
|
||||
`if ! command -v mongosh &> /dev/null; then tar -xvzf mongosh-${PACKAGE_VERSION}-linux-x64.tgz; fi`,
|
||||
`if ! command -v mongosh &> /dev/null; then mkdir -p ~/mongosh && mv mongosh-${PACKAGE_VERSION}-linux-x64/* ~/mongosh/; fi`,
|
||||
"if ! command -v mongosh &> /dev/null; then echo 'export PATH=$HOME/mongosh/bin:$PATH' >> ~/.bashrc; fi",
|
||||
"source ~/.bashrc",
|
||||
];
|
||||
}
|
||||
|
||||
public getConnectionCommand(): string {
|
||||
if (!this._endpoint) {
|
||||
return `echo '${this.getShellName()} endpoint not found.'`;
|
||||
}
|
||||
|
||||
const dbName = userContext?.databaseAccount?.name;
|
||||
if (!dbName) {
|
||||
return "echo 'Database name not found.'";
|
||||
}
|
||||
return `mongosh --host ${getHostFromUrl(this._endpoint)} --port 10255 --username ${dbName} --password ${
|
||||
this._key
|
||||
} --tls --tlsAllowInvalidCertificates`;
|
||||
}
|
||||
|
||||
public getTerminalSuppressedData(): string {
|
||||
return "Warning: Non-Genuine MongoDB Detected";
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
import { PostgresShellHandler } from "./PostgresShellHandler";
|
||||
|
||||
// Mock dependencies
|
||||
jest.mock("../../../../UserContext", () => ({
|
||||
userContext: {
|
||||
databaseAccount: {
|
||||
properties: {
|
||||
postgresqlEndpoint: "test-postgres.postgres.database.azure.com",
|
||||
},
|
||||
},
|
||||
postgresConnectionStrParams: {
|
||||
adminLogin: "test-admin",
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
describe("PostgresShellHandler", () => {
|
||||
let postgresShellHandler: PostgresShellHandler;
|
||||
|
||||
beforeEach(() => {
|
||||
postgresShellHandler = new PostgresShellHandler();
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
// Clean up after each test
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
// Clean up after all tests
|
||||
afterAll(() => {
|
||||
jest.resetAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
jest.resetModules();
|
||||
});
|
||||
|
||||
// Positive test cases
|
||||
describe("Positive Tests", () => {
|
||||
it("should return correct shell name", () => {
|
||||
expect(postgresShellHandler.getShellName()).toBe("PostgreSQL");
|
||||
});
|
||||
|
||||
it("should return array of setup commands with correct package version", () => {
|
||||
const commands = postgresShellHandler.getSetUpCommands();
|
||||
|
||||
expect(Array.isArray(commands)).toBe(true);
|
||||
expect(commands.length).toBe(9);
|
||||
expect(commands[1]).toContain("postgresql-15.2.tar.bz2");
|
||||
expect(commands[0]).toContain("psql not found");
|
||||
});
|
||||
|
||||
it("should generate proper connection command with endpoint", () => {
|
||||
const connectionCommand = postgresShellHandler.getConnectionCommand();
|
||||
|
||||
expect(connectionCommand).toContain('-h "test-postgres.postgres.database.azure.com"');
|
||||
expect(connectionCommand).toContain("-p 5432");
|
||||
expect(connectionCommand).toContain("--set=sslmode=require");
|
||||
});
|
||||
|
||||
it("should return empty string for terminal suppressed data", () => {
|
||||
expect(postgresShellHandler.getTerminalSuppressedData()).toBe("");
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,63 @@
|
||||
import { userContext } from "../../../../UserContext";
|
||||
import { AbstractShellHandler } from "./AbstractShellHandler";
|
||||
|
||||
const PACKAGE_VERSION: string = "15.2";
|
||||
|
||||
export class PostgresShellHandler extends AbstractShellHandler {
|
||||
private _endpoint: string | undefined;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._endpoint = userContext?.databaseAccount?.properties?.postgresqlEndpoint;
|
||||
}
|
||||
|
||||
public getShellName(): string {
|
||||
return "PostgreSQL";
|
||||
}
|
||||
|
||||
/**
|
||||
* PostgreSQL setup commands for CloudShell:
|
||||
*
|
||||
* 1. Check if psql client is already installed
|
||||
* 2. Download PostgreSQL source package if needed
|
||||
* 3. Extract the PostgreSQL package
|
||||
* 4. Create installation directory
|
||||
* 5. Download and extract readline dependency
|
||||
* 6. Configure readline with appropriate installation path
|
||||
* 7. Add PostgreSQL binaries to system PATH
|
||||
* 8. Apply PATH changes
|
||||
*
|
||||
* All installation steps run conditionally only if
|
||||
* psql is not already available in the environment.
|
||||
*/
|
||||
public getSetUpCommands(): string[] {
|
||||
return [
|
||||
"if ! command -v psql &> /dev/null; then echo '⚠️ psql not found. Installing...'; fi",
|
||||
`if ! command -v psql &> /dev/null; then curl -LO https://ftp.postgresql.org/pub/source/v${PACKAGE_VERSION}/postgresql-${PACKAGE_VERSION}.tar.bz2; fi`,
|
||||
`if ! command -v psql &> /dev/null; then tar -xvjf postgresql-${PACKAGE_VERSION}.tar.bz2; fi`,
|
||||
"if ! command -v psql &> /dev/null; then mkdir -p ~/pgsql; fi",
|
||||
"if ! command -v psql &> /dev/null; then curl -LO https://ftp.gnu.org/gnu/readline/readline-8.1.tar.gz; fi",
|
||||
"if ! command -v psql &> /dev/null; then tar -xvzf readline-8.1.tar.gz; fi",
|
||||
"if ! command -v psql &> /dev/null; then cd readline-8.1 && ./configure --prefix=$HOME/pgsql; fi",
|
||||
"if ! command -v psql &> /dev/null; then echo 'export PATH=$HOME/pgsql/bin:$PATH' >> ~/.bashrc; fi",
|
||||
"source ~/.bashrc",
|
||||
];
|
||||
}
|
||||
|
||||
public getConnectionCommand(): string {
|
||||
if (!this._endpoint) {
|
||||
return `echo '${this.getShellName()} endpoint not found.'`;
|
||||
}
|
||||
|
||||
// Database name is hardcoded as "citus" because Azure Cosmos DB for PostgreSQL
|
||||
// uses Citus as its distributed database extension with this default database name.
|
||||
// All Azure Cosmos DB PostgreSQL deployments follow this convention.
|
||||
// Ref. https://learn.microsoft.com/en-us/azure/cosmos-db/postgresql/reference-limits#database-creation
|
||||
const loginName = userContext.postgresConnectionStrParams.adminLogin;
|
||||
return `psql -h "${this._endpoint}" -p 5432 -d "citus" -U "${loginName}" --set=sslmode=require`;
|
||||
}
|
||||
|
||||
public getTerminalSuppressedData(): string {
|
||||
return "";
|
||||
}
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
import { TerminalKind } from "../../../../Contracts/ViewModels";
|
||||
import { userContext } from "../../../../UserContext";
|
||||
import { listKeys } from "../../../../Utils/arm/generatedClients/cosmos/databaseAccounts";
|
||||
import { CassandraShellHandler } from "./CassandraShellHandler";
|
||||
import { MongoShellHandler } from "./MongoShellHandler";
|
||||
import { PostgresShellHandler } from "./PostgresShellHandler";
|
||||
import { getHandler, getKey } from "./ShellTypeFactory";
|
||||
import { VCoreMongoShellHandler } from "./VCoreMongoShellHandler";
|
||||
|
||||
// Mock dependencies
|
||||
jest.mock("../../../../UserContext", () => ({
|
||||
userContext: {
|
||||
databaseAccount: { name: "testDbName" },
|
||||
subscriptionId: "testSubId",
|
||||
resourceGroup: "testResourceGroup",
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock("../../../../Utils/arm/generatedClients/cosmos/databaseAccounts", () => ({
|
||||
listKeys: jest.fn(),
|
||||
}));
|
||||
|
||||
describe("ShellTypeHandlerFactory", () => {
|
||||
const mockKey = "testKey";
|
||||
|
||||
beforeEach(() => {
|
||||
(listKeys as jest.Mock).mockResolvedValue({ primaryMasterKey: mockKey });
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
// Clean up after each test
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
// Clean up after all tests
|
||||
afterAll(() => {
|
||||
jest.resetAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
jest.resetModules();
|
||||
});
|
||||
|
||||
// Negative test cases
|
||||
describe("Negative test cases", () => {
|
||||
it("should throw an error for unsupported terminal kind", async () => {
|
||||
await expect(getHandler("UnsupportedKind" as unknown as TerminalKind)).rejects.toThrow(
|
||||
"Unsupported shell type: UnsupportedKind",
|
||||
);
|
||||
});
|
||||
|
||||
it("should return empty string when database name is missing", async () => {
|
||||
// Temporarily modify the mock
|
||||
const originalName = userContext.databaseAccount.name;
|
||||
type DatabaseAccountType = { name: string };
|
||||
(userContext.databaseAccount as DatabaseAccountType).name = "";
|
||||
|
||||
const key = await getKey();
|
||||
expect(key).toBe("");
|
||||
expect(listKeys).not.toHaveBeenCalled();
|
||||
|
||||
// Restore the mock
|
||||
(userContext.databaseAccount as DatabaseAccountType).name = originalName;
|
||||
});
|
||||
|
||||
it("should return empty string when listKeys returns null", async () => {
|
||||
(listKeys as jest.Mock).mockResolvedValue(null);
|
||||
|
||||
const key = await getKey();
|
||||
expect(key).toBe("");
|
||||
});
|
||||
|
||||
it("should return empty string when primaryMasterKey is missing", async () => {
|
||||
(listKeys as jest.Mock).mockResolvedValue({
|
||||
/* no primaryMasterKey */
|
||||
});
|
||||
|
||||
const key = await getKey();
|
||||
expect(key).toBe("");
|
||||
});
|
||||
});
|
||||
|
||||
// Positive test cases
|
||||
describe("Positive test cases", () => {
|
||||
it("should return PostgresShellHandler for Postgres terminal kind", async () => {
|
||||
const handler = await getHandler(TerminalKind.Postgres);
|
||||
expect(handler).toBeInstanceOf(PostgresShellHandler);
|
||||
});
|
||||
|
||||
it("should return MongoShellHandler with key for Mongo terminal kind", async () => {
|
||||
const handler = await getHandler(TerminalKind.Mongo);
|
||||
expect(handler).toBeInstanceOf(MongoShellHandler);
|
||||
});
|
||||
|
||||
it("should return VCoreMongoShellHandler for VCoreMongo terminal kind", async () => {
|
||||
const handler = await getHandler(TerminalKind.VCoreMongo);
|
||||
expect(handler).toBeInstanceOf(VCoreMongoShellHandler);
|
||||
});
|
||||
|
||||
it("should return CassandraShellHandler with key for Cassandra terminal kind", async () => {
|
||||
const handler = await getHandler(TerminalKind.Cassandra);
|
||||
expect(handler).toBeInstanceOf(CassandraShellHandler);
|
||||
});
|
||||
|
||||
it("should get key successfully when database name exists", async () => {
|
||||
const key = await getKey();
|
||||
expect(key).toBe(mockKey);
|
||||
expect(listKeys).toHaveBeenCalledWith("testSubId", "testResourceGroup", "testDbName");
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,36 @@
|
||||
import { TerminalKind } from "../../../../Contracts/ViewModels";
|
||||
import { userContext } from "../../../../UserContext";
|
||||
import { listKeys } from "../../../../Utils/arm/generatedClients/cosmos/databaseAccounts";
|
||||
import { AbstractShellHandler } from "./AbstractShellHandler";
|
||||
import { CassandraShellHandler } from "./CassandraShellHandler";
|
||||
import { MongoShellHandler } from "./MongoShellHandler";
|
||||
import { PostgresShellHandler } from "./PostgresShellHandler";
|
||||
import { VCoreMongoShellHandler } from "./VCoreMongoShellHandler";
|
||||
|
||||
/**
|
||||
* Gets the appropriate handler for the given shell type
|
||||
*/
|
||||
export async function getHandler(shellType: TerminalKind): Promise<AbstractShellHandler> {
|
||||
switch (shellType) {
|
||||
case TerminalKind.Postgres:
|
||||
return new PostgresShellHandler();
|
||||
case TerminalKind.Mongo:
|
||||
return new MongoShellHandler(await getKey());
|
||||
case TerminalKind.VCoreMongo:
|
||||
return new VCoreMongoShellHandler();
|
||||
case TerminalKind.Cassandra:
|
||||
return new CassandraShellHandler(await getKey());
|
||||
default:
|
||||
throw new Error(`Unsupported shell type: ${shellType}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getKey(): Promise<string> {
|
||||
const dbName = userContext.databaseAccount.name;
|
||||
if (!dbName) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const keys = await listKeys(userContext.subscriptionId, userContext.resourceGroup, dbName);
|
||||
return keys?.primaryMasterKey || "";
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
import { VCoreMongoShellHandler } from "./VCoreMongoShellHandler";
|
||||
|
||||
// Mock dependencies
|
||||
jest.mock("../../../../UserContext", () => ({
|
||||
userContext: {
|
||||
databaseAccount: {
|
||||
properties: {
|
||||
vcoreMongoEndpoint: "test-vcore-mongo.mongo.cosmos.azure.com",
|
||||
},
|
||||
},
|
||||
vcoreMongoConnectionParams: {
|
||||
adminLogin: "username",
|
||||
},
|
||||
},
|
||||
}));
|
||||
|
||||
describe("VCoreMongoShellHandler", () => {
|
||||
let vcoreMongoShellHandler: VCoreMongoShellHandler;
|
||||
|
||||
beforeEach(() => {
|
||||
vcoreMongoShellHandler = new VCoreMongoShellHandler();
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
// Clean up after each test
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
// Clean up after all tests
|
||||
afterAll(() => {
|
||||
jest.resetAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
jest.resetModules();
|
||||
});
|
||||
|
||||
// Positive test cases
|
||||
describe("Positive Tests", () => {
|
||||
it("should return correct shell name", () => {
|
||||
expect(vcoreMongoShellHandler.getShellName()).toBe("MongoDB VCore");
|
||||
});
|
||||
|
||||
it("should return array of setup commands with correct package version", () => {
|
||||
const commands = vcoreMongoShellHandler.getSetUpCommands();
|
||||
|
||||
expect(Array.isArray(commands)).toBe(true);
|
||||
expect(commands.length).toBe(6);
|
||||
expect(commands[1]).toContain("mongosh-2.5.0-linux-x64.tgz");
|
||||
expect(commands[0]).toContain("mongosh not found");
|
||||
});
|
||||
|
||||
it("should generate proper connection command with endpoint", () => {
|
||||
const connectionCommand = vcoreMongoShellHandler.getConnectionCommand();
|
||||
|
||||
expect(connectionCommand).toContain("mongodb+srv://username:@test-vcore-mongo.mongo.cosmos.azure.com");
|
||||
expect(connectionCommand).toContain("authMechanism=SCRAM-SHA-256");
|
||||
});
|
||||
|
||||
it("should return the correct terminal suppressed data", () => {
|
||||
expect(vcoreMongoShellHandler.getTerminalSuppressedData()).toBe("Warning: Non-Genuine MongoDB Detected");
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,54 @@
|
||||
import { userContext } from "../../../../UserContext";
|
||||
import { AbstractShellHandler } from "./AbstractShellHandler";
|
||||
|
||||
const PACKAGE_VERSION: string = "2.5.0";
|
||||
|
||||
export class VCoreMongoShellHandler extends AbstractShellHandler {
|
||||
private _endpoint: string | undefined;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this._endpoint = userContext?.databaseAccount?.properties?.vcoreMongoEndpoint;
|
||||
}
|
||||
|
||||
public getShellName(): string {
|
||||
return "MongoDB VCore";
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup commands for MongoDB VCore shell:
|
||||
*
|
||||
* 1. Check if mongosh is already installed
|
||||
* 2. Download mongosh package if not installed
|
||||
* 3. Extract the package to access mongosh binaries
|
||||
* 4. Move extracted files to ~/mongosh directory
|
||||
* 5. Add mongosh binary path to system PATH
|
||||
* 6. Apply PATH changes by sourcing .bashrc
|
||||
*
|
||||
* Each command runs conditionally only if mongosh
|
||||
* is not already present in the environment.
|
||||
*/
|
||||
public getSetUpCommands(): string[] {
|
||||
return [
|
||||
"if ! command -v mongosh &> /dev/null; then echo '⚠️ mongosh not found. Installing...'; fi",
|
||||
`if ! command -v mongosh &> /dev/null; then curl -LO https://downloads.mongodb.com/compass/mongosh-${PACKAGE_VERSION}-linux-x64.tgz; fi`,
|
||||
`if ! command -v mongosh &> /dev/null; then tar -xvzf mongosh-${PACKAGE_VERSION}-linux-x64.tgz; fi`,
|
||||
`if ! command -v mongosh &> /dev/null; then mkdir -p ~/mongosh && mv mongosh-${PACKAGE_VERSION}-linux-x64/* ~/mongosh/; fi`,
|
||||
"if ! command -v mongosh &> /dev/null; then echo 'export PATH=$HOME/mongosh/bin:$PATH' >> ~/.bashrc; fi",
|
||||
"source ~/.bashrc",
|
||||
];
|
||||
}
|
||||
|
||||
public getConnectionCommand(): string {
|
||||
if (!this._endpoint) {
|
||||
return `echo '${this.getShellName()} endpoint not found.'`;
|
||||
}
|
||||
|
||||
const userName = userContext.vcoreMongoConnectionParams.adminLogin;
|
||||
return `mongosh "mongodb+srv://${userName}:@${this._endpoint}/?authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000"`;
|
||||
}
|
||||
|
||||
public getTerminalSuppressedData(): string {
|
||||
return "Warning: Non-Genuine MongoDB Detected";
|
||||
}
|
||||
}
|
207
src/Explorer/Tabs/CloudShellTab/Utils/AttachAddOn.tsx
Normal file
207
src/Explorer/Tabs/CloudShellTab/Utils/AttachAddOn.tsx
Normal file
@ -0,0 +1,207 @@
|
||||
import { AbstractShellHandler } from "Explorer/Tabs/CloudShellTab/ShellTypes/AbstractShellHandler";
|
||||
import { IDisposable, ITerminalAddon, Terminal } from "@xterm/xterm";
|
||||
|
||||
interface IAttachOptions {
|
||||
bidirectional?: boolean;
|
||||
startMarker?: string;
|
||||
shellHandler?: AbstractShellHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Terminal addon that attaches a terminal to a WebSocket for bidirectional
|
||||
* communication with Azure CloudShell.
|
||||
*
|
||||
* Features:
|
||||
* - Manages bidirectional data flow between terminal and CloudShell WebSocket
|
||||
* - Processes special status messages within the data stream
|
||||
* - Controls terminal output display during shell initialization
|
||||
* - Supports shell-specific customizations via AbstractShellHandler
|
||||
*
|
||||
* @implements {ITerminalAddon}
|
||||
*/
|
||||
export class AttachAddon implements ITerminalAddon {
|
||||
private _socket: WebSocket;
|
||||
private _bidirectional: boolean;
|
||||
private _disposables: IDisposable[] = [];
|
||||
private _socketData: string;
|
||||
|
||||
private _allowTerminalWrite: boolean = true;
|
||||
|
||||
private _startMarker: string;
|
||||
private _shellHandler: AbstractShellHandler;
|
||||
|
||||
constructor(socket: WebSocket, options?: IAttachOptions) {
|
||||
this._socket = socket;
|
||||
// always set binary type to arraybuffer, we do not handle blobs
|
||||
this._socket.binaryType = "arraybuffer";
|
||||
this._bidirectional = !(options && options.bidirectional === false);
|
||||
this._startMarker = options?.startMarker;
|
||||
this._shellHandler = options?.shellHandler;
|
||||
this._socketData = "";
|
||||
this._allowTerminalWrite = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates the addon with the provided terminal
|
||||
*
|
||||
* Sets up event listeners for terminal input and WebSocket messages.
|
||||
* Links the terminal input to the WebSocket and vice versa.
|
||||
*
|
||||
* @param {Terminal} terminal - The XTerm terminal instance
|
||||
*/
|
||||
public activate(terminal: Terminal): void {
|
||||
this.addMessageListener(terminal);
|
||||
if (this._bidirectional) {
|
||||
this._disposables.push(terminal.onData((data) => this._sendData(data)));
|
||||
this._disposables.push(terminal.onBinary((data) => this._sendBinary(data)));
|
||||
}
|
||||
|
||||
this._disposables.push(addSocketListener(this._socket, "close", () => this.dispose()));
|
||||
this._disposables.push(addSocketListener(this._socket, "error", () => this.dispose()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a message listener to process data from the WebSocket
|
||||
*
|
||||
* Handles:
|
||||
* - Status message extraction (between ie_us and ie_ue markers)
|
||||
* - Partial message accumulation
|
||||
* - Shell initialization messages
|
||||
* - Suppression of unwanted shell output
|
||||
*
|
||||
* @param {Terminal} terminal - The XTerm terminal instance
|
||||
*/
|
||||
public addMessageListener(terminal: Terminal): void {
|
||||
this._disposables.push(
|
||||
addSocketListener(this._socket, "message", (ev) => {
|
||||
let data: ArrayBuffer | string = ev.data;
|
||||
const startStatusJson = "ie_us";
|
||||
const endStatusJson = "ie_ue";
|
||||
|
||||
if (typeof data === "object") {
|
||||
const enc = new TextDecoder("utf-8");
|
||||
data = enc.decode(ev.data as ArrayBuffer);
|
||||
}
|
||||
|
||||
// for example of json object look in TerminalHelper in the socket.onMessage
|
||||
if (data.includes(startStatusJson) && data.includes(endStatusJson)) {
|
||||
// process as one line
|
||||
const statusData = data.split(startStatusJson)[1].split(endStatusJson)[0];
|
||||
data = data.replace(statusData, "");
|
||||
data = data.replace(startStatusJson, "");
|
||||
data = data.replace(endStatusJson, "");
|
||||
} else if (data.includes(startStatusJson)) {
|
||||
// check for start
|
||||
const partialStatusData = data.split(startStatusJson)[1];
|
||||
this._socketData += partialStatusData;
|
||||
data = data.replace(partialStatusData, "");
|
||||
data = data.replace(startStatusJson, "");
|
||||
} else if (data.includes(endStatusJson)) {
|
||||
// check for end and process the command
|
||||
const partialStatusData = data.split(endStatusJson)[0];
|
||||
this._socketData += partialStatusData;
|
||||
data = data.replace(partialStatusData, "");
|
||||
data = data.replace(endStatusJson, "");
|
||||
this._socketData = "";
|
||||
} else if (this._socketData.length > 0) {
|
||||
// check if the line is all data then just concatenate
|
||||
this._socketData += data;
|
||||
data = "";
|
||||
}
|
||||
|
||||
if (this._allowTerminalWrite && data.includes(this._startMarker)) {
|
||||
this._allowTerminalWrite = false;
|
||||
terminal.write(`Preparing ${this._shellHandler.getShellName()} environment...\r\n`);
|
||||
}
|
||||
|
||||
if (this._allowTerminalWrite) {
|
||||
const suppressedData = this._shellHandler?.getTerminalSuppressedData();
|
||||
const hasSuppressedData = suppressedData && suppressedData.length > 0;
|
||||
|
||||
if (!hasSuppressedData || !data.includes(suppressedData)) {
|
||||
terminal.write(data);
|
||||
}
|
||||
}
|
||||
|
||||
if (data.includes(this._shellHandler.getConnectionCommand())) {
|
||||
this._allowTerminalWrite = true;
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public dispose(): void {
|
||||
for (const d of this._disposables) {
|
||||
d.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends string data from the terminal to the WebSocket
|
||||
*
|
||||
* @param {string} data - The data to send
|
||||
*/
|
||||
private _sendData(data: string): void {
|
||||
if (!this._checkOpenSocket()) {
|
||||
return;
|
||||
}
|
||||
this._socket.send(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends binary data from the terminal to the WebSocket
|
||||
*
|
||||
* @param {string} data - The string data to convert to binary and send
|
||||
*/
|
||||
private _sendBinary(data: string): void {
|
||||
if (!this._checkOpenSocket()) {
|
||||
return;
|
||||
}
|
||||
const buffer = new Uint8Array(data.length);
|
||||
for (let i = 0; i < data.length; ++i) {
|
||||
buffer[i] = data.charCodeAt(i) & 255;
|
||||
}
|
||||
this._socket.send(buffer);
|
||||
}
|
||||
|
||||
private _checkOpenSocket(): boolean {
|
||||
switch (this._socket.readyState) {
|
||||
case WebSocket.OPEN:
|
||||
return true;
|
||||
case WebSocket.CONNECTING:
|
||||
throw new Error("Attach addon was loaded before socket was open");
|
||||
case WebSocket.CLOSING:
|
||||
return false;
|
||||
case WebSocket.CLOSED:
|
||||
throw new Error("Attach addon socket is closed");
|
||||
default:
|
||||
throw new Error("Unexpected socket state");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an event listener to a WebSocket and returns a disposable object
|
||||
* for cleanup
|
||||
*
|
||||
* @param {WebSocket} socket - The WebSocket instance
|
||||
* @param {K} type - The event type to listen for
|
||||
* @param {Function} handler - The event handler function
|
||||
* @returns {IDisposable} An object with a dispose method to remove the listener
|
||||
*/
|
||||
function addSocketListener<K extends keyof WebSocketEventMap>(
|
||||
socket: WebSocket,
|
||||
type: K,
|
||||
handler: (this: WebSocket, ev: WebSocketEventMap[K]) => void,
|
||||
): IDisposable {
|
||||
socket.addEventListener(type, handler);
|
||||
return {
|
||||
dispose: () => {
|
||||
if (!handler) {
|
||||
// Already disposed
|
||||
return;
|
||||
}
|
||||
socket.removeEventListener(type, handler);
|
||||
},
|
||||
};
|
||||
}
|
52
src/Explorer/Tabs/CloudShellTab/Utils/CommonUtils.tsx
Normal file
52
src/Explorer/Tabs/CloudShellTab/Utils/CommonUtils.tsx
Normal file
@ -0,0 +1,52 @@
|
||||
import { Terminal } from "@xterm/xterm";
|
||||
import { TerminalKind } from "../../../../Contracts/ViewModels";
|
||||
|
||||
/**
|
||||
* Utility function to wait for a specified duration
|
||||
*/
|
||||
export const wait = (ms: number): Promise<void> => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
/**
|
||||
* Extract host from a URL
|
||||
*/
|
||||
export const getHostFromUrl = (url: string): string => {
|
||||
try {
|
||||
const urlObj = new URL(url);
|
||||
return urlObj.hostname;
|
||||
} catch (error) {
|
||||
console.error("Invalid URL:", error);
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
export const askConfirmation = async (terminal: Terminal, question: string): Promise<boolean> => {
|
||||
terminal.writeln(`\n${question} (Y/N)`);
|
||||
terminal.focus();
|
||||
return new Promise<boolean>((resolve) => {
|
||||
const keyListener = terminal.onKey(({ key }: { key: string }) => {
|
||||
keyListener.dispose();
|
||||
terminal.writeln(key);
|
||||
return resolve(key.toLowerCase() === "y");
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Gets the current locale for API requests
|
||||
*/
|
||||
export const getLocale = (): string => {
|
||||
const langLocale = navigator.language;
|
||||
return langLocale && langLocale.length > 2 ? langLocale : "en-us";
|
||||
};
|
||||
|
||||
export const getShellNameForDisplay = (terminalKind: TerminalKind): string => {
|
||||
switch (terminalKind) {
|
||||
case TerminalKind.Postgres:
|
||||
return "PostgreSQL";
|
||||
case TerminalKind.Mongo:
|
||||
case TerminalKind.VCoreMongo:
|
||||
return "MongoDB";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
};
|
48
src/Explorer/Tabs/CloudShellTab/Utils/RegionUtils.tsx
Normal file
48
src/Explorer/Tabs/CloudShellTab/Utils/RegionUtils.tsx
Normal file
@ -0,0 +1,48 @@
|
||||
// Check this list for regional availability https://azure.microsoft.com/en-us/explore/global-infrastructure/products-by-region/table
|
||||
const validCloudShellRegions = new Set([
|
||||
"westus",
|
||||
"southcentralus",
|
||||
"eastus",
|
||||
"northeurope",
|
||||
"westeurope",
|
||||
"centralindia",
|
||||
"southeastasia",
|
||||
"westcentralus",
|
||||
]);
|
||||
|
||||
/**
|
||||
* Normalizes a region name to ensure compatibility with Azure CloudShell.
|
||||
*
|
||||
* Azure CloudShell is only available in specific regions. This function:
|
||||
* 1. Maps certain regions to their CloudShell-supported equivalents (e.g., centralus → westcentralus)
|
||||
* 2. Validates if the region is supported by CloudShell
|
||||
* 3. Falls back to the default region if the provided region is unsupported
|
||||
*
|
||||
* This ensures users can connect to CloudShell even when their database is in a region
|
||||
* where CloudShell isn't directly available, by routing to the nearest supported region.
|
||||
*
|
||||
* @param region - The source region (typically from the user's database account location)
|
||||
* @param defaultCloudshellRegion - Fallback region to use if the provided region is not supported
|
||||
* @returns A valid CloudShell region name that's as close as possible to the requested region
|
||||
*
|
||||
* @example
|
||||
* // Returns "westcentralus" (mapped region)
|
||||
* getNormalizedRegion("centralus", "westus")
|
||||
*
|
||||
* @example
|
||||
* // Returns "westus" (default region) since "antarctica" isn't supported
|
||||
* getNormalizedRegion("antarctica", "westus")
|
||||
*/
|
||||
export const getNormalizedRegion = (region: string, defaultCloudshellRegion: string) => {
|
||||
if (!region) {
|
||||
return defaultCloudshellRegion;
|
||||
}
|
||||
|
||||
const regionMap: Record<string, string> = {
|
||||
centralus: "westcentralus",
|
||||
eastus2: "eastus",
|
||||
};
|
||||
|
||||
const normalizedRegion = regionMap[region.toLowerCase()] || region;
|
||||
return validCloudShellRegions.has(normalizedRegion.toLowerCase()) ? normalizedRegion : defaultCloudshellRegion;
|
||||
};
|
39
src/Explorer/Tabs/CloudShellTab/Utils/TerminalLogFormats.tsx
Normal file
39
src/Explorer/Tabs/CloudShellTab/Utils/TerminalLogFormats.tsx
Normal file
@ -0,0 +1,39 @@
|
||||
// This file contains utility functions and constants for formatting terminal messages in a cloud shell environment.
|
||||
// It includes ANSI escape codes for colors and functions to format messages for different log levels (info, success, warning, error).
|
||||
export const TERMINAL_COLORS = {
|
||||
RESET: "\x1b[0m",
|
||||
BRIGHT: "\x1b[1m",
|
||||
DIM: "\x1b[2m",
|
||||
BLACK: "\x1b[30m",
|
||||
RED: "\x1b[31m",
|
||||
GREEN: "\x1b[32m",
|
||||
YELLOW: "\x1b[33m",
|
||||
BLUE: "\x1b[34m",
|
||||
MAGENTA: "\x1b[35m",
|
||||
CYAN: "\x1b[36m",
|
||||
WHITE: "\x1b[37m",
|
||||
BG_BLACK: "\x1b[40m",
|
||||
BG_RED: "\x1b[41m",
|
||||
BG_GREEN: "\x1b[42m",
|
||||
BG_YELLOW: "\x1b[43m",
|
||||
BG_BLUE: "\x1b[44m",
|
||||
BG_MAGENTA: "\x1b[45m",
|
||||
BG_CYAN: "\x1b[46m",
|
||||
BG_WHITE: "\x1b[47m",
|
||||
};
|
||||
|
||||
export const START_MARKER = `echo "START INITIALIZATION" > /dev/null`;
|
||||
export const END_MARKER = `echo "END INITIALIZATION" > /dev/null`;
|
||||
|
||||
// Terminal message formatting functions
|
||||
export const formatInfoMessage = (message: string): string =>
|
||||
`${TERMINAL_COLORS.BRIGHT}${TERMINAL_COLORS.CYAN}${message}${TERMINAL_COLORS.RESET}`;
|
||||
|
||||
export const formatSuccessMessage = (message: string): string =>
|
||||
`${TERMINAL_COLORS.BRIGHT}${TERMINAL_COLORS.GREEN}${message}${TERMINAL_COLORS.RESET}`;
|
||||
|
||||
export const formatWarningMessage = (message: string): string =>
|
||||
`${TERMINAL_COLORS.BRIGHT}${TERMINAL_COLORS.YELLOW}${message}${TERMINAL_COLORS.RESET}`;
|
||||
|
||||
export const formatErrorMessage = (message: string): string =>
|
||||
`${TERMINAL_COLORS.BRIGHT}${TERMINAL_COLORS.RED}${message}${TERMINAL_COLORS.RESET}`;
|
@ -773,8 +773,11 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
|
||||
[_collection, _partitionKey],
|
||||
);
|
||||
const partitionKeyPropertyHeaders: string[] = useMemo(
|
||||
() => (partitionKey?.systemKey ? [] : _collection?.partitionKeyPropertyHeaders || partitionKey?.paths),
|
||||
[_collection?.partitionKeyPropertyHeaders, partitionKey?.paths, partitionKey?.systemKey],
|
||||
() =>
|
||||
isPreferredApiMongoDB && partitionKey?.systemKey
|
||||
? []
|
||||
: _collection?.partitionKeyPropertyHeaders || partitionKey?.paths,
|
||||
[_collection?.partitionKeyPropertyHeaders, partitionKey?.paths, partitionKey?.systemKey, isPreferredApiMongoDB],
|
||||
);
|
||||
let partitionKeyProperties = useMemo(() => {
|
||||
return partitionKeyPropertyHeaders?.map((partitionKeyPropertyHeader) =>
|
||||
@ -2116,6 +2119,7 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
|
||||
/>
|
||||
<Button
|
||||
appearance="primary"
|
||||
data-test={"DocumentsTab/ApplyFilter"}
|
||||
size="small"
|
||||
onClick={() => {
|
||||
if (isExecuting) {
|
||||
@ -2188,6 +2192,7 @@ export const DocumentsTabComponent: React.FunctionComponent<IDocumentsTabCompone
|
||||
{tableItems.length > 0 && (
|
||||
<a
|
||||
className={styles.loadMore}
|
||||
data-test={"DocumentsTab/LoadMore"}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={() => loadNextPage(documentsIterator.iterator, false)}
|
||||
|
@ -51,6 +51,7 @@ exports[`Documents tab (noSql API) when rendered should render the page 1`] = `
|
||||
<Button
|
||||
appearance="primary"
|
||||
aria-label="Apply filter"
|
||||
data-test="DocumentsTab/ApplyFilter"
|
||||
disabled={false}
|
||||
onClick={[Function]}
|
||||
size="small"
|
||||
|
@ -0,0 +1,62 @@
|
||||
import { Spinner, SpinnerSize } from "@fluentui/react";
|
||||
import { MessageTypes } from "Contracts/ExplorerContracts";
|
||||
import { QuickstartFirewallNotification } from "Explorer/Quickstart/QuickstartFirewallNotification";
|
||||
import { getShellNameForDisplay } from "Explorer/Tabs/CloudShellTab/Utils/CommonUtils";
|
||||
import * as React from "react";
|
||||
import FirewallRuleScreenshot from "../../../../images/firewallRule.png";
|
||||
import VcoreFirewallRuleScreenshot from "../../../../images/vcoreMongoFirewallRule.png";
|
||||
import { ReactAdapter } from "../../../Bindings/ReactBindingHandler";
|
||||
import * as DataModels from "../../../Contracts/DataModels";
|
||||
import * as ViewModels from "../../../Contracts/ViewModels";
|
||||
|
||||
/**
|
||||
* Base terminal component adapter
|
||||
*/
|
||||
export abstract class BaseTerminalComponentAdapter implements ReactAdapter {
|
||||
// parameters: true: show, false: hide
|
||||
public parameters: ko.Computed<boolean>;
|
||||
|
||||
constructor(
|
||||
protected getDatabaseAccount: () => DataModels.DatabaseAccount,
|
||||
protected getTabId: () => string,
|
||||
protected getUsername: () => string,
|
||||
protected isAllPublicIPAddressesEnabled: ko.Observable<boolean>,
|
||||
protected kind: ViewModels.TerminalKind,
|
||||
) {}
|
||||
|
||||
public renderComponent(): JSX.Element {
|
||||
if (!this.isAllPublicIPAddressesEnabled()) {
|
||||
return (
|
||||
<QuickstartFirewallNotification
|
||||
messageType={this.getMessageType()}
|
||||
screenshot={
|
||||
this.kind === ViewModels.TerminalKind.Mongo || this.kind === ViewModels.TerminalKind.VCoreMongo
|
||||
? VcoreFirewallRuleScreenshot
|
||||
: FirewallRuleScreenshot
|
||||
}
|
||||
shellName={getShellNameForDisplay(this.kind)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return this.parameters() ? (
|
||||
this.renderTerminalComponent()
|
||||
) : (
|
||||
<Spinner styles={{ root: { marginTop: 10 } }} size={SpinnerSize.large}></Spinner>
|
||||
);
|
||||
}
|
||||
|
||||
private getMessageType(): MessageTypes {
|
||||
switch (this.kind) {
|
||||
case ViewModels.TerminalKind.Postgres:
|
||||
return MessageTypes.OpenPostgresNetworkingBlade;
|
||||
case ViewModels.TerminalKind.Mongo:
|
||||
case ViewModels.TerminalKind.VCoreMongo:
|
||||
return MessageTypes.OpenVCoreMongoNetworkingBlade;
|
||||
default:
|
||||
return MessageTypes.OpenPostgresNetworkingBlade;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract renderTerminalComponent(): JSX.Element;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
import { CloudShellTerminalComponent } from "Explorer/Tabs/CloudShellTab/CloudShellTerminalComponent";
|
||||
import * as React from "react";
|
||||
import { BaseTerminalComponentAdapter } from "./BaseTerminalComponentAdapter";
|
||||
|
||||
/**
|
||||
* CloudShell terminal tab
|
||||
*/
|
||||
export class CloudShellTerminalComponentAdapter extends BaseTerminalComponentAdapter {
|
||||
protected renderTerminalComponent(): JSX.Element {
|
||||
return (
|
||||
<CloudShellTerminalComponent
|
||||
databaseAccount={this.getDatabaseAccount()}
|
||||
tabId={this.getTabId()}
|
||||
shellType={this.kind}
|
||||
username={this.getUsername()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
import { NotebookTerminalComponent } from "Explorer/Controls/Notebook/NotebookTerminalComponent";
|
||||
import * as React from "react";
|
||||
import * as DataModels from "../../../Contracts/DataModels";
|
||||
import * as ViewModels from "../../../Contracts/ViewModels";
|
||||
import { BaseTerminalComponentAdapter } from "./BaseTerminalComponentAdapter";
|
||||
|
||||
/**
|
||||
* Notebook terminal tab
|
||||
*/
|
||||
export class NotebookTerminalComponentAdapter extends BaseTerminalComponentAdapter {
|
||||
constructor(
|
||||
private getNotebookServerInfo: () => DataModels.NotebookWorkspaceConnectionInfo,
|
||||
getDatabaseAccount: () => DataModels.DatabaseAccount,
|
||||
getTabId: () => string,
|
||||
getUsername: () => string,
|
||||
isAllPublicIPAddressesEnabled: ko.Observable<boolean>,
|
||||
kind: ViewModels.TerminalKind,
|
||||
) {
|
||||
super(getDatabaseAccount, getTabId, getUsername, isAllPublicIPAddressesEnabled, kind);
|
||||
}
|
||||
|
||||
protected renderTerminalComponent(): JSX.Element {
|
||||
return (
|
||||
<NotebookTerminalComponent
|
||||
notebookServerInfo={this.getNotebookServerInfo()}
|
||||
databaseAccount={this.getDatabaseAccount()}
|
||||
tabId={this.getTabId()}
|
||||
username={this.getUsername()}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
@ -1,19 +1,14 @@
|
||||
import { Spinner, SpinnerSize } from "@fluentui/react";
|
||||
import { MessageTypes } from "Contracts/ExplorerContracts";
|
||||
import { QuickstartFirewallNotification } from "Explorer/Quickstart/QuickstartFirewallNotification";
|
||||
import { checkFirewallRules } from "Explorer/Tabs/Shared/CheckFirewallRules";
|
||||
import { CloudShellTerminalComponentAdapter } from "Explorer/Tabs/ShellAdapters/CloudShellTerminalComponentAdapter";
|
||||
import * as ko from "knockout";
|
||||
import * as React from "react";
|
||||
import FirewallRuleScreenshot from "../../../images/firewallRule.png";
|
||||
import VcoreFirewallRuleScreenshot from "../../../images/vcoreMongoFirewallRule.png";
|
||||
import { ReactAdapter } from "../../Bindings/ReactBindingHandler";
|
||||
import * as DataModels from "../../Contracts/DataModels";
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
import { userContext } from "../../UserContext";
|
||||
import { CommandButtonComponentProps } from "../Controls/CommandButton/CommandButtonComponent";
|
||||
import { NotebookTerminalComponent } from "../Controls/Notebook/NotebookTerminalComponent";
|
||||
import Explorer from "../Explorer";
|
||||
import { useNotebook } from "../Notebook/useNotebook";
|
||||
import { NotebookTerminalComponentAdapter } from "./ShellAdapters/NotebookTerminalComponentAdapter";
|
||||
import TabsBase from "./TabsBase";
|
||||
|
||||
export interface TerminalTabOptions extends ViewModels.TabOptions {
|
||||
@ -23,90 +18,52 @@ export interface TerminalTabOptions extends ViewModels.TabOptions {
|
||||
username?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notebook terminal tab
|
||||
*/
|
||||
class NotebookTerminalComponentAdapter implements ReactAdapter {
|
||||
// parameters: true: show, false: hide
|
||||
public parameters: ko.Computed<boolean>;
|
||||
constructor(
|
||||
private getNotebookServerInfo: () => DataModels.NotebookWorkspaceConnectionInfo,
|
||||
private getDatabaseAccount: () => DataModels.DatabaseAccount,
|
||||
private getTabId: () => string,
|
||||
private getUsername: () => string,
|
||||
private isAllPublicIPAddressesEnabled: ko.Observable<boolean>,
|
||||
private kind: ViewModels.TerminalKind,
|
||||
) {}
|
||||
|
||||
public renderComponent(): JSX.Element {
|
||||
if (!this.isAllPublicIPAddressesEnabled()) {
|
||||
return (
|
||||
<QuickstartFirewallNotification
|
||||
messageType={MessageTypes.OpenPostgresNetworkingBlade}
|
||||
screenshot={
|
||||
this.kind === ViewModels.TerminalKind.Mongo || this.kind === ViewModels.TerminalKind.VCoreMongo
|
||||
? VcoreFirewallRuleScreenshot
|
||||
: FirewallRuleScreenshot
|
||||
}
|
||||
shellName={this.getShellNameForDisplay(this.kind)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return this.parameters() ? (
|
||||
<NotebookTerminalComponent
|
||||
notebookServerInfo={this.getNotebookServerInfo()}
|
||||
databaseAccount={this.getDatabaseAccount()}
|
||||
tabId={this.getTabId()}
|
||||
username={this.getUsername()}
|
||||
/>
|
||||
) : (
|
||||
<Spinner styles={{ root: { marginTop: 10 } }} size={SpinnerSize.large}></Spinner>
|
||||
);
|
||||
}
|
||||
|
||||
private getShellNameForDisplay(terminalKind: ViewModels.TerminalKind): string {
|
||||
switch (terminalKind) {
|
||||
case ViewModels.TerminalKind.Postgres:
|
||||
return "PostgreSQL";
|
||||
case ViewModels.TerminalKind.Mongo:
|
||||
case ViewModels.TerminalKind.VCoreMongo:
|
||||
return "MongoDB";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default class TerminalTab extends TabsBase {
|
||||
public readonly html = '<div style="height: 100%" data-bind="react:notebookTerminalComponentAdapter"></div> ';
|
||||
private container: Explorer;
|
||||
private notebookTerminalComponentAdapter: NotebookTerminalComponentAdapter;
|
||||
private notebookTerminalComponentAdapter: ReactAdapter;
|
||||
private isAllPublicIPAddressesEnabled: ko.Observable<boolean>;
|
||||
|
||||
constructor(options: TerminalTabOptions) {
|
||||
super(options);
|
||||
this.container = options.container;
|
||||
this.isAllPublicIPAddressesEnabled = ko.observable(true);
|
||||
this.notebookTerminalComponentAdapter = new NotebookTerminalComponentAdapter(
|
||||
() => this.getNotebookServerInfo(options),
|
||||
|
||||
const commonArgs: [
|
||||
() => DataModels.DatabaseAccount,
|
||||
() => string,
|
||||
() => string,
|
||||
ko.Observable<boolean>,
|
||||
ViewModels.TerminalKind,
|
||||
] = [
|
||||
() => userContext?.databaseAccount,
|
||||
() => this.tabId,
|
||||
() => this.getUsername(),
|
||||
this.isAllPublicIPAddressesEnabled,
|
||||
options.kind,
|
||||
);
|
||||
this.notebookTerminalComponentAdapter.parameters = ko.computed<boolean>(() => {
|
||||
if (
|
||||
this.isTemplateReady() &&
|
||||
useNotebook.getState().isNotebookEnabled &&
|
||||
useNotebook.getState().notebookServerInfo?.notebookServerEndpoint &&
|
||||
this.isAllPublicIPAddressesEnabled()
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
];
|
||||
|
||||
if (userContext.features.enableCloudShell) {
|
||||
this.notebookTerminalComponentAdapter = new CloudShellTerminalComponentAdapter(...commonArgs);
|
||||
|
||||
this.notebookTerminalComponentAdapter.parameters = ko.computed<boolean>(() => {
|
||||
return this.isTemplateReady() && this.isAllPublicIPAddressesEnabled();
|
||||
});
|
||||
} else {
|
||||
this.notebookTerminalComponentAdapter = new NotebookTerminalComponentAdapter(
|
||||
() => this.getNotebookServerInfo(options),
|
||||
...commonArgs,
|
||||
);
|
||||
|
||||
this.notebookTerminalComponentAdapter.parameters = ko.computed<boolean>(() => {
|
||||
return (
|
||||
this.isTemplateReady() &&
|
||||
useNotebook.getState().isNotebookEnabled &&
|
||||
useNotebook.getState().notebookServerInfo?.notebookServerEndpoint &&
|
||||
this.isAllPublicIPAddressesEnabled()
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
if (options.kind === ViewModels.TerminalKind.Postgres) {
|
||||
checkFirewallRules(
|
||||
|
@ -241,21 +241,6 @@ export class ResourceTreeAdapter implements ReactAdapter {
|
||||
contextMenu: ResourceTreeContextMenuButtonFactory.createCollectionContextMenuButton(this.container, collection),
|
||||
});
|
||||
|
||||
if (
|
||||
useNotebook.getState().isNotebookEnabled &&
|
||||
userContext.apiType === "Mongo" &&
|
||||
isPublicInternetAccessAllowed()
|
||||
) {
|
||||
children.push({
|
||||
label: "Schema (Preview)",
|
||||
onClick: collection.onSchemaAnalyzerClick.bind(collection),
|
||||
isSelected: () =>
|
||||
useSelectedNode
|
||||
.getState()
|
||||
.isDataNodeSelected(collection.databaseId, collection.id(), [ViewModels.CollectionTabKind.SchemaAnalyzer]),
|
||||
});
|
||||
}
|
||||
|
||||
if (userContext.apiType !== "Cassandra" || !isServerlessAccount()) {
|
||||
children.push({
|
||||
label: database.isDatabaseShared() || isServerlessAccount() ? "Settings" : "Scale & Settings",
|
||||
|
@ -338,11 +338,6 @@ exports[`createDatabaseTreeNodes generates the correct tree structure for the Mo
|
||||
"label": "Documents",
|
||||
"onClick": [Function],
|
||||
},
|
||||
{
|
||||
"isSelected": [Function],
|
||||
"label": "Schema (Preview)",
|
||||
"onClick": [Function],
|
||||
},
|
||||
{
|
||||
"id": "",
|
||||
"isSelected": [Function],
|
||||
@ -406,11 +401,6 @@ exports[`createDatabaseTreeNodes generates the correct tree structure for the Mo
|
||||
"label": "Documents",
|
||||
"onClick": [Function],
|
||||
},
|
||||
{
|
||||
"isSelected": [Function],
|
||||
"label": "Schema (Preview)",
|
||||
"onClick": [Function],
|
||||
},
|
||||
{
|
||||
"id": "",
|
||||
"isSelected": [Function],
|
||||
@ -515,11 +505,6 @@ exports[`createDatabaseTreeNodes generates the correct tree structure for the Mo
|
||||
"label": "Documents",
|
||||
"onClick": [Function],
|
||||
},
|
||||
{
|
||||
"isSelected": [Function],
|
||||
"label": "Schema (Preview)",
|
||||
"onClick": [Function],
|
||||
},
|
||||
{
|
||||
"id": "sampleSettings",
|
||||
"isSelected": [Function],
|
||||
@ -610,11 +595,6 @@ exports[`createDatabaseTreeNodes generates the correct tree structure for the Mo
|
||||
"label": "Documents",
|
||||
"onClick": [Function],
|
||||
},
|
||||
{
|
||||
"isSelected": [Function],
|
||||
"label": "Schema (Preview)",
|
||||
"onClick": [Function],
|
||||
},
|
||||
{
|
||||
"id": "",
|
||||
"isSelected": [Function],
|
||||
|
@ -6,12 +6,11 @@ import StoredProcedure from "Explorer/Tree/StoredProcedure";
|
||||
import Trigger from "Explorer/Tree/Trigger";
|
||||
import UserDefinedFunction from "Explorer/Tree/UserDefinedFunction";
|
||||
import { useDatabases } from "Explorer/useDatabases";
|
||||
import { isFabric, isFabricMirrored, isFabricNative } from "Platform/Fabric/FabricUtil";
|
||||
import { isFabric, isFabricMirrored, isFabricNative, isFabricNativeReadOnly } from "Platform/Fabric/FabricUtil";
|
||||
import { getItemName } from "Utils/APITypeUtils";
|
||||
import { isServerlessAccount } from "Utils/CapabilityUtils";
|
||||
import { useTabs } from "hooks/useTabs";
|
||||
import React from "react";
|
||||
import { isPublicInternetAccessAllowed } from "../../Common/DatabaseAccountUtility";
|
||||
import { Platform, configContext } from "../../ConfigContext";
|
||||
import * as DataModels from "../../Contracts/DataModels";
|
||||
import * as ViewModels from "../../Contracts/ViewModels";
|
||||
@ -19,7 +18,6 @@ import { userContext } from "../../UserContext";
|
||||
import * as ResourceTreeContextMenuButtonFactory from "../ContextMenuButtonFactory";
|
||||
import Explorer from "../Explorer";
|
||||
import { useCommandBar } from "../Menus/CommandBar/CommandBarComponentAdapter";
|
||||
import { useNotebook } from "../Notebook/useNotebook";
|
||||
import { useSelectedNode } from "../useSelectedNode";
|
||||
|
||||
export const shouldShowScriptNodes = (): boolean => {
|
||||
@ -294,23 +292,7 @@ const buildCollectionNodeChildren = (
|
||||
contextMenu: ResourceTreeContextMenuButtonFactory.createCollectionContextMenuButton(container, collection),
|
||||
});
|
||||
|
||||
if (
|
||||
isNotebookEnabled &&
|
||||
userContext.apiType === "Mongo" &&
|
||||
isPublicInternetAccessAllowed() &&
|
||||
useNotebook.getState().isPhoenixFeatures
|
||||
) {
|
||||
children.push({
|
||||
label: "Schema (Preview)",
|
||||
onClick: collection.onSchemaAnalyzerClick.bind(collection),
|
||||
isSelected: () =>
|
||||
useSelectedNode
|
||||
.getState()
|
||||
.isDataNodeSelected(collection.databaseId, collection.id(), [ViewModels.CollectionTabKind.SchemaAnalyzer]),
|
||||
});
|
||||
}
|
||||
|
||||
if (userContext.apiType !== "Cassandra" || !isServerlessAccount()) {
|
||||
if ((userContext.apiType !== "Cassandra" || !isServerlessAccount()) && !isFabricNativeReadOnly()) {
|
||||
let id = "";
|
||||
if (collection.isSampleCollection) {
|
||||
id = database.isDatabaseShared() ? "sampleSettings" : "sampleScaleSettings";
|
||||
|
@ -136,3 +136,4 @@ export const isFabricMirroredAAD = (): boolean =>
|
||||
export const isFabricMirrored = (): boolean => isFabricMirroredKey() || isFabricMirroredAAD();
|
||||
export const isFabricNative = (): boolean =>
|
||||
isFabric() && userContext.fabricContext?.artifactType === CosmosDbArtifactType.NATIVE;
|
||||
export const isFabricNativeReadOnly = (): boolean => isFabricNative() && !!userContext.fabricContext?.isReadOnly;
|
||||
|
@ -39,6 +39,7 @@ export type Features = {
|
||||
readonly copilotChatFixedMonacoEditorHeight: boolean;
|
||||
readonly enablePriorityBasedExecution: boolean;
|
||||
readonly disableConnectionStringLogin: boolean;
|
||||
readonly enableCloudShell: boolean;
|
||||
|
||||
// can be set via both flight and feature flag
|
||||
autoscaleDefault: boolean;
|
||||
@ -110,6 +111,7 @@ export function extractFeatures(given = new URLSearchParams(window.location.sear
|
||||
copilotChatFixedMonacoEditorHeight: "true" === get("copilotchatfixedmonacoeditorheight"),
|
||||
enablePriorityBasedExecution: "true" === get("enableprioritybasedexecution"),
|
||||
disableConnectionStringLogin: "true" === get("disableconnectionstringlogin"),
|
||||
enableCloudShell: "true" === get("enablecloudshell"),
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,7 @@ export enum Action {
|
||||
PhoenixDBAccountAllowed,
|
||||
DeleteCellFromMenu,
|
||||
OpenTerminal,
|
||||
OpenCloudShellTerminal,
|
||||
CreateMongoCollectionWithWildcardIndex,
|
||||
ClickCommandBarButton,
|
||||
RefreshResourceTreeMyNotebooks,
|
||||
@ -146,6 +147,8 @@ export enum Action {
|
||||
SavePersistedTabState,
|
||||
DeletePersistedTabState,
|
||||
UploadDocuments, // Used in Fabric. Please do not rename.
|
||||
CloudShellUserConsent,
|
||||
CloudShellTerminalSession,
|
||||
OpenVSCode,
|
||||
}
|
||||
|
||||
|
@ -52,22 +52,10 @@ export const allowedAadEndpoints: ReadonlyArray<string> = [
|
||||
];
|
||||
|
||||
export const defaultAllowedBackendEndpoints: ReadonlyArray<string> = [
|
||||
"https://main.documentdb.ext.azure.com",
|
||||
"https://main.documentdb.ext.azure.cn",
|
||||
"https://main.documentdb.ext.azure.us",
|
||||
"https://main.cosmos.ext.azure",
|
||||
"https://localhost:12901",
|
||||
"https://localhost:1234",
|
||||
];
|
||||
|
||||
export const PortalBackendIPs: { [key: string]: string[] } = {
|
||||
"https://main.documentdb.ext.azure.com": ["104.42.195.92", "40.76.54.131"],
|
||||
// DE doesn't talk to prod2 (main2) but it might be added
|
||||
//"https://main2.documentdb.ext.azure.com": ["104.42.196.69"],
|
||||
"https://main.documentdb.ext.azure.cn": ["139.217.8.252"],
|
||||
"https://main.documentdb.ext.azure.us": ["52.244.48.71"],
|
||||
};
|
||||
|
||||
export const PortalBackendOutboundIPs: { [key: string]: string[] } = {
|
||||
[PortalBackendEndpoints.Mpac]: ["13.91.105.215", "4.210.172.107"],
|
||||
[PortalBackendEndpoints.Prod]: ["13.88.56.148", "40.91.218.243"],
|
||||
@ -98,14 +86,6 @@ export const defaultAllowedCassandraProxyEndpoints: ReadonlyArray<string> = [
|
||||
CassandraProxyEndpoints.Mooncake,
|
||||
];
|
||||
|
||||
export const allowedCassandraProxyEndpoints_ToBeDeprecated: ReadonlyArray<string> = [
|
||||
"https://main.documentdb.ext.azure.com",
|
||||
"https://main.documentdb.ext.azure.cn",
|
||||
"https://main.documentdb.ext.azure.us",
|
||||
"https://main.cosmos.ext.azure",
|
||||
"https://localhost:12901",
|
||||
];
|
||||
|
||||
export const CassandraProxyOutboundIPs: { [key: string]: string[] } = {
|
||||
[CassandraProxyEndpoints.Mpac]: ["40.113.96.14", "104.42.11.145"],
|
||||
[CassandraProxyEndpoints.Prod]: ["137.117.230.240", "168.61.72.237"],
|
||||
|
@ -17,7 +17,6 @@ describe("isInvalidParentFrameOrigin", () => {
|
||||
${"https://cdb-ff-prod-pbe.cosmos.azure.us"} | ${false}
|
||||
${"https://cdb-mc-prod-pbe.cosmos.azure.cn"} | ${false}
|
||||
${"https://cosmos-db-dataexplorer-germanycentral.azurewebsites.de"} | ${false}
|
||||
${"https://main.documentdb.ext.microsoftazure.de"} | ${false}
|
||||
${"https://random.domain"} | ${true}
|
||||
${"https://malicious.cloudapp.azure.com"} | ${true}
|
||||
${"https://malicious.germanycentral.cloudapp.microsoftazure.de"} | ${true}
|
||||
|
@ -47,6 +47,7 @@ interface Options {
|
||||
body?: unknown;
|
||||
queryParams?: ARMQueryParams;
|
||||
contentType?: string;
|
||||
customHeaders?: Record<string, string>;
|
||||
}
|
||||
|
||||
export async function armRequestWithoutPolling<T>({
|
||||
@ -57,6 +58,7 @@ export async function armRequestWithoutPolling<T>({
|
||||
body: requestBody,
|
||||
queryParams,
|
||||
contentType,
|
||||
customHeaders,
|
||||
}: Options): Promise<{ result: T; operationStatusUrl: string }> {
|
||||
const url = new URL(path, host);
|
||||
url.searchParams.append("api-version", configContext.armAPIVersion || apiVersion);
|
||||
@ -65,18 +67,22 @@ export async function armRequestWithoutPolling<T>({
|
||||
queryParams.metricNames && url.searchParams.append("metricnames", queryParams.metricNames);
|
||||
}
|
||||
|
||||
if (!userContext.authorizationToken) {
|
||||
if (!userContext?.authorizationToken && !customHeaders?.["Authorization"]) {
|
||||
throw new Error("No authority token provided");
|
||||
}
|
||||
|
||||
const headers: Record<string, string> = {
|
||||
Authorization: userContext.authorizationToken || customHeaders?.["Authorization"] || "",
|
||||
[HttpHeaders.contentType]: contentType || "application/json",
|
||||
...(customHeaders || {}),
|
||||
};
|
||||
|
||||
const response = await window.fetch(url.href, {
|
||||
method,
|
||||
headers: {
|
||||
Authorization: userContext.authorizationToken,
|
||||
[HttpHeaders.contentType]: contentType || "application/json",
|
||||
},
|
||||
headers,
|
||||
body: requestBody ? JSON.stringify(requestBody) : undefined,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
let error: ARMError;
|
||||
try {
|
||||
@ -109,6 +115,7 @@ export async function armRequest<T>({
|
||||
body: requestBody,
|
||||
queryParams,
|
||||
contentType,
|
||||
customHeaders,
|
||||
}: Options): Promise<T> {
|
||||
const armRequestResult = await armRequestWithoutPolling<T>({
|
||||
host,
|
||||
@ -118,6 +125,7 @@ export async function armRequest<T>({
|
||||
body: requestBody,
|
||||
queryParams,
|
||||
contentType,
|
||||
customHeaders,
|
||||
});
|
||||
const operationStatusUrl = armRequestResult.operationStatusUrl;
|
||||
if (operationStatusUrl) {
|
||||
|
@ -42,214 +42,92 @@
|
||||
<div class="container-fluid">
|
||||
<ul class="nav nav-tabs qslevel">
|
||||
<li class="active">
|
||||
<a data-toggle="tab" href="#net"
|
||||
><img class="qsmenuicons" src="../images/dotnet.png" alt=".NET platform" />.NET</a
|
||||
>
|
||||
<a data-toggle="tab" href="#net">
|
||||
<img class="qsmenuicons" src="../images/dotnet.png" alt=".NET" /> .NET
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a data-toggle="tab" href="#corenet"
|
||||
><img class="qsmenuicons" src="../images/dotnet.png" alt=".NET Core platform" />.NET Core</a
|
||||
>
|
||||
<a data-toggle="tab" href="#java"> <img class="qsmenuicons" src="../images/java.png" alt="Java" /> Java </a>
|
||||
</li>
|
||||
<li>
|
||||
<a data-toggle="tab" href="#Java"
|
||||
><img class="qsmenuicons" src="../images/java.png" alt="Java platform" />Java</a
|
||||
>
|
||||
<a data-toggle="tab" href="#nodejs">
|
||||
<img class="qsmenuicons" src="../images/nodejs.png" alt="Node.js" /> Node.js
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a data-toggle="tab" href="#NodeJs"
|
||||
><img class="qsmenuicons" src="../images/nodejs.png" alt="Node.js platform" />Node.js</a
|
||||
>
|
||||
<a data-toggle="tab" href="#python">
|
||||
<img class="qsmenuicons" src="../images/python.png" alt="Python" /> Python
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a data-toggle="tab" href="#Python"
|
||||
><img class="qsmenuicons" src="../images/python.png" alt="Python platform" />Python</a
|
||||
>
|
||||
<a data-toggle="tab" href="#go"> <img class="qsmenuicons" src="../images/golang.svg" alt="Go" /> Go </a>
|
||||
</li>
|
||||
<li>
|
||||
<a data-toggle="tab" href="#springboot">
|
||||
<img class="qsmenuicons" src="../images/springboot.svg" alt="Spring Boot" /> Spring Boot
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<div class="tab-content tab-content-override">
|
||||
|
||||
<div class="tab-content">
|
||||
<div id="net" class="tab-pane fade in active">
|
||||
<div class="netApp">
|
||||
<div class="sampleApp">
|
||||
<div class="numbersize numbersizePadding">1</div>
|
||||
<div class="numberheading">
|
||||
Open and run a sample .NET app
|
||||
Create a new .NET app
|
||||
<p>
|
||||
We created a sample .NET app connected to your Azure Cosmos DB Emulator instance. Download, extract,
|
||||
build and run the app.
|
||||
Follow this
|
||||
<a href="https://learn.microsoft.com/azure/cosmos-db/nosql/quickstart-dotnet" target="_blank"
|
||||
>tutorial
|
||||
</a>
|
||||
to create a new .NET app connected to Azure Cosmos DB.
|
||||
</p>
|
||||
<a href="quickstart/DocumentDB-Quickstart-DotNet.zip"
|
||||
><button class="btncreatecoll">Download</button></a
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="netApp">
|
||||
<div class="numbersize">2</div>
|
||||
<div class="numberheading">
|
||||
Learn more about Azure Cosmos DB
|
||||
<ul>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/samples/dotnet"
|
||||
>Code Samples</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/docs">Documentation</a>
|
||||
</li>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/pricing">Pricing</a>
|
||||
</li>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/capacity-planner"
|
||||
>Capacity Planner</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/stackoverflow">Forum</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="corenet" class="tab-pane fade">
|
||||
<div class="netApp">
|
||||
<div class="numbersize numbersizePadding">1</div>
|
||||
<div class="numberheading">
|
||||
Open and run a sample .NET Core app
|
||||
<p>
|
||||
We created a sample .NET Core app connected to your Azure Cosmos DB Emulator instance. Download,
|
||||
extract, build and run the app.
|
||||
</p>
|
||||
<a href="quickstart/DocumentDB-Quickstart-DotNetCore.zip"
|
||||
><button class="btncreatecoll">Download</button></a
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="netApp">
|
||||
<div class="numbersize">2</div>
|
||||
<div class="numberheading">
|
||||
Learn more about Azure Cosmos DB.
|
||||
<ul>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/samples/dotnet"
|
||||
>Code Samples</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/docs">Documentation</a>
|
||||
</li>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/pricing">Pricing</a>
|
||||
</li>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/capacity-planner"
|
||||
>Capacity Planner</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/stackoverflow">Forum</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="learn-more"></div>
|
||||
</div>
|
||||
|
||||
<div id="Java" class="tab-pane fade">
|
||||
<div class="step1">
|
||||
<div id="java" class="tab-pane fade">
|
||||
<div class="sampleApp">
|
||||
<div class="numbersize numbersizePadding">1</div>
|
||||
<div class="numberheading">
|
||||
Open and run a sample Java app
|
||||
Create a new Java app
|
||||
<p>
|
||||
We created a sample Java app connected to your Azure Cosmos DB Emulator instance. Download, extract,
|
||||
build and run the app.
|
||||
</p>
|
||||
<a href="quickstart/DocumentDB-Quickstart-Java.zip"><button class="btncreatecoll">Download</button></a>
|
||||
<p>
|
||||
Follow instructions in the readme.md to setup prerequisites needed to run Java web apps, if you
|
||||
haven’t already.
|
||||
Follow this
|
||||
<a href="https://learn.microsoft.com/azure/cosmos-db/nosql/quickstart-java" target="_blank"
|
||||
>tutorial
|
||||
</a>
|
||||
to create a new Java app connected to Azure Cosmos DB.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="step1">
|
||||
<div class="numbersize">2</div>
|
||||
<div class="numberheading">
|
||||
Learn more about Azure Cosmos DB.
|
||||
<ul>
|
||||
<!--<li><a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/samples/java">Code Samples</a></li>-->
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/docs">Documentation</a>
|
||||
</li>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/pricing">Pricing</a>
|
||||
</li>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/capacity-planner"
|
||||
>Capacity Planner</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/stackoverflow">Forum</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="learn-more"></div>
|
||||
</div>
|
||||
|
||||
<div id="NodeJs" class="tab-pane fade">
|
||||
<div class="step1">
|
||||
<div id="nodejs" class="tab-pane fade">
|
||||
<div class="sampleApp">
|
||||
<div class="numbersize numbersizePadding">1</div>
|
||||
<div class="numberheading">
|
||||
Open and run a sample Node.js app
|
||||
Create a new Node.js app
|
||||
<p>
|
||||
We created a sample Node.js app connected to your Azure Cosmos DB Emulator instance. Download,
|
||||
extract, build and run the app.
|
||||
</p>
|
||||
<a href="quickstart/DocumentDB-Quickstart-NodeJs.zip"
|
||||
><button class="btncreatecoll">Download</button></a
|
||||
>
|
||||
<p>
|
||||
Run <strong>npm install</strong> and <strong>npm start</strong>, and navigate to
|
||||
<a href="http://localhost:3000" _targe="blank">http://localhost:3000</a>.
|
||||
Follow this
|
||||
<a
|
||||
href="https://learn.microsoft.com/azure/cosmos-db/nosql/quickstart-nodejs?pivots=programming-language-ts"
|
||||
target="_blank"
|
||||
>tutorial
|
||||
</a>
|
||||
to create a new Node.js app connected to Azure Cosmos DB.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="step1">
|
||||
<div class="numbersize">2</div>
|
||||
<div class="numberheading">
|
||||
Learn more about Azure Cosmos DB.
|
||||
<ul>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/samples/nodejs"
|
||||
>Code Samples</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/docs">Documentation</a>
|
||||
</li>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/pricing">Pricing</a>
|
||||
</li>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/capacity-planner"
|
||||
>Capacity Planner</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/stackoverflow">Forum</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="learn-more"></div>
|
||||
</div>
|
||||
|
||||
<div id="Python" class="tab-pane fade">
|
||||
<div class="pythonApp">
|
||||
<div id="python" class="tab-pane fade">
|
||||
<div class="sampleApp">
|
||||
<div class="numbersize numbersizePadding">1</div>
|
||||
<div class="numberheading">
|
||||
Create a new Python app.
|
||||
Create a new Python app
|
||||
<p>
|
||||
Follow this
|
||||
<a href="https://aka.ms/cosmos-db-emulator/tutorial/python" target="_blank">tutorial</a>
|
||||
@ -257,42 +135,73 @@
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="learn-more"></div>
|
||||
</div>
|
||||
|
||||
<div class="pythonApp">
|
||||
<div class="numbersize">2</div>
|
||||
<div id="go" class="tab-pane fade">
|
||||
<div class="sampleApp">
|
||||
<div class="numbersize numbersizePadding">1</div>
|
||||
<div class="numberheading">
|
||||
Learn more about Azure Cosmos DB.
|
||||
<ul>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/samples/python"
|
||||
>Code Samples</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/docs">Documentation</a>
|
||||
</li>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/pricing">Pricing</a>
|
||||
</li>
|
||||
<li>
|
||||
<a target="_blank" class="atags" href="https://aka.ms/cosmos-db-emulator/capacity-planner"
|
||||
>Capacity planner</a
|
||||
>
|
||||
</li>
|
||||
<li>
|
||||
<a
|
||||
target="_blank"
|
||||
class="atags"
|
||||
href="https://social.msdn.microsoft.com/forums/azure/home?forum=AzureDocumentDB"
|
||||
>Forum</a
|
||||
>
|
||||
</li>
|
||||
</ul>
|
||||
Create a new Go app
|
||||
<p>
|
||||
Follow this
|
||||
<a href="https://learn.microsoft.com/azure/cosmos-db/nosql/quickstart-go" target="_blank">tutorial</a>
|
||||
to create a new Go app connected to Azure Cosmos DB.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="learn-more"></div>
|
||||
</div>
|
||||
|
||||
<div id="springboot" class="tab-pane fade">
|
||||
<div class="sampleApp">
|
||||
<div class="numbersize numbersizePadding">1</div>
|
||||
<div class="numberheading">
|
||||
Create a new Spring Boot app
|
||||
<p>
|
||||
Follow this
|
||||
<a
|
||||
href="https://learn.microsoft.com/azure/cosmos-db/nosql/tutorial-springboot-azure-kubernetes-service"
|
||||
target="_blank"
|
||||
>tutorial</a
|
||||
>
|
||||
to create a new Spring Boot app connected to Azure Cosmos DB.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="learn-more"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<template id="learnMoreTpl">
|
||||
<div class="app-block">
|
||||
<div class="numbersize">2</div>
|
||||
<div class="numberheading">
|
||||
Learn more about Azure Cosmos DB
|
||||
<ul>
|
||||
<li>
|
||||
<a href="https://azurecosmosdb.github.io/gallery/?tags=example" target="_blank" class="atags"
|
||||
>Code Samples</a
|
||||
>
|
||||
</li>
|
||||
<li><a href="https://aka.ms/cosmos-db-emulator/docs" target="_blank" class="atags">Documentation</a></li>
|
||||
<li><a href="https://aka.ms/cosmos-db-emulator/pricing" target="_blank" class="atags">Pricing</a></li>
|
||||
<li>
|
||||
<a href="https://cosmos.azure.com/capacitycalculator/" target="_blank" class="atags">Capacity planner</a>
|
||||
</li>
|
||||
<li><a href="https://aka.ms/cosmos-db-emulator/stackoverflow" target="_blank" class="atags">Forum</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
document.querySelectorAll(".learn-more").forEach((slot) => {
|
||||
const node = document.getElementById("learnMoreTpl").content.cloneNode(true);
|
||||
slot.appendChild(node);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
23
test/CORSBypass.ts
Normal file
23
test/CORSBypass.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { Page } from "@playwright/test";
|
||||
|
||||
export async function setupCORSBypass(page: Page) {
|
||||
await page.route("**/api/mongo/explorer{,/**}", async (route) => {
|
||||
const response = await route.fetch({
|
||||
headers: {
|
||||
...route.request().headers(),
|
||||
},
|
||||
});
|
||||
|
||||
await route.fulfill({
|
||||
status: response.status(),
|
||||
headers: {
|
||||
...response.headers(),
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
"Access-Control-Allow-Methods": "*",
|
||||
"Access-Control-Allow-Headers": "*",
|
||||
"Access-Control-Allow-Credentials": "*",
|
||||
},
|
||||
body: await response.body(),
|
||||
});
|
||||
});
|
||||
}
|
16
test/fx.ts
16
test/fx.ts
@ -1,4 +1,4 @@
|
||||
import { AzureCliCredential } from "@azure/identity";
|
||||
import { DefaultAzureCredential } from "@azure/identity";
|
||||
import { Frame, Locator, Page, expect } from "@playwright/test";
|
||||
import crypto from "crypto";
|
||||
|
||||
@ -20,8 +20,8 @@ export function generateUniqueName(baseName, options?: TestNameOptions): string
|
||||
return `${prefix}${baseName}${crypto.randomBytes(length).toString("hex")}${suffix}`;
|
||||
}
|
||||
|
||||
export function getAzureCLICredentials(): AzureCliCredential {
|
||||
return new AzureCliCredential();
|
||||
export function getAzureCLICredentials(): DefaultAzureCredential {
|
||||
return new DefaultAzureCredential();
|
||||
}
|
||||
|
||||
export async function getAzureCLICredentialsToken(): Promise<string> {
|
||||
@ -223,6 +223,9 @@ export class DocumentsTab {
|
||||
documentsListPane: Locator;
|
||||
documentResultsPane: Locator;
|
||||
resultsEditor: Editor;
|
||||
loadMoreButton: Locator;
|
||||
filterInput: Locator;
|
||||
filterButton: Locator;
|
||||
|
||||
constructor(
|
||||
public frame: Frame,
|
||||
@ -234,6 +237,13 @@ export class DocumentsTab {
|
||||
this.documentsListPane = this.locator.getByTestId("DocumentsTab/DocumentsPane");
|
||||
this.documentResultsPane = this.locator.getByTestId("DocumentsTab/ResultsPane");
|
||||
this.resultsEditor = new Editor(this.frame, this.documentResultsPane.getByTestId("EditorReact/Host/Loaded"));
|
||||
this.loadMoreButton = this.documentsListPane.getByTestId("DocumentsTab/LoadMore");
|
||||
this.filterInput = this.documentsFilter.getByTestId("DocumentsTab/FilterInput");
|
||||
this.filterButton = this.documentsFilter.getByTestId("DocumentsTab/ApplyFilter");
|
||||
}
|
||||
|
||||
async setFilter(text: string) {
|
||||
await this.filterInput.fill(text);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
|
||||
import { setupCORSBypass } from "../CORSBypass";
|
||||
import { DataExplorer, DocumentsTab, TestAccount } from "../fx";
|
||||
import { retry, serializeMongoToJson, setPartitionKeys } from "../testData";
|
||||
import { documentTestCases } from "./testCases";
|
||||
@ -9,7 +10,9 @@ let documentsTab: DocumentsTab = null!;
|
||||
|
||||
for (const { name, databaseId, containerId, documents } of documentTestCases) {
|
||||
test.describe(`Test MongoRU Documents with ${name}`, () => {
|
||||
// test.skip(true, "Temporarily disabling all tests in this spec file");
|
||||
test.beforeEach("Open documents tab", async ({ page }) => {
|
||||
await setupCORSBypass(page);
|
||||
explorer = await DataExplorer.open(page, TestAccount.MongoReadonly);
|
||||
|
||||
const containerNode = await explorer.waitForContainerNode(databaseId, containerId);
|
||||
@ -24,6 +27,9 @@ for (const { name, databaseId, containerId, documents } of documentTestCases) {
|
||||
await documentsTab.documentsListPane.waitFor();
|
||||
await expect(documentsTab.resultsEditor.locator).toBeAttached({ timeout: 60 * 1000 });
|
||||
});
|
||||
test.afterEach(async ({ page }) => {
|
||||
await page.unrouteAll({ behavior: "ignoreErrors" });
|
||||
});
|
||||
|
||||
for (const document of documents) {
|
||||
const { documentId: docId, partitionKeys } = document;
|
||||
@ -67,8 +73,12 @@ for (const { name, databaseId, containerId, documents } of documentTestCases) {
|
||||
await documentsTab.resultsEditor.setText(JSON.stringify(newDocument));
|
||||
const saveButton = await explorer.waitForCommandBarButton("Save", 5000);
|
||||
await saveButton.click({ timeout: 5000 });
|
||||
await expect(saveButton).toBeHidden({ timeout: 5000 });
|
||||
}, 3);
|
||||
|
||||
await documentsTab.setFilter(`{_id: "${newDocumentId}"}`);
|
||||
await documentsTab.filterButton.click();
|
||||
|
||||
const newSpan = documentsTab.documentsListPane.getByText(newDocumentId, { exact: true }).nth(0);
|
||||
await newSpan.waitFor();
|
||||
await newSpan.click();
|
||||
|
@ -9,6 +9,7 @@ let documentsTab: DocumentsTab = null!;
|
||||
|
||||
for (const { name, databaseId, containerId, documents } of documentTestCases) {
|
||||
test.describe(`Test SQL Documents with ${name}`, () => {
|
||||
// test.skip(true, "Temporarily disabling all tests in this spec file");
|
||||
test.beforeEach("Open documents tab", async ({ page }) => {
|
||||
explorer = await DataExplorer.open(page, TestAccount.SQLReadOnly);
|
||||
|
||||
@ -26,7 +27,7 @@ for (const { name, databaseId, containerId, documents } of documentTestCases) {
|
||||
});
|
||||
|
||||
for (const document of documents) {
|
||||
const { documentId: docId, partitionKeys } = document;
|
||||
const { documentId: docId, partitionKeys, skipCreateDelete } = document;
|
||||
test.describe(`Document ID: ${docId}`, () => {
|
||||
test(`should load and view document ${docId}`, async () => {
|
||||
const span = documentsTab.documentsListPane.getByText(docId, { exact: true }).nth(0);
|
||||
@ -41,7 +42,9 @@ for (const { name, databaseId, containerId, documents } of documentTestCases) {
|
||||
expect(resultText).not.toBeNull();
|
||||
expect(resultData?.id).toEqual(docId);
|
||||
});
|
||||
test(`should be able to create and delete new document from ${docId}`, async ({ page }) => {
|
||||
|
||||
const testOrSkip = skipCreateDelete ? test.skip : test;
|
||||
testOrSkip(`should be able to create and delete new document from ${docId}`, async ({ page }) => {
|
||||
const span = documentsTab.documentsListPane.getByText(docId, { exact: true }).nth(0);
|
||||
await span.waitFor();
|
||||
await expect(span).toBeVisible();
|
||||
@ -50,10 +53,6 @@ for (const { name, databaseId, containerId, documents } of documentTestCases) {
|
||||
let newDocumentId;
|
||||
await page.waitForTimeout(5000);
|
||||
await retry(async () => {
|
||||
// const discardButton = await explorer.waitForCommandBarButton("Discard", 5000);
|
||||
// if (await discardButton.isEnabled()) {
|
||||
// await discardButton.click();
|
||||
// }
|
||||
const newDocumentButton = await explorer.waitForCommandBarButton("New Item", 5000);
|
||||
await expect(newDocumentButton).toBeVisible();
|
||||
await expect(newDocumentButton).toBeEnabled();
|
||||
@ -71,10 +70,15 @@ for (const { name, databaseId, containerId, documents } of documentTestCases) {
|
||||
await documentsTab.resultsEditor.setText(JSON.stringify(newDocument));
|
||||
const saveButton = await explorer.waitForCommandBarButton("Save", 5000);
|
||||
await saveButton.click({ timeout: 5000 });
|
||||
await expect(saveButton).toBeHidden({ timeout: 5000 });
|
||||
}, 3);
|
||||
|
||||
await documentsTab.setFilter(`WHERE c.id = "${newDocumentId}"`);
|
||||
await documentsTab.filterButton.click();
|
||||
|
||||
const newSpan = documentsTab.documentsListPane.getByText(newDocumentId, { exact: true }).nth(0);
|
||||
await newSpan.waitFor();
|
||||
|
||||
await newSpan.click();
|
||||
await expect(documentsTab.resultsEditor.locator).toBeAttached({ timeout: 60 * 1000 });
|
||||
|
||||
|
@ -5,7 +5,24 @@ export const documentTestCases: DocumentTestCase[] = [
|
||||
name: "System Partition Key",
|
||||
databaseId: "e2etests-sql-readonly",
|
||||
containerId: "systemPartitionKey",
|
||||
documents: [{ documentId: "systempartition", partitionKeys: [] }],
|
||||
documents: [
|
||||
{
|
||||
documentId: "systempartition",
|
||||
partitionKeys: [{ key: "/_partitionKey", value: "partitionKey" }],
|
||||
skipCreateDelete: true,
|
||||
},
|
||||
{
|
||||
documentId: "systempartition_empty",
|
||||
partitionKeys: [{ key: "/_partitionKey", value: "" }],
|
||||
skipCreateDelete: true,
|
||||
},
|
||||
{
|
||||
documentId: "systempartition_null",
|
||||
partitionKeys: [{ key: "/_partitionKey", value: null }],
|
||||
skipCreateDelete: true,
|
||||
},
|
||||
{ documentId: "systempartition_missing", partitionKeys: [] },
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Single Partition Key",
|
||||
|
@ -1,13 +1,16 @@
|
||||
import crypto from "crypto";
|
||||
|
||||
import { CosmosDBManagementClient } from "@azure/arm-cosmosdb";
|
||||
import { BulkOperationType, Container, CosmosClient, Database, JSONObject } from "@azure/cosmos";
|
||||
import crypto from "crypto";
|
||||
import { AzureIdentityCredentialAdapter } from "@azure/ms-rest-js";
|
||||
|
||||
import {
|
||||
TestAccount,
|
||||
generateUniqueName,
|
||||
getAccountName,
|
||||
getAzureCLICredentials,
|
||||
resourceGroupName,
|
||||
subscriptionId,
|
||||
TestAccount,
|
||||
} from "./fx";
|
||||
|
||||
export interface TestItem {
|
||||
@ -26,6 +29,7 @@ export interface DocumentTestCase {
|
||||
export interface TestDocument {
|
||||
documentId: string;
|
||||
partitionKeys?: PartitionKey[];
|
||||
skipCreateDelete?: boolean;
|
||||
}
|
||||
|
||||
export interface PartitionKey {
|
||||
@ -74,7 +78,8 @@ export async function createTestSQLContainer(includeTestData?: boolean) {
|
||||
const databaseId = generateUniqueName("db");
|
||||
const containerId = "testcontainer"; // A unique container name isn't needed because the database is unique
|
||||
const credentials = getAzureCLICredentials();
|
||||
const armClient = new CosmosDBManagementClient(credentials, subscriptionId);
|
||||
const adaptedCredentials = new AzureIdentityCredentialAdapter(credentials);
|
||||
const armClient = new CosmosDBManagementClient(adaptedCredentials, subscriptionId);
|
||||
const accountName = getAccountName(TestAccount.SQL);
|
||||
const account = await armClient.databaseAccounts.get(resourceGroupName, accountName);
|
||||
const keys = await armClient.databaseAccounts.listKeys(resourceGroupName, accountName);
|
||||
|
Loading…
x
Reference in New Issue
Block a user