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);
            }
        }
Ejemplo n.º 2
0
        public void GetAccountName_ShouldReturn2()
        {
            var result = AzureStorageUtils.GetAccountName(AzureStorageAccountConnectionParameters.CreateUsingResourceGroupAndAccountName("resourceGroup", "accountName"));

            Assert.Equal("accountName", result);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo 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);
        }
Ejemplo n.º 6
0
 public void GetAccountName_ShouldThrow()
 {
     Assert.Throws <NullReferenceException>(() => AzureStorageUtils.GetAccountName(null));
 }