I am working on a project for Enterprise business where I need to migrate applications from On-premises to Azure Cloud.
Some applications require Azure Blob Storage. All Azure Cloud infrastructure is accessible using Manage Identity, and the business requirement was to test and validate the Azure Blob methods without having access to Azure Portal, developers are restricted access to any storage resource none production or production. That said the business asked us to make all Storage stuff work before the code even is pushed to Cloud by testing it locally and on GitHub workflows.
Of course, I can fire up my personal Azure account and play with it, but still, it will be tested with my account as a playground but not really a usable test.
The whole idea of generic testing Azure Blob Storage without needing to have any kind of access rights to Blob Storage.
Is that possible and How can I achieve this?
Following are my working POC methods for Azure Blob:
private readonly BlobContainerClient _blobContainerClient;
public AzureBlobStorage(string connectionString, string container)
{
_blobContainerClient = new BlobContainerClient(connectionString, container);
_blobContainerClient.CreateIfNotExists();
}
public async Task<string> ReadTextFile(string filename)
{
var blob = _blobContainerClient.GetBlobClient(filename);
if (!await _blobContainerClient.ExistsAsync()) return string.Empty;
var reading = await blob.DownloadStreamingAsync();
StreamReader reader = new StreamReader(reading.Value.Content);
return await reader.ReadToEndAsync();
}
public async Task CreateTextFile(string filename, byte[] data)
{
var blob = _blobContainerClient.GetBlobClient(filename);
await using var ms = new MemoryStream(data, false);
await blob.UploadAsync(ms, CancellationToken.None);
}
public async Task DeleteTextFile(string filename)
{
var blobClient = _blobContainerClient.GetBlobClient(filename);
await blobClient.DeleteAsync();
}