-
Notifications
You must be signed in to change notification settings - Fork 267
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 #890 from colinin/integration-sonatype-nexus
feat(oss): add Sonatype Nexus integration.
- Loading branch information
Showing
76 changed files
with
2,410 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
3 changes: 3 additions & 0 deletions
3
aspnet-core/modules/nexus/LINGYUN.Abp.BlobStoring.Nexus/FodyWeavers.xml
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> |
30 changes: 30 additions & 0 deletions
30
aspnet-core/modules/nexus/LINGYUN.Abp.BlobStoring.Nexus/FodyWeavers.xsd
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> |
20 changes: 20 additions & 0 deletions
20
aspnet-core/modules/nexus/LINGYUN.Abp.BlobStoring.Nexus/LINGYUN.Abp.BlobStoring.Nexus.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,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<Import Project="..\..\..\configureawait.props" /> | ||
<Import Project="..\..\..\common.props" /> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<RootNamespace /> | ||
<Description>Oss对象存储Nexus集成</Description> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Volo.Abp.BlobStoring" Version="$(VoloAbpPackageVersion)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\LINGYUN.Abp.Sonatype.Nexus\LINGYUN.Abp.Sonatype.Nexus.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
12 changes: 12 additions & 0 deletions
12
.../LINGYUN.Abp.BlobStoring.Nexus/LINGYUN/Abp/BlobStoring/Nexus/AbpBlobStoringNexusModule.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,12 @@ | ||
using LINGYUN.Abp.Sonatype.Nexus; | ||
using Volo.Abp.BlobStoring; | ||
using Volo.Abp.Modularity; | ||
|
||
namespace LINGYUN.Abp.BlobStoring.Nexus; | ||
|
||
[DependsOn( | ||
typeof(AbpBlobStoringModule), | ||
typeof(AbpSonatypeNexusModule))] | ||
public class AbpBlobStoringNexusModule : AbpModule | ||
{ | ||
} |
70 changes: 70 additions & 0 deletions
70
...NGYUN.Abp.BlobStoring.Nexus/LINGYUN/Abp/BlobStoring/Nexus/DefaultBlobRawPathCalculator.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,70 @@ | ||
using System; | ||
using Volo.Abp.BlobStoring; | ||
using Volo.Abp.DependencyInjection; | ||
using Volo.Abp.MultiTenancy; | ||
|
||
namespace LINGYUN.Abp.BlobStoring.Nexus; | ||
public class DefaultBlobRawPathCalculator : IBlobRawPathCalculator, ITransientDependency | ||
{ | ||
protected ICurrentTenant CurrentTenant { get; } | ||
protected IBlobContainerConfigurationProvider ConfigurationProvider { get; } | ||
|
||
public DefaultBlobRawPathCalculator( | ||
ICurrentTenant currentTenant, | ||
IBlobContainerConfigurationProvider configurationProvider) | ||
{ | ||
CurrentTenant = currentTenant; | ||
ConfigurationProvider = configurationProvider; | ||
} | ||
|
||
public string CalculateGroup(string containerName, string blobName) | ||
{ | ||
var blobPath = CalculateBasePath(containerName); | ||
|
||
var lastFolderIndex = blobName.LastIndexOf("/"); | ||
if (lastFolderIndex > 0) | ||
{ | ||
blobPath = blobPath.EnsureEndsWith('/'); | ||
blobPath += blobName.Substring(0, lastFolderIndex); | ||
} | ||
|
||
return blobPath.EnsureStartsWith('/').RemovePostFix("/"); | ||
} | ||
|
||
public string CalculateName(string containerName, string blobName, bool replacePath = false) | ||
{ | ||
var blobPath = CalculateBasePath(containerName); | ||
blobPath = blobPath.EnsureEndsWith('/'); | ||
blobPath += blobName; | ||
|
||
if (replacePath) | ||
{ | ||
return blobName.Replace(blobPath.RemovePreFix("/"), "").RemovePreFix("/"); | ||
} | ||
|
||
return blobPath.RemovePreFix("/"); | ||
} | ||
|
||
protected virtual string CalculateBasePath(string containerName) | ||
{ | ||
var configuration = ConfigurationProvider.Get<DefaultContainer>(); | ||
var nexusConfiguration = configuration.GetNexusConfiguration(); | ||
var blobPath = nexusConfiguration.BasePath; | ||
|
||
if (CurrentTenant.Id == null) | ||
{ | ||
blobPath = $"{blobPath}/host"; | ||
} | ||
else | ||
{ | ||
blobPath = $"{blobPath}/tenants/{CurrentTenant.Id.Value.ToString("D")}"; | ||
} | ||
|
||
if (nexusConfiguration.AppendContainerNameToBasePath) | ||
{ | ||
blobPath = $"{blobPath}/{containerName.RemovePreFix("/")}"; | ||
} | ||
|
||
return blobPath.EnsureStartsWith('/'); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...xus/LINGYUN.Abp.BlobStoring.Nexus/LINGYUN/Abp/BlobStoring/Nexus/IBlobRawPathCalculator.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,9 @@ | ||
using Volo.Abp.BlobStoring; | ||
|
||
namespace LINGYUN.Abp.BlobStoring.Nexus; | ||
public interface IBlobRawPathCalculator | ||
{ | ||
string CalculateGroup(string containerName, string blobName); | ||
|
||
string CalculateName(string containerName, string blobName, bool replacePath = false); | ||
} |
26 changes: 26 additions & 0 deletions
26
...bStoring.Nexus/LINGYUN/Abp/BlobStoring/Nexus/NexusBlobContainerConfigurationExtensions.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,26 @@ | ||
using System; | ||
using Volo.Abp.BlobStoring; | ||
|
||
namespace LINGYUN.Abp.BlobStoring.Nexus | ||
{ | ||
public static class NexusBlobContainerConfigurationExtensions | ||
{ | ||
public static NexusBlobProviderConfiguration GetNexusConfiguration( | ||
this BlobContainerConfiguration containerConfiguration) | ||
{ | ||
return new NexusBlobProviderConfiguration(containerConfiguration); | ||
} | ||
|
||
public static BlobContainerConfiguration UseNexus( | ||
this BlobContainerConfiguration containerConfiguration, | ||
Action<NexusBlobProviderConfiguration> nexusConfigureAction) | ||
{ | ||
containerConfiguration.ProviderType = typeof(NexusBlobProvider); | ||
containerConfiguration.NamingNormalizers.TryAdd<NexusBlobNamingNormalizer>(); | ||
|
||
nexusConfigureAction(new NexusBlobProviderConfiguration(containerConfiguration)); | ||
|
||
return containerConfiguration; | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
.../LINGYUN.Abp.BlobStoring.Nexus/LINGYUN/Abp/BlobStoring/Nexus/NexusBlobNamingNormalizer.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,21 @@ | ||
using Volo.Abp.BlobStoring; | ||
using Volo.Abp.DependencyInjection; | ||
|
||
namespace LINGYUN.Abp.BlobStoring.Nexus; | ||
public class NexusBlobNamingNormalizer : IBlobNamingNormalizer, ITransientDependency | ||
{ | ||
public virtual string NormalizeContainerName(string containerName) | ||
{ | ||
return Normalize(containerName); | ||
} | ||
|
||
public virtual string NormalizeBlobName(string blobName) | ||
{ | ||
return Normalize(blobName); | ||
} | ||
|
||
protected virtual string Normalize(string fileName) | ||
{ | ||
return fileName.Replace("\\", "/").Replace("//", "/"); | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
...es/nexus/LINGYUN.Abp.BlobStoring.Nexus/LINGYUN/Abp/BlobStoring/Nexus/NexusBlobProvider.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,114 @@ | ||
using LINGYUN.Abp.Sonatype.Nexus.Assets; | ||
using LINGYUN.Abp.Sonatype.Nexus.Components; | ||
using LINGYUN.Abp.Sonatype.Nexus.Search; | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Volo.Abp.BlobStoring; | ||
using Volo.Abp.DependencyInjection; | ||
|
||
namespace LINGYUN.Abp.BlobStoring.Nexus; | ||
public class NexusBlobProvider : BlobProviderBase, ITransientDependency | ||
{ | ||
protected INexusAssetManager NexusAssetManager { get; } | ||
protected INexusComponentManager NexusComponentManager { get; } | ||
protected INexusLookupService NexusLookupService { get; } | ||
protected IBlobRawPathCalculator BlobDirectoryCalculator { get; } | ||
|
||
public NexusBlobProvider( | ||
INexusAssetManager nexusAssetManager, | ||
INexusComponentManager nexusComponentManager, | ||
INexusLookupService nexusLookupService, | ||
IBlobRawPathCalculator blobDirectoryCalculator) | ||
{ | ||
NexusAssetManager = nexusAssetManager; | ||
NexusComponentManager = nexusComponentManager; | ||
NexusLookupService = nexusLookupService; | ||
BlobDirectoryCalculator = blobDirectoryCalculator; | ||
} | ||
|
||
public async override Task<bool> DeleteAsync(BlobProviderDeleteArgs args) | ||
{ | ||
var nexusComponent = await GetNexusomponentOrNull(args); | ||
if (nexusComponent == null) | ||
{ | ||
return false; | ||
} | ||
return await NexusComponentManager.DeleteAsync(nexusComponent.Id, args.CancellationToken); | ||
} | ||
|
||
public async override Task<bool> ExistsAsync(BlobProviderExistsArgs args) | ||
{ | ||
var nexusAsset = await GetNexusAssetOrNull(args); | ||
return nexusAsset != null; | ||
} | ||
|
||
public async override Task<Stream> GetOrNullAsync(BlobProviderGetArgs args) | ||
{ | ||
var nexusAsset = await GetNexusAssetOrNull(args); | ||
if (nexusAsset == null) | ||
{ | ||
return null; | ||
} | ||
|
||
return await NexusAssetManager.GetContentOrNullAsync(nexusAsset); | ||
} | ||
|
||
public async override Task SaveAsync(BlobProviderSaveArgs args) | ||
{ | ||
var nexusAsset = await GetNexusAssetOrNull(args); | ||
if (!args.OverrideExisting && nexusAsset != null) | ||
{ | ||
throw new BlobAlreadyExistsException($"Saving BLOB '{args.BlobName}' does already exists in the container '{args.ContainerName}'! Set {nameof(args.OverrideExisting)} if it should be overwritten."); | ||
} | ||
|
||
var fileBytes = await args.BlobStream.GetAllBytesAsync(); | ||
var blobPath = BlobDirectoryCalculator.CalculateGroup(args.ContainerName, args.BlobName); | ||
var blobName = BlobDirectoryCalculator.CalculateName(args.ContainerName, args.BlobName, true); | ||
// blobName = blobName.Replace(blobPath.RemovePreFix("/"), "").RemovePreFix("/"); | ||
var asset1 = new Asset(blobName, fileBytes); | ||
|
||
var nexusConfiguration = args.Configuration.GetNexusConfiguration(); | ||
var repository = nexusConfiguration.Repository; | ||
|
||
var nexusRawBlobUploadArgs = new NexusRawBlobUploadArgs( | ||
repository, | ||
blobPath, | ||
asset1); | ||
|
||
await NexusComponentManager.UploadAsync(nexusRawBlobUploadArgs, args.CancellationToken); | ||
} | ||
|
||
protected async virtual Task<NexusAsset> GetNexusAssetOrNull(BlobProviderArgs args) | ||
{ | ||
var nexusConfiguration = args.Configuration.GetNexusConfiguration(); | ||
var blobPath = BlobDirectoryCalculator.CalculateGroup(args.ContainerName, args.BlobName); | ||
var blobName = BlobDirectoryCalculator.CalculateName(args.ContainerName, args.BlobName); | ||
var nexusSearchArgs = new NexusSearchArgs( | ||
nexusConfiguration.Repository, | ||
blobPath, | ||
blobName); | ||
|
||
var nexusAssetListResult = await NexusLookupService.ListAssetAsync(nexusSearchArgs, args.CancellationToken); | ||
var nexusAsset = nexusAssetListResult.Items.FirstOrDefault(); | ||
|
||
return nexusAsset; | ||
} | ||
|
||
protected async virtual Task<NexusComponent> GetNexusomponentOrNull(BlobProviderArgs args) | ||
{ | ||
var nexusConfiguration = args.Configuration.GetNexusConfiguration(); | ||
var blobPath = BlobDirectoryCalculator.CalculateGroup(args.ContainerName, args.BlobName); | ||
var blobName = BlobDirectoryCalculator.CalculateName(args.ContainerName, args.BlobName); | ||
var nexusSearchArgs = new NexusSearchArgs( | ||
nexusConfiguration.Repository, | ||
blobPath, | ||
blobName); | ||
|
||
var nexusComponentResult = await NexusLookupService.ListComponentAsync(nexusSearchArgs, args.CancellationToken); | ||
var nexusComponent = nexusComponentResult.Items.FirstOrDefault(); | ||
|
||
return nexusComponent; | ||
} | ||
} |
Oops, something went wrong.