コード例 #1
0
        public Task <ICloudBlob> ConvertAsync(string input, CancellationToken cancellationToken)
        {
            BlobPath path      = BlobPath.ParseAndValidate(input);
            var      container = _client.GetContainerReference(path.ContainerName);

            return(container.GetBlobReferenceFromServerAsync(path.BlobName, cancellationToken));
        }
コード例 #2
0
        public async Task <BlobBaseClient> ConvertAsync(string input, CancellationToken cancellationToken)
        {
            BlobPath path      = BlobPath.ParseAndValidate(input);
            var      container = _client.GetBlobContainerClient(path.ContainerName);

            return((await container.GetBlobReferenceFromServerAsync(path.BlobName, cancellationToken).ConfigureAwait(false)).Item1);
        }
コード例 #3
0
        public virtual async Task <ICloudBlob> GetBlockBlobAsync(string path)
        {
            var blobPath  = BlobPath.ParseAndValidate(path);
            var container = _storageAccount.CreateCloudBlobClient().GetContainerReference(blobPath.ContainerName);
            var exists    = await container.ExistsAsync();

            return(exists ? container.GetBlockBlobReference(blobPath.FilePath) : throw new DirectoryNotFoundException(@"Container with name {container} do not exists."));
        }
コード例 #4
0
        // Initial rule that captures the muti-blob context.
        // Then a converter morphs this to the user type
        MultiBlobContext IConverter <BlobAttribute, MultiBlobContext> .Convert(BlobAttribute attr)
        {
            var path = BlobPath.ParseAndValidate(attr.BlobPath, isContainerBinding: true);

            return(new MultiBlobContext
            {
                Prefix = path.BlobName,
                Container = GetContainer(attr)
            });
        }
コード例 #5
0
        // Initial rule that captures the muti-blob context.
        // Then a converter morphs this to the user type
        async Task <MultiBlobContext> IAsyncConverter <BlobAttribute, MultiBlobContext> .ConvertAsync(BlobAttribute attr, CancellationToken cancellationToken)
        {
            var path = BlobPath.ParseAndValidate(attr.BlobPath, isContainerBinding: true);

            return(new MultiBlobContext
            {
                Prefix = path.BlobName,
                Container = await this.GetContainerAsync(attr, cancellationToken)
            });
        }
コード例 #6
0
        // For describing InvokeStrings.
        private async Task <BlobBaseClient> ConvertFromInvokeString(DirectInvokeString input, Attribute attr, ValueBindingContext context)
        {
            var attrResolved = (BlobTriggerAttribute)attr;

            var      client    = _blobServiceClientProvider.Get(attrResolved.Connection);
            BlobPath path      = BlobPath.ParseAndValidate(input.Value);
            var      container = client.GetBlobContainerClient(path.ContainerName);
            var      blob      = await container.GetBlobReferenceFromServerAsync(path.BlobName).ConfigureAwait(false);

            return(blob.Client);
        }
コード例 #7
0
        private BlobContainerClient GetContainer(
            BlobAttribute blobAttribute)
        {
            var client = GetClient(blobAttribute);

            BlobPath boundPath = BlobPath.ParseAndValidate(blobAttribute.BlobPath, isContainerBinding: true);

            var container = client.GetBlobContainerClient(boundPath.ContainerName);

            return(container);
        }
コード例 #8
0
        public async Task <ICloudBlob> ConvertAsync(EncryptedBlobAttribute input, CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(_keyNameProvider.DefaultKey) && input.KeyName is string kn && !string.IsNullOrWhiteSpace(kn))
            {
                _keyNameProvider.DefaultKey = input.KeyName;
            }
            var cloudBlobClient    = CloudStorageAccount.Parse(input.BlobConnectionString).CreateCloudBlobClient();
            var keyVaultBlobClient = new KeyVaultBlobClient(cloudBlobClient, _keyVaultClient, _keyNameProvider);
            var blobPath           = BlobPath.ParseAndValidate(input.BlobPath) ?? throw new ArgumentException(nameof(EncryptedBlobAttribute.BlobPath));

            return(await keyVaultBlobClient.GetBlob(blobPath, cancellationToken));
        }
コード例 #9
0
        private async Task <CloudBlobContainer> GetContainerAsync(
            BlobAttribute blobAttribute,
            CancellationToken cancellationToken)
        {
            var client = await GetClientAsync(blobAttribute, cancellationToken);

            BlobPath boundPath = BlobPath.ParseAndValidate(blobAttribute.BlobPath, isContainerBinding: true);

            var container = client.GetContainerReference(boundPath.ContainerName);

            return(container);
        }
コード例 #10
0
        // For describing InvokeStrings.
        private async Task <ICloudBlob> ConvertFromInvokeString(DirectInvokeString input, Attribute attr, ValueBindingContext context)
        {
            var attrResolved = (BlobTriggerAttribute)attr;

            var      account   = _accountProvider.Get(attrResolved.Connection);
            var      client    = account.CreateCloudBlobClient();
            BlobPath path      = BlobPath.ParseAndValidate(input.Value);
            var      container = client.GetContainerReference(path.ContainerName);
            var      blob      = await container.GetBlobReferenceFromServerAsync(path.BlobName);

            return(blob);
        }
コード例 #11
0
        // For describing InvokeStrings.
        private async Task <IStorageBlob> ConvertFromInvokeString(DirectInvokeString input, Attribute attr, ValueBindingContext context)
        {
            var attrResolved = (BlobTriggerAttribute)attr;
            var account      = await _accountProvider.GetStorageAccountAsync(attrResolved, CancellationToken.None);

            var client = account.CreateBlobClient();

            var      cancellationToken = context.CancellationToken;
            BlobPath path = BlobPath.ParseAndValidate(input.Value);
            IStorageBlobContainer container = client.GetContainerReference(path.ContainerName);
            var blob = await container.GetBlobReferenceFromServerAsync(path.BlobName, cancellationToken);

            return(blob);
        }
