Skip to content

Latest commit

 

History

History

Bet.Extensions.AzureStorage

Bet.Extensions.AzureStorage

GitHub license Build status NuGet feedz.io

The second letter in the Hebrew alphabet is the ב bet/beit. Its meaning is "house". In the ancient pictographic Hebrew it was a symbol resembling a tent on a landscape.

Note: Pre-release packages are distributed via feedz.io.

Summary

The purpose of this repo is create an extension to Azure Storage Libraries and support MSI identity or token authentication.

This library contains collection of Azure Storage functionality.

  • It provides with a configurable model that centralizes creation of the instances of CloudStorageAccount per configuration.
  • It allows configuration of AspNetCore Static File options to use Azure Storage Blob Container.

Sample App requires Azure storage emulator for development

buymeacoffee

Give a Star! ⭐

If you like or are using this project to learn or start your solution, please give it a star. Thanks!

Install

    dotnet add package Bet.Extensions.AzureStorage

Usage

StorageAccountOptions class enables configuration of the CloudStorageAccount

Azure Storage Account can be created with the following configurations settings:

  1. MSI authentication simply specify Azure Storage Name of the account.
 "AzureStorage": {
    "DefaultAccount": {
      "Name": "storageName"
    }
  }
  1. SAS Token Authentication
 "AzureStorage": {
    "DefaultAccount": {
      "Name": "storageName",
      "Token":  "tokenValue",
      "ConnectionString": ""
    }
  }
  1. ConnectionString
 "AzureStorage": {
    "DefaultAccount": {
      "ConnectionString": "full-connection-string"
    }
  }

Azure Managed Identities support

By default the following roles are not assigned:

  • Storage Blob Data Contributor
  • Storage Queue Data Contributor

AspNetCore StaticFilesOptions as Azure Storage Blob Container

  1. Make sure that default configuration exists for CloudStorageAccount. In the below configuration MSI authentication will be used to connect to the container. As you can see no need to provide secure SAS token.
 "AzureStorage": {
    "DefaultAccount": {
      "Name": "teststorage"
    }
  }
  1. Create UploadsStorageBlobsOptions class
    public class UploadsProviderOptions : StorageFileProviderOptions
    {
    }
  1. Configure the Azure Blob Container
  "StorageFileProviders": {
    "UploadsProviderOptions": {
      "RequestPath": "/uploads",
      "ContainerName": "uploads",
      "EnableDirectoryBrowsing": true
    }
  }
  1. Add Service registration
    services.AddAzureStorageAccount()
            .AddAzureBlobContainer<UploadsBlobOptions>()
            .AddAzureStorageForStaticFiles<UploadsBlobStaticFilesOptions>();
  1. Enable middleware
   app.UseAzureStorageForStaticFiles<UploadsProviderOptions>();

Resources