-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22004 from suhaib-mousa/features/blob-storing-bunny
feat(blob-storing): implement Bunny.net blob storage provider
- Loading branch information
Showing
29 changed files
with
976 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# BLOB Storing Bunny Provider | ||
|
||
BLOB Storing Bunny Provider can store BLOBs in [bunny.net Storage](https://bunny.net/storage/). | ||
|
||
> Read the [BLOB Storing document](../blob-storing) to understand how to use the BLOB storing system. This document only covers how to configure containers to use a Bunny BLOB as the storage provider. | ||
## Installation | ||
|
||
Use the ABP CLI to add [Volo.Abp.BlobStoring.Bunny](https://www.nuget.org/packages/Volo.Abp.BlobStoring.Bunny) NuGet package to your project: | ||
|
||
* Install the [ABP CLI](../../../cli) if you haven't installed before. | ||
* Open a command line (terminal) in the directory of the `.csproj` file you want to add the `Volo.Abp.BlobStoring.Bunny` package. | ||
* Run `abp add-package Volo.Abp.BlobStoring.Bunny` command. | ||
|
||
If you want to do it manually, install the [Volo.Abp.BlobStoring.Bunny](https://www.nuget.org/packages/Volo.Abp.BlobStoring.Bunny) NuGet package to your project and add `[DependsOn(typeof(AbpBlobStoringBunnyModule))]` to the [ABP module](../../architecture/modularity/basics.md) class inside your project. | ||
|
||
## Configuration | ||
|
||
Configuration is done in the `ConfigureServices` method of your [module](../../architecture/modularity/basics.md) class, as explained in the [BLOB Storing document](../blob-storing). | ||
|
||
**Example: Configure to use the Bunny storage provider by default** | ||
|
||
````csharp | ||
Configure<AbpBlobStoringOptions>(options => | ||
{ | ||
options.Containers.ConfigureDefault(container => | ||
{ | ||
container.UseBunny(Bunny => | ||
{ | ||
Bunny.AccessKey = "your Bunny account access key"; | ||
Bunny.Region = "the code of the main storage zone region"; // "de" is the default value | ||
Bunny.ContainerName = "your bunny storage zone name"; | ||
Bunny.CreateContainerIfNotExists = true; | ||
}); | ||
}); | ||
}); | ||
|
||
```` | ||
|
||
> See the [BLOB Storing document](../blob-storing) to learn how to configure this provider for a specific container. | ||
### Options | ||
|
||
* **AccessKey** (string): Bunny Account Access Key. [Where do I find my Access key?](https://support.bunny.net/hc/en-us/articles/360012168840-Where-do-I-find-my-API-key) | ||
* **Region** (string?): The code of the main storage zone region (Possible values: DE, NY, LA, SG). | ||
* **ContainerName** (string): You can specify the container name in Bunny. If this is not specified, it uses the name of the BLOB container defined with the `BlobContainerName` attribute (see the [BLOB storing document](../blob-storing)). Please note that Bunny has some **rules for naming containers**: | ||
* Storage Zone names must be a globaly unique. | ||
* Storage Zone names must be between **4** and **64** characters long. | ||
* Storage Zone names can consist only of **lowercase** letters, numbers, and hyphens (-). | ||
* **CreateContainerIfNotExists** (bool): Default value is `false`, If a container does not exist in Bunny, `BunnyBlobProvider` will try to create it. | ||
|
||
## Bunny Blob Name Calculator | ||
|
||
Bunny Blob Provider organizes BLOB name and implements some conventions. The full name of a BLOB is determined by the following rules by default: | ||
|
||
* Appends `host` string if [current tenant](../../architecture/multi-tenancy) is `null` (or multi-tenancy is disabled for the container - see the [BLOB Storing document](../blob-storing) to learn how to disable multi-tenancy for a container). | ||
* Appends `tenants/<tenant-id>` string if current tenant is not `null`. | ||
* Appends the BLOB name. | ||
|
||
## Other Services | ||
|
||
* `BunnyBlobProvider` is the main service that implements the Bunny BLOB storage provider, if you want to override/replace it via [dependency injection](../../fundamentals/dependency-injection.md) (don't replace `IBlobProvider` interface, but replace `BunnyBlobProvider` class). | ||
* `IBunnyBlobNameCalculator` is used to calculate the full BLOB name (that is explained above). It is implemented by the `DefaultBunnyBlobNameCalculator` by default. | ||
* `IBunnyClientFactory` is implemented by `DefaultBunnyClientFactory` by default. You can override/replace it,if you want customize. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> | ||
<ConfigureAwait ContinueOnCapturedContext="false" /> | ||
</Weavers> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> | ||
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. --> | ||
<xs:element name="Weavers"> | ||
<xs:complexType> | ||
<xs:all> | ||
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1"> | ||
<xs:complexType> | ||
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" /> | ||
</xs:complexType> | ||
</xs:element> | ||
</xs:all> | ||
<xs:attribute name="VerifyAssembly" type="xs:boolean"> | ||
<xs:annotation> | ||
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="VerifyIgnoreCodes" type="xs:string"> | ||
<xs:annotation> | ||
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
<xs:attribute name="GenerateXsd" type="xs:boolean"> | ||
<xs:annotation> | ||
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation> | ||
</xs:annotation> | ||
</xs:attribute> | ||
</xs:complexType> | ||
</xs:element> | ||
</xs:schema> |
3 changes: 3 additions & 0 deletions
3
framework/src/Volo.Abp.BlobStoring.Bunny/Volo.Abp.BlobStoring.Bunny.abppkg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"role": "lib.framework" | ||
} |
68 changes: 68 additions & 0 deletions
68
framework/src/Volo.Abp.BlobStoring.Bunny/Volo.Abp.BlobStoring.Bunny.abppkg.analyze.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{ | ||
"name": "Volo.Abp.BlobStoring.Bunny", | ||
"hash": "", | ||
"contents": [ | ||
{ | ||
"namespace": "Volo.Abp.BlobStoring.Bunny", | ||
"dependsOnModules": [ | ||
{ | ||
"declaringAssemblyName": "Volo.Abp.BlobStoring", | ||
"namespace": "Volo.Abp.BlobStoring", | ||
"name": "AbpBlobStoringModule" | ||
}, | ||
{ | ||
"declaringAssemblyName": "Volo.Abp.Caching", | ||
"namespace": "Volo.Abp.Caching", | ||
"name": "AbpCachingModule" | ||
} | ||
], | ||
"implementingInterfaces": [ | ||
{ | ||
"name": "IAbpModule", | ||
"namespace": "Volo.Abp.Modularity", | ||
"declaringAssemblyName": "Volo.Abp.Core", | ||
"fullName": "Volo.Abp.Modularity.IAbpModule" | ||
}, | ||
{ | ||
"name": "IOnPreApplicationInitialization", | ||
"namespace": "Volo.Abp.Modularity", | ||
"declaringAssemblyName": "Volo.Abp.Core", | ||
"fullName": "Volo.Abp.Modularity.IOnPreApplicationInitialization" | ||
}, | ||
{ | ||
"name": "IOnApplicationInitialization", | ||
"namespace": "Volo.Abp", | ||
"declaringAssemblyName": "Volo.Abp.Core", | ||
"fullName": "Volo.Abp.IOnApplicationInitialization" | ||
}, | ||
{ | ||
"name": "IOnPostApplicationInitialization", | ||
"namespace": "Volo.Abp.Modularity", | ||
"declaringAssemblyName": "Volo.Abp.Core", | ||
"fullName": "Volo.Abp.Modularity.IOnPostApplicationInitialization" | ||
}, | ||
{ | ||
"name": "IOnApplicationShutdown", | ||
"namespace": "Volo.Abp", | ||
"declaringAssemblyName": "Volo.Abp.Core", | ||
"fullName": "Volo.Abp.IOnApplicationShutdown" | ||
}, | ||
{ | ||
"name": "IPreConfigureServices", | ||
"namespace": "Volo.Abp.Modularity", | ||
"declaringAssemblyName": "Volo.Abp.Core", | ||
"fullName": "Volo.Abp.Modularity.IPreConfigureServices" | ||
}, | ||
{ | ||
"name": "IPostConfigureServices", | ||
"namespace": "Volo.Abp.Modularity", | ||
"declaringAssemblyName": "Volo.Abp.Core", | ||
"fullName": "Volo.Abp.Modularity.IPostConfigureServices" | ||
} | ||
], | ||
"contentType": "abpModule", | ||
"name": "AbpBlobStoringBunnyModule", | ||
"summary": null | ||
} | ||
] | ||
} |
26 changes: 26 additions & 0 deletions
26
framework/src/Volo.Abp.BlobStoring.Bunny/Volo.Abp.BlobStoring.Bunny.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Import Project="..\..\..\configureawait.props" /> | ||
<Import Project="..\..\..\common.props" /> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0;net9.0</TargetFrameworks> | ||
<Nullable>enable</Nullable> | ||
<WarningsAsErrors>Nullable</WarningsAsErrors> | ||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> | ||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> | ||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> | ||
<RootNamespace /> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Volo.Abp.BlobStoring\Volo.Abp.BlobStoring.csproj" /> | ||
<ProjectReference Include="..\Volo.Abp.Caching\Volo.Abp.Caching.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BunnyCDN.Net.Storage" /> | ||
<PackageReference Include="Microsoft.Extensions.Http" /> | ||
</ItemGroup> | ||
|
||
</Project> |
16 changes: 16 additions & 0 deletions
16
...k/src/Volo.Abp.BlobStoring.Bunny/Volo/Abp/BlobStoring/Bunny/AbpBunnyBlobStoringModule .cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Volo.Abp.Caching; | ||
using Volo.Abp.Modularity; | ||
|
||
namespace Volo.Abp.BlobStoring.Bunny; | ||
|
||
[DependsOn( | ||
typeof(AbpBlobStoringModule), | ||
typeof(AbpCachingModule))] | ||
public class AbpBlobStoringBunnyModule : AbpModule | ||
{ | ||
public override void ConfigureServices(ServiceConfigurationContext context) | ||
{ | ||
context.Services.AddHttpClient(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
framework/src/Volo.Abp.BlobStoring.Bunny/Volo/Abp/BlobStoring/Bunny/BunnyApiException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
|
||
namespace Volo.Abp.BlobStoring.Bunny; | ||
|
||
public class BunnyApiException : Exception | ||
{ | ||
public BunnyApiException(string message) | ||
: base(message) | ||
{ | ||
|
||
} | ||
|
||
public BunnyApiException(string message, Exception innerException) | ||
: base(message, innerException) | ||
{ | ||
|
||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...BlobStoring.Bunny/Volo/Abp/BlobStoring/Bunny/BunnyBlobContainerConfigurationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
|
||
namespace Volo.Abp.BlobStoring.Bunny; | ||
|
||
public static class BunnyBlobContainerConfigurationExtensions | ||
{ | ||
public static BunnyBlobProviderConfiguration GetBunnyConfiguration( | ||
this BlobContainerConfiguration containerConfiguration) | ||
{ | ||
return new BunnyBlobProviderConfiguration(containerConfiguration); | ||
} | ||
|
||
public static BlobContainerConfiguration UseBunny( | ||
this BlobContainerConfiguration containerConfiguration, | ||
Action<BunnyBlobProviderConfiguration> bunnyConfigureAction) | ||
{ | ||
containerConfiguration.ProviderType = typeof(BunnyBlobProvider); | ||
containerConfiguration.NamingNormalizers.TryAdd<BunnyBlobNamingNormalizer>(); | ||
|
||
bunnyConfigureAction(new BunnyBlobProviderConfiguration(containerConfiguration)); | ||
|
||
return containerConfiguration; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...rk/src/Volo.Abp.BlobStoring.Bunny/Volo/Abp/BlobStoring/Bunny/BunnyBlobNamingNormalizer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System.Globalization; | ||
using System.Text.RegularExpressions; | ||
using Volo.Abp.DependencyInjection; | ||
using Volo.Abp.Localization; | ||
|
||
namespace Volo.Abp.BlobStoring.Bunny; | ||
|
||
public class BunnyBlobNamingNormalizer : IBlobNamingNormalizer, ITransientDependency | ||
{ | ||
private readonly static Regex ValidCharactersRegex = | ||
new Regex(@"^[a-z0-9-]*$", RegexOptions.Compiled); | ||
|
||
private const int MinLength = 4; | ||
private const int MaxLength = 64; | ||
|
||
public virtual string NormalizeBlobName(string blobName) => blobName; | ||
|
||
public virtual string NormalizeContainerName(string containerName) | ||
{ | ||
Check.NotNullOrWhiteSpace(containerName, nameof(containerName)); | ||
|
||
using (CultureHelper.Use(CultureInfo.InvariantCulture)) | ||
{ | ||
// Trim whitespace and convert to lowercase | ||
var normalizedName = containerName | ||
.Trim() | ||
.ToLowerInvariant(); | ||
|
||
// Remove any invalid characters | ||
normalizedName = Regex.Replace(normalizedName, "[^a-z0-9-]", string.Empty); | ||
|
||
// Validate structure | ||
if (!ValidCharactersRegex.IsMatch(normalizedName)) | ||
{ | ||
throw new AbpException( | ||
$"Container name contains invalid characters: {containerName}. " + | ||
"Only lowercase letters, numbers, and hyphens are allowed."); | ||
} | ||
|
||
// Validate length | ||
if (normalizedName.Length < MinLength || normalizedName.Length > MaxLength) | ||
{ | ||
throw new AbpException( | ||
$"Container name must be between {MinLength} and {MaxLength} characters. " + | ||
$"Current length: {normalizedName.Length}"); | ||
} | ||
|
||
return normalizedName; | ||
} | ||
} | ||
} |
Oops, something went wrong.