-
Notifications
You must be signed in to change notification settings - Fork 7
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
Support SFTP paths to root or home directory #5
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.
The path abstraction is certainly hard to generalize and still support all stores native features (e.g. s3 store must have size on put or could support per path encryption).
We did make that compromise that if you need different settings per file Path you would need different Store instances (at LendUp I had to do this for files with different encryption algorithms).
Our use case for SFTP (and also box.com store) was that we had to restrict users to a specific dir just like a “bucket” so this is why we never added support for abs paths.
All these assumptions can certainly be revised and improved.
f2fcc5b
to
b877a84
Compare
a3ede5e
to
042ac30
Compare
Codecov Report
@@ Coverage Diff @@
## master #5 +/- ##
=======================================
Coverage 67.57% 67.57%
=======================================
Files 8 8
Lines 293 293
Branches 11 8 -3
=======================================
Hits 198 198
Misses 95 95
Continue to review full report at Codecov.
|
fc31639
to
4c6d45b
Compare
for{ | ||
q <- fs2.Stream.eval(Queue.bounded[F, Option[ChannelSftp#LsEntry]](64)) | ||
channel <- fs2.Stream.resource(channelResource) | ||
entry <- q.dequeue.unNoneTerminate.filter(e => e.getFilename != "." && e.getFilename != "..").concurrently( | ||
fs2.Stream.eval( | ||
blocker.blockOn(F.flatMap(F.attempt(F.delay(channel.ls(path, entrySelector(e => F.runAsync(q.enqueue1(Some(e)))(_ => IO.unit).unsafeRunSync())))))(_ => q.enqueue1(None))) | ||
for { | ||
q <- fs2.Stream.eval(Queue.bounded[F, Option[ChannelSftp#LsEntry]](64)) | ||
channel <- fs2.Stream.resource(channelResource) | ||
entry <- q.dequeue.unNoneTerminate.filter(e => e.getFilename != "." && e.getFilename != "..").concurrently( | ||
fs2.Stream.eval( | ||
blocker.blockOn(F.flatMap(F.attempt(F.delay(channel.ls(path, entrySelector(e => F.runAsync(q.enqueue1(Some(e)))(_ => IO.unit).unsafeRunSync())))))(_ => q.enqueue1(None))) | ||
) | ||
) | ||
} yield { | ||
val newPath = if (path.filename == entry.getFilename) path else path / entry.getFilename | ||
newPath.copy( | ||
size = Option(entry.getAttrs.getSize), | ||
isDir = entry.getAttrs.isDir, | ||
lastModified = Option(entry.getAttrs.getMTime).map(i => new Date(i.toLong * 1000)) | ||
) | ||
) | ||
} yield { | ||
val newPath = if (path.filename == entry.getFilename) path else path / entry.getFilename | ||
newPath.copy( | ||
size = Option(entry.getAttrs.getSize), | ||
isDir = entry.getAttrs.isDir, | ||
lastModified = Option(entry.getAttrs.getMTime).map(i => new Date(i.toLong * 1000)) | ||
) | ||
} | ||
} | ||
} |
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.
Just formatting here
This PR introduces a new test container that configures the SFTP server without the
ChrootDirectory
directive. This causes users to land in/home/<username>/
instead of/
(ChrootDirectory %h
maps the user's home directory to/
).In order for tests to pass on both server configuration, we must support relative paths. This PR introduces that support.
Discussion, not strictly related to PR contents
I think the
Path
abstraction needs to be augmented or adjusted in order to fully support SFTP. It currently leaks assumptions about the underlying storage, i.e. there's always two components to paths (root
andkey
) and there's no separation between absolute and relative paths. This doesn't hold up for SFTP stores where the following paths are all valid and pointing to different files (ref spec#section-6):"/foo.txt"
"./foo.txt"
"foo.txt"
Since we don't surface any APIs for changing CWD, we can probably get away with assuming
CWD == user home
.Any views on a better API is welcome. I think we should encode the fact that blobstore paths are different from filestore paths (e.g. SFTP) and introduce something like