コード例 #12
0
        // Write-only rule.
        async Task <CloudBlobDirectory> IAsyncConverter <BlobAttribute, CloudBlobDirectory> .ConvertAsync(
            BlobAttribute blobAttribute, CancellationToken cancellationToken)
        {
            var client = await GetClientAsync(blobAttribute, cancellationToken);

            BlobPath boundPath = BlobPath.ParseAndValidate(blobAttribute.BlobPath, isContainerBinding: false);

            var container = client.GetContainerReference(boundPath.ContainerName);

            CloudBlobDirectory directory = container.GetDirectoryReference(
                boundPath.BlobName);

            return(directory);
        }
コード例 #13
0
        internal static bool TryConvert(object value, IStorageBlobClient client, out IStorageBlobContainer container, out BlobPath path)
        {
            container = null;
            path      = null;

            string fullPath = value as string;

            if (fullPath != null)
            {
                path      = BlobPath.ParseAndValidate(fullPath, isContainerBinding: true);
                container = client.GetContainerReference(path.ContainerName);
                return(true);
            }

            return(false);
        }
コード例 #14
0
        public async Task <IStorageBlob> ConvertAsync(string input, CancellationToken cancellationToken)
        {
            BlobPath path;

            // For convenience, treat an an empty string as a request for the default value.
            if (String.IsNullOrEmpty(input) && _defaultPath.IsBound)
            {
                path = _defaultPath.Bind(null);
            }
            else
            {
                path = BlobPath.ParseAndValidate(input);
            }

            IStorageBlobContainer container = _client.GetContainerReference(path.ContainerName);
            await container.CreateIfNotExistsAsync(cancellationToken);

            return(await container.GetBlobReferenceForArgumentTypeAsync(path.BlobName, _argumentType,
                                                                        cancellationToken));
        }
コード例 #15
0
        private async Task <ICloudBlob> GetBlobAsync(
            BlobAttribute blobAttribute,
            CancellationToken cancellationToken,
            Type requestedType = null)
        {
            var client = await GetClientAsync(blobAttribute, cancellationToken);

            BlobPath boundPath = BlobPath.ParseAndValidate(blobAttribute.BlobPath);

            var container = client.GetContainerReference(boundPath.ContainerName);

            if (blobAttribute.Access != FileAccess.Read)
            {
                await container.CreateIfNotExistsAsync(cancellationToken);
            }

            var blob = await container.GetBlobReferenceForArgumentTypeAsync(
                boundPath.BlobName, requestedType, cancellationToken);

            return(blob);
        }
コード例 #16
0
        private async Task <BlobWithContainer <BlobBaseClient> > GetBlobAsync(
            BlobAttribute blobAttribute,
            CancellationToken cancellationToken,
            Type requestedType = null)
        {
            var      client    = GetClient(blobAttribute);
            BlobPath boundPath = BlobPath.ParseAndValidate(blobAttribute.BlobPath);

            var container = client.GetBlobContainerClient(boundPath.ContainerName);

            // Call ExistsAsync before attempting to create. This reduces the number of
            // 40x calls that App Insights may be tracking automatically
            if (blobAttribute.Access != FileAccess.Read && !await container.ExistsAsync().ConfigureAwait(false))
            {
                await container.CreateIfNotExistsAsync(cancellationToken : cancellationToken).ConfigureAwait(false);
            }

            var blob = await container.GetBlobReferenceForArgumentTypeAsync(
                boundPath.BlobName, requestedType, cancellationToken).ConfigureAwait(false);

            return(new BlobWithContainer <BlobBaseClient>(container, blob));
        }
コード例 #17
0
 public static EncryptedBlob Convert(byte[] input, Attribute config)
 => EncryptedBlob.FromByteArray(BlobPath.ParseAndValidate(((EncryptedBlobAttribute)config).BlobPath), input);
コード例 #18
0
 public static EncryptedBlob Convert(string input, Attribute config)
 => EncryptedBlob.FromString(BlobPath.ParseAndValidate(((EncryptedBlobAttribute)config).BlobPath), input);
コード例 #19
0
        public void ParseAndValidate_IfHierarchicalBlobName_ReturnsBlobPath()
        {
            BlobPath blobPath = BlobPath.ParseAndValidate(@"container/my/blob");

            Assert.NotNull(blobPath);
        }
コード例 #20
0
 public void ParseAndValidate_IfBackslashInBlobName_ThrowsFormatException()
 {
     ExceptionAssert.ThrowsFormat(() => BlobPath.ParseAndValidate(@"container/my\name"), "The given blob name 'my\\name' contain illegal characters. A blob name cannot the following character(s): '\\'.");
 }
コード例 #21
0
 public void ParseAndValidate_IfInvalidContainerName_ThrowsFormatException()
 {
     ExceptionAssert.ThrowsFormat(() => BlobPath.ParseAndValidate(@"container-/blob"), "Invalid container name: container-");
 }
コード例 #22
0
 public void ParseAndValidate_IfCloseSquareBracketInBlobName_ThrowsFormatException()
 {
     ExceptionAssert.ThrowsFormat(() => BlobPath.ParseAndValidate(@"container/my]name"), "The given blob name 'my]name' contain illegal characters. A blob name cannot the following characters: '\\', '[' and ']'.");
 }