-
Notifications
You must be signed in to change notification settings - Fork 154
SFTP Integration #1087
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
SFTP Integration #1087
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a comprehensive SFTP integration for .NET Aspire, providing both hosting and client capabilities for working with SFTP servers using the atmoz/sftp Docker container and the SSH.NET library.
Key Changes:
- Hosting integration (
CommunityToolkit.Aspire.Hosting.Sftp) for running atmoz SFTP containers with support for user configuration, host keys, and public key authentication - Client integration (
CommunityToolkit.Aspire.Sftp) for connecting to SFTP servers with health checks, telemetry, and configuration support - Complete test coverage including functional tests and unit tests
Reviewed changes
Copilot reviewed 36 out of 37 changed files in this pull request and generated 30 comments.
Show a summary per file
| File | Description |
|---|---|
src/CommunityToolkit.Aspire.Hosting.Sftp/SftpHostingExtensions.cs |
Extension methods for adding SFTP container resources with user files and key management |
src/CommunityToolkit.Aspire.Hosting.Sftp/SftpContainerResource.cs |
Resource definition with connection string and endpoint properties |
src/CommunityToolkit.Aspire.Hosting.Sftp/SftpContainerImageTags.cs |
Container image configuration for atmoz/sftp |
src/CommunityToolkit.Aspire.Hosting.Sftp/KeyType.cs |
Enum defining supported key types (Ed25519, RSA) |
src/CommunityToolkit.Aspire.Hosting.Sftp/README.md |
Documentation for hosting integration usage |
src/CommunityToolkit.Aspire.Sftp/AspireSftpExtensions.cs |
Client registration with DI, configuration, and health check setup |
src/CommunityToolkit.Aspire.Sftp/SftpSettings.cs |
Configuration settings for connection, authentication, health checks, and tracing |
src/CommunityToolkit.Aspire.Sftp/SftpHealthCheck.cs |
Health check implementation for SFTP connectivity |
src/CommunityToolkit.Aspire.Sftp/README.md |
Documentation for client integration usage |
tests/CommunityToolkit.Aspire.Hosting.Sftp.Tests/SftpFunctionalTests.cs |
Functional tests for various SFTP configuration scenarios |
tests/CommunityToolkit.Aspire.Hosting.Sftp.Tests/ContainerResourceCreationTests.cs |
Unit tests for resource builder validation |
tests/CommunityToolkit.Aspire.Hosting.Sftp.Tests/AppHostTests.cs |
Integration tests using the example AppHost |
tests/CommunityToolkit.Aspire.Sftp.Tests/AspireSftpClientExtensionsTest.cs |
Unit tests for client extension methods and configuration |
examples/sftp/CommunityToolkit.Aspire.Hosting.Sftp.AppHost/Program.cs |
Example AppHost demonstrating SFTP integration |
examples/sftp/CommunityToolkit.Aspire.Hosting.Sftp.ApiService/Program.cs |
Example API service with upload/download endpoints |
Directory.Packages.props |
Added SSH.NET and Polly package versions |
CommunityToolkit.Aspire.slnx |
Added new projects to solution |
tests/CommunityToolkit.Aspire.Hosting.Sftp.Tests/SftpFunctionalTests.cs
Outdated
Show resolved
Hide resolved
tests/CommunityToolkit.Aspire.Hosting.Sftp.Tests/SftpFunctionalTests.cs
Outdated
Show resolved
Hide resolved
tests/CommunityToolkit.Aspire.Hosting.Sftp.Tests/AppHostTests.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.Sftp/SftpContainerResource.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.Sftp/SftpContainerResource.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.Sftp/SftpContainerResource.cs
Outdated
Show resolved
Hide resolved
src/CommunityToolkit.Aspire.Hosting.Sftp/SftpContainerResource.cs
Outdated
Show resolved
Hide resolved
tests/CommunityToolkit.Aspire.Hosting.Sftp.Tests/SftpFunctionalTests.cs
Outdated
Show resolved
Hide resolved
|
@dotnet-policy-service agree |
aaronpowell
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice looking implementation. Just have a question around the API design and some comments on the tests as we want to ensure they are easy to maintain.
|
|
||
| var builder = DistributedApplication.CreateBuilder(args); | ||
|
|
||
| var sftp = builder.AddSftp("sftp").WithEnvironment("SFTP_USERS", "foo:$5$t9qxNlrcFqVBNnad$U27ZrjbKNjv4JkRWvi6MjX4x6KXNQGr8NTIySOcDgi4:e:::uploads"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the SFTP_USERS always going to be needed when using the hosting integration? If so, is there a way we could wrap it in an API that helps craft the environment variable in the appropriate format to avoid user error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's not. There are two other ways to supply users to the server: arguments (WithArgs()) and config file (WithUsersFile()). But at least one user is required for the server to start.
All of the above methods use the same format for specifying users and support both clear-text (pass) and encrypted ($5$t9qxNlrcFqVBNnad$U27ZrjbKNjv4JkRWvi6MjX4x6KXNQGr8NTIySOcDgi4:e) passwords.
There's a quick note in the README about generating encrypted passwords using mkpasswd.
I've only added a public API for files so they get mounted in the right place, but it's easy enough to add APIs for WithArgs() and WithEnvironment(), just let me know?
src/CommunityToolkit.Aspire.Hosting.Sftp/CommunityToolkit.Aspire.Hosting.Sftp.csproj
Outdated
Show resolved
Hide resolved
| { | ||
| public const string Registry = "docker.io"; | ||
| public const string Image = "atmoz/sftp"; | ||
| public const string Tag = "debian"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a more specific version tag that we can use to avoid versions being pushed that could introduce behaviour changes we don't anticipate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this, only debian, alpine and latest seem to be supported...
I could make it a parameter in the AddSftp() API with a default of latest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well... I suppose SFTP is pretty stable so it shouldn't make a huge difference 🤣
tests/CommunityToolkit.Aspire.Hosting.Sftp.Tests/AppHostTests.cs
Outdated
Show resolved
Hide resolved
tests/CommunityToolkit.Aspire.Hosting.Sftp.Tests/AppHostTests.cs
Outdated
Show resolved
Hide resolved
tests/CommunityToolkit.Aspire.Hosting.Sftp.Tests/SftpFunctionalTests.cs
Outdated
Show resolved
Hide resolved
|
Thank you! 😊 I have implemented most of the changes now and left a note about the rest... |
|
Last thing, the tests need to be added to the github actions workflow - there's a script in |
|
Thank you for fixing that conflict for me @aaronpowell. I've increased the retry params for the unit tests, hopefully that'll allow those tests to pass now... |
**Closes #1057 **
Adds a hosting and client integration for this SFTP server.
PR Checklist
Other information