新 AzureStorageContext:端点与环境

New-AzureStorageContext: Endpoint vs Environment

对于 New-AzureStorageContext cmdlet,假设我知道两者的值,Endpoint 和 Environment 参数之间有什么区别?

例如,假设我想在 Azure 中国云中创建一个名为 foo 的新存储上下文,因此环境为 AzureChinaCloud,端点为 foo.core.chinacloudapi.cn 我可以将其中任何一个作为参数传递给 cmdlet,尽管从 docs 看来它们是互斥的。

传递一个或另一个在功能上有什么不同?如果我通过环境,创建的存储上下文是否没有端点?如果它确实有端点,它不是设置为 foo.core.chinacloudapi.cn 吗?如果我通过端点,上下文不会设置为 AzureChinaCloud 吗?甚至可以没有一个吗?

此外,返回的 AzureStorageContext 具有许多与端点相关的属性:BlobEndPointEndPointSuffixFileEndPointQueueEndPointTableEndPoint。传递环境或端点时应设置以下哪些属性?

what are the differences between the Endpoint and Environment parameters?

Endpoint:包含存储账户名和Azure环境,如果AzureCloud则为storagename.core.windows.net,如果AzureChinaCloud则为storagename.core.chinacloudapi.cn 就像你提到的,它属于 Optional Parameters

Environment:只指定环境,不包含存储帐户名。

If I pass Environment, does the created storage context not have an endpoint? If it does have an endpoint, is it not set to foo.core.chinacloudapi.cn? If I pass the Endpoint, does the context not get set to AzureChinaCloud?

我认为你不需要同时使用它们,如果你传递帐户名和环境,上下文就会有端点,同样,如果你传递端点,它就会有环境。

Is it even possible not to have one or the other?

当然,您可以使用其他参数来创建上下文,例如您可以只使用 StorageAccountNameStorageAccountKey 来创建上下文,您可以在您提到的文档中找到它。

Which of these properties should be set when passing either Environment or Endpoint?

这四个属性都是由端点决定的,如果你通过端点,我觉得你不需要设置它们。例如如果端点是 storagename.core.windows.netBlobEndPoint 将是 storagename.blob.core.windows.net

更新:

what are the differences between the Endpoint and Environment parameters?

不同的环境决定不同的端点,可以通过命令Get-AzureRmEnvironment查看。如果AzureCloud,它将是core.windows.net,如果AzureChinaCloud,它将是core.chinacloudapi.cn

AzureCloud:

蔚蓝中国云:

If I pass Environment, does the created storage context not have an endpoint? If it does have an endpoint, is it not set to foo.core.chinacloudapi.cn? If I pass the Endpoint, does the context not get set to AzureChinaCloud?

你可以只使用其中一个,参考截图,注意:实际上Endpoint意味着EndPointSuffix,你可以在我的测试结果。所以我们应该通过例如-Endpoint "core.windows.net" 而不是 -Endpoint "storagename.core.windows.net"。如果我们传递 -Endpoint "storagename.core.windows.net",它将不正确,结果中的 EndPointSuffix 将是 storagename.core.windows.net

不正确的结果:

Which of these properties should be set when passing either Environment or Endpoint?

在上面的截图中,我没有传递这四个端点中的任何一个,但你会发现结果将包含所有这些端点。你也不需要传递 EndPointSuffix,它等于 EndPoint.