public static PSStorageAccount Create(StorageModels.StorageAccount storageAccount, IStorageManagementClient client) { var result = new PSStorageAccount(storageAccount); 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); return(result); }
protected string GetStorageKey() { string storageKey = string.Empty; if (!string.IsNullOrEmpty(StorageAccountName)) { var storageCredentials = StorageUtilities.GenerateStorageCredentials(this.StorageClient, this.ResourceGroupName, this.StorageAccountName); storageKey = storageCredentials.ExportBase64EncodedKey(); } return(storageKey); }
/// <summary> /// Make sure the storage account key is set. /// If user doesn't specify it in command line, we try to resolve the key for the user given the storage account. /// </summary> /// <param name="storageAccount">The storage account to list the key.</param> private void InitializeStorageAccountKey(StorageAccount storageAccount) { if (string.IsNullOrEmpty(this.StorageAccountKey)) { if (storageAccount == null) { throw new Exception(string.Format(CultureInfo.InvariantCulture, Properties.Resources.DiagnosticsExtensionFailedToListKeyForNoStorageAccount, this.StorageAccountName)); } var psStorageAccount = new PSStorageAccount(storageAccount); var credentials = StorageUtilities.GenerateStorageCredentials(this.StorageClient, psStorageAccount.ResourceGroupName, psStorageAccount.StorageAccountName); this.StorageAccountKey = credentials.ExportBase64EncodedKey(); } }
public static PSStorageAccount Create(StorageModels.StorageAccount storageAccount, IStorageManagementClient client) { var result = new PSStorageAccount(storageAccount); result.Context = new LazyAzureStorageContext((s) => { var credentials = StorageUtilities.GenerateStorageCredentials(new ARMStorageProvider(client), result.ResourceGroupName, s); return(new CloudStorageAccount(credentials, ARMStorageService.GetUri(storageAccount.PrimaryEndpoints.Blob), ARMStorageService.GetUri(storageAccount.PrimaryEndpoints.Queue), ARMStorageService.GetUri(storageAccount.PrimaryEndpoints.Table), ARMStorageService.GetUri(storageAccount.PrimaryEndpoints.File))); }, result.StorageAccountName) as AzureStorageContext; return(result); }
/// <summary> /// Initialize the storage account key if it's not specified. /// It can be defined in multiple places, we only take the one with higher precedence. And the precedence is: /// 1. The one we try to resolve within current subscription /// 2. The one defined in PrivateConfig in the configuration file /// </summary> public static string InitializeStorageAccountKey(IStorageManagementClient storageClient, string storageAccountName = null, string configurationPath = null) { string storageAccountKey = null; StorageAccount storageAccount = null; 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); storageAccountKey = credentials.ExportBase64EncodedKey(); } else { // Use the one defined in PrivateConfig storageAccountKey = GetStorageAccountInfoFromPrivateConfig(configurationPath, PrivConfKeyAttr); } return(storageAccountKey); }
/// <summary> /// Initialize the storage account key if it's not specified. /// It can be defined in multiple places, we only take the one with higher precedence. And the precedence is: /// 1. The one we try to resolve within current subscription /// 2. The one defined in PrivateConfig in the configuration file /// </summary> public static string InitializeStorageAccountKey(IStorageManagementClient storageClient, string storageAccountName = null, string configurationPath = null) { string storageAccountKey = null; StorageAccount storageAccount = null; if (TryGetStorageAccount(storageClient, storageAccountName, out storageAccount)) { // Help user retrieve the storage account key var credentials = StorageUtilities.GenerateStorageCredentials(new ARMStorageProvider(storageClient), ARMStorageService.ParseResourceGroupFromId(storageAccount.Id), storageAccount.Name); storageAccountKey = credentials.ExportBase64EncodedKey(); } else { // Use the one defined in PrivateConfig storageAccountKey = GetConfigValueFromPrivateConfig(configurationPath, StorageAccountElemStr, PrivConfKeyAttr); } return(storageAccountKey); }