public async Task <UriBuilder> CreateUriBuilder(
            string containerName,
            string resourceType = "c",
            BlobContainerSasPermissions permission = BlobContainerSasPermissions.Read,
            int expiresOnMinutes = 10,
            CancellationToken cancellationToken = default
            )
        {
            var accountName = AzureStorageUtils.GetAccountName(_connectionParameters);

            if (!String.IsNullOrWhiteSpace(accountName))
            {
                var uriBuilder = new UriBuilder()
                {
                    Scheme = "https",
                    Host   = string.Format("{0}.blob.core.windows.net", accountName)
                };

                if (_connectionParameters.IsDevelopmentStorage)
                {
                    return(uriBuilder);
                }
                else
                {
                    var sasBuilder = CreateBlobSasBuilder(containerName, resourceType, permission, expiresOnMinutes);

                    StorageSharedKeyCredential credential;

                    if (!String.IsNullOrWhiteSpace(_connectionParameters.ConnectionString))
                    {
                        credential = AzureStorageUtils.CreateCredentialFromConnectionString(_connectionParameters.ConnectionString);
                    }
                    else
                    {
                        string accessKey = await GetStorageAccountKey(cancellationToken);

                        credential = new StorageSharedKeyCredential(_connectionParameters.StorageAccountName, accessKey);
                    }

                    var sasToken = sasBuilder.ToSasQueryParameters(credential);

                    uriBuilder.Query = sasToken.ToString();

                    return(uriBuilder);
                }
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
        public void GetAccountName_ShouldReturn2()
        {
            var result = AzureStorageUtils.GetAccountName(AzureStorageAccountConnectionParameters.CreateUsingResourceGroupAndAccountName("resourceGroup", "accountName"));

            Assert.Equal("accountName", result);
        }
Esempio n. 3
0
        public void GetAccountName_ShouldReturn()
        {
            var result = AzureStorageUtils.GetAccountName(AzureStorageAccountConnectionParameters.CreateUsingConnectionString("AccountName=This is the account name;aaa=aa"));

            Assert.Equal("This is the account name", result);
        }
Esempio n. 4
0
        public void GetAccountName_ShouldThrow3()
        {
            var ex = Assert.Throws <ArgumentException>(() => AzureStorageUtils.GetAccountName(AzureStorageAccountConnectionParameters.CreateUsingConnectionString("aaaaa")));

            Assert.Equal("Connection string in wrong format", ex.Message);
        }
Esempio n. 5
0
        public void GetAccountName_ShouldThrow2()
        {
            var ex = Assert.Throws <ArgumentException>(() => AzureStorageUtils.GetAccountName(AzureStorageAccountConnectionParameters.CreateUsingConnectionString("")));

            Assert.Equal("Neither connection string or account name specified", ex.Message);
        }
Esempio n. 6
0
 public void GetAccountName_ShouldThrow()
 {
     Assert.Throws <NullReferenceException>(() => AzureStorageUtils.GetAccountName(null));
 }