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)); }
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); }
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.")); }
// 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) }); }
// 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) }); }
// 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); }
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); }
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)); }
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); }
// 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); }
// 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); }
// 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); }
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); }
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)); }
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); }
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)); }
public static EncryptedBlob Convert(byte[] input, Attribute config) => EncryptedBlob.FromByteArray(BlobPath.ParseAndValidate(((EncryptedBlobAttribute)config).BlobPath), input);
public static EncryptedBlob Convert(string input, Attribute config) => EncryptedBlob.FromString(BlobPath.ParseAndValidate(((EncryptedBlobAttribute)config).BlobPath), input);
public void ParseAndValidate_IfHierarchicalBlobName_ReturnsBlobPath() { BlobPath blobPath = BlobPath.ParseAndValidate(@"container/my/blob"); Assert.NotNull(blobPath); }
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): '\\'."); }
public void ParseAndValidate_IfInvalidContainerName_ThrowsFormatException() { ExceptionAssert.ThrowsFormat(() => BlobPath.ParseAndValidate(@"container-/blob"), "Invalid container name: container-"); }
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 ']'."); }