Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add azure blob storage support #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// <copyright file="FileSystemAmazonS3Options.cs" company="Fubar Development Junker">
// Copyright (c) Fubar Development Junker. All rights reserved.
// </copyright>

namespace TestFtpServer.Configuration
{
/// <summary>
/// Options for the Azure blob storage file system.
/// </summary>
public class FileSystemAzureBlobStorageOptions
{
/// <summary>
/// Gets or sets the root name.
/// </summary>
public string? RootPath { get; set; }

/// <summary>
/// Gets or sets the container name.
/// </summary>
public string? ContainerName { get; set; }

/// <summary>
/// Gets or sets the connection string.
/// </summary>
public string? ConnectionString { get; set; }
}
}
5 changes: 5 additions & 0 deletions samples/TestFtpServer/Configuration/FileSystemType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@ public enum FileSystemType
/// Amazon S3 file system.
/// </summary>
AmazonS3,

/// <summary>
/// Azure Blob Storage file system.
/// </summary>
AzureBlobStorage,
}
}
11 changes: 10 additions & 1 deletion samples/TestFtpServer/Configuration/FtpOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public string Backend
switch (BackendType)
{
case FileSystemType.AmazonS3: return "amazon-s3";
case FileSystemType.AzureBlobStorage: return "azureblobstorage";
case FileSystemType.InMemory: return "in-memory";
case FileSystemType.SystemIO: return "system-io";
case FileSystemType.Unix: return "unix";
Expand All @@ -77,6 +78,9 @@ public string Backend
case "amazon-s3":
BackendType = FileSystemType.AmazonS3;
break;
case "azureblobstorage":
BackendType = FileSystemType.AzureBlobStorage;
break;
case "inMemory":
case "in-memory":
BackendType = FileSystemType.InMemory;
Expand All @@ -98,7 +102,7 @@ public string Backend
break;
default:
throw new ArgumentOutOfRangeException(
$"Value must be one of \"in-memory\", \"system-io\", \"unix\", \"google-drive:user\", \"google-drive:service\", \"amazon-s3\" but was , \"{value}\"");
$"Value must be one of \"in-memory\", \"system-io\", \"unix\", \"google-drive:user\", \"google-drive:service\", \"amazon-s3\", \"azureblobstorage\" but was , \"{value}\"");
}
}
}
Expand Down Expand Up @@ -170,6 +174,11 @@ public string Layout
/// </summary>
public FileSystemAmazonS3Options AmazonS3 { get; set; } = new FileSystemAmazonS3Options();

/// <summary>
/// Gets or sets azure blob storage system options.
/// </summary>
public FileSystemAzureBlobStorageOptions AzureBlobStorage { get; set; } = new FileSystemAzureBlobStorageOptions();

