PlagueHO / CosmosDB

PowerShell Module for working with Azure Cosmos DB databases, collections, documents, attachments, offers, users, permissions, triggers, stored procedures and user defined functions.
http://dscottraynsford.com
MIT License
154 stars 46 forks source link

Default Environment Context 'AzureChinaCloud' #411

Closed brettmillerb closed 3 years ago

brettmillerb commented 3 years ago

I have just downloaded the latest version from the gallery today and when creating a new context the default value that gets assigned to the context is 'AzureChinaCloud'. Even I try overriding by specifying the Environment parameter.

$cosmosAccount = Get-AzCosmosDBAccount -ResourceGroupName $ResourceGroupName
$accountkey = $cosmosAccount | Get-AzCosmosDBAccountKey | Select-Object -ExpandProperty PrimaryMasterKey
$secureAccountKey = ConvertTo-SecureString -String $accountkey -AsPlainText -Force
$cosmosDatabase = $cosmosAccount | Get-AzCosmosDBSqlDatabase

$cosmosDbContext = New-CosmosDbContext -Account $cosmosAccount.Name -Database $cosmosDatabase.name -Key $secureAccountKey -Environment AzureCloud

Result:

Account       : cosmos-dev
Database      : storage
Key           : System.Security.SecureString
KeyType       : master
BaseUri       : https://<baseUri>.documents.azure.com/
Token         : 
BackoffPolicy : 
Environment   : AzureChinaCloud

Environment:

ModuleType Version    PreRelease Name
---------- -------    ---------- ----
Script     4.4.3                 CosmosDB
Name                           Value
----                           -----
PSVersion                      7.1.0-rc.2
PSEdition                      Core
GitCommitId                    7.1.0-rc.2
OS                             Darwin 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

I tried debugging execution but it looks to be setting the value correctly to AzureCloud so not sure how it's ending up as AzureChinaCloud in the returned object.

It hits the Account value in the switch here: https://github.com/PlagueHO/CosmosDB/blob/main/source/Public/utils/New-CosmosDbContext.ps1#L166-L169

Even inside the Get-CosmosDbUri function, $environment is showing AzureCloud image

I can see that there is no Environment being passed into the context object here:

https://github.com/PlagueHO/CosmosDB/blob/main/source/Public/utils/New-CosmosDbContext.ps1#L184-L192

Not sure if that's the cause or not. Will try and debug some more over the weekend to find out. Unfortunately the class object is not visible in the debugger when stepping through the code.

PlagueHO commented 3 years ago

It looks like it's just not setting the value before returning the Context object. Is an easy fix and I'll correct it now. Unit tests should also pick this up in future.

PlagueHO commented 3 years ago

This has been fixed now with PR #416