Files
cosmos-explorer/src/Explorer/Tabs/CloudShellTab/Utils/RegionUtils.tsx
Sourabh Jain 205355bf55 Shell: Integrate Cloudshell to existing shells (#2098)
* first draft

* refactored code

* ux fix

* add custom header support and fix ui

* minor changes

* hide last command also

* remove logger

* bug fixes

* updated loick file

* fix tests

* moved files

* update readme

* documentation update

* fix compilationerror

* undefined check handle

* format fix

* format fix

* fix lints

* format fix

* fix unrelatred test

* code refator

* fix format

* ut fix

* cgmanifest

* Revert "cgmanifest"

This reverts commit 2e76a6926ee0d3d4e0510f2e04e03446c2ca8c47.

* fix snap

* test fix

* formatting code

* updated xterm

* include username in command

* cloudshell add exit

* fix test

* format fix

* tets fix

* fix multiple open cloudshell calls

* socket time out after 20 min

* remove unused code

* 120 min

* Addressed comments
2025-04-30 13:19:01 -07:00

49 lines
1.8 KiB
TypeScript

// 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;
};