diff --git a/setup/azurecmdfiles.wxi b/setup/azurecmdfiles.wxi index 97c9d5032f27..f0055cc5f0a1 100644 --- a/setup/azurecmdfiles.wxi +++ b/setup/azurecmdfiles.wxi @@ -29,9 +29,6 @@ - - - @@ -163,9 +160,6 @@ - - - @@ -634,9 +628,6 @@ - - - @@ -670,15 +661,6 @@ - - - - - - - - - @@ -3079,9 +3061,6 @@ - - - @@ -3198,9 +3177,6 @@ - - - @@ -3576,9 +3552,6 @@ - - - @@ -3731,9 +3704,6 @@ - - - @@ -4294,9 +4264,6 @@ - - - @@ -4680,9 +4647,6 @@ - - - @@ -5014,7 +4978,6 @@ - @@ -5058,7 +5021,6 @@ - @@ -5211,7 +5173,6 @@ - @@ -5223,9 +5184,6 @@ - - - @@ -6008,7 +5966,6 @@ - @@ -6047,7 +6004,6 @@ - @@ -6171,7 +6127,6 @@ - @@ -6222,7 +6177,6 @@ - @@ -6397,7 +6351,6 @@ - @@ -6515,7 +6468,6 @@ - diff --git a/src/Common/Commands.Common.Storage/Adapters/ARM.Storage.3/ARMStorageProvider.cs b/src/Common/Commands.Common.Storage/Adapters/ARM.Storage.3/ARMStorageProvider.cs new file mode 100644 index 000000000000..5328488c2b66 --- /dev/null +++ b/src/Common/Commands.Common.Storage/Adapters/ARM.Storage.3/ARMStorageProvider.cs @@ -0,0 +1,37 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System.Management.Automation; +using Microsoft.Azure.Management.Storage; +using Microsoft.WindowsAzure.Commands.Common.Storage; + +namespace Microsoft.Azure.Commands.Management.Storage.Models +{ + public class ARMStorageProvider : IStorageServiceProvider + { + IStorageManagementClient _client; + + public ARMStorageProvider(IStorageManagementClient client) + { + _client = client; + } + public IStorageService GetStorageService(string name, string resourceGroupName) + { + var account = _client.StorageAccounts.GetProperties(resourceGroupName, name); + var keys = _client.StorageAccounts.ListKeys(resourceGroupName, name); + return new ARMStorageService(account.StorageAccount, keys.StorageAccountKeys.Key1, + keys.StorageAccountKeys.Key2); + } + } +} diff --git a/src/Common/Commands.Common.Storage/Adapters/ARM.Storage.3/ARMStorageService.cs b/src/Common/Commands.Common.Storage/Adapters/ARM.Storage.3/ARMStorageService.cs new file mode 100644 index 000000000000..d8be5246acb8 --- /dev/null +++ b/src/Common/Commands.Common.Storage/Adapters/ARM.Storage.3/ARMStorageService.cs @@ -0,0 +1,90 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.WindowsAzure.Commands.Common.Storage; + +namespace Microsoft.Azure.Commands.Management.Storage.Models +{ + public class ARMStorageService : IStorageService + { + Azure.Management.Storage.Models.StorageAccount _account; + List _authenticationKeys = new List(); + public ARMStorageService(Azure.Management.Storage.Models.StorageAccount account, + params string[] authenticationKeys) + { + _account = account; + foreach (var key in authenticationKeys) + { + _authenticationKeys.Add(key); + } + } + + public Uri BlobEndpoint + { + get { return _account.PrimaryEndpoints.Blob; } + } + + public Uri FileEndpoint + { + get { return _account.PrimaryEndpoints.File; } + } + + public Uri QueueEndpoint + { + get { return _account.PrimaryEndpoints.Queue; } + } + + public Uri TableEndpoint + { + get { return _account.PrimaryEndpoints.Table; } + } + + public string Name + { + get { return _account.Name; } + } + + public List AuthenticationKeys + { + get { return _authenticationKeys; } + } + + /// + /// Get the resource group name from a storage account resource Id + /// + /// The resource Id for the storage account + /// The resource group containing the storage account + public static string ParseResourceGroupFromId(string resourceId) + { + if (!string.IsNullOrEmpty(resourceId)) + { + string[] tokens = resourceId.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); + if (tokens == null || tokens.Length < 4) + { + throw new ArgumentOutOfRangeException("resourceId"); + } + + return tokens[3]; + } + + return null; + } + + } +} diff --git a/src/Common/Commands.Common.Storage/AzureContextExtensions.cs b/src/Common/Commands.Common.Storage/AzureContextExtensions.cs index bb3604da3d0b..268386c44a44 100644 --- a/src/Common/Commands.Common.Storage/AzureContextExtensions.cs +++ b/src/Common/Commands.Common.Storage/AzureContextExtensions.cs @@ -14,7 +14,6 @@ using Microsoft.Azure.Commands.Common.Authentication.Models; using Microsoft.WindowsAzure.Commands.Common.Storage; -using ArmStorage = Microsoft.Azure.Management.Storage; using SmStorage = Microsoft.WindowsAzure.Management.Storage; using Microsoft.WindowsAzure.Storage; diff --git a/src/Common/Commands.Common.Storage/Commands.Common.Storage.csproj b/src/Common/Commands.Common.Storage/Commands.Common.Storage.csproj index 85b805df9968..8131020b438f 100644 --- a/src/Common/Commands.Common.Storage/Commands.Common.Storage.csproj +++ b/src/Common/Commands.Common.Storage/Commands.Common.Storage.csproj @@ -63,10 +63,6 @@ ..\..\packages\Microsoft.Azure.KeyVault.Core.1.0.0\lib\net40\Microsoft.Azure.KeyVault.Core.dll True - - False - ..\..\packages\Microsoft.Azure.Management.Storage.3.0.0\lib\net40\Microsoft.Azure.Management.Storage.dll - False ..\..\packages\Microsoft.Azure.Management.Resources.2.19.0-preview\lib\net40\Microsoft.Azure.ResourceManager.dll @@ -162,6 +158,8 @@ + + True True diff --git a/src/Common/Commands.Common.Storage/IStorageService.cs b/src/Common/Commands.Common.Storage/IStorageService.cs new file mode 100644 index 000000000000..9f85a3727a30 --- /dev/null +++ b/src/Common/Commands.Common.Storage/IStorageService.cs @@ -0,0 +1,52 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Collections.Generic; + +namespace Microsoft.WindowsAzure.Commands.Common.Storage +{ + public interface IStorageService + { + /// + /// The blob service endpoint + /// + Uri BlobEndpoint { get; } + + /// + /// The file service endpoint + /// + Uri FileEndpoint { get; } + + /// + /// The queue service endpoint + /// + Uri QueueEndpoint { get; } + + /// + /// The table service endpoint + /// + Uri TableEndpoint { get; } + + /// + /// The storage account name + /// + string Name { get;} + + /// + /// Authentication keys for the storage account + /// + List AuthenticationKeys { get; } + } +} diff --git a/src/Common/Commands.Common.Storage/IStorageServiceProvider.cs b/src/Common/Commands.Common.Storage/IStorageServiceProvider.cs new file mode 100644 index 000000000000..d1d626d39210 --- /dev/null +++ b/src/Common/Commands.Common.Storage/IStorageServiceProvider.cs @@ -0,0 +1,27 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Microsoft.WindowsAzure.Commands.Common.Storage +{ + public interface IStorageServiceProvider + { + IStorageService GetStorageService(string name, string resourceGroupName); + } +} diff --git a/src/Common/Commands.Common.Storage/StorageUtilities.cs b/src/Common/Commands.Common.Storage/StorageUtilities.cs index bc28956c0085..dd685fc2b8a4 100644 --- a/src/Common/Commands.Common.Storage/StorageUtilities.cs +++ b/src/Common/Commands.Common.Storage/StorageUtilities.cs @@ -1,19 +1,28 @@ - -using System.CodeDom; -using System.Diagnostics.Eventing.Reader; -using System.Text; -using Microsoft.Azure.Management.Storage; +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- namespace Microsoft.WindowsAzure.Commands.Common.Storage { using System; + using System.Linq; + using System.Text; using Microsoft.WindowsAzure.Commands.Utilities.Common; using Microsoft.WindowsAzure.Management.Storage; using Microsoft.WindowsAzure.Storage; using Microsoft.WindowsAzure.Storage.Auth; using Microsoft.WindowsAzure.Storage.Blob; using Microsoft.WindowsAzure.Storage.Table; - using Arm = Microsoft.Azure.Management.Storage; public class StorageUtilities { @@ -35,27 +44,24 @@ public static Uri CreateHttpsEndpoint(string endpointUri) /// /// Create a cloud storage account using an ARM storage management client /// - /// The client to use to get storage account details. - /// The resource group contining the storage account. + /// The adapter to ARM storage services. + /// The resource group containing the storage account. /// The name of the storage account. /// A CloudStorageAccount that can be used by windows azure storage library to manipulate objects in the storage account. - public static CloudStorageAccount GenerateCloudStorageAccount(Arm.IStorageManagementClient storageClient, + public static CloudStorageAccount GenerateCloudStorageAccount(IStorageServiceProvider provider, string resourceGroupName, string accountName) { if (!TestMockSupport.RunningMocked) { - var storageServiceResponse = storageClient.StorageAccounts.GetProperties(resourceGroupName, accountName); - Uri blobEndpoint = storageServiceResponse.StorageAccount.PrimaryEndpoints.Blob; - Uri queueEndpoint = storageServiceResponse.StorageAccount.PrimaryEndpoints.Queue; - Uri tableEndpoint = storageServiceResponse.StorageAccount.PrimaryEndpoints.Table; - Uri fileEndpoint = storageServiceResponse.StorageAccount.PrimaryEndpoints.File; + var service = provider.GetStorageService(accountName, resourceGroupName); + return new CloudStorageAccount( - GenerateStorageCredentials(storageClient, resourceGroupName, accountName), - blobEndpoint, - queueEndpoint, - tableEndpoint, - fileEndpoint); + new StorageCredentials(service.Name, service.AuthenticationKeys.First()), + service.BlobEndpoint, + service.QueueEndpoint, + service.TableEndpoint, + service.FileEndpoint); } else { @@ -64,7 +70,7 @@ public static CloudStorageAccount GenerateCloudStorageAccount(Arm.IStorageManage Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString()))), new Uri(string.Format("https://{0}.blob.core.windows.net", accountName)), new Uri(string.Format("https://{0}.queue.core.windows.net", accountName)), - new Uri(string.Format("https://{0}.table.core.windows.net", accountName)), + new Uri(string.Format("https://{0}.table.core.windows.net", accountName)), new Uri(string.Format("https://{0}.file.core.windows.net", accountName))); } } @@ -127,23 +133,22 @@ public static CloudStorageAccount GenerateCloudStorageAccount(IStorageManagement new Uri(string.Format("https://{0}.table.core.windows.net", accountName)), new Uri(string.Format("https://{0}.file.core.windows.net", accountName))); } - } + } /// /// Create storage credentials for the given account /// - /// The ARM storage management client. + /// The storage provider for ARM storage services. /// The resource group containing the storage account. /// The storage account name. /// Storage credentials for the given account. - public static StorageCredentials GenerateStorageCredentials(Arm.IStorageManagementClient storageClient, + public static StorageCredentials GenerateStorageCredentials(IStorageServiceProvider provider, string resourceGroupName, string accountName) { if (!TestMockSupport.RunningMocked) { - var storageKeysResponse = storageClient.StorageAccounts.ListKeys(resourceGroupName, accountName); - return new StorageCredentials(accountName, - storageKeysResponse.StorageAccountKeys.Key1); + var service = provider.GetStorageService(accountName, resourceGroupName); + return new StorageCredentials(accountName, service.AuthenticationKeys.First()); } else { @@ -158,8 +163,8 @@ public static StorageCredentials GenerateStorageCredentials(Arm.IStorageManageme /// The RDFE storage management client. /// The storage account name. /// Storage credentials for the given account. - public static StorageCredentials GenerateStorageCredentials(IStorageManagementClient storageClient, - string accountName) + public static StorageCredentials GenerateStorageCredentials(IStorageManagementClient storageClient, + string accountName) { if (!TestMockSupport.RunningMocked) { diff --git a/src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj b/src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj index a1178cb73435..ac72785c84c8 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj +++ b/src/ResourceManager/Compute/Commands.Compute/Commands.Compute.csproj @@ -168,6 +168,12 @@ + + Common\ARMStorageProvider.cs + + + Common\ARMStorageService.cs + Extension\DSC\DscExtensionCmdletConstants.cs @@ -196,6 +202,7 @@ + @@ -370,10 +377,6 @@ {e1f5201d-6067-430e-b303-4e367652991b} Commands.Resources - - {a50ab133-5c04-4a17-9054-f8343683ec23} - Commands.Management.Storage - {2493a8f7-1949-4f29-8d53-9d459046c3b8} Commands.Tags diff --git a/src/ResourceManager/Compute/Commands.Compute/Common/DiagnosticsHelper.cs b/src/ResourceManager/Compute/Commands.Compute/Common/DiagnosticsHelper.cs index e20acf7ff1e6..f395acb58bcd 100644 --- a/src/ResourceManager/Compute/Commands.Compute/Common/DiagnosticsHelper.cs +++ b/src/ResourceManager/Compute/Commands.Compute/Common/DiagnosticsHelper.cs @@ -318,8 +318,8 @@ public static string InitializeStorageAccountKey(IStorageManagementClient storag if (TryGetStorageAccount(storageClient, storageAccountName, out storageAccount)) { // Help user retrieve the storage account key - var psStorageAccount = new PSStorageAccount(storageAccount); - var credentials = StorageUtilities.GenerateStorageCredentials(storageClient, psStorageAccount.ResourceGroupName, psStorageAccount.StorageAccountName); + var credentials = StorageUtilities.GenerateStorageCredentials(new ARMStorageProvider(storageClient), + ARMStorageService.ParseResourceGroupFromId(storageAccount.Id), storageAccount.Name); storageAccountKey = credentials.ExportBase64EncodedKey(); } else diff --git a/src/ResourceManager/Compute/Commands.Compute/Common/StorageManagementClient.cs b/src/ResourceManager/Compute/Commands.Compute/Common/StorageManagementClient.cs new file mode 100644 index 000000000000..3fa53f64e691 --- /dev/null +++ b/src/ResourceManager/Compute/Commands.Compute/Common/StorageManagementClient.cs @@ -0,0 +1,40 @@ +// ---------------------------------------------------------------------------------- +// +// Copyright Microsoft Corporation +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// http://www.apache.org/licenses/LICENSE-2.0 +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ---------------------------------------------------------------------------------- + +using System; +using Microsoft.Azure.Commands.Common.Authentication; +using Microsoft.Azure.Commands.Common.Authentication.Models; +using Microsoft.Azure.Management.Storage; + +namespace Microsoft.Azure.Commands.Management.Storage +{ + public partial class StorageManagementClientWrapper + { + public IStorageManagementClient StorageManagementClient { get; set; } + + public Action VerboseLogger { get; set; } + + public Action ErrorLogger { get; set; } + + public StorageManagementClientWrapper(AzureContext context) + : this(AzureSession.ClientFactory.CreateClient(context, AzureEnvironment.Endpoint.ResourceManager)) + { + } + + public StorageManagementClientWrapper(IStorageManagementClient resourceManagementClient) + { + StorageManagementClient = resourceManagementClient; + } + } +} \ No newline at end of file diff --git a/src/ResourceManager/Storage/Commands.Management.Storage/Commands.Management.Storage.csproj b/src/ResourceManager/Storage/Commands.Management.Storage/Commands.Management.Storage.csproj index 19aaecbf8be3..0f701466637f 100644 --- a/src/ResourceManager/Storage/Commands.Management.Storage/Commands.Management.Storage.csproj +++ b/src/ResourceManager/Storage/Commands.Management.Storage/Commands.Management.Storage.csproj @@ -135,6 +135,12 @@ + + Models\ARMStorageProvider.cs + + + Models\ARMStorageService.cs + diff --git a/src/ResourceManager/Storage/Commands.Management.Storage/Models/PSStorageAccount.cs b/src/ResourceManager/Storage/Commands.Management.Storage/Models/PSStorageAccount.cs index e3c9c1b08559..2b9340d4438f 100644 --- a/src/ResourceManager/Storage/Commands.Management.Storage/Models/PSStorageAccount.cs +++ b/src/ResourceManager/Storage/Commands.Management.Storage/Models/PSStorageAccount.cs @@ -79,7 +79,7 @@ public PSStorageAccount(StorageModels.StorageAccount storageAccount) public static PSStorageAccount Create(StorageModels.StorageAccount storageAccount, IStorageManagementClient client) { var result = new PSStorageAccount(storageAccount); - var credentials = StorageUtilities.GenerateStorageCredentials(client, result.ResourceGroupName, result.StorageAccountName); + var credentials = StorageUtilities.GenerateStorageCredentials(new ARMStorageProvider(client), result.ResourceGroupName, result.StorageAccountName); CloudStorageAccount account = new CloudStorageAccount(credentials, storageAccount.PrimaryEndpoints.Blob, storageAccount.PrimaryEndpoints.Queue, storageAccount.PrimaryEndpoints.Table, null); result.Context = new AzureStorageContext(account); diff --git a/src/ResourceManager/Storage/Commands.Management.Storage/StorageAccount/SetAzureRmCurrentStorageAccount.cs b/src/ResourceManager/Storage/Commands.Management.Storage/StorageAccount/SetAzureRmCurrentStorageAccount.cs index 0911ff6c8fb1..7dde7bf5de46 100644 --- a/src/ResourceManager/Storage/Commands.Management.Storage/StorageAccount/SetAzureRmCurrentStorageAccount.cs +++ b/src/ResourceManager/Storage/Commands.Management.Storage/StorageAccount/SetAzureRmCurrentStorageAccount.cs @@ -13,6 +13,7 @@ // ---------------------------------------------------------------------------------- using System.Management.Automation; +using Microsoft.Azure.Commands.Management.Storage.Models; using Microsoft.WindowsAzure.Commands.Common; using Microsoft.WindowsAzure.Commands.Common.Storage; using Microsoft.WindowsAzure.Commands.Utilities.Common; @@ -51,7 +52,7 @@ public override void ExecuteCmdlet() } else { - account = StorageUtilities.GenerateCloudStorageAccount(StorageClient, ResourceGroupName, StorageAccountName); + account = StorageUtilities.GenerateCloudStorageAccount(new ARMStorageProvider(StorageClient), ResourceGroupName, StorageAccountName); } // Clear the current storage account for both SM and RM