How do I rewrite this code used for User delegation to account key?
public async Task<string> GetBlobSASToken(string containerName)
{
_logger.LogInformation($"Initial Load Worker called Blob SAS Token creation.");
try
{
DbConnectionStringBuilder dbConnectionStringBuilder = new DbConnectionStringBuilder();
dbConnectionStringBuilder.ConnectionString = _config.BlobStorageConnectionString;
var azureStorageAccount = dbConnectionStringBuilder["AccountName"].ToString();
var azureStorageAccessKey = dbConnectionStringBuilder["AccountKey"].ToString();
Azure.Storage.Sas.BlobSasBuilder blobSasBuilder = new Azure.Storage.Sas.BlobSasBuilder()
{
BlobContainerName = containerName,
Protocol = SasProtocol.Https,
Resource = "c",
StartsOn = DateTimeOffset.UtcNow.AddDays(-1),
ExpiresOn = DateTimeOffset.UtcNow.AddDays(3),
};
blobSasBuilder.SetPermissions(
Azure.Storage.Sas.BlobSasPermissions.Read |
Azure.Storage.Sas.BlobSasPermissions.Add |
Azure.Storage.Sas.BlobSasPermissions.Create |
Azure.Storage.Sas.BlobSasPermissions.Write |
Azure.Storage.Sas.BlobSasPermissions.Delete |
Azure.Storage.Sas.BlobSasPermissions.List |
Azure.Storage.Sas.BlobSasPermissions.SetImmutabilityPolicy
);
var sasToken = blobSasBuilder.ToSasQueryParameters(new StorageSharedKeyCredential(azureStorageAccount,
azureStorageAccessKey)).ToString();
return sasToken;
}
catch (Exception ex)
{
_logger.LogError(ex, $"Inital Load Worker has error when creating a SAS token for Initial Load Worker.");
throw;
}
}
Unfortunately, I can't use user delegation: