Ejemplo n.º 1
0
 public string[] GetStorageAccountKeys(string name)
 {
     var keys = new GetStorageAccountKeysCommand(name)
     {
         SubscriptionId = SubscriptionId,
         Certificate = ManagementCertificate
     };
     keys.Execute();
     return new string[2] {keys.PrimaryStorageKey, keys.SecondaryStorageKey};
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Used to create a storage account
        /// </summary>
        private bool CreateStorageAccount()
        {
            // Check to see whether the storage account details have been populated correctly
            if (Manager.StorageAccountDescription == null || Manager.StorageAccountLocation == null)
            {
                Manager.WriteComplete(EventPoint.ExceptionOccurrence, "Description or location not specified");
                return false;
            }

            try
            {
                // issue the create storage account command
                var create = new CreateStorageAccountCommand(Manager.StorageAccountName,
                                                             Manager.StorageAccountDescription,
                                                             Manager.StorageAccountLocation)
                                 {
                                     SubscriptionId = Manager.SubscriptionId,
                                     Certificate = Manager.ManagementCertificate
                                 };
                create.Execute();
                Manager.WriteComplete(EventPoint.StorageAccountCreated,
                                      "Storage account " + Manager.StorageAccountName + " created");
                // get the storage account keys
                var keys = new GetStorageAccountKeysCommand(Manager.StorageAccountName)
                               {
                                   SubscriptionId = Manager.SubscriptionId,
                                   Certificate = Manager.ManagementCertificate
                               };
                keys.Execute();
                Manager.WriteComplete(EventPoint.StorageKeyRequestSuccess, "Keys returned from storage request");
                // populate the primary and secondary keys
                Manager.StorageAccountPrimaryKey = keys.PrimaryStorageKey;
                Manager.StorageAccountSecondaryKey = keys.SecondaryStorageKey;
            }
            catch (Exception exception)
            {
                // rollback the operation if it failed
                Manager.WriteComplete(EventPoint.ExceptionOccurrence, exception.GetType() + ": " + exception.Message);
                return false;
            }
            return true;
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Gets a list of storage accounts from the storage catalog
 /// </summary>
 List<StorageAccount> IStorageActivity.GetStorageAccountList(bool includeKeys)
 {
     var getStorageAccountList = new ListStorageAccountsCommand
                                     {
                                         SubscriptionId = Manager.SubscriptionId,
                                         Certificate = Manager.ManagementCertificate
                                     };
     getStorageAccountList.Execute();
     if(!includeKeys)
         return getStorageAccountList.StorageAccounts;
     // if the get keys flag is supplied then ensure that this returns the keys with the structure
     foreach (var storageAccount in getStorageAccountList.StorageAccounts)
     {
         var keys = new GetStorageAccountKeysCommand(storageAccount.Name)
             {
                 SubscriptionId = Manager.SubscriptionId,
                 Certificate = Manager.ManagementCertificate
             };
         keys.Execute();
         storageAccount.PrimaryAccessKey = keys.PrimaryStorageKey;
         storageAccount.SecondaryAccessKey = keys.SecondaryStorageKey;
     }
     return getStorageAccountList.StorageAccounts;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Gets the blob account key
 /// </summary>
 public string GetAccountKey()
 {
     var getStorageAccountKeysCommand = new GetStorageAccountKeysCommand(AccountName)
     {
         SubscriptionId = SubscriptionId,
         Certificate = ManagementCertificate
     };
     getStorageAccountKeysCommand.Execute();
     return (AccountKey = getStorageAccountKeysCommand.PrimaryStorageKey);
 }