Наследование: IStorageContextProvider
 public static PSStorageAccount Create(StorageModels.StorageAccount storageAccount, IStorageManagementClient client)
 {
     var result = new PSStorageAccount(storageAccount);
     var credentials = StorageUtilities.GenerateStorageCredentials(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;
 }
        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);
        }
        public static PSStorageAccount Create(StorageModels.StorageAccount storageAccount, IStorageManagementClient client)
        {
            var result = new PSStorageAccount(storageAccount);

            result.Context = new LazyAzureStorageContext((s) =>
            {
                return((new ARMStorageProvider(client)).GetCloudStorageAccount(s, result.ResourceGroupName));
            }, result.StorageAccountName) as AzureStorageContext;

            return(result);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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;
        }
Пример #6
0
        /// <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>
        /// 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();
            }
        }