Skip to content

Commit 9fcb67c

Browse files
authored
Merge pull request #6939 from MSSedusch/preview
fix AEM cmdlets for other environments e.g. Azure China
2 parents e11a067 + ad6cb1b commit 9fcb67c

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

src/ResourceManager/Compute/Commands.Compute/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
-->
2121
## Current Release
2222
* Fixed issue with default resource groups not being set.
23+
* Fix AEM Extension cmdlets for other environments, for example Azure China
2324

2425
## Version 5.5.0
2526
* Updated to the latest version of the Azure ClientRuntime.

src/ResourceManager/Compute/Commands.Compute/Extension/AEM/AEMHelper.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,18 @@ internal class AEMHelper
4646
private Dictionary<string, string> _StorageKeyCache = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase);
4747
private StorageManagementClient _StorageClient;
4848
private IAzureSubscription _Subscription;
49+
private string _StorageEndpoint;
4950

5051
public AEMHelper(Action<ErrorRecord> errorAction, Action<string> verboseAction, Action<string> warningAction,
51-
PSHostUserInterface ui, StorageManagementClient storageClient, IAzureSubscription subscription)
52+
PSHostUserInterface ui, StorageManagementClient storageClient, IAzureSubscription subscription, String storageEndpoint)
5253
{
5354
this._ErrorAction = errorAction;
5455
this._VerboseAction = verboseAction;
5556
this._WarningAction = warningAction;
5657
this._UI = ui;
5758
this._StorageClient = storageClient;
5859
this._Subscription = subscription;
60+
this._StorageEndpoint = storageEndpoint;
5961
}
6062

6163
internal string GetStorageAccountFromUri(string uri)
@@ -140,7 +142,7 @@ internal bool IsPremiumStorageAccount(string accountName)
140142
StorageCredentialsFactory storageCredentialsFactory = new StorageCredentialsFactory(resGroupName,
141143
this._StorageClient, this._Subscription);
142144
StorageCredentials sc = storageCredentialsFactory.Create(blobUri);
143-
CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(sc, true);
145+
CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(sc, this._StorageEndpoint, true);
144146
CloudBlobClient blobClient = cloudStorageAccount.CreateCloudBlobClient();
145147
CloudBlobContainer blobContainer = blobClient.GetContainerReference(blobUri.BlobContainerName);
146148
var cloudBlob = blobContainer.GetPageBlobReference(blobUri.BlobName);
@@ -729,7 +731,7 @@ internal ServiceProperties GetStorageAnalytics(string storageAccountName)
729731
{
730732
var key = this.GetAzureStorageKeyFromCache(storageAccountName);
731733
var credentials = new StorageCredentials(storageAccountName, key);
732-
var cloudStorageAccount = new CloudStorageAccount(credentials, true);
734+
var cloudStorageAccount = new CloudStorageAccount(credentials, this._StorageEndpoint, true);
733735
return cloudStorageAccount.CreateCloudBlobClient().GetServicePropertiesAsync().ConfigureAwait(false).GetAwaiter().GetResult();
734736
}
735737

src/ResourceManager/Compute/Commands.Compute/Extension/AEM/RemoveAzureRmVMAEMExtension.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ public override void ExecuteCmdlet()
7474
this._Helper = new AEMHelper((err) => this.WriteError(err), (msg) => this.WriteVerbose(msg), (msg) => this.WriteWarning(msg),
7575
this.CommandRuntime.Host.UI,
7676
AzureSession.Instance.ClientFactory.CreateArmClient<StorageManagementClient>(DefaultProfile.DefaultContext, AzureEnvironment.Endpoint.ResourceManager),
77-
this.DefaultContext.Subscription);
77+
this.DefaultContext.Subscription,
78+
this.DefaultContext.Environment.GetEndpoint(AzureEnvironment.Endpoint.StorageEndpointSuffix));
7879

7980
base.ExecuteCmdlet();
8081

src/ResourceManager/Compute/Commands.Compute/Extension/AEM/SetAzureRmVMAEMExtension.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace Microsoft.Azure.Commands.Compute
3838
[OutputType(typeof(PSAzureOperationResponse))]
3939
public class SetAzureRmVMAEMExtension : VirtualMachineExtensionBaseCmdlet
4040
{
41+
private string _StorageEndpoint;
4142
private AEMHelper _Helper = null;
4243

4344
[Parameter(
@@ -91,8 +92,13 @@ public SetAzureRmVMAEMExtension()
9192

9293
public override void ExecuteCmdlet()
9394
{
95+
this._StorageEndpoint = this.DefaultContext.Environment.GetEndpoint(AzureEnvironment.Endpoint.StorageEndpointSuffix);
9496
this._Helper = new AEMHelper((err) => this.WriteError(err), (msg) => this.WriteVerbose(msg), (msg) => this.WriteWarning(msg),
95-
this.CommandRuntime.Host.UI, AzureSession.Instance.ClientFactory.CreateArmClient<StorageManagementClient>(DefaultProfile.DefaultContext, AzureEnvironment.Endpoint.ResourceManager), this.DefaultContext.Subscription);
97+
this.CommandRuntime.Host.UI,
98+
AzureSession.Instance.ClientFactory.CreateArmClient<StorageManagementClient>(
99+
DefaultProfile.DefaultContext, AzureEnvironment.Endpoint.ResourceManager),
100+
this.DefaultContext.Subscription,
101+
this._StorageEndpoint);
96102

97103
base.ExecuteCmdlet();
98104

@@ -521,7 +527,7 @@ private void SetStorageAnalytics(string storageAccountName)
521527

522528
var key = this._Helper.GetAzureStorageKeyFromCache(storageAccountName);
523529
var credentials = new StorageCredentials(storageAccountName, key);
524-
var cloudStorageAccount = new CloudStorageAccount(credentials, true);
530+
var cloudStorageAccount = new CloudStorageAccount(credentials, this._StorageEndpoint, true);
525531

526532
cloudStorageAccount.CreateCloudBlobClient().SetServicePropertiesAsync(props)
527533
.ConfigureAwait(false).GetAwaiter().GetResult();

src/ResourceManager/Compute/Commands.Compute/Extension/AEM/TestAzureRmVMAEMExtension.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ public override void ExecuteCmdlet()
8989
this._Helper = new AEMHelper((err) => this.WriteError(err), (msg) => this.WriteVerbose(msg), (msg) => this.WriteWarning(msg),
9090
this.CommandRuntime.Host.UI,
9191
AzureSession.Instance.ClientFactory.CreateArmClient<StorageManagementClient>(DefaultProfile.DefaultContext, AzureEnvironment.Endpoint.ResourceManager),
92-
this.DefaultContext.Subscription);
92+
this.DefaultContext.Subscription,
93+
this.DefaultContext.Environment.GetEndpoint(AzureEnvironment.Endpoint.StorageEndpointSuffix));
9394

9495
this._Helper.WriteVerbose("Starting TestAzureRmVMAEMExtension");
9596

0 commit comments

Comments
 (0)