mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-09-19 09:02:41 +01:00
Fix MongoDB 3.6 Cloud Shell compatibility (#2603)
Use the MongoDB 3.6-compatible mongosh package for Mongo server version 3.6 while keeping the newer package for other accounts. This reads serverVersion from account metadata and adds a unit test covering the 3.6 path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -39,6 +39,7 @@ export interface DatabaseAccountBackupPolicy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface DatabaseAccountExtendedProperties {
|
export interface DatabaseAccountExtendedProperties {
|
||||||
|
apiProperties?: DatabaseAccountApiProperties;
|
||||||
documentEndpoint?: string;
|
documentEndpoint?: string;
|
||||||
disableLocalAuth?: boolean;
|
disableLocalAuth?: boolean;
|
||||||
tableEndpoint?: string;
|
tableEndpoint?: string;
|
||||||
@@ -68,6 +69,10 @@ export interface DatabaseAccountExtendedProperties {
|
|||||||
enableAllVersionsAndDeletesChangeFeed?: boolean;
|
enableAllVersionsAndDeletesChangeFeed?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DatabaseAccountApiProperties {
|
||||||
|
serverVersion?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface DatabaseAccountResponseLocation {
|
export interface DatabaseAccountResponseLocation {
|
||||||
documentEndpoint: string;
|
documentEndpoint: string;
|
||||||
failoverPriority: number;
|
failoverPriority: number;
|
||||||
|
|||||||
@@ -26,6 +26,9 @@ export const EXIT_COMMAND_MONGO = ` printf "\\033[1;31mSession ended. Please clo
|
|||||||
*/
|
*/
|
||||||
export const DISABLE_TELEMETRY_COMMAND = `mongosh --nodb --quiet --eval 'disableTelemetry()'`;
|
export const DISABLE_TELEMETRY_COMMAND = `mongosh --nodb --quiet --eval 'disableTelemetry()'`;
|
||||||
|
|
||||||
|
const MONGOSH_PACKAGE_VERSION = "2.5.6";
|
||||||
|
const MONGOSH_36_PACKAGE_VERSION = "1.10.6";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class that defines the interface for shell-specific handlers
|
* Abstract class that defines the interface for shell-specific handlers
|
||||||
* in the CloudShell terminal implementation. Each supported shell type
|
* in the CloudShell terminal implementation. Each supported shell type
|
||||||
@@ -96,14 +99,14 @@ export abstract class AbstractShellHandler {
|
|||||||
* Each command runs conditionally only if mongosh
|
* Each command runs conditionally only if mongosh
|
||||||
* is not already present in the environment.
|
* is not already present in the environment.
|
||||||
*/
|
*/
|
||||||
protected mongoShellSetupCommands(): string[] {
|
protected mongoShellSetupCommands(serverVersion?: string): string[] {
|
||||||
const PACKAGE_VERSION: string = "2.5.6";
|
const packageVersion = serverVersion === "3.6" ? MONGOSH_36_PACKAGE_VERSION : MONGOSH_PACKAGE_VERSION;
|
||||||
return [
|
return [
|
||||||
"if ! command -v mongosh &> /dev/null; then echo '⚠️ mongosh not found. Installing...'; fi",
|
"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 curl -LO https://downloads.mongodb.com/compass/mongosh-${packageVersion}-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 tar -xvzf mongosh-${packageVersion}-linux-x64.tgz; fi`,
|
||||||
`if ! command -v mongosh &> /dev/null; then mkdir -p ~/mongosh/bin && mv mongosh-${PACKAGE_VERSION}-linux-x64/bin/mongosh ~/mongosh/bin/ && chmod +x ~/mongosh/bin/mongosh; fi`,
|
`if ! command -v mongosh &> /dev/null; then mkdir -p ~/mongosh/bin && mv mongosh-${packageVersion}-linux-x64/bin/mongosh ~/mongosh/bin/ && chmod +x ~/mongosh/bin/mongosh; fi`,
|
||||||
`if ! command -v mongosh &> /dev/null; then rm -rf mongosh-${PACKAGE_VERSION}-linux-x64 mongosh-${PACKAGE_VERSION}-linux-x64.tgz; fi`,
|
`if ! command -v mongosh &> /dev/null; then rm -rf mongosh-${packageVersion}-linux-x64 mongosh-${packageVersion}-linux-x64.tgz; fi`,
|
||||||
"if ! command -v mongosh &> /dev/null; then echo 'export PATH=$HOME/mongosh/bin:$PATH' >> ~/.bashrc; fi",
|
"if ! command -v mongosh &> /dev/null; then echo 'export PATH=$HOME/mongosh/bin:$PATH' >> ~/.bashrc; fi",
|
||||||
"if ! command -v mongosh &> /dev/null; then source ~/.bashrc; fi",
|
"if ! command -v mongosh &> /dev/null; then source ~/.bashrc; fi",
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -5,6 +5,9 @@ import { MongoShellHandler } from "./MongoShellHandler";
|
|||||||
// Define interfaces for type safety
|
// Define interfaces for type safety
|
||||||
interface DatabaseAccountProperties {
|
interface DatabaseAccountProperties {
|
||||||
mongoEndpoint?: string;
|
mongoEndpoint?: string;
|
||||||
|
apiProperties?: {
|
||||||
|
serverVersion?: string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DatabaseAccount {
|
interface DatabaseAccount {
|
||||||
@@ -80,6 +83,17 @@ describe("MongoShellHandler", () => {
|
|||||||
expect(commands.length).toBe(7);
|
expect(commands.length).toBe(7);
|
||||||
expect(commands[1]).toContain("mongosh-2.5.6-linux-x64.tgz");
|
expect(commands[1]).toContain("mongosh-2.5.6-linux-x64.tgz");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should download a MongoDB 3.6-compatible package for 3.6 accounts", () => {
|
||||||
|
const properties = (userContext as UserContextType).databaseAccount.properties;
|
||||||
|
const originalApiProperties = properties.apiProperties;
|
||||||
|
properties.apiProperties = { serverVersion: "3.6" };
|
||||||
|
|
||||||
|
const commands = mongoShellHandler.getSetUpCommands();
|
||||||
|
|
||||||
|
expect(commands[1]).toContain("mongosh-1.10.6-linux-x64.tgz");
|
||||||
|
properties.apiProperties = originalApiProperties;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("getConnectionCommand", () => {
|
describe("getConnectionCommand", () => {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export class MongoShellHandler extends AbstractShellHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public getSetUpCommands(): string[] {
|
public getSetUpCommands(): string[] {
|
||||||
return this.mongoShellSetupCommands();
|
return this.mongoShellSetupCommands(userContext.databaseAccount?.properties.apiProperties?.serverVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getConnectionCommand(): string {
|
public getConnectionCommand(): string {
|
||||||
|
|||||||
Reference in New Issue
Block a user