public string ExportToStorageAccount(string account, string container, string folder)
        {
            if (String.IsNullOrEmpty(SubscriptionId) && ManagementCertificate == null)
            {
                throw new FluentManagementException("please provide a subscription id and management certificate to continue", "CertificateGenerator");
            }

            var client      = new StorageClient(SubscriptionId, ManagementCertificate);
            var storageKeys = client.GetStorageAccountKeys(account);
            var key         = storageKeys[0];

            var credentials   = new CloudStorageAccount(new StorageCredentials(account, key), true);
            var blobClient    = credentials.CreateCloudBlobClient();
            var blobContainer = blobClient.GetContainerReference(container);

            blobContainer.CreateIfNotExists();

            var pemBlob = blobContainer.GetBlockBlobReference(String.Format("{0}/{1}.{2}.pem", folder, DerEncodedCertificate.Thumbprint, DateTime.UtcNow.ToString("ddMMyyyy")));

            pemBlob.UploadText(GetPemData());

            var pfxBlob = blobContainer.GetBlockBlobReference(String.Format("{0}/{1}.{2}.pfx", folder, DerEncodedCertificate.Thumbprint, DateTime.UtcNow.ToString("ddMMyyyy")));

            pfxBlob.UploadFromByteArray(GetPfxData(), 0, GetPfxData().Count());

            var cerBlob = blobContainer.GetBlockBlobReference(String.Format("{0}/{1}.{2}.cer", folder, DerEncodedCertificate.Thumbprint, DateTime.UtcNow.ToString("ddMMyyyy")));

            cerBlob.UploadFromByteArray(GetCerData(), 0, GetCerData().Count());

            return(String.Format("http://{0}.blob.core.windows.net/{1}/{2}/{3}.{4}", account, container, folder,
                                 DerEncodedCertificate.Thumbprint, DateTime.UtcNow.ToString("ddMMyyyy")));
        }
Esempio n. 2
0
        /// <summary>
        /// Gets a list of storage accounts from the storage catalog
        /// </summary>
        List <StorageAccount> IStorageActivity.GetStorageAccountList(bool includeKeys)
        {
            var getStorageAccountList = _client.GetStorageAccountList();

            if (!includeKeys)
            {
                return(getStorageAccountList);
            }
            // if the get keys flag is supplied then ensure that this returns the keys with the structure
            foreach (var storageAccount in getStorageAccountList)
            {
                var keys = _client.GetStorageAccountKeys(storageAccount.Name);

                storageAccount.PrimaryAccessKey   = keys[0];
                storageAccount.SecondaryAccessKey = keys[1];
            }
            return(getStorageAccountList);
        }