internal FileSystemLayoutType LayoutType
{
get => _layout ?? FileSystemLayoutType.SingleRoot;
Expand Down
12 changes: 11 additions & 1 deletion samples/TestFtpServer/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using FubarDev.FtpServer.CommandExtensions;
using FubarDev.FtpServer.Commands;
using FubarDev.FtpServer.FileSystem;
using FubarDev.FtpServer.FileSystem.AzureBlobStorage;
using FubarDev.FtpServer.FileSystem.DotNet;
using FubarDev.FtpServer.FileSystem.GoogleDrive;
using FubarDev.FtpServer.FileSystem.InMemory;
Expand Down Expand Up @@ -93,7 +94,12 @@ public static IServiceCollection AddFtpServices(
opt.BucketRegion = options.AmazonS3.BucketRegion;
opt.AwsAccessKeyId = options.AmazonS3.AwsAccessKeyId;
opt.AwsSecretAccessKey = options.AmazonS3.AwsSecretAccessKey;
});
})
.Configure<AzureBlobStorageFileSystemOptions>(opt =>
{
opt.ContainerName = options.AzureBlobStorage.ContainerName;
opt.ConnectionString = options.AzureBlobStorage.ConnectionString;
});
#if NETCOREAPP
services
.Configure<PamMembershipProviderOptions>(
Expand Down Expand Up @@ -184,6 +190,10 @@ public static IServiceCollection AddFtpServices(
services = services
.AddFtpServer(sb => sb.ConfigureAuthentication(options).UseS3FileSystem().ConfigureServer(options));
break;
case FileSystemType.AzureBlobStorage:
services = services
.AddFtpServer(sb => sb.ConfigureAuthentication(options).UseAzureBlobStorageFileSystem().ConfigureServer(options));
break;
default:
throw new NotSupportedException(
$"Backend of type {options.Backend} cannot be run from configuration file options.");
Expand Down
1 change: 1 addition & 0 deletions samples/TestFtpServer/TestFtpServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\FubarDev.FtpServer.FileSystem.AzureBlobStorage\FubarDev.FtpServer.FileSystem.AzureBlobStorage.csproj" />
<ProjectReference Include="..\..\src\FubarDev.FtpServer.FileSystem.DotNet\FubarDev.FtpServer.FileSystem.DotNet.csproj" />
<ProjectReference Include="..\..\src\FubarDev.FtpServer.FileSystem.GoogleDrive\FubarDev.FtpServer.FileSystem.GoogleDrive.csproj" />
<ProjectReference Include="..\..\src\FubarDev.FtpServer.FileSystem.InMemory\FubarDev.FtpServer.FileSystem.InMemory.csproj" />
Expand Down
11 changes: 11 additions & 0 deletions samples/TestFtpServer/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,16 @@
"awsAccessKeyId": null,
/* The AWS secret key */
"awsSecretAccessKey": null
},

/* Use Azure Blob Storage as backend */
"azureblobstorage": {
/* Name of the root path */
"rootPath": null,
/* Name of the container */
"containerName": null,
/* Connection string to the blob storage */
"connectionString": null
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// <copyright file="S3DirectoryEntry.cs" company="Fubar Development Junker">
// Copyright (c) Fubar Development Junker. All rights reserved.
// </copyright>

using System.IO;


namespace FubarDev.FtpServer.FileSystem.AzureBlobStorage
{
/// <summary>
/// The virtual directory entry for blob objects.
/// </summary>
internal class AzureBlobStorageDirectoryEntry : AzureBlobStorageFileSystemEntry, IUnixDirectoryEntry
{
/// <summary>
/// Initializes a new instance of the <see cref="AzureBlobStorageDirectoryEntry"/> class.
/// </summary>
/// <param name="key">The path/prefix of the child entries.</param>
/// <param name="isRoot">Determines if this is the root directory.</param>
public AzureBlobStorageDirectoryEntry(string key, bool isRoot = false)
: base(key.EndsWith("/") || isRoot ? key : key + "/", Path.GetFileName(key.TrimEnd('/')))
{
IsRoot = isRoot;
}

/// <inheritdoc />
public bool IsRoot { get; }


/// <inheritdoc />
public bool IsDeletable => !IsRoot;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// <copyright file="S3FileEntry.cs" company="Fubar Development Junker">
// Copyright (c) Fubar Development Junker. All rights reserved.
// </copyright>

using System.IO;

namespace FubarDev.FtpServer.FileSystem.AzureBlobStorage
{
/// <summary>
/// A file entry for an azure blob storage object.
/// </summary>
internal class AzureBlobStorageFileEntry : AzureBlobStorageFileSystemEntry, IUnixFileEntry
{
/// <summary>
/// Initializes a new instance of the <see cref="AzureBlobStorageFileEntry"/> class.
/// </summary>
/// <param name="key">The blob object key.</param>
/// <param name="size">The object size.</param>
public AzureBlobStorageFileEntry(string key, long size)
: base(key, Path.GetFileName(key))
{
Size = size;
}

/// <inheritdoc />
public long Size { get; }
}
}
Loading