public void GivenIHaveTheStorageAbstraction(string account)
 {
     account = Constants.WabsProtocolSchemeName + account;
     var factory = ServiceLocator.Instance.Locate<IWabStorageAbstractionFactory>();
     // NOTE: when run against production we should pull the key out of the valid creds file.
     var creds = new WindowsAzureStorageAccountCredentials() { Name = account, Key = string.Empty };
     abstraction = factory.Create(creds);
 }
 public WabStorageAbstractionSimulator(WindowsAzureStorageAccountCredentials credentials)
 {
     this.credentials = credentials;
     this.RootPath = this.credentials.Name;
     this.ChosenProtocol = Constants.WabsProtocol;
     this.ChosenProtocolScheme = Constants.WabsProtocolSchemeName;
     this.Root = new StorageSimulatorItem(this.Account, string.Empty);
 }
 public IStorageAbstraction Create(WindowsAzureStorageAccountCredentials credentials)
 {
     WabStorageAbstractionSimulator simulator;
     if (!this.simulators.TryGetValue(credentials.Name, out simulator))
     {
         simulator = new WabStorageAbstractionSimulator(credentials);
         this.simulators.Add(credentials.Name, simulator);
     }
     return simulator;
 }
        public void CanGetStorageAccountName_Production()
        {
            var storageCreds = new WindowsAzureStorageAccountCredentials()
            {
                Name = "demostorage"
            };

            var wabsStorageClient = new WabStorageAbstraction(storageCreds);
            Assert.AreEqual(wabsStorageClient.StorageAccountName, "demostorage");
            Assert.AreEqual(wabsStorageClient.StorageAccountRoot, "http://demostorage.blob.core.windows.net/");
        }
        public void CanConvertWabsPathToHttpPath()
        {
            var storageCreds = new WindowsAzureStorageAccountCredentials()
            {
                Name = "demostorage.blob.core.windows-int.net"
            };

            var asvPath = Constants.WabsProtocolSchemeName + "[email protected]/path1/path2";
            var httpPath = WabStorageAbstraction.ConvertToHttpPath(new Uri(asvPath));
            Assert.AreEqual("http://demostorage.blob.core.windows-int.net/container/path1/path2", httpPath.AbsoluteUri);
        }
        public void CanGetStorageAccountName_Internal()
        {
            var storageCreds = new WindowsAzureStorageAccountCredentials()
            {
                Name = Constants.WabsProtocolSchemeName + "demostorage.blob.core.windows-int.net"
            };

            var wabsStorageClient = new WabStorageAbstraction(storageCreds);
            Assert.AreEqual("demostorage", wabsStorageClient.StorageAccountName);
            Assert.AreEqual("http://demostorage.blob.core.windows-int.net", wabsStorageClient.StorageAccountRoot);
        }
 public async Task CreateContainerIfNotExists(string fullAccount, string key, string container)
 {
     try
     {
         var storageAbstractionCreds = new WindowsAzureStorageAccountCredentials() { Key = key, Name = fullAccount };
         var storageAbstraction = ServiceLocator.Instance.Locate<IWabStorageAbstractionFactory>().Create(storageAbstractionCreds);
         await storageAbstraction.CreateContainerIfNotExists(container);
     }
     catch (Exception e)
     {
         throw new ConfigurationErrorsException(string.Format(CultureInfo.InvariantCulture,
                                                              "Validating container '{0}' (storage '{1}') failed. Inner exception:{2}",
                                                              container,
                                                              fullAccount,
                                                              e.Message),
                                                e);
     }
 }
 public async Task ValidateAccount(string fullAccount, string key)
 {
     try
     {
         var storageAbstractionCreds = new WindowsAzureStorageAccountCredentials() { Key = key, Name = fullAccount };
         var storageAbstraction = ServiceLocator.Instance.Locate<IWabStorageAbstractionFactory>().Create(storageAbstractionCreds);
         var listContainersUri = new Uri(string.Format("{0}://{1}/", Constants.WabsProtocol, fullAccount));
         await storageAbstraction.List(listContainersUri, false);
     }
     catch (Exception e)
     {
         throw new ConfigurationErrorsException(string.Format(CultureInfo.InvariantCulture,
                                                              "Validating connection to '{0}' failed. Inner exception:{1}",
                                                              fullAccount,
                                                              e.Message),
                                                e);
     }
 }
        public async Task ICanPerformA_PositiveCreateContainer_WithNonExistantContainer()
        {
            var storageCreds = new WindowsAzureStorageAccountCredentials()
            {
                Key = IntegrationTestBase.TestCredentials.Environments[0].DefaultStorageAccount.Key,
                Name = IntegrationTestBase.TestCredentials.Environments[0].DefaultStorageAccount.Name
            };

            var nonExistantContainer = Guid.NewGuid().ToString("N").ToLowerInvariant();
            var client = ServiceLocator.Instance.Locate<IAsvValidatorClientFactory>().Create();
            await client.CreateContainerIfNotExists(storageCreds.Name, storageCreds.Key, nonExistantContainer);

            var storageAbstraction = ServiceLocator.Instance.Locate<IWabStorageAbstractionFactory>().Create(storageCreds);
            var listContainerPath = new Uri(Constants.WabsProtocolSchemeName + nonExistantContainer + "@" + storageCreds.Name);
            var containers = await storageAbstraction.List(listContainerPath, false);
            var containerExists = containers.Any(path => path.UserInfo == nonExistantContainer);
            Assert.IsTrue(containerExists);
        }
 private void WriteJobResultFile(string statusDirectory, string content, string fileName)
 {
     if (!string.IsNullOrEmpty(statusDirectory))
     {
         var storageCreds = new WindowsAzureStorageAccountCredentials()
         {
             Name = Constants.WabsProtocolSchemeName + this.cluster.Cluster.DefaultStorageAccount.Name,
             Key = this.cluster.Cluster.DefaultStorageAccount.Key
         };
         var storageHandler = ServiceLocator.Instance.Locate<IWabStorageAbstractionFactory>().Create(storageCreds);
         storageHandler.Write(this.GetStatusPath(statusDirectory, fileName), this.GetStream(content));
     }
 }
        public static async Task ValidateAndResolveWasbScriptActionEndpointUri(Uri uri, WabStorageAccountConfiguration storage)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            if (storage == null)
            {
                throw new ArgumentNullException("storage");
            }

            // Try to check the existence of the script in the URI specified.
            var storageAbstractionCreds = new WindowsAzureStorageAccountCredentials()
            {
                Key = storage.Key,
                Name = GetFullyQualifiedStorageAccountName(storage.Name),
            };

            var storageAbstraction = new WabStorageAbstraction(storageAbstractionCreds);

            bool exists = false;

            try
            {
                // Firstly converts the URI to wasb style and then test it against wasb storage for existence.
                exists = await storageAbstraction.Exists(ConvertToWasbUriIfNeeded(uri));
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Script action URI: {0} cannot be retrieved correctly. Inner exception: {1}", uri.AbsoluteUri, e.Message), e);
            }

            if (!exists)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Script action URI: {0} cannot be retrieved correctly because it does not exist", uri.AbsoluteUri));
            }
        }
        public async Task NegativeTest_InvalidAsvContainer_Using_PocoClient_AgainstAzure()
        {
            this.ApplyIndividualTestMockingOnly();
            var cluster = GetRandomCluster();
            IHDInsightCertificateCredential credentials = IntegrationTestBase.GetValidCredentials();
            await ServiceLocator.Instance.Locate<IHDInsightManagementPocoClientFactory>().Create(credentials, GetAbstractionContext(), false).CreateContainer(cluster);

            var storageCreds = new WindowsAzureStorageAccountCredentials()
            {
                Key = cluster.DefaultStorageAccountKey,
                Name = cluster.DefaultStorageAccountName
            };
            var storageAbstraction = ServiceLocator.Instance.Locate<IWabStorageAbstractionFactory>().Create(storageCreds);
            var listContainerPath = new Uri(Constants.WabsProtocolSchemeName + storageCreds.Name);
            var containers = await storageAbstraction.List(listContainerPath, false);
            var containerExists = containers.Any(path => path.UserInfo == cluster.DefaultStorageContainer);
            Assert.IsTrue(containerExists);
        }
 public async Task CreateContainerIfNotExists(string fullAccount, string key, string container)
 {
     var storageAbstractionCreds = new WindowsAzureStorageAccountCredentials() { Key = key, Name = fullAccount };
     var storageAbstraction = ServiceLocator.Instance.Locate<IWabStorageAbstractionFactory>().Create(storageAbstractionCreds);
     await storageAbstraction.CreateContainerIfNotExists(container);
